-
Notifications
You must be signed in to change notification settings - Fork 29.3k
[SPARK-29680][SQL] Remove ALTER TABLE CHANGE COLUMN syntax #26338
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
91c8e58
a432da7
05f0584
17a34c2
dade338
fb7564a
9e7a678
ac76822
64a68fc
b2acddb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -151,7 +151,7 @@ statement | |||||||||||||||||||
| | ALTER TABLE multipartIdentifier | ||||||||||||||||||||
| (ALTER | CHANGE) COLUMN? qualifiedName | ||||||||||||||||||||
| (TYPE dataType)? (COMMENT comment=STRING)? colPosition? #alterTableColumn | ||||||||||||||||||||
| | ALTER TABLE tableIdentifier partitionSpec? | ||||||||||||||||||||
| | ALTER TABLE multipartIdentifier partitionSpec? | ||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm, the parser rule above seems to include this one?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the above one is for v2 command. two rules have a bit difference. v1 rule can specify new column name with data type (i.e.,
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did not combine two rules and two statements. A possible combine might have few Option fields and a logic to interpret it to v1/v2 cases, a bit mess it sounds like.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The v2 rule The Seems like the v1 rule is more powerful and can rename a column and change data type together. If other DBs support it as well, maybe Spark should also support it. Otherwise, maybe 3.0 is a good time to drop this syntax.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems we do not really support it, though we allow such syntax: spark/sql/core/src/main/scala/org/apache/spark/sql/execution/command/ddl.scala Lines 343 to 351 in 7aca0dd
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure what if the original plan was to support that in the future.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's simply remove this syntax. We have ALTER TABLE CHANGE COLUMN and ALTER TABLE RENAME COLUMN, which is good enough to me.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok. let's remove it. |
||||||||||||||||||||
| CHANGE COLUMN? | ||||||||||||||||||||
| colName=errorCapturingIdentifier colType colPosition? #changeColumn | ||||||||||||||||||||
| | ALTER TABLE tableIdentifier (partitionSpec)? | ||||||||||||||||||||
|
|
||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,7 +24,7 @@ import org.apache.spark.sql.catalyst.plans.logical._ | |
| import org.apache.spark.sql.catalyst.rules.Rule | ||
| import org.apache.spark.sql.connector.catalog.{CatalogManager, CatalogPlugin, LookupCatalog, TableChange, V1Table} | ||
| import org.apache.spark.sql.connector.expressions.Transform | ||
| import org.apache.spark.sql.execution.command.{AlterTableAddColumnsCommand, AlterTableRecoverPartitionsCommand, AlterTableSetLocationCommand, AlterTableSetPropertiesCommand, AlterTableUnsetPropertiesCommand, AnalyzeColumnCommand, AnalyzePartitionCommand, AnalyzeTableCommand, CacheTableCommand, CreateDatabaseCommand, DescribeColumnCommand, DescribeTableCommand, DropDatabaseCommand, DropTableCommand, LoadDataCommand, ShowColumnsCommand, ShowCreateTableCommand, ShowPartitionsCommand, ShowTablesCommand, TruncateTableCommand, UncacheTableCommand} | ||
| import org.apache.spark.sql.execution.command.{AlterTableAddColumnsCommand, AlterTableChangeColumnCommand, AlterTableRecoverPartitionsCommand, AlterTableSetLocationCommand, AlterTableSetPropertiesCommand, AlterTableUnsetPropertiesCommand, AnalyzeColumnCommand, AnalyzePartitionCommand, AnalyzeTableCommand, CacheTableCommand, CreateDatabaseCommand, DescribeColumnCommand, DescribeTableCommand, DropDatabaseCommand, DropTableCommand, LoadDataCommand, ShowColumnsCommand, ShowCreateTableCommand, ShowPartitionsCommand, ShowTablesCommand, TruncateTableCommand, UncacheTableCommand} | ||
| import org.apache.spark.sql.execution.datasources.{CreateTable, DataSource, RefreshTable} | ||
| import org.apache.spark.sql.execution.datasources.v2.FileDataSourceV2 | ||
| import org.apache.spark.sql.internal.SQLConf | ||
|
|
@@ -369,6 +369,13 @@ class ResolveSessionCatalog( | |
| AlterTableRecoverPartitionsCommand( | ||
| v1TableName.asTableIdentifier, | ||
| "ALTER TABLE RECOVER PARTITIONS") | ||
|
|
||
| case AlterTableChangeColumnStatement(tableName, columnName, newColumn) => | ||
| val v1TableName = parseV1Table(tableName, "ALTER TABLE CHANGE COLUMN") | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems this command can also work on V2, if old column name and new column name is the same. cc @cloud-fan |
||
| AlterTableChangeColumnCommand( | ||
| v1TableName.asTableIdentifier, | ||
| columnName, | ||
| newColumn) | ||
| } | ||
|
|
||
| private def parseV1Table(tableName: Seq[String], sql: String): Seq[String] = { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can distinguish the two
multipartIdentifierYou can fix it in your followup
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok.