You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sqoop.apache.org by ja...@apache.org on 2015/04/01 17:52:48 UTC

sqoop git commit: SQOOP-2213: Sqoop2: toCSVFixedPoint ClassCastException

Repository: sqoop
Updated Branches:
  refs/heads/sqoop2 a3362a256 -> 947f53281


SQOOP-2213: Sqoop2: toCSVFixedPoint ClassCastException

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

Branch: refs/heads/sqoop2
Commit: 947f5328158e715bd54331043eb7e0ca6a909263
Parents: a3362a2
Author: Jarek Jarcec Cecho <ja...@apache.org>
Authored: Wed Apr 1 08:52:30 2015 -0700
Committer: Jarek Jarcec Cecho <ja...@apache.org>
Committed: Wed Apr 1 08:52:30 2015 -0700

----------------------------------------------------------------------
 .../sqoop/connector/common/SqoopIDFUtils.java   | 12 +++++--
 .../connector/common/TestSqoopIDFUtils.java     | 33 ++++++++++++++++++--
 2 files changed, 41 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/sqoop/blob/947f5328/connector/connector-sdk/src/main/java/org/apache/sqoop/connector/common/SqoopIDFUtils.java
----------------------------------------------------------------------
diff --git a/connector/connector-sdk/src/main/java/org/apache/sqoop/connector/common/SqoopIDFUtils.java b/connector/connector-sdk/src/main/java/org/apache/sqoop/connector/common/SqoopIDFUtils.java
index c460f80..2a7aa1b 100644
--- a/connector/connector-sdk/src/main/java/org/apache/sqoop/connector/common/SqoopIDFUtils.java
+++ b/connector/connector-sdk/src/main/java/org/apache/sqoop/connector/common/SqoopIDFUtils.java
@@ -128,9 +128,17 @@ public class SqoopIDFUtils {
 
   public static String toCSVFixedPoint(Object obj, Column column) {
     if (isInteger(column)) {
-      return ((Integer) obj).toString();
+      if (obj instanceof Number) {
+        return new Integer(((Number)obj).intValue()).toString();
+      } else {
+        return new Integer(obj.toString()).toString();
+      }
     } else {
-      return ((Long) obj).toString();
+      if (obj instanceof Number) {
+        return new Long(((Number)obj).longValue()).toString();
+      } else {
+        return new Long(obj.toString()).toString();
+      }
     }
   }
 

http://git-wip-us.apache.org/repos/asf/sqoop/blob/947f5328/connector/connector-sdk/src/test/java/org/apache/sqoop/connector/common/TestSqoopIDFUtils.java
----------------------------------------------------------------------
diff --git a/connector/connector-sdk/src/test/java/org/apache/sqoop/connector/common/TestSqoopIDFUtils.java b/connector/connector-sdk/src/test/java/org/apache/sqoop/connector/common/TestSqoopIDFUtils.java
index f99d1af..f9b676b 100644
--- a/connector/connector-sdk/src/test/java/org/apache/sqoop/connector/common/TestSqoopIDFUtils.java
+++ b/connector/connector-sdk/src/test/java/org/apache/sqoop/connector/common/TestSqoopIDFUtils.java
@@ -158,12 +158,11 @@ public class TestSqoopIDFUtils {
     assertTrue(Integer.valueOf(encodedText) instanceof Integer);
   }
 
-  @Test(expectedExceptions = Exception.class)
+  @Test
   public void testToCSVFixedPointWithLongSignedAsInteger() {
     Column col = new FixedPoint("ft", 4L, true);
     Long test = 459999999444L;
     String encodedText = toCSVFixedPoint(test, col);
-    // should be a long
     assertTrue(Integer.valueOf(encodedText) instanceof Integer);
   }
 
@@ -194,6 +193,36 @@ public class TestSqoopIDFUtils {
   }
 
   @Test
+  public void testToCSVFixedPointWithLongAsInt() {
+    Column col = new FixedPoint("ft", 2L, false);
+    // java does not have a concept of unsigned int, so it has to be a long for
+    // testing
+    String encodedText = toCSVFixedPoint(new Long(Integer.MAX_VALUE), col);
+    assertEquals("2147483647", encodedText);
+  }
+
+  @Test
+  public void testToCSVFixedPointWithIntAsLong() {
+    Column col = new FixedPoint("ft", 4L, false);
+    // java does not have a concept of unsigned int, so it has to be a long for
+    // testing
+    String encodedText = toCSVFixedPoint(Integer.MAX_VALUE, col);
+    assertEquals("2147483647", encodedText);
+  }
+
+  @Test(expectedExceptions = NumberFormatException.class)
+  public void testToCSVFixedPointWithBadNumberAsLong() {
+    Column col = new FixedPoint("ft", 4L, false);
+    toCSVFixedPoint("lame", col);
+  }
+
+  @Test(expectedExceptions = NumberFormatException.class)
+  public void testToCSVFixedPointWithBadNumberAsInteger() {
+    Column col = new FixedPoint("ft", 2L, false);
+    toCSVFixedPoint("lame", col);
+  }
+
+  @Test
   public void testToFixedPointReturnsInt() {
     Column col = new FixedPoint("fixt", 4L, true);
     assertTrue(toFixedPoint("233", col) instanceof Integer);