[HUDI-3237] gracefully fail to change column data type (#4677)
This commit is contained in:
@@ -312,4 +312,10 @@ object HoodieSqlCommonUtils extends SparkAdapterSupport {
|
||||
case field if resolver(field.name, name) => field
|
||||
}
|
||||
}
|
||||
|
||||
// Compare a [[StructField]] to another, return true if they have the same column
|
||||
// name(by resolver) and dataType.
|
||||
def columnEqual(field: StructField, other: StructField, resolver: Resolver): Boolean = {
|
||||
resolver(field.name, other.name) && field.dataType == other.dataType
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,6 +49,13 @@ case class AlterHoodieTableChangeColumnCommand(
|
||||
throw new AnalysisException(s"Can't find column `$columnName` given table data columns " +
|
||||
s"${hoodieCatalogTable.dataSchema.fieldNames.mkString("[`", "`, `", "`]")}")
|
||||
)
|
||||
// Throw an AnalysisException if the column name/dataType is changed.
|
||||
if (!columnEqual(originColumn, newColumn, resolver)) {
|
||||
throw new AnalysisException(
|
||||
"ALTER TABLE CHANGE COLUMN is not supported for changing column " +
|
||||
s"'${originColumn.name}' with type '${originColumn.dataType}' to " +
|
||||
s"'${newColumn.name}' with type '${newColumn.dataType}'")
|
||||
}
|
||||
|
||||
// Get the new schema
|
||||
val newTableSchema = StructType(
|
||||
|
||||
Reference in New Issue
Block a user