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


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

Review Comment:
   should this be in try-catch like the `alterTable` call?



##########
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")

Review Comment:
   shouldn't we use `columnChanges` instead of `changes` here?



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

Review Comment:
   This seems awkward. In `SessionCatalog` I see there is a comment "not 
supporting dropping columns **yet**" (emphasis added), should we instead make 
the change to allow this within `alterTableDataSchema`? It seems that it can 
make this much cleaner and have a clear separation of schema changes from 
`alterTableDataSchema` vs other changes in `alterTable`.



##########
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:
   should this be `otherChanges` instead of `changes`?



##########
sql/hive/src/test/scala/org/apache/spark/sql/hive/HiveExternalV2SessionCatalogSuite.scala:
##########
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.spark.sql.hive
+
+import org.scalactic.source.Position
+import org.scalatest.Tag
+
+import org.apache.spark.sql.execution.datasources.v2.{V2SessionCatalog, 
V2SessionCatalogTableBaseSuite}
+import org.apache.spark.sql.hive.test.TestHiveSingleton
+import org.apache.spark.sql.util.CaseInsensitiveStringMap
+
+
+  class HiveExternalV2SessionCatalogTableSuite extends 
V2SessionCatalogTableBaseSuite
+    with TestHiveSingleton {
+
+  override def newCatalog(): V2SessionCatalog = {
+    val newCatalog = new V2SessionCatalog(spark.sessionState.catalog)
+    newCatalog.initialize("test", CaseInsensitiveStringMap.empty())
+    newCatalog
+  }

Review Comment:
   isn't this the same definition as in the base class? am I missing anything?



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