Skip to content

BigQuery dialect should escape backslashes in string literals#5094

Open
Samin061 wants to merge 1 commit into
apache:mainfrom
Samin061:bigquery-backslash-escape
Open

BigQuery dialect should escape backslashes in string literals#5094
Samin061 wants to merge 1 commit into
apache:mainfrom
Samin061:bigquery-backslash-escape

Conversation

@Samin061

Copy link
Copy Markdown

Jira Link

No Jira filed yet; happy to open one if preferred. This is a small escaping fix in the SQL generator.

Changes Proposed

BigQuerySqlDialect declares its escaped quote as \', but the base quoteStringLiteral only 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 as x\ or \'; ... closes the literal early and the trailing characters are parsed as SQL rather than data. Override quoteStringLiteral to double backslashes before the base method escapes the enclosing quote, so backslash-containing values round-trip as data. Added a rel2sql regression test next to testCharLiteralForBigQuery.

@sonarqubecloud

Copy link
Copy Markdown

.withBigQuery().ok(expectedBigQuery);
}

/** Tests that a backslash in a character literal is escaped for BigQuery,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xuzifu666 I think the policy is that very small fixes don't require a JIRA issue

+ "FROM \"foodmart\".\"product\"";
final String expectedBigQuery = "SELECT 'a\\\\b'\n"
+ "FROM foodmart.product";
sql(query)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume you have validated the resulting query using BigQuery?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants