Skip to content

Commit df5486c

Browse files
committed
cargo clippy fix
1 parent c7c5d80 commit df5486c

File tree

3 files changed

+23
-30
lines changed

3 files changed

+23
-30
lines changed

datafusion/physical-expr-adapter/src/schema_rewriter.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ impl DefaultPhysicalExprAdapterRewriter {
439439
// TODO: add optimization to move the cast from the column to literal expressions in the case of `col = 123`
440440
// since that's much cheaper to evalaute.
441441
// See https://github.com/apache/datafusion/issues/15780#issuecomment-2824716928
442-
self.create_cast_expr(resolved_column, physical_field, logical_field)
442+
self.create_cast_expr(resolved_column, &physical_field, logical_field)
443443
}
444444

445445
/// Resolves a logical column to the corresponding physical column and field.
@@ -483,7 +483,7 @@ impl DefaultPhysicalExprAdapterRewriter {
483483
fn create_cast_expr(
484484
&self,
485485
column: Column,
486-
physical_field: FieldRef,
486+
physical_field: &FieldRef,
487487
logical_field: &Field,
488488
) -> Result<Transformed<Arc<dyn PhysicalExpr>>> {
489489
// For struct types, use validate_struct_compatibility which handles:
@@ -1597,7 +1597,7 @@ mod tests {
15971597
let transformed = rewriter
15981598
.create_cast_expr(
15991599
Column::new("a", 0),
1600-
Arc::new(physical_schema.field_with_name("a").unwrap().clone()),
1600+
&Arc::new(physical_schema.field_with_name("a").unwrap().clone()),
16011601
logical_schema.field_with_name("a").unwrap(),
16021602
)
16031603
.unwrap();

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

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -341,26 +341,23 @@ pub(crate) fn cast_with_target_field_and_options(
341341
cast_options: Option<CastOptions<'static>>,
342342
) -> Result<Arc<dyn PhysicalExpr>> {
343343
let expr_type = expr.data_type(input_schema)?;
344-
let cast_type = target_field.data_type();
345-
let candidate = CastExpr::new_with_target_field(
346-
Arc::clone(&expr),
347-
Arc::clone(&target_field),
348-
cast_options.clone(),
349-
);
350-
351-
if expr_type == *cast_type
344+
let cast_type = target_field.data_type().clone();
345+
let candidate =
346+
CastExpr::new_with_target_field(Arc::clone(&expr), target_field, cast_options);
347+
348+
if expr_type == cast_type
352349
&& candidate.preserves_child_field_semantics(input_schema)?
353350
{
354-
return Ok(Arc::clone(&expr));
351+
return Ok(expr);
355352
}
356353

357-
let is_valid_cast = match (&expr_type, cast_type) {
354+
let is_valid_cast = match (&expr_type, &cast_type) {
358355
// Allow struct-to-struct casts that pass name-based compatibility validation.
359356
// This validation is applied at planning time (now) to fail fast, rather than
360357
// deferring errors to execution time. The name-based casting logic will be
361358
// executed at runtime via ColumnarValue::cast_to.
362-
(Struct(_), Struct(_)) => can_cast_struct_types(&expr_type, cast_type),
363-
_ => can_cast_types(&expr_type, cast_type),
359+
(Struct(_), Struct(_)) => can_cast_struct_types(&expr_type, &cast_type),
360+
_ => can_cast_types(&expr_type, &cast_type),
364361
};
365362

366363
if !is_valid_cast {
@@ -933,15 +930,12 @@ mod tests {
933930
#[test]
934931
fn field_aware_same_type_cast_preserves_explicit_target_field() -> Result<()> {
935932
let schema = Schema::new(vec![Field::new("a", Int32, false)]);
933+
let a_col = col("a", &schema)?;
934+
let logical_field = Arc::new(Field::new("logical_a", Int32, true).with_metadata(
935+
HashMap::from([("target_meta".to_string(), "1".to_string())]),
936+
));
936937
let expr =
937-
cast_with_target_field_and_options(
938-
col("a", &schema)?,
939-
&schema,
940-
Arc::new(Field::new("logical_a", Int32, true).with_metadata(
941-
HashMap::from([("target_meta".to_string(), "1".to_string())]),
942-
)),
943-
None,
944-
)?;
938+
cast_with_target_field_and_options(a_col, &schema, logical_field, None)?;
945939

946940
let cast_expr = expr
947941
.as_any()
@@ -962,12 +956,10 @@ mod tests {
962956
#[test]
963957
fn default_same_type_cast_is_elided() -> Result<()> {
964958
let schema = Schema::new(vec![Field::new("a", Int32, false)]);
965-
let expr = cast_with_target_field_and_options(
966-
col("a", &schema)?,
967-
&schema,
968-
Int32.into_nullable_field_ref(),
969-
None,
970-
)?;
959+
let a_col = col("a", &schema)?;
960+
let target_field = Int32.into_nullable_field_ref();
961+
let expr =
962+
cast_with_target_field_and_options(a_col, &schema, target_field, None)?;
971963

972964
assert!(expr.as_any().downcast_ref::<Column>().is_some());
973965
assert!(expr.as_any().downcast_ref::<CastExpr>().is_none());

datafusion/physical-expr/src/planner.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,9 @@ pub fn create_physical_expr(
289289
Ok(expressions::case(expr, when_then_expr, else_expr)?)
290290
}
291291
Expr::Cast(Cast { expr, field }) => {
292+
let child = create_physical_expr(expr, input_dfschema, execution_props)?;
292293
expressions::cast_with_target_field_and_options(
293-
create_physical_expr(expr, input_dfschema, execution_props)?,
294+
child,
294295
input_schema,
295296
Arc::clone(field),
296297
None,

0 commit comments

Comments
 (0)