cloud-fan commented on a change in pull request #35265:
URL: https://github.com/apache/spark/pull/35265#discussion_r802627193



##########
File path: 
sql/core/src/test/scala/org/apache/spark/sql/execution/command/DescribeTableSuiteBase.scala
##########
@@ -0,0 +1,157 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.spark.sql.execution.command
+
+import org.apache.spark.sql.{QueryTest, Row}
+import 
org.apache.spark.sql.execution.command.DDLCommandTestUtils.V1_COMMAND_VERSION
+import org.apache.spark.sql.functions.when
+import org.apache.spark.sql.types.StringType
+import org.apache.spark.util.Utils
+
+/**
+ * This base suite contains unified tests for the `DESCRIBE TABLE` command 
that check V1 and V2
+ * table catalogs. The tests that cannot run for all supported catalogs are 
located in more
+ * specific test suites:
+ *
+ *   - V2 table catalog tests: 
`org.apache.spark.sql.execution.command.v2.DescribeTableSuite`
+ *   - V1 table catalog tests:
+ *     `org.apache.spark.sql.execution.command.v1.DescribeTableSuiteBase`
+ *     - V1 In-Memory catalog: 
`org.apache.spark.sql.execution.command.v1.DescribeTableSuite`
+ *     - V1 Hive External catalog:
+ *        `org.apache.spark.sql.hive.execution.command.DescribeTableSuite`
+ */
+trait DescribeTableSuiteBase extends QueryTest with DDLCommandTestUtils {
+  override val command = "DESCRIBE TABLE"
+
+  protected def namespace: String
+
+  test("basic") {
+    withNamespaceAndTable(namespace, "table") { tbl =>
+      spark.sql(s"CREATE TABLE $tbl (id bigint, data string) $defaultUsing")
+      val descriptionDf = spark.sql(s"DESCRIBE TABLE $tbl")
+      assert(descriptionDf.schema.map(field => (field.name, field.dataType)) 
===
+        Seq(
+          ("col_name", StringType),
+          ("data_type", StringType),
+          ("comment", StringType)))
+      val description = descriptionDf.collect()
+      assert(description === Seq(
+        Row("data", "string", null),
+        Row("id", "bigint", null)).toArray)
+    }
+  }
+
+  test("describe table with partition columns") {
+    withNamespaceAndTable(namespace, "table") { tbl =>
+      spark.sql(s"CREATE TABLE $tbl (id bigint, data string) $defaultUsing" +
+        " PARTITIONED BY (id)")
+      val descriptionDf = spark.sql(s"DESCRIBE TABLE $tbl")
+      assert(descriptionDf.schema.map(field => (field.name, field.dataType)) 
===
+        Seq(
+          ("col_name", StringType),
+          ("data_type", StringType),
+          ("comment", StringType)))
+      val description = descriptionDf.collect()
+      assert(description === Seq(
+        Row("data", "string", null),
+        Row("id", "bigint", null),
+        Row("# Partition Information", "", ""),
+        Row("# col_name", "data_type", "comment"),
+        Row("id", "bigint", null)).toArray)
+    }
+  }
+
+  test("describe table extended") {
+    withNamespaceAndTable(namespace, "table") { tbl =>
+      spark.sql(s"CREATE TABLE $tbl (id bigint, data string) $defaultUsing" +
+        " PARTITIONED BY (id)" +
+        " TBLPROPERTIES ('bar'='baz')" +
+        " COMMENT 'this is a test table'" +
+        " LOCATION 'file:/tmp/table_name'")
+      val descriptionDf = spark.sql(s"DESCRIBE TABLE EXTENDED $tbl")
+      val cleansedDescriptionDf = descriptionDf
+        .withColumn("data_type", when(descriptionDf("col_name") === "Created 
Time", "")
+        .otherwise(descriptionDf("data_type")))
+      assert(cleansedDescriptionDf.schema.map(field => (field.name, 
field.dataType)) ===
+        Seq(
+          ("col_name", StringType),
+          ("data_type", StringType),
+          ("comment", StringType)))
+
+      val cleansedDescription = cleansedDescriptionDf.collect
+      if (commandVersion == V1_COMMAND_VERSION) {
+        assert(cleansedDescription === Seq(
+          Row("data", "string", null),
+          Row("id", "bigint", null),
+          Row("# Partition Information", "", ""),
+          Row("# col_name", "data_type", "comment"),
+          Row("id", "bigint", null),
+          Row("", "", ""),
+          Row("# Detailed Table Information", "", ""),
+          Row("Database", "db", ""),
+          Row("Table", "table", ""),
+          Row("Created Time", "", ""),
+          Row("Last Access", "UNKNOWN", ""),
+          Row("Created By", s"Spark ${org.apache.spark.SPARK_VERSION}", ""),
+          Row("Type", "EXTERNAL", ""),
+          Row("Provider", "parquet", ""),
+          Row("Comment", "this is a test table", ""),
+          Row("Table Properties", "[bar=baz]", ""),
+          Row("Location", "file:/tmp/table_name", ""),
+          Row("Partition Provider", "Catalog", "")).toArray)
+      } else {
+        if (catalogVersion == "V1") {
+          assert(cleansedDescription === Seq(
+            Row("data", "string", null),
+            Row("id", "bigint", null),
+            Row("# Partition Information", "", ""),
+            Row("# col_name", "data_type", "comment"),
+            Row("id", "bigint", null),
+            Row("", "", ""),
+            Row("# Detailed Table Information", "", ""),
+            Row("Name", "db.table", ""),
+            Row("Comment", "this is a test table", ""),
+            Row("Location", "file:/tmp/table_name", ""),
+            Row("Provider", "parquet", ""),
+            Row("Owner", "", ""),
+            Row("External", "true", ""),
+            Row("Table Properties", "[bar=baz]", "")).toArray)
+        } else {
+          assert(cleansedDescription === Seq(
+            Row("data", "string", null),
+            Row("id", "bigint", null),
+            Row("# Partition Information", "", ""),
+            Row("# col_name", "data_type", "comment"),
+            Row("id", "bigint", null),
+            Row("", "", ""),
+            Row("# Metadata Columns", "", ""),

Review comment:
       is it the only difference?




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