Skip to content

Commit a7b9a17

Browse files
committed
modify the check logic
1 parent 232a835 commit a7b9a17

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/rules.scala

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -407,10 +407,8 @@ case class PreprocessTableInsertion(conf: SQLConf) extends Rule[LogicalPlan] {
407407
catalogTable.isDefined &&
408408
catalogTable.get.partitionColumnNames.nonEmpty &&
409409
catalogTable.get.tracksPartitionsInCatalog
410-
// check static partition
411410
if (partitionsTrackedByCatalog &&
412-
normalizedPartSpec.nonEmpty &&
413-
staticPartCols.size == partColNames.size) {
411+
normalizedPartSpec.nonEmpty) {
414412
// empty partition column value
415413
if (normalizedPartSpec.filter(_._2.isDefined).exists(_._2.get.isEmpty)) {
416414
val spec = normalizedPartSpec.map(p => p._1 + "=" + p._2).mkString("[", ", ", "]")

sql/core/src/test/scala/org/apache/spark/sql/sources/InsertSuite.scala

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -877,10 +877,17 @@ class InsertSuite extends DataSourceTest with SharedSparkSession {
877877
""".stripMargin)
878878

879879
withSQLConf(SQLConf.HIVE_MANAGE_FILESOURCE_PARTITIONS.key -> "true") {
880-
val e = intercept[AnalysisException] {
880+
val msg = "Partition spec is invalid"
881+
assert(intercept[AnalysisException] {
881882
sql("INSERT INTO TABLE insertTable PARTITION(part1=1, part2='') SELECT 1")
882-
}.getMessage
883-
assert(e.contains("Partition spec is invalid"))
883+
}.getMessage.contains(msg))
884+
assert(intercept[AnalysisException] {
885+
sql("INSERT INTO TABLE insertTable PARTITION(part1='', part2) SELECT 1 ,'' AS part2")
886+
}.getMessage.contains(msg))
887+
888+
sql("INSERT INTO TABLE insertTable PARTITION(part1='1', part2='2') SELECT 1")
889+
sql("INSERT INTO TABLE insertTable PARTITION(part1='1', part2) SELECT 1 ,'2' AS part2")
890+
sql("INSERT INTO TABLE insertTable PARTITION(part1='1', part2) SELECT 1 ,'' AS part2")
884891
}
885892

886893
withSQLConf(SQLConf.HIVE_MANAGE_FILESOURCE_PARTITIONS.key -> "false") {

0 commit comments

Comments
 (0)