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/11/14 06:49:01 UTC

[GitHub] [arrow-datafusion] Jefffrey opened a new pull request, #4200: Add additional expr boolean simplification rules

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

   # 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 #1406.
   
   # 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?
   
   Introduce new boolean simplification rules for expressions:
   
   - `A AND !A` evaluates to `false` given `A` is not nullable
   - `A OR !A` evaluates to `true` given `A` is not nullable
   
   # 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)?
   -->
   
   Added unit tests
   
   # 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 merged pull request #4200: Add additional expr boolean simplification rules

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


-- 
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] ursabot commented on pull request #4200: Add additional expr boolean simplification rules

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

   Benchmark runs are scheduled for baseline = d2814c960168b45c4a0f5d7bbb72d9f412cb08bd and contender = 9de893e54bba2c70782f4e684da70653b9241499. 9de893e54bba2c70782f4e684da70653b9241499 is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
   Conbench compare runs links:
   [Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on ec2-t3-xlarge-us-east-2] [ec2-t3-xlarge-us-east-2](https://conbench.ursa.dev/compare/runs/a303de6e080d43c2a7e8542265c17e23...52b5fb3febe644a58f6deecac7e190a5/)
   [Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on test-mac-arm] [test-mac-arm](https://conbench.ursa.dev/compare/runs/a570f145df2445aea8dcb4ef8bf7e762...ee27c96bf5d94a689c65926b587042ba/)
   [Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on ursa-i9-9960x] [ursa-i9-9960x](https://conbench.ursa.dev/compare/runs/da2cc5ee3a9441fc97e61f364f1d04b3...00befacfa2f9482aa8ccc5ec541990ac/)
   [Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on ursa-thinkcentre-m75q] [ursa-thinkcentre-m75q](https://conbench.ursa.dev/compare/runs/3ae2b5109aa54e18847168cf82631868...7a22d81cd07640a9a9cb10b701472f5f/)
   Buildkite builds:
   Supported benchmarks:
   ec2-t3-xlarge-us-east-2: Supported benchmark langs: Python, R. Runs only benchmarks with cloud = True
   test-mac-arm: Supported benchmark langs: C++, Python, R
   ursa-i9-9960x: Supported benchmark langs: Python, R, JavaScript
   ursa-thinkcentre-m75q: Supported benchmark langs: C++, Java
   


-- 
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 #4200: Add additional expr boolean simplification rules

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


##########
datafusion/optimizer/src/simplify_expressions/expr_simplifier.rs:
##########
@@ -470,6 +470,22 @@ impl<'a, S: SimplifyInfo> ExprRewriter for Simplifier<'a, S> {
                 op: Or,
                 right,
             }) if is_false(&right) => *left,
+            // A OR !A ---> true (if A not nullable)

Review Comment:
   👍  I suspect we would need to add some logic to https://github.com/apache/arrow-datafusion/blob/master/datafusion/optimizer/src/type_coercion.rs



-- 
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] Ted-Jiang commented on a diff in pull request #4200: Add additional expr boolean simplification rules

Posted by GitBox <gi...@apache.org>.
Ted-Jiang commented on code in PR #4200:
URL: https://github.com/apache/arrow-datafusion/pull/4200#discussion_r1021387680


##########
datafusion/optimizer/src/simplify_expressions/expr_simplifier.rs:
##########
@@ -1105,6 +1149,18 @@ mod tests {
         assert_eq!(simplify(expr_b), expected);
     }
 
+    #[test]
+    fn test_simplify_and_not_self() {
+        // A AND !A if A is not nullable --> false
+        // !A AND A if A is not nullable --> false
+        let expr_a = col("c2_non_null").and(col("c2_non_null").not());
+        let expr_b = col("c2_non_null").not().and(col("c2_non_null"));

Review Comment:
   Without this change, these test fail.



-- 
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] Ted-Jiang commented on a diff in pull request #4200: Add additional expr boolean simplification rules

Posted by GitBox <gi...@apache.org>.
Ted-Jiang commented on code in PR #4200:
URL: https://github.com/apache/arrow-datafusion/pull/4200#discussion_r1021374351


##########
datafusion/optimizer/src/simplify_expressions/expr_simplifier.rs:
##########
@@ -470,6 +470,22 @@ impl<'a, S: SimplifyInfo> ExprRewriter for Simplifier<'a, S> {
                 op: Or,
                 right,
             }) if is_false(&right) => *left,
+            // A OR !A ---> true (if A not nullable)

Review Comment:
   Nice!  It's quit complicated deal with `null`.
   in datafsuion:
   ```
   ❯ select true or NULL ;
   Plan("'Boolean OR Null' can't be evaluated because there isn't a common type to coerce the types to")
   ❯ select true or FALSE ;
   +---------------------------------+
   | Boolean(true) OR Boolean(false) |
   +---------------------------------+
   | true                            |
   +---------------------------------+
   1 row in set. Query took 0.003 seconds.
   ❯
   ```
   RUN in spark-sql
   ```
   spark-sql> select true or false;
   true
   Time taken: 3.139 seconds, Fetched 1 row(s)
   spark-sql> select true or NULL;
   true
   Time taken: 0.076 seconds, Fetched 1 row(s)
   spark-sql> select FALSE or NULL;
   NULL
   Time taken: 0.06 seconds, Fetched 1 row(s)
   spark-sql>
   ```
   I think its ok get error when run  `NULL or xxx`



##########
datafusion/optimizer/src/simplify_expressions/expr_simplifier.rs:
##########
@@ -1105,6 +1149,18 @@ mod tests {
         assert_eq!(simplify(expr_b), expected);
     }
 
+    #[test]
+    fn test_simplify_and_not_self() {
+        // A AND !A if A is not nullable --> false
+        // !A AND A if A is not nullable --> false
+        let expr_a = col("c2_non_null").and(col("c2_non_null").not());
+        let expr_b = col("c2_non_null").not().and(col("c2_non_null"));

Review Comment:
   tests win! 👍



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