sqoop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From q..@apache.org
Subject sqoop git commit: SQOOP-2103: Not able define Decimal(n, p) data type in map-column-hive option
Date Thu, 25 Jun 2015 03:24:21 GMT
Repository: sqoop
Updated Branches:
  refs/heads/trunk fa8b733e4 -> 71956cad3


SQOOP-2103: Not able define Decimal(n,p) data type in map-column-hive option

(Abraham Elmahrek via Qian Xu)


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

Branch: refs/heads/trunk
Commit: 71956cad3f18b385845fbb2d803612766f269590
Parents: fa8b733
Author: Qian Xu <qian.a.xu@intel.com>
Authored: Thu Jun 25 11:23:35 2015 +0800
Committer: Qian Xu <qian.a.xu@intel.com>
Committed: Thu Jun 25 11:23:35 2015 +0800

----------------------------------------------------------------------
 src/java/org/apache/sqoop/SqoopOptions.java     | 13 ++++++-
 src/test/org/apache/sqoop/TestSqoopOptions.java | 37 ++++++++++++++++++++
 2 files changed, 49 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/sqoop/blob/71956cad/src/java/org/apache/sqoop/SqoopOptions.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/sqoop/SqoopOptions.java b/src/java/org/apache/sqoop/SqoopOptions.java
index ef6e0ce..d7c9cbb 100644
--- a/src/java/org/apache/sqoop/SqoopOptions.java
+++ b/src/java/org/apache/sqoop/SqoopOptions.java
@@ -20,7 +20,9 @@ package org.apache.sqoop;
 
 import java.io.File;
 import java.io.IOException;
+import java.io.UnsupportedEncodingException;
 import java.lang.reflect.Field;
+import java.net.URLDecoder;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Iterator;
@@ -1214,6 +1216,7 @@ public class SqoopOptions implements Cloneable {
   protected void parseColumnMapping(String mapping,
           Properties output) {
     output.clear();
+
     String[] maps = mapping.split(",");
     for(String map : maps) {
       String[] details = map.split("=");
@@ -1221,7 +1224,15 @@ public class SqoopOptions implements Cloneable {
         throw new IllegalArgumentException("Malformed mapping.  "
             + "Column mapping should be the form key=value[,key=value]*");
       }
-      output.put(details[0], details[1]);
+
+      try {
+        output.put(
+            URLDecoder.decode(details[0], "UTF-8"),
+            URLDecoder.decode(details[1], "UTF-8"));
+      } catch (UnsupportedEncodingException e) {
+        throw new IllegalArgumentException("Encoding not supported. "
+            + "Column mapping should be UTF-8 encoding.");
+      }
     }
   }
 

http://git-wip-us.apache.org/repos/asf/sqoop/blob/71956cad/src/test/org/apache/sqoop/TestSqoopOptions.java
----------------------------------------------------------------------
diff --git a/src/test/org/apache/sqoop/TestSqoopOptions.java b/src/test/org/apache/sqoop/TestSqoopOptions.java
new file mode 100644
index 0000000..87b340a
--- /dev/null
+++ b/src/test/org/apache/sqoop/TestSqoopOptions.java
@@ -0,0 +1,37 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.sqoop;
+
+import java.util.Properties;
+
+import junit.framework.TestCase;
+
+public class TestSqoopOptions extends TestCase {
+  public void testParseColumnParsing() {
+    new SqoopOptions() {
+      public void testParseColumnMapping() {
+        Properties result = new Properties();
+        parseColumnMapping("test=INTEGER,test1=DECIMAL(1%2C1),test2=NUMERIC(1%2C%202)", result);
+        assertEquals("INTEGER", result.getProperty("test"));
+        assertEquals("DECIMAL(1,1)", result.getProperty("test1"));
+        assertEquals("NUMERIC(1, 2)", result.getProperty("test2"));
+      }
+    }.testParseColumnMapping();
+  }
+}


Mime
View raw message