You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/07/04 15:03:51 UTC

[GitHub] [arrow-datafusion] liukun4515 opened a new pull request, #2834: InList: set/list value must be evaluated to get the values

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

   
   
   # 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.
   -->
   
   Closes #2820 
   
    # Rationale for this change
   <!--
    Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
    Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.  
   -->
   
   # 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.
   -->
   
   # 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-unsubscribe@arrow.apache.org

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


[GitHub] [arrow-datafusion] alamb commented on a diff in pull request #2834: InList: set/list value must be evaluated to get the values

Posted by GitBox <gi...@apache.org>.
alamb commented on code in PR #2834:
URL: https://github.com/apache/arrow-datafusion/pull/2834#discussion_r914024066


##########
datafusion/physical-expr/src/expressions/in_list.rs:
##########
@@ -270,37 +270,51 @@ fn not_in_list_utf8<OffsetSize: OffsetSizeTrait>(
 }
 
 //check all filter values of In clause are static.
-//include `CastExpr + Literal` or `Literal`
+//include `TryCastExpr/CastExpr + Literal` or `Literal`
 fn check_all_static_filter_expr(list: &[Arc<dyn PhysicalExpr>]) -> bool {
+    // TODO optimize the checker for constant in datafusion

Review Comment:
   I think `ColumnarValue` is one such interface
   
   https://github.com/apache/arrow-datafusion/blob/41b4e491663029f653e491b110d0b5e74d08a0b6/datafusion/expr/src/columnar_value.rs#L29-L34
   
   So if you call `evaluate()` on a `Literal` `PhysicalExpr` the returned value is `ColumnarValue::Scalar`:
   
   https://github.com/apache/arrow-datafusion/blob/master/datafusion/physical-expr/src/expressions/literal.rs#L72



##########
datafusion/physical-expr/src/expressions/in_list.rs:
##########
@@ -270,37 +270,51 @@ fn not_in_list_utf8<OffsetSize: OffsetSizeTrait>(
 }
 
 //check all filter values of In clause are static.
-//include `CastExpr + Literal` or `Literal`
+//include `TryCastExpr/CastExpr + Literal` or `Literal`
 fn check_all_static_filter_expr(list: &[Arc<dyn PhysicalExpr>]) -> bool {
+    // TODO optimize the checker for constant in datafusion

Review Comment:
   One way to make this code more general might be to change the check for all static expressions to *after* `evaluate()` is called. 
   
   Specifically, maybe the  
   
   ```rust
           if list.len() > OPTIMIZER_INSET_THRESHOLD && check_all_static_filter_expr(&list) {
   ```
   
   check could be refactored to call `evaluate` on all the elements of the list and then if all elements were `ColumnarValue::Scalar` and the list was sufficiently larger the set optimization could be invoked 🤔 
   
   



-- 
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-unsubscribe@arrow.apache.org

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


[GitHub] [arrow-datafusion] liukun4515 commented on a diff in pull request #2834: InList: set/list value must be evaluated to get the values

Posted by GitBox <gi...@apache.org>.
liukun4515 commented on code in PR #2834:
URL: https://github.com/apache/arrow-datafusion/pull/2834#discussion_r915391620


##########
datafusion/physical-expr/src/expressions/in_list.rs:
##########
@@ -270,37 +270,27 @@ fn not_in_list_utf8<OffsetSize: OffsetSizeTrait>(
 }
 
 //check all filter values of In clause are static.
-//include `CastExpr + Literal` or `Literal`
-fn check_all_static_filter_expr(list: &[Arc<dyn PhysicalExpr>]) -> bool {
-    list.iter().all(|v| {
-        let cast = v.as_any().downcast_ref::<expressions::CastExpr>();
-        if let Some(c) = cast {
-            c.expr()
-                .as_any()
-                .downcast_ref::<expressions::Literal>()
-                .is_some()
-        } else {
-            let cast = v.as_any().downcast_ref::<expressions::Literal>();
-            cast.is_some()
-        }
+//include `TryCastExpr/CastExpr + Literal` or `Literal`
+fn check_all_static_filter_expr(list: &[Arc<dyn PhysicalExpr>], schema: &Schema) -> bool {
+    let batch = RecordBatch::new_empty(Arc::new(schema.to_owned()));

Review Comment:
   I add a new function `try_cast_static_filter_to_set` to replace these two function in the InLIst.
   



-- 
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-unsubscribe@arrow.apache.org

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


[GitHub] [arrow-datafusion] liukun4515 commented on pull request #2834: InList: set/list value must be evaluated to get the values

Posted by GitBox <gi...@apache.org>.
liukun4515 commented on PR #2834:
URL: https://github.com/apache/arrow-datafusion/pull/2834#issuecomment-1175730534

   > I think this PR is an improvement. Thank you @liukun4515
   > 
   > I left a suggestion on how to maybe make the check more general (aka not have to special case different expression types).
   
   Thanks for you suggestion about `evel const value`.
   I have changed the code according to your suggestion.
   ```
   let batch = RecordBatch::new_empty(Arc::new(schema.to_owned()));
       list.iter().all(|v| match v.evaluate(&batch) {
           Err(_) | Ok(ColumnarValue::Array(_)) => false,
           Ok(ColumnarValue::Scalar(_)) => true,
       })
   ```
   PTAL @alamb 


-- 
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-unsubscribe@arrow.apache.org

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


[GitHub] [arrow-datafusion] alamb commented on a diff in pull request #2834: InList: set/list value must be evaluated to get the values

Posted by GitBox <gi...@apache.org>.
alamb commented on code in PR #2834:
URL: https://github.com/apache/arrow-datafusion/pull/2834#discussion_r914809203


##########
datafusion/physical-expr/src/expressions/in_list.rs:
##########
@@ -270,37 +270,27 @@ fn not_in_list_utf8<OffsetSize: OffsetSizeTrait>(
 }
 
 //check all filter values of In clause are static.
-//include `CastExpr + Literal` or `Literal`
-fn check_all_static_filter_expr(list: &[Arc<dyn PhysicalExpr>]) -> bool {
-    list.iter().all(|v| {
-        let cast = v.as_any().downcast_ref::<expressions::CastExpr>();
-        if let Some(c) = cast {
-            c.expr()
-                .as_any()
-                .downcast_ref::<expressions::Literal>()
-                .is_some()
-        } else {
-            let cast = v.as_any().downcast_ref::<expressions::Literal>();
-            cast.is_some()
-        }
+//include `TryCastExpr/CastExpr + Literal` or `Literal`
+fn check_all_static_filter_expr(list: &[Arc<dyn PhysicalExpr>], schema: &Schema) -> bool {
+    let batch = RecordBatch::new_empty(Arc::new(schema.to_owned()));

Review Comment:
   This is looking better -- but now `evaluate()` will be called *twice* on the inputs; Both here as well as in `cast_static_filter_to_set` . Since calling `evaluate` may be quite expensive, what do you think about calling it once and then passing the resulting `Vec<ColumnarValue>` to both `check_all_static_filter_expr` and `cast_static_filter_to_set`?



-- 
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-unsubscribe@arrow.apache.org

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


[GitHub] [arrow-datafusion] liukun4515 commented on a diff in pull request #2834: InList: set/list value must be evaluated to get the values

Posted by GitBox <gi...@apache.org>.
liukun4515 commented on code in PR #2834:
URL: https://github.com/apache/arrow-datafusion/pull/2834#discussion_r913453698


##########
datafusion/physical-expr/src/expressions/in_list.rs:
##########
@@ -270,37 +270,51 @@ fn not_in_list_utf8<OffsetSize: OffsetSizeTrait>(
 }
 
 //check all filter values of In clause are static.
-//include `CastExpr + Literal` or `Literal`
+//include `TryCastExpr/CastExpr + Literal` or `Literal`
 fn check_all_static_filter_expr(list: &[Arc<dyn PhysicalExpr>]) -> bool {
+    // TODO optimize the checker for constant in datafusion

Review Comment:
   for datafusion, we need to add interface which is used to identify the expr is constant or  literal or not.
   If we have this interface, we can make more optimization.
   But the interface should be better in the logical expr not in the physical expr like sprak `fold`



-- 
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-unsubscribe@arrow.apache.org

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


[GitHub] [arrow-datafusion] liukun4515 commented on pull request #2834: InList: set/list value must be evaluated to get the values

Posted by GitBox <gi...@apache.org>.
liukun4515 commented on PR #2834:
URL: https://github.com/apache/arrow-datafusion/pull/2834#issuecomment-1177021281

   Thanks for your review. @alamb 
   I think it's ready to be merged.


-- 
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-unsubscribe@arrow.apache.org

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


[GitHub] [arrow-datafusion] alamb merged pull request #2834: InList: set/list value must be evaluated to get the values

Posted by GitBox <gi...@apache.org>.
alamb merged PR #2834:
URL: https://github.com/apache/arrow-datafusion/pull/2834


-- 
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-unsubscribe@arrow.apache.org

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


[GitHub] [arrow-datafusion] codecov-commenter commented on pull request #2834: InList: set/list value must be evaluated to get the values

Posted by GitBox <gi...@apache.org>.
codecov-commenter commented on PR #2834:
URL: https://github.com/apache/arrow-datafusion/pull/2834#issuecomment-1174668591

   # [Codecov](https://codecov.io/gh/apache/arrow-datafusion/pull/2834?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
   > Merging [#2834](https://codecov.io/gh/apache/arrow-datafusion/pull/2834?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (2fe8f01) into [master](https://codecov.io/gh/apache/arrow-datafusion/commit/bf7564f62117487a9a397c25326fcda1ed22d08d?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (bf7564f) will **increase** coverage by `0.01%`.
   > The diff coverage is `93.02%`.
   
   ```diff
   @@            Coverage Diff             @@
   ##           master    #2834      +/-   ##
   ==========================================
   + Coverage   85.19%   85.21%   +0.01%     
   ==========================================
     Files         275      275              
     Lines       48761    48790      +29     
   ==========================================
   + Hits        41541    41574      +33     
   + Misses       7220     7216       -4     
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/arrow-datafusion/pull/2834?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
   |---|---|---|
   | [...atafusion/physical-expr/src/expressions/in\_list.rs](https://codecov.io/gh/apache/arrow-datafusion/pull/2834/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZGF0YWZ1c2lvbi9waHlzaWNhbC1leHByL3NyYy9leHByZXNzaW9ucy9pbl9saXN0LnJz) | `82.67% <92.50%> (+0.84%)` | :arrow_up: |
   | [datafusion/core/src/physical\_plan/planner.rs](https://codecov.io/gh/apache/arrow-datafusion/pull/2834/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZGF0YWZ1c2lvbi9jb3JlL3NyYy9waHlzaWNhbF9wbGFuL3BsYW5uZXIucnM=) | `80.98% <100.00%> (ø)` | |
   | [datafusion/physical-expr/src/planner.rs](https://codecov.io/gh/apache/arrow-datafusion/pull/2834/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZGF0YWZ1c2lvbi9waHlzaWNhbC1leHByL3NyYy9wbGFubmVyLnJz) | `92.36% <100.00%> (ø)` | |
   | [datafusion/expr/src/logical\_plan/plan.rs](https://codecov.io/gh/apache/arrow-datafusion/pull/2834/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZGF0YWZ1c2lvbi9leHByL3NyYy9sb2dpY2FsX3BsYW4vcGxhbi5ycw==) | `74.70% <0.00%> (+0.39%)` | :arrow_up: |
   | [...tafusion/physical-expr/src/expressions/try\_cast.rs](https://codecov.io/gh/apache/arrow-datafusion/pull/2834/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZGF0YWZ1c2lvbi9waHlzaWNhbC1leHByL3NyYy9leHByZXNzaW9ucy90cnlfY2FzdC5ycw==) | `99.19% <0.00%> (+0.40%)` | :arrow_up: |
   | [datafusion/physical-expr/src/expressions/cast.rs](https://codecov.io/gh/apache/arrow-datafusion/pull/2834/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZGF0YWZ1c2lvbi9waHlzaWNhbC1leHByL3NyYy9leHByZXNzaW9ucy9jYXN0LnJz) | `98.84% <0.00%> (+0.76%)` | :arrow_up: |
   
   ------
   
   [Continue to review full report at Codecov](https://codecov.io/gh/apache/arrow-datafusion/pull/2834?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
   > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   > `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
   > Powered by [Codecov](https://codecov.io/gh/apache/arrow-datafusion/pull/2834?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Last update [bf7564f...2fe8f01](https://codecov.io/gh/apache/arrow-datafusion/pull/2834?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
   


-- 
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-unsubscribe@arrow.apache.org

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


[GitHub] [arrow-datafusion] alamb commented on a diff in pull request #2834: InList: set/list value must be evaluated to get the values

Posted by GitBox <gi...@apache.org>.
alamb commented on code in PR #2834:
URL: https://github.com/apache/arrow-datafusion/pull/2834#discussion_r915707736


##########
datafusion/physical-expr/src/expressions/in_list.rs:
##########
@@ -379,22 +365,24 @@ impl InListExpr {
         expr: Arc<dyn PhysicalExpr>,
         list: Vec<Arc<dyn PhysicalExpr>>,
         negated: bool,
+        schema: &Schema,
     ) -> Self {
-        if list.len() > OPTIMIZER_INSET_THRESHOLD && check_all_static_filter_expr(&list) {
-            Self {
-                expr,
-                set: Some(InSet::new(cast_static_filter_to_set(&list))),
-                list,
-                negated,
-            }
-        } else {
-            Self {
-                expr,
-                list,
-                negated,
-                set: None,
+        if list.len() > OPTIMIZER_INSET_THRESHOLD {
+            if let Ok(set) = try_cast_static_filter_to_set(&list, schema) {
+                return Self {

Review Comment:
   👍 



-- 
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-unsubscribe@arrow.apache.org

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