Github user gatorsmile commented on a diff in the pull request:
https://github.com/apache/spark/pull/15717#discussion_r92120744
--- Diff:
sql/core/src/main/scala/org/apache/spark/sql/execution/command/ddl.scala ---
@@ -274,6 +274,76 @@ case class AlterTableUnsetPropertiesCommand(
}
+
+/**
+ * A command to change the columns for a table, only support changing the
comments of non-partition
+ * columns for now.
+ *
+ * The syntax of using this command in SQL is:
+ * {{{
+ * ALTER TABLE table_identifier
+ * CHANGE [COLUMN] column_old_name column_new_name column_dataType
[COMMENT column_comment]
+ * [FIRST | AFTER column_name];
+ * }}}
+ */
+case class AlterTableChangeColumnsCommand(
+ tableName: TableIdentifier,
+ columns: Map[String, StructField]) extends RunnableCommand {
+
+ // TODO: support change column name/dataType/metadata/position.
+ override def run(sparkSession: SparkSession): Seq[Row] = {
+ val catalog = sparkSession.sessionState.catalog
+ val table = catalog.getTableMetadata(tableName)
+ val resolver = sparkSession.sessionState.conf.resolver
+ DDLUtils.verifyAlterTableType(catalog, table, isView = false)
+
+ // Create a map that converts the origin column to the new column with
changed comment, throw
+ // a Exception if the column reference is invalid or the column
name/dataType is changed.
+ val columnsMap = columns.map { case (oldName: String, newField:
StructField) =>
+ // Find the origin column from schema by column name.
+ val originColumn = findColumn(table.schema, oldName, resolver)
+ // Throw a Exception if the column name/dataType is changed.
+ if (!columnEqual(originColumn, newField, resolver)) {
+ throw new AnalysisException(
+ "ALTER TABLE CHANGE COLUMN is not supported for changing column
" +
+ s"'${originColumn.name}' with type '${originColumn.dataType}'
to " +
+ s"'${newField.name}' with type '${newField.dataType}'")
+ }
+ // Create a new column from the origin column with new comment.
--- End diff --
Actually, the rule is very simple.
> A countable noun always takes either the indefinite (a, an) or definite
(the) article when it is singular. When plural, it takes the definite article
if it refers to a definite, specific group and no article if it is used in a
general sense.
---
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]