Github user andrewor14 commented on a diff in the pull request:
https://github.com/apache/spark/pull/12121#discussion_r58418639
--- 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 --
> Thinking about the error message, users probably do not really what are
data source tables and what are hive tables. So, how about we just say
something like "it is not allowed to modify table properties."
I personally think that's too obscure. It's super confusing when the user
can modify table properties for some tables but not others, and all the error
message says is "it's not allowed". It reminds me of the [super unhelpful Hive
error
message](https://github.com/apache/spark/blob/5743c6476dbef50852b7f9873112a2d299966ebd/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/catalog/CatalogTestCases.scala#L349)
I ran into. Do you have other suggestions on a good message?
---
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]