Skip to content
Closed
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 @@ -139,6 +139,7 @@ object FakeV2SessionCatalog extends TableCatalog with FunctionCatalog with Suppo
* expressions in a subquery.
*/
case class AnalysisContext(
isDefault: Boolean = false,
Copy link
Member

Choose a reason for hiding this comment

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

nit: do we consider putting this at the end of the parameter list?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This should always be set when copying an AnalysisContext, so put it at the beginning as a highlight.

catalogAndNamespace: Seq[String] = Nil,
nestedViewDepth: Int = 0,
maxNestedViewDepth: Int = -1,
Expand Down Expand Up @@ -175,7 +176,7 @@ case class AnalysisContext(

object AnalysisContext {
private val value = new ThreadLocal[AnalysisContext]() {
override def initialValue: AnalysisContext = AnalysisContext()
override def initialValue: AnalysisContext = AnalysisContext(isDefault = true)
}

def get: AnalysisContext = value.get()
Expand All @@ -201,13 +202,14 @@ object AnalysisContext {
originContext.maxNestedViewDepth
}
val context = AnalysisContext(
viewDesc.viewCatalogAndNamespace,
originContext.nestedViewDepth + 1,
maxNestedViewDepth,
originContext.relationCache,
viewDesc.viewReferredTempViewNames,
mutable.Set(viewDesc.viewReferredTempFunctionNames: _*),
viewDesc.viewReferredTempVariableNames,
isDefault = false,
catalogAndNamespace = viewDesc.viewCatalogAndNamespace,
nestedViewDepth = originContext.nestedViewDepth + 1,
maxNestedViewDepth = maxNestedViewDepth,
relationCache = originContext.relationCache,
referredTempViewNames = viewDesc.viewReferredTempViewNames,
referredTempFunctionNames = mutable.Set(viewDesc.viewReferredTempFunctionNames: _*),
referredTempVariableNames = viewDesc.viewReferredTempVariableNames,
collation = viewDesc.collation)
set(context)
try f finally { set(originContext) }
Expand All @@ -217,12 +219,13 @@ object AnalysisContext {
def withNewAnalysisContext[A](f: => A): A = {
val originContext = value.get()
reset()
set(get.copy(isDefault = false))
try f finally { set(originContext) }
}

def withOuterPlan[A](outerPlan: LogicalPlan)(f: => A): A = {
val originContext = value.get()
val context = originContext.copy(outerPlan = Some(outerPlan))
val context = originContext.copy(isDefault = false, outerPlan = Some(outerPlan))
set(context)
try f finally { set(originContext) }
}
Expand Down Expand Up @@ -308,9 +311,20 @@ class Analyzer(override val catalogManager: CatalogManager) extends RuleExecutor
if (plan.analyzed) {
plan
} else {
AnalysisContext.withNewAnalysisContext {
AnalysisHelper.markInAnalyzer {
HybridAnalyzer.fromLegacyAnalyzer(legacyAnalyzer = this).apply(plan, tracker)
if (AnalysisContext.get.isDefault) {
AnalysisContext.reset()
try {
AnalysisHelper.markInAnalyzer {
HybridAnalyzer.fromLegacyAnalyzer(legacyAnalyzer = this).apply(plan, tracker)
}
} finally {
AnalysisContext.reset()
}
} else {
AnalysisContext.withNewAnalysisContext {
AnalysisHelper.markInAnalyzer {
HybridAnalyzer.fromLegacyAnalyzer(legacyAnalyzer = this).apply(plan, tracker)
}
}
}
}
Expand Down