mirror of
https://github.com/apache/sqoop.git
synced 2025-05-13 07:21:08 +08:00
SQOOP-1669: Sqoop2: JDBC connector does not understand iso8610 representation using " " as separator
(Qian Xu via Jarek Jarcec Cecho)
This commit is contained in:
parent
3c111205c0
commit
e4455d193b
@ -220,7 +220,11 @@ public Object[] getObjectData() {
|
||||
out[i] = LocalDate.parse(fields[i]);
|
||||
break;
|
||||
case DATE_TIME:
|
||||
out[i] = LocalDateTime.parse(fields[i]);
|
||||
// A datetime string with a space as date-time separator will not be
|
||||
// parsed expectedly. The expected separator is "T". See also:
|
||||
// https://github.com/JodaOrg/joda-time/issues/11
|
||||
String iso8601 = fields[i].replace(" ", "T");
|
||||
out[i] = LocalDateTime.parse(iso8601);
|
||||
break;
|
||||
case BIT:
|
||||
out[i] = Boolean.valueOf(fields[i].equals("1")
|
||||
|
@ -251,6 +251,27 @@ public void testDateTime() {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* In ISO8601 "T" is used as date-time separator. Unfortunately in the real
|
||||
* world, database (confirmed with mysql and postgres) might return a datatime
|
||||
* string with a space as separator. The test case intends to check, whether
|
||||
* such datatime string can be handled expectedly.
|
||||
*/
|
||||
@Test
|
||||
public void testDateTimeISO8601Alternative() {
|
||||
Schema schema = new Schema("test");
|
||||
schema.addColumn(new DateTime("1"));
|
||||
data.setSchema(schema);
|
||||
|
||||
for (String dateTime : new String[]{
|
||||
"2014-10-01 12:00:00",
|
||||
"2014-10-01 12:00:00.000"
|
||||
}) {
|
||||
data.setTextData(dateTime);
|
||||
assertEquals("2014-10-01T12:00:00.000", data.getObjectData()[0].toString());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBit() {
|
||||
Schema schema = new Schema("test");
|
||||
|
Loading…
Reference in New Issue
Block a user