diff --git a/sql/hive/src/main/scala/org/apache/spark/sql/hive/execution/InsertIntoHiveTable.scala b/sql/hive/src/main/scala/org/apache/spark/sql/hive/execution/InsertIntoHiveTable.scala index 9f83f2ab96094..116217ecec0ba 100644 --- a/sql/hive/src/main/scala/org/apache/spark/sql/hive/execution/InsertIntoHiveTable.scala +++ b/sql/hive/src/main/scala/org/apache/spark/sql/hive/execution/InsertIntoHiveTable.scala @@ -29,6 +29,7 @@ import org.apache.spark.sql.{AnalysisException, Row, SparkSession} import org.apache.spark.sql.catalyst.catalog._ import org.apache.spark.sql.catalyst.expressions.Attribute import org.apache.spark.sql.catalyst.plans.logical.LogicalPlan +import org.apache.spark.sql.catalyst.util.CaseInsensitiveMap import org.apache.spark.sql.execution.SparkPlan import org.apache.spark.sql.execution.command.CommandUtils import org.apache.spark.sql.hive.HiveExternalCatalog @@ -225,9 +226,12 @@ case class InsertIntoHiveTable( ExternalCatalogUtils.unescapePathName(splitPart(1)) }.toMap + val caseInsensitiveDpMap = CaseInsensitiveMap(dpMap) + val updatedPartitionSpec = partition.map { case (key, Some(value)) => key -> value - case (key, None) if dpMap.contains(key) => key -> dpMap(key) + case (key, None) if caseInsensitiveDpMap.contains(key) => + key -> caseInsensitiveDpMap(key) case (key, _) => throw new SparkException(s"Dynamic partition key $key is not among " + "written partition paths.") diff --git a/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/SQLQuerySuite.scala b/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/SQLQuerySuite.scala index 79c6ade2807d3..d12eae0e410b1 100644 --- a/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/SQLQuerySuite.scala +++ b/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/SQLQuerySuite.scala @@ -2544,6 +2544,19 @@ abstract class SQLQuerySuiteBase extends QueryTest with SQLTestUtils with TestHi assert(e.getMessage.contains("Cannot modify the value of a static config")) } } + + test("SPARK-29295: dynamic partition map parsed from partition path should be case insensitive") { + withTable("t") { + withSQLConf("hive.exec.dynamic.partition" -> "true", + "hive.exec.dynamic.partition.mode" -> "nonstrict") { + withTempDir { loc => + sql(s"CREATE TABLE t(c1 INT) PARTITIONED BY(P1 STRING) LOCATION '${loc.getAbsolutePath}'") + sql("INSERT OVERWRITE TABLE t PARTITION(P1) VALUES(1, 'caseSensitive')") + checkAnswer(sql("select * from t"), Row(1, "caseSensitive")) + } + } + } + } } class SQLQuerySuite extends SQLQuerySuiteBase with DisableAdaptiveExecutionSuite