imback82 commented on a change in pull request #33200:
URL: https://github.com/apache/spark/pull/33200#discussion_r673289064
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/CheckAnalysis.scala
##########
@@ -1025,17 +938,23 @@ trait CheckAnalysis extends PredicateHelper with
LookupCatalog {
/**
* Validates the options used for alter table commands after table and
columns are resolved.
*/
- private def checkAlterTableCommand(alter: AlterTableCommand): Unit = {
- def checkColumnNotExists(fieldNames: Seq[String], struct: StructType):
Unit = {
+ private def checkAlterTableColumnCommand(alter: AlterTableColumnCommand):
Unit = {
+ def checkColumnNotExists(op: String, fieldNames: Seq[String], struct:
StructType): Unit = {
if (struct.findNestedField(fieldNames, includeCollections =
true).isDefined) {
- alter.failAnalysis(s"Cannot ${alter.operation} column, because
${fieldNames.quoted} " +
+ alter.failAnalysis(s"Cannot $op column, because ${fieldNames.quoted} "
+
s"already exists in ${struct.treeString}")
}
}
alter match {
+ case AlterTableAddColumns(table: ResolvedTable, colsToAdd) =>
+ colsToAdd.foreach { colToAdd =>
+ checkColumnNotExists("add", colToAdd.name, table.schema)
Review comment:
For v1 command, this is checked in
[AlterTableAddColumnsCommand](https://github.com/apache/spark/blob/c0d84e6cf1046b7944796038414ef21fe9c7e3b5/sql/core/src/main/scala/org/apache/spark/sql/execution/command/tables.scala#L235),
but for v2, this is not checked and it's up to the catalog implementation to
handle it. Is this a bug? If so, I can fix this as a separate PR.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]