sqoop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jar...@apache.org
Subject git commit: SQOOP-1661: Sqoop2: Intermediate data format text null handling
Date Wed, 05 Nov 2014 21:45:31 GMT
Repository: sqoop
Updated Branches:
  refs/heads/sqoop2 162cab8ec -> a63c9efe1


SQOOP-1661: Sqoop2: Intermediate data format text null handling

(Abraham Elmahrek 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/a63c9efe
Tree: http://git-wip-us.apache.org/repos/asf/sqoop/tree/a63c9efe
Diff: http://git-wip-us.apache.org/repos/asf/sqoop/diff/a63c9efe

Branch: refs/heads/sqoop2
Commit: a63c9efe198571a3bc4bed6f7118f0e3d45a94fb
Parents: 162cab8
Author: Jarek Jarcec Cecho <jarcec@apache.org>
Authored: Wed Nov 5 13:45:06 2014 -0800
Committer: Jarek Jarcec Cecho <jarcec@apache.org>
Committed: Wed Nov 5 13:45:06 2014 -0800

----------------------------------------------------------------------
 .../idf/CSVIntermediateDataFormat.java          |  5 ++++
 .../idf/TestCSVIntermediateDataFormat.java      | 28 ++++++++++++++++++++
 2 files changed, 33 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/sqoop/blob/a63c9efe/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 4e0ecee..e0e4061 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
@@ -45,6 +45,7 @@ public class CSVIntermediateDataFormat extends IntermediateDataFormat<String>
{
   public static final char SEPARATOR_CHARACTER = ',';
   public static final char ESCAPE_CHARACTER = '\\';
   public static final char QUOTE_CHARACTER = '\'';
+  public static final String NULL_STRING = "NULL";
 
 
   private static final char[] originals = {
@@ -326,6 +327,10 @@ public class CSVIntermediateDataFormat extends IntermediateDataFormat<String>
{
   }
 
   private String escapeStrings(String orig) {
+    if (orig == null) {
+      return NULL_STRING;
+    }
+
     int j = 0;
     String replacement = orig;
     try {

http://git-wip-us.apache.org/repos/asf/sqoop/blob/a63c9efe/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 291fef2..72e95ed 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
@@ -183,6 +183,34 @@ public class TestCSVIntermediateDataFormat {
   }
 
   @Test
+  public void testObjectWithNullInStringOut() {
+    Schema schema = new Schema("test");
+    schema.addColumn(new FixedPoint("1"))
+        .addColumn(new FixedPoint("2"))
+        .addColumn(new Text("3"))
+        .addColumn(new Text("4"))
+        .addColumn(new Binary("5"))
+        .addColumn(new Text("6"));
+    data.setSchema(schema);
+
+    byte[] byteFieldData = new byte[] { (byte) 0x0D, (byte) -112, (byte) 54};
+    Object[] in = new Object[6];
+    in[0] = new Long(10);
+    in[1] = new Long(34);
+    in[2] = null;
+    in[3] = "random data";
+    in[4] = byteFieldData;
+    in[5] = new String(new char[] { 0x0A });
+
+    data.setObjectData(in);
+
+    //byte[0] = \r byte[1] = -112, byte[1] = 54 - 2's complements
+    String testData = "10,34,NULL,'random data'," +
+        getByteFieldString(byteFieldData).replaceAll("\r", "\\\\r") + ",'\\n'";
+    assertEquals(testData, data.getTextData());
+  }
+
+  @Test
   public void testStringFullRangeOfCharacters() {
     Schema schema = new Schema("test");
     schema.addColumn(new Text("1"));


Mime
View raw message