Skip to content

Commit 4fe34db

Browse files
authored
Merge pull request #33948 SnowflakeIO: be consistent with backslash escape char.
2 parents 15346bb + 9e0ce6d commit 4fe34db

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

sdks/java/io/snowflake/src/main/java/org/apache/beam/sdk/io/snowflake/SnowflakeIO.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1176,7 +1176,10 @@ public void processElement(ProcessContext context) {
11761176
for (Object o : context.element()) {
11771177
if (o instanceof String) {
11781178
String field = (String) o;
1179-
field = field.replace("'", "''");
1179+
field = field.replace("\\", "\\\\");
1180+
if (!this.quotationMark.isEmpty()) {
1181+
field = field.replace(this.quotationMark, "\\" + this.quotationMark);
1182+
}
11801183
field = quoteNonEmptyField(field);
11811184

11821185
csvItems.add(field);

sdks/java/io/snowflake/src/test/java/org/apache/beam/sdk/io/snowflake/test/unit/write/SnowflakeIOWriteTest.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ public void writeToExternalWithDoubleQuotation() throws SnowflakeSQLException {
208208
List<String> actualData = FakeSnowflakeDatabase.getElements(FAKE_TABLE);
209209
List<String> escapedTestData =
210210
testDataInStrings.stream()
211-
.map(e -> e.replace("'", "''"))
211+
.map(e -> e.replace("\"", "\\\""))
212212
.map(e -> e.isEmpty() ? "" : String.format("\"%s\"", e))
213213
.collect(Collectors.toList());
214214
assertTrue(TestUtils.areListsEqual(escapedTestData, actualData));
@@ -233,8 +233,7 @@ public void writeToExternalWithBlankQuotation() throws SnowflakeSQLException {
233233

234234
List<String> actualData = FakeSnowflakeDatabase.getElements(FAKE_TABLE);
235235

236-
List<String> escapedTestData =
237-
testDataInStrings.stream().map(e -> e.replace("'", "''")).collect(Collectors.toList());
238-
assertTrue(TestUtils.areListsEqual(escapedTestData, actualData));
236+
// no escape for blank quotation
237+
assertTrue(TestUtils.areListsEqual(testDataInStrings, actualData));
239238
}
240239
}

0 commit comments

Comments
 (0)