Skip to content
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
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ public class IcebergColumnHandle
private static final int INSTANCE_SIZE = instanceSize(IcebergColumnHandle.class);

// Iceberg reserved row ids begin at INTEGER.MAX_VALUE and count down. Starting with MIN_VALUE here to avoid conflicts.
public static final int TRINO_UPDATE_ROW_ID = Integer.MIN_VALUE;
public static final int TRINO_MERGE_ROW_ID = Integer.MIN_VALUE + 1;
public static final int TRINO_MERGE_ROW_ID = Integer.MIN_VALUE;
public static final String TRINO_ROW_ID_NAME = "$row_id";

public static final int TRINO_MERGE_PARTITION_SPEC_ID = Integer.MIN_VALUE + 2;
Copy link
Contributor

@findinpath findinpath Nov 8, 2024

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

Expand Down Expand Up @@ -182,12 +181,6 @@ public boolean isRowPositionColumn()
return id == ROW_POSITION.fieldId();
}

@JsonIgnore
public boolean isUpdateRowIdColumn()
{
return id == TRINO_UPDATE_ROW_ID;
}

@JsonIgnore
public boolean isMergeRowIdColumn()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ 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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mapFieldIdsToIndex function is not used anymore.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ public ConnectorPageSource createPageSource(
.forEach(requiredColumns::add);

icebergColumns.stream()
.filter(column -> column.isUpdateRowIdColumn() || column.isMergeRowIdColumn())
.filter(IcebergColumnHandle::isMergeRowIdColumn)
.findFirst().ifPresent(rowIdColumn -> {
Set<Integer> alreadyRequiredColumnIds = requiredColumns.stream()
.map(IcebergColumnHandle::getId)
Expand Down Expand Up @@ -679,8 +679,8 @@ else if (column.isPathColumn()) {
else if (column.isFileModifiedTimeColumn()) {
columnAdaptations.add(ColumnAdaptation.constantColumn(nativeValueToBlock(FILE_MODIFIED_TIME.getType(), packDateTimeWithZone(inputFile.lastModified().toEpochMilli(), UTC_KEY))));
}
else if (column.isUpdateRowIdColumn() || column.isMergeRowIdColumn()) {
// $row_id is a composite of multiple physical columns. It is assembled by the IcebergPageSource
else if (column.isMergeRowIdColumn()) {
// The merge $row_id is a composite of multiple physical columns. It is assembled by the IcebergPageSource
columnAdaptations.add(ColumnAdaptation.nullColumn(column.getType()));
}
else if (column.isRowPositionColumn()) {
Expand Down Expand Up @@ -831,8 +831,8 @@ public IdBasedFieldMapperFactory(List<IcebergColumnHandle> columns)

ImmutableMap.Builder<Integer, Map<String, Integer>> mapping = ImmutableMap.builder();
for (IcebergColumnHandle column : columns) {
if (column.isUpdateRowIdColumn() || column.isMergeRowIdColumn()) {
// The update $row_id column contains fields which should not be accounted for in the mapping.
if (column.isMergeRowIdColumn()) {
// The merge $row_id column contains fields which should not be accounted for in the mapping.
continue;
}

Expand Down Expand Up @@ -979,8 +979,8 @@ else if (column.isPathColumn()) {
else if (column.isFileModifiedTimeColumn()) {
pageSourceBuilder.addConstantColumn(nativeValueToBlock(FILE_MODIFIED_TIME.getType(), packDateTimeWithZone(inputFile.lastModified().toEpochMilli(), UTC_KEY)));
}
else if (column.isUpdateRowIdColumn() || column.isMergeRowIdColumn()) {
// $row_id is a composite of multiple physical columns, it is assembled by the IcebergPageSource
else if (column.isMergeRowIdColumn()) {
// The merge $row_id is a composite of multiple physical columns, it is assembled by the IcebergPageSource
pageSourceBuilder.addNullColumn(column.getType());
}
else if (column.isRowPositionColumn()) {
Expand Down