-
Notifications
You must be signed in to change notification settings - Fork 3k
Core: Support serializable and snapshot isolation for ReplacePartitions #2925
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
Changes from all commits
05640fc
26981db
7c7d3c5
d966274
9026182
c25e605
7afb3ff
ec5d1ac
800d8ae
640b46f
d3674c8
1510714
e12eb55
e04dc8e
59ac6ed
371b382
1802c41
37cd8e8
4dbc301
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,12 +22,20 @@ | |
| import java.util.List; | ||
| import org.apache.iceberg.exceptions.ValidationException; | ||
| import org.apache.iceberg.expressions.Expressions; | ||
| import org.apache.iceberg.util.PartitionSet; | ||
|
|
||
| public class BaseReplacePartitions | ||
| extends MergingSnapshotProducer<ReplacePartitions> implements ReplacePartitions { | ||
|
|
||
| private final PartitionSet replacedPartitions; | ||
| private Long startingSnapshotId; | ||
| private boolean validateConflictingData = false; | ||
| private boolean validateConflictingDeletes = false; | ||
|
|
||
| BaseReplacePartitions(String tableName, TableOperations ops) { | ||
| super(tableName, ops); | ||
| set(SnapshotSummary.REPLACE_PARTITIONS_PROP, "true"); | ||
| replacedPartitions = PartitionSet.create(ops.current().specsById()); | ||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -43,6 +51,7 @@ protected String operation() { | |
| @Override | ||
| public ReplacePartitions addFile(DataFile file) { | ||
| dropPartition(file.specId(), file.partition()); | ||
| replacedPartitions.add(file.specId(), file.partition()); | ||
| add(file); | ||
| return this; | ||
| } | ||
|
|
@@ -53,6 +62,45 @@ public ReplacePartitions validateAppendOnly() { | |
| return this; | ||
| } | ||
|
|
||
| @Override | ||
| public ReplacePartitions validateFromSnapshot(long newStartingSnapshotId) { | ||
| this.startingSnapshotId = newStartingSnapshotId; | ||
| return this; | ||
| } | ||
|
|
||
| @Override | ||
| public ReplacePartitions validateNoConflictingDeletes() { | ||
| this.validateConflictingDeletes = true; | ||
| return this; | ||
| } | ||
|
|
||
| @Override | ||
| public ReplacePartitions validateNoConflictingData() { | ||
| this.validateConflictingData = true; | ||
| return this; | ||
| } | ||
|
|
||
| @Override | ||
| public void validate(TableMetadata currentMetadata) { | ||
| if (validateConflictingData) { | ||
| if (dataSpec().isUnpartitioned()) { | ||
aokolnychyi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| validateAddedDataFiles(currentMetadata, startingSnapshotId, Expressions.alwaysTrue()); | ||
| } else { | ||
| validateAddedDataFiles(currentMetadata, startingSnapshotId, replacedPartitions); | ||
| } | ||
| } | ||
|
|
||
| if (validateConflictingDeletes) { | ||
| if (dataSpec().isUnpartitioned()) { | ||
| validateDeletedDataFiles(currentMetadata, startingSnapshotId, Expressions.alwaysTrue()); | ||
| validateNoNewDeleteFiles(currentMetadata, startingSnapshotId, Expressions.alwaysTrue()); | ||
| } else { | ||
| validateDeletedDataFiles(currentMetadata, startingSnapshotId, replacedPartitions); | ||
| validateNoNewDeleteFiles(currentMetadata, startingSnapshotId, replacedPartitions); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public List<ManifestFile> apply(TableMetadata base) { | ||
| if (dataSpec().fields().size() <= 0) { | ||
|
Contributor
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. Not directly related to this PR. It seems the implementation behaves differently when the current spec is unpartitioned. If we have multiple specs and the current one is partitioned, it will only replace partitions in the current spec without touching old specs. If the current spec is unpartitioned, though, it will replace everything. Is that expected, @rdblue? |
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.