Jefffrey commented on code in PR #19563:
URL: https://github.com/apache/datafusion/pull/19563#discussion_r2658730284
##########
datafusion/physical-expr/src/expressions/binary.rs:
##########
@@ -251,6 +340,11 @@ impl PhysicalExpr for BinaryExpr {
match self.op {
Operator::Plus if self.fail_on_overflow => return apply(&lhs,
&rhs, add),
Operator::Plus => return apply(&lhs, &rhs, add_wrapping),
+ // Special case: Date - Date returns Int64 (days difference)
+ // This aligns with PostgreSQL, DuckDB, and MySQL behavior
+ Operator::Minus if is_date_minus_date(&left_data_type,
&right_data_type) => {
Review Comment:
Do we need to take into account overflow config like below?
##########
datafusion/expr-common/src/type_coercion/binary.rs:
##########
@@ -261,6 +261,17 @@ impl<'a> BinaryTypeCoercer<'a> {
})
}
Plus | Minus | Multiply | Divide | Modulo => {
Review Comment:
```suggestion
Minus if is_date_minus_date(lhs, rhs) => {
return Ok(Signature {
lhs: lhs.clone(),
rhs: rhs.clone(),
ret: Int64,
});
}
Plus | Minus | Multiply | Divide | Modulo => {
```
Can move it into a match arm
##########
datafusion/sqllogictest/test_files/datetime/dates.slt:
##########
@@ -94,12 +94,20 @@ caused by
Error during planning: Cannot coerce arithmetic expression Timestamp(ns) +
Utf8 to valid types
-# DATE minus DATE
-# https://github.com/apache/arrow-rs/issues/4383
-query ?
+# DATE minus DATE returns Int64 (days difference)
+# This aligns with PostgreSQL, DuckDB, and MySQL behavior
+# See: https://www.postgresql.org/docs/current/functions-datetime.html
+query I
SELECT DATE '2023-04-09' - DATE '2023-04-02';
----
-7 days 0 hours 0 mins 0 secs
+7
+
+# Verify Date - Date returns Int64 type
+query T
+SELECT arrow_typeof(DATE '2023-04-09' - DATE '2023-04-02');
+----
+Int64
Review Comment:
These tests seem duplicated with what we already have in
`arith_date_date.slt`?
--
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]