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

refactor(interactive): Support Nested Branch Logical Plan #3151

Merged
merged 23 commits into from
Sep 5, 2023

Conversation

MeloYang05
Copy link
Collaborator

What do these changes do?

In the previous implementation, a branch node in the GIE logical plan was required to correspond to exactly one merge node. However, it is common to encounter nested branch plans in real-world scenarios, where a branch node may correspond to multiple merge nodes at different levels.

For example:
root(1)
/ |
2 3 4
\ / /
5 /
\ /
6

To support these situations, this pull request updates the implementation of get_branch_plans, sub_plans, get_merge_node, and other related methods. As a result, the logical plan can theoretically accommodate arbitrary branches, as long as they are reasonable.

BingqingLyu and others added 12 commits July 28, 2023 11:13
Committed-by: bingqing.lbq from Dev container
Committed-by: bingqing.lbq from Dev container
1. Fix the bug of multiple pattern matching
2. Add more test cases for pattern matching
1. Edit testcases
2. Fix some bugs
3. Now the new multiple match implementation with dummy source can pass all the tests in the rust side
1. Update clean redundant methods. Now it will firstly remove all the redundant scan nodes, and then check the redundant dummy root node
2. It will ensure remove a redundant dummy root nodes which followed by another several of redundant scan nodes
1. Edit methods of get subplans and get branch plans, now it can support nested branch plans
2. Introduce a new Branch Logical Operator for helping handle branches
1. Fix bugs in `get_merge_node` and `get_branch_node` method when facing more comlicated logical plan, now it will uses more strict condition for final merge/first branch checking
2. Fix a bug in `append_branch_plan`, when branch plan having a node with id already exist in the original plan, now it will not cover the existing node, but it will now merge the children of the two nodes. It solves the problem in finding subplans that two branch nodes overlap
3. Add more test cases to validate the new `subplan` and `get_branch_plans` method
1. Add 6 types logical plans for testing
1.1 Verify the correctness `get_merge_node`, `get_branch_node`, `subplan`, `get_branch_plans` with these logical plans
1.2 Verify whether these logical plan can converted to expected physical plan
1.3 Verify whether the query based on these logical plans can generate expected results

2. Use flow algorithm in `get_merge_node` and `get_branch_node`, greatly improve the efficiency
2.1 Implement a Fraction abstraction for the precision during flow comparison

3. Solve a problem in `append_branch_plans`, now it supports to append branch plans which having nodes alreading existing in the original plan

4. Completely rewrite the logic of `get_merge_node`, `get_branch_node`, `subplan`, `get_branch_plans
4.1 Now it in theory can support arbitrary DAG logical plan as long as it is reasonable

5. Solve a problem in `extract_subplans`, now the last node of a subplan can be a merge node

6. Make the code much safer that now it will check the existence of merge node subplans much more strictly
6.1 Remove `expect`, instead throws None or Error

7. Add more comments which suggests the logic for handling nested branches
@MeloYang05 MeloYang05 self-assigned this Aug 28, 2023
@MeloYang05 MeloYang05 changed the title feat(interactive): Support Nested Branch Logical Plan refactor(interactive): Support Nested Branch Logical Plan Aug 28, 2023
@codecov-commenter
Copy link

codecov-commenter commented Aug 28, 2023

Codecov Report

Merging #3151 (b5ab11c) into main (698f5c3) will not change coverage.
Report is 1 commits behind head on main.
The diff coverage is n/a.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #3151   +/-   ##
=======================================
  Coverage   42.05%   42.05%           
=======================================
  Files         101      101           
  Lines       10985    10985           
=======================================
  Hits         4620     4620           
  Misses       6365     6365           

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 698f5c3...b5ab11c. Read the comment docs.

This commit edit constructors for LogicalPlan:

Previous Constructor -> Current Constructor

1.LogicalPlan::with_root() -> LogicalPlan::with_node(), to distringuish from the pb::Root operator

2.LogicalPlan::default() -> LogicalPlan::with_root(), the LogicalPlan is initialized with a pb::Root Node

3.LogicalPlan::empty() -> LogicalPlan::default(), the LogicalPlan is initialized as empty
longbinlai
longbinlai previously approved these changes Aug 29, 2023
Copy link
Collaborator

@longbinlai longbinlai left a comment

Choose a reason for hiding this comment

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

LGTM

}
}

impl Add for Fraction {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Fraction and GCD, using some rust package.

Copy link
Collaborator

@longbinlai longbinlai left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Collaborator

@BingqingLyu BingqingLyu left a comment

Choose a reason for hiding this comment

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

LGTM

@longbinlai longbinlai merged commit d3515e8 into alibaba:main Sep 5, 2023
28 checks passed
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.

4 participants