-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-22546][SQL] Supporting for changing column dataType #19773
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
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
…t of partition column
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -318,7 +318,7 @@ case class AlterTableChangeColumnCommand( | |
|
|
||
| // Find the origin column from dataSchema by column name. | ||
| val originColumn = findColumnByName(table.dataSchema, columnName, resolver) | ||
| // Throw an AnalysisException if the column name/dataType is changed. | ||
| // Throw an AnalysisException if the column name is changed. | ||
| if (!columnEqual(originColumn, newColumn, resolver)) { | ||
| throw new AnalysisException( | ||
| "ALTER TABLE CHANGE COLUMN is not supported for changing column " + | ||
|
|
@@ -327,6 +327,16 @@ case class AlterTableChangeColumnCommand( | |
| } | ||
|
|
||
| val typeChanged = originColumn.dataType != newColumn.dataType | ||
| val partitionColumnChanged = table.partitionColumnNames.contains(originColumn.name) | ||
|
|
||
| // Throw an AnalysisException if the type of partition column is changed. | ||
| if (typeChanged && partitionColumnChanged) { | ||
|
||
| throw new AnalysisException( | ||
| "ALTER TABLE CHANGE COLUMN is not supported for changing partition column" + | ||
| s"'${originColumn.name}' with type '${originColumn.dataType}' to " + | ||
| s"'${newColumn.name}' with type '${newColumn.dataType}'") | ||
| } | ||
|
|
||
| val newDataSchema = table.dataSchema.fields.map { field => | ||
| if (field.name == originColumn.name) { | ||
| // Add the comment to a column, if comment is empty, return the original column. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1702,6 +1702,11 @@ abstract class DDLSuite extends QueryTest with SQLTestUtils { | |
| sql("ALTER TABLE dbx.tab1 CHANGE COLUMN col1 col1 STRING") | ||
| val column = catalog.getTableMetadata(tableIdent).schema.fields.find(_.name == "col1") | ||
| assert(column.get.dataType == StringType) | ||
|
|
||
| // Ensure that changing partition column type throw exception | ||
| intercept[AnalysisException] { | ||
| sql("ALTER TABLE dbx.tab1 CHANGE COLUMN a a STRING") | ||
| } | ||
|
Member
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. Please compare the error message.
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. Thanks, done in ef65c4d. Also add check for type compatible check. |
||
| } | ||
|
|
||
| test("drop build-in function") { | ||
|
|
||
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.
Its ok to check names only?
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.
Thanks, not enough yet, add type compatible check in ef65c4d.