gobblin-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject incubator-gobblin git commit: [GOBBLIN-175] Escape string in hive query for avro2orc conversion
Date Sat, 29 Jul 2017 20:53:01 GMT
Repository: incubator-gobblin
Updated Branches:
  refs/heads/master 11646563a -> 9b68773e0


[GOBBLIN-175] Escape string in hive query for avro2orc conversion

Closes #2029 from aditya1105/avro2orc


Project: http://git-wip-us.apache.org/repos/asf/incubator-gobblin/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-gobblin/commit/9b68773e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-gobblin/tree/9b68773e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-gobblin/diff/9b68773e

Branch: refs/heads/master
Commit: 9b68773e0384f75f523203ff46178f183c51a485
Parents: 1164656
Author: aditya1105 <adsharma@linkedin.com>
Authored: Sat Jul 29 13:52:55 2017 -0700
Committer: Abhishek Tiwari <abhishektiwari.btech@gmail.com>
Committed: Sat Jul 29 13:52:55 2017 -0700

----------------------------------------------------------------------
 .../hive/query/HiveAvroORCQueryGenerator.java       | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-gobblin/blob/9b68773e/gobblin-data-management/src/main/java/gobblin/data/management/conversion/hive/query/HiveAvroORCQueryGenerator.java
----------------------------------------------------------------------
diff --git a/gobblin-data-management/src/main/java/gobblin/data/management/conversion/hive/query/HiveAvroORCQueryGenerator.java
b/gobblin-data-management/src/main/java/gobblin/data/management/conversion/hive/query/HiveAvroORCQueryGenerator.java
index 850ee4d..023e060 100644
--- a/gobblin-data-management/src/main/java/gobblin/data/management/conversion/hive/query/HiveAvroORCQueryGenerator.java
+++ b/gobblin-data-management/src/main/java/gobblin/data/management/conversion/hive/query/HiveAvroORCQueryGenerator.java
@@ -511,7 +511,7 @@ public class HiveAvroORCQueryGenerator {
       if (hiveColumns.isPresent()) {
         hiveColumns.get().put(name, type);
       }
-      columns.append(String.format("  `%s` %s COMMENT '%s'", name, type, comment));
+      columns.append(String.format("  `%s` %s COMMENT '%s'", name, type, escapeStringForHive(comment)));
     }
 
     return columns.toString();
@@ -848,7 +848,7 @@ public class HiveAvroORCQueryGenerator {
             ddl.add(String.format("USE %s%n", finalDbName));
             ddl.add(String.format("ALTER TABLE `%s` CHANGE COLUMN %s %s %s COMMENT '%s'",
                 finalTableName, evolvedColumn.getKey(), evolvedColumn.getKey(), evolvedColumn.getValue(),
-                destinationField.getComment()));
+                escapeStringForHive(destinationField.getComment())));
           }
           found = true;
           break;
@@ -1101,4 +1101,16 @@ public class HiveAvroORCQueryGenerator {
       return String.format("'%s'", value);
     }
   };
+
+  private static String escapeStringForHive(String st) {
+    char backslash = '\\';
+    char singleQuote = '\'';
+    char semicolon = ';';
+    String escapedSingleQuote = String.valueOf(backslash) + String.valueOf(singleQuote);
+    String escapedSemicolon = String.valueOf(backslash) + String.valueOf(semicolon);
+
+    st = st.replace(String.valueOf(singleQuote), escapedSingleQuote)
+        .replace(String.valueOf(semicolon), escapedSemicolon);
+    return st;
+  }
 }


Mime
View raw message