Github user marmbrus commented on a diff in the pull request:

    https://github.com/apache/spark/pull/1325#discussion_r14633377
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala
 ---
    @@ -112,6 +113,23 @@ object ColumnPruning extends Rule[LogicalPlan] {
     }
     
     /**
    + * Simplifies LIKE expressions that do not need full regular expressions 
to evaluate the condition.
    + * For example, when the expression is just checking to see if a string 
starts with a given
    + * pattern.
    + */
    +object LikeSimplification extends Rule[LogicalPlan] {
    +  val startsWith = "([^_%]+)%".r
    +  val endsWith = "%([^_%]+)".r
    +  val contains = "%([^_%]+)%".r
    +
    +  def apply(plan: LogicalPlan): LogicalPlan = plan transformAllExpressions 
{
    +    case Like(l, Literal(startsWith(pattern), StringType)) => 
StartsWith(l, Literal(pattern))
    --- End diff --
    
    I'll also note that this is not meant to be exaustive, but only cover some 
common cases that we can speed up 10x
    
    Hive does the same thing: 
https://github.com/apache/hive/blob/590c37f075def63e8507f2bfca820308b40e78b3/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/FilterStringColLikeStringScalar.java#L64


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to