sqoop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject [49/52] [abbrv] git commit: SQOOP-1562: Sqoop2: BIT handling in CSV IDF
Date Fri, 10 Oct 2014 02:52:18 GMT
SQOOP-1562: Sqoop2: BIT handling in CSV IDF

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

Branch: refs/heads/SQOOP-1367
Commit: c78b75a645fa77e55809da57fedee3b0dea2fe60
Parents: 1e9db01
Author: Jarek Jarcec Cecho <jarcec@apache.org>
Authored: Mon Oct 6 06:46:46 2014 -0700
Committer: Abraham Elmahrek <abraham@elmahrek.com>
Committed: Thu Oct 9 18:22:51 2014 -0700

----------------------------------------------------------------------
 .../idf/CSVIntermediateDataFormat.java          |  3 ++-
 .../idf/TestCSVIntermediateDataFormat.java      | 25 +++++++++++++++++++-
 2 files changed, 26 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/sqoop/blob/c78b75a6/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 3c3543c..7eb1d8d 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
@@ -223,7 +223,8 @@ public class CSVIntermediateDataFormat extends IntermediateDataFormat<String>
{
           out[i] = LocalDateTime.parse(fields[i]);
           break;
         case BIT:
-          out[i] = fields[i];
+          out[i] = Boolean.valueOf(fields[i].equals("1")
+              || fields[i].toLowerCase().equals("true"));
           break;
         default:
           throw new SqoopException(IntermediateDataFormatError.INTERMEDIATE_DATA_FORMAT_0004,
"Column type from schema was not recognized for " + colType);

http://git-wip-us.apache.org/repos/asf/sqoop/blob/c78b75a6/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 3159883..74f2e07 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
@@ -19,6 +19,7 @@
 package org.apache.sqoop.connector.idf;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 
@@ -28,6 +29,7 @@ import java.util.Arrays;
 import org.apache.sqoop.common.SqoopException;
 import org.apache.sqoop.schema.Schema;
 import org.apache.sqoop.schema.type.Binary;
+import org.apache.sqoop.schema.type.Bit;
 import org.apache.sqoop.schema.type.Date;
 import org.apache.sqoop.schema.type.DateTime;
 import org.apache.sqoop.schema.type.FixedPoint;
@@ -195,7 +197,7 @@ public class TestCSVIntermediateDataFormat {
 
     Object[] in = {strData};
     Object[] inCopy = new Object[1];
-    System.arraycopy(in,0,inCopy,0,in.length);
+    System.arraycopy(in, 0, inCopy, 0, in.length);
 
     // Modifies the input array, so we use the copy to confirm
     data.setObjectData(in);
@@ -249,6 +251,27 @@ public class TestCSVIntermediateDataFormat {
     }
   }
 
+  @Test
+  public void testBit() {
+    Schema schema = new Schema("test");
+    schema.addColumn(new Bit("1"));
+    data.setSchema(schema);
+
+    for (String trueBit : new String[]{
+        "true", "TRUE", "1"
+    }) {
+      data.setTextData(trueBit);
+      assertTrue((Boolean) data.getObjectData()[0]);
+    }
+
+    for (String falseBit : new String[]{
+        "false", "FALSE", "0"
+    }) {
+      data.setTextData(falseBit);
+      assertFalse((Boolean) data.getObjectData()[0]);
+    }
+  }
+
   @Test(expected=SqoopException.class)
   public void testEmptySchema() {
     String testData = "10,34,'54','random data'," + getByteFieldString(new byte[] { (byte)
-112, (byte) 54})


Mime
View raw message