imback82 commented on a change in pull request #25771: [SPARK-28970][SQL] 
Implement USE CATALOG/NAMESPACE for Data Source V2
URL: https://github.com/apache/spark/pull/25771#discussion_r326868076
 
 

 ##########
 File path: 
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/DataSourceResolution.scala
 ##########
 @@ -170,45 +171,36 @@ case class DataSourceResolution(
       DeleteFromTable(aliased, delete.condition)
 
     case ShowNamespacesStatement(None, pattern) =>
-      defaultCatalog match {
-        case Some(catalog) =>
-          ShowNamespaces(catalog.asNamespaceCatalog, None, pattern)
-        case None =>
-          throw new AnalysisException("No default v2 catalog is set.")
-      }
+      ShowNamespaces(currentCatalog.asNamespaceCatalog, None, pattern)
 
     case ShowNamespacesStatement(Some(namespace), pattern) =>
-      val CatalogNamespace(maybeCatalog, ns) = namespace
-      maybeCatalog match {
-        case Some(catalog) =>
-          ShowNamespaces(catalog.asNamespaceCatalog, Some(ns), pattern)
-        case None =>
-          throw new AnalysisException(
-            s"No v2 catalog is available for ${namespace.quoted}")
-      }
+      val CurrentCatalogAndNamespace(catalog, ns) = namespace
+      ShowNamespaces(catalog.asNamespaceCatalog, Some(ns), pattern)
 
     case ShowTablesStatement(None, pattern) =>
-      defaultCatalog match {
-        case Some(catalog) =>
-          ShowTables(
-            catalog.asTableCatalog,
-            catalogManager.currentNamespace,
-            pattern)
-        case None =>
-          ShowTablesCommand(None, pattern)
-      }
+      ShowTables(currentCatalog.asTableCatalog, 
catalogManager.currentNamespace, pattern)
 
     case ShowTablesStatement(Some(namespace), pattern) =>
-      val CatalogNamespace(maybeCatalog, ns) = namespace
-      maybeCatalog match {
-        case Some(catalog) =>
-          ShowTables(catalog.asTableCatalog, ns, pattern)
+      val CurrentCatalogAndNamespace(catalog, ns) = namespace
+      ShowTables(catalog.asTableCatalog, ns, pattern)
+
+    case UseCatalogAndNamespaceStatement(catalogName, namespace) =>
+      catalogName match {
+        case Some(c) =>
+          validateCatalog(c)
+          UseCatalogAndNamespace(catalogManager, Some(c), namespace)
         case None =>
-          if (namespace.length != 1) {
-            throw new AnalysisException(
-              s"The database name is not valid: ${namespace.quoted}")
+          assert(namespace.nonEmpty)
+          val CurrentCatalogAndNamespace(catalog, ns) = namespace.get
+          if (isSessionCatalog(catalog)) {
+            if (namespace.get.length != 1) {
+              throw new AnalysisException(
+                s"The database name is not valid: '${namespace.get.quoted}'")
+            }
+            SetDatabaseCommand(namespace.get.head)
 
 Review comment:
   @cloud-fan does it make sense to move 
`setCurrentNamespace`/`getCurrentNamespace` to `SupportsNamespace` or not?

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to