BigQuery dialect should escape backslashes in string literals#5094
BigQuery dialect should escape backslashes in string literals#5094Samin061 wants to merge 1 commit into
Conversation
|
| .withBigQuery().ok(expectedBigQuery); | ||
| } | ||
|
|
||
| /** Tests that a backslash in a character literal is escaped for BigQuery, |
There was a problem hiding this comment.
Please refer to other PRs: first create a relevant Jira ticket describing the background of the issue, and then update the commit message and the PR details accordingly.
There was a problem hiding this comment.
@xuzifu666 I think the policy is that very small fixes don't require a JIRA issue
There was a problem hiding this 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.
| + "FROM \"foodmart\".\"product\""; | ||
| final String expectedBigQuery = "SELECT 'a\\\\b'\n" | ||
| + "FROM foodmart.product"; | ||
| sql(query) |
There was a problem hiding this comment.
I assume you have validated the resulting query using BigQuery?
There was a problem hiding this 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.



Jira Link
No Jira filed yet; happy to open one if preferred. This is a small escaping fix in the SQL generator.
Changes Proposed
BigQuerySqlDialectdeclares its escaped quote as\', but the basequoteStringLiteralonly replaces the quote character, so a literal backslash in a string value reaches BigQuery unescaped. BigQuery treats backslash as an escape character inside string literals, so a pushed-down value such asx\or\'; ...closes the literal early and the trailing characters are parsed as SQL rather than data. OverridequoteStringLiteralto double backslashes before the base method escapes the enclosing quote, so backslash-containing values round-trip as data. Added a rel2sql regression test next totestCharLiteralForBigQuery.