You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2020/12/07 08:04:54 UTC

[GitHub] [spark] cloud-fan commented on a change in pull request #30625: [SPARK-33677][SQL] Skip LikeSimplification rule if pattern contains any escapeChar

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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org