-
Notifications
You must be signed in to change notification settings - Fork 28.9k
[SPARK-22932] [SQL] Refactor AnalysisContext #20127
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 all commits
Commits
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
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 |
|---|---|---|
|
|
@@ -52,6 +52,7 @@ object SimpleAnalyzer extends Analyzer( | |
| /** | ||
| * Provides a way to keep state during the analysis, this enables us to decouple the concerns | ||
| * of analysis environment from the catalog. | ||
| * The state that is kept here is per-query. | ||
| * | ||
| * Note this is thread local. | ||
| * | ||
|
|
@@ -70,6 +71,8 @@ object AnalysisContext { | |
| } | ||
|
|
||
| def get: AnalysisContext = value.get() | ||
| def reset(): Unit = value.remove() | ||
|
|
||
| private def set(context: AnalysisContext): Unit = value.set(context) | ||
|
|
||
| def withAnalysisContext[A](database: Option[String])(f: => A): A = { | ||
|
|
@@ -95,6 +98,17 @@ class Analyzer( | |
| this(catalog, conf, conf.optimizerMaxIterations) | ||
| } | ||
|
|
||
| override def execute(plan: LogicalPlan): LogicalPlan = { | ||
| AnalysisContext.reset() | ||
| try { | ||
| executeSameContext(plan) | ||
| } finally { | ||
| AnalysisContext.reset() | ||
| } | ||
| } | ||
|
|
||
| private def executeSameContext(plan: LogicalPlan): LogicalPlan = super.execute(plan) | ||
|
Member
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.
Contributor
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. +1 |
||
|
|
||
| def resolver: Resolver = conf.resolver | ||
|
|
||
| protected val fixedPoint = FixedPoint(maxIterations) | ||
|
|
@@ -176,7 +190,7 @@ class Analyzer( | |
| case With(child, relations) => | ||
| substituteCTE(child, relations.foldLeft(Seq.empty[(String, LogicalPlan)]) { | ||
| case (resolved, (name, relation)) => | ||
| resolved :+ name -> execute(substituteCTE(relation, resolved)) | ||
| resolved :+ name -> executeSameContext(substituteCTE(relation, resolved)) | ||
| }) | ||
| case other => other | ||
| } | ||
|
|
@@ -600,7 +614,7 @@ class Analyzer( | |
| "avoid errors. Increase the value of spark.sql.view.maxNestedViewDepth to work " + | ||
| "aroud this.") | ||
| } | ||
| execute(child) | ||
| executeSameContext(child) | ||
| } | ||
| view.copy(child = newChild) | ||
| case p @ SubqueryAlias(_, view: View) => | ||
|
|
@@ -1269,7 +1283,7 @@ class Analyzer( | |
| do { | ||
| // Try to resolve the subquery plan using the regular analyzer. | ||
| previous = current | ||
| current = execute(current) | ||
| current = executeSameContext(current) | ||
|
|
||
| // Use the outer references to resolve the subquery plan if it isn't resolved yet. | ||
| val i = plans.iterator | ||
|
|
@@ -1392,7 +1406,7 @@ class Analyzer( | |
| grouping, | ||
| Alias(cond, "havingCondition")() :: Nil, | ||
| child) | ||
| val resolvedOperator = execute(aggregatedCondition) | ||
| val resolvedOperator = executeSameContext(aggregatedCondition) | ||
| def resolvedAggregateFilter = | ||
| resolvedOperator | ||
| .asInstanceOf[Aggregate] | ||
|
|
@@ -1450,7 +1464,8 @@ class Analyzer( | |
| val aliasedOrdering = | ||
| unresolvedSortOrders.map(o => Alias(o.child, "aggOrder")()) | ||
| val aggregatedOrdering = aggregate.copy(aggregateExpressions = aliasedOrdering) | ||
| val resolvedAggregate: Aggregate = execute(aggregatedOrdering).asInstanceOf[Aggregate] | ||
| val resolvedAggregate: Aggregate = | ||
| executeSameContext(aggregatedOrdering).asInstanceOf[Aggregate] | ||
| val resolvedAliasedOrdering: Seq[Alias] = | ||
| resolvedAggregate.aggregateExpressions.asInstanceOf[Seq[Alias]] | ||
|
|
||
|
|
||
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.
privateThere 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.
Will be resolved by the future PR.