-
Notifications
You must be signed in to change notification settings - Fork 28.6k
[SPARK-27747][SQL] add a logical plan link in the physical plan #24626
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
Conversation
cc @pengbo this is a more general approach than #24389 also cc @maryannxue @bogdanrdc @gatorsmile |
@@ -620,4 +620,8 @@ class TreeNodeSuite extends SparkFunSuite with SQLHelper { | |||
assert(planString.startsWith("Truncated plan of")) | |||
} | |||
} | |||
|
|||
test("tags will be carried over after copy") { | |||
|
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
Test build #105456 has finished for PR 24626 at commit
|
|
||
// The exchange related nodes are created after the planning, they don't have corresponding | ||
// logical plan. | ||
case _: ShuffleExchangeExec | _: BroadcastExchangeExec | _: ReusedExchangeExec => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add ReusedSubqueryExec?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added below
@@ -280,9 +297,15 @@ abstract class TreeNode[BaseType <: TreeNode[BaseType]] extends Product { | |||
rule.applyOrElse(this, identity[BaseType]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here after applying the rule
, we need to carry over the tags, if needed, too.
Since carrying the tags in both if and else branches, so maybe:
val newNode = if (this fastEquals afterRuleOnChildren) {
CurrentOrigin.withOrigin(origin) {
rule.applyOrElse(this, identity[BaseType])
}
} else {
CurrentOrigin.withOrigin(origin) {
rule.applyOrElse(afterRuleOnChildren, identity[BaseType])
}
}
// carrying over the tags to newNode...
/** | ||
* A mutable map for holding auxiliary information of this tree node. It will be carried over | ||
* when this node is copied via `makeCopy`. If a user copies the tree node via other ways like the | ||
* `copy` method, it's his responsibility to carry over the tags. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add something like The tags will be kept after transforming, if transformed to the same type, otherwise, will be dropped.
@@ -271,6 +271,8 @@ abstract class QueryPlan[PlanType <: QueryPlan[PlanType]] extends TreeNode[PlanT | |||
} | |||
|
|||
object QueryPlan extends PredicateHelper { | |||
val LOGICAL_PLAN_TAG_NAME = TreeNodeTagName("logical_plan") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add some comment? For example, After query plans go through SQL planner, the planner will attach the optimized logical plan to the generated physical plan under this tag name.
case ReturnAnswer(rootPlan) => rootPlan | ||
case _ => plan | ||
} | ||
p.tags += QueryPlan.LOGICAL_PLAN_TAG_NAME -> logicalPlan |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only the most top physical plan has the link to logical plan, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This pattern is called stackable traits in Scala. When super.plan
is called, its recursive plan
call points to this overridden version.
You can also see from the tests that, not only the root node has the logical plan link.
Test build #105482 has finished for PR 24626 at commit
|
retest this please. |
Test build #105485 has finished for PR 24626 at commit
|
Test build #105497 has finished for PR 24626 at commit
|
After changing to always carry over the tags in transform, it seems that the unit test has to be adjusted as well. I have created a PR cloud-fan#13 if that helps. |
LGTM, pending Jenkins. |
Test build #105548 has finished for PR 24626 at commit
|
Test build #105549 has finished for PR 24626 at commit
|
retest this please. |
retest this please |
Test build #105572 has finished for PR 24626 at commit
|
LGTM Thanks! Merged to master. |
It's pretty useful if we can convert a physical plan back to a logical plan, e.g., in apache#24389 This PR introduces a new feature to `TreeNode`, which allows `TreeNode` to carry some extra information via a mutable map, and keep the information when it's copied. The planner leverages this feature to put the logical plan into the physical plan. a test suite that runs all TPCDS queries and checks that some common physical plans contain the corresponding logical plans. Closes apache#24626 from cloud-fan/link. Lead-authored-by: Wenchen Fan <wenchen@databricks.com> Co-authored-by: Peng Bo <bo.peng1019@gmail.com> Signed-off-by: gatorsmile <gatorsmile@gmail.com>
It's pretty useful if we can convert a physical plan back to a logical plan, e.g., in apache#24389 This PR introduces a new feature to `TreeNode`, which allows `TreeNode` to carry some extra information via a mutable map, and keep the information when it's copied. The planner leverages this feature to put the logical plan into the physical plan. a test suite that runs all TPCDS queries and checks that some common physical plans contain the corresponding logical plans. Closes apache#24626 from cloud-fan/link. Lead-authored-by: Wenchen Fan <wenchen@databricks.com> Co-authored-by: Peng Bo <bo.peng1019@gmail.com> Signed-off-by: gatorsmile <gatorsmile@gmail.com>
What changes were proposed in this pull request?
It's pretty useful if we can convert a physical plan back to a logical plan, e.g., in #24389
This PR introduces a new feature to
TreeNode
, which allowsTreeNode
to carry some extra information via a mutable map, and keep the information when it's copied.The planner leverages this feature to put the logical plan into the physical plan.
How was this patch tested?
a test suite that runs all TPCDS queries and checks that some common physical plans contain the corresponding logical plans.