Skip to content

Commit f4a3d08

Browse files
committed
address comments
1 parent 53db6f0 commit f4a3d08

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/connector/catalog/LookupCatalog.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ private[sql] trait LookupCatalog extends Logging {
9595
* Catalog name takes precedence over identifier, but for a single-part name, identifier takes
9696
* precedence over catalog name.
9797
*
98-
* Note that, this pattern is used to look up catalog objects like table, function, permanent
99-
* view, etc. If you need to look up temp views, please do it separately before calling this
100-
* pattern.
98+
* Note that, this pattern is used to look up permanent catalog objects like table, view,
99+
* function, etc. If you need to look up temp objects like temp view, please do it separately
100+
* before calling this pattern, as temp objects don't belong to any catalog.
101101
*/
102102
object CatalogAndIdentifier {
103103
import org.apache.spark.sql.connector.catalog.CatalogV2Implicits.MultipartIdentifierHelper

sql/core/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveSessionCatalog.scala

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ class ResolveSessionCatalog(
535535
if (isTemp) {
536536
// temp func doesn't belong to any catalog and we shouldn't resolve catalog in the name.
537537
val database = if (nameParts.length > 2) {
538-
throw new AnalysisException(s"${nameParts.quoted} is not a valid function name.")
538+
throw new AnalysisException(s"Unsupported function name '${nameParts.quoted}'")
539539
} else if (nameParts.length == 2) {
540540
Some(nameParts.head)
541541
} else {
@@ -566,20 +566,24 @@ class ResolveSessionCatalog(
566566
}
567567

568568
nameParts match {
569-
case SessionCatalogAndTable(_, funcName) => funcName match {
570-
case Seq(db, fn) => FunctionIdentifier(fn, Some(db))
571-
case Seq(fn) =>
572-
val database = if (nameParts.head == CatalogManager.SESSION_CATALOG_NAME) {
569+
case SessionCatalogAndIdentifier(_, ident) =>
570+
if (nameParts.length == 1) {
571+
// If there is only one name part, it means the current catalog is the session catalog.
572+
// Here we don't fill the default database, to keep the error message unchanged for
573+
// v1 commands.
574+
FunctionIdentifier(nameParts.head, None)
575+
} else {
576+
ident.namespace match {
573577
// For name parts like `spark_catalog.t`, we need to fill in the default database so
574578
// that the caller side won't treat it as a temp function.
575-
Some(catalogManager.v1SessionCatalog.getCurrentDatabase)
576-
} else {
577-
None
579+
case Array() if nameParts.head == CatalogManager.SESSION_CATALOG_NAME =>
580+
FunctionIdentifier(
581+
ident.name, Some(catalogManager.v1SessionCatalog.getCurrentDatabase))
582+
case Array(db) => FunctionIdentifier(ident.name, Some(db))
583+
case _ =>
584+
throw new AnalysisException(s"Unsupported function name '$ident'")
578585
}
579-
FunctionIdentifier(fn, database)
580-
case _ =>
581-
throw new AnalysisException(s"Unsupported function name '${funcName.quoted}'")
582-
}
586+
}
583587

584588
case _ => throw new AnalysisException(s"$sql is only supported in v1 catalog")
585589
}

0 commit comments

Comments
 (0)