Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor: Remove some clone in TypeCoercion #10203

Merged
merged 3 commits into from
Apr 24, 2024

Conversation

alamb
Copy link
Contributor

@alamb alamb commented Apr 23, 2024

Which issue does this PR close?

Part of #9637

Rationale for this change

While working on #10039 I saw a few copies that could be avoided that are independent of the larger refactor (which is proving trickier than I had hoped)

What changes are included in this PR?

  1. Remove some unnecessary clones in ExprRewriter (these are pretty minor in the grand scheme of things)

Are these changes tested?

Existing CI

Are there any user-facing changes?

@github-actions github-actions bot added the optimizer Optimizer rules label Apr 23, 2024
}

/// Returns `expressions` coerced to types compatible with
/// `signature`, if possible.
///
/// See the module level documentation for more detail on coercion.
fn coerce_arguments_for_signature(
expressions: &[Expr],
expressions: Vec<Expr>,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will stop all the arguments to function calls being copied, which seems good

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I always thought having less possible coercible type is preferred 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure what you mean

Perhaps you are referring to preferring &[Expr] over &Vec<Expr>? If so the difference here is that the Vec was owned (and thus we don't have to copy the contents via to_vec())

.into_iter()
.map(|expr| {
let data_type = expr.get_type(schema).unwrap();
if let DataType::FixedSizeList(field, _) = data_type {
let field = field.as_ref().clone();
let to_type = DataType::List(Arc::new(field));
let to_type = DataType::List(field.clone());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FieldRef is an Arc<Field> -- so this clone is just an Arc::clone (rather than copying the entire filed)

}

/// Cast `expr` to the specified type, if possible
fn cast_expr(expr: &Expr, to_type: &DataType, schema: &DFSchema) -> Result<Expr> {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function just wrapped Expr::cast_to in an API that forced a clone, so I removed it

@alamb alamb marked this pull request as ready for review April 23, 2024 19:41
Copy link
Contributor

@jayzhan211 jayzhan211 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@Dandandan Dandandan merged commit deebda7 into apache:main Apr 24, 2024
23 checks passed
@Dandandan
Copy link
Contributor

Thank you @alamb

@alamb alamb deleted the alamb/chipping_away branch April 24, 2024 10:50
ccciudatu pushed a commit to hstack/arrow-datafusion that referenced this pull request Apr 26, 2024
* Remove some clone in TypeCoercion

* Less clone

* less copy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
optimizer Optimizer rules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants