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/10/01 00:04:09 UTC
[GitHub] [arrow-datafusion] HaoYang670 commented on a diff in pull request #3669: Simplification Rules for Modulo Operator
HaoYang670 commented on code in PR #3669:
URL: https://github.com/apache/arrow-datafusion/pull/3669#discussion_r985007946
##########
datafusion/optimizer/src/simplify_expressions.rs:
##########
@@ -790,6 +791,43 @@ impl<'a, S: SimplifyInfo> ExprRewriter for Simplifier<'a, S> {
right,
} if !info.nullable(&left)? && left == right => lit(1),
+ //
+ // Rules for Modulo
+ //
+
+ // A % null --> null
+ BinaryExpr {
+ left: _,
+ op: Modulo,
+ right,
+ } if is_null(&right) => *right,
+ // null % A --> null
+ BinaryExpr {
+ left,
+ op: Modulo,
+ right: _,
+ } if is_null(&left) => *left,
+ // A % 1 --> 0
+ BinaryExpr {
+ left,
+ op: Modulo,
+ right,
+ } if !info.nullable(&left)? && is_one(&right) => lit(0),
+ // A % A --> 0
+ BinaryExpr {
+ left,
+ op: Modulo,
+ right,
+ } if !info.nullable(&left)? && left == right => lit(0),
Review Comment:
I prefer removing `A % A` because `A` might contain `0` and `0 % 0 = 0` is wrong
--
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