Skip to content

fix NamedStructField should be rewritten in OperatorToFunction in subquery regression (change ApplyFunctionRewrites to use TreeNode API #10032

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

Merged
merged 4 commits into from
Apr 12, 2024

Conversation

alamb
Copy link
Contributor

@alamb alamb commented Apr 10, 2024

Which issue does this PR close?

Closes #10029

Rationale for this change

  1. Fix a regression

What changes are included in this PR?

  1. Properly recurse into subqueries that are embedded in expressions using the TreeNodeRewriter API
  2. As a bonus avoids a bunch of copies

Are these changes tested?

Yes with new tests

Are there any user-facing changes?

Fix regression

@github-actions github-actions bot added optimizer Optimizer rules sqllogictest SQL Logic Tests (.slt) labels Apr 10, 2024
@alamb alamb marked this pull request as ready for review April 10, 2024 16:15
Copy link
Contributor Author

@alamb alamb left a comment

Choose a reason for hiding this comment

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

@wiedld and I found this while upgrading IOx.

The code in this PR fixes the regression, but I think it could be substantially shorter (and do less copying) by using the TreeNode APIs.

I will work on that later today hopefully

@alamb alamb changed the title fix NamedStructField should be rewritten in OperatorToFunction in subquery fix NamedStructField should be rewritten in OperatorToFunction in subquery regression Apr 10, 2024
@alamb
Copy link
Contributor Author

alamb commented Apr 10, 2024

I reworked this PR to use the TreeNode API in a546e69 and I am quite happy with how it looks now

};
let name_preserver = NamePreserver::new(&plan);

plan.map_expressions(|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.

using the new map_expressions API it is quite straightforward to rewrite these expressions (and it doesn't copy them!)


plan.with_new_exprs(new_expr, new_inputs)
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 copies the plan + expressions

@alamb alamb changed the title fix NamedStructField should be rewritten in OperatorToFunction in subquery regression fix NamedStructField should be rewritten in OperatorToFunction in subquery regression (change ApplyFunctionRewrites to use TreeNode API Apr 11, 2024
@alamb
Copy link
Contributor Author

alamb commented Apr 12, 2024

Thanks for the review @crepererum and for the help tracking this down @wiedld

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
optimizer Optimizer rules sqllogictest SQL Logic Tests (.slt)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Regression: Error in NamedStructField should be rewritten in OperatorToFunction with subquery
2 participants