Github user gatorsmile commented on a diff in the pull request:

    https://github.com/apache/spark/pull/15797#discussion_r87141007
  
    --- Diff: 
sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveExternalCatalog.scala ---
    @@ -810,13 +825,44 @@ private[spark] class HiveExternalCatalog(conf: 
SparkConf, hadoopConf: Configurat
           newSpecs: Seq[TablePartitionSpec]): Unit = withClient {
         client.renamePartitions(
           db, table, specs.map(lowerCasePartitionSpec), 
newSpecs.map(lowerCasePartitionSpec))
    +
    +    val tableMeta = getTable(db, table)
    +    val partitionColumnNames = tableMeta.partitionColumnNames
    +    // Hive metastore is not case preserving and keeps partition columns 
with lower cased names.
    +    // When Hive rename partition for managed tables, it will create the 
partition location with
    +    // a default path generate by the new spec with lower cased partition 
column names. This is
    +    // unexpected and we need to rename them manually and alter the 
partition location.
    +    val hasUpperCasePartitionColumn = partitionColumnNames.exists(col => 
col.toLowerCase != col)
    +    if (tableMeta.tableType == MANAGED && hasUpperCasePartitionColumn) {
    +      val tablePath = new Path(tableMeta.location)
    +      val fs = tablePath.getFileSystem(hadoopConf)
    +      val newParts = newSpecs.map { spec =>
    +        val partition = client.getPartition(db, table, 
lowerCasePartitionSpec(spec))
    +        val wrongPath = new Path(partition.storage.locationUri.get)
    +        val rightPath = ExternalCatalogUtils.generatePartitionPath(
    +          spec, partitionColumnNames, tablePath)
    +        try {
    +          fs.rename(wrongPath, rightPath)
    +        } catch {
    +          case e: IOException =>
    +            throw new SparkException(s"Unable to rename partition path 
$wrongPath", e)
    --- End diff --
    
    Maybe we also need to add `rightPath` here


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to