haohuaijin opened a new pull request, #7909:
URL: https://github.com/apache/arrow-datafusion/pull/7909

   ## Which issue does this PR close?
   
   <!--
   We generally require a GitHub issue to be filed for all bug fixes and 
enhancements and this helps us generate change logs for our releases. You can 
link an issue to this PR using the GitHub syntax. For example `Closes #123` 
indicates that this PR will close issue #123.
   -->
   
   related to #7876 
   
   ## Rationale for this change
   
   As @jonahgao said, 
   
   > Pushing `random` through the projection can also cause problems.
   > If it can be fixed, then `random` will not be pushed further through the 
aggregatation in this case.
   
   Previously, projection pushed down all predicates. Now, projection pushes 
down predicates that do not contain volatile functions or contain volatile 
functions but are not included in projection.
   
   For example,
   ```sql
   SELECT t.c1, t.r FROM (SELECT c1, random() AS r FROM test GROUP BY c1) as t 
WHERE t.r > 0.5 AND random() > 0.8 AND t.c1 > 5;
   ```
   initial logical plan
   ```
   
+------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------+
   | initial_logical_plan                                       | Projection: 
t.c1, t.r                                                                       
                              |
   |                                                            |   Filter: t.r 
> Float64(0.5) AND random() > Float64(0.8) AND t.c1 > Int64(5)                  
                            |
   |                                                            |     
SubqueryAlias: t                                                                
                                      |
   |                                                            |       
Projection: test.csv.c1, random() AS r                                          
                                    |
   |                                                            |         
Aggregate: groupBy=[[test.csv.c1]], aggr=[[]]                                   
                                  |
   |                                                            |           
TableScan: test.csv       
   ```
   
   before this pr
   ```
   | logical_plan  | SubqueryAlias: t                                           
                                                                                
                      |
   |               |   Projection: aggregate_test_100.c1, random() AS r         
                                                                                
                      |
   |               |     Aggregate: groupBy=[[aggregate_test_100.c1]], 
aggr=[[]]                                                                       
                               |
   |               |       Projection: aggregate_test_100.c1                    
                                                                                
                      |
   |               |         Filter: random() > Float64(0.5) AND random() > 
Float64(0.8) AND aggregate_test_100.c1 > Utf8("5")                              
                          |
   |               |           Projection: random(), aggregate_test_100.c1      
                                                                                
                      |
   |               |             TableScan: aggregate_test_100 projection=[c1], 
partial_filters=[random() > Float64(0.5), random() > Float64(0.8), 
aggregate_test_100.c1 > Utf8("5")] |
   ```
   
   after this pr
   ```
   | logical_plan  | SubqueryAlias: t                                           
                                                                                
           |
   |               |   Filter: r > Float64(0.5)                                 
                                                                                
           |
   |               |     Projection: aggregate_test_100.c1, random() AS r       
                                                                                
           |
   |               |       Aggregate: groupBy=[[aggregate_test_100.c1]], 
aggr=[[]]                                                                       
                  |
   |               |         Filter: random() > Float64(0.8) AND 
aggregate_test_100.c1 > Utf8("5")                                               
                          |
   |               |           TableScan: aggregate_test_100 projection=[c1], 
partial_filters=[random() > Float64(0.8), aggregate_test_100.c1 > Utf8("5")] 
   ```
   
   ## What changes are included in this PR?
   
   <!--
   There is no need to duplicate the description in the issue here but it is 
sometimes worth providing a summary of the individual changes in this PR.
   -->
   modify `push_down_filter` to support only push down  predicates that do not 
contain volatile functions or contain volatile functions but are not included 
in projection.
   
   ## Are these changes tested?
   
   <!--
   We typically require tests for all PRs in order to:
   1. Prevent the code from being accidentally broken by subsequent changes
   2. Serve as another way to document the expected behavior of the code
   
   If tests are not included in your PR, please explain why (for example, are 
they covered by existing tests)?
   -->
   Yes, if need, I can add more.
   ## Are there any user-facing changes?
   
   <!--
   If there are user-facing changes then we may require documentation to be 
updated before approving the PR.
   -->
   
   <!--
   If there are any breaking changes to public APIs, please add the `api 
change` label.
   -->


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

To unsubscribe, e-mail: github-unsubscr...@arrow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to