You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@gobblin.apache.org by su...@apache.org on 2020/10/20 21:28:04 UTC
[incubator-gobblin] branch master updated: [GOBBLIN-1295] Provide
escape for each character of '"' where hive doesn't do it properly
This is an automated email from the ASF dual-hosted git repository.
suvasude pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-gobblin.git
The following commit(s) were added to refs/heads/master by this push:
new 73a2a1c [GOBBLIN-1295] Provide escape for each character of '"' where hive doesn't do it properly
73a2a1c is described below
commit 73a2a1c945918a6a606b1c467fcac099d40a0f7e
Author: Lei Sun <au...@gmail.com>
AuthorDate: Tue Oct 20 14:27:57 2020 -0700
[GOBBLIN-1295] Provide escape for each character of '"' where hive doesn't do it properly
Replacement of replaceAll() by replace() to avoid
confusion in terms of the number of slashes
Closes #3133 from autumnust/escapeToMakeUpForHive
---
.../src/main/java/org/apache/gobblin/util/AvroUtils.java | 3 ++-
.../test/java/org/apache/gobblin/util/AvroUtilsTest.java | 13 +++++++++++++
2 files changed, 15 insertions(+), 1 deletion(-)
diff --git a/gobblin-utility/src/main/java/org/apache/gobblin/util/AvroUtils.java b/gobblin-utility/src/main/java/org/apache/gobblin/util/AvroUtils.java
index 65d3279..cd72883 100644
--- a/gobblin-utility/src/main/java/org/apache/gobblin/util/AvroUtils.java
+++ b/gobblin-utility/src/main/java/org/apache/gobblin/util/AvroUtils.java
@@ -891,7 +891,8 @@ public class AvroUtils {
* Therefore the escaping behavior won't cause correctness issues.
*/
public static String sanitizeSchemaString(String schemaString) {
- return schemaString.replaceAll(";", "\\\\;").replaceAll("'", "\\\\'");
+ return schemaString.replace("\\\"", "\\\\\\\"").replace(";", "\\;")
+ .replace("'", "\\'");
}
/**
diff --git a/gobblin-utility/src/test/java/org/apache/gobblin/util/AvroUtilsTest.java b/gobblin-utility/src/test/java/org/apache/gobblin/util/AvroUtilsTest.java
index e7a8c35..991be36 100644
--- a/gobblin-utility/src/test/java/org/apache/gobblin/util/AvroUtilsTest.java
+++ b/gobblin-utility/src/test/java/org/apache/gobblin/util/AvroUtilsTest.java
@@ -272,6 +272,19 @@ public class AvroUtilsTest {
Assert.assertEquals(actualString, expectedString);
// Verify that there's only one slash being added.
Assert.assertEquals(actualString.length(), invalidString.length() + 2);
+
+ // An instance of invalid string that contains a slash followed by a quote, both of which should be escaped.
+ String invalidStringWithSlash = "abc\\\"";
+ // Should have a slash before the actual slash, and a slash before the actual quote.
+ actualString = AvroUtils.sanitizeSchemaString(invalidStringWithSlash);
+ // Meaning for each slash:
+ // first two: escape in java and the actual escape the output string
+ // second pair: escape in java and the actual slash
+ // third pair: escape for the actual quote
+ // last pair: java escape slash with the actual quote.
+ expectedString = "abc\\\\\\\"";
+ Assert.assertEquals(actualString, expectedString);
+ Assert.assertEquals(actualString.length(), invalidStringWithSlash.length() + 2);
}
public static List<GenericRecord> getRecordFromFile(String path)