GitHub user ianluyan opened a pull request:

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

    [SPARK-5614][SQL] Predicate pushdown through Generate.

    Now in Catalyst's rules, predicates can not be pushed through "Generate" 
nodes. Further more, partition pruning in HiveTableScan can not be applied on 
those queries involves "Generate". This makes such queries very inefficient. In 
practice, it finds patterns like 
    
    ```scala
    Filter(predicate, Generate(generator, _, _, _, grandChild))
    ```
    
    and splits the predicate into 2 parts by referencing the generated column 
from Generate node or not. And a new Filter will be created for those conjuncts 
can be pushed beneath Generate node. If nothing left for the original Filter, 
it will be removed.
    For example, physical plan for query
    ```sql
    select len, bk
    from s_server lateral view explode(len_arr) len_table as len 
    where len > 5 and day = '20150102';
    ```
    where 'day' is a partition column in metastore is like this in current 
version of Spark SQL:
    
    > Project [len, bk]
    > 
    > Filter ((len > "5") && "(day = "20150102")")
    > 
    > Generate explode(len_arr), true, false
    > 
    > HiveTableScan [bk, len_arr, day], (MetastoreRelation default, s_server, 
None), None
    
    But theoretically the plan should be like this
    
    > Project [len, bk]
    > 
    > Filter (len > "5")
    > 
    > Generate explode(len_arr), true, false
    > 
    > HiveTableScan [bk, len_arr, day], (MetastoreRelation default, s_server, 
None), Some(day = "20150102")
    
    Where partition pruning predicates can be pushed to HiveTableScan nodes.

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

    $ git pull https://github.com/ianluyan/spark ppd

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

    https://github.com/apache/spark/pull/4394.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 #4394
    
----
commit d312f20fb00faeda2f0a207fad75555896102e05
Author: Lu Yan <[email protected]>
Date:   2015-02-05T11:13:39Z

    [SPARK-5614][SQL] Predicate pushdown through Generate.
    
    With this patch, queries involves 'explode' can benefit from predicate 
pushdown, thus partition pruning.

----


---
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 [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to