Peng-Lei commented on a change in pull request #32931:
URL: https://github.com/apache/spark/pull/32931#discussion_r656318122



##########
File path: 
sql/core/src/test/scala/org/apache/spark/sql/connector/DataSourceV2SQLSuite.scala
##########
@@ -1961,12 +1961,118 @@ class DataSourceV2SQLSuite
     }
   }
 
-  test("SHOW CREATE TABLE") {
+  test("SHOW CREATE TABLE AS SERDE") {
     val t = "testcat.ns1.ns2.tbl"
     withTable(t) {
       spark.sql(s"CREATE TABLE $t (id bigint, data string) USING foo")
-      testNotSupportedV2Command("SHOW CREATE TABLE", t)
-      testNotSupportedV2Command("SHOW CREATE TABLE", s"$t AS SERDE")
+      val e = intercept[AnalysisException] {
+        sql(s"SHOW CREATE TABLE $t AS SERDE")
+      }
+      assert(e.message.contains(s"SHOW CREATE TABLE AS SERDE is not supported 
for v2 tables."))
+    }
+  }
+
+  test("SPARK-33898: SHOW CREATE TABLE") {
+    val t = "testcat.ns1.ns2.tbl"
+    withTable(t) {
+      spark.sql(  s"""CREATE TABLE $t (
+                     |  a bigint,
+                     |  b bigint,
+                     |  c bigint,
+                     |  `extra col` ARRAY<INT>,
+                     |  `<another>` STRUCT<x: INT, y: ARRAY<BOOLEAN>>
+                     |)
+                     |USING foo
+                     |OPTIONS (
+                     |  from = 0,
+                     |  to = 1)
+                     |COMMENT 'This is a comment'
+                     |TBLPROPERTIES ('prop1' = '1')
+                     |PARTITIONED BY (a)
+                     |LOCATION '/tmp'
+         """.stripMargin)
+      val showDDL = getShowCreateDDL(s"SHOW CREATE TABLE $t")
+      assert(showDDL === Array(
+        "CREATE TABLE testcat.ns1.ns2.tbl (",
+        "`a` BIGINT,",
+        "`b` BIGINT,",
+        "`c` BIGINT,",
+        "`extra col` ARRAY<INT>,",
+        "`<another>` STRUCT<`x`: INT, `y`: ARRAY<BOOLEAN>>)",
+        "USING foo",
+        "OPTIONS(",
+        "'option.from' = '0',",
+        "'option.to' = '1')",
+        "PARTITIONED BY (a)",
+        "COMMENT 'This is a comment'",
+        "LOCATION /tmp",
+        "TBLPROPERTIES (",
+        "'prop1' = '1',",
+        "'to' = '1',",
+        "'from' = '0',",
+        "'option.from' = '0',",
+        "'option.to' = '1')"
+      ))
+    }
+  }
+
+  test("SPARK-33898: SHOW CREATE TABLE WITH AS SELECT") {
+    val t = "testcat.ns1.ns2.tbl"
+    withTable(t) {
+      spark.sql(  s"""CREATE TABLE $t
+                     |USING foo
+                     |AS SELECT 1 AS a, "foo" AS b
+         """.stripMargin)
+      val showDDL = getShowCreateDDL(s"SHOW CREATE TABLE $t")
+      assert(showDDL === Array(
+        "CREATE TABLE testcat.ns1.ns2.tbl (",
+        "`a` INT,",
+        "`b` STRING)",
+        "USING foo"
+      ))
+    }
+  }
+
+  test("SPARK-33898: SHOW CREATE TABLE PARTITIONED BY Transforms") {
+    val t = "testcat.ns1.ns2.tbl"
+    withTable(t) {
+      val createSql =
+        s"""
+          |CREATE TABLE $t (a INT, b STRING, ts TIMESTAMP) USING foo
+          |PARTITIONED BY (
+          |    a,
+          |    bucket(16, b),
+          |    years(ts),
+          |    months(ts),
+          |    days(ts),
+          |    hours(ts))
+      """.stripMargin
+      spark.sql(createSql)
+      val showDDL = getShowCreateDDL(s"SHOW CREATE TABLE $t")
+      assert(showDDL === Array(
+        "CREATE TABLE testcat.ns1.ns2.tbl (",
+        "`a` INT,",
+        "`b` STRING,",
+        "`ts` TIMESTAMP)",
+        "USING foo",
+        "PARTITIONED BY (a, bucket(16, b), years(ts), months(ts), days(ts), 
hours(ts))"
+      ))
+    }
+  }
+
+  test("SPARK-33898: SHOW CREATE TABLE WITH HIVE PROPERTIES") {
+    val t = "testcat.ns1.ns2.tbl"
+    withTable(t) {
+      val createSql =
+        s"""
+           |CREATE TABLE $t (a INT, b STRING, ts TIMESTAMP) USING foo
+           |TBLPROPERTIES ('hive.serde' = 'prop1', 'hive.stored-as' = 'prop2')

Review comment:
       @cloud-fan I added an isHive judgment, which will throw an exception. 
Now I have deleted that judgment. This use case should also be deleted. I'll 
fix it tomorrow morning. And I may need to know more about v2.
   
   > If CREATE TABLE does not fail, it means hive properties are ok, and I 
don't see why `SHOW CREATE TABLE` should fail
   
   @cloud-fan I added an isHive judgment, which will throw an exception. Now I 
have deleted that judgment. This test case should also be deleted. I'll fix it 
tomorrow morning. And I need to know more about v2.




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



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

Reply via email to