Samin061 commented on code in PR #5094:
URL: https://github.com/apache/calcite/pull/5094#discussion_r3568188384


##########
core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java:
##########
@@ -3905,6 +3905,20 @@ private SqlDialect nonOrdinalDialect() {
         .withBigQuery().ok(expectedBigQuery);
   }
 
+  /** Tests that a backslash in a character literal is escaped for BigQuery,
+   * which uses backslash as the escape character. Without doubling the
+   * backslash the generated literal is terminated early. */
+  @Test void testCharLiteralWithBackslashForBigQuery() {
+    final String query = "select 'a\\b' from \"product\"";
+    final String expectedPostgresql = "SELECT 'a\\b'\n"
+        + "FROM \"foodmart\".\"product\"";
+    final String expectedBigQuery = "SELECT 'a\\\\b'\n"
+        + "FROM foodmart.product";
+    sql(query)

Review Comment:
   Yeah. BigQuery treats backslash as the escape character in string literals, 
so an unescaped `\b` reads as a backspace and a trailing `\` closes the literal 
early. Doubling the backslash before the base method escapes the enclosing 
quote makes the value round-trip as data. I checked the generated output 
against BigQuery's documented string-literal escaping rules; the rel2sql tests 
here are string comparisons so it isn't run against a live instance, but I can 
capture it against a real dataset if you'd like that on record.



##########
core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java:
##########
@@ -3905,6 +3905,20 @@ private SqlDialect nonOrdinalDialect() {
         .withBigQuery().ok(expectedBigQuery);
   }
 
+  /** Tests that a backslash in a character literal is escaped for BigQuery,

Review Comment:
   Per @mihaibudiu's note I'll skip the JIRA since this is a small escaping 
fix. Happy to file one and update the commit message if you'd rather have it 
tracked.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to