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


##########
sql/catalyst/src/main/java/org/apache/spark/sql/connector/write/SupportsColumnUpdates.java:
##########
@@ -0,0 +1,111 @@
+/*
+ * 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.connector.write;
+
+import org.apache.spark.annotation.Experimental;
+import org.apache.spark.sql.connector.expressions.NamedReference;
+
+/**
+ * A mix-in interface for {@link RowLevelOperation}. Data sources can 
implement this interface to
+ * receive a narrow row containing only the columns declared via {@link 
#requiredDataAttributes()}
+ * for updated, copied, and reinserted records, instead of the full table row.
+ * <p>
+ * When {@link LogicalWriteInfo#columnUpdateSchema()} is present, updated, 
copied, and reinserted
+ * rows follow it: group-based operations receive them through
+ * {@link DataWriter#writeColumnUpdate(Object, Object)} or
+ * {@link DataWriter#writeColumnUpdate(Object)}, and operations that mix in 
{@link SupportsDelta}
+ * through {@link DeltaWriter#update} and {@link DeltaWriter#reinsert}. Rows 
the command inserts
+ * always follow {@link LogicalWriteInfo#schema()} and arrive through
+ * {@link DataWriter#write(Object)} and {@link DeltaWriter#insert}. When
+ * {@link LogicalWriteInfo#columnUpdateSchema()} is absent, every row follows
+ * {@link LogicalWriteInfo#schema()}, as for any other operation. Connectors 
must decide which
+ * layout to expect by whether {@link LogicalWriteInfo#columnUpdateSchema()} 
is present, not by
+ * the command. A builder that wants full-width rows for some command can check
+ * {@link RowLevelOperationInfo#command()} and build an operation without this 
mix-in. Currently
+ * Spark narrows only UPDATE.
+ * <p>
+ * The scan builder returned by {@link #newScanBuilder} should implement
+ * {@link 
org.apache.spark.sql.connector.read.SupportsPushDownRequiredColumns}, so that 
the scan
+ * does not read columns the command neither references nor declares. 
Otherwise the scan reads
+ * every column. For operations that do not mix in {@link SupportsDelta}, only 
top-level columns
+ * are pruned: a struct column the command references through a nested field 
is read in full.
+ *
+ * @since 4.4.0
+ */
+@Experimental
+public interface SupportsColumnUpdates extends RowLevelOperation {
+  /**
+   * Returns the data column references required to perform this row-level 
operation.
+   * <p>
+   * When Spark narrows the write, the returned columns become
+   * {@link LogicalWriteInfo#columnUpdateSchema()}, in declared order. Spark 
matches each declared
+   * column with the session's resolver, and {@link 
LogicalWriteInfo#columnUpdateSchema()} uses the
+   * table's spelling of each column, which can differ in case from the 
declared reference.
+   * Implementations must include every column they want to receive: every 
column reported by
+   * {@link RowLevelOperationInfo#updatedColumns()}, plus any columns needed 
for row lookup or
+   * routing. Columns that are not declared are absent from the rows the 
connector receives, so
+   * the connector must preserve their values itself. Spark may call this 
method more than once
+   * for the same operation, and every call must return the same columns.
+   * <p>
+   * If {@link RowLevelOperationInfo#updatedColumns()} is empty, the builder 
should build an
+   * operation without this mix-in.

Review Comment:
   This sentence leaves out "for UPDATE". `updatedColumns()` is always empty 
for DELETE and MERGE (RowLevelOperationInfo L43-44), so read literally it tells 
connectors to drop the mix-in for every DELETE and MERGE, which the test 
fixture does not do (it drops it only for `command == UPDATE && 
updatedColumns().isEmpty`). It would also help to say why, since keeping the 
mix-in still works. Maybe replace lines 65-66 with:
   
   ```java
      * For an UPDATE whose assignments are all identity assignments,
      * {@link RowLevelOperationInfo#updatedColumns()} is empty and there is 
nothing to narrow, so the
      * builder may build an operation without this mix-in to receive 
full-width rows.
   ```



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