Skip to content

Conversation

@alamb
Copy link

@alamb alamb commented Aug 8, 2024

Here is a proposed refactor of apache#11683

I found the type signature of this

    ) -> Result<Transformed<(Vec<Vec<Expr>>, FindCommonExprResult)>> {

Where

type FindCommonExprResult = Option<(Vec<(Expr, String)>, Vec<Vec<Expr>>)>;

to be hard to follow

Thus I propose pulling this into an enum so the fields are named

I don't think this changes the logic or performance -- it is solely for readability

We can also merge apache#11683 and consider this proposal separately

@alamb alamb changed the title Alamb/extract to struct Extract result of find_common_exprs into a strucgt Aug 8, 2024
@alamb alamb changed the title Extract result of find_common_exprs into a strucgt Extract result of find_common_exprs into a struct Aug 8, 2024
} => {
build_common_expr_project_plan(input, common_exprs).map(|new_input| {
(new_window_expr_list, new_input, Some(window_expr_list))
(new_exprs_list, new_input, Some(original_exprs_list))
Copy link
Author

Choose a reason for hiding this comment

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

I also renamed the local variables to follow the naming of the fields

config: &dyn OptimizerConfig,
expr_mask: ExprMask,
) -> Result<Transformed<(Vec<Vec<Expr>>, FindCommonExprResult)>> {
) -> Result<Transformed<FoundCommonExprs>> {
Copy link
Author

Choose a reason for hiding this comment

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

The point of the PR is to make this change and the rest of the changes are a consequence of doign so

.map(|new_input| (new_exprs, new_input))
}
None => Ok((new_exprs, input)),
.map_data(|common| match common {
Copy link
Author

Choose a reason for hiding this comment

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

This isn't quite as concise as the previous version but I do think it is more explicit and easier to follow

Copy link
Owner

@peter-toth peter-toth left a comment

Choose a reason for hiding this comment

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

I like this refactor. Indeed this is much easier to follow. Thanks @alamb!

@peter-toth peter-toth merged commit 5fa5457 into peter-toth:make-cse-top-down-like Aug 8, 2024
@alamb alamb deleted the alamb/extract_to_struct branch August 8, 2024 16:57
peter-toth added a commit that referenced this pull request Sep 8, 2024
* Make `CommonSubexprEliminate` top-down like

* fix top-down recursion, fix unit tests to use real a Optimizer to verify behavior on plans

* Extract result of `find_common_exprs` into a struct (#4)

* Extract the result of find_common_exprs into a struct

* Make naming consistent

---------

Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org>
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.

2 participants