GitHub user dongjoon-hyun opened a pull request:

    https://github.com/apache/spark/pull/12312

    [SPARK-14545][SQL] Improve `LikeSimplification` by adding `a%b` rule

    ## What changes were proposed in this pull request?
    
    Current `LikeSimplification` handles the following four rules.
    - 'a%' => expr.StartsWith("a")
    - '%b' => expr.EndsWith("b")
    - '%a%' => expr.Contains("a")
    - 'a' => EqualTo("a")
    
    This PR adds the following rule.
    - 'a%b' => expr.Length() > 2 && expr.StartsWith("a") && expr.EndsWith("b")
    
    Here, 2 is statically calculated from "a".size + "b".size.
    
    **Before**
    ```
    scala> sql("select a from (select explode(array('abc','adc')) a) T where a 
like 'a%c'").explain()
    == Physical Plan ==
    WholeStageCodegen
    :  +- Filter a#5 LIKE a%c
    :     +- INPUT
    +- Generate explode([abc,adc]), false, false, [a#5]
       +- Scan OneRowRelation[]
    ```
    
    **After**
    ```
    scala> sql("select a from (select explode(array('abc','adc')) a) T where a 
like 'a%c'").explain()
    == Physical Plan ==
    WholeStageCodegen
    :  +- Filter ((length(a#5) >= 2) && (StartsWith(a#5, a) && EndsWith(a#5, 
c)))
    :     +- INPUT
    +- Generate explode([abc,adc]), false, false, [a#5]
       +- Scan OneRowRelation[]
    ```
    
    ## How was this patch tested?
    
    Pass the Jenkins tests (including new testcase).


You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/dongjoon-hyun/spark SPARK-14545

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/spark/pull/12312.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #12312
    
----
commit 8d496f63dd3e760a6c165738152afe44a5203fda
Author: Dongjoon Hyun <dongj...@apache.org>
Date:   2016-04-12T00:01:19Z

    [SPARK-14545][SQL] Improve `LikeSimplification` by adding `a%b` rule

----


---
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.
---

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

Reply via email to