panbingkun commented on code in PR #37588:
URL: https://github.com/apache/spark/pull/37588#discussion_r1374453999


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolvePartitionSpec.scala:
##########
@@ -50,6 +50,16 @@ object ResolvePartitionSpec extends Rule[LogicalPlan] {
           }
         case _ => command
       }
+    case command @ ShowTableExtended(ResolvedNamespace(catalog: TableCatalog, 
namespace),

Review Comment:
   Based on the above suggestions, the modifications have been completed and we 
will add 2 commands: `ShowTablesExtended ` and `ShowTablePartition `
   Simultaneously delete: `ShowTableExtended`
   And in  `ResolveSessionCatalog`, conversion was made for the two new command 
mentioned above.



##########
sql/core/src/test/scala/org/apache/spark/sql/execution/command/ShowTablesSuiteBase.scala:
##########
@@ -126,4 +127,512 @@ 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 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)")
+      }
+      checkError(
+        exception = e,
+        errorClass = e.getErrorClass,
+        parameters = e.getErrorClass match {
+          case "_LEGACY_ERROR_TEMP_1251" =>
+            Map("action" -> "SHOW TABLE EXTENDED", "tableName" -> table) // v1 
v2
+          case "_LEGACY_ERROR_TEMP_1231" =>
+            Map("key" -> "id", "tblName" -> 
s"`$catalog`.`$namespace`.`$table`") // hive
+        }
+      )
+    }
+  }
+
+  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 multi partition key table") {
+    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"))
+      assert(result.collect()(0).length == 4)
+      assert(result.collect()(0)(0) === namespace)
+      assert(result.collect()(0)(1) === table)
+      assert(result.collect()(0)(2) === false)
+      val actualResult = exclude(result.collect()(0)(3).toString)
+      val expectedResult_v1_v2 = "Partition Values: [id1=1, id2=2]"
+      val expectedResult_hive =
+        """Partition Values: [id1=1, id2=2]
+          |Serde Library: org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe
+          |InputFormat: org.apache.hadoop.mapred.TextInputFormat
+          |OutputFormat: 
org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat
+          |Storage Properties: [serialization.format=1]""".stripMargin
+      assert(actualResult === expectedResult_v1_v2 || actualResult === 
expectedResult_hive)
+
+      checkError(

Review Comment:
   Done.



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