Github user yhuai commented on a diff in the pull request: https://github.com/apache/spark/pull/12121#discussion_r58297607 --- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/command/ddl.scala --- @@ -195,67 +195,133 @@ case class DropFunction( isTemp: Boolean)(sql: String) extends NativeDDLCommand(sql) with Logging -/** Rename in ALTER TABLE/VIEW: change the name of a table/view to a different name. */ +/** + * A command that renames a table/view. + * + * The syntax of this command is: + * {{{ + * ALTER TABLE table1 RENAME TO table2; + * ALTER VIEW view1 RENAME TO view2; + * }}} + */ case class AlterTableRename( oldName: TableIdentifier, - newName: TableIdentifier)(sql: String) - extends NativeDDLCommand(sql) with Logging + newName: TableIdentifier) + extends RunnableCommand { + + override def run(sqlContext: SQLContext): Seq[Row] = { + sqlContext.sessionState.catalog.renameTable(oldName, newName) + Seq.empty[Row] + } -/** Set Properties in ALTER TABLE/VIEW: add metadata to a table/view. */ +} + +/** + * A command that sets table/view properties. + * + * The syntax of this command is: + * {{{ + * ALTER TABLE table1 SET TBLPROPERTIES ('key1' = 'val1', 'key2' = 'val2', ...); + * ALTER VIEW view1 SET TBLPROPERTIES ('key1' = 'val1', 'key2' = 'val2', ...); + * }}} + */ case class AlterTableSetProperties( tableName: TableIdentifier, - properties: Map[String, String])(sql: String) - extends NativeDDLCommand(sql) with Logging + properties: Map[String, String]) + extends RunnableCommand { -/** Unset Properties in ALTER TABLE/VIEW: remove metadata from a table/view. */ + override def run(sqlContext: SQLContext): Seq[Row] = { + val catalog = sqlContext.sessionState.catalog + val table = catalog.getTable(tableName) + val newProperties = table.properties ++ properties + // TODO: make this a constant + if (newProperties.contains("spark.sql.sources.provider")) { + throw new AnalysisException( + "alter table properties is not supported for datasource tables") + } --- End diff -- I am wondering maybe we can enforce this check. For example, a command for alter table does not implement `run` directly. Instead, a command implements one method for processing data source tables and another one for processing hive tables. The method `run` is implemented in the base class.
--- 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