Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
zml1206 committed Jan 6, 2025
1 parent 54e760f commit f6ad45c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ abstract class Optimizer(catalogManager: CatalogManager)
Batch("Finish Analysis", FixedPoint(1), FinishAnalysis),
// We must run this batch after `ReplaceExpressions`, as `RuntimeReplaceable` expression
// may produce `With` expressions that need to be rewritten.
Batch("Rewrite With expression", Once, RewriteWithExpression),
Batch("Rewrite With expression", FixedPoint(1), RewriteWithExpression),
//////////////////////////////////////////////////////////////////////////////////////////
// Optimizer rules start here
//////////////////////////////////////////////////////////////////////////////////////////
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,14 @@ import org.apache.spark.util.Utils
*/
object RewriteWithExpression extends Rule[LogicalPlan] with AliasHelper {
override def apply(plan: LogicalPlan): LogicalPlan = {
if (!plan.containsPattern(WITH_EXPRESSION)) {
return plan
}
var p = plan
while (p.containsPattern(WITH_EXPRESSION)) {
p = applyOnce(p)
p = CollapseProject(applyOnce(p))
}
rewriteAlias(CollapseProject.apply(p))
rewriteAlias(p)
}

// Expensive common expression will be evaluated twice: once in the Filter being pushed down,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ class FilterPushdownSuite extends PlanTest {
PushPredicateThroughNonJoin,
BooleanSimplification,
PushPredicateThroughJoin,
RewriteWithExpression) ::
RewriteWithExpression,
CollapseProject) ::
Batch("Push extra predicate through join", FixedPoint(10),
PushExtraPredicateThroughJoin,
PushDownPredicates,
Expand Down

0 comments on commit f6ad45c

Please sign in to comment.