New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added a fix for BQ connector to correctly treat single quote in query criteria #7869
Conversation
Thank you for your pull request and welcome to our community. We could not parse the GitHub identity of the following contributors: Ayush Bilala.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for sending a PR.
It'd be nice to also handle other possible cases. It can be part of a follow-up if needed.
Please also change the commit message to describe the fix instead of referencing a GitHub issue. You can comment in the PR description as Fixes #7784
instead.
@@ -179,7 +179,7 @@ private static ZonedDateTime toZonedDateTime(long millisUtc, ZoneId zoneId) | |||
static String stringToStringConverter(Object value) | |||
{ | |||
Slice slice = (Slice) value; | |||
return quote(slice.toStringUtf8()); | |||
return quote(slice.toStringUtf8().replace("'", "\\'")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'd be nice to handle all possible characters that need escaping.
If possible can you also add support for the ones listed at https://cloud.google.com/bigquery/docs/reference/standard-sql/lexical#string_and_bytes_literals along with test-cases?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, let me take a look and figure out what does it actually take to add escaping for all possible characters.
If it is too much effort, I'll probably take it up as a follow-up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hashhar Adding support for other literals doesn't look straightforward. Is it fine if we go ahead with this one and I'll do some more research and raise a separate issue for other characters?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please create an issue with your findings and add a TODO comment here so that we don't forget.
cc: @ebyhr
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I am on it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Created an issue for adding support for all characters #7900.
Added a TODO comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for fixing this. Understood remained patterns will be handled in #7900.
Left only minor comments. Please squash commits into one and update the commit title as
Escape single quote in BigQuery string condition
.../trino-bigquery/src/test/java/io/trino/plugin/bigquery/TestBigQueryIntegrationSmokeTest.java
Outdated
Show resolved
Hide resolved
.../trino-bigquery/src/test/java/io/trino/plugin/bigquery/TestBigQueryIntegrationSmokeTest.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ayushbilala Please squash the commits and amend commit message as suggested by @ebyhr in #7869 (review).
@ebyhr I've verified TestBigQueryIntegrationSmokeTest passes.
Merged, thanks! |
Fix for #7784.
Added a change to properly rewrite filter values containing the ANSI SQL single quote Escape sequence into the one that BigQuery is happy with.
Example:
'Looney''s Lane' string in Presto query filter will be changed to 'Looney\'s Lane' in order to make the query work.