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 clones and unnecessary Arcs in from_substrait_rex #11337

Merged
merged 2 commits into from
Jul 10, 2024

Conversation

alamb
Copy link
Contributor

@alamb alamb commented Jul 8, 2024

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 of clone in from_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 than Result<Arc<Expr>> when creating DataFusion structures from substrait REX, and avoid unecessary copies the Arc was requiring

Are these changes tested?

Existing CI

Are there any user-facing changes?

@alamb alamb force-pushed the alamb/clean_substrait branch from 7745ce8 to f2ea105 Compare July 8, 2024 18:34
if new_name != name {
exprs.push(x.as_ref().clone().alias(new_name.clone()));
exprs.push(x.alias(new_name.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.

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()
Copy link
Contributor Author

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

Copy link
Contributor

@Blizzara Blizzara left a 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!

@alamb alamb marked this pull request as ready for review July 8, 2024 18:55
@@ -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 {
Copy link
Contributor

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 🤔

Copy link
Contributor Author

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

Copy link
Contributor

@comphead comphead left a comment

Choose a reason for hiding this comment

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

lgtm thanks @alamb

@alamb alamb merged commit 32cb3c5 into apache:main Jul 10, 2024
23 checks passed
@alamb
Copy link
Contributor Author

alamb commented Jul 10, 2024

Thanks again @comphead and @Blizzara -- we are making things better, if sometimes it seems to go slowly

@alamb alamb deleted the alamb/clean_substrait branch July 10, 2024 18:22
Lordworms pushed a commit to Lordworms/arrow-datafusion that referenced this pull request Jul 12, 2024
findepi pushed a commit to findepi/datafusion that referenced this pull request Jul 16, 2024
xinlifoobar pushed a commit to xinlifoobar/datafusion that referenced this pull request Jul 17, 2024
xinlifoobar pushed a commit to xinlifoobar/datafusion that referenced this pull request Jul 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants