Github user andrewor14 commented on a diff in the pull request: https://github.com/apache/spark/pull/12121#discussion_r58440925 --- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/command/ddl.scala --- @@ -312,11 +378,38 @@ case class AlterTableSetFileFormat( genericFormat: Option[String])(sql: String) extends NativeDDLCommand(sql) with Logging +/** + * A command that sets the location of a table or a partition. + * + * The syntax of this command is: + * {{{ + * ALTER TABLE table_name [PARTITION partition_spec] SET LOCATION "loc"; + * }}} + */ case class AlterTableSetLocation( tableName: TableIdentifier, partitionSpec: Option[TablePartitionSpec], - location: String)(sql: String) - extends NativeDDLCommand(sql) with Logging + location: String) + extends RunnableCommand { + + override def run(sqlContext: SQLContext): Seq[Row] = { + val catalog = sqlContext.sessionState.catalog + if (partitionSpec.isEmpty) { + // No partition spec is specified, so we set the location for the table itself + val table = catalog.getTable(tableName) + val newTable = table.withNewStorage(locationUri = Some(location)) + catalog.alterTable(newTable) + } else { + // Partition spec is specified, so we set the location only for this partition + val spec = partitionSpec.get + val part = catalog.getPartition(tableName, spec) + val newPart = part.copy(storage = part.storage.copy(locationUri = Some(location))) + catalog.alterPartitions(tableName, Seq(newPart)) + } + Seq.empty[Row] + } + +} --- End diff -- done
--- 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