srielau commented on code in PR #60515:
URL: https://github.com/apache/spark/pull/60515#discussion_r4589642906
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/internal/SQLConf.scala:
##########
@@ -10945,34 +10944,52 @@ class SQLConf extends Serializable with Logging with
SqlApiConf {
* Returns the resolution search path for error messages and resolution
order.
* This is the single source of truth for the search path used for
functions, tables, and views.
* Uses [[sessionFunctionResolutionOrder]]: "first" (session first),
"second" (session second),
- * "last" (session last). When catalogPath is empty, returns only system
namespaces.
+ * "last" (session last). When catalogPath is empty, current schema and
catalog entries are
+ * omitted.
*/
- def resolutionSearchPath(catalogPath: Seq[String]): Seq[Seq[String]] =
- defaultPathOrder(if (catalogPath.isEmpty) Seq.empty else Seq(catalogPath))
+ def resolutionSearchPath(catalogPath: Seq[String]): Seq[Seq[String]] = {
+ val schemaEntries = if (catalogPath.isEmpty) Seq.empty else
Seq(catalogPath)
+ val catalogEntries = catalogPath.headOption.toSeq.map(Seq(_))
+ defaultPathOrder(schemaEntries, catalogEntries)
+ }
/**
- * Orders the given catalog path entries by
[[sessionFunctionResolutionOrder]], inserting
- * system.session and system.builtin. Used by the legacy single-schema
resolution and by
- * SET PATH's DEFAULT_PATH expansion (when `spark.sql.defaultPath` is empty)
to keep
- * ordering in sync. SYSTEM_PATH no longer flows through here -- see
[[systemPathOrder]].
+ * Orders schema entries by [[sessionFunctionResolutionOrder]] with
system.session and
+ * system.builtin, then orders the system and persistent catalog entries
using
+ * [[persistentCatalogFirst]]. Used by the legacy single-schema resolution
and by SET PATH's
+ * DEFAULT_PATH expansion (when `spark.sql.defaultPath` is empty) to keep
ordering in sync.
+ * SYSTEM_PATH no longer flows through here -- see [[systemPathOrder]].
*
+ * @param schemaEntries persistent schema path entries (may be empty).
* @param catalogEntries persistent catalog path entries (may be empty).
*/
- def defaultPathOrder(catalogEntries: Seq[Seq[String]]): Seq[Seq[String]] = {
+ def defaultPathOrder(schemaEntries: Seq[Seq[String]]): Seq[Seq[String]] = {
Review Comment:
Addressed.
The two-argument defaultPathOrder carries the schemaEntries and
catalogEntries docs. The one-argument overload has a one-line doc.
##########
sql/core/src/test/resources/sql-tests/inputs/sql-path.sql:
##########
@@ -179,9 +179,11 @@ SET PATH = SYSTEM_PATH, SYSTEM_PATH;
SET PATH = current_database, current_schema;
--- 4.5 Single-part schema reference rejected
-----------------------------------
+-- 4.5 Single-part catalog reference accepted
----------------------------------
Review Comment:
Open.
Not changed yet. Case 4.5 still sits under section 4, 'Static error
conditions at SET PATH'.
##########
sql/core/src/test/scala/org/apache/spark/sql/SetPathSuite.scala:
##########
@@ -1050,7 +1228,8 @@ class SetPathSuite extends SharedSparkSession {
s"Expected BIGINT (builtin count rewrite); got: $tpe")
}
- sql("SET PATH = system.session, system.builtin")
+ // The catalog-only system entry resolves the two-part builtin.count
reference below.
Review Comment:
Addressed.
The premise no longer holds. Two-part names take catalogs only from catalog
entries, so the bare system entry is what resolves builtin.count. The comment
at the SET PATH = system.session, system.builtin, system test says so.
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/interface.scala:
##########
@@ -815,8 +826,74 @@ object CatalogTable {
/** Frozen expanded PATH at view creation (PATH feature); not a SQL config
property. */
val VIEW_RESOLUTION_PATH = VIEW_PREFIX + "resolutionPath"
+ /**
+ * Sequence counter for incompatible changes to persisted view property
interpretation.
+ * Absent = 0. Version history:
+ * 0 - Pre-metadataVersion payloads. Frozen PATH schema entries only;
two-part names used a
+ * separate mini-path of `system` and the creation catalog.
+ * 1 - Frozen PATH may include catalog-only entries that participate in
two-part resolution.
+ */
+ val VIEW_METADATA_VERSION = VIEW_PREFIX + "metadataVersion"
+
+ /**
+ * Current [[VIEW_METADATA_VERSION]] written by this Spark build. Bump when
a change cannot
+ * read older view property payloads without a version branch.
+ */
+ val CURRENT_VIEW_METADATA_VERSION: Int = 1
+
+ /**
+ * First [[VIEW_METADATA_VERSION]] / function metadata version where frozen
PATH catalog
+ * entries are authoritative for two-part name resolution.
+ */
+ val METADATA_VERSION_PATH_WITH_CATALOG_ENTRIES: Int = 1
+
val VIEW_STORING_ANALYZED_PLAN = VIEW_PREFIX + "storingAnalyzedPlan"
+ /** Parse a persisted metadata-version property; absent means 0. */
+ def parseMetadataVersion(
+ raw: Option[String],
+ objectType: String,
+ objectName: String): Int = {
+ raw.map { value =>
+ try {
+ value.toInt
+ } catch {
+ case _: NumberFormatException =>
+ throw new AnalysisException(
Review Comment:
Open.
Not added yet. No test covers a non-numeric metadataVersion on a view or SQL
function.
##########
sql/core/src/test/scala/org/apache/spark/sql/execution/command/v1/AlterViewSchemaBindingSuite.scala:
##########
@@ -52,18 +54,66 @@ class AlterViewSchemaBindingSuite
sql(s"SET PATH = $catalog.default, system.builtin")
sql(s"ALTER VIEW $view WITH SCHEMA EVOLUTION")
- val pathAfterAlter = spark.sessionState.catalog
+ val metaAfterAlter = spark.sessionState.catalog
.getTableMetadata(TableIdentifier(viewName, Some(namespace)))
- .viewStoredResolutionPath
+ val pathAfterAlter = metaAfterAlter.viewStoredResolutionPath
.getOrElse(fail("Frozen SQL path was dropped by ALTER VIEW WITH
SCHEMA"))
assert(pathAfterAlter == pathAfterCreate,
s"ALTER VIEW WITH SCHEMA must preserve the frozen path. " +
s"Before: $pathAfterCreate; after: $pathAfterAlter")
+ assert(metaAfterAlter.viewMetadataVersion == versionAfterCreate,
Review Comment:
Open.
Not added yet. No test ALTERs a version-0 view and checks that it stays
version 0 and resolves through its creation catalog.
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/connector/catalog/PathElement.scala:
##########
@@ -73,14 +76,17 @@ private[sql] object PathElement {
catalogManager: CatalogManager,
isConfDefaultExpansion: Boolean = false): Seq[SessionPathEntry] = {
val currentSchemaSentinel = Seq("__current_schema__")
+ val currentCatalogSentinel = Seq("__current_catalog__")
def toEntries(parts: Seq[Seq[String]]): Seq[SessionPathEntry] = parts.map {
case p if p == currentSchemaSentinel => CurrentSchemaEntry
+ case p if p == currentCatalogSentinel => CurrentCatalogEntry
case p => LiteralPathEntry(p)
}
def builtinDefaultWithCurrentSchema: Seq[SessionPathEntry] =
- toEntries(conf.defaultPathOrder(Seq(currentSchemaSentinel)))
+ toEntries(conf.defaultPathOrder(
Review Comment:
Partially addressed in 1363cf75fc9.
The DEFAULT_PATH USE test now changes the current catalog and checks
current_path() and two-part lookups. Not covered yet: an unregistered one-part
entry (SET PATH = myschema), and a pathless view under a CURRENT_SCHEMA default
path.
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala:
##########
@@ -2422,18 +2465,8 @@ class Analyzer(
UNRESOLVED_TABLE_VALUED_FUNCTION, UNRESOLVED_TVF_ALIASES,
UNRESOLVED_JSON_CONSTRUCTOR),
ruleId) {
// Resolve scalar/table functions and get the function metadata for
DESCRIBE FUNCTION.
- case u @ UnresolvedFunctionName(nameParts, _, _) =>
- functionResolution.lookupBuiltinOrTempFunction(nameParts, None)
-
.orElse(functionResolution.lookupBuiltinOrTempTableFunction(nameParts)).map {
info =>
- ResolvedNonPersistentFunc(nameParts.head,
V1Function.metadataOnly(info))
- }.getOrElse {
- val CatalogAndIdentifier(catalog, ident) =
- relationResolution.expandIdentifier(nameParts)
- val fullName = catalog.name +: ident.namespace :+ ident.name
- CatalogV2Util.loadFunction(catalog, ident).map { func =>
- ResolvedPersistentFunc(catalog.asFunctionCatalog, ident, func)
- }.getOrElse(u.copy(possibleQualifiedName =
Some(fullName.toImmutableArraySeq)))
- }
+ case u: UnresolvedFunctionName =>
+ functionResolution.resolveFunctionName(u)
Review Comment:
Open.
Not added yet. SECTION 16k covers only two-part builtin.abs. No test checks
one-part DESCRIBE FUNCTION under a SET PATH.
--
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]