cloud-fan commented on code in PR #37588:
URL: https://github.com/apache/spark/pull/37588#discussion_r1380290514


##########
sql/core/src/test/scala/org/apache/spark/sql/execution/command/ShowTablesSuiteBase.scala:
##########
@@ -126,4 +158,258 @@ trait ShowTablesSuiteBase extends QueryTest with 
DDLCommandTestUtils {
       }
     }
   }
+
+  test("show table in a not existing namespace") {
+    checkError(
+      exception = intercept[AnalysisException] {
+        sql(s"SHOW TABLES IN $catalog.nonexist")
+      },
+      errorClass = "SCHEMA_NOT_FOUND",
+      parameters = Map("schemaName" -> "`nonexist`"))
+  }
+
+  test("show table extended in a not existing namespace") {
+    checkError(
+      exception = intercept[AnalysisException] {
+        sql(s"SHOW TABLE EXTENDED IN $catalog.nonexist LIKE '*tbl*'")
+      },
+      errorClass = "SCHEMA_NOT_FOUND",
+      parameters = Map("schemaName" -> "`nonexist`"))
+  }
+
+  test("show table extended in a not existing table") {
+    val namespace = "ns1"
+    val table = "nonexist"
+    withNamespaceAndTable(namespace, table, catalog) { _ =>
+      val result = sql(s"SHOW TABLE EXTENDED IN $catalog.$namespace LIKE 
'*$table*'")
+      assert(result.schema.fieldNames ===
+        Seq("namespace", "tableName", "isTemporary", "information"))
+      assert(result.collect().isEmpty)
+    }
+  }
+
+  test("show table extended in a not existing partition") {
+    val namespace = "ns1"
+    val table = "tbl"
+    withNamespaceAndTable(namespace, table, catalog) { tbl =>
+      sql(s"CREATE TABLE $tbl (id bigint, data string) $defaultUsing 
PARTITIONED BY (id)")
+      sql(s"ALTER TABLE $tbl ADD PARTITION (id = 1)")
+      checkError(
+        exception = intercept[AnalysisException] {
+          sql(s"SHOW TABLE EXTENDED IN $catalog.$namespace LIKE '$table' 
PARTITION(id = 2)")
+        },
+        errorClass = "PARTITIONS_NOT_FOUND",
+        parameters = Map(
+          "partitionList" -> "PARTITION (`id` = 2)",
+          "tableName" -> "`ns1`.`tbl`"
+        )
+      )
+    }
+  }
+
+  test("show table extended in non-partitioned table") {
+    val namespace = "ns1"
+    val table = "tbl"
+    withNamespaceAndTable(namespace, table, catalog) { tbl =>
+      sql(s"CREATE TABLE $tbl (id bigint, data string) $defaultUsing")
+      val e = intercept[AnalysisException] {
+        sql(s"SHOW TABLE EXTENDED IN $catalog.$namespace LIKE '$table' 
PARTITION(id = 1)")
+      }
+      val (errorClass, parameters) = 
extendedPartInNonPartedTableError(catalog, namespace, table)
+      checkError(exception = e, errorClass = errorClass, parameters = 
parameters)
+    }
+  }
+
+  test("show table extended in multi partition key - " +
+    "the command's partition parameters are complete") {
+    val namespace = "ns1"
+    val table = "tbl"
+    withNamespaceAndTable(namespace, table, catalog) { tbl =>
+      sql(s"CREATE TABLE $tbl (id1 bigint, id2 bigint, data string) " +
+        s"$defaultUsing PARTITIONED BY (id1, id2)")
+      sql(s"ALTER TABLE $tbl ADD PARTITION (id1 = 1, id2 = 2)")
+
+      val result = sql(s"SHOW TABLE EXTENDED FROM $catalog.$namespace " +
+        s"LIKE '$table' PARTITION(id1 = 1, id2 = 2)")
+      assert(result.schema.fieldNames ===
+        Seq("namespace", "tableName", "isTemporary", "information"))
+      val resultCollect = result.collect()
+      assert(resultCollect(0).length == 4)
+      assert(resultCollect(0)(0) === namespace)
+      assert(resultCollect(0)(1) === table)
+      assert(resultCollect(0)(2) === false)
+      val actualResult = replace(resultCollect(0)(3).toString)
+      assert(actualResult === extendedPartExpectedResult)
+    }
+  }
+
+  test("show table extended in multi partition key - " +
+    "the command's partition parameters are incomplete") {
+    val namespace = "ns1"
+    val table = "tbl"
+    withNamespaceAndTable(namespace, table, catalog) { tbl =>
+      sql(s"CREATE TABLE $tbl (id1 bigint, id2 bigint, data string) " +
+        s"$defaultUsing PARTITIONED BY (id1, id2)")
+      sql(s"ALTER TABLE $tbl ADD PARTITION (id1 = 1, id2 = 2)")
+
+      checkError(
+        exception = intercept[AnalysisException] {
+          sql(s"SHOW TABLE EXTENDED IN $catalog.$namespace " +
+            s"LIKE '$table' PARTITION(id1 = 1)")
+        },
+        errorClass = "_LEGACY_ERROR_TEMP_1232",
+        parameters = Map(
+          "specKeys" -> "id1",
+          "partitionColumnNames" -> "id1, id2",
+          "tableName" -> s"`$catalog`.`$namespace`.`$table`")
+      )
+    }
+  }
+
+  test("show table extended in multi tables") {
+    val namespace = "ns1"
+    val table = "tbl"
+    withNamespaceAndTable(namespace, table, catalog) { _ =>
+      sql(s"CREATE TABLE $catalog.$namespace.$table (id bigint, data string) " 
+
+        s"$defaultUsing PARTITIONED BY (id)")
+      val table1 = "tbl1"
+      val table2 = "tbl2"
+      withTable(table1, table2) {
+        sql(s"CREATE TABLE $catalog.$namespace.$table1 (id1 bigint, data1 
string) " +
+          s"$defaultUsing PARTITIONED BY (id1)")
+        sql(s"CREATE TABLE $catalog.$namespace.$table2 (id2 bigint, data2 
string) " +
+          s"$defaultUsing PARTITIONED BY (id2)")
+
+        val result = sql(s"SHOW TABLE EXTENDED FROM $catalog.$namespace LIKE 
'$table*'")
+          .sort("tableName")
+        assert(result.schema.fieldNames ===
+          Seq("namespace", "tableName", "isTemporary", "information"))
+        val resultCollect = result.collect()
+        assert(resultCollect.length == 3)
+
+        assert(resultCollect(0).length == 4)
+        assert(resultCollect(0)(1) === table)
+        assert(resultCollect(0)(2) === false)
+        // replace "Created Time", "Last Access", "Created By", "Location"
+        val actualResult_0_3 = replace(resultCollect(0)(3).toString)
+        val expectedResult_0_3 = extendedTableExpectedResult(
+          catalog, namespaceKey, namespace, table, "id", "data")
+        assert(actualResult_0_3 === expectedResult_0_3)
+
+        assert(resultCollect(1).length == 4)
+        assert(resultCollect(1)(1) === table1)
+        assert(resultCollect(1)(2) === false)
+        val actualResult_1_3 = replace(resultCollect(1)(3).toString)
+        // replace "Table Properties"
+        val expectedResult_1_3 = extendedTableExpectedResult(
+          catalog, namespaceKey, namespace, table1, "id1", "data1")
+        assert(actualResult_1_3 === expectedResult_1_3)
+
+        assert(resultCollect(2).length == 4)
+        assert(resultCollect(2)(1) === table2)
+        assert(resultCollect(2)(2) === false)
+        val actualResult_2_3 = replace(resultCollect(2)(3).toString)
+        // replace "Table Properties"
+        val expectedResult_2_3 = extendedTableExpectedResult(
+          catalog, namespaceKey, namespace, table2, "id2", "data2")
+        assert(actualResult_2_3 === expectedResult_2_3)
+      }
+    }
+  }
+
+  test("show table extended in temp view, include: temp global, temp local") {
+    val namespace = "ns"
+    val table = "tbl"
+    withNamespaceAndTable(namespace, table, catalog) { t =>
+      sql(s"CREATE TABLE $t (id int) $defaultUsing")
+      val viewName = table + "_view"
+      val localTmpViewName = viewName + "_local_tmp"
+      val globalTmpViewName = viewName + "_global_tmp"
+      val globalNamespace = "global_temp"
+      withView(localTmpViewName, globalNamespace + "." + globalTmpViewName) {
+        sql(s"CREATE TEMPORARY VIEW $localTmpViewName AS SELECT id FROM $t")
+        sql(s"CREATE GLOBAL TEMPORARY VIEW $globalTmpViewName AS SELECT id 
FROM $t")
+
+        // temp local view
+        val localResult = sql(s"SHOW TABLE EXTENDED LIKE 
'$viewName*'").sort("tableName")
+        assert(localResult.schema.fieldNames ===
+          Seq("namespace", "tableName", "isTemporary", "information"))
+        val localResultCollect = localResult.collect()
+        assert(localResultCollect.length == 1)
+        assert(localResultCollect(0).length == 4)
+        assert(localResultCollect(0)(1) === localTmpViewName)
+        assert(localResultCollect(0)(2) === true)
+        val actualLocalResult = replace(localResultCollect(0)(3).toString)
+        val expectedLocalResult =
+          s"""Table: $localTmpViewName
+             |Created Time: <created time>
+             |Last Access: <last access>
+             |Created By: <created by>
+             |Type: VIEW
+             |View Text: SELECT id FROM $catalog.$namespace.$table
+             |View Catalog and Namespace: spark_catalog.default
+             |View Query Output Columns: [id]
+             |Schema: root
+             | |-- id: integer (nullable = true)""".stripMargin
+        assert(actualLocalResult === expectedLocalResult)
+
+        // temp global view
+        val globalResult = sql(s"SHOW TABLE EXTENDED in global_temp LIKE 
'$viewName*'").

Review Comment:
   ```suggestion
           val globalResult = sql(s"SHOW TABLE EXTENDED IN global_temp LIKE 
'$viewName*'").
   ```



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

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to