dongjoon-hyun commented on a change in pull request #24723: [SPARK-27857][SQL] 
Move ALTER TABLE parsing into Catalyst
URL: https://github.com/apache/spark/pull/24723#discussion_r289662310
 
 

 ##########
 File path: 
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/DataSourceResolution.scala
 ##########
 @@ -98,6 +98,42 @@ case class DataSourceResolution(
 
     case DropViewStatement(AsTableIdentifier(tableName), ifExists) =>
       DropTableCommand(tableName, ifExists, isView = true, purge = false)
+
+    case AlterTableSetPropertiesStatement(AsTableIdentifier(table), 
properties) =>
+      AlterTableSetPropertiesCommand(table, properties, isView = false)
+
+    case AlterViewSetPropertiesStatement(AsTableIdentifier(table), properties) 
=>
+      AlterTableSetPropertiesCommand(table, properties, isView = true)
+
+    case AlterTableUnsetPropertiesStatement(AsTableIdentifier(table), 
propertyKeys, ifExists) =>
+      AlterTableUnsetPropertiesCommand(table, propertyKeys, ifExists, isView = 
false)
+
+    case AlterViewUnsetPropertiesStatement(AsTableIdentifier(table), 
propertyKeys, ifExists) =>
+      AlterTableUnsetPropertiesCommand(table, propertyKeys, ifExists, isView = 
true)
+
+    case AlterTableSetLocationStatement(AsTableIdentifier(table), newLocation) 
=>
+      AlterTableSetLocationCommand(table, None, newLocation)
+
+    case AlterTableAddColumnsStatement(AsTableIdentifier(table), newColumns)
+        if newColumns.forall(_.name.size == 1) =>
+      // only top-level adds are supported using AlterTableAddColumnsCommand
+      val newFields = newColumns.map { newCol =>
+        val builder = new MetadataBuilder
+        newCol.comment.foreach(builder.putString("comment", _))
+
+        val cleanedDataType = HiveStringType.replaceCharType(newCol.dataType)
+        if (newCol.dataType != cleanedDataType) {
+          builder.putString(HIVE_TYPE_STRING, newCol.dataType.catalogString)
+        }
+
+        StructField(
+          newCol.name.head,
+          cleanedDataType,
+          nullable = true,
+          builder.build())
+      }
 
 Review comment:
   Could you make a function for line 120~134 because it seems that we need to 
reuse this logic for `AlterTableAlterColumnStatement` very soon?

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to