-
Notifications
You must be signed in to change notification settings - Fork 1.1k
fix(bigquery-jdbc): Add escape character support for pattern matching #13259
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -243,6 +243,17 @@ public void testCompileSqlLikePattern() { | |
| assertNotNull(bracketPattern); | ||
| assertTrue(bracketPattern.matcher("array[0]").matches()); | ||
| assertFalse(bracketPattern.matcher("array_0_").matches()); | ||
|
|
||
| // Escaped wildcards | ||
| Pattern escapedUnderscore = dbMetadata.compileSqlLikePattern("test\\_table"); | ||
| assertNotNull(escapedUnderscore); | ||
| assertTrue(escapedUnderscore.matcher("test_table").matches()); | ||
| assertFalse(escapedUnderscore.matcher("test1table").matches()); | ||
|
|
||
| Pattern escapedPercent = dbMetadata.compileSqlLikePattern("100\\%discount"); | ||
| assertNotNull(escapedPercent); | ||
| assertTrue(escapedPercent.matcher("100%discount").matches()); | ||
| assertFalse(escapedPercent.matcher("100PERCENTdiscount").matches()); | ||
|
Comment on lines
+255
to
+256
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider adding test cases for an escaped escape character (e.g., assertTrue(escapedPercent.matcher("100%discount").matches());
assertFalse(escapedPercent.matcher("100PERCENTdiscount").matches());
// Escaped escape character
Pattern escapedBackslash = dbMetadata.compileSqlLikePattern("test\\\\table");
assertTrue(escapedBackslash.matcher("test\\table").matches());
// Trailing escape character
Pattern trailingBackslash = dbMetadata.compileSqlLikePattern("test\\");
assertTrue(trailingBackslash.matcher("test\\").matches());References
|
||
| } | ||
|
|
||
| @Test | ||
|
|
||
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.
The current implementation ignores a trailing backslash if it is the last character in the
sqlLikePattern. Previously, a trailing backslash was treated as a literal character and escaped in the resulting regex. To maintain backward compatibility and handle this edge case, the code should check if theescapedflag is still true after the loop and append the escaped backslash to the regex.