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 @@ -76,57 +76,59 @@ class ResolveDefaultColumnsSuite extends QueryTest with SharedSparkSession {
}

test("INSERT into partitioned tables") {
sql("create table t(c1 int, c2 int, c3 int, c4 int) using parquet partitioned by (c3, c4)")

// INSERT without static partitions
checkError(
exception = intercept[AnalysisException] {
sql("insert into t values (1, 2, 3)")
},
errorClass = "INSERT_COLUMN_ARITY_MISMATCH.NOT_ENOUGH_DATA_COLUMNS",
parameters = Map(
"tableName" -> "`spark_catalog`.`default`.`t`",
"tableColumns" -> "`c1`, `c2`, `c3`, `c4`",
"dataColumns" -> "`col1`, `col2`, `col3`"))

// INSERT without static partitions but with column list
sql("truncate table t")
sql("insert into t (c2, c1, c4) values (1, 2, 3)")
checkAnswer(spark.table("t"), Row(2, 1, null, 3))

// INSERT with static partitions
sql("truncate table t")
checkError(
exception = intercept[AnalysisException] {
sql("insert into t partition(c3=3, c4=4) values (1)")
},
errorClass = "INSERT_PARTITION_COLUMN_ARITY_MISMATCH",
parameters = Map(
"tableName" -> "`spark_catalog`.`default`.`t`",
"tableColumns" -> "`c1`, `c2`, `c3`, `c4`",
"dataColumns" -> "`col1`",
"staticPartCols" -> "`c3`, `c4`"))

// INSERT with static partitions and with column list
sql("truncate table t")
sql("insert into t partition(c3=3, c4=4) (c2) values (1)")
checkAnswer(spark.table("t"), Row(null, 1, 3, 4))

// INSERT with partial static partitions
sql("truncate table t")
checkError(
exception = intercept[AnalysisException] {
sql("insert into t partition(c3=3, c4) values (1, 2)")
},
errorClass = "INSERT_PARTITION_COLUMN_ARITY_MISMATCH",
parameters = Map(
"tableName" -> "`spark_catalog`.`default`.`t`",
"tableColumns" -> "`c1`, `c2`, `c3`, `c4`",
"dataColumns" -> "`col1`, `col2`",
"staticPartCols" -> "`c3`"))

// INSERT with partial static partitions and with column list is not allowed
intercept[AnalysisException](sql("insert into t partition(c3=3, c4) (c1) values (1, 4)"))
withTable("t") {
sql("create table t(c1 int, c2 int, c3 int, c4 int) using parquet partitioned by (c3, c4)")

// INSERT without static partitions
checkError(
exception = intercept[AnalysisException] {
sql("insert into t values (1, 2, 3)")
},
errorClass = "INSERT_COLUMN_ARITY_MISMATCH.NOT_ENOUGH_DATA_COLUMNS",
parameters = Map(
"tableName" -> "`spark_catalog`.`default`.`t`",
"tableColumns" -> "`c1`, `c2`, `c3`, `c4`",
"dataColumns" -> "`col1`, `col2`, `col3`"))

// INSERT without static partitions but with column list
sql("truncate table t")
sql("insert into t (c2, c1, c4) values (1, 2, 3)")
checkAnswer(spark.table("t"), Row(2, 1, null, 3))

// INSERT with static partitions
sql("truncate table t")
checkError(
exception = intercept[AnalysisException] {
sql("insert into t partition(c3=3, c4=4) values (1)")
},
errorClass = "INSERT_PARTITION_COLUMN_ARITY_MISMATCH",
parameters = Map(
"tableName" -> "`spark_catalog`.`default`.`t`",
"tableColumns" -> "`c1`, `c2`, `c3`, `c4`",
"dataColumns" -> "`col1`",
"staticPartCols" -> "`c3`, `c4`"))

// INSERT with static partitions and with column list
sql("truncate table t")
sql("insert into t partition(c3=3, c4=4) (c2) values (1)")
checkAnswer(spark.table("t"), Row(null, 1, 3, 4))

// INSERT with partial static partitions
sql("truncate table t")
checkError(
exception = intercept[AnalysisException] {
sql("insert into t partition(c3=3, c4) values (1, 2)")
},
errorClass = "INSERT_PARTITION_COLUMN_ARITY_MISMATCH",
parameters = Map(
"tableName" -> "`spark_catalog`.`default`.`t`",
"tableColumns" -> "`c1`, `c2`, `c3`, `c4`",
"dataColumns" -> "`col1`, `col2`",
"staticPartCols" -> "`c3`"))

// INSERT with partial static partitions and with column list is not allowed
intercept[AnalysisException](sql("insert into t partition(c3=3, c4) (c1) values (1, 4)"))
}
}

test("SPARK-43085: Column DEFAULT assignment for target tables with multi-part names") {
Expand Down