cloud-fan commented on a change in pull request #30625:
URL: https://github.com/apache/spark/pull/30625#discussion_r537301594
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/expressions.scala
##########
@@ -543,27 +543,27 @@ object LikeSimplification extends Rule[LogicalPlan] {
private val equalTo = "([^_%]*)".r
def apply(plan: LogicalPlan): LogicalPlan = plan transformAllExpressions {
- case Like(input, Literal(pattern, StringType), escapeChar) =>
+ case l @ Like(input, Literal(pattern, StringType), escapeChar) =>
if (pattern == null) {
// If pattern is null, return null value directly, since "col like
null" == null.
Literal(null, BooleanType)
} else {
- val escapeStr = String.valueOf(escapeChar)
pattern.toString match {
- case startsWith(prefix) if !prefix.endsWith(escapeStr) =>
+ case p if p.contains(escapeChar) => l
Review comment:
correct me if I was wrong: we need to make sure this rule doesn't change
result. If the pattern is invalid, `Like` should fail. However, it's expensive
to validate the pattern (need to compile it). Here we use
`p.contains(escapeChar)` as a shortcut to know if the pattern might be invalid.
Can we add some comments to explain it?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]