jayzhan211 commented on code in PR #22906:
URL: https://github.com/apache/datafusion/pull/22906#discussion_r4319612498
##########
datafusion/expr-common/src/casts.rs:
##########
@@ -76,6 +112,501 @@ pub fn try_cast_literal_to_type(
.or_else(|| try_cast_binary(lit_value, target_type))
}
+/// Computes a source-domain preimage for `CAST(source AS target_type) OP
literal`.
+///
+/// This is the shared semantic core for logical and physical cast-predicate
+/// rewrites. It returns an exact same-operator source bound or literal as
+/// [`CastPredicatePreimage::Exact`] where moving the cast preserves comparison
+/// semantics subject to the documented family-level overflow exceptions, and a
+/// [`CastPredicatePreimage::Range`] for many-to-one casts with known preimages
+/// such as timestamp precision narrowing.
+pub fn cast_predicate_preimage(
Review Comment:
The decimal change looks good, thanks for adding the Bloom-filter test. Fine
to do this in a follow-up: every timestamp unit pair can use one interval.
Narrowing takes the truncation bucket and widening takes `[ceil(v/r),
floor(v/r) + 1)`. A singleton becomes `Exact`, an empty interval with
`=`/`!=`/`IN` returns `None`, and anything else becomes `Range`. That replaces
`maybe_range_preimage`, `timestamp_widening_ordered_preimage` and the
round-trip check, and in my local try it removed about 100 non-test lines. The
dispatcher needs to strip one `Dictionary` level first so dictionary-encoded
timestamps keep their rewrites.
```rs
let (lower, upper) = if source_scale > target_scale {
let Some(bucket) = trunc_toward_zero_bucket(value, source_scale /
target_scale) else {
return Ok(None);
};
bucket
} else {
let ratio = target_scale / source_scale;
let floor = value.div_euclid(ratio);
let ceil = floor + i128::from(value.rem_euclid(ratio) != 0);
(ceil, floor + 1)
};
```
--
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]