Amogh-2404 commented on code in PR #24668:
URL: https://github.com/apache/datafusion/pull/24668#discussion_r3860103220


##########
datafusion/physical-expr/src/expressions/negative.rs:
##########
@@ -78,6 +84,46 @@ impl std::fmt::Display for NegativeExpr {
     }
 }
 
+fn negate_timestamp_array<T: ArrowTimestampType>(array: &dyn Array) -> 
Result<ArrayRef> {
+    let array = array.as_primitive::<T>();
+    let timezone = array.timezone().map(Arc::<str>::from);
+    let result = array.try_unary::<_, T, _>(|value| value.neg_checked())?;
+    Ok(Arc::new(result.with_timezone_opt(timezone)))
+}
+
+fn negate_scalar(scalar: ScalarValue) -> Result<ScalarValue> {
+    Ok(match scalar {
+        ScalarValue::Int8(value) => 
ScalarValue::Int8(value.map(i8::wrapping_neg)),
+        ScalarValue::Int16(value) => 
ScalarValue::Int16(value.map(i16::wrapping_neg)),
+        ScalarValue::Int32(value) => 
ScalarValue::Int32(value.map(i32::wrapping_neg)),
+        ScalarValue::Int64(value) => 
ScalarValue::Int64(value.map(i64::wrapping_neg)),

Review Comment:
   Fixed in `69af50622`. I added a `MIN`-aware guard when pruning inequalities 
through direct signed-integer negation. The normal rewrite remains precise away 
from the wrapping point; scalar `MIN`, input `MIN`, casts, and nested negation 
fall back conservatively. Unit tests cover all four integer widths and 
comparison forms, and the Parquet regression runs all four inequality 
directions with pruning enabled.
   



##########
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 `69af50622`. Double-negation cancellation is now type-aware: signed 
integers, floating-point values, valid decimals, and `NULL` cancel, while 
timestamp and interval negation remains explicit. This restores the full 
ordering equivalence for integer `-(-i)`. The unbounded regression now includes 
the reported two-key fixed-prefix plan and keeps `fetch=1` on 
`StreamingTableExec` without a partial sort.
   



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

Reply via email to