cloud-fan commented on code in PR #51001: URL: https://github.com/apache/spark/pull/51001#discussion_r2110780641
########## sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/ApplyDefaultCollationToStringType.scala: ########## @@ -151,22 +150,82 @@ object ApplyDefaultCollationToStringType extends Rule[LogicalPlan] { case p if isCreateOrAlterPlan(p) || AnalysisContext.get.collation.isDefined => transformPlan(p, newType) - case addCols: AddColumns => + case addCols@AddColumns(_: ResolvedTable, _) => addCols.copy(columnsToAdd = replaceColumnTypes(addCols.columnsToAdd, newType)) - case replaceCols: ReplaceColumns => + case replaceCols@ReplaceColumns(_: ResolvedTable, _) => replaceCols.copy(columnsToAdd = replaceColumnTypes(replaceCols.columnsToAdd, newType)) - case a @ AlterColumns(_, specs: Seq[AlterColumnSpec]) => + case a @ AlterColumns(ResolvedTable(_, _, table: Table, _), specs: Seq[AlterColumnSpec]) => val newSpecs = specs.map { - case spec if spec.newDataType.isDefined && hasDefaultStringType(spec.newDataType.get) => + case spec if shouldApplyDefaultCollationToAlterColumn(spec, table) => spec.copy(newDataType = Some(replaceDefaultStringType(spec.newDataType.get, newType))) case col => col } a.copy(specs = newSpecs) } } + /** + * The column type should not be changed if the original column type is [[StringType]] and the new + * type is the default [[StringType]] (i.e., [[StringType]] without an explicit collation). + * + * Query Example: + * {{{ + * CREATE TABLE t (c1 STRING COLLATE UNICODE) + * ALTER TABLE t ALTER COLUMN c1 TYPE STRING -- c1 will remain STRING COLLATE UNICODE Review Comment: cc @srielau -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org