diff --git a/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/command/V1WriteHiveCommandSuite.scala b/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/command/V1WriteHiveCommandSuite.scala index 0f219032fc052..e0e056be5987c 100644 --- a/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/command/V1WriteHiveCommandSuite.scala +++ b/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/command/V1WriteHiveCommandSuite.scala @@ -19,33 +19,48 @@ package org.apache.spark.sql.hive.execution.command import org.apache.spark.sql.QueryTest import org.apache.spark.sql.execution.datasources.V1WriteCommandSuiteBase +import org.apache.spark.sql.hive.HiveUtils._ import org.apache.spark.sql.hive.test.TestHiveSingleton class V1WriteHiveCommandSuite extends QueryTest with TestHiveSingleton with V1WriteCommandSuiteBase { + def withCovnertMetastore(testFunc: Boolean => Any): Unit = { + Seq(true, false).foreach { enabled => + withSQLConf( + CONVERT_METASTORE_PARQUET.key -> enabled.toString, + CONVERT_METASTORE_ORC.key -> enabled.toString) { + testFunc(enabled) + } + } + } + test("create hive table as select - no partition column") { - withPlannedWrite { enabled => - withTable("t") { - executeAndCheckOrdering(hasLogicalSort = false, orderingMatched = true) { - sql("CREATE TABLE t AS SELECT * FROM t0") + withCovnertMetastore { _ => + withPlannedWrite { enabled => + withTable("t") { + executeAndCheckOrdering(hasLogicalSort = false, orderingMatched = true) { + sql("CREATE TABLE t STORED AS PARQUET AS SELECT * FROM t0") + } } } } } test("create hive table as select") { - withPlannedWrite { enabled => - withTable("t") { - withSQLConf("hive.exec.dynamic.partition.mode" -> "nonstrict") { - executeAndCheckOrdering( - hasLogicalSort = enabled, orderingMatched = enabled, hasEmpty2Null = enabled) { - sql( - """ - |CREATE TABLE t - |PARTITIONED BY (k) - |AS SELECT * FROM t0 - |""".stripMargin) + withCovnertMetastore { _ => + withPlannedWrite { enabled => + withTable("t") { + withSQLConf("hive.exec.dynamic.partition.mode" -> "nonstrict") { + executeAndCheckOrdering( + hasLogicalSort = enabled, orderingMatched = enabled, hasEmpty2Null = enabled) { + sql( + """ + |CREATE TABLE t STORED AS PARQUET + |PARTITIONED BY (k) + |AS SELECT * FROM t0 + |""".stripMargin) + } } } } @@ -53,18 +68,20 @@ class V1WriteHiveCommandSuite } test("insert into hive table") { - withPlannedWrite { enabled => - withTable("t") { - sql( - """ - |CREATE TABLE t (i INT, j INT) - |PARTITIONED BY (k STRING) - |CLUSTERED BY (i, j) SORTED BY (j) INTO 2 BUCKETS - |""".stripMargin) - withSQLConf("hive.exec.dynamic.partition.mode" -> "nonstrict") { - executeAndCheckOrdering( - hasLogicalSort = enabled, orderingMatched = enabled, hasEmpty2Null = enabled) { - sql("INSERT INTO t SELECT * FROM t0") + withCovnertMetastore { _ => + withPlannedWrite { enabled => + withTable("t") { + sql( + """ + |CREATE TABLE t (i INT, j INT) STORED AS PARQUET + |PARTITIONED BY (k STRING) + |CLUSTERED BY (i, j) SORTED BY (j) INTO 2 BUCKETS + |""".stripMargin) + withSQLConf("hive.exec.dynamic.partition.mode" -> "nonstrict") { + executeAndCheckOrdering( + hasLogicalSort = enabled, orderingMatched = enabled, hasEmpty2Null = enabled) { + sql("INSERT INTO t SELECT * FROM t0") + } } } } @@ -72,18 +89,20 @@ class V1WriteHiveCommandSuite } test("insert overwrite hive table") { - withPlannedWrite { enabled => - withTable("t") { - withSQLConf("hive.exec.dynamic.partition.mode" -> "nonstrict") { - sql( - """ - |CREATE TABLE t - |PARTITIONED BY (k) - |AS SELECT * FROM t0 - |""".stripMargin) - executeAndCheckOrdering( - hasLogicalSort = enabled, orderingMatched = enabled, hasEmpty2Null = enabled) { - sql("INSERT OVERWRITE t SELECT j AS i, i AS j, k FROM t0") + withCovnertMetastore { _ => + withPlannedWrite { enabled => + withTable("t") { + withSQLConf("hive.exec.dynamic.partition.mode" -> "nonstrict") { + sql( + """ + |CREATE TABLE t STORED AS PARQUET + |PARTITIONED BY (k) + |AS SELECT * FROM t0 + |""".stripMargin) + executeAndCheckOrdering( + hasLogicalSort = enabled, orderingMatched = enabled, hasEmpty2Null = enabled) { + sql("INSERT OVERWRITE t SELECT j AS i, i AS j, k FROM t0") + } } } } @@ -91,16 +110,18 @@ class V1WriteHiveCommandSuite } test("insert into hive table with static partitions only") { - withPlannedWrite { enabled => - withTable("t") { - sql( - """ - |CREATE TABLE t (i INT, j INT) - |PARTITIONED BY (k STRING) - |""".stripMargin) - // No dynamic partition so no sort is needed. - executeAndCheckOrdering(hasLogicalSort = false, orderingMatched = true) { - sql("INSERT INTO t PARTITION (k='0') SELECT i, j FROM t0 WHERE k = '0'") + withCovnertMetastore { _ => + withPlannedWrite { enabled => + withTable("t") { + sql( + """ + |CREATE TABLE t (i INT, j INT) STORED AS PARQUET + |PARTITIONED BY (k STRING) + |""".stripMargin) + // No dynamic partition so no sort is needed. + executeAndCheckOrdering(hasLogicalSort = false, orderingMatched = true) { + sql("INSERT INTO t PARTITION (k='0') SELECT i, j FROM t0 WHERE k = '0'") + } } } }