dongjoon-hyun commented on code in PR #50959: URL: https://github.com/apache/spark/pull/50959#discussion_r2100442726
########## sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/TypeCoercionBase.scala: ########## @@ -81,6 +87,66 @@ abstract class TypeCoercionBase extends TypeCoercionHelper { } } + object DefaultValueExpressionCoercion extends Rule[LogicalPlan] { + override def apply(plan: LogicalPlan): LogicalPlan = plan resolveOperators { + case createTable @ CreateTable(_, cols, _, _, _) if createTable.resolved && + cols.exists(_.defaultValue.isDefined) => + val newCols = cols.map { c => + c.copy(defaultValue = c.defaultValue.map(d => + d.copy(child = ResolveDefaultColumns.coerceDefaultValue( + d.child, + c.dataType, + "CREATE TABLE", + c.name, + d.originalSQL, + castWiderOnlyLiterals = false)))) + } + createTable.copy(columns = newCols) + + case replaceTable @ ReplaceTable(_, cols, _, _, _) if replaceTable.resolved && + cols.exists(_.defaultValue.isDefined) => + val newCols = cols.map { c => + c.copy(defaultValue = c.defaultValue.map(d => + d.copy(child = ResolveDefaultColumns.coerceDefaultValue( + d.child, + c.dataType, + "REPLACE TABLE", + c.name, + d.originalSQL, + castWiderOnlyLiterals = false)))) + } + replaceTable.copy(columns = newCols) + + case addColumns @ AddColumns(_, cols) if addColumns.resolved && + cols.exists(_.default.isDefined) => + val newCols = cols.map { c => + c.copy(default = c.default.map(d => + d.copy(child = ResolveDefaultColumns.coerceDefaultValue( + d.child, + c.dataType, + "ALTER TABLE ADD COLUMNS", + c.colName, + d.originalSQL, + castWiderOnlyLiterals = false)))) + } + addColumns.copy(columnsToAdd = newCols) + case alterColumns @ AlterColumns(_, specs) if alterColumns.resolved && Review Comment: nit. Could you add an empty line before this? -- 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