-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Add information from written files to Iceberg conflict detection #24470
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
Merged
raunaqmorarka
merged 3 commits into
trinodb:master
from
pajaks:pajaks/iceberg_concurent_merge
Feb 12, 2025
Merged
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 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -272,6 +272,7 @@ | |
| import static io.trino.plugin.iceberg.IcebergSessionProperties.isBucketExecutionEnabled; | ||
| import static io.trino.plugin.iceberg.IcebergSessionProperties.isCollectExtendedStatisticsOnWrite; | ||
| import static io.trino.plugin.iceberg.IcebergSessionProperties.isExtendedStatisticsEnabled; | ||
| import static io.trino.plugin.iceberg.IcebergSessionProperties.isFileBasedConflictDetectionEnabled; | ||
| import static io.trino.plugin.iceberg.IcebergSessionProperties.isIncrementalRefreshEnabled; | ||
| import static io.trino.plugin.iceberg.IcebergSessionProperties.isMergeManifestsOnWrite; | ||
| import static io.trino.plugin.iceberg.IcebergSessionProperties.isProjectionPushdownEnabled; | ||
|
|
@@ -307,6 +308,7 @@ | |
| import static io.trino.plugin.iceberg.IcebergUtil.getFileFormat; | ||
| import static io.trino.plugin.iceberg.IcebergUtil.getIcebergTableProperties; | ||
| import static io.trino.plugin.iceberg.IcebergUtil.getPartitionKeys; | ||
| import static io.trino.plugin.iceberg.IcebergUtil.getPartitionValues; | ||
| import static io.trino.plugin.iceberg.IcebergUtil.getProjectedColumns; | ||
| import static io.trino.plugin.iceberg.IcebergUtil.getSnapshotIdAsOfTime; | ||
| import static io.trino.plugin.iceberg.IcebergUtil.getTableComment; | ||
|
|
@@ -353,6 +355,7 @@ | |
| import static io.trino.spi.connector.MaterializedViewFreshness.Freshness.UNKNOWN; | ||
| import static io.trino.spi.connector.RetryMode.NO_RETRIES; | ||
| import static io.trino.spi.connector.RowChangeParadigm.DELETE_ROW_AND_INSERT_ROW; | ||
| import static io.trino.spi.predicate.TupleDomain.withColumnDomains; | ||
| import static io.trino.spi.type.BigintType.BIGINT; | ||
| import static io.trino.spi.type.DateTimeEncoding.unpackMillisUtc; | ||
| import static io.trino.spi.type.DateType.DATE; | ||
|
|
@@ -3033,8 +3036,13 @@ private void finishWrite(ConnectorSession session, IcebergTableHandle table, Col | |
| RowDelta rowDelta = transaction.newRowDelta(); | ||
| table.getSnapshotId().map(icebergTable::snapshot).ifPresent(s -> rowDelta.validateFromSnapshot(s.snapshotId())); | ||
| TupleDomain<IcebergColumnHandle> dataColumnPredicate = table.getEnforcedPredicate().filter((column, domain) -> !isMetadataColumnId(column.getId())); | ||
| TupleDomain<IcebergColumnHandle> convertibleUnenforcedPredicate = table.getUnenforcedPredicate().filter((_, domain) -> isConvertibleToIcebergExpression(domain)); | ||
| TupleDomain<IcebergColumnHandle> effectivePredicate = dataColumnPredicate.intersect(convertibleUnenforcedPredicate); | ||
| TupleDomain<IcebergColumnHandle> effectivePredicate = dataColumnPredicate.intersect(table.getUnenforcedPredicate()); | ||
| if (isFileBasedConflictDetectionEnabled(session)) { | ||
| effectivePredicate = effectivePredicate.intersect(extractTupleDomainsFromCommitTasks(table, icebergTable, commitTasks, typeManager)); | ||
| } | ||
|
|
||
| effectivePredicate = effectivePredicate.filter((_, domain) -> isConvertibleToIcebergExpression(domain)); | ||
|
|
||
| if (!effectivePredicate.isAll()) { | ||
| rowDelta.conflictDetectionFilter(toIcebergExpression(effectivePredicate)); | ||
| } | ||
|
|
@@ -3099,6 +3107,40 @@ private void finishWrite(ConnectorSession session, IcebergTableHandle table, Col | |
| commitUpdateAndTransaction(rowDelta, session, transaction, "write"); | ||
| } | ||
|
|
||
| static TupleDomain<IcebergColumnHandle> extractTupleDomainsFromCommitTasks(IcebergTableHandle table, Table icebergTable, List<CommitTaskData> commitTasks, TypeManager typeManager) | ||
| { | ||
| Set<IcebergColumnHandle> partitionColumns = new HashSet<>(getProjectedColumns(icebergTable.schema(), typeManager, identityPartitionColumnsInAllSpecs(icebergTable))); | ||
| PartitionSpec partitionSpec = icebergTable.spec(); | ||
| Type[] partitionColumnTypes = partitionSpec.fields().stream() | ||
| .map(field -> field.transform().getResultType(icebergTable.schema().findType(field.sourceId()))) | ||
| .toArray(Type[]::new); | ||
| Schema schema = SchemaParser.fromJson(table.getTableSchemaJson()); | ||
| Map<IcebergColumnHandle, List<Domain>> domainsFromTasks = new HashMap<>(); | ||
| for (CommitTaskData commitTask : commitTasks) { | ||
| PartitionSpec taskPartitionSpec = PartitionSpecParser.fromJson(schema, commitTask.partitionSpecJson()); | ||
| if (commitTask.partitionDataJson().isEmpty() || taskPartitionSpec.isUnpartitioned() || !taskPartitionSpec.equals(partitionSpec)) { | ||
|
Member
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. You can potentially use something like |
||
| // We should not produce any specific domains if there are no partitions or current partitions does not match task partitions for any of tasks | ||
| // As each partition value narrows down conflict scope we should produce values from all commit tasks or not at all, to avoid partial information | ||
| return TupleDomain.all(); | ||
| } | ||
|
|
||
| PartitionData partitionData = PartitionData.fromJson(commitTask.partitionDataJson().get(), partitionColumnTypes); | ||
| Map<Integer, Optional<String>> partitionKeys = getPartitionKeys(partitionData, partitionSpec); | ||
| Map<ColumnHandle, NullableValue> partitionValues = getPartitionValues(partitionColumns, partitionKeys); | ||
|
|
||
| for (Map.Entry<ColumnHandle, NullableValue> entry : partitionValues.entrySet()) { | ||
| IcebergColumnHandle columnHandle = (IcebergColumnHandle) entry.getKey(); | ||
| NullableValue value = entry.getValue(); | ||
| Domain newDomain = value.isNull() ? Domain.onlyNull(columnHandle.getType()) : Domain.singleValue(columnHandle.getType(), value.getValue()); | ||
| domainsFromTasks.computeIfAbsent(columnHandle, _ -> new ArrayList<>()).add(newDomain); | ||
| } | ||
| } | ||
| return withColumnDomains(domainsFromTasks.entrySet().stream() | ||
| .collect(toImmutableMap( | ||
| Map.Entry::getKey, | ||
| entry -> Domain.union(entry.getValue())))); | ||
| } | ||
|
|
||
| @Override | ||
| public void createView(ConnectorSession session, SchemaTableName viewName, ConnectorViewDefinition definition, Map<String, Object> viewProperties, boolean replace) | ||
| { | ||
|
|
||
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.
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.
@ConfigHidden- this is a kill-switch as i see it .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.
That doesn't mean it has to be hidden, it should just be removed eventually