-
Notifications
You must be signed in to change notification settings - Fork 28.5k
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-30625][SQL] Support escape
as third parameter of the like
function
#27355
Conversation
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.
Ur, actually, I expected a smaller change.
Actually I did bigger change but reverted my refactoring in |
Test build #117356 has finished for PR 27355 at commit
|
override def inputTypes: Seq[DataType] = Seq(StringType, StringType, StringType) | ||
override def children: Seq[Expression] = Seq(str, pattern, escape) | ||
|
||
private lazy val escapeChar: Char = if (escape.foldable) { |
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 need lazy
here? I personally think its better to check error conditions as soon as possible.
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.
When I remove lazy
, I get the exception:
makeCopy, tree: str#13580 LIKE pattern#13581 ESCAPE '@'
org.apache.spark.sql.catalyst.errors.package$TreeNodeException: makeCopy, tree: str#13580 LIKE pattern#13581 ESCAPE '@'
at org.apache.spark.sql.catalyst.errors.package$.attachTree(package.scala:56)
at org.apache.spark.sql.catalyst.trees.TreeNode.makeCopy(TreeNode.scala:435)
at org.apache.spark.sql.catalyst.trees.TreeNode.mapChildren(TreeNode.scala:408)
...
Caused by: org.apache.spark.sql.AnalysisException: The 'escape' parameter must be a string literal.;
at org.apache.spark.sql.catalyst.expressions.Like.<init>(regexpExpressions.scala:135)
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.
I got the error when I run new test in DataFrameFunctionsSuite
, and I remember I got the error on other tests as well. PrettyAttribute is not foldable.
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.
Ur, ok. Thanks for the check. The current one looks ok to me.
s"The 'escape' parameter must be a string literal of one char but it is $s.") | ||
} | ||
} else { | ||
throw new AnalysisException("The 'escape' parameter must be 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.
Can you add tests for this path and line 131 (error 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.
Added
The refactoring still looks fine to me. |
Test build #117428 has finished for PR 27355 at commit
|
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.
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.
Sorry for posting this review post-hoc, but I strongly believe this PR should be reverted for now, and re-land after redesign. There are both design and implementation issues with this PR:
Seq(("abc", "%bc", "/")).toDF("s", "p", "esc").selectExpr("like(s, p, esc)").explain(true) and on a freshly built Apache Spark master, you'll get:
It doesn't look like supporting full-blown EDIT: to make my comment clear: I do think it's reasonable to allow the builtin In order to support a 3-arg version of |
Which systems support this syntax? |
Thank you for pointing that, @rednaxelafx . |
According to the above comment, @MaxGekk is trying to revert this first from 3.0.0 and will target 3.1.0 later. |
s"The 'escape' parameter must be a string literal of one char but it is $s.") | ||
} | ||
} else { | ||
throw new AnalysisException("The 'escape' parameter must be 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.
This kind of thing should be done in checkInputDataTypes
.
… `like` function ### What changes were proposed in this pull request? In the PR, I propose to revert the commit 8aebc80. ### Why are the changes needed? See the concerns #27355 (comment) ### Does this PR introduce any user-facing change? No ### How was this patch tested? By existing test suites. Closes #27531 from MaxGekk/revert-like-3-args. Authored-by: Maxim Gekk <max.gekk@gmail.com> Signed-off-by: Dongjoon Hyun <dhyun@apple.com>
… `like` function In the PR, I propose to revert the commit 8aebc80. See the concerns #27355 (comment) No By existing test suites. Closes #27531 from MaxGekk/revert-like-3-args. Authored-by: Maxim Gekk <max.gekk@gmail.com> Signed-off-by: Dongjoon Hyun <dhyun@apple.com>
… `like` function ### What changes were proposed in this pull request? In the PR, I propose to revert the commit 8aebc80. ### Why are the changes needed? See the concerns apache#27355 (comment) ### Does this PR introduce any user-facing change? No ### How was this patch tested? By existing test suites. Closes apache#27531 from MaxGekk/revert-like-3-args. Authored-by: Maxim Gekk <max.gekk@gmail.com> Signed-off-by: Dongjoon Hyun <dhyun@apple.com>
What changes were proposed in this pull request?
In the PR, I propose to transform the
Like
expression toTernaryExpression
, and add third parameterescape
. So, thelike
function will have feature parity withLIKE ... ESCAPE
syntax supported by 187f3c1.Why are the changes needed?
The
like
functions can be called with 2 or 3 parameters, and functionally equivalent toLIKE
andLIKE ... ESCAPE
SQL expressions.Does this PR introduce any user-facing change?
Yes, before
like
fails with the exception:After:
How was this patch tested?
like
function which is checked bySQLQuerySuite
RegexpExpressionsSuite
andExpressionParserSuite
.