-
Notifications
You must be signed in to change notification settings - Fork 29.3k
[SPARK-24865] Remove AnalysisBarrier #21822
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
Closed
Closed
Changes from 8 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
f6f2bcc
[SPARK-24865] Remove AnalysisBarrier
rxin 8ccafca
Minimize change
rxin 0afa7ea
Fix bug
rxin 738e99c
More bug fixes
rxin 83ffa51
more fixes
rxin 7c76c83
bypass EliminateSubqueryAliases
rxin 14ac09c
Added BooleanSimplification back
rxin 38980ad
revert mistake
rxin abfd0a8
Switch to use thread local to make things go faster.
rxin 75fb114
Test cases
rxin f2f1a97
Remove one TODO
rxin e7d3f53
Merge remote-tracking branch 'upstream/master' into SPARK-24865-xiao
gatorsmile 7995272
add a dummy fix
gatorsmile fe52801
Merge pull request #22 from gatorsmile/SPARK-24865-xiao
rxin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
117 changes: 50 additions & 67 deletions
117
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,8 +23,24 @@ import org.apache.spark.sql.catalyst.analysis._ | |
| import org.apache.spark.sql.catalyst.expressions._ | ||
| import org.apache.spark.sql.catalyst.plans.QueryPlan | ||
| import org.apache.spark.sql.catalyst.plans.logical.statsEstimation.LogicalPlanStats | ||
| import org.apache.spark.sql.catalyst.trees.CurrentOrigin | ||
| import org.apache.spark.sql.catalyst.trees.{CurrentOrigin, TreeNode} | ||
| import org.apache.spark.sql.types.StructType | ||
| import org.apache.spark.util.Utils | ||
|
|
||
|
|
||
| object LogicalPlan { | ||
|
|
||
| private val resolveOperatorDepth = new ThreadLocal[Int] { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. todo: explain what this is |
||
| override def initialValue(): Int = 0 | ||
| } | ||
|
|
||
| def allowInvokingTransformsInAnalyzer[T](f: => T): T = { | ||
| resolveOperatorDepth.set(resolveOperatorDepth.get + 1) | ||
| try f finally { | ||
| resolveOperatorDepth.set(resolveOperatorDepth.get - 1) | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
| abstract class LogicalPlan | ||
|
|
@@ -33,6 +49,116 @@ abstract class LogicalPlan | |
| with QueryPlanConstraints | ||
| with Logging { | ||
|
|
||
| private var _analyzed: Boolean = false | ||
|
|
||
| /** | ||
| * Marks this plan as already analyzed. This should only be called by [[CheckAnalysis]]. | ||
| */ | ||
| private[catalyst] def setAnalyzed(): Unit = { _analyzed = true } | ||
|
|
||
| /** | ||
| * Returns true if this node and its children have already been gone through analysis and | ||
| * verification. Note that this is only an optimization used to avoid analyzing trees that | ||
| * have already been analyzed, and can be reset by transformations. | ||
| */ | ||
| def analyzed: Boolean = _analyzed | ||
|
|
||
| /** | ||
| * Returns a copy of this node where `rule` has been recursively applied first to all of its | ||
| * children and then itself (post-order, bottom-up). When `rule` does not apply to a given node, | ||
| * it is left unchanged. This function is similar to `transformUp`, but skips sub-trees that | ||
| * have already been marked as analyzed. | ||
| * | ||
| * @param rule the function use to transform this nodes children | ||
| */ | ||
| def resolveOperators(rule: PartialFunction[LogicalPlan, LogicalPlan]): LogicalPlan = { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. todo: add unit tests |
||
| if (!analyzed) { | ||
| LogicalPlan.allowInvokingTransformsInAnalyzer { | ||
| val afterRuleOnChildren = mapChildren(_.resolveOperators(rule)) | ||
| if (this fastEquals afterRuleOnChildren) { | ||
| CurrentOrigin.withOrigin(origin) { | ||
| rule.applyOrElse(this, identity[LogicalPlan]) | ||
| } | ||
| } else { | ||
| CurrentOrigin.withOrigin(origin) { | ||
| rule.applyOrElse(afterRuleOnChildren, identity[LogicalPlan]) | ||
| } | ||
| } | ||
| } | ||
| } else { | ||
| this | ||
| } | ||
| } | ||
|
|
||
| /** Similar to [[resolveOperators]], but does it top-down. */ | ||
| def resolveOperatorsDown(rule: PartialFunction[LogicalPlan, LogicalPlan]): LogicalPlan = { | ||
| if (!analyzed) { | ||
| LogicalPlan.allowInvokingTransformsInAnalyzer { | ||
| val afterRule = CurrentOrigin.withOrigin(origin) { | ||
| rule.applyOrElse(this, identity[LogicalPlan]) | ||
| } | ||
|
|
||
| // Check if unchanged and then possibly return old copy to avoid gc churn. | ||
| if (this fastEquals afterRule) { | ||
| mapChildren(_.resolveOperatorsDown(rule)) | ||
| } else { | ||
| afterRule.mapChildren(_.resolveOperatorsDown(rule)) | ||
| } | ||
| } | ||
| } else { | ||
| this | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Recursively transforms the expressions of a tree, skipping nodes that have already | ||
| * been analyzed. | ||
| */ | ||
| def resolveExpressions(r: PartialFunction[Expression, Expression]): LogicalPlan = { | ||
| this resolveOperators { | ||
| case p => p.transformExpressions(r) | ||
| } | ||
| } | ||
|
|
||
| protected def assertNotAnalysisRule(): Unit = { | ||
| if (Utils.isTesting && LogicalPlan.resolveOperatorDepth.get == 0) { | ||
| if (Thread.currentThread.getStackTrace.exists(_.getClassName.contains("Analyzer"))) { | ||
| val e = new RuntimeException("This method should not be called in the analyzer") | ||
| e.printStackTrace() | ||
| throw e | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * In analyzer, use [[resolveOperatorsDown()]] instead. If this is used in the analyzer, | ||
| * an exception will be thrown in test mode. It is however OK to call this function within | ||
| * the scope of a [[resolveOperatorsDown()]] call. | ||
| * @see [[TreeNode.transformDown()]]. | ||
| */ | ||
| override def transformDown(rule: PartialFunction[LogicalPlan, LogicalPlan]): LogicalPlan = { | ||
| assertNotAnalysisRule() | ||
| super.transformDown(rule) | ||
| } | ||
|
|
||
| /** | ||
| * Use [[resolveOperators()]] in the analyzer. | ||
| * @see [[TreeNode.transformUp()]] | ||
| */ | ||
| override def transformUp(rule: PartialFunction[LogicalPlan, LogicalPlan]): LogicalPlan = { | ||
| assertNotAnalysisRule() | ||
| super.transformUp(rule) | ||
| } | ||
|
|
||
| /** | ||
| * Use [[resolveExpressions()]] in the analyzer. | ||
| * @see [[QueryPlan.transformAllExpressions()]] | ||
| */ | ||
| override def transformAllExpressions(rule: PartialFunction[Expression, Expression]): this.type = { | ||
| assertNotAnalysisRule() | ||
| super.transformAllExpressions(rule) | ||
| } | ||
|
|
||
| /** Returns true if this subtree has data from a streaming data source. */ | ||
| def isStreaming: Boolean = children.exists(_.isStreaming == true) | ||
|
|
||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
im using a weird wrapping here to minimize the diff.