Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,88 +19,109 @@ 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)
}
}
}
}
}
}

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")
}
}
}
}
}
}

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")
}
}
}
}
}
}

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'")
}
}
}
}
Expand Down