-
Notifications
You must be signed in to change notification settings - Fork 28.1k
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
[SPARK-30230][SQL] Like ESCAPE syntax can not use '_' and '%' #26860
Conversation
if (Set('%', '_').contains(escapeChar)) { | ||
throw new ParseException("Invalid escape string." + | ||
"Escape string can not be '%', '_'.", ctx) | ||
} |
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.
We cannot avoid this case in the antlr side (SqlBase.g4)?
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.
no, the antlr side just mach a string literal.
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.
You mean like this ?
ESCAPE_STRING
: '\'' ( ~('\''|'\\') | ('\\' .) | ~('%' | '_') )* '\''
| '\'' ( ~('\''|'\\') | ('\\' .) | ~('%' | '_') )* '\''
;
NOT? kind=LIKE pattern=valueExpression (ESCAPE escapeChar=ESCAPE_STRING)?
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.
seems much easier to do at scala side...
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.
with better error message.
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.
Yes, I do agree.
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.
ok.
ok to test |
1 similar comment
ok to test |
add to whitelist |
6f62fff
to
20532d2
Compare
Sorry for a mistake. |
@@ -1393,6 +1393,10 @@ class AstBuilder(conf: SQLConf) extends SqlBaseBaseVisitor[AnyRef] with Logging | |||
} | |||
str.charAt(0) | |||
}.getOrElse('\\') | |||
if (Set('%', '_').contains(escapeChar)) { |
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.
nit: don't use Set
for just 2 elements. We can just do a = % || a = _
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.
Done.
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.
LGTM except for the @cloud-fan comment.
Test build #115224 has finished for PR 26860 at commit
|
Test build #115236 has finished for PR 26860 at commit
|
Thanks, merging to master |
Thanks. |
@ulysses-you @maropu @cloud-fan @gengliangwang |
@beliefer you are right. I run the following in PostgreSQL:
I should not merge it without checking on PostgreSQL. I am going to revert this one. |
Can we check more systems? it does look weird to support % and _ as escape chars. |
If '%' and '_' as escape, how to use the real pattern.
But actually
|
Because '%' is escaped. |
@gengliangwang let's revert this. |
+1 for the revert, thanks for taking care, @gengliangwang ! |
OK, I see. Thanks for reverting. |
What changes were proposed in this pull request?
Since 25001, spark support like escape syntax.
But '%' and '_' is the reserve char in
Like
expression. We can not use them as escape char.Why are the changes needed?
Avoid some unexpect problem when using like escape syntax.
Does this PR introduce any user-facing change?
No.
How was this patch tested?
Add UT.