jayzhan211 commented on code in PR #27148:
URL: https://github.com/apache/datafusion/pull/27148#discussion_r4576260391
##########
datafusion/physical-expr/src/analysis.rs:
##########
@@ -148,6 +149,9 @@ impl ExprBoundaries {
/// # Returns
///
/// * `AnalysisContext` constructed by pruned boundaries and a selectivity
value.
+/// The selectivity is `None` when the number of values of a column in `expr`
Review Comment:
Optional: `analyze` is public, and it now returns `selectivity: None` for a
predicate on a column without min/max, where it used to return `Some(1.0)`.
Could you add a line about this under "Are there any user-facing changes?", so
downstream callers know to fall back to a default the way `FilterExec` does?
##########
datafusion/expr-common/src/casts.rs:
##########
@@ -987,6 +987,42 @@ fn try_cast_binary(
}
}
+/// Returns true if casting `from` to the decimal type `into` keeps every value
+/// exactly, i.e. `into` has at least as many integer and fractional digits as
+/// `from`. `from` can be an integer, which has no fractional digits, or a
+/// decimal.
+///
+/// Returns false if `into` is not a decimal.
+pub fn is_lossless_decimal_cast(from: &DataType, into: &DataType) -> bool {
Review Comment:
Optional: could you add a unit test for this public helper? Removing the
`!into.is_decimal()` check still passes every test, and without it
`(Decimal128(19, 0), Int64)` returns true even though 9999999999999999999
doesn't fit in an `i64`.
```rust
#[test]
fn test_is_lossless_decimal_cast() {
use DataType::*;
for (from, into, expected) in [
(Int32, Decimal128(10, 0), true),
(Int32, Decimal128(9, 0), false),
(UInt64, Decimal128(20, 0), true),
(Decimal128(15, 2), Decimal128(20, 4), true),
(Decimal128(15, 2), Decimal128(15, 3), false),
(Decimal128(15, 2), Decimal128(15, 1), false),
// `into` must be a decimal:
(Decimal128(19, 0), Int64, false),
(Int64, UInt64, false),
(Decimal128(15, 2), Float64, false),
] {
assert_eq!(is_lossless_decimal_cast(&from, &into), expected, "{from}
-> {into}");
}
}
```
--
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]