Repository navigation
[SPARK-58111][SQL] Scan and write schema narrowing for column-level UPDATE in DSv2 #55518
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
anuragmantri
wants to merge
16
commits into
apache:master
Choose a base branch
from
anuragmantri:dsv2-required-data-attrs
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+3,526
−61
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
bcf72ae
[SPARK-58111][SQL] Write schema narrowing for column-level UPDATE in …
anuragmantri 8db6b05
Add new replace data narrow projection
anuragmantri 48fc37d
Add tests for nested column updates
anuragmantri 44cb845
Update comments
anuragmantri d107c1e
Add mima excludes
anuragmantri d56d906
Scala fmt
anuragmantri 5caed6d
Address review comments
cincrement e5406c8
Rebase with master and minor changes
anuragmantri 16005ad
Address review comments except finding 9
anuragmantri 5ca2c39
Add scanOnlyDataAttributes() API
anuragmantri c11475a
Address findings 7, 15, 16, 17, 18
anuragmantri 117a7fc
Address Dongjoon's review comments
anuragmantri 646b4c9
Address Peter's Finding 21 and 22
anuragmantri ec9f82b
Address Anton's review comments
anuragmantri 9746d24
Address Peter's review comments
anuragmantri 2463813
Narrow only the write relation for column updates and address review …
anuragmantri File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
sql/catalyst/src/main/java/org/apache/spark/sql/connector/write/SupportsColumnUpdates.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| /* | ||
| * 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}. Inserted rows 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. | ||
| * | ||
| * @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. 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, e.g. a primary key. Columns that are not declared are absent from the rows the | ||
| * connector receives, so the connector must preserve their values itself. | ||
| * <p> | ||
| * Each entry must name a top-level data column of the table. For updates on nested fields such | ||
| * as {@code SET s.c1 = -1}, the connector must declare the root struct column {@code s}. Spark | ||
| * rejects with an analysis exception an empty array, a column that does not exist, a column | ||
| * declared more than once, a nested field, a metadata column (declare those through | ||
| * {@link #requiredMetadataAttributes()} instead), and an array that misses a column reported by | ||
| * {@link RowLevelOperationInfo#updatedColumns()}. | ||
| * <p> | ||
| * If this operation also mixes in {@link SupportsDelta} and represents updates as deletes and | ||
| * inserts ({@link SupportsDelta#representUpdateAsDeleteAndInsert()} returns {@code true}), | ||
| * every row-ID column ({@link SupportsDelta#rowId()}) must reach the reinserted row: a data | ||
| * row-ID column must be declared here, and a metadata row-ID column must be returned by | ||
| * {@link #requiredMetadataAttributes()} with | ||
| * {@link org.apache.spark.sql.connector.catalog.MetadataColumn#PRESERVE_ON_REINSERT} set. In | ||
| * this mode, an UPDATE that assigns a new value to a row-ID column is also rejected, unless | ||
| * every table column is declared here. Both cases are rejected with an analysis exception. | ||
| * <p> | ||
| * Data columns the write needs must be declared here too, even if the command does not | ||
| * reference them, such as the source columns of partition transforms and any columns used by | ||
| * {@link RequiresDistributionAndOrdering#requiredDistribution()} or | ||
| * {@link RequiresDistributionAndOrdering#requiredOrdering()}. Such columns appear in the rows | ||
| * the connector receives; a connector that does not want to persist them should project them | ||
| * away inside the connector before writing. A write whose distribution or ordering references | ||
| * any other column is rejected with an analysis exception, except for metadata columns returned | ||
| * by {@link #requiredMetadataAttributes()} and, for operations that mix in | ||
| * {@link SupportsDelta}, row-ID columns. | ||
| * <p> | ||
| * Spark does not read an undeclared column that neither the command nor a table constraint | ||
| * references, so such a column is not available for runtime filtering. A scan that reports | ||
| * runtime filter attributes based on the columns it reads loses runtime group filtering on it, | ||
| * and a scan that still reports it as a runtime filter attribute fails with | ||
| * {@code DATA_SOURCE_INVALID_RUNTIME_FILTER_ATTRIBUTE}. Declare partition source columns used | ||
| * for runtime filtering to keep it. | ||
| */ | ||
| NamedReference[] requiredDataAttributes(); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Finding 11. The interface doc reads as if the mix-in applies to any
RowLevelOperation, but onlyRewriteUpdateTablehonours it:RewriteDeleteFromTableandRewriteMergeIntoTablecall the three-argumentbuildReplaceDataProjections/ four-argumentbuildWriteDeltaProjections, soupdateRowProjectionstaysNone,updateSchema()stays absent, andrequiredDataAttributes()is never read. I confirmed a MERGE against aSupportsColumnUpdatesconnector runs correctly with full-width rows -- so this is not a correctness problem, but a connector reading the doc would reasonably expect narrow rows there.Finding 2 fixed the equivalent note on
updatedColumns(); this is the same point on the mix-in itself, which is what @dongjoon-hyun originally asked for ("shall we mention thatDELETE and MERGE ignores this method?" on the oldRowLevelOperation.java).Worth a cross-reference from
DeltaWriter#updateandDeltaWriter#reinserttoo -- theirrowparameter is documented as "a row with updated values" with no hint that it may followupdateSchema()rather thanschema().There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added the lines on all mentioned API docs.