Skip to content

Commit

Permalink
Remove unnecessary clones from .../logical_plan/builder.rs (#12196)
Browse files Browse the repository at this point in the history
  • Loading branch information
findepi authored Aug 27, 2024
1 parent 66bc222 commit 6ffb1f6
Showing 1 changed file with 13 additions and 16 deletions.
29 changes: 13 additions & 16 deletions datafusion/expr/src/logical_plan/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ impl LogicalPlanBuilder {
};
common_type = Some(new_type);
} else {
common_type = Some(data_type.clone());
common_type = Some(data_type);
}
}
field_types.push(common_type.unwrap_or(DataType::Utf8));
Expand All @@ -220,7 +220,7 @@ impl LogicalPlanBuilder {
for row in &mut values {
for (j, field_type) in field_types.iter().enumerate() {
if let Expr::Literal(ScalarValue::Null) = row[j] {
row[j] = Expr::Literal(ScalarValue::try_from(field_type.clone())?);
row[j] = Expr::Literal(ScalarValue::try_from(field_type)?);
} else {
row[j] =
std::mem::take(&mut row[j]).cast_to(field_type, &empty_schema)?;
Expand Down Expand Up @@ -552,20 +552,17 @@ impl LogicalPlanBuilder {

// Collect sort columns that are missing in the input plan's schema
let mut missing_cols: Vec<Column> = vec![];
exprs
.clone()
.into_iter()
.try_for_each::<_, Result<()>>(|expr| {
let columns = expr.column_refs();
exprs.iter().try_for_each::<_, Result<()>>(|expr| {
let columns = expr.column_refs();

columns.into_iter().for_each(|c| {
if !schema.has_column(c) {
missing_cols.push(c.clone());
}
});
columns.into_iter().for_each(|c| {
if !schema.has_column(c) {
missing_cols.push(c.clone());
}
});

Ok(())
})?;
Ok(())
})?;

if missing_cols.is_empty() {
return Ok(Self::new(LogicalPlan::Sort(Sort {
Expand Down Expand Up @@ -710,7 +707,7 @@ impl LogicalPlanBuilder {

pub(crate) fn normalize(
plan: &LogicalPlan,
column: impl Into<Column> + Clone,
column: impl Into<Column>,
) -> Result<Column> {
let schema = plan.schema();
let fallback_schemas = plan.fallback_normalize_schemas();
Expand Down Expand Up @@ -1536,7 +1533,7 @@ pub fn get_unnested_columns(
| DataType::FixedSizeList(field, _)
| DataType::LargeList(field) => {
let new_field = Arc::new(Field::new(
col_name.clone(),
col_name,
field.data_type().clone(),
// Unnesting may produce NULLs even if the list is not null.
// For example: unnset([1], []) -> 1, null
Expand Down

0 comments on commit 6ffb1f6

Please sign in to comment.