diff --git a/sql/core/src/main/scala/org/apache/spark/sql/execution/command/ddl.scala b/sql/core/src/main/scala/org/apache/spark/sql/execution/command/ddl.scala index 2fc6d6fd85..3e91dab6a5 100644 --- a/sql/core/src/main/scala/org/apache/spark/sql/execution/command/ddl.scala +++ b/sql/core/src/main/scala/org/apache/spark/sql/execution/command/ddl.scala @@ -848,7 +848,12 @@ case class AlterTableSetLocationCommand( DDLUtils.verifyPartitionProviderIsHive( sparkSession, table, "ALTER TABLE ... SET LOCATION") // Partition spec is specified, so we set the location only for this partition - val part = catalog.getPartition(table.identifier, spec) + val normalizedSpec = PartitioningUtils.normalizePartitionSpec( + spec, + table.partitionSchema, + table.identifier.quotedString, + sparkSession.sessionState.conf.resolver) + val part = catalog.getPartition(table.identifier, normalizedSpec) val newPart = part.copy(storage = part.storage.copy(locationUri = Some(locUri))) catalog.alterPartitions(table.identifier, Seq(newPart)) case None => diff --git a/sql/core/src/test/scala/org/apache/spark/sql/execution/command/DDLSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/execution/command/DDLSuite.scala index 7086c31082..19b5118a23 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/execution/command/DDLSuite.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/execution/command/DDLSuite.scala @@ -1261,6 +1261,17 @@ abstract class DDLSuite extends QueryTest with SQLTestUtils { // set table partition location sql("ALTER TABLE dbx.tab1 PARTITION (a='1', b='2') SET LOCATION '/path/to/part/ways'") verifyLocation(new URI("/path/to/part/ways"), Some(partSpec)) + // set location for partition spec in the upper case + withSQLConf(SQLConf.CASE_SENSITIVE.key -> "false") { + sql("ALTER TABLE dbx.tab1 PARTITION (A='1', B='2') SET LOCATION '/path/to/part/ways2'") + verifyLocation(new URI("/path/to/part/ways2"), Some(partSpec)) + } + withSQLConf(SQLConf.CASE_SENSITIVE.key -> "true") { + val errMsg = intercept[AnalysisException] { + sql("ALTER TABLE dbx.tab1 PARTITION (A='1', B='2') SET LOCATION '/path/to/part/ways3'") + }.getMessage + assert(errMsg.contains("not a valid partition column")) + } // set table location without explicitly specifying database catalog.setCurrentDatabase("dbx") sql("ALTER TABLE tab1 SET LOCATION '/swanky/steak/place'")