cloud-fan commented on a change in pull request #25601: [SPARK-28856][SQL] 
Implement SHOW DATABASES for Data Source V2 Tables
URL: https://github.com/apache/spark/pull/25601#discussion_r320742819
 
 

 ##########
 File path: 
sql/core/src/test/scala/org/apache/spark/sql/sources/v2/DataSourceV2SQLSuite.scala
 ##########
 @@ -747,6 +747,81 @@ class DataSourceV2SQLSuite
     assert(expected === df.collect())
   }
 
+  test("ShowNamespaces: show root namespaces with default v2 catalog") {
+    spark.conf.set("spark.sql.default.catalog", "testcat")
+
+    runShowDatabasesSql("SHOW NAMESPACES", Seq())
+
+    spark.sql("CREATE TABLE testcat.ns1.table (id bigint) USING foo")
+    spark.sql("CREATE TABLE testcat.ns1.ns1_1.table (id bigint) USING foo")
+    spark.sql("CREATE TABLE testcat.ns2.table (id bigint) USING foo")
+
+    runShowDatabasesSql("SHOW NAMESPACES", Seq("ns1", "ns2"))
+    runShowDatabasesSql("SHOW NAMESPACES LIKE '*1*'", Seq("ns1"))
+
+    // Try to look up only with catalog name, which should list root 
namespaces.
+    runShowDatabasesSql("SHOW NAMESPACES IN testcat", Seq("ns1", "ns2"))
+  }
+
+  test("ShowNamespaces: show sub-namespaces") {
+    spark.sql("CREATE TABLE testcat.ns.table (id bigint) USING foo")
+    spark.sql("CREATE TABLE testcat.ns.ns1.table (id bigint) USING foo")
+    spark.sql("CREATE TABLE testcat.ns.ns2.table (id bigint) USING foo")
+
+    runShowDatabasesSql("SHOW NAMESPACES IN testcat.ns", Seq("ns.ns1", 
"ns.ns2"))
+    runShowDatabasesSql("SHOW NAMESPACES IN testcat.ns LIKE '*2*'", 
Seq("ns.ns2"))
+
+    // Try to look up namespace that doesn't exist.
+    runShowDatabasesSql("SHOW NAMESPACES IN testcat.ns.ns3", Seq())
+  }
+
+  test("ShowNamespaces: default v2 catalog is not set") {
+    spark.sql("CREATE TABLE testcat.ns.table (id bigint) USING foo")
+
+    val exception = intercept[AnalysisException] {
+      runShowDatabasesSql("SHOW NAMESPACES", Seq(""))
+    }
+
+    assert(exception.getMessage.contains("No default v2 catalog is set."))
+  }
+
+  test("ShowNamespaces: default v2 catalog doesn't support namespace") {
+    spark.conf.set(
+      "spark.sql.catalog.testcat_no_namspace",
+      classOf[InMemoryTableCatalogBase].getName)
+    spark.conf.set("spark.sql.default.catalog", "testcat_no_namspace")
+
+    val exception = intercept[AnalysisException] {
+      runShowDatabasesSql("SHOW NAMESPACES", Seq(""))
+    }
+
+    assert(exception.getMessage.contains(
+      "The default v2 catalog doesn't support showing namespaces."))
+  }
+
+  test("ShowNamespaces: v2 catalog doesn't support namespace") {
+    spark.conf.set(
+      "spark.sql.catalog.testcat_no_namspace",
+      classOf[InMemoryTableCatalogBase].getName)
+
+    val exception = intercept[AnalysisException] {
+      runShowDatabasesSql("SHOW NAMESPACES in testcat_no_namspace", Seq(""))
+    }
+
+    assert(exception.getMessage.contains(
+      "No v2 catalog with showing namespaces is available"))
+  }
+
+  private def runShowDatabasesSql(
 
 Review comment:
   nit: `testShowNamespaces`

----------------------------------------------------------------
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