Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add the checking logic in next commit and fix bug for changing commen…
…t of partition column
  • Loading branch information
xuanyuanking committed Jul 24, 2018
commit d8982b1ce8294c9234f88b9adaf649cb8dd0c6f6
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Copy link
Member

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?

Copy link
Member Author

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.

throw new AnalysisException(
"ALTER TABLE CHANGE COLUMN is not supported for changing column " +
Expand All @@ -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) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just adding a check here when user changing the type of partition columns.

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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please compare the error message.

Copy link
Member Author

Choose a reason for hiding this comment

The 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") {
Expand Down