5
0
mirror of https://github.com/apache/sqoop.git synced 2025-05-05 05:59:07 +08:00

SQOOP-2586: Sqoop2: Oracle DATE type error

(lvchuanwen via Jarek Jarcec Cecho)
This commit is contained in:
Jarek Jarcec Cecho 2015-09-28 10:56:33 -07:00
parent 52e9c11ad2
commit 2ee3bdd342
2 changed files with 13 additions and 6 deletions

View File

@ -301,7 +301,12 @@ public void addBatch(Object[] array, Schema schema) {
break; break;
case DATE_TIME: case DATE_TIME:
// convert the JODA date time to sql date // convert the JODA date time to sql date
DateTime dateTime = (DateTime) array[i]; DateTime dateTime = null;
if (array[i] instanceof org.joda.time.LocalDateTime) {
dateTime = ((org.joda.time.LocalDateTime) array[i]).toDateTime();
} else {
dateTime = (DateTime) array[i];
}
Timestamp timestamp = new Timestamp(dateTime.getMillis()); Timestamp timestamp = new Timestamp(dateTime.getMillis());
preparedStatement.setObject(i + 1, timestamp); preparedStatement.setObject(i + 1, timestamp);
break; break;

View File

@ -74,7 +74,7 @@ public void setUp() {
if (!executor.existTable(tableName)) { if (!executor.existTable(tableName)) {
executor.executeUpdate("CREATE TABLE " + executor.encloseIdentifier(tableName) executor.executeUpdate("CREATE TABLE " + executor.encloseIdentifier(tableName)
+ "(ICOL INTEGER PRIMARY KEY, DCOL DOUBLE, VCOL VARCHAR(20), DATECOL DATE, DATETIMECOL TIMESTAMP, TIMECOL TIME)"); + "(ICOL INTEGER PRIMARY KEY, DCOL DOUBLE, VCOL VARCHAR(20), DATECOL DATE, DATETIMECOL TIMESTAMP, TIMECOL TIME , LOCALDATETIMECOL TIMESTAMP)");
} else { } else {
executor.deleteTableData(tableName); executor.deleteTableData(tableName);
} }
@ -98,7 +98,7 @@ public void testInsert() throws Exception {
ToJobConfiguration jobConfig = new ToJobConfiguration(); ToJobConfiguration jobConfig = new ToJobConfiguration();
context.setString(GenericJdbcConnectorConstants.CONNECTOR_JDBC_TO_DATA_SQL, context.setString(GenericJdbcConnectorConstants.CONNECTOR_JDBC_TO_DATA_SQL,
"INSERT INTO " + executor.encloseIdentifier(tableName) + " VALUES (?,?,?,?,?,?)"); "INSERT INTO " + executor.encloseIdentifier(tableName) + " VALUES (?,?,?,?,?,?,?)");
Loader loader = new GenericJdbcLoader(); Loader loader = new GenericJdbcLoader();
@ -106,7 +106,7 @@ public void testInsert() throws Exception {
Schema schema = new Schema("TestLoader"); Schema schema = new Schema("TestLoader");
schema.addColumn(new FixedPoint("c1", 2L, true)).addColumn(new Decimal("c2", 5, 2)) schema.addColumn(new FixedPoint("c1", 2L, true)).addColumn(new Decimal("c2", 5, 2))
.addColumn(new Text("c3")).addColumn(new Date("c4")) .addColumn(new Text("c3")).addColumn(new Date("c4"))
.addColumn(new DateTime("c5", false, false)).addColumn(new Time("c6", false)); .addColumn(new DateTime("c5", false, false)).addColumn(new Time("c6", false)).addColumn(new DateTime("c7", false, false));
LoaderContext loaderContext = new LoaderContext(context, reader, schema); LoaderContext loaderContext = new LoaderContext(context, reader, schema);
loader.load(loaderContext, linkConfig, jobConfig); loader.load(loaderContext, linkConfig, jobConfig);
@ -122,7 +122,7 @@ public void testInsert() throws Exception {
assertEquals("2004-10-19", rs.getObject(4).toString()); assertEquals("2004-10-19", rs.getObject(4).toString());
assertEquals("2004-10-19 10:23:34.0", rs.getObject(5).toString()); assertEquals("2004-10-19 10:23:34.0", rs.getObject(5).toString());
assertEquals("11:33:59", rs.getObject(6).toString()); assertEquals("11:33:59", rs.getObject(6).toString());
assertEquals("2004-10-19 10:23:34.0", rs.getObject(7).toString());
index++; index++;
} }
assertEquals(numberOfRows, index - START); assertEquals(numberOfRows, index - START);
@ -136,6 +136,7 @@ public class DummyReader extends DataReader {
public Object[] readArrayRecord() { public Object[] readArrayRecord() {
LocalDate jodaDate= new LocalDate(2004, 10, 19); LocalDate jodaDate= new LocalDate(2004, 10, 19);
org.joda.time.DateTime jodaDateTime= new org.joda.time.DateTime(2004, 10, 19, 10, 23, 34); org.joda.time.DateTime jodaDateTime= new org.joda.time.DateTime(2004, 10, 19, 10, 23, 34);
org.joda.time.LocalDateTime LocalJodaDateTime= new org.joda.time.LocalDateTime(2004, 10, 19, 10, 23, 34);
LocalTime time= new LocalTime(11, 33, 59); LocalTime time= new LocalTime(11, 33, 59);
if (index < numberOfRows) { if (index < numberOfRows) {
@ -145,7 +146,8 @@ public Object[] readArrayRecord() {
String.valueOf(START+index), String.valueOf(START+index),
jodaDate, jodaDate,
jodaDateTime, jodaDateTime,
time}; time,
LocalJodaDateTime};
index++; index++;
return array; return array;
} else { } else {