planga82 commented on code in PR #39826:
URL: https://github.com/apache/spark/pull/39826#discussion_r1093344579


##########
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/V2SessionCatalog.scala:
##########
@@ -149,26 +150,42 @@ class V2SessionCatalog(catalog: SessionCatalog)
         throw QueryCompilationErrors.noSuchTableError(ident)
     }
 
-    val properties = 
CatalogV2Util.applyPropertiesChanges(catalogTable.properties, changes)
-    val schema = CatalogV2Util.applySchemaChanges(
-      catalogTable.schema, changes, catalogTable.provider, "ALTER TABLE")
-    val comment = properties.get(TableCatalog.PROP_COMMENT)
-    val owner = properties.getOrElse(TableCatalog.PROP_OWNER, 
catalogTable.owner)
-    val location = 
properties.get(TableCatalog.PROP_LOCATION).map(CatalogUtils.stringToURI)
-    val storage = if (location.isDefined) {
-      catalogTable.storage.copy(locationUri = location)
-    } else {
-      catalogTable.storage
+
+    val (columnChanges, otherChanges) = changes.toSeq.partition(change =>
+      change.isInstanceOf[ColumnChange] &&
+        // Not supported changes in alterTableDataSchema
+        !change.isInstanceOf[RenameColumn] && 
!change.isInstanceOf[DeleteColumn]
+    )
+
+    if(columnChanges.size > 0) {
+      val schema = CatalogV2Util.applySchemaChanges(
+        catalogTable.schema, changes, catalogTable.provider, "ALTER TABLE")
+
+      catalog.alterTableDataSchema(ident.asTableIdentifier, schema)
     }
 
-    try {
-      catalog.alterTable(
-        catalogTable.copy(
-          properties = properties, schema = schema, owner = owner, comment = 
comment,
-          storage = storage))
-    } catch {
-      case _: NoSuchTableException =>
-        throw QueryCompilationErrors.noSuchTableError(ident)
+    if(otherChanges.size > 0) {
+      val properties = 
CatalogV2Util.applyPropertiesChanges(catalogTable.properties, changes)
+      val schema = CatalogV2Util.applySchemaChanges(
+        catalogTable.schema, changes, catalogTable.provider, "ALTER TABLE")

Review Comment:
   yes, you are right, thank you!



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