Amogh-2404 commented on code in PR #24668:
URL: https://github.com/apache/datafusion/pull/24668#discussion_r3855783926
##########
datafusion/optimizer/src/simplify_expressions/expr_simplifier.rs:
##########
@@ -1411,11 +1339,6 @@ impl TreeNodeRewriter for Simplifier<'_> {
//
Expr::Not(inner) => Transformed::yes(negate_clause(*inner)),
- //
- // Rules for Negative
- //
- Expr::Negative(inner) =>
Transformed::yes(distribute_negation(*inner)),
Review Comment:
Fixed in `4e9d57f3c`. `NegativeExpr` now uses checked negation for timestamp
arrays in seconds, milliseconds, microseconds, and nanoseconds. It preserves
timezone metadata and nulls, and reports overflow for `i64::MIN`. I added unit
coverage for each case and an end-to-end timestamp-column regression.
##########
datafusion/optimizer/src/simplify_expressions/expr_simplifier.rs:
##########
@@ -3115,47 +3038,24 @@ mod tests {
}
#[test]
- fn test_simplify_negated_bitwise_and() {
- // !c3 & c3 --> 0
- let expr = (-col("c3_non_null")) & col("c3_non_null");
- let expected = lit(0i64);
-
- assert_eq!(simplify(expr), expected);
- // c3 & !c3 --> 0
- let expr = col("c3_non_null") & (-col("c3_non_null"));
- let expected = lit(0i64);
-
- assert_eq!(simplify(expr), expected);
- }
-
- #[test]
- fn test_simplify_negated_bitwise_or() {
- // !c3 | c3 --> -1
- let expr = (-col("c3_non_null")) | col("c3_non_null");
- let expected = lit(-1i64);
-
- assert_eq!(simplify(expr), expected);
-
- // c3 | !c3 --> -1
- let expr = col("c3_non_null") | (-col("c3_non_null"));
- let expected = lit(-1i64);
-
- assert_eq!(simplify(expr), expected);
- }
-
- #[test]
- fn test_simplify_negated_bitwise_xor() {
- // !c3 ^ c3 --> -1
- let expr = (-col("c3_non_null")) ^ col("c3_non_null");
- let expected = lit(-1i64);
-
- assert_eq!(simplify(expr), expected);
-
- // c3 ^ !c3 --> -1
- let expr = col("c3_non_null") ^ (-col("c3_non_null"));
- let expected = lit(-1i64);
+ fn test_preserve_arithmetic_negation() {
+ let c3 = col("c3_non_null");
+ let expressions = [
+ (-c3.clone()) & c3.clone(),
+ c3.clone() & (-c3.clone()),
+ (-c3.clone()) | c3.clone(),
+ c3.clone() | (-c3.clone()),
+ (-c3.clone()) ^ c3.clone(),
+ c3.clone() ^ (-c3.clone()),
+ -bitwise_and(col("c3"), c3.clone()),
+ -bitwise_or(col("c3"), c3.clone()),
+ // The inner negation can overflow for the signed minimum.
+ -(-c3),
Review Comment:
Fixed in `4e9d57f3c`. The unparser now parenthesizes a unary minus when its
child is another unary minus or a negative numeric literal. Tests cover direct
expression unparsing and optimized-plan SQL round trips in both pretty modes.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]