sqoop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jar...@apache.org
Subject git commit: SQOOP-1669: Sqoop2: JDBC connector does not understand iso8610 representation using " " as separator
Date Wed, 05 Nov 2014 14:36:33 GMT
Repository: sqoop
Updated Branches:
  refs/heads/branch-1.99.4 3c111205c -> e4455d193


SQOOP-1669: Sqoop2: JDBC connector does not understand iso8610 representation using " " as
separator

(Qian Xu via Jarek Jarcec Cecho)


Project: http://git-wip-us.apache.org/repos/asf/sqoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/sqoop/commit/e4455d19
Tree: http://git-wip-us.apache.org/repos/asf/sqoop/tree/e4455d19
Diff: http://git-wip-us.apache.org/repos/asf/sqoop/diff/e4455d19

Branch: refs/heads/branch-1.99.4
Commit: e4455d193b907f972bd2393f5045ca63d2a6ca07
Parents: 3c11120
Author: Jarek Jarcec Cecho <jarcec@apache.org>
Authored: Wed Nov 5 06:35:37 2014 -0800
Committer: Jarek Jarcec Cecho <jarcec@apache.org>
Committed: Wed Nov 5 06:36:22 2014 -0800

----------------------------------------------------------------------
 .../idf/CSVIntermediateDataFormat.java          |  6 +++++-
 .../idf/TestCSVIntermediateDataFormat.java      | 21 ++++++++++++++++++++
 2 files changed, 26 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/sqoop/blob/e4455d19/connector/connector-sdk/src/main/java/org/apache/sqoop/connector/idf/CSVIntermediateDataFormat.java
----------------------------------------------------------------------
diff --git a/connector/connector-sdk/src/main/java/org/apache/sqoop/connector/idf/CSVIntermediateDataFormat.java
b/connector/connector-sdk/src/main/java/org/apache/sqoop/connector/idf/CSVIntermediateDataFormat.java
index 7eb1d8d..4e0ecee 100644
--- a/connector/connector-sdk/src/main/java/org/apache/sqoop/connector/idf/CSVIntermediateDataFormat.java
+++ b/connector/connector-sdk/src/main/java/org/apache/sqoop/connector/idf/CSVIntermediateDataFormat.java
@@ -220,7 +220,11 @@ public class CSVIntermediateDataFormat extends IntermediateDataFormat<String>
{
           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")

http://git-wip-us.apache.org/repos/asf/sqoop/blob/e4455d19/connector/connector-sdk/src/test/java/org/apache/sqoop/connector/idf/TestCSVIntermediateDataFormat.java
----------------------------------------------------------------------
diff --git a/connector/connector-sdk/src/test/java/org/apache/sqoop/connector/idf/TestCSVIntermediateDataFormat.java
b/connector/connector-sdk/src/test/java/org/apache/sqoop/connector/idf/TestCSVIntermediateDataFormat.java
index 74f2e07..291fef2 100644
--- a/connector/connector-sdk/src/test/java/org/apache/sqoop/connector/idf/TestCSVIntermediateDataFormat.java
+++ b/connector/connector-sdk/src/test/java/org/apache/sqoop/connector/idf/TestCSVIntermediateDataFormat.java
@@ -251,6 +251,27 @@ public class TestCSVIntermediateDataFormat {
     }
   }
 
+  /**
+   * 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");


Mime
View raw message