cloud-fan commented on a change in pull request #33200:
URL: https://github.com/apache/spark/pull/33200#discussion_r672831210



##########
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:
       What if the to-be-added columns have duplicated names? e.g. `ADD COLUMNS 
a ..., a ...`




-- 
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]

Reply via email to