cloud-fan commented on code in PR #49445: URL: https://github.com/apache/spark/pull/49445#discussion_r1946867299
########## sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveCatalogs.scala: ########## @@ -73,28 +95,49 @@ class ResolveCatalogs(val catalogManager: CatalogManager) } } - private def resolveVariableName(nameParts: Seq[String]): ResolvedIdentifier = { - def ident: Identifier = Identifier.of(Array(CatalogManager.SESSION_NAMESPACE), nameParts.last) - if (nameParts.length == 1) { - ResolvedIdentifier(FakeSystemCatalog, ident) - } else if (nameParts.length == 2) { - if (nameParts.head.equalsIgnoreCase(CatalogManager.SESSION_NAMESPACE)) { - ResolvedIdentifier(FakeSystemCatalog, ident) - } else { - throw QueryCompilationErrors.unresolvedVariableError( - nameParts, Seq(CatalogManager.SYSTEM_CATALOG_NAME, CatalogManager.SESSION_NAMESPACE)) - } - } else if (nameParts.length == 3) { - if (nameParts(0).equalsIgnoreCase(CatalogManager.SYSTEM_CATALOG_NAME) && - nameParts(1).equalsIgnoreCase(CatalogManager.SESSION_NAMESPACE)) { - ResolvedIdentifier(FakeSystemCatalog, ident) - } else { - throw QueryCompilationErrors.unresolvedVariableError( - nameParts, Seq(CatalogManager.SYSTEM_CATALOG_NAME, CatalogManager.SESSION_NAMESPACE)) - } - } else { + private def resolveCreateVariableName(nameParts: Seq[String]): ResolvedIdentifier = { + val resolvedIdentifier = SqlScriptingLocalVariableManager.get() + .filterNot(_ => AnalysisContext.get.isExecuteImmediate) + .getOrElse(catalogManager.tempVariableManager) + .resolveIdentifier(nameParts.last) Review Comment: We can make the logic clearer: 1. create local variables if and only if we are in the scripting environment and there is only one name part 2. otherwise, create session variables if the qualifier is system.session or it's not qualified. Or create persistent variables (not implemented yet) -- 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: reviews-unsubscr...@spark.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org