You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2021/06/23 09:52:07 UTC

[GitHub] [spark] yaooqinn commented on a change in pull request #32931: [SPARK-33898][SQL] Support SHOW CREATE TABLE In V2

yaooqinn commented on a change in pull request #32931:
URL: https://github.com/apache/spark/pull/32931#discussion_r656939720



##########
File path: sql/core/src/test/scala/org/apache/spark/sql/connector/DataSourceV2SQLSuite.scala
##########
@@ -1961,12 +1961,98 @@ 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(",
+        "'from' = '0',",
+        "'to' = '1')",
+        "PARTITIONED BY (a)",
+        "COMMENT 'This is a comment'",
+        "LOCATION '/tmp'",
+        "TBLPROPERTIES(",
+        "'prop1' = '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))"

Review comment:
       shall these attributes be quoted too?




-- 
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org