Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ object ComputeCurrentTime extends Rule[LogicalPlan] {
treePatternbits.containsPattern(CURRENT_LIKE)
}

plan.transformDownWithSubqueries(transformCondition) {
plan.transformDownWithSubqueriesAndPruning(transformCondition) {
case subQuery =>
subQuery.transformAllExpressionsWithPruning(transformCondition) {
case cd: CurrentDate =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ abstract class QueryPlan[PlanType <: QueryPlan[PlanType]]
* to rewrite the whole plan, include its subqueries, in one go.
*/
def transformWithSubqueries(f: PartialFunction[PlanType, PlanType]): PlanType =
transformDownWithSubqueries(AlwaysProcess.fn, UnknownRuleId)(f)
transformDownWithSubqueries(f)

/**
* Returns a copy of this node where the given partial function has been recursively applied
Expand All @@ -479,18 +479,28 @@ abstract class QueryPlan[PlanType <: QueryPlan[PlanType]]
* first to this node, then this node's subqueries and finally this node's children.
* When the partial function does not apply to a given node, it is left unchanged.
*/
def transformDownWithSubqueries(
cond: TreePatternBits => Boolean = AlwaysProcess.fn, ruleId: RuleId = UnknownRuleId)
(f: PartialFunction[PlanType, PlanType])
: PlanType = {
def transformDownWithSubqueries(f: PartialFunction[PlanType, PlanType]): PlanType = {
transformDownWithSubqueriesAndPruning(AlwaysProcess.fn, UnknownRuleId)(f)
}

/**
* This method is the top-down (pre-order) counterpart of transformUpWithSubqueries.
* Returns a copy of this node where the given partial function has been recursively applied
* first to this node, then this node's subqueries and finally this node's children.
* When the partial function does not apply to a given node, it is left unchanged.
*/
def transformDownWithSubqueriesAndPruning(
Copy link
Member

Choose a reason for hiding this comment

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

I was about to say we shouldn't make these changes for binary compatibility for internal API (e.g., #35378) but reading the codes, it looks more like a refactoring. So LGTM from me 2.

cond: TreePatternBits => Boolean,
ruleId: RuleId = UnknownRuleId)
(f: PartialFunction[PlanType, PlanType]): PlanType = {
val g: PartialFunction[PlanType, PlanType] = new PartialFunction[PlanType, PlanType] {
override def isDefinedAt(x: PlanType): Boolean = true

override def apply(plan: PlanType): PlanType = {
val transformed = f.applyOrElse[PlanType, PlanType](plan, identity)
transformed transformExpressionsDown {
case planExpression: PlanExpression[PlanType] =>
val newPlan = planExpression.plan.transformDownWithSubqueries(cond, ruleId)(f)
val newPlan = planExpression.plan.transformDownWithSubqueriesAndPruning(cond, ruleId)(f)
planExpression.withNewPlan(newPlan)
}
}
Expand Down