Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 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 @@ -185,6 +185,9 @@ abstract class Optimizer(catalogManager: CatalogManager)
RemoveLiteralFromGroupExpressions,
RemoveRepetitionFromGroupExpressions) :: Nil ++
operatorOptimizationBatch) :+
// This batch rewrites plans and should be run after the operator
// optimization batch and before any batches that depend on stats.
Batch("Rewrite Rules", Once, rewriteRules: _*) :+
Copy link
Member

Choose a reason for hiding this comment

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

Basically, every optimizer rule is rewriting the plans, isn't it?

Copy link
Member

Choose a reason for hiding this comment

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

Hmm, same question. This naming looks too general.

Copy link
Contributor Author

@aokolnychyi aokolnychyi Dec 1, 2020

Choose a reason for hiding this comment

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

Well, you are right after removing v2Source from the name is it a bit too abstract. Any suggestions, @dongjoon-hyun @viirya ? I am not sure making it specific to v2 sources is a good idea too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I decided to call it dataSourceRewriteRules as this seems to be generic enough but yet describes what it is.

Copy link
Member

Choose a reason for hiding this comment

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

Looks better. Thanks for the change.

// This batch pushes filters and projections into scan nodes. Before this batch, the logical
// plan may contain nodes that do not report stats. Anything that uses stats must run after
// this batch.
Expand Down Expand Up @@ -289,6 +292,12 @@ abstract class Optimizer(catalogManager: CatalogManager)
*/
def earlyScanPushDownRules: Seq[Rule[LogicalPlan]] = Nil

/**
* Override to provide additional rules for rewriting plans. Such rules will be executed
* after operator optimization rules and before any rules that depend on stats.
*/
def rewriteRules: Seq[Rule[LogicalPlan]] = Nil

/**
* Returns (defaultBatches - (excludedRules - nonExcludableRules)), the rule batches that
* eventually run in the Optimizer.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,9 @@ abstract class BaseSessionStateBuilder(
override def earlyScanPushDownRules: Seq[Rule[LogicalPlan]] =
super.earlyScanPushDownRules ++ customEarlyScanPushDownRules

override def rewriteRules: Seq[Rule[LogicalPlan]] =
super.rewriteRules ++ customRewriteRules

override def extendedOperatorOptimizationRules: Seq[Rule[LogicalPlan]] =
super.extendedOperatorOptimizationRules ++ customOperatorOptimizationRules
}
Expand All @@ -263,6 +266,14 @@ abstract class BaseSessionStateBuilder(
*/
protected def customEarlyScanPushDownRules: Seq[Rule[LogicalPlan]] = Nil

/**
* Custom rules for rewriting plans to add to the Optimizer. Prefer overriding this instead
* of creating your own Optimizer.
*
* Note that this may NOT depend on the `optimizer` function.
*/
protected def customRewriteRules: Seq[Rule[LogicalPlan]] = Nil

/**
* Planner that converts optimized logical plans to physical plans.
*
Expand Down