Skip to content

Commit

Permalink
[SPARK-42600][SQL] CatalogImpl.currentDatabase shall use NamespaceHel…
Browse files Browse the repository at this point in the history
…per instead of MultipartIdentifierHelper

### What changes were proposed in this pull request?

v2 catalog default namespace may be empty

```java
Exception in thread "main" org.apache.spark.sql.AnalysisException: Multi-part identifier cannot be empty.
	at org.apache.spark.sql.errors.QueryCompilationErrors$.emptyMultipartIdentifierError(QueryCompilationErrors.scala:1887)
	at org.apache.spark.sql.connector.catalog.CatalogV2Implicits$MultipartIdentifierHelper.<init>(CatalogV2Implicits.scala:152)
	at org.apache.spark.sql.connector.catalog.CatalogV2Implicits$.MultipartIdentifierHelper(CatalogV2Implicits.scala:150)
	at org.apache.spark.sql.internal.CatalogImpl.currentDatabase(CatalogImpl.scala:65)
```

### Why are the changes needed?

bugfix

### Does this PR introduce _any_ user-facing change?

no

### How was this patch tested?

locally verified

Closes #40192 from yaooqinn/SPARK-42600.

Authored-by: Kent Yao <yao@apache.org>
Signed-off-by: Wenchen Fan <wenchen@databricks.com>
(cherry picked from commit 53c4158)
Signed-off-by: Wenchen Fan <wenchen@databricks.com>
  • Loading branch information
yaooqinn authored and cloud-fan committed Feb 28, 2023
1 parent f3d834d commit 9b6b66d
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import org.apache.spark.sql.catalyst.catalog._
import org.apache.spark.sql.catalyst.encoders.ExpressionEncoder
import org.apache.spark.sql.catalyst.plans.logical.{CreateTable, LocalRelation, LogicalPlan, RecoverPartitions, ShowFunctions, ShowNamespaces, ShowTables, TableSpec, View}
import org.apache.spark.sql.connector.catalog.{CatalogManager, CatalogPlugin, CatalogV2Util, FunctionCatalog, Identifier, SupportsNamespaces, Table => V2Table, TableCatalog, V1Table}
import org.apache.spark.sql.connector.catalog.CatalogV2Implicits.{CatalogHelper, MultipartIdentifierHelper, TransformHelper}
import org.apache.spark.sql.connector.catalog.CatalogV2Implicits.{CatalogHelper, MultipartIdentifierHelper, NamespaceHelper, TransformHelper}
import org.apache.spark.sql.errors.QueryCompilationErrors
import org.apache.spark.sql.execution.command.ShowTablesCommand
import org.apache.spark.sql.execution.datasources.{DataSource, LogicalRelation}
Expand Down Expand Up @@ -62,7 +62,7 @@ class CatalogImpl(sparkSession: SparkSession) extends Catalog {
* Returns the current default database in this session.
*/
override def currentDatabase: String =
sparkSession.sessionState.catalogManager.currentNamespace.toSeq.quoted
sparkSession.sessionState.catalogManager.currentNamespace.quoted

/**
* Sets the current default database in this session.
Expand Down

0 comments on commit 9b6b66d

Please sign in to comment.