aokolnychyi commented on code in PR #55518:
URL: https://github.com/apache/spark/pull/55518#discussion_r3787781513


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/RewriteUpdateTable.scala:
##########
@@ -155,29 +254,125 @@ object RewriteUpdateTable extends RewriteRowLevelCommand 
{
 
     val operation = operationTable.operation.asInstanceOf[SupportsDelta]
 
-    // resolve all needed attrs (e.g. row ID and any required metadata attrs)
+    // resolve all needed attrs (e.g. row ID, any required metadata attrs and 
optionally connector
+    // declared attrs)
     val rowAttrs = relation.output
+    val supportsColumnUpdate = operation.isInstanceOf[SupportsColumnUpdates]
+    val connectorDataAttrs = if (supportsColumnUpdate) {
+      resolveConnectorDataAttrs(relation, operation)
+    } else Nil
+    val scanOnlyDataAttrs = if (supportsColumnUpdate) {
+      resolveScanOnlyDataAttrs(relation, operation)
+    } else Nil
+
+    if (supportsColumnUpdate) {
+      validateUpdatedColumnsSubset(operation, assignments, connectorDataAttrs)
+      validateNoOverlap(operation, connectorDataAttrs, scanOnlyDataAttrs)
+      validatePartitionAttrsDeclared(operation, relation, connectorDataAttrs, 
scanOnlyDataAttrs)
+    }
+
+
     val rowIdAttrs = resolveRowIdAttrs(relation, operation)
     val metadataAttrs = resolveRequiredMetadataAttrs(relation, operation)
 
-    // construct a read relation and include all required metadata columns
-    val readRelation = buildRelationWithAttrs(relation, operationTable, 
metadataAttrs, rowIdAttrs)
+    if (supportsColumnUpdate && operation.representUpdateAsDeleteAndInsert) {
+      validateNoRowIdReassignment(operation, assignments, rowIdAttrs)
+      validateRowIdDeclared(operation, connectorDataAttrs, rowIdAttrs)
+    }
+
+    val narrowDataAttrs = if (supportsColumnUpdate) {
+      computeNarrowReadAttrs(relation, connectorDataAttrs, scanOnlyDataAttrs, 
assignments, cond)
+    } else {
+      relation.output
+    }
+
+    val readRelation = if (supportsColumnUpdate) {
+      buildNarrowRelationWithAttrs(relation, operationTable, narrowDataAttrs, 
metadataAttrs,
+        rowIdAttrs)
+    } else {
+      buildRelationWithAttrs(relation, operationTable, metadataAttrs, 
rowIdAttrs)
+    }
 
     // build a plan for updated records that match the condition
     val matchedRowsPlan = Filter(cond, readRelation)
-    val rowDeltaPlan = if (operation.representUpdateAsDeleteAndInsert) {
-      buildDeletesAndInserts(matchedRowsPlan, assignments, rowIdAttrs)
+    val rowDeltaPlan = if (supportsColumnUpdate) {

Review Comment:
   I am worried about these constant if statements. We will need to find a 
better structure.



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