kosiew commented on code in PR #26989:
URL: https://github.com/apache/datafusion/pull/26989#discussion_r4628390248
##########
datafusion/expr-common/src/casts.rs:
##########
@@ -391,6 +476,121 @@ fn exact_preimage_int_to_str_eq_like(
}
}
+/// Computes the source-domain preimage of a `Date32` to timezone-naive
timestamp
Review Comment:
Could we document the retained overflow policy and add a SQL regression for
out-of-range Date32/Date64 casts? Rewritten comparisons can return Booleans
where CAST errors or TRY_CAST returns NULL.
##########
datafusion/expr-common/src/casts.rs:
##########
@@ -128,6 +129,26 @@ pub fn cast_predicate_preimage(
));
}
+ if let Some((source, target)) = date32_to_timestamp_types(source_type,
target_type) {
Review Comment:
Optional cleanup: consider sharing the timestamp, Date32, and Date64
preimage dispatch between both callers. Keep the family-specific arithmetic
separate.
##########
datafusion/sqllogictest/test_files/simplify_expr.slt:
##########
@@ -1099,3 +1099,132 @@ drop table cast_preimage_tz;
statement ok
drop table cast_preimage_tz_ms;
+
+# Date32 -> timestamp: midnight literals unwrap to a date comparison.
+statement ok
+CREATE TABLE cast_preimage_date32 AS
+SELECT id, arrow_cast(v, 'Date32') AS d
+FROM (VALUES (1, -2), (2, -1), (3, 0), (4, 1), (5, 2), (6, NULL)) AS t(id, v);
+
+query TT
+EXPLAIN SELECT * FROM cast_preimage_date32
+WHERE CAST(d AS TIMESTAMP(0)) = arrow_cast(-86400, 'Timestamp(s)');
+----
+logical_plan
+01)Filter: cast_preimage_date32.d = Date32("1969-12-31")
+02)--TableScan: cast_preimage_date32 projection=[id, d]
+physical_plan
+01)FilterExec: d@1 = 1969-12-31
+02)--DataSourceExec: partitions=1, partition_sizes=[1]
+
+# A non-midnight literal rounds up to the next day, including before the epoch.
+query TT
+EXPLAIN SELECT * FROM cast_preimage_date32
+WHERE TIMESTAMP '1969-12-31 23:59:59.999999999' < d;
+----
+logical_plan
+01)Filter: cast_preimage_date32.d >= Date32("1970-01-01")
+02)--TableScan: cast_preimage_date32 projection=[id, d]
+physical_plan
+01)FilterExec: d@1 >= 1970-01-01
+02)--DataSourceExec: partitions=1, partition_sizes=[1]
+
+# IN lists use the exact-preimage path rather than the comparison range path.
+query TT
Review Comment:
Could we add an IN membership result check? IDs 2 and 4 should be true, 1,
3, and 5 false, and 6 NULL. The plan alone cannot verify NULL semantics.
--
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]