-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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 clones and unnecessary Arcs in from_substrait_rex
#11337
Conversation
7745ce8
to
f2ea105
Compare
if new_name != name { | ||
exprs.push(x.as_ref().clone().alias(new_name.clone())); | ||
exprs.push(x.alias(new_name.clone())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because the code returned Arc<Expr>
previously, but most places in Expr
need either Expr
or Box<Expr>
the code ended up copying the expressions unnecessarily
@@ -1069,9 +1065,7 @@ pub async fn from_substrait_rex( | |||
input_schema, | |||
extensions, | |||
) | |||
.await? | |||
.as_ref() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these clones are entirely uncessary
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, that’s just better in every way, thanks!
@@ -411,11 +411,11 @@ pub async fn from_substrait_rel( | |||
from_substrait_rex(ctx, e, input.clone().schema(), extensions) | |||
.await?; | |||
// if the expression is WindowFunction, wrap in a Window relation | |||
if let Expr::WindowFunction(_) = x.as_ref() { | |||
if let Expr::WindowFunction(_) = &x { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hoped clippy can find things like this 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For some reason, to convert an Arc<T>
to &T
you can't just do
let my_ref = &my_arc;
Rust seems to require you to do
let my_ref = my_arc.as_ref();
I don't really know the nuances as to why.
After this change, x
is no longer an Arc<Expr>
it is only an Expr
which Rust is happier to auto-reference
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm thanks @alamb
Which issue does this PR close?
Closes #.
Rationale for this change
While reviewing #11329 from @Blizzara I was confused about the use of
Arc<Expr>
: #11329 (comment)I looked into it more deeply and I found we can remove the
Arc
and a bunch ofclone
infrom_substrait_rex
This not only makes the code simpler, it is also more efficient.
What changes are included in this PR?
Return
Result<Expr>
rather thanResult<Arc<Expr>>
when creating DataFusion structures from substrait REX, and avoid unecessary copies theArc
was requiringAre these changes tested?
Existing CI
Are there any user-facing changes?