srielau commented on code in PR #55523:
URL: https://github.com/apache/spark/pull/55523#discussion_r3144627245
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala:
##########
@@ -139,17 +139,22 @@ object FakeV2SessionCatalog extends TableCatalog with
FunctionCatalog with Suppo
* even if a temp view `t` has been created.
* @param outerPlan The query plan from the outer query that can be used to
resolve star
* expressions in a subquery.
+ * @param resolutionPathEntries When resolving a view body, the ordered path
for unqualified
+ * relation names (see
[[AnalysisContext.withAnalysisContext]]).
+ * [[None]] outside views: compute from session
+ * [[CatalogManager.sqlResolutionPathEntries]].
*/
case class AnalysisContext(
isDefault: Boolean = false,
catalogAndNamespace: Seq[String] = Nil,
+ resolutionPathEntries: Option[Seq[Seq[String]]] = None,
nestedViewDepth: Int = 0,
maxNestedViewDepth: Int = -1,
relationCache: mutable.Map[(Seq[String], Option[TimeTravelSpec]),
LogicalPlan] =
mutable.Map.empty,
referredTempViewNames: Seq[Seq[String]] = Seq.empty,
// 1. If we are resolving a view, this field will be restored from the
view metadata,
- // by calling `AnalysisContext.withAnalysisContext(viewDesc)`.
+ // by calling `AnalysisContext.withAnalysisContext(viewDesc,
catalogManager)`.
Review Comment:
Fixed in 99415fd4d5e. Updated the comment to reference the actual signature:
`AnalysisContext.withAnalysisContext(viewDesc)`.
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala:
##########
@@ -139,17 +139,22 @@ object FakeV2SessionCatalog extends TableCatalog with
FunctionCatalog with Suppo
* even if a temp view `t` has been created.
* @param outerPlan The query plan from the outer query that can be used to
resolve star
* expressions in a subquery.
+ * @param resolutionPathEntries When resolving a view body, the ordered path
for unqualified
+ * relation names (see
[[AnalysisContext.withAnalysisContext]]).
+ * [[None]] outside views: compute from session
+ * [[CatalogManager.sqlResolutionPathEntries]].
Review Comment:
Agreed and fixed in 99415fd4d5e. Reworded the Scaladoc to state
`resolutionPathEntries` stays `None` in this PR and that frozen-path population
is wired in a follow-up.
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/RelationResolution.scala:
##########
@@ -110,34 +114,61 @@ class RelationResolution(
/**
* Scope in the relation resolution search path. Used to interpret
- * [[SQLConf.resolutionSearchPath]] when resolving unqualified table/view
names.
+ * [[CatalogManager.sqlResolutionPathEntries]] when resolving unqualified
table/view names.
*/
- private sealed trait RelationResolutionScope
- private case object SessionScope extends RelationResolutionScope
- private case object PersistentScope extends RelationResolutionScope
+ private sealed trait RelationResolutionStep
+ private case object SessionScopeStep extends RelationResolutionStep
+ private case class PersistentCatalogStep(catalogAndNamespace: Seq[String])
+ extends RelationResolutionStep
+
+ /**
+ * Path entries for unqualified relation resolution.
+ *
+ * Inside a view, [[AnalysisContext.resolutionPathEntries]] will be
+ * populated from the frozen path stored in view metadata (follow-up PR).
+ * When PATH is disabled, legacy resolution rules apply.
+ */
+ private def relationResolutionEntries: Seq[Seq[String]] = {
+ val pinned = AnalysisContext.get.resolutionPathEntries
+ if (pinned.isDefined && conf.pathEnabled) {
+ pinned.get
+ } else {
+ val expandCatalog = catalogManager.currentCatalog.name
+ val expandNamespace = catalogManager.currentNamespace.toSeq
+ val (pathCatalog, pathNamespace) =
+ if (isResolvingView) {
+ val p = AnalysisContext.get.catalogAndNamespace
+ (p.head, p.tail.toSeq)
+ } else {
+ (expandCatalog, expandNamespace)
+ }
+ catalogManager.sqlResolutionPathEntries(
+ pathCatalog,
+ pathNamespace,
+ expandCatalog,
+ expandNamespace)
Review Comment:
Thanks, agreed this is a visible interim behavior before frozen-path wiring.
In this PR I kept the current semantics but made it explicit in code with a
comment in `RelationResolution` that `CurrentSchemaEntry` expansion uses live
session catalog/namespace until the follow-up wires frozen
`resolutionPathEntries`.
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala:
##########
@@ -2078,9 +2101,14 @@ class Analyzer(
throw
QueryCompilationErrors.notAScalarFunctionError(nameParts.mkString("."), f)
case FunctionType.NotFound =>
- val catalogPath =
- catalogManager.currentCatalog.name +:
catalogManager.currentNamespace
- val searchPath =
SQLConf.get.resolutionSearchPath(catalogPath.toSeq)
+ val catalogPath = {
+ val ctx = AnalysisContext.get.catalogAndNamespace
+ if (ctx.nonEmpty) ctx
+ else (catalogManager.currentCatalog.name +:
+ catalogManager.currentNamespace).toSeq
+ }
Review Comment:
Addressed in 99415fd4d5e. I consolidated this by making
`catalogPathForError` `protected final` in `CheckAnalysis` and reusing it in
`Analyzer` for unresolved routine search-path construction.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]