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

Improve & unify validation in LogicalPlan::with_new_exprs #12264

Conversation

findepi
Copy link
Member

@findepi findepi commented Aug 30, 2024

When adding new plan node type, LogicalPlan::with_new_exprs needs to
be updated. Different code branches apply different inputs validation
style (no validation, just assert, or assert with messages), so it's
unclear which code pattern to follow. This commit unifies the
validation and adds it to the branches where there was none.

@github-actions github-actions bot added the logical-expr Logical plan and expressions label Aug 30, 2024
@findepi findepi force-pushed the findepi/improve-unify-validation-in-logicalplan-with-new-exprs-903b47 branch from b5efaab to 97e8e2f Compare August 30, 2024 15:17
When adding new plan node type, `LogicalPlan::with_new_exprs` needs to
be updated. Different code branches apply different inputs validation
style (no validation, just assert, or assert with messages), so it's
unclear which code pattern to follow.  This commit unifies the
validation and adds it to the branches where there was none.
@findepi findepi force-pushed the findepi/improve-unify-validation-in-logicalplan-with-new-exprs-903b47 branch from 97e8e2f to e4c5a92 Compare August 30, 2024 19:13
@findepi
Copy link
Member Author

findepi commented Sep 1, 2024

@comphead would you like to take a look?

);
}

fn only_expr(&self, mut expr: Vec<Expr>) -> Expr {
Copy link
Contributor

Choose a reason for hiding this comment

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

I doubt whether this is helpful, a little over abstraction IMO 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

i had this initially inline but then the check code would take more space, and it was making it harder to see the important part of the logic (obviously this is subjective)
another subjective bonus is there is type system help -- i cannot check there are no expressions or that there is only one expression and still use expressions vector to pull something later from it.

if you would prefer to have these functions inlined back, just let me know, happy to do so

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we could add some comments explaining the rationale as a way to make the reason for the extra abstraction clear

Copy link
Member Author

Choose a reason for hiding this comment

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

done!

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.

Thanks @findepi it does make sense for me to unify assertions, we probably should not doing assertions itself but return Result from check* methods. And make them better naming like assert instead of check. It would be more intuitive.

Removing swap_remove feels ok, it was an performance issue long time ago rust-lang/rust#52150

We can probably also set #[inline] hit to this methods and check the planner benchmark if we dont have any perf drop

Copy link
Contributor

@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.

Thank you @findepi @comphead and @jayzhan211

I think this PR is an improvement as it makes the assumptions about inputs explicit., and since it doesn't change the API for users it is good to me

I do think it would be worth considering @comphead 's suggestion for returning an internal error rather than a panic (what happens when assert fails) but I also think we could do that as a follow on PR or never

);
}

fn only_expr(&self, mut expr: Vec<Expr>) -> Expr {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we could add some comments explaining the rationale as a way to make the reason for the extra abstraction clear

@findepi
Copy link
Member Author

findepi commented Sep 4, 2024

thanks @comphead @alamb for the feedback!

I do think it would be worth considering @comphead 's suggestion for returning an internal error rather than a panic (what happens when assert fails) but I also think we could do that as a follow on PR or never

@alamb i applied this suggestion locally already, just pushed out

@alamb alamb merged commit ab1e3e2 into apache:main Sep 5, 2024
24 checks passed
@alamb
Copy link
Contributor

alamb commented Sep 5, 2024

Thanks again @comphead @jayzhan211 and @findepi

@findepi findepi deleted the findepi/improve-unify-validation-in-logicalplan-with-new-exprs-903b47 branch September 6, 2024 18:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
logical-expr Logical plan and expressions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants