Skip to content

Commit 40874f9

Browse files
committed
cargo clippy fix
1 parent c7c5d80 commit 40874f9

2 files changed

Lines changed: 21 additions & 23 deletions

File tree

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

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -324,34 +324,36 @@ pub fn cast_with_options(
324324
cast_type: DataType,
325325
cast_options: Option<CastOptions<'static>>,
326326
) -> Result<Arc<dyn PhysicalExpr>> {
327+
// borrow expr and temporary field reference; the helper clones as needed
327328
cast_with_target_field_and_options(
328-
expr,
329+
&expr,
329330
input_schema,
330-
cast_type.into_nullable_field_ref(),
331+
&cast_type.into_nullable_field_ref(),
331332
cast_options,
332333
)
333334
}
334335

335336
/// Return a [`PhysicalExpr`] representing `expr` casted to `target_field`,
336337
/// preserving the field metadata in the resulting expression.
337338
pub(crate) fn cast_with_target_field_and_options(
338-
expr: Arc<dyn PhysicalExpr>,
339+
expr: &Arc<dyn PhysicalExpr>,
339340
input_schema: &Schema,
340-
target_field: FieldRef,
341+
target_field: &FieldRef,
341342
cast_options: Option<CastOptions<'static>>,
342343
) -> Result<Arc<dyn PhysicalExpr>> {
344+
// borrow inputs to satisfy clippy
343345
let expr_type = expr.data_type(input_schema)?;
344346
let cast_type = target_field.data_type();
345347
let candidate = CastExpr::new_with_target_field(
346-
Arc::clone(&expr),
347-
Arc::clone(&target_field),
348+
Arc::clone(expr),
349+
Arc::clone(target_field),
348350
cast_options.clone(),
349351
);
350352

351353
if expr_type == *cast_type
352354
&& candidate.preserves_child_field_semantics(input_schema)?
353355
{
354-
return Ok(Arc::clone(&expr));
356+
return Ok(Arc::clone(expr));
355357
}
356358

357359
let is_valid_cast = match (&expr_type, cast_type) {
@@ -933,15 +935,12 @@ mod tests {
933935
#[test]
934936
fn field_aware_same_type_cast_preserves_explicit_target_field() -> Result<()> {
935937
let schema = Schema::new(vec![Field::new("a", Int32, false)]);
938+
let a_col = col("a", &schema)?;
939+
let logical_field = Arc::new(Field::new("logical_a", Int32, true).with_metadata(
940+
HashMap::from([("target_meta".to_string(), "1".to_string())]),
941+
));
936942
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-
)?;
943+
cast_with_target_field_and_options(&a_col, &schema, &logical_field, None)?;
945944

946945
let cast_expr = expr
947946
.as_any()
@@ -962,12 +961,10 @@ mod tests {
962961
#[test]
963962
fn default_same_type_cast_is_elided() -> Result<()> {
964963
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-
)?;
964+
let a_col = col("a", &schema)?;
965+
let target_field = Int32.into_nullable_field_ref();
966+
let expr =
967+
cast_with_target_field_and_options(&a_col, &schema, &target_field, None)?;
971968

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

datafusion/physical-expr/src/planner.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,10 +289,11 @@ 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,
295-
Arc::clone(field),
296+
&field,
296297
None,
297298
)
298299
}

0 commit comments

Comments
 (0)