Github user ericl commented on a diff in the pull request:
https://github.com/apache/spark/pull/15797#discussion_r86868525
--- Diff:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/InMemoryCatalog.scala
---
@@ -423,33 +424,35 @@ class InMemoryCatalog(
requirePartitionsExist(db, table, specs)
requirePartitionsNotExist(db, table, newSpecs)
- val tableDir = new Path(catalog(db).db.locationUri, table)
- val partitionColumnNames = getTable(db, table).partitionColumnNames
+ val tableMeta = getTable(db, table)
+ val partitionColumnNames = tableMeta.partitionColumnNames
+ val tableLocation = new Path(tableMeta.storage.locationUri.get)
+ val shouldUpdatePartitionLocation = getTable(db, table).tableType ==
CatalogTableType.MANAGED
+ val existingParts = catalog(db).tables(table).partitions
// TODO: we should follow hive to roll back if one partition path
failed to rename.
specs.zip(newSpecs).foreach { case (oldSpec, newSpec) =>
- val newPart = getPartition(db, table, oldSpec).copy(spec = newSpec)
- val existingParts = catalog(db).tables(table).partitions
-
- // If location is set, the partition is using an external partition
location and we don't
- // need to handle its directory.
- if (newPart.storage.locationUri.isEmpty) {
- val oldPath = partitionColumnNames.flatMap { col =>
- oldSpec.get(col).map(col + "=" + _)
- }.mkString("/")
- val newPath = partitionColumnNames.flatMap { col =>
- newSpec.get(col).map(col + "=" + _)
- }.mkString("/")
+ val oldPartition = getPartition(db, table, oldSpec)
+ val newPartition = if (shouldUpdatePartitionLocation) {
+ val oldPartPath = new Path(oldPartition.storage.locationUri.get)
+ val newPartPath = new Path(
+ tableLocation,
+ partitionColumnNames.map(col => col + "=" +
newSpec(col)).mkString("/"))
--- End diff --
Should we pull this into PartitioningUtils?
---
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 [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]