Skip to content
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

[SPARK-48413][SQL][FOLLOW-UP] Fix ALTER COLUMN with collation #48582

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -1546,7 +1546,10 @@ trait CheckAnalysis extends PredicateHelper with LookupCatalog with QueryErrorsB
.map(dt => col.field.copy(dataType = dt))
.getOrElse(col.field)
val newDataType = a.dataType.get
val sameTypeExceptCollations =
DataType.equalsIgnoreCompatibleCollation(field.dataType, newDataType)
newDataType match {
case _ if sameTypeExceptCollations =>
jovanm-db marked this conversation as resolved.
Show resolved Hide resolved
case _: StructType => alter.failAnalysis(
"CANNOT_UPDATE_FIELD.STRUCT_TYPE",
Map("table" -> toSQLId(table.name), "fieldName" -> toSQLId(fieldName)))
Expand Down Expand Up @@ -1576,7 +1579,7 @@ trait CheckAnalysis extends PredicateHelper with LookupCatalog with QueryErrorsB
case _ => Cast.canUpCast(from, to)
}

if (!canAlterColumnType(field.dataType, newDataType)) {
if (!sameTypeExceptCollations && !canAlterColumnType(field.dataType, newDataType)) {
alter.failAnalysis(
errorClass = "NOT_SUPPORTED_CHANGE_COLUMN",
messageParameters = Map(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,14 @@ class CollationSuite extends DatasourceV2SQLBase with AdaptiveSparkPlanHelper {
}
}

test("SPARK-48413: Alter column with collation") {
Copy link
Contributor

Choose a reason for hiding this comment

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

can we also add tests for complex types (struct, map, array)?

val tableName = "testcat.alter_column_tbl"
withTable(tableName) {
sql(s"CREATE TABLE $tableName (c1 STRING) USING PARQUET")
sql(s"ALTER TABLE $tableName ALTER COLUMN c1 TYPE STRING COLLATE UTF8_LCASE")
}
jovanm-db marked this conversation as resolved.
Show resolved Hide resolved
}

test("SPARK-47210: Implicit casting of collated strings") {
val tableName = "parquet_dummy_implicit_cast_t22"
withTable(tableName) {
Expand Down