-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Fix Iceberg merge, update, delete, for tables with equality deletes #24062
Open
dain
wants to merge
3
commits into
trinodb:master
Choose a base branch
from
dain:update-after-equality-delete
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.
+71
−123
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 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 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 |
---|---|---|
|
@@ -30,13 +30,13 @@ | |
import java.util.Optional; | ||
import java.util.OptionalLong; | ||
import java.util.concurrent.CompletableFuture; | ||
import java.util.function.Function; | ||
import java.util.function.Supplier; | ||
|
||
import static com.google.common.base.Preconditions.checkArgument; | ||
import static com.google.common.base.Throwables.throwIfInstanceOf; | ||
import static io.trino.plugin.base.util.Closables.closeAllSuppress; | ||
import static io.trino.plugin.iceberg.IcebergErrorCode.ICEBERG_BAD_DATA; | ||
import static java.lang.String.format; | ||
import static java.util.Objects.requireNonNull; | ||
|
||
public class IcebergPageSource | ||
|
@@ -46,10 +46,9 @@ public class IcebergPageSource | |
private final ConnectorPageSource delegate; | ||
private final Optional<ReaderProjectionsAdapter> projectionsAdapter; | ||
private final Supplier<Optional<RowPredicate>> deletePredicate; | ||
// An array with one element per field in the $row_id column. The value in the array points to the | ||
// channel where the data can be read from. | ||
private int[] rowIdChildColumnIndexes = new int[0]; | ||
private final Function<Block, RowBlock> rowIdBlockFactory; | ||
// The $row_id's index in 'expectedColumns', or -1 if there isn't one | ||
// this column with contain row position populated in the source, and must be wrapped with constant data for full row id | ||
private int rowIdColumnIndex = -1; | ||
// Maps the Iceberg field ids of unmodified columns to their indexes in updateRowIdChildColumnIndexes | ||
|
||
|
@@ -58,7 +57,8 @@ public IcebergPageSource( | |
List<IcebergColumnHandle> requiredColumns, | ||
ConnectorPageSource delegate, | ||
Optional<ReaderProjectionsAdapter> projectionsAdapter, | ||
Supplier<Optional<RowPredicate>> deletePredicate) | ||
Supplier<Optional<RowPredicate>> deletePredicate, | ||
Function<Block, RowBlock> rowIdBlockFactory) | ||
{ | ||
// expectedColumns should contain columns which should be in the final Page | ||
// requiredColumns should include all expectedColumns as well as any columns needed by the DeleteFilter | ||
|
@@ -70,22 +70,15 @@ public IcebergPageSource( | |
checkArgument(expectedColumn.equals(requiredColumns.get(i)), "Expected columns must be a prefix of required columns"); | ||
expectedColumnIndexes[i] = i; | ||
|
||
if (expectedColumn.isUpdateRowIdColumn() || expectedColumn.isMergeRowIdColumn()) { | ||
if (expectedColumn.isMergeRowIdColumn()) { | ||
this.rowIdColumnIndex = i; | ||
|
||
Map<Integer, Integer> fieldIdToColumnIndex = mapFieldIdsToIndex(requiredColumns); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
List<ColumnIdentity> rowIdFields = expectedColumn.getColumnIdentity().getChildren(); | ||
this.rowIdChildColumnIndexes = new int[rowIdFields.size()]; | ||
for (int columnIndex = 0; columnIndex < rowIdFields.size(); columnIndex++) { | ||
int fieldId = rowIdFields.get(columnIndex).getId(); | ||
rowIdChildColumnIndexes[columnIndex] = requireNonNull(fieldIdToColumnIndex.get(fieldId), () -> format("Column %s not found in requiredColumns", fieldId)); | ||
} | ||
} | ||
} | ||
|
||
this.delegate = requireNonNull(delegate, "delegate is null"); | ||
this.projectionsAdapter = requireNonNull(projectionsAdapter, "projectionsAdapter is null"); | ||
this.deletePredicate = requireNonNull(deletePredicate, "deletePredicate is null"); | ||
this.rowIdBlockFactory = requireNonNull(rowIdBlockFactory, "rowIdBlockFactory is null"); | ||
} | ||
|
||
@Override | ||
|
@@ -161,21 +154,11 @@ private Page withRowIdBlock(Page page) | |
return page; | ||
} | ||
|
||
Block[] rowIdFields = new Block[rowIdChildColumnIndexes.length]; | ||
for (int childIndex = 0; childIndex < rowIdChildColumnIndexes.length; childIndex++) { | ||
rowIdFields[childIndex] = page.getBlock(rowIdChildColumnIndexes[childIndex]); | ||
} | ||
|
||
RowBlock rowIdBlock = rowIdBlockFactory.apply(page.getBlock(rowIdColumnIndex)); | ||
Block[] fullPage = new Block[page.getChannelCount()]; | ||
for (int channel = 0; channel < page.getChannelCount(); channel++) { | ||
if (channel == rowIdColumnIndex) { | ||
fullPage[channel] = RowBlock.fromFieldBlocks(page.getPositionCount(), rowIdFields); | ||
continue; | ||
} | ||
|
||
fullPage[channel] = page.getBlock(channel); | ||
fullPage[channel] = channel == rowIdColumnIndex ? rowIdBlock : page.getBlock(channel); | ||
} | ||
|
||
return new Page(page.getPositionCount(), fullPage); | ||
} | ||
|
||
|
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.
We can likely adjust the values (decrease by 1) of the other ID fields now that we don't have anymore
Integer.MIN_VALUE + 1