sqoop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From venkatran...@apache.org
Subject sqoop git commit: SQOOP-2864: ClassWriter chokes on column names containing double quotes (Jarek Jarcec Cecho via Venkat Ranganathan)
Date Fri, 04 Mar 2016 19:37:54 GMT
Repository: sqoop
Updated Branches:
  refs/heads/trunk d21699e2a -> 152fe9300


SQOOP-2864: ClassWriter chokes on column names containing double quotes
      (Jarek Jarcec Cecho via Venkat Ranganathan)


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

Branch: refs/heads/trunk
Commit: 152fe93002253b8b3e433d4193ad1e9d1c1591ba
Parents: d21699e
Author: Venkat Ranganathan <venkat@hortonworks.com>
Authored: Fri Mar 4 11:37:40 2016 -0800
Committer: Venkat Ranganathan <venkat@hortonworks.com>
Committed: Fri Mar 4 11:37:40 2016 -0800

----------------------------------------------------------------------
 src/java/org/apache/sqoop/orm/ClassWriter.java | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/sqoop/blob/152fe930/src/java/org/apache/sqoop/orm/ClassWriter.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/sqoop/orm/ClassWriter.java b/src/java/org/apache/sqoop/orm/ClassWriter.java
index 95c655d..23a9c41 100644
--- a/src/java/org/apache/sqoop/orm/ClassWriter.java
+++ b/src/java/org/apache/sqoop/orm/ClassWriter.java
@@ -1096,7 +1096,7 @@ public class ClassWriter {
             sb.append("    else");
           }
 
-          sb.append("    if (\"" + rawColNames[i] + "\".equals(__fieldName)) {\n");
+          sb.append("    if (\"" + serializeRawColName(rawColNames[i]) + "\".equals(__fieldName))
{\n");
           sb.append("      this." + colNames[i] + " = (" + javaType
               + ") __fieldVal;\n");
           sb.append("    }\n");
@@ -1116,6 +1116,20 @@ public class ClassWriter {
   }
 
   /**
+   * Raw column name is a column name as it was created on database and we need to serialize
it between
+   * double quotes into java class that will be further complied with javac. Various databases
supports
+   * various edge conditions for column names, so we can't assume that raw column name can
be just passed
+   * between double quotes and everything will work correctly. That will break for databases
that supports
+   * double quotes in column name as that will result in "column with "" which is invalid.
+   *
+   * @param name Raw column name to escape
+   * @return
+   */
+  private String serializeRawColName(String name) {
+    return name.replace("\"", "\\\"");
+  }
+
+  /**
    * Generate the setField() method.
    * @param columnTypes - mapping from column names to sql types
    * @param colNames - ordered list of column names for table.
@@ -1143,7 +1157,7 @@ public class ClassWriter {
           sb.append("    else");
         }
 
-        sb.append("    if (\"" + rawColName + "\".equals(__fieldName)) {\n");
+        sb.append("    if (\"" + serializeRawColName(rawColName) + "\".equals(__fieldName))
{\n");
         sb.append("      this." + colName + " = (" + javaType
             + ") __fieldVal;\n");
         sb.append("      return true;\n");
@@ -1208,8 +1222,7 @@ public class ClassWriter {
 
     for (int i = methodNumber * size;
          i < topBoundary(colNames, methodNumber, size); ++i) {
-      sb.append("    __sqoop$field_map.put(\"" + rawColNames[i] + "\", this."
-          + colNames[i] + ");\n");
+      sb.append("    __sqoop$field_map.put(\"" + serializeRawColName(rawColNames[i]) + "\",
this." + colNames[i] + ");\n");
     }
 
     if (wrapInMethod) {


Mime
View raw message