gengliangwang commented on code in PR #36212:
URL: https://github.com/apache/spark/pull/36212#discussion_r856226381
##########
sql/hive/src/test/scala/org/apache/spark/sql/hive/InsertSuite.scala:
##########
@@ -443,6 +443,76 @@ class InsertSuite extends QueryTest with TestHiveSingleton
with BeforeAndAfter
}
}
+ testPartitionedTable("INSERT INTO a partitioned table, use nulls for missing
columns") {
+ tableName =>
+ withSQLConf(("hive.exec.dynamic.partition.mode", "nonstrict"),
+ (SQLConf.USE_NULLS_FOR_MISSING_DEFAULT_COLUMN_VALUES.key, "true")) {
+ sql(s"INSERT INTO TABLE $tableName PARTITION (b=2, c=3) SELECT 1, 4")
+
+ sql(s"INSERT INTO TABLE $tableName PARTITION (b=6, c=7) SELECT 5, 8")
+
+ sql(s"INSERT INTO TABLE $tableName PARTITION (c=11, b=10) SELECT 9,
12")
+
+ // c is defined twice. Analyzer will complain.
+ intercept[AnalysisException] {
+ sql(s"INSERT INTO TABLE $tableName PARTITION (b=14, c=15, c=16)
SELECT 13")
+ }
+
+ // d is not a partitioning column.
+ intercept[AnalysisException] {
+ sql(s"INSERT INTO TABLE $tableName PARTITION (b=14, c=15, d=16)
SELECT 13, 14")
+ }
+
+ // d is not a partitioning column. The total number of columns is
correct.
+ intercept[AnalysisException] {
+ sql(s"INSERT INTO TABLE $tableName PARTITION (b=14, c=15, d=16)
SELECT 13")
+ }
+
+ // The data is missing a column.
+ sql(s"INSERT INTO TABLE $tableName PARTITION (c=15, b=16) SELECT 13")
+
+ // d is not a partitioning column.
+ intercept[AnalysisException] {
+ sql(s"INSERT INTO TABLE $tableName PARTITION (b=15, d=15) SELECT 13,
14")
+ }
+
+ // The statement is missing a column.
+ intercept[AnalysisException] {
+ sql(s"INSERT INTO TABLE $tableName PARTITION (b=15) SELECT 13, 14")
+ }
+
+ // The statement is missing a column.
+ intercept[AnalysisException] {
+ sql(s"INSERT INTO TABLE $tableName PARTITION (b=15) SELECT 13, 14,
16")
+ }
+
+ sql(s"INSERT INTO TABLE $tableName PARTITION (b=14, c) SELECT 13, 16,
15")
+
+ // Dynamic partitioning columns need to be after static partitioning
columns.
+ intercept[AnalysisException] {
+ sql(s"INSERT INTO TABLE $tableName PARTITION (b, c=19) SELECT 17,
20, 18")
+ }
+
+ sql(s"INSERT INTO TABLE $tableName PARTITION (b, c) SELECT 17, 20, 18,
19")
Review Comment:
shall we group all the insertions together?
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]