Skip to content

Commit cab5d0f

Browse files
authored
Minor: remove clone in exprlist_to_fields (#9657)
* remove clone Signed-off-by: jayzhan211 <[email protected]> * remove lifetime Signed-off-by: jayzhan211 <[email protected]> * fmt Signed-off-by: jayzhan211 <[email protected]> --------- Signed-off-by: jayzhan211 <[email protected]>
1 parent e37ac35 commit cab5d0f

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

datafusion/expr/src/logical_plan/plan.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2031,7 +2031,8 @@ impl Window {
20312031
let fields = input.schema().fields();
20322032
let input_len = fields.len();
20332033
let mut window_fields = fields.clone();
2034-
window_fields.extend_from_slice(&exprlist_to_fields(window_expr.iter(), &input)?);
2034+
let expr_fields = exprlist_to_fields(window_expr.as_slice(), &input)?;
2035+
window_fields.extend_from_slice(expr_fields.as_slice());
20352036
let metadata = input.schema().metadata().clone();
20362037

20372038
// Update functional dependencies for window:
@@ -2357,7 +2358,7 @@ impl DistinctOn {
23572358
let on_expr = normalize_cols(on_expr, input.as_ref())?;
23582359

23592360
let schema = DFSchema::new_with_metadata(
2360-
exprlist_to_fields(&select_expr, &input)?,
2361+
exprlist_to_fields(select_expr.as_slice(), &input)?,
23612362
input.schema().metadata().clone(),
23622363
)?;
23632364

@@ -2436,7 +2437,7 @@ impl Aggregate {
24362437

24372438
let grouping_expr: Vec<Expr> = grouping_set_to_exprlist(group_expr.as_slice())?;
24382439

2439-
let mut fields = exprlist_to_fields(grouping_expr.iter(), &input)?;
2440+
let mut fields = exprlist_to_fields(grouping_expr.as_slice(), &input)?;
24402441

24412442
// Even columns that cannot be null will become nullable when used in a grouping set.
24422443
if is_grouping_set {
@@ -2446,7 +2447,7 @@ impl Aggregate {
24462447
.collect::<Vec<_>>();
24472448
}
24482449

2449-
fields.extend(exprlist_to_fields(aggr_expr.iter(), &input)?);
2450+
fields.extend(exprlist_to_fields(aggr_expr.as_slice(), &input)?);
24502451

24512452
let schema =
24522453
DFSchema::new_with_metadata(fields, input.schema().metadata().clone())?;

datafusion/expr/src/utils.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -753,17 +753,13 @@ fn exprlist_to_fields_aggregate(exprs: &[Expr], agg: &Aggregate) -> Result<Vec<D
753753
}
754754

755755
/// Create field meta-data from an expression, for use in a result set schema
756-
pub fn exprlist_to_fields<'a>(
757-
expr: impl IntoIterator<Item = &'a Expr>,
758-
plan: &LogicalPlan,
759-
) -> Result<Vec<DFField>> {
760-
let exprs: Vec<Expr> = expr.into_iter().cloned().collect();
756+
pub fn exprlist_to_fields(exprs: &[Expr], plan: &LogicalPlan) -> Result<Vec<DFField>> {
761757
// when dealing with aggregate plans we cannot simply look in the aggregate output schema
762758
// because it will contain columns representing complex expressions (such a column named
763759
// `GROUPING(person.state)` so in order to resolve `person.state` in this case we need to
764760
// look at the input to the aggregate instead.
765761
let fields = match plan {
766-
LogicalPlan::Aggregate(agg) => Some(exprlist_to_fields_aggregate(&exprs, agg)),
762+
LogicalPlan::Aggregate(agg) => Some(exprlist_to_fields_aggregate(exprs, agg)),
767763
_ => None,
768764
};
769765
if let Some(fields) = fields {

0 commit comments

Comments
 (0)