-
Notifications
You must be signed in to change notification settings - Fork 29.3k
[SPARK-33692][SQL] View should use captured catalog and namespace to lookup function #30662
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
Changes from 6 commits
f3c2fd6
c104cfe
00e32d6
ef7c6b2
d87f249
11523f4
a8c7722
ab440e3
b30272c
632f3d6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1488,12 +1488,29 @@ class SessionCatalog( | |
| // We probably shouldn't use a single FunctionRegistry to register all three kinds of functions | ||
| // (built-in, temp, and external). | ||
| if (name.database.isEmpty && functionRegistry.functionExists(name)) { | ||
| // This function has been already loaded into the function registry. | ||
| return functionRegistry.lookupFunction(name, children) | ||
| val isResolvingPermanentView = | ||
| AnalysisContext.get.catalogAndNamespace.nonEmpty && !AnalysisContext.get.isTempView | ||
| // We lookup function without database in two cases: | ||
| // 1. the function is not a temporary function | ||
|
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.
Contributor
Author
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. there are also external functions, in |
||
| // 2. the function is a temporary function but we are not resolving permanent view | ||
| if (!isTemporaryFunction(name) || !isResolvingPermanentView) { | ||
| // This function has been already loaded into the function registry. | ||
| return functionRegistry.lookupFunction(name, children) | ||
| } | ||
| } | ||
|
|
||
| // Get the database from AnalysisContext if it's defined, otherwise, use current database | ||
| val currentDatabase = AnalysisContext.get.catalogAndNamespace match { | ||
| case Seq() => getCurrentDatabase | ||
| case Seq(_, db) => db | ||
| case Seq(catalog, namespace @ _*) => | ||
| throw new AnalysisException( | ||
| s"V2 catalog does not support functions yet. " + | ||
| s"catalog: ${catalog}, namespace '${namespace.mkString("[", ".", "]")}'") | ||
|
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. nit: |
||
| } | ||
|
|
||
| // If the name itself is not qualified, add the current database to it. | ||
| val database = formatDatabaseName(name.database.getOrElse(getCurrentDatabase)) | ||
| val database = formatDatabaseName(name.database.getOrElse(currentDatabase)) | ||
| val qualifiedName = name.copy(database = Some(database)) | ||
|
|
||
| if (functionRegistry.functionExists(qualifiedName)) { | ||
|
|
||
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.
then shall we just use
referredTempFuncNames?Uh oh!
There was an error while loading. Please reload this page.
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.
if we change the type to
referredTempFuncNames: Option[Seq[String]], then it can replaceisTempView. Because Seq.empty can be permanent view or temp view refers non temp functions.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.
yea let's do it then. We can use
isTempView: Boolean = falsein the backport PR of 3.0/2.4.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.
you are correct in the first comment. we can just use
referredTempFunctionNames. But this approach will fix both permanent and temp view problems, which I was planning to fix them separately. Anyway, I switch to usereferredTempFunctionNamesin the latest commit.BTW, in 3.0/2.4, temp view stores analyzed plan, and won't be wrapped in
View, so we don't need theisTempViewflag.