Skip to content

Commit 28ede8a

Browse files
committed
fix: preserve existing CastExpr public API names
1 parent 664bdb4 commit 28ede8a

3 files changed

Lines changed: 30 additions & 30 deletions

File tree

‎datafusion-examples/examples/custom_data_source/custom_file_casts.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ impl PhysicalExprAdapter for CustomCastsPhysicalExprAdapter {
189189
let input_data_type =
190190
cast.expr().data_type(&self.physical_file_schema)?;
191191
let output_field = cast.target_field();
192-
if !cast.is_lossless_cast(&input_data_type) {
192+
if !cast.is_bigger_cast(&input_data_type) {
193193
return not_impl_err!(
194194
"Unsupported CAST from {input_data_type} to {}",
195195
output_field.data_type()

‎datafusion/physical-expr/src/expressions/cast.rs‎

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ impl CastExpr {
254254
/// conversions such as `Int32` to `Date32`, which interprets the same integer
255255
/// as days since the epoch, or `Int64` to `Date64`, which interprets the same
256256
/// integer as milliseconds since the epoch.
257-
pub fn check_lossless_cast(cast_type: &DataType, src: &DataType) -> bool {
257+
pub fn check_bigger_cast(cast_type: &DataType, src: &DataType) -> bool {
258258
if cast_type.eq(src) {
259259
return true;
260260
}
@@ -278,9 +278,9 @@ impl CastExpr {
278278
}
279279

280280
/// Check if the cast is lossless and strictly order-preserving for all source
281-
/// values, preserving nulls. See [`Self::check_lossless_cast`].
282-
pub fn is_lossless_cast(&self, src: &DataType) -> bool {
283-
Self::check_lossless_cast(self.cast_type(), src)
281+
/// values, preserving nulls. See [`Self::check_bigger_cast`].
282+
pub fn is_bigger_cast(&self, src: &DataType) -> bool {
283+
Self::check_bigger_cast(self.cast_type(), src)
284284
}
285285
}
286286

@@ -299,10 +299,10 @@ pub(crate) fn cast_expr_properties(
299299
) -> Result<ExprProperties> {
300300
let unbounded = Interval::make_unbounded(target_type)?;
301301
let source_type = child.range.data_type();
302-
// A lossless cast recognized by check_lossless_cast is one-to-one, so it is
302+
// A lossless cast recognized by check_bigger_cast is one-to-one, so it is
303303
// strictly order-preserving; a narrowing cast may collapse distinct values,
304304
// breaking the ordering of subsequent sort keys.
305-
let lossless_cast = CastExpr::check_lossless_cast(target_type, &source_type);
305+
let lossless_cast = CastExpr::check_bigger_cast(target_type, &source_type);
306306
if is_order_preserving_cast_family(&source_type, target_type) || lossless_cast {
307307
Ok(child
308308
.clone()
@@ -1543,7 +1543,7 @@ mod tests {
15431543
expected.data_type().clone(),
15441544
None,
15451545
);
1546-
assert!(expr.is_lossless_cast(input.data_type()));
1546+
assert!(expr.is_bigger_cast(input.data_type()));
15471547
let child = ExprProperties::new_unknown()
15481548
.with_range(
15491549
Interval::make_unbounded(input.data_type())
@@ -1614,7 +1614,7 @@ mod tests {
16141614
)]));
16151615
let expr =
16161616
CastExpr::new(col("a", &schema)?, expected.data_type().clone(), None);
1617-
assert!(expr.is_lossless_cast(input.data_type()));
1617+
assert!(expr.is_bigger_cast(input.data_type()));
16181618
for descending in [false, true] {
16191619
for nulls_first in [false, true] {
16201620
let child = ExprProperties::new_unknown()
@@ -1639,7 +1639,7 @@ mod tests {
16391639
(LargeBinary, Binary),
16401640
(BinaryView, Binary),
16411641
] {
1642-
assert!(!CastExpr::check_lossless_cast(&target, &source));
1642+
assert!(!CastExpr::check_bigger_cast(&target, &source));
16431643
}
16441644
Ok(())
16451645
}
@@ -1740,33 +1740,33 @@ mod tests {
17401740
}
17411741

17421742
#[test]
1743-
fn test_check_lossless_cast_precision_loss() {
1743+
fn test_check_bigger_cast_precision_loss() {
17441744
use DataType::*;
17451745

17461746
// Exact conversions without precision loss
1747-
assert!(CastExpr::check_lossless_cast(&Int16, &Int8));
1748-
assert!(CastExpr::check_lossless_cast(&Int64, &Int32));
1749-
assert!(CastExpr::check_lossless_cast(&Float32, &Int16));
1750-
assert!(CastExpr::check_lossless_cast(&Float32, &UInt16));
1751-
assert!(CastExpr::check_lossless_cast(&Float64, &Int32));
1752-
assert!(CastExpr::check_lossless_cast(&Float64, &UInt32));
1753-
assert!(CastExpr::check_lossless_cast(&LargeUtf8, &Utf8));
1747+
assert!(CastExpr::check_bigger_cast(&Int16, &Int8));
1748+
assert!(CastExpr::check_bigger_cast(&Int64, &Int32));
1749+
assert!(CastExpr::check_bigger_cast(&Float32, &Int16));
1750+
assert!(CastExpr::check_bigger_cast(&Float32, &UInt16));
1751+
assert!(CastExpr::check_bigger_cast(&Float64, &Int32));
1752+
assert!(CastExpr::check_bigger_cast(&Float64, &UInt32));
1753+
assert!(CastExpr::check_bigger_cast(&LargeUtf8, &Utf8));
17541754

17551755
// Precision-losing int-to-float conversions should return false
1756-
assert!(!CastExpr::check_lossless_cast(&Float32, &Int32));
1757-
assert!(!CastExpr::check_lossless_cast(&Float32, &UInt32));
1758-
assert!(!CastExpr::check_lossless_cast(&Float64, &Int64));
1759-
assert!(!CastExpr::check_lossless_cast(&Float64, &UInt64));
1756+
assert!(!CastExpr::check_bigger_cast(&Float32, &Int32));
1757+
assert!(!CastExpr::check_bigger_cast(&Float32, &UInt32));
1758+
assert!(!CastExpr::check_bigger_cast(&Float64, &Int64));
1759+
assert!(!CastExpr::check_bigger_cast(&Float64, &UInt64));
17601760

17611761
// Signed-to-unsigned and unsigned-to-signed casts whose target cannot
17621762
// represent the entire source range are not lossless for all values.
1763-
assert!(!CastExpr::check_lossless_cast(&UInt16, &Int8));
1764-
assert!(!CastExpr::check_lossless_cast(&UInt32, &Int16));
1765-
assert!(!CastExpr::check_lossless_cast(&Int8, &UInt8));
1766-
assert!(!CastExpr::check_lossless_cast(&Int16, &UInt16));
1767-
assert!(!CastExpr::check_lossless_cast(&Int32, &UInt32));
1768-
assert!(!CastExpr::check_lossless_cast(&Int64, &UInt64));
1769-
assert!(!CastExpr::check_lossless_cast(&Int8, &UInt16));
1763+
assert!(!CastExpr::check_bigger_cast(&UInt16, &Int8));
1764+
assert!(!CastExpr::check_bigger_cast(&UInt32, &Int16));
1765+
assert!(!CastExpr::check_bigger_cast(&Int8, &UInt8));
1766+
assert!(!CastExpr::check_bigger_cast(&Int16, &UInt16));
1767+
assert!(!CastExpr::check_bigger_cast(&Int32, &UInt32));
1768+
assert!(!CastExpr::check_bigger_cast(&Int64, &UInt64));
1769+
assert!(!CastExpr::check_bigger_cast(&Int8, &UInt16));
17701770
}
17711771
}
17721772

‎datafusion/physical-expr/src/projection.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -890,7 +890,7 @@ fn project_column_statistics_through_expr(
890890
// domain, for example, does not bound the converted column. Merely casting
891891
// a failing endpoint to NULL also cannot establish the remaining extrema.
892892
let preserves_values = source_type.is_some_and(|source_type| {
893-
CastExpr::check_lossless_cast(target_type, &source_type)
893+
CastExpr::check_bigger_cast(target_type, &source_type)
894894
|| is_within_extrema(
895895
&inner_stats.min_value,
896896
&inner_stats.max_value,

0 commit comments

Comments
 (0)