You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iceberg.apache.org by bl...@apache.org on 2023/01/23 15:48:31 UTC
[iceberg] branch master updated: Core, API: Support branch writes in more operations (#5234)
This is an automated email from the ASF dual-hosted git repository.
blue pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iceberg.git
The following commit(s) were added to refs/heads/master by this push:
new eec20ed14f Core, API: Support branch writes in more operations (#5234)
eec20ed14f is described below
commit eec20ed14f02ede937dd6bf98d613e8c8228bc80
Author: Namratha Mysore Keshavaprakash <nm...@gmail.com>
AuthorDate: Mon Jan 23 07:48:25 2023 -0800
Core, API: Support branch writes in more operations (#5234)
---
.palantir/revapi.yml | 10 +
.../org/apache/iceberg/BaseOverwriteFiles.java | 14 +-
.../org/apache/iceberg/BaseReplacePartitions.java | 21 +-
.../java/org/apache/iceberg/BaseRewriteFiles.java | 8 +-
.../main/java/org/apache/iceberg/BaseRowDelta.java | 25 +-
.../apache/iceberg/MergingSnapshotProducer.java | 269 +++++++++--
.../java/org/apache/iceberg/SnapshotProducer.java | 7 +-
.../java/org/apache/iceberg/TableTestBase.java | 16 +-
.../java/org/apache/iceberg/TestOverwrite.java | 111 +++--
.../iceberg/TestOverwriteWithValidation.java | 486 ++++++++++---------
.../org/apache/iceberg/TestReplacePartitions.java | 286 ++++++-----
.../java/org/apache/iceberg/TestRewriteFiles.java | 359 ++++++++------
.../test/java/org/apache/iceberg/TestRowDelta.java | 535 +++++++++++----------
13 files changed, 1301 insertions(+), 846 deletions(-)
diff --git a/.palantir/revapi.yml b/.palantir/revapi.yml
index fbfaae868a..6c2628cc00 100644
--- a/.palantir/revapi.yml
+++ b/.palantir/revapi.yml
@@ -353,6 +353,16 @@ acceptedBreaks:
old: "method org.apache.iceberg.Table org.apache.iceberg.BaseMetadataTable::table()"
new: "method org.apache.iceberg.BaseTable org.apache.iceberg.BaseMetadataTable::table()"
justification: "Returning more specific subclass"
+ - code: "java.method.returnTypeChangedCovariantly"
+ old: "method ThisT org.apache.iceberg.SnapshotUpdate<ThisT>::toBranch(java.lang.String)\
+ \ @ org.apache.iceberg.BaseOverwriteFiles"
+ new: "method org.apache.iceberg.BaseOverwriteFiles org.apache.iceberg.BaseOverwriteFiles::toBranch(java.lang.String)"
+ justification: "Introducing branch snapshot operations on BaseOverwrite"
+ - code: "java.method.returnTypeChangedCovariantly"
+ old: "method ThisT org.apache.iceberg.SnapshotUpdate<ThisT>::toBranch(java.lang.String)\
+ \ @ org.apache.iceberg.BaseReplacePartitions"
+ new: "method org.apache.iceberg.BaseReplacePartitions org.apache.iceberg.BaseReplacePartitions::toBranch(java.lang.String)"
+ justification: "Introducing branch snapshot operations for BaseReplacePartitions"
org.apache.iceberg:iceberg-orc:
- code: "java.method.removed"
old: "method org.apache.iceberg.orc.ORC.WriteBuilder org.apache.iceberg.orc.ORC.WriteBuilder::config(java.lang.String,\
diff --git a/core/src/main/java/org/apache/iceberg/BaseOverwriteFiles.java b/core/src/main/java/org/apache/iceberg/BaseOverwriteFiles.java
index a073d79e55..55bbad7750 100644
--- a/core/src/main/java/org/apache/iceberg/BaseOverwriteFiles.java
+++ b/core/src/main/java/org/apache/iceberg/BaseOverwriteFiles.java
@@ -104,6 +104,12 @@ public class BaseOverwriteFiles extends MergingSnapshotProducer<OverwriteFiles>
return this;
}
+ @Override
+ public BaseOverwriteFiles toBranch(String branch) {
+ targetBranch(branch);
+ return this;
+ }
+
@Override
protected void validate(TableMetadata base, Snapshot snapshot) {
if (validateAddedFilesMatchOverwriteFilter) {
@@ -133,19 +139,19 @@ public class BaseOverwriteFiles extends MergingSnapshotProducer<OverwriteFiles>
}
if (validateNewDataFiles) {
- validateAddedDataFiles(base, startingSnapshotId, dataConflictDetectionFilter());
+ validateAddedDataFiles(base, startingSnapshotId, dataConflictDetectionFilter(), snapshot);
}
if (validateNewDeletes) {
if (rowFilter() != Expressions.alwaysFalse()) {
Expression filter = conflictDetectionFilter != null ? conflictDetectionFilter : rowFilter();
- validateNoNewDeleteFiles(base, startingSnapshotId, filter);
- validateDeletedDataFiles(base, startingSnapshotId, filter);
+ validateNoNewDeleteFiles(base, startingSnapshotId, filter, snapshot);
+ validateDeletedDataFiles(base, startingSnapshotId, filter, snapshot);
}
if (deletedDataFiles.size() > 0) {
validateNoNewDeletesForDataFiles(
- base, startingSnapshotId, conflictDetectionFilter, deletedDataFiles);
+ base, startingSnapshotId, conflictDetectionFilter, deletedDataFiles, snapshot);
}
}
}
diff --git a/core/src/main/java/org/apache/iceberg/BaseReplacePartitions.java b/core/src/main/java/org/apache/iceberg/BaseReplacePartitions.java
index dd44505e9d..327a276a87 100644
--- a/core/src/main/java/org/apache/iceberg/BaseReplacePartitions.java
+++ b/core/src/main/java/org/apache/iceberg/BaseReplacePartitions.java
@@ -79,23 +79,32 @@ public class BaseReplacePartitions extends MergingSnapshotProducer<ReplacePartit
return this;
}
+ @Override
+ public BaseReplacePartitions toBranch(String branch) {
+ targetBranch(branch);
+ return this;
+ }
+
@Override
public void validate(TableMetadata currentMetadata, Snapshot snapshot) {
if (validateConflictingData) {
if (dataSpec().isUnpartitioned()) {
- validateAddedDataFiles(currentMetadata, startingSnapshotId, Expressions.alwaysTrue());
+ validateAddedDataFiles(
+ currentMetadata, startingSnapshotId, Expressions.alwaysTrue(), snapshot);
} else {
- validateAddedDataFiles(currentMetadata, startingSnapshotId, replacedPartitions);
+ validateAddedDataFiles(currentMetadata, startingSnapshotId, replacedPartitions, snapshot);
}
}
if (validateConflictingDeletes) {
if (dataSpec().isUnpartitioned()) {
- validateDeletedDataFiles(currentMetadata, startingSnapshotId, Expressions.alwaysTrue());
- validateNoNewDeleteFiles(currentMetadata, startingSnapshotId, Expressions.alwaysTrue());
+ validateDeletedDataFiles(
+ currentMetadata, startingSnapshotId, Expressions.alwaysTrue(), snapshot);
+ validateNoNewDeleteFiles(
+ currentMetadata, startingSnapshotId, Expressions.alwaysTrue(), snapshot);
} else {
- validateDeletedDataFiles(currentMetadata, startingSnapshotId, replacedPartitions);
- validateNoNewDeleteFiles(currentMetadata, startingSnapshotId, replacedPartitions);
+ validateDeletedDataFiles(currentMetadata, startingSnapshotId, replacedPartitions, snapshot);
+ validateNoNewDeleteFiles(currentMetadata, startingSnapshotId, replacedPartitions, snapshot);
}
}
}
diff --git a/core/src/main/java/org/apache/iceberg/BaseRewriteFiles.java b/core/src/main/java/org/apache/iceberg/BaseRewriteFiles.java
index 8a3b137b2d..05a446a14c 100644
--- a/core/src/main/java/org/apache/iceberg/BaseRewriteFiles.java
+++ b/core/src/main/java/org/apache/iceberg/BaseRewriteFiles.java
@@ -109,12 +109,18 @@ class BaseRewriteFiles extends MergingSnapshotProducer<RewriteFiles> implements
return this;
}
+ @Override
+ public BaseRewriteFiles toBranch(String branch) {
+ targetBranch(branch);
+ return this;
+ }
+
@Override
protected void validate(TableMetadata base, Snapshot snapshot) {
if (replacedDataFiles.size() > 0) {
// if there are replaced data files, there cannot be any new row-level deletes for those data
// files
- validateNoNewDeletesForDataFiles(base, startingSnapshotId, replacedDataFiles);
+ validateNoNewDeletesForDataFiles(base, startingSnapshotId, replacedDataFiles, snapshot);
}
}
}
diff --git a/core/src/main/java/org/apache/iceberg/BaseRowDelta.java b/core/src/main/java/org/apache/iceberg/BaseRowDelta.java
index 50a0e26ab3..a8e60045ac 100644
--- a/core/src/main/java/org/apache/iceberg/BaseRowDelta.java
+++ b/core/src/main/java/org/apache/iceberg/BaseRowDelta.java
@@ -22,6 +22,7 @@ import org.apache.iceberg.expressions.Expression;
import org.apache.iceberg.expressions.Expressions;
import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
import org.apache.iceberg.util.CharSequenceSet;
+import org.apache.iceberg.util.SnapshotUtil;
class BaseRowDelta extends MergingSnapshotProducer<RowDelta> implements RowDelta {
private Long startingSnapshotId = null; // check all versions by default
@@ -96,23 +97,37 @@ class BaseRowDelta extends MergingSnapshotProducer<RowDelta> implements RowDelta
}
@Override
- protected void validate(TableMetadata base, Snapshot snapshot) {
- if (base.currentSnapshot() != null) {
+ public RowDelta toBranch(String branch) {
+ targetBranch(branch);
+ return this;
+ }
+
+ @Override
+ protected void validate(TableMetadata base, Snapshot parent) {
+ if (parent != null) {
+ if (startingSnapshotId != null) {
+ Preconditions.checkArgument(
+ SnapshotUtil.isAncestorOf(parent.snapshotId(), startingSnapshotId, base::snapshot),
+ "Snapshot %s is not an ancestor of %s",
+ startingSnapshotId,
+ parent.snapshotId());
+ }
if (!referencedDataFiles.isEmpty()) {
validateDataFilesExist(
base,
startingSnapshotId,
referencedDataFiles,
!validateDeletes,
- conflictDetectionFilter);
+ conflictDetectionFilter,
+ parent);
}
if (validateNewDataFiles) {
- validateAddedDataFiles(base, startingSnapshotId, conflictDetectionFilter);
+ validateAddedDataFiles(base, startingSnapshotId, conflictDetectionFilter, parent);
}
if (validateNewDeleteFiles) {
- validateNoNewDeleteFiles(base, startingSnapshotId, conflictDetectionFilter);
+ validateNoNewDeleteFiles(base, startingSnapshotId, conflictDetectionFilter, parent);
}
}
}
diff --git a/core/src/main/java/org/apache/iceberg/MergingSnapshotProducer.java b/core/src/main/java/org/apache/iceberg/MergingSnapshotProducer.java
index e0452e0be2..57df521b51 100644
--- a/core/src/main/java/org/apache/iceberg/MergingSnapshotProducer.java
+++ b/core/src/main/java/org/apache/iceberg/MergingSnapshotProducer.java
@@ -268,6 +268,20 @@ abstract class MergingSnapshotProducer<ThisT> extends SnapshotProducer<ThisT> {
appendedManifestsSummary);
}
+ /**
+ * @param base table metadata to validate
+ * @param startingSnapshotId id of the snapshot current at the start of the operation
+ * @param partitionSet a set of partitions to filter new conflicting data files
+ * @deprecated will be removed in 1.3.0; use {@link
+ * MergingSnapshotProducer#validateAddedDataFiles(TableMetadata, Long, PartitionSet,
+ * Snapshot)} instead
+ */
+ @Deprecated
+ protected void validateAddedDataFiles(
+ TableMetadata base, Long startingSnapshotId, PartitionSet partitionSet) {
+ validateAddedDataFiles(base, startingSnapshotId, partitionSet, base.currentSnapshot());
+ }
+
/**
* Validates that no files matching given partitions have been added to the table since a starting
* snapshot.
@@ -275,11 +289,12 @@ abstract class MergingSnapshotProducer<ThisT> extends SnapshotProducer<ThisT> {
* @param base table metadata to validate
* @param startingSnapshotId id of the snapshot current at the start of the operation
* @param partitionSet a set of partitions to filter new conflicting data files
+ * @param parent ending snapshot on the lineage being validated
*/
protected void validateAddedDataFiles(
- TableMetadata base, Long startingSnapshotId, PartitionSet partitionSet) {
+ TableMetadata base, Long startingSnapshotId, PartitionSet partitionSet, Snapshot parent) {
CloseableIterable<ManifestEntry<DataFile>> conflictEntries =
- addedDataFiles(base, startingSnapshotId, null, partitionSet);
+ addedDataFiles(base, startingSnapshotId, null, partitionSet, parent);
try (CloseableIterator<ManifestEntry<DataFile>> conflicts = conflictEntries.iterator()) {
if (conflicts.hasNext()) {
@@ -296,6 +311,21 @@ abstract class MergingSnapshotProducer<ThisT> extends SnapshotProducer<ThisT> {
}
}
+ /**
+ * @param base table metadata to validate
+ * @param startingSnapshotId id of the snapshot current at the start of the operation
+ * @param conflictDetectionFilter an expression used to find new conflicting data files
+ * @deprecated will be removed in 1.3.0; use {@link
+ * MergingSnapshotProducer#validateAddedDataFiles(TableMetadata, Long, Expression, Snapshot)}
+ * instead
+ */
+ @Deprecated
+ protected void validateAddedDataFiles(
+ TableMetadata base, Long startingSnapshotId, Expression conflictDetectionFilter) {
+ validateAddedDataFiles(
+ base, startingSnapshotId, conflictDetectionFilter, base.currentSnapshot());
+ }
+
/**
* Validates that no files matching a filter have been added to the table since a starting
* snapshot.
@@ -305,9 +335,12 @@ abstract class MergingSnapshotProducer<ThisT> extends SnapshotProducer<ThisT> {
* @param conflictDetectionFilter an expression used to find new conflicting data files
*/
protected void validateAddedDataFiles(
- TableMetadata base, Long startingSnapshotId, Expression conflictDetectionFilter) {
+ TableMetadata base,
+ Long startingSnapshotId,
+ Expression conflictDetectionFilter,
+ Snapshot parent) {
CloseableIterable<ManifestEntry<DataFile>> conflictEntries =
- addedDataFiles(base, startingSnapshotId, conflictDetectionFilter, null);
+ addedDataFiles(base, startingSnapshotId, conflictDetectionFilter, null, parent);
try (CloseableIterator<ManifestEntry<DataFile>> conflicts = conflictEntries.iterator()) {
if (conflicts.hasNext()) {
@@ -325,27 +358,33 @@ abstract class MergingSnapshotProducer<ThisT> extends SnapshotProducer<ThisT> {
}
/**
- * Returns an iterable of files matching a filter have been added to the table since a starting
+ * Returns an iterable of files matching a filter have been added to a branch since a starting
* snapshot.
*
* @param base table metadata to validate
* @param startingSnapshotId id of the snapshot current at the start of the operation
* @param dataFilter an expression used to find new data files
* @param partitionSet a set of partitions to find new data files
+ * @param parent ending snapshot of the branch
*/
private CloseableIterable<ManifestEntry<DataFile>> addedDataFiles(
TableMetadata base,
Long startingSnapshotId,
Expression dataFilter,
- PartitionSet partitionSet) {
+ PartitionSet partitionSet,
+ Snapshot parent) {
// if there is no current table state, no files have been added
- if (base.currentSnapshot() == null) {
+ if (parent == null) {
return CloseableIterable.empty();
}
Pair<List<ManifestFile>, Set<Long>> history =
validationHistory(
- base, startingSnapshotId, VALIDATE_ADDED_FILES_OPERATIONS, ManifestContent.DATA);
+ base,
+ startingSnapshotId,
+ VALIDATE_ADDED_FILES_OPERATIONS,
+ ManifestContent.DATA,
+ parent);
List<ManifestFile> manifests = history.first();
Set<Long> newSnapshots = history.second();
@@ -377,11 +416,34 @@ abstract class MergingSnapshotProducer<ThisT> extends SnapshotProducer<ThisT> {
* @param base table metadata to validate
* @param startingSnapshotId id of the snapshot current at the start of the operation
* @param dataFiles data files to validate have no new row deletes
+ * @param parent ending snapshot on the branch being validated
+ */
+ protected void validateNoNewDeletesForDataFiles(
+ TableMetadata base, Long startingSnapshotId, Iterable<DataFile> dataFiles, Snapshot parent) {
+ validateNoNewDeletesForDataFiles(
+ base, startingSnapshotId, null, dataFiles, newFilesSequenceNumber != null, parent);
+ }
+
+ /**
+ * Validates that no new delete files that must be applied to the given data files have been added
+ * to the table since a starting snapshot.
+ *
+ * @param base table metadata to validate
+ * @param startingSnapshotId id of the snapshot current at the start of the operation
+ * @param dataFiles data files to validate have no new row deletes
+ * @deprecated will be removed in 1.3.0; use {@link
+ * MergingSnapshotProducer#validateNoNewDeletesForDataFiles} instead
*/
+ @Deprecated
protected void validateNoNewDeletesForDataFiles(
TableMetadata base, Long startingSnapshotId, Iterable<DataFile> dataFiles) {
validateNoNewDeletesForDataFiles(
- base, startingSnapshotId, null, dataFiles, newFilesSequenceNumber != null);
+ base,
+ startingSnapshotId,
+ null,
+ dataFiles,
+ newFilesSequenceNumber != null,
+ base.currentSnapshot());
}
/**
@@ -392,13 +454,37 @@ abstract class MergingSnapshotProducer<ThisT> extends SnapshotProducer<ThisT> {
* @param startingSnapshotId id of the snapshot current at the start of the operation
* @param dataFilter a data filter
* @param dataFiles data files to validate have no new row deletes
+ * @deprecated will be removed in 1.3.0; use {@link
+ * MergingSnapshotProducer#validateNoNewDeletesForDataFiles} instead
*/
+ @Deprecated
protected void validateNoNewDeletesForDataFiles(
TableMetadata base,
Long startingSnapshotId,
Expression dataFilter,
Iterable<DataFile> dataFiles) {
- validateNoNewDeletesForDataFiles(base, startingSnapshotId, dataFilter, dataFiles, false);
+ validateNoNewDeletesForDataFiles(
+ base, startingSnapshotId, dataFilter, dataFiles, base.currentSnapshot());
+ }
+
+ /**
+ * Validates that no new delete files that must be applied to the given data files have been added
+ * to the table since a starting snapshot.
+ *
+ * @param base table metadata to validate
+ * @param startingSnapshotId id of the snapshot current at the start of the operation
+ * @param dataFilter a data filter
+ * @param dataFiles data files to validate have no new row deletes
+ * @param parent ending snapshot on the branch being validated
+ */
+ protected void validateNoNewDeletesForDataFiles(
+ TableMetadata base,
+ Long startingSnapshotId,
+ Expression dataFilter,
+ Iterable<DataFile> dataFiles,
+ Snapshot parent) {
+ validateNoNewDeletesForDataFiles(
+ base, startingSnapshotId, dataFilter, dataFiles, false, parent);
}
/**
@@ -417,19 +503,21 @@ abstract class MergingSnapshotProducer<ThisT> extends SnapshotProducer<ThisT> {
* @param dataFilter a data filter
* @param dataFiles data files to validate have no new row deletes
* @param ignoreEqualityDeletes whether equality deletes should be ignored in validation
+ * @param parent ending snapshot on the branch being validated
*/
private void validateNoNewDeletesForDataFiles(
TableMetadata base,
Long startingSnapshotId,
Expression dataFilter,
Iterable<DataFile> dataFiles,
- boolean ignoreEqualityDeletes) {
+ boolean ignoreEqualityDeletes,
+ Snapshot parent) {
// if there is no current table state, no files have been added
- if (base.currentSnapshot() == null || base.formatVersion() < 2) {
+ if (parent == null || base.formatVersion() < 2) {
return;
}
- DeleteFileIndex deletes = addedDeleteFiles(base, startingSnapshotId, dataFilter, null);
+ DeleteFileIndex deletes = addedDeleteFiles(base, startingSnapshotId, dataFilter, null, parent);
long startingSequenceNumber = startingSequenceNumber(base, startingSnapshotId);
for (DataFile dataFile : dataFiles) {
@@ -458,10 +546,27 @@ abstract class MergingSnapshotProducer<ThisT> extends SnapshotProducer<ThisT> {
* @param base table metadata to validate
* @param startingSnapshotId id of the snapshot current at the start of the operation
* @param dataFilter an expression used to find new conflicting delete files
+ * @deprecated will be removed in 1.3.0; use {@link
+ * MergingSnapshotProducer#validateNoNewDeleteFiles} instead
*/
+ @Deprecated
protected void validateNoNewDeleteFiles(
TableMetadata base, Long startingSnapshotId, Expression dataFilter) {
- DeleteFileIndex deletes = addedDeleteFiles(base, startingSnapshotId, dataFilter, null);
+ validateNoNewDeleteFiles(base, startingSnapshotId, dataFilter, base.currentSnapshot());
+ }
+
+ /**
+ * Validates that no delete files matching a filter have been added to the table since a starting
+ * snapshot.
+ *
+ * @param base table metadata to validate
+ * @param startingSnapshotId id of the snapshot current at the start of the operation
+ * @param dataFilter an expression used to find new conflicting delete files
+ * @param parent ending snapshot on the branch being validated
+ */
+ protected void validateNoNewDeleteFiles(
+ TableMetadata base, Long startingSnapshotId, Expression dataFilter, Snapshot parent) {
+ DeleteFileIndex deletes = addedDeleteFiles(base, startingSnapshotId, dataFilter, null, parent);
ValidationException.check(
deletes.isEmpty(),
"Found new conflicting delete files that can apply to records matching %s: %s",
@@ -476,10 +581,29 @@ abstract class MergingSnapshotProducer<ThisT> extends SnapshotProducer<ThisT> {
* @param base table metadata to validate
* @param startingSnapshotId id of the snapshot current at the start of the operation
* @param partitionSet a partition set used to find new conflicting delete files
+ * @deprecated will be removed in 1.3.0; use {@link
+ * MergingSnapshotProducer#validateNoNewDeleteFiles(TableMetadata, Long, PartitionSet,
+ * Snapshot)} instead
*/
+ @Deprecated
protected void validateNoNewDeleteFiles(
TableMetadata base, Long startingSnapshotId, PartitionSet partitionSet) {
- DeleteFileIndex deletes = addedDeleteFiles(base, startingSnapshotId, null, partitionSet);
+ validateNoNewDeleteFiles(base, startingSnapshotId, partitionSet, base.currentSnapshot());
+ }
+
+ /**
+ * Validates that no delete files matching a partition set have been added to the table since a
+ * starting snapshot.
+ *
+ * @param base table metadata to validate
+ * @param startingSnapshotId id of the snapshot current at the start of the operation
+ * @param partitionSet a partition set used to find new conflicting delete files
+ * @param parent ending snapshot on the branch being validated
+ */
+ protected void validateNoNewDeleteFiles(
+ TableMetadata base, Long startingSnapshotId, PartitionSet partitionSet, Snapshot parent) {
+ DeleteFileIndex deletes =
+ addedDeleteFiles(base, startingSnapshotId, null, partitionSet, parent);
ValidationException.check(
deletes.isEmpty(),
"Found new conflicting delete files that can apply to records matching %s: %s",
@@ -494,14 +618,37 @@ abstract class MergingSnapshotProducer<ThisT> extends SnapshotProducer<ThisT> {
* @param startingSnapshotId id of the snapshot current at the start of the operation
* @param dataFilter an expression used to find delete files
* @param partitionSet a partition set used to find delete files
+ * @deprecated will be removed in 1.3.0; use {@link
+ * MergingSnapshotProducer#addedDeleteFiles(TableMetadata, Long, Expression, PartitionSet,
+ * Snapshot)} instead
*/
+ @Deprecated
protected DeleteFileIndex addedDeleteFiles(
TableMetadata base,
Long startingSnapshotId,
Expression dataFilter,
PartitionSet partitionSet) {
+ return addedDeleteFiles(
+ base, startingSnapshotId, dataFilter, partitionSet, base.currentSnapshot());
+ }
+
+ /**
+ * Returns matching delete files have been added to the table since a starting snapshot.
+ *
+ * @param base table metadata to validate
+ * @param startingSnapshotId id of the snapshot current at the start of the operation
+ * @param dataFilter an expression used to find delete files
+ * @param partitionSet a partition set used to find delete files
+ * @param parent parent snapshot of the branch
+ */
+ protected DeleteFileIndex addedDeleteFiles(
+ TableMetadata base,
+ Long startingSnapshotId,
+ Expression dataFilter,
+ PartitionSet partitionSet,
+ Snapshot parent) {
// if there is no current table state, return empty delete file index
- if (base.currentSnapshot() == null || base.formatVersion() < 2) {
+ if (parent == null || base.formatVersion() < 2) {
return DeleteFileIndex.builderFor(ops.io(), ImmutableList.of())
.specsById(base.specsById())
.build();
@@ -512,7 +659,8 @@ abstract class MergingSnapshotProducer<ThisT> extends SnapshotProducer<ThisT> {
base,
startingSnapshotId,
VALIDATE_ADDED_DELETE_FILES_OPERATIONS,
- ManifestContent.DELETES);
+ ManifestContent.DELETES,
+ parent);
List<ManifestFile> deleteManifests = history.first();
long startingSequenceNumber = startingSequenceNumber(base, startingSnapshotId);
@@ -526,11 +674,29 @@ abstract class MergingSnapshotProducer<ThisT> extends SnapshotProducer<ThisT> {
* @param base table metadata to validate
* @param startingSnapshotId id of the snapshot current at the start of the operation
* @param dataFilter an expression used to find deleted data files
+ * @deprecated will be removed in 1.3.0; use {@link
+ * MergingSnapshotProducer#validateDeletedDataFiles(TableMetadata, Long, Expression,
+ * Snapshot)} instead
*/
+ @Deprecated
protected void validateDeletedDataFiles(
TableMetadata base, Long startingSnapshotId, Expression dataFilter) {
+ validateDeletedDataFiles(base, startingSnapshotId, dataFilter, base.currentSnapshot());
+ }
+
+ /**
+ * Validates that no files matching a filter have been deleted from the table since a starting
+ * snapshot.
+ *
+ * @param base table metadata to validate
+ * @param startingSnapshotId id of the snapshot current at the start of the operation
+ * @param dataFilter an expression used to find deleted data files
+ * @param parent ending snapshot on the branch being validated
+ */
+ protected void validateDeletedDataFiles(
+ TableMetadata base, Long startingSnapshotId, Expression dataFilter, Snapshot parent) {
CloseableIterable<ManifestEntry<DataFile>> conflictEntries =
- deletedDataFiles(base, startingSnapshotId, dataFilter, null);
+ deletedDataFiles(base, startingSnapshotId, dataFilter, null, parent);
try (CloseableIterator<ManifestEntry<DataFile>> conflicts = conflictEntries.iterator()) {
if (conflicts.hasNext()) {
@@ -554,11 +720,29 @@ abstract class MergingSnapshotProducer<ThisT> extends SnapshotProducer<ThisT> {
* @param base table metadata to validate
* @param startingSnapshotId id of the snapshot current at the start of the operation
* @param partitionSet a partition set used to find deleted data files
+ * @deprecated will be removed in 1.3.0; use {@link
+ * MergingSnapshotProducer#validateNoNewDeleteFiles(TableMetadata, Long, PartitionSet,
+ * Snapshot)} instead
*/
+ @Deprecated
protected void validateDeletedDataFiles(
TableMetadata base, Long startingSnapshotId, PartitionSet partitionSet) {
+ validateDeletedDataFiles(base, startingSnapshotId, partitionSet, base.currentSnapshot());
+ }
+
+ /**
+ * Validates that no files matching a filter have been deleted from the table since a starting
+ * snapshot.
+ *
+ * @param base table metadata to validate
+ * @param startingSnapshotId id of the snapshot current at the start of the operation
+ * @param partitionSet a partition set used to find deleted data files
+ * @param parent ending snapshot on the branch being validated
+ */
+ protected void validateDeletedDataFiles(
+ TableMetadata base, Long startingSnapshotId, PartitionSet partitionSet, Snapshot parent) {
CloseableIterable<ManifestEntry<DataFile>> conflictEntries =
- deletedDataFiles(base, startingSnapshotId, null, partitionSet);
+ deletedDataFiles(base, startingSnapshotId, null, partitionSet, parent);
try (CloseableIterator<ManifestEntry<DataFile>> conflicts = conflictEntries.iterator()) {
if (conflicts.hasNext()) {
@@ -583,20 +767,26 @@ abstract class MergingSnapshotProducer<ThisT> extends SnapshotProducer<ThisT> {
* @param startingSnapshotId id of the snapshot current at the start of the operation
* @param dataFilter an expression used to find deleted data files
* @param partitionSet a set of partitions to find deleted data files
+ * @param parent ending snapshot on the branch being validated
*/
private CloseableIterable<ManifestEntry<DataFile>> deletedDataFiles(
TableMetadata base,
Long startingSnapshotId,
Expression dataFilter,
- PartitionSet partitionSet) {
+ PartitionSet partitionSet,
+ Snapshot parent) {
// if there is no current table state, no files have been deleted
- if (base.currentSnapshot() == null) {
+ if (parent == null) {
return CloseableIterable.empty();
}
Pair<List<ManifestFile>, Set<Long>> history =
validationHistory(
- base, startingSnapshotId, VALIDATE_DATA_FILES_EXIST_OPERATIONS, ManifestContent.DATA);
+ base,
+ startingSnapshotId,
+ VALIDATE_DATA_FILES_EXIST_OPERATIONS,
+ ManifestContent.DATA,
+ parent);
List<ManifestFile> manifests = history.first();
Set<Long> newSnapshots = history.second();
@@ -656,15 +846,37 @@ abstract class MergingSnapshotProducer<ThisT> extends SnapshotProducer<ThisT> {
return builder.build();
}
- @SuppressWarnings("CollectionUndefinedEquality")
+ @Deprecated
+ /**
+ * @deprecated will be removed in 1.3.0 use {@link
+ * MergingSnapshotProducer#validateDataFilesExist(TableMetadata, Long, CharSequenceSet,
+ * boolean, Expression, Snapshot)} instead.
+ */
protected void validateDataFilesExist(
TableMetadata base,
Long startingSnapshotId,
CharSequenceSet requiredDataFiles,
boolean skipDeletes,
Expression conflictDetectionFilter) {
+ validateDataFilesExist(
+ base,
+ startingSnapshotId,
+ requiredDataFiles,
+ skipDeletes,
+ conflictDetectionFilter,
+ base.currentSnapshot());
+ }
+
+ @SuppressWarnings("CollectionUndefinedEquality")
+ protected void validateDataFilesExist(
+ TableMetadata base,
+ Long startingSnapshotId,
+ CharSequenceSet requiredDataFiles,
+ boolean skipDeletes,
+ Expression conflictDetectionFilter,
+ Snapshot parent) {
// if there is no current table state, no files have been removed
- if (base.currentSnapshot() == null) {
+ if (parent == null) {
return;
}
@@ -674,7 +886,8 @@ abstract class MergingSnapshotProducer<ThisT> extends SnapshotProducer<ThisT> {
: VALIDATE_DATA_FILES_EXIST_OPERATIONS;
Pair<List<ManifestFile>, Set<Long>> history =
- validationHistory(base, startingSnapshotId, matchingOperations, ManifestContent.DATA);
+ validationHistory(
+ base, startingSnapshotId, matchingOperations, ManifestContent.DATA, parent);
List<ManifestFile> manifests = history.first();
Set<Long> newSnapshots = history.second();
@@ -710,14 +923,14 @@ abstract class MergingSnapshotProducer<ThisT> extends SnapshotProducer<ThisT> {
TableMetadata base,
Long startingSnapshotId,
Set<String> matchingOperations,
- ManifestContent content) {
+ ManifestContent content,
+ Snapshot parent) {
List<ManifestFile> manifests = Lists.newArrayList();
Set<Long> newSnapshots = Sets.newHashSet();
Snapshot lastSnapshot = null;
Iterable<Snapshot> snapshots =
- SnapshotUtil.ancestorsBetween(
- base.currentSnapshot().snapshotId(), startingSnapshotId, base::snapshot);
+ SnapshotUtil.ancestorsBetween(parent.snapshotId(), startingSnapshotId, base::snapshot);
for (Snapshot currentSnapshot : snapshots) {
lastSnapshot = currentSnapshot;
diff --git a/core/src/main/java/org/apache/iceberg/SnapshotProducer.java b/core/src/main/java/org/apache/iceberg/SnapshotProducer.java
index f11cad4e79..4a7aa74631 100644
--- a/core/src/main/java/org/apache/iceberg/SnapshotProducer.java
+++ b/core/src/main/java/org/apache/iceberg/SnapshotProducer.java
@@ -267,9 +267,10 @@ abstract class SnapshotProducer<ThisT> implements SnapshotUpdate<ThisT> {
}
Map<String, String> previousSummary;
- if (previous.currentSnapshot() != null) {
- if (previous.currentSnapshot().summary() != null) {
- previousSummary = previous.currentSnapshot().summary();
+ SnapshotRef previousBranchHead = previous.ref(targetBranch);
+ if (previousBranchHead != null) {
+ if (previous.snapshot(previousBranchHead.snapshotId()).summary() != null) {
+ previousSummary = previous.snapshot(previousBranchHead.snapshotId()).summary();
} else {
// previous snapshot had no summary, use an empty summary
previousSummary = ImmutableMap.of();
diff --git a/core/src/test/java/org/apache/iceberg/TableTestBase.java b/core/src/test/java/org/apache/iceberg/TableTestBase.java
index e118b42000..0914f1d773 100644
--- a/core/src/test/java/org/apache/iceberg/TableTestBase.java
+++ b/core/src/test/java/org/apache/iceberg/TableTestBase.java
@@ -458,13 +458,25 @@ public class TableTestBase {
Assert.assertEquals("Files should match", expectedFilePaths, actualFilePaths);
}
- void validateTableDeleteFiles(Table tbl, DeleteFile... expectedFiles) {
+ void validateBranchFiles(Table tbl, String ref, DataFile... expectedFiles) {
+ Set<CharSequence> expectedFilePaths = Sets.newHashSet();
+ for (DataFile file : expectedFiles) {
+ expectedFilePaths.add(file.path());
+ }
+ Set<CharSequence> actualFilePaths = Sets.newHashSet();
+ for (FileScanTask task : tbl.newScan().useRef(ref).planFiles()) {
+ actualFilePaths.add(task.file().path());
+ }
+ Assert.assertEquals("Files should match", expectedFilePaths, actualFilePaths);
+ }
+
+ void validateBranchDeleteFiles(Table tbl, String branch, DeleteFile... expectedFiles) {
Set<CharSequence> expectedFilePaths = Sets.newHashSet();
for (DeleteFile file : expectedFiles) {
expectedFilePaths.add(file.path());
}
Set<CharSequence> actualFilePaths = Sets.newHashSet();
- for (FileScanTask task : tbl.newScan().planFiles()) {
+ for (FileScanTask task : tbl.newScan().useRef(branch).planFiles()) {
for (DeleteFile file : task.deletes()) {
actualFilePaths.add(file.path());
}
diff --git a/core/src/test/java/org/apache/iceberg/TestOverwrite.java b/core/src/test/java/org/apache/iceberg/TestOverwrite.java
index 082f6396bd..7df76961f3 100644
--- a/core/src/test/java/org/apache/iceberg/TestOverwrite.java
+++ b/core/src/test/java/org/apache/iceberg/TestOverwrite.java
@@ -102,13 +102,21 @@ public class TestOverwrite extends TableTestBase {
))
.build();
- @Parameterized.Parameters(name = "formatVersion = {0}")
+ private final String branch;
+
+ @Parameterized.Parameters(name = "formatVersion = {0}, branch = {1}")
public static Object[] parameters() {
- return new Object[] {1, 2};
+ return new Object[][] {
+ new Object[] {1, "main"},
+ new Object[] {1, "testBranch"},
+ new Object[] {2, "main"},
+ new Object[] {2, "testBranch"}
+ };
}
- public TestOverwrite(int formatVersion) {
+ public TestOverwrite(int formatVersion, String branch) {
super(formatVersion);
+ this.branch = branch;
}
private static ByteBuffer longToBuffer(long value) {
@@ -125,26 +133,26 @@ public class TestOverwrite extends TableTestBase {
this.table =
TestTables.create(tableDir, TABLE_NAME, DATE_SCHEMA, PARTITION_BY_DATE, formatVersion);
- table.newAppend().appendFile(FILE_0_TO_4).appendFile(FILE_5_TO_9).commit();
+ commit(table, table.newAppend().appendFile(FILE_0_TO_4).appendFile(FILE_5_TO_9), branch);
}
@Test
public void testOverwriteWithoutAppend() {
TableMetadata base = TestTables.readMetadata(TABLE_NAME);
- long baseId = base.currentSnapshot().snapshotId();
+ long baseId = latestSnapshot(base, branch).snapshotId();
- table.newOverwrite().overwriteByRowFilter(equal("date", "2018-06-08")).commit();
+ commit(table, table.newOverwrite().overwriteByRowFilter(equal("date", "2018-06-08")), branch);
- long overwriteId = table.currentSnapshot().snapshotId();
+ long overwriteId = latestSnapshot(table, branch).snapshotId();
Assert.assertNotEquals("Should create a new snapshot", baseId, overwriteId);
Assert.assertEquals(
"Table should have one manifest",
1,
- table.currentSnapshot().allManifests(table.io()).size());
+ latestSnapshot(table, branch).allManifests(table.io()).size());
validateManifestEntries(
- table.currentSnapshot().allManifests(table.io()).get(0),
+ latestSnapshot(table, branch).allManifests(table.io()).get(0),
ids(overwriteId, baseId),
files(FILE_0_TO_4, FILE_5_TO_9),
statuses(Status.DELETED, Status.EXISTING));
@@ -153,7 +161,8 @@ public class TestOverwrite extends TableTestBase {
@Test
public void testOverwriteFailsDelete() {
TableMetadata base = TestTables.readMetadata(TABLE_NAME);
- long baseId = base.currentSnapshot().snapshotId();
+ long baseId =
+ latestSnapshot(base, branch) == null ? -1 : latestSnapshot(base, branch).snapshotId();
OverwriteFiles overwrite =
table
@@ -164,40 +173,43 @@ public class TestOverwrite extends TableTestBase {
"Should reject commit with file not matching delete expression",
ValidationException.class,
"Cannot delete file where some, but not all, rows match filter",
- overwrite::commit);
+ () -> commit(table, overwrite, branch));
Assert.assertEquals(
- "Should not create a new snapshot", baseId, table.currentSnapshot().snapshotId());
+ "Should not create a new snapshot", baseId, latestSnapshot(base, branch).snapshotId());
}
@Test
public void testOverwriteWithAppendOutsideOfDelete() {
TableMetadata base = TestTables.readMetadata(TABLE_NAME);
- long baseId = base.currentSnapshot().snapshotId();
+ long baseId =
+ latestSnapshot(base, branch) == null ? -1 : latestSnapshot(base, branch).snapshotId();
- table
- .newOverwrite()
- .overwriteByRowFilter(equal("date", "2018-06-08"))
- .addFile(FILE_10_TO_14) // in 2018-06-09, NOT in 2018-06-08
- .commit();
+ commit(
+ table,
+ table
+ .newOverwrite()
+ .overwriteByRowFilter(equal("date", "2018-06-08"))
+ .addFile(FILE_10_TO_14),
+ branch); // in 2018-06-09, NOT in 2018-06-08
- long overwriteId = table.currentSnapshot().snapshotId();
+ long overwriteId = latestSnapshot(table, branch).snapshotId();
Assert.assertNotEquals("Should create a new snapshot", baseId, overwriteId);
Assert.assertEquals(
"Table should have 2 manifests",
2,
- table.currentSnapshot().allManifests(table.io()).size());
+ latestSnapshot(table, branch).allManifests(table.io()).size());
// manifest is not merged because it is less than the minimum
validateManifestEntries(
- table.currentSnapshot().allManifests(table.io()).get(0),
+ latestSnapshot(table, branch).allManifests(table.io()).get(0),
ids(overwriteId),
files(FILE_10_TO_14),
statuses(Status.ADDED));
validateManifestEntries(
- table.currentSnapshot().allManifests(table.io()).get(1),
+ latestSnapshot(table, branch).allManifests(table.io()).get(1),
ids(overwriteId, baseId),
files(FILE_0_TO_4, FILE_5_TO_9),
statuses(Status.DELETED, Status.EXISTING));
@@ -209,24 +221,27 @@ public class TestOverwrite extends TableTestBase {
table.updateProperties().set(TableProperties.MANIFEST_MIN_MERGE_COUNT, "1").commit();
TableMetadata base = TestTables.readMetadata(TABLE_NAME);
- long baseId = base.currentSnapshot().snapshotId();
+ long baseId =
+ latestSnapshot(base, branch) == null ? -1 : latestSnapshot(base, branch).snapshotId();
- table
- .newOverwrite()
- .overwriteByRowFilter(equal("date", "2018-06-08"))
- .addFile(FILE_10_TO_14) // in 2018-06-09, NOT in 2018-06-08
- .commit();
+ commit(
+ table,
+ table
+ .newOverwrite()
+ .overwriteByRowFilter(equal("date", "2018-06-08"))
+ .addFile(FILE_10_TO_14),
+ branch); // in 2018-06-09, NOT in 2018-06-08
- long overwriteId = table.currentSnapshot().snapshotId();
+ long overwriteId = latestSnapshot(table, branch).snapshotId();
Assert.assertNotEquals("Should create a new snapshot", baseId, overwriteId);
Assert.assertEquals(
"Table should have one merged manifest",
1,
- table.currentSnapshot().allManifests(table.io()).size());
+ latestSnapshot(table, branch).allManifests(table.io()).size());
validateManifestEntries(
- table.currentSnapshot().allManifests(table.io()).get(0),
+ latestSnapshot(table, branch).allManifests(table.io()).get(0),
ids(overwriteId, overwriteId, baseId),
files(FILE_10_TO_14, FILE_0_TO_4, FILE_5_TO_9),
statuses(Status.ADDED, Status.DELETED, Status.EXISTING));
@@ -238,7 +253,8 @@ public class TestOverwrite extends TableTestBase {
table.updateProperties().set(TableProperties.MANIFEST_MIN_MERGE_COUNT, "1").commit();
TableMetadata base = TestTables.readMetadata(TABLE_NAME);
- long baseId = base.currentSnapshot().snapshotId();
+ long baseId =
+ latestSnapshot(base, branch) == null ? -1 : latestSnapshot(base, branch).snapshotId();
OverwriteFiles overwrite =
table
@@ -251,16 +267,17 @@ public class TestOverwrite extends TableTestBase {
"Should reject commit with file not matching delete expression",
ValidationException.class,
"Cannot append file with rows that do not match filter",
- overwrite::commit);
+ () -> commit(table, overwrite, branch));
Assert.assertEquals(
- "Should not create a new snapshot", baseId, table.currentSnapshot().snapshotId());
+ "Should not create a new snapshot", baseId, latestSnapshot(table, branch).snapshotId());
}
@Test
public void testValidatedOverwriteWithAppendOutsideOfDeleteMetrics() {
TableMetadata base = TestTables.readMetadata(TABLE_NAME);
- long baseId = base.currentSnapshot().snapshotId();
+ long baseId =
+ latestSnapshot(base, branch) == null ? -1 : latestSnapshot(base, branch).snapshotId();
OverwriteFiles overwrite =
table
@@ -273,16 +290,17 @@ public class TestOverwrite extends TableTestBase {
"Should reject commit with file not matching delete expression",
ValidationException.class,
"Cannot append file with rows that do not match filter",
- overwrite::commit);
+ () -> commit(table, overwrite, branch));
Assert.assertEquals(
- "Should not create a new snapshot", baseId, table.currentSnapshot().snapshotId());
+ "Should not create a new snapshot", baseId, latestSnapshot(base, branch).snapshotId());
}
@Test
public void testValidatedOverwriteWithAppendSuccess() {
TableMetadata base = TestTables.readMetadata(TABLE_NAME);
- long baseId = base.currentSnapshot().snapshotId();
+ long baseId =
+ latestSnapshot(base, branch) == null ? -1 : latestSnapshot(base, branch).snapshotId();
OverwriteFiles overwrite =
table
@@ -295,22 +313,9 @@ public class TestOverwrite extends TableTestBase {
"Should reject commit with file not matching delete expression",
ValidationException.class,
"Cannot append file with rows that do not match filter",
- overwrite::commit);
+ () -> commit(table, overwrite, branch));
Assert.assertEquals(
- "Should not create a new snapshot", baseId, table.currentSnapshot().snapshotId());
- }
-
- @Test
- public void testOverwriteToBranchUnsupported() {
- AssertHelpers.assertThrows(
- "Cannot commit to branch someBranch: org.apache.iceberg.BaseOverwriteFiles does not support branch commits",
- UnsupportedOperationException.class,
- () ->
- table
- .newOverwrite()
- .overwriteByRowFilter(and(equal("date", "2018-06-09"), lessThan("id", 20)))
- .addFile(FILE_10_TO_14)
- .toBranch("someBranch"));
+ "Should not create a new snapshot", baseId, latestSnapshot(base, branch).snapshotId());
}
}
diff --git a/core/src/test/java/org/apache/iceberg/TestOverwriteWithValidation.java b/core/src/test/java/org/apache/iceberg/TestOverwriteWithValidation.java
index acc11b6d8e..0b7ed03025 100644
--- a/core/src/test/java/org/apache/iceberg/TestOverwriteWithValidation.java
+++ b/core/src/test/java/org/apache/iceberg/TestOverwriteWithValidation.java
@@ -177,13 +177,21 @@ public class TestOverwriteWithValidation extends TableTestBase {
private static final Expression EXPRESSION_DAY_2_ANOTHER_ID_RANGE = greaterThanOrEqual("id", 10L);
- @Parameterized.Parameters(name = "formatVersion = {0}")
+ private final String branch;
+
+ @Parameterized.Parameters(name = "formatVersion = {0}, branch = {1}")
public static Object[] parameters() {
- return new Object[] {1, 2};
+ return new Object[][] {
+ new Object[] {1, "main"},
+ new Object[] {1, "testBranch"},
+ new Object[] {2, "main"},
+ new Object[] {2, "testBranch"}
+ };
}
- public TestOverwriteWithValidation(int formatVersion) {
+ public TestOverwriteWithValidation(int formatVersion, String branch) {
super(formatVersion);
+ this.branch = branch;
}
private static ByteBuffer longToBuffer(long value) {
@@ -202,112 +210,120 @@ public class TestOverwriteWithValidation extends TableTestBase {
@Test
public void testOverwriteEmptyTableNotValidated() {
- Assert.assertNull("Should be empty table", table.currentSnapshot());
+ Assert.assertNull("Should be empty table", latestSnapshot(table, branch));
- table.newOverwrite().addFile(FILE_DAY_2_MODIFIED).commit();
+ commit(table, table.newOverwrite().addFile(FILE_DAY_2_MODIFIED), branch);
- validateTableFiles(table, FILE_DAY_2_MODIFIED);
+ validateBranchFiles(table, branch, FILE_DAY_2_MODIFIED);
}
@Test
public void testOverwriteEmptyTableStrictValidated() {
- Assert.assertNull("Should be empty table", table.currentSnapshot());
+ Assert.assertNull("Should be empty table", latestSnapshot(table, branch));
- table
- .newOverwrite()
- .addFile(FILE_DAY_2_MODIFIED)
- .conflictDetectionFilter(alwaysTrue())
- .validateNoConflictingData()
- .commit();
+ commit(
+ table,
+ table
+ .newOverwrite()
+ .addFile(FILE_DAY_2_MODIFIED)
+ .conflictDetectionFilter(alwaysTrue())
+ .validateNoConflictingData(),
+ branch);
- validateTableFiles(table, FILE_DAY_2_MODIFIED);
+ validateBranchFiles(table, branch, FILE_DAY_2_MODIFIED);
}
@Test
public void testOverwriteEmptyTableValidated() {
- Assert.assertNull("Should be empty table", table.currentSnapshot());
+ Assert.assertNull("Should be empty table", latestSnapshot(table, branch));
- table
- .newOverwrite()
- .addFile(FILE_DAY_2_MODIFIED)
- .conflictDetectionFilter(EXPRESSION_DAY_2)
- .validateNoConflictingData()
- .commit();
+ commit(
+ table,
+ table
+ .newOverwrite()
+ .addFile(FILE_DAY_2_MODIFIED)
+ .conflictDetectionFilter(EXPRESSION_DAY_2)
+ .validateNoConflictingData(),
+ branch);
- validateTableFiles(table, FILE_DAY_2_MODIFIED);
+ validateBranchFiles(table, branch, FILE_DAY_2_MODIFIED);
}
@Test
public void testOverwriteTableNotValidated() {
- table.newAppend().appendFile(FILE_DAY_1).appendFile(FILE_DAY_2).commit();
+ commit(table, table.newAppend().appendFile(FILE_DAY_1).appendFile(FILE_DAY_2), branch);
- Snapshot baseSnapshot = table.currentSnapshot();
+ Snapshot baseSnapshot = latestSnapshot(table, branch);
validateSnapshot(null, baseSnapshot, FILE_DAY_1, FILE_DAY_2);
- table.newOverwrite().deleteFile(FILE_DAY_2).addFile(FILE_DAY_2_MODIFIED).commit();
+ commit(table, table.newOverwrite().deleteFile(FILE_DAY_2).addFile(FILE_DAY_2_MODIFIED), branch);
- validateTableFiles(table, FILE_DAY_1, FILE_DAY_2_MODIFIED);
+ validateBranchFiles(table, branch, FILE_DAY_1, FILE_DAY_2_MODIFIED);
}
@Test
public void testOverwriteTableStrictValidated() {
- table.newAppend().appendFile(FILE_DAY_1).appendFile(FILE_DAY_2).commit();
+ commit(table, table.newAppend().appendFile(FILE_DAY_1).appendFile(FILE_DAY_2), branch);
- Snapshot baseSnapshot = table.currentSnapshot();
+ Snapshot baseSnapshot = latestSnapshot(table, branch);
validateSnapshot(null, baseSnapshot, FILE_DAY_1, FILE_DAY_2);
- table
- .newOverwrite()
- .deleteFile(FILE_DAY_2)
- .addFile(FILE_DAY_2_MODIFIED)
- .validateFromSnapshot(baseSnapshot.snapshotId())
- .conflictDetectionFilter(alwaysTrue())
- .validateNoConflictingData()
- .commit();
+ commit(
+ table,
+ table
+ .newOverwrite()
+ .deleteFile(FILE_DAY_2)
+ .addFile(FILE_DAY_2_MODIFIED)
+ .validateFromSnapshot(baseSnapshot.snapshotId())
+ .conflictDetectionFilter(alwaysTrue())
+ .validateNoConflictingData(),
+ branch);
- validateTableFiles(table, FILE_DAY_1, FILE_DAY_2_MODIFIED);
+ validateBranchFiles(table, branch, FILE_DAY_1, FILE_DAY_2_MODIFIED);
}
@Test
public void testOverwriteTableValidated() {
- table.newAppend().appendFile(FILE_DAY_1).appendFile(FILE_DAY_2).commit();
+ commit(table, table.newAppend().appendFile(FILE_DAY_1).appendFile(FILE_DAY_2), branch);
- Snapshot baseSnapshot = table.currentSnapshot();
+ Snapshot baseSnapshot = latestSnapshot(table, branch);
validateSnapshot(null, baseSnapshot, FILE_DAY_1, FILE_DAY_2);
- table
- .newOverwrite()
- .deleteFile(FILE_DAY_2)
- .addFile(FILE_DAY_2_MODIFIED)
- .validateFromSnapshot(baseSnapshot.snapshotId())
- .conflictDetectionFilter(EXPRESSION_DAY_2)
- .validateNoConflictingData()
- .commit();
+ commit(
+ table,
+ table
+ .newOverwrite()
+ .deleteFile(FILE_DAY_2)
+ .addFile(FILE_DAY_2_MODIFIED)
+ .validateFromSnapshot(baseSnapshot.snapshotId())
+ .conflictDetectionFilter(EXPRESSION_DAY_2)
+ .validateNoConflictingData(),
+ branch);
- validateTableFiles(table, FILE_DAY_1, FILE_DAY_2_MODIFIED);
+ validateBranchFiles(table, branch, FILE_DAY_1, FILE_DAY_2_MODIFIED);
}
@Test
public void testOverwriteCompatibleAdditionNotValidated() {
- table.newAppend().appendFile(FILE_DAY_2).commit();
+ commit(table, table.newAppend().appendFile(FILE_DAY_2), branch);
- validateSnapshot(null, table.currentSnapshot(), FILE_DAY_2);
+ validateSnapshot(null, latestSnapshot(table, branch), FILE_DAY_2);
OverwriteFiles overwrite =
table.newOverwrite().deleteFile(FILE_DAY_2).addFile(FILE_DAY_2_MODIFIED);
- table.newAppend().appendFile(FILE_DAY_1).commit();
+ commit(table, table.newAppend().appendFile(FILE_DAY_1), branch);
- overwrite.commit();
+ commit(table, overwrite, branch);
- validateTableFiles(table, FILE_DAY_1, FILE_DAY_2_MODIFIED);
+ validateBranchFiles(table, branch, FILE_DAY_1, FILE_DAY_2_MODIFIED);
}
@Test
public void testOverwriteCompatibleAdditionStrictValidated() {
- table.newAppend().appendFile(FILE_DAY_2).commit();
+ commit(table, table.newAppend().appendFile(FILE_DAY_2), branch);
- Snapshot baseSnapshot = table.currentSnapshot();
+ Snapshot baseSnapshot = latestSnapshot(table, branch);
validateSnapshot(null, baseSnapshot, FILE_DAY_2);
OverwriteFiles overwrite =
@@ -319,26 +335,26 @@ public class TestOverwriteWithValidation extends TableTestBase {
.conflictDetectionFilter(alwaysTrue())
.validateNoConflictingData();
- table.newAppend().appendFile(FILE_DAY_1).commit();
- long committedSnapshotId = table.currentSnapshot().snapshotId();
+ commit(table, table.newAppend().appendFile(FILE_DAY_1), branch);
+ long committedSnapshotId = latestSnapshot(table, branch).snapshotId();
AssertHelpers.assertThrows(
"Should reject commit",
ValidationException.class,
"Found conflicting files",
- overwrite::commit);
+ () -> commit(table, overwrite, branch));
Assert.assertEquals(
"Should not create a new snapshot",
committedSnapshotId,
- table.currentSnapshot().snapshotId());
+ latestSnapshot(table, branch).snapshotId());
}
@Test
public void testOverwriteCompatibleAdditionValidated() {
- table.newAppend().appendFile(FILE_DAY_2).commit();
+ commit(table, table.newAppend().appendFile(FILE_DAY_2), branch);
- Snapshot baseSnapshot = table.currentSnapshot();
+ Snapshot baseSnapshot = latestSnapshot(table, branch);
validateSnapshot(null, baseSnapshot, FILE_DAY_2);
OverwriteFiles overwrite =
@@ -350,18 +366,18 @@ public class TestOverwriteWithValidation extends TableTestBase {
.conflictDetectionFilter(EXPRESSION_DAY_2)
.validateNoConflictingData();
- table.newAppend().appendFile(FILE_DAY_1).commit();
+ commit(table, table.newAppend().appendFile(FILE_DAY_1), branch);
- overwrite.commit();
+ commit(table, overwrite, branch);
- validateTableFiles(table, FILE_DAY_1, FILE_DAY_2_MODIFIED);
+ validateBranchFiles(table, branch, FILE_DAY_1, FILE_DAY_2_MODIFIED);
}
@Test
public void testOverwriteCompatibleDeletionValidated() {
- table.newAppend().appendFile(FILE_DAY_1).appendFile(FILE_DAY_2).commit();
+ commit(table, table.newAppend().appendFile(FILE_DAY_1).appendFile(FILE_DAY_2), branch);
- Snapshot baseSnapshot = table.currentSnapshot();
+ Snapshot baseSnapshot = latestSnapshot(table, branch);
validateSnapshot(null, baseSnapshot, FILE_DAY_1, FILE_DAY_2);
OverwriteFiles overwrite =
@@ -373,18 +389,18 @@ public class TestOverwriteWithValidation extends TableTestBase {
.conflictDetectionFilter(EXPRESSION_DAY_2)
.validateNoConflictingData();
- table.newDelete().deleteFile(FILE_DAY_1).commit();
+ commit(table, table.newDelete().deleteFile(FILE_DAY_1), branch);
- overwrite.commit();
+ commit(table, overwrite, branch);
- validateTableFiles(table, FILE_DAY_2_MODIFIED);
+ validateBranchFiles(table, branch, FILE_DAY_2_MODIFIED);
}
@Test
public void testOverwriteIncompatibleAdditionValidated() {
- table.newAppend().appendFile(FILE_DAY_1).commit();
+ commit(table, table.newAppend().appendFile(FILE_DAY_1), branch);
- Snapshot baseSnapshot = table.currentSnapshot();
+ Snapshot baseSnapshot = latestSnapshot(table, branch);
validateSnapshot(null, baseSnapshot, FILE_DAY_1);
OverwriteFiles overwrite =
@@ -395,26 +411,26 @@ public class TestOverwriteWithValidation extends TableTestBase {
.conflictDetectionFilter(EXPRESSION_DAY_2)
.validateNoConflictingData();
- table.newAppend().appendFile(FILE_DAY_2).commit();
- long committedSnapshotId = table.currentSnapshot().snapshotId();
+ commit(table, table.newAppend().appendFile(FILE_DAY_2), branch);
+ long committedSnapshotId = latestSnapshot(table, branch).snapshotId();
AssertHelpers.assertThrows(
"Should reject commit",
ValidationException.class,
"Found conflicting files",
- overwrite::commit);
+ () -> commit(table, overwrite, branch));
Assert.assertEquals(
"Should not create a new snapshot",
committedSnapshotId,
- table.currentSnapshot().snapshotId());
+ latestSnapshot(table, branch).snapshotId());
}
@Test
public void testOverwriteIncompatibleDeletionValidated() {
- table.newAppend().appendFile(FILE_DAY_1).appendFile(FILE_DAY_2).commit();
+ commit(table, table.newAppend().appendFile(FILE_DAY_1).appendFile(FILE_DAY_2), branch);
- Snapshot baseSnapshot = table.currentSnapshot();
+ Snapshot baseSnapshot = latestSnapshot(table, branch);
validateSnapshot(null, baseSnapshot, FILE_DAY_1, FILE_DAY_2);
OverwriteFiles overwrite =
@@ -426,26 +442,26 @@ public class TestOverwriteWithValidation extends TableTestBase {
.conflictDetectionFilter(EXPRESSION_DAY_2)
.validateNoConflictingData();
- table.newDelete().deleteFile(FILE_DAY_2).commit();
- long committedSnapshotId = table.currentSnapshot().snapshotId();
+ commit(table, table.newDelete().deleteFile(FILE_DAY_2), branch);
+ long committedSnapshotId = latestSnapshot(table, branch).snapshotId();
AssertHelpers.assertThrows(
"Should reject commit",
ValidationException.class,
"Missing required files to delete:",
- overwrite::commit);
+ () -> commit(table, overwrite, branch));
Assert.assertEquals(
"Should not create a new snapshot",
committedSnapshotId,
- table.currentSnapshot().snapshotId());
+ latestSnapshot(table, branch).snapshotId());
}
@Test
public void testOverwriteCompatibleRewriteAllowed() {
- table.newAppend().appendFile(FILE_DAY_1).appendFile(FILE_DAY_2).commit();
+ commit(table, table.newAppend().appendFile(FILE_DAY_1).appendFile(FILE_DAY_2), branch);
- Snapshot baseSnapshot = table.currentSnapshot();
+ Snapshot baseSnapshot = latestSnapshot(table, branch);
validateSnapshot(null, baseSnapshot, FILE_DAY_1, FILE_DAY_2);
OverwriteFiles overwrite =
@@ -457,23 +473,25 @@ public class TestOverwriteWithValidation extends TableTestBase {
.conflictDetectionFilter(EXPRESSION_DAY_2)
.validateNoConflictingData();
- table
- .newRewrite()
- .rewriteFiles(ImmutableSet.of(FILE_DAY_2), ImmutableSet.of(FILE_DAY_2))
- .commit();
- long committedSnapshotId = table.currentSnapshot().snapshotId();
+ commit(
+ table,
+ table.newRewrite().rewriteFiles(ImmutableSet.of(FILE_DAY_2), ImmutableSet.of(FILE_DAY_2)),
+ branch);
+ long committedSnapshotId = latestSnapshot(table, branch).snapshotId();
- overwrite.commit();
+ commit(table, overwrite, branch);
Assert.assertNotEquals(
- "Should successfully commit", committedSnapshotId, table.currentSnapshot().snapshotId());
+ "Should successfully commit",
+ committedSnapshotId,
+ latestSnapshot(table, branch).snapshotId());
}
@Test
public void testOverwriteCompatibleExpirationAdditionValidated() {
- table.newAppend().appendFile(FILE_DAY_2).commit(); // id 1
+ commit(table, table.newAppend().appendFile(FILE_DAY_2), branch); // id 1
- Snapshot baseSnapshot = table.currentSnapshot();
+ Snapshot baseSnapshot = latestSnapshot(table, branch);
validateSnapshot(null, baseSnapshot, FILE_DAY_2);
OverwriteFiles overwrite =
@@ -485,20 +503,20 @@ public class TestOverwriteWithValidation extends TableTestBase {
.conflictDetectionFilter(EXPRESSION_DAY_2)
.validateNoConflictingData();
- table.newAppend().appendFile(FILE_DAY_1).commit(); // id 2
+ commit(table, table.newAppend().appendFile(FILE_DAY_1), branch); // id 2
table.expireSnapshots().expireSnapshotId(1L).commit();
- overwrite.commit();
+ commit(table, overwrite, branch);
- validateTableFiles(table, FILE_DAY_1, FILE_DAY_2_MODIFIED);
+ validateBranchFiles(table, branch, FILE_DAY_1, FILE_DAY_2_MODIFIED);
}
@Test
public void testOverwriteCompatibleExpirationDeletionValidated() {
- table.newAppend().appendFile(FILE_DAY_1).appendFile(FILE_DAY_2).commit(); // id 1
+ commit(table, table.newAppend().appendFile(FILE_DAY_1).appendFile(FILE_DAY_2), branch); // id 1
- Snapshot baseSnapshot = table.currentSnapshot();
+ Snapshot baseSnapshot = latestSnapshot(table, branch);
validateSnapshot(null, baseSnapshot, FILE_DAY_1, FILE_DAY_2);
OverwriteFiles overwrite =
@@ -510,20 +528,20 @@ public class TestOverwriteWithValidation extends TableTestBase {
.conflictDetectionFilter(EXPRESSION_DAY_2)
.validateNoConflictingData();
- table.newDelete().deleteFile(FILE_DAY_1).commit(); // id 2
+ commit(table, table.newDelete().deleteFile(FILE_DAY_1), branch); // id 2
table.expireSnapshots().expireSnapshotId(1L).commit();
- overwrite.commit();
+ commit(table, overwrite, branch);
- validateTableFiles(table, FILE_DAY_2_MODIFIED);
+ validateBranchFiles(table, branch, FILE_DAY_2_MODIFIED);
}
@Test
public void testOverwriteIncompatibleExpirationValidated() {
- table.newAppend().appendFile(FILE_DAY_1).commit(); // id 1
+ commit(table, table.newAppend().appendFile(FILE_DAY_1), branch); // id 1
- Snapshot baseSnapshot = table.currentSnapshot();
+ Snapshot baseSnapshot = latestSnapshot(table, branch);
OverwriteFiles overwrite =
table
.newOverwrite()
@@ -532,28 +550,28 @@ public class TestOverwriteWithValidation extends TableTestBase {
.conflictDetectionFilter(EXPRESSION_DAY_2)
.validateNoConflictingData();
- table.newAppend().appendFile(FILE_DAY_2).commit(); // id 2
+ commit(table, table.newAppend().appendFile(FILE_DAY_2), branch); // id 2
- table.newDelete().deleteFile(FILE_DAY_1).commit(); // id 3
+ commit(table, table.newDelete().deleteFile(FILE_DAY_1), branch); // id 3
table.expireSnapshots().expireSnapshotId(2L).commit();
- long committedSnapshotId = table.currentSnapshot().snapshotId();
+ long committedSnapshotId = latestSnapshot(table, branch).snapshotId();
AssertHelpers.assertThrows(
"Should reject commit",
ValidationException.class,
"Cannot determine history",
- overwrite::commit);
+ () -> commit(table, overwrite, branch));
Assert.assertEquals(
"Should not create a new snapshot",
committedSnapshotId,
- table.currentSnapshot().snapshotId());
+ latestSnapshot(table, branch).snapshotId());
}
@Test
public void testOverwriteIncompatibleBaseExpirationEmptyTableValidated() {
- Assert.assertNull("Should be empty table", table.currentSnapshot());
+ Assert.assertNull("Should be empty table", latestSnapshot(table, branch));
OverwriteFiles overwrite =
table
@@ -562,28 +580,28 @@ public class TestOverwriteWithValidation extends TableTestBase {
.conflictDetectionFilter(EXPRESSION_DAY_2)
.validateNoConflictingData();
- table.newAppend().appendFile(FILE_DAY_2).commit(); // id 1
+ commit(table, table.newAppend().appendFile(FILE_DAY_2), branch); // id 1
- table.newDelete().deleteFile(FILE_DAY_1).commit(); // id 2
+ commit(table, table.newDelete().deleteFile(FILE_DAY_1), branch); // id 2
table.expireSnapshots().expireSnapshotId(1L).commit();
- long committedSnapshotId = table.currentSnapshot().snapshotId();
+ long committedSnapshotId = latestSnapshot(table, branch).snapshotId();
AssertHelpers.assertThrows(
"Should reject commit",
ValidationException.class,
"Cannot determine history",
- overwrite::commit);
+ () -> commit(table, overwrite, branch));
Assert.assertEquals(
"Should not create a new snapshot",
committedSnapshotId,
- table.currentSnapshot().snapshotId());
+ latestSnapshot(table, branch).snapshotId());
}
@Test
public void testOverwriteAnotherRangeValidated() {
- Assert.assertNull("Should be empty table", table.currentSnapshot());
+ Assert.assertNull("Should be empty table", latestSnapshot(table, branch));
OverwriteFiles overwrite =
table
@@ -592,16 +610,16 @@ public class TestOverwriteWithValidation extends TableTestBase {
.conflictDetectionFilter(EXPRESSION_DAY_2_ID_RANGE)
.validateNoConflictingData();
- table.newAppend().appendFile(FILE_DAY_1).commit();
+ commit(table, table.newAppend().appendFile(FILE_DAY_1), branch);
- overwrite.commit();
+ commit(table, overwrite, branch);
- validateTableFiles(table, FILE_DAY_1, FILE_DAY_2_MODIFIED);
+ validateBranchFiles(table, branch, FILE_DAY_1, FILE_DAY_2_MODIFIED);
}
@Test
public void testOverwriteAnotherRangeWithinPartitionValidated() {
- Assert.assertNull("Should be empty table", table.currentSnapshot());
+ Assert.assertNull("Should be empty table", latestSnapshot(table, branch));
Expression conflictDetectionFilter = and(EXPRESSION_DAY_2, EXPRESSION_DAY_2_ID_RANGE);
OverwriteFiles overwrite =
@@ -611,20 +629,20 @@ public class TestOverwriteWithValidation extends TableTestBase {
.conflictDetectionFilter(conflictDetectionFilter)
.validateNoConflictingData();
- table.newAppend().appendFile(FILE_DAY_2_ANOTHER_RANGE).commit();
+ commit(table, table.newAppend().appendFile(FILE_DAY_2_ANOTHER_RANGE), branch);
- overwrite.commit();
+ commit(table, overwrite, branch);
- validateTableFiles(table, FILE_DAY_2_ANOTHER_RANGE, FILE_DAY_2_MODIFIED);
+ validateBranchFiles(table, branch, FILE_DAY_2_ANOTHER_RANGE, FILE_DAY_2_MODIFIED);
}
@Test
public void testTransactionCompatibleAdditionValidated() {
- Assert.assertNull("Should be empty table", table.currentSnapshot());
+ Assert.assertNull("Should be empty table", latestSnapshot(table, branch));
- table.newAppend().appendFile(FILE_DAY_2).commit();
+ commit(table, table.newAppend().appendFile(FILE_DAY_2), branch);
- Snapshot baseSnapshot = table.currentSnapshot();
+ Snapshot baseSnapshot = latestSnapshot(table, branch);
Transaction txn = table.newTransaction();
OverwriteFiles overwrite =
@@ -635,21 +653,21 @@ public class TestOverwriteWithValidation extends TableTestBase {
.conflictDetectionFilter(EXPRESSION_DAY_2)
.validateNoConflictingData();
- table.newAppend().appendFile(FILE_DAY_1).commit();
+ commit(table, table.newAppend().appendFile(FILE_DAY_1), branch);
- overwrite.commit();
+ commit(table, overwrite, branch);
txn.commitTransaction();
- validateTableFiles(table, FILE_DAY_1, FILE_DAY_2_MODIFIED);
+ validateBranchFiles(table, branch, FILE_DAY_1, FILE_DAY_2_MODIFIED);
}
@Test
public void testTransactionIncompatibleAdditionValidated() {
- Assert.assertNull("Should be empty table", table.currentSnapshot());
+ Assert.assertNull("Should be empty table", latestSnapshot(table, branch));
Transaction txn = table.newTransaction();
- txn.newAppend().appendFile(FILE_DAY_1).commit();
+ commit(table, txn.newAppend().appendFile(FILE_DAY_1), branch);
OverwriteFiles overwrite =
txn.newOverwrite()
@@ -657,10 +675,10 @@ public class TestOverwriteWithValidation extends TableTestBase {
.conflictDetectionFilter(EXPRESSION_DAY_2)
.validateNoConflictingData();
- table.newAppend().appendFile(FILE_DAY_2).commit();
- long committedSnapshotId = table.currentSnapshot().snapshotId();
+ commit(table, table.newAppend().appendFile(FILE_DAY_2), branch);
+ long committedSnapshotId = latestSnapshot(table, branch).snapshotId();
- overwrite.commit();
+ commit(table, overwrite, branch);
AssertHelpers.assertThrows(
"Should reject commit",
@@ -671,18 +689,18 @@ public class TestOverwriteWithValidation extends TableTestBase {
Assert.assertEquals(
"Should not create a new snapshot",
committedSnapshotId,
- table.currentSnapshot().snapshotId());
+ latestSnapshot(table, branch).snapshotId());
}
@Test
public void testConcurrentConflictingPositionDeletes() {
Assume.assumeTrue(formatVersion == 2);
- Assert.assertNull("Should be empty table", table.currentSnapshot());
+ Assert.assertNull("Should be empty table", latestSnapshot(table, branch));
- table.newAppend().appendFile(FILE_DAY_1).appendFile(FILE_DAY_2).commit();
+ commit(table, table.newAppend().appendFile(FILE_DAY_1).appendFile(FILE_DAY_2), branch);
- Snapshot firstSnapshot = table.currentSnapshot();
+ Snapshot firstSnapshot = latestSnapshot(table, branch);
OverwriteFiles overwrite =
table
@@ -694,21 +712,24 @@ public class TestOverwriteWithValidation extends TableTestBase {
.validateNoConflictingData()
.validateNoConflictingDeletes();
- table.newRowDelta().addDeletes(FILE_DAY_2_POS_DELETES).commit();
+ commit(table, table.newRowDelta().addDeletes(FILE_DAY_2_POS_DELETES), branch);
AssertHelpers.assertThrows(
- "Should reject commit", ValidationException.class, "found new delete", overwrite::commit);
+ "Should reject commit",
+ ValidationException.class,
+ "found new delete",
+ () -> commit(table, overwrite, branch));
}
@Test
public void testConcurrentConflictingPositionDeletesOverwriteByFilter() {
Assume.assumeTrue(formatVersion == 2);
- Assert.assertNull("Should be empty table", table.currentSnapshot());
+ Assert.assertNull("Should be empty table", latestSnapshot(table, branch));
- table.newAppend().appendFile(FILE_DAY_1).appendFile(FILE_DAY_2).commit();
+ commit(table, table.newAppend().appendFile(FILE_DAY_1).appendFile(FILE_DAY_2), branch);
- Snapshot firstSnapshot = table.currentSnapshot();
+ Snapshot firstSnapshot = latestSnapshot(table, branch);
OverwriteFiles overwrite =
table
@@ -720,22 +741,22 @@ public class TestOverwriteWithValidation extends TableTestBase {
.validateNoConflictingData()
.validateNoConflictingDeletes();
- table.newRowDelta().addDeletes(FILE_DAY_2_POS_DELETES).commit();
+ commit(table, table.newRowDelta().addDeletes(FILE_DAY_2_POS_DELETES), branch);
AssertHelpers.assertThrows(
"Should reject commit",
ValidationException.class,
"Found new conflicting delete",
- overwrite::commit);
+ () -> commit(table, overwrite, branch));
}
@Test
public void testConcurrentConflictingDataFileDeleteOverwriteByFilter() {
- Assert.assertNull("Should be empty table", table.currentSnapshot());
+ Assert.assertNull("Should be empty table", latestSnapshot(table, branch));
- table.newAppend().appendFile(FILE_DAY_1).appendFile(FILE_DAY_2).commit();
+ commit(table, table.newAppend().appendFile(FILE_DAY_1).appendFile(FILE_DAY_2), branch);
- Snapshot firstSnapshot = table.currentSnapshot();
+ Snapshot firstSnapshot = latestSnapshot(table, branch);
OverwriteFiles overwrite =
table
@@ -746,22 +767,22 @@ public class TestOverwriteWithValidation extends TableTestBase {
.validateNoConflictingData()
.validateNoConflictingDeletes();
- table.newOverwrite().deleteFile(FILE_DAY_2).commit();
+ commit(table, table.newOverwrite().deleteFile(FILE_DAY_2), branch);
AssertHelpers.assertThrows(
"Should reject commit",
ValidationException.class,
"Found conflicting deleted files",
- overwrite::commit);
+ () -> commit(table, overwrite, branch));
}
@Test
public void testConcurrentNonConflictingDataFileDeleteOverwriteByFilter() {
- Assert.assertNull("Should be empty table", table.currentSnapshot());
+ Assert.assertNull("Should be empty table", latestSnapshot(table, branch));
- table.newAppend().appendFile(FILE_DAY_1).appendFile(FILE_DAY_2).commit();
+ commit(table, table.newAppend().appendFile(FILE_DAY_1).appendFile(FILE_DAY_2), branch);
- Snapshot firstSnapshot = table.currentSnapshot();
+ Snapshot firstSnapshot = latestSnapshot(table, branch);
OverwriteFiles overwrite =
table
@@ -772,22 +793,22 @@ public class TestOverwriteWithValidation extends TableTestBase {
.validateNoConflictingData()
.validateNoConflictingDeletes();
- table.newOverwrite().deleteFile(FILE_DAY_1).commit();
+ commit(table, table.newOverwrite().deleteFile(FILE_DAY_1), branch);
- overwrite.commit();
+ commit(table, overwrite, branch);
- validateTableFiles(table, FILE_DAY_2_MODIFIED);
+ validateBranchFiles(table, branch, FILE_DAY_2_MODIFIED);
}
@Test
public void testConcurrentNonConflictingPositionDeletes() {
Assume.assumeTrue(formatVersion == 2);
- Assert.assertNull("Should be empty table", table.currentSnapshot());
+ Assert.assertNull("Should be empty table", latestSnapshot(table, branch));
- table.newAppend().appendFile(FILE_DAY_1).appendFile(FILE_DAY_2).commit();
+ commit(table, table.newAppend().appendFile(FILE_DAY_1).appendFile(FILE_DAY_2), branch);
- Snapshot firstSnapshot = table.currentSnapshot();
+ Snapshot firstSnapshot = latestSnapshot(table, branch);
OverwriteFiles overwrite =
table
@@ -799,23 +820,23 @@ public class TestOverwriteWithValidation extends TableTestBase {
.validateNoConflictingData()
.validateNoConflictingDeletes();
- table.newRowDelta().addDeletes(FILE_DAY_1_POS_DELETES).commit();
+ commit(table, table.newRowDelta().addDeletes(FILE_DAY_1_POS_DELETES), branch);
- overwrite.commit();
+ commit(table, overwrite, branch);
- validateTableFiles(table, FILE_DAY_1, FILE_DAY_2_MODIFIED);
- validateTableDeleteFiles(table, FILE_DAY_1_POS_DELETES);
+ validateBranchFiles(table, branch, FILE_DAY_1, FILE_DAY_2_MODIFIED);
+ validateBranchDeleteFiles(table, branch, FILE_DAY_1_POS_DELETES);
}
@Test
public void testConcurrentNonConflictingPositionDeletesOverwriteByFilter() {
Assume.assumeTrue(formatVersion == 2);
- Assert.assertNull("Should be empty table", table.currentSnapshot());
+ Assert.assertNull("Should be empty table", latestSnapshot(table, branch));
- table.newAppend().appendFile(FILE_DAY_1).appendFile(FILE_DAY_2).commit();
+ commit(table, table.newAppend().appendFile(FILE_DAY_1).appendFile(FILE_DAY_2), branch);
- Snapshot firstSnapshot = table.currentSnapshot();
+ Snapshot firstSnapshot = latestSnapshot(table, branch);
OverwriteFiles overwrite =
table
@@ -827,23 +848,23 @@ public class TestOverwriteWithValidation extends TableTestBase {
.validateNoConflictingData()
.validateNoConflictingDeletes();
- table.newRowDelta().addDeletes(FILE_DAY_1_POS_DELETES).commit();
+ commit(table, table.newRowDelta().addDeletes(FILE_DAY_1_POS_DELETES), branch);
- overwrite.commit();
+ commit(table, overwrite, branch);
- validateTableFiles(table, FILE_DAY_1, FILE_DAY_2_MODIFIED);
- validateTableDeleteFiles(table, FILE_DAY_1_POS_DELETES);
+ validateBranchFiles(table, branch, FILE_DAY_1, FILE_DAY_2_MODIFIED);
+ validateBranchDeleteFiles(table, branch, FILE_DAY_1_POS_DELETES);
}
@Test
public void testConcurrentConflictingEqualityDeletes() {
Assume.assumeTrue(formatVersion == 2);
- Assert.assertNull("Should be empty table", table.currentSnapshot());
+ Assert.assertNull("Should be empty table", latestSnapshot(table, branch));
- table.newAppend().appendFile(FILE_DAY_1).appendFile(FILE_DAY_2).commit();
+ commit(table, table.newAppend().appendFile(FILE_DAY_1).appendFile(FILE_DAY_2), branch);
- Snapshot firstSnapshot = table.currentSnapshot();
+ Snapshot firstSnapshot = latestSnapshot(table, branch);
OverwriteFiles overwrite =
table
@@ -855,21 +876,27 @@ public class TestOverwriteWithValidation extends TableTestBase {
.validateNoConflictingData()
.validateNoConflictingDeletes();
- table.newRowDelta().addDeletes(FILE_DAY_2_EQ_DELETES).commit();
+ commit(table, table.newRowDelta().addDeletes(FILE_DAY_2_EQ_DELETES), branch);
AssertHelpers.assertThrows(
- "Should reject commit", ValidationException.class, "found new delete", overwrite::commit);
+ "Should reject commit",
+ ValidationException.class,
+ "found new delete",
+ () -> commit(table, overwrite, branch));
}
@Test
public void testConcurrentNonConflictingEqualityDeletes() {
Assume.assumeTrue(formatVersion == 2);
- Assert.assertNull("Should be empty table", table.currentSnapshot());
+ Assert.assertNull("Should be empty table", latestSnapshot(table, branch));
- table.newAppend().appendFile(FILE_DAY_2).appendFile(FILE_DAY_2_ANOTHER_RANGE).commit();
+ commit(
+ table,
+ table.newAppend().appendFile(FILE_DAY_2).appendFile(FILE_DAY_2_ANOTHER_RANGE),
+ branch);
- Snapshot firstSnapshot = table.currentSnapshot();
+ Snapshot firstSnapshot = latestSnapshot(table, branch);
OverwriteFiles overwrite =
table
@@ -881,23 +908,23 @@ public class TestOverwriteWithValidation extends TableTestBase {
.validateNoConflictingData()
.validateNoConflictingDeletes();
- table.newRowDelta().addDeletes(FILE_DAY_2_ANOTHER_RANGE_EQ_DELETES).commit();
+ commit(table, table.newRowDelta().addDeletes(FILE_DAY_2_ANOTHER_RANGE_EQ_DELETES), branch);
- overwrite.commit();
+ commit(table, overwrite, branch);
- validateTableFiles(table, FILE_DAY_2_ANOTHER_RANGE, FILE_DAY_2_MODIFIED);
- validateTableDeleteFiles(table, FILE_DAY_2_ANOTHER_RANGE_EQ_DELETES);
+ validateBranchFiles(table, branch, FILE_DAY_2_ANOTHER_RANGE, FILE_DAY_2_MODIFIED);
+ validateBranchDeleteFiles(table, branch, FILE_DAY_2_ANOTHER_RANGE_EQ_DELETES);
}
@Test
public void testOverwriteByFilterInheritsConflictDetectionFilter() {
Assume.assumeTrue(formatVersion == 2);
- Assert.assertNull("Should be empty table", table.currentSnapshot());
+ Assert.assertNull("Should be empty table", latestSnapshot(table, branch));
- table.newAppend().appendFile(FILE_DAY_1).appendFile(FILE_DAY_2).commit();
+ commit(table, table.newAppend().appendFile(FILE_DAY_1).appendFile(FILE_DAY_2), branch);
- Snapshot firstSnapshot = table.currentSnapshot();
+ Snapshot firstSnapshot = latestSnapshot(table, branch);
OverwriteFiles overwrite =
table
@@ -909,19 +936,19 @@ public class TestOverwriteWithValidation extends TableTestBase {
.validateNoConflictingData()
.validateNoConflictingDeletes();
- table.newRowDelta().addDeletes(FILE_DAY_1_POS_DELETES).commit();
+ commit(table, table.newRowDelta().addDeletes(FILE_DAY_1_POS_DELETES), branch);
- overwrite.commit();
+ commit(table, overwrite, branch);
- validateTableFiles(table, FILE_DAY_1, FILE_DAY_2_MODIFIED);
- validateTableDeleteFiles(table, FILE_DAY_1_POS_DELETES);
+ validateBranchFiles(table, branch, FILE_DAY_1, FILE_DAY_2_MODIFIED);
+ validateBranchDeleteFiles(table, branch, FILE_DAY_1_POS_DELETES);
}
@Test
public void testOverwriteCaseSensitivity() {
- table.newAppend().appendFile(FILE_DAY_1).appendFile(FILE_DAY_2).commit();
+ commit(table, table.newAppend().appendFile(FILE_DAY_1).appendFile(FILE_DAY_2), branch);
- table.newAppend().appendFile(FILE_DAY_1).commit();
+ commit(table, table.newAppend().appendFile(FILE_DAY_1), branch);
Expression rowFilter = equal("dAtE", "2018-06-09");
@@ -930,25 +957,29 @@ public class TestOverwriteWithValidation extends TableTestBase {
ValidationException.class,
"Cannot find field 'dAtE'",
() ->
- table
- .newOverwrite()
- .addFile(FILE_DAY_2_MODIFIED)
- .conflictDetectionFilter(rowFilter)
- .validateNoConflictingData()
- .commit());
+ commit(
+ table,
+ table
+ .newOverwrite()
+ .addFile(FILE_DAY_2_MODIFIED)
+ .conflictDetectionFilter(rowFilter)
+ .validateNoConflictingData(),
+ branch));
AssertHelpers.assertThrows(
"Should fail with case sensitive binding",
ValidationException.class,
"Cannot find field 'dAtE'",
() ->
- table
- .newOverwrite()
- .caseSensitive(true)
- .addFile(FILE_DAY_2_MODIFIED)
- .conflictDetectionFilter(rowFilter)
- .validateNoConflictingData()
- .commit());
+ commit(
+ table,
+ table
+ .newOverwrite()
+ .caseSensitive(true)
+ .addFile(FILE_DAY_2_MODIFIED)
+ .conflictDetectionFilter(rowFilter)
+ .validateNoConflictingData(),
+ branch));
// binding should succeed and trigger the validation
AssertHelpers.assertThrows(
@@ -956,36 +987,45 @@ public class TestOverwriteWithValidation extends TableTestBase {
ValidationException.class,
"Found conflicting files",
() ->
- table
- .newOverwrite()
- .caseSensitive(false)
- .addFile(FILE_DAY_2_MODIFIED)
- .conflictDetectionFilter(rowFilter)
- .validateNoConflictingData()
- .commit());
+ commit(
+ table,
+ table
+ .newOverwrite()
+ .caseSensitive(false)
+ .addFile(FILE_DAY_2_MODIFIED)
+ .conflictDetectionFilter(rowFilter)
+ .validateNoConflictingData(),
+ branch));
}
@Test
public void testMetadataOnlyDeleteWithPositionDeletes() {
Assume.assumeTrue(formatVersion == 2);
- Assert.assertNull("Should be empty table", table.currentSnapshot());
+ Assert.assertNull("Should be empty table", latestSnapshot(table, branch));
- table.newAppend().appendFile(FILE_DAY_2).appendFile(FILE_DAY_2_ANOTHER_RANGE).commit();
+ commit(
+ table,
+ table.newAppend().appendFile(FILE_DAY_2).appendFile(FILE_DAY_2_ANOTHER_RANGE),
+ branch);
- table
- .newRowDelta()
- .addDeletes(FILE_DAY_2_POS_DELETES)
- .addDeletes(FILE_DAY_2_ANOTHER_RANGE_EQ_DELETES)
- .commit();
+ commit(
+ table,
+ table
+ .newRowDelta()
+ .addDeletes(FILE_DAY_2_POS_DELETES)
+ .addDeletes(FILE_DAY_2_ANOTHER_RANGE_EQ_DELETES),
+ branch);
- table
- .newOverwrite()
- .overwriteByRowFilter(EXPRESSION_DAY_2_ANOTHER_ID_RANGE)
- .addFile(FILE_DAY_2_MODIFIED)
- .commit();
+ commit(
+ table,
+ table
+ .newOverwrite()
+ .overwriteByRowFilter(EXPRESSION_DAY_2_ANOTHER_ID_RANGE)
+ .addFile(FILE_DAY_2_MODIFIED),
+ branch);
- validateTableFiles(table, FILE_DAY_2, FILE_DAY_2_MODIFIED);
- validateTableDeleteFiles(table, FILE_DAY_2_POS_DELETES);
+ validateBranchFiles(table, branch, FILE_DAY_2, FILE_DAY_2_MODIFIED);
+ validateBranchDeleteFiles(table, branch, FILE_DAY_2_POS_DELETES);
}
}
diff --git a/core/src/test/java/org/apache/iceberg/TestReplacePartitions.java b/core/src/test/java/org/apache/iceberg/TestReplacePartitions.java
index 6a23596aee..dc74099028 100644
--- a/core/src/test/java/org/apache/iceberg/TestReplacePartitions.java
+++ b/core/src/test/java/org/apache/iceberg/TestReplacePartitions.java
@@ -70,40 +70,48 @@ public class TestReplacePartitions extends TableTestBase {
.withRecordCount(1)
.build();
- @Parameterized.Parameters(name = "formatVersion = {0}")
+ private final String branch;
+
+ @Parameterized.Parameters(name = "formatVersion = {0}, branch = {1}")
public static Object[] parameters() {
- return new Object[] {1, 2};
+ return new Object[][] {
+ new Object[] {1, "main"},
+ new Object[] {1, "testBranch"},
+ new Object[] {2, "main"},
+ new Object[] {2, "testBranch"}
+ };
}
- public TestReplacePartitions(int formatVersion) {
+ public TestReplacePartitions(int formatVersion, String branch) {
super(formatVersion);
+ this.branch = branch;
}
@Test
public void testReplaceOnePartition() {
- table.newFastAppend().appendFile(FILE_A).appendFile(FILE_B).commit();
+ table.newFastAppend().appendFile(FILE_A).appendFile(FILE_B).toBranch(branch).commit();
TableMetadata base = readMetadata();
- long baseId = base.currentSnapshot().snapshotId();
+ long baseId = latestSnapshot(base, branch).snapshotId();
- table.newReplacePartitions().addFile(FILE_E).commit();
+ table.newReplacePartitions().addFile(FILE_E).toBranch(branch).commit();
- long replaceId = readMetadata().currentSnapshot().snapshotId();
+ long replaceId = latestSnapshot(readMetadata(), branch).snapshotId();
Assert.assertNotEquals("Should create a new snapshot", baseId, replaceId);
Assert.assertEquals(
"Table should have 2 manifests",
2,
- table.currentSnapshot().allManifests(table.io()).size());
+ latestSnapshot(table, branch).allManifests(table.io()).size());
// manifest is not merged because it is less than the minimum
validateManifestEntries(
- table.currentSnapshot().allManifests(table.io()).get(0),
+ latestSnapshot(table, branch).allManifests(table.io()).get(0),
ids(replaceId),
files(FILE_E),
statuses(Status.ADDED));
validateManifestEntries(
- table.currentSnapshot().allManifests(table.io()).get(1),
+ latestSnapshot(table, branch).allManifests(table.io()).get(1),
ids(replaceId, baseId),
files(FILE_A, FILE_B),
statuses(Status.DELETED, Status.EXISTING));
@@ -114,20 +122,22 @@ public class TestReplacePartitions extends TableTestBase {
// ensure the overwrite results in a merge
table.updateProperties().set(TableProperties.MANIFEST_MIN_MERGE_COUNT, "1").commit();
- table.newFastAppend().appendFile(FILE_A).appendFile(FILE_B).commit();
+ table.newFastAppend().appendFile(FILE_A).appendFile(FILE_B).toBranch(branch).commit();
TableMetadata base = readMetadata();
- long baseId = base.currentSnapshot().snapshotId();
+ long baseId = latestSnapshot(base, branch).snapshotId();
- table.newReplacePartitions().addFile(FILE_E).commit();
+ table.newReplacePartitions().addFile(FILE_E).toBranch(branch).commit();
- long replaceId = readMetadata().currentSnapshot().snapshotId();
+ long replaceId = latestSnapshot(table, branch).snapshotId();
Assert.assertNotEquals("Should create a new snapshot", baseId, replaceId);
Assert.assertEquals(
- "Table should have 1 manifest", 1, table.currentSnapshot().allManifests(table.io()).size());
+ "Table should have 1 manifest",
+ 1,
+ latestSnapshot(table, branch).allManifests(table.io()).size());
validateManifestEntries(
- table.currentSnapshot().allManifests(table.io()).get(0),
+ latestSnapshot(table, branch).allManifests(table.io()).get(0),
ids(replaceId, replaceId, baseId),
files(FILE_E, FILE_A, FILE_B),
statuses(Status.ADDED, Status.DELETED, Status.EXISTING));
@@ -145,33 +155,34 @@ public class TestReplacePartitions extends TableTestBase {
Assert.assertEquals(
"Table version should be 0", 0, (long) TestTables.metadataVersion("unpartitioned"));
- unpartitioned.newAppend().appendFile(FILE_A).commit();
-
+ unpartitioned.newAppend().appendFile(FILE_A).toBranch(branch).commit();
// make sure the data was successfully added
Assert.assertEquals(
"Table version should be 1", 1, (long) TestTables.metadataVersion("unpartitioned"));
- validateSnapshot(null, TestTables.readMetadata("unpartitioned").currentSnapshot(), FILE_A);
+ validateSnapshot(
+ null, latestSnapshot(TestTables.readMetadata("unpartitioned"), branch), FILE_A);
- unpartitioned.newReplacePartitions().addFile(FILE_B).commit();
+ ReplacePartitions replacePartitions = unpartitioned.newReplacePartitions().addFile(FILE_B);
+ commit(table, replacePartitions, branch);
Assert.assertEquals(
"Table version should be 2", 2, (long) TestTables.metadataVersion("unpartitioned"));
TableMetadata replaceMetadata = TestTables.readMetadata("unpartitioned");
- long replaceId = replaceMetadata.currentSnapshot().snapshotId();
+ long replaceId = latestSnapshot(replaceMetadata, branch).snapshotId();
Assert.assertEquals(
"Table should have 2 manifests",
2,
- replaceMetadata.currentSnapshot().allManifests(unpartitioned.io()).size());
+ latestSnapshot(replaceMetadata, branch).allManifests(unpartitioned.io()).size());
validateManifestEntries(
- replaceMetadata.currentSnapshot().allManifests(unpartitioned.io()).get(0),
+ latestSnapshot(replaceMetadata, branch).allManifests(unpartitioned.io()).get(0),
ids(replaceId),
files(FILE_B),
statuses(Status.ADDED));
validateManifestEntries(
- replaceMetadata.currentSnapshot().allManifests(unpartitioned.io()).get(1),
+ latestSnapshot(replaceMetadata, branch).allManifests(unpartitioned.io()).get(1),
ids(replaceId),
files(FILE_A),
statuses(Status.DELETED));
@@ -192,27 +203,30 @@ public class TestReplacePartitions extends TableTestBase {
Assert.assertEquals(
"Table version should be 1", 1, (long) TestTables.metadataVersion("unpartitioned"));
- unpartitioned.newAppend().appendFile(FILE_A).commit();
+ AppendFiles appendFiles = unpartitioned.newAppend().appendFile(FILE_A);
+ commit(table, appendFiles, branch);
// make sure the data was successfully added
Assert.assertEquals(
"Table version should be 2", 2, (long) TestTables.metadataVersion("unpartitioned"));
- validateSnapshot(null, TestTables.readMetadata("unpartitioned").currentSnapshot(), FILE_A);
+ validateSnapshot(
+ null, latestSnapshot(TestTables.readMetadata("unpartitioned"), branch), FILE_A);
- unpartitioned.newReplacePartitions().addFile(FILE_B).commit();
+ ReplacePartitions replacePartitions = unpartitioned.newReplacePartitions().addFile(FILE_B);
+ commit(table, replacePartitions, branch);
Assert.assertEquals(
"Table version should be 3", 3, (long) TestTables.metadataVersion("unpartitioned"));
TableMetadata replaceMetadata = TestTables.readMetadata("unpartitioned");
- long replaceId = replaceMetadata.currentSnapshot().snapshotId();
+ long replaceId = latestSnapshot(replaceMetadata, branch).snapshotId();
Assert.assertEquals(
"Table should have 1 manifest",
1,
- replaceMetadata.currentSnapshot().allManifests(unpartitioned.io()).size());
+ latestSnapshot(replaceMetadata, branch).allManifests(unpartitioned.io()).size());
validateManifestEntries(
- replaceMetadata.currentSnapshot().allManifests(unpartitioned.io()).get(0),
+ latestSnapshot(replaceMetadata, branch).allManifests(unpartitioned.io()).get(0),
ids(replaceId, replaceId),
files(FILE_B, FILE_A),
statuses(Status.ADDED, Status.DELETED));
@@ -220,13 +234,18 @@ public class TestReplacePartitions extends TableTestBase {
@Test
public void testValidationFailure() {
- table.newFastAppend().appendFile(FILE_A).appendFile(FILE_B).commit();
+ table.newFastAppend().appendFile(FILE_A).appendFile(FILE_B).toBranch(branch).commit();
TableMetadata base = readMetadata();
- long baseId = base.currentSnapshot().snapshotId();
+ long baseId = latestSnapshot(base, branch).snapshotId();
ReplacePartitions replace =
- table.newReplacePartitions().addFile(FILE_F).addFile(FILE_G).validateAppendOnly();
+ table
+ .newReplacePartitions()
+ .addFile(FILE_F)
+ .addFile(FILE_G)
+ .toBranch(branch)
+ .validateAppendOnly();
AssertHelpers.assertThrows(
"Should reject commit with file not matching delete expression",
@@ -235,34 +254,36 @@ public class TestReplacePartitions extends TableTestBase {
replace::commit);
Assert.assertEquals(
- "Should not create a new snapshot", baseId, readMetadata().currentSnapshot().snapshotId());
+ "Should not create a new snapshot",
+ baseId,
+ latestSnapshot(readMetadata(), branch).snapshotId());
}
@Test
public void testValidationSuccess() {
- table.newFastAppend().appendFile(FILE_A).appendFile(FILE_B).commit();
+ table.newFastAppend().appendFile(FILE_A).appendFile(FILE_B).toBranch(branch).commit();
TableMetadata base = readMetadata();
- long baseId = base.currentSnapshot().snapshotId();
+ long baseId = latestSnapshot(base, branch).snapshotId();
- table.newReplacePartitions().addFile(FILE_G).validateAppendOnly().commit();
+ table.newReplacePartitions().addFile(FILE_G).validateAppendOnly().toBranch(branch).commit();
- long replaceId = readMetadata().currentSnapshot().snapshotId();
+ long replaceId = latestSnapshot(readMetadata(), branch).snapshotId();
Assert.assertNotEquals("Should create a new snapshot", baseId, replaceId);
Assert.assertEquals(
"Table should have 2 manifests",
2,
- table.currentSnapshot().allManifests(table.io()).size());
+ latestSnapshot(table, branch).allManifests(table.io()).size());
// manifest is not merged because it is less than the minimum
validateManifestEntries(
- table.currentSnapshot().allManifests(table.io()).get(0),
+ latestSnapshot(table, branch).allManifests(table.io()).get(0),
ids(replaceId),
files(FILE_G),
statuses(Status.ADDED));
validateManifestEntries(
- table.currentSnapshot().allManifests(table.io()).get(1),
+ latestSnapshot(table, branch).allManifests(table.io()).get(1),
ids(baseId, baseId),
files(FILE_A, FILE_B),
statuses(Status.ADDED, Status.ADDED));
@@ -270,7 +291,7 @@ public class TestReplacePartitions extends TableTestBase {
@Test
public void testValidationNotInvoked() {
- table.newFastAppend().appendFile(FILE_A).commit();
+ table.newFastAppend().appendFile(FILE_A).toBranch(branch).commit();
TableMetadata base = readMetadata();
@@ -278,25 +299,29 @@ public class TestReplacePartitions extends TableTestBase {
table
.newReplacePartitions()
.addFile(FILE_E)
- .validateFromSnapshot(base.currentSnapshot().snapshotId())
+ .validateFromSnapshot(latestSnapshot(base, branch).snapshotId())
+ .toBranch(branch)
.commit();
table
.newReplacePartitions()
.addFile(FILE_A) // Replaces FILE_E which becomes Deleted
.addFile(FILE_B)
- .validateFromSnapshot(base.currentSnapshot().snapshotId())
+ .validateFromSnapshot(latestSnapshot(base, branch).snapshotId())
+ .toBranch(branch)
.commit();
- long replaceId = readMetadata().currentSnapshot().snapshotId();
+ long replaceId = latestSnapshot(readMetadata(), branch).snapshotId();
Assert.assertEquals(
- "Table should have 2 manifest", 2, table.currentSnapshot().allManifests(table.io()).size());
+ "Table should have 2 manifest",
+ 2,
+ latestSnapshot(table, branch).allManifests(table.io()).size());
validateManifestEntries(
- table.currentSnapshot().allManifests(table.io()).get(0),
+ latestSnapshot(table, branch).allManifests(table.io()).get(0),
ids(replaceId, replaceId),
files(FILE_A, FILE_B),
statuses(Status.ADDED, Status.ADDED));
validateManifestEntries(
- table.currentSnapshot().allManifests(table.io()).get(1),
+ latestSnapshot(table, branch).allManifests(table.io()).get(1),
ids(replaceId),
files(FILE_E),
statuses(Status.DELETED));
@@ -304,7 +329,7 @@ public class TestReplacePartitions extends TableTestBase {
@Test
public void testValidateWithDefaultSnapshotId() {
- table.newReplacePartitions().addFile(FILE_A).commit();
+ table.newReplacePartitions().addFile(FILE_A).toBranch(branch).commit();
// Concurrent Replace Partitions should fail with ValidationException
ReplacePartitions replace = table.newReplacePartitions();
@@ -319,18 +344,19 @@ public class TestReplacePartitions extends TableTestBase {
.addFile(FILE_B)
.validateNoConflictingData()
.validateNoConflictingDeletes()
+ .toBranch(branch)
.commit());
}
@Test
public void testConcurrentReplaceConflict() {
- table.newFastAppend().appendFile(FILE_A).appendFile(FILE_B).commit();
+ table.newFastAppend().appendFile(FILE_A).appendFile(FILE_B).toBranch(branch).commit();
TableMetadata base = readMetadata();
- long baseId = base.currentSnapshot().snapshotId();
+ long baseId = latestSnapshot(base, branch).snapshotId();
// Concurrent Replace Partitions should fail with ValidationException
- table.newReplacePartitions().addFile(FILE_A).commit();
+ table.newReplacePartitions().addFile(FILE_A).toBranch(branch).commit();
AssertHelpers.assertThrows(
"Should reject commit with file matching partitions replaced",
@@ -345,40 +371,42 @@ public class TestReplacePartitions extends TableTestBase {
.addFile(FILE_B)
.validateNoConflictingData()
.validateNoConflictingDeletes()
+ .toBranch(branch)
.commit());
}
@Test
public void testConcurrentReplaceNoConflict() {
- table.newFastAppend().appendFile(FILE_A).commit();
+ table.newFastAppend().appendFile(FILE_A).toBranch(branch).commit();
TableMetadata base = readMetadata();
- long id1 = base.currentSnapshot().snapshotId();
+ long id1 = latestSnapshot(base, branch).snapshotId();
// Concurrent Replace Partitions should not fail if concerning different partitions
- table.newReplacePartitions().addFile(FILE_A).commit();
- long id2 = readMetadata().currentSnapshot().snapshotId();
+ table.newReplacePartitions().addFile(FILE_A).toBranch(branch).commit();
+ long id2 = latestSnapshot(readMetadata(), branch).snapshotId();
table
.newReplacePartitions()
.validateFromSnapshot(id1)
.validateNoConflictingData()
.validateNoConflictingDeletes()
+ .toBranch(branch)
.addFile(FILE_B)
.commit();
- long id3 = readMetadata().currentSnapshot().snapshotId();
+ long id3 = latestSnapshot(readMetadata(), branch).snapshotId();
Assert.assertEquals(
"Table should have 2 manifests",
2,
- table.currentSnapshot().allManifests(table.io()).size());
+ latestSnapshot(table, branch).allManifests(table.io()).size());
validateManifestEntries(
- table.currentSnapshot().allManifests(table.io()).get(0),
+ latestSnapshot(table, branch).allManifests(table.io()).get(0),
ids(id3),
files(FILE_B),
statuses(Status.ADDED));
validateManifestEntries(
- table.currentSnapshot().allManifests(table.io()).get(1),
+ latestSnapshot(table, branch).allManifests(table.io()).get(1),
ids(id2),
files(FILE_A),
statuses(Status.ADDED));
@@ -389,13 +417,13 @@ public class TestReplacePartitions extends TableTestBase {
Table unpartitioned =
TestTables.create(
tableDir, "unpartitioned", SCHEMA, PartitionSpec.unpartitioned(), formatVersion);
- unpartitioned.newAppend().appendFile(FILE_UNPARTITIONED_A).commit();
+ unpartitioned.newAppend().appendFile(FILE_UNPARTITIONED_A).toBranch(branch).commit();
TableMetadata replaceMetadata = TestTables.readMetadata("unpartitioned");
- long replaceBaseId = replaceMetadata.currentSnapshot().snapshotId();
+ long replaceBaseId = latestSnapshot(replaceMetadata, branch).snapshotId();
// Concurrent ReplacePartitions should fail with ValidationException
- unpartitioned.newReplacePartitions().addFile(FILE_UNPARTITIONED_A).commit();
+ unpartitioned.newReplacePartitions().addFile(FILE_UNPARTITIONED_A).toBranch(branch).commit();
AssertHelpers.assertThrows(
"Should reject commit with file matching partitions replaced",
@@ -409,18 +437,19 @@ public class TestReplacePartitions extends TableTestBase {
.validateNoConflictingData()
.validateNoConflictingDeletes()
.addFile(FILE_UNPARTITIONED_A)
+ .toBranch(branch)
.commit());
}
@Test
public void testAppendReplaceConflict() {
- table.newFastAppend().appendFile(FILE_A).commit();
+ table.newFastAppend().appendFile(FILE_A).toBranch(branch).commit();
TableMetadata base = readMetadata();
- long baseId = base.currentSnapshot().snapshotId();
+ long baseId = latestSnapshot(base, branch).snapshotId();
// Concurrent Append and ReplacePartition should fail with ValidationException
- table.newFastAppend().appendFile(FILE_B).commit();
+ table.newFastAppend().appendFile(FILE_B).toBranch(branch).commit();
AssertHelpers.assertThrows(
"Should reject commit with file matching partitions replaced",
@@ -435,46 +464,48 @@ public class TestReplacePartitions extends TableTestBase {
.validateNoConflictingDeletes()
.addFile(FILE_A)
.addFile(FILE_B)
+ .toBranch(branch)
.commit());
}
@Test
public void testAppendReplaceNoConflict() {
- table.newFastAppend().appendFile(FILE_A).commit();
+ table.newFastAppend().appendFile(FILE_A).toBranch(branch).commit();
TableMetadata base = readMetadata();
- long id1 = base.currentSnapshot().snapshotId();
+ long id1 = latestSnapshot(base, branch).snapshotId();
// Concurrent Append and ReplacePartition should not conflict if concerning different partitions
- table.newFastAppend().appendFile(FILE_B).commit();
+ table.newFastAppend().appendFile(FILE_B).toBranch(branch).commit();
- long id2 = readMetadata().currentSnapshot().snapshotId();
+ long id2 = latestSnapshot(readMetadata(), branch).snapshotId();
table
.newReplacePartitions()
.validateFromSnapshot(id1)
.validateNoConflictingData()
.validateNoConflictingDeletes()
+ .toBranch(branch)
.addFile(FILE_A)
.commit();
- long id3 = readMetadata().currentSnapshot().snapshotId();
+ long id3 = latestSnapshot(readMetadata(), branch).snapshotId();
Assert.assertEquals(
"Table should have 3 manifests",
3,
- table.currentSnapshot().allManifests(table.io()).size());
+ latestSnapshot(table, branch).allManifests(table.io()).size());
validateManifestEntries(
- table.currentSnapshot().allManifests(table.io()).get(0),
+ latestSnapshot(table, branch).allManifests(table.io()).get(0),
ids(id3),
files(FILE_A),
statuses(Status.ADDED));
validateManifestEntries(
- table.currentSnapshot().allManifests(table.io()).get(1),
+ latestSnapshot(table, branch).allManifests(table.io()).get(1),
ids(id2),
files(FILE_B),
statuses(Status.ADDED));
validateManifestEntries(
- table.currentSnapshot().allManifests(table.io()).get(2),
+ latestSnapshot(table, branch).allManifests(table.io()).get(2),
ids(id3),
files(FILE_A),
statuses(Status.DELETED));
@@ -485,13 +516,13 @@ public class TestReplacePartitions extends TableTestBase {
Table unpartitioned =
TestTables.create(
tableDir, "unpartitioned", SCHEMA, PartitionSpec.unpartitioned(), formatVersion);
- unpartitioned.newAppend().appendFile(FILE_UNPARTITIONED_A).commit();
+ unpartitioned.newAppend().appendFile(FILE_UNPARTITIONED_A).toBranch(branch).commit();
TableMetadata replaceMetadata = TestTables.readMetadata("unpartitioned");
- long replaceBaseId = replaceMetadata.currentSnapshot().snapshotId();
+ long replaceBaseId = latestSnapshot(replaceMetadata, branch).snapshotId();
// Concurrent Append and ReplacePartitions should fail with ValidationException
- unpartitioned.newAppend().appendFile(FILE_UNPARTITIONED_A).commit();
+ unpartitioned.newAppend().appendFile(FILE_UNPARTITIONED_A).toBranch(branch).commit();
AssertHelpers.assertThrows(
"Should reject commit with file matching partitions replaced",
@@ -505,19 +536,25 @@ public class TestReplacePartitions extends TableTestBase {
.validateNoConflictingData()
.validateNoConflictingDeletes()
.addFile(FILE_UNPARTITIONED_A)
+ .toBranch(branch)
.commit());
}
@Test
public void testDeleteReplaceConflict() {
Assume.assumeTrue(formatVersion == 2);
- table.newFastAppend().appendFile(FILE_A).commit();
+ table.newFastAppend().appendFile(FILE_A).toBranch(branch).commit();
TableMetadata base = readMetadata();
- long baseId = base.currentSnapshot().snapshotId();
+ long baseId = latestSnapshot(base, branch).snapshotId();
// Concurrent Delete and ReplacePartition should fail with ValidationException
- table.newRowDelta().addDeletes(FILE_A_DELETES).validateFromSnapshot(baseId).commit();
+ table
+ .newRowDelta()
+ .addDeletes(FILE_A_DELETES)
+ .validateFromSnapshot(baseId)
+ .toBranch(branch)
+ .commit();
AssertHelpers.assertThrows(
"Should reject commit with file matching partitions replaced",
@@ -530,6 +567,7 @@ public class TestReplacePartitions extends TableTestBase {
.validateFromSnapshot(baseId)
.validateNoConflictingData()
.validateNoConflictingDeletes()
+ .toBranch(branch)
.addFile(FILE_A)
.commit());
}
@@ -541,13 +579,13 @@ public class TestReplacePartitions extends TableTestBase {
Table unpartitioned =
TestTables.create(
tableDir, "unpartitioned", SCHEMA, PartitionSpec.unpartitioned(), formatVersion);
- unpartitioned.newAppend().appendFile(FILE_A).commit();
+ unpartitioned.newAppend().appendFile(FILE_A).toBranch(branch).commit();
TableMetadata replaceMetadata = TestTables.readMetadata("unpartitioned");
- long replaceBaseId = replaceMetadata.currentSnapshot().snapshotId();
+ long replaceBaseId = latestSnapshot(replaceMetadata, branch).snapshotId();
// Concurrent Delete and ReplacePartitions should fail with ValidationException
- unpartitioned.newRowDelta().addDeletes(FILE_UNPARTITIONED_A_DELETES).commit();
+ unpartitioned.newRowDelta().addDeletes(FILE_UNPARTITIONED_A_DELETES).toBranch(branch).commit();
AssertHelpers.assertThrows(
"Should reject commit with file matching partitions replaced",
@@ -561,14 +599,15 @@ public class TestReplacePartitions extends TableTestBase {
.validateNoConflictingData()
.validateNoConflictingDeletes()
.addFile(FILE_UNPARTITIONED_A)
+ .toBranch(branch)
.commit());
}
@Test
public void testDeleteReplaceNoConflict() {
Assume.assumeTrue(formatVersion == 2);
- table.newFastAppend().appendFile(FILE_A).commit();
- long id1 = readMetadata().currentSnapshot().snapshotId();
+ table.newFastAppend().appendFile(FILE_A).toBranch(branch).commit();
+ long id1 = latestSnapshot(readMetadata(), branch).snapshotId();
// Concurrent Delta and ReplacePartition should not conflict if concerning different partitions
table
@@ -578,8 +617,9 @@ public class TestReplacePartitions extends TableTestBase {
.validateNoConflictingDataFiles()
.validateNoConflictingDeleteFiles()
.validateFromSnapshot(id1)
+ .toBranch(branch)
.commit();
- long id2 = readMetadata().currentSnapshot().snapshotId();
+ long id2 = latestSnapshot(readMetadata(), branch).snapshotId();
table
.newReplacePartitions()
@@ -587,23 +627,26 @@ public class TestReplacePartitions extends TableTestBase {
.validateNoConflictingDeletes()
.validateFromSnapshot(id1)
.addFile(FILE_B)
+ .toBranch(branch)
.commit();
- long id3 = readMetadata().currentSnapshot().snapshotId();
+ long id3 = latestSnapshot(readMetadata(), branch).snapshotId();
Assert.assertEquals(
- "Table should have 3 manifest", 3, table.currentSnapshot().allManifests(table.io()).size());
+ "Table should have 3 manifest",
+ 3,
+ latestSnapshot(table, branch).allManifests(table.io()).size());
validateManifestEntries(
- table.currentSnapshot().allManifests(table.io()).get(0),
+ latestSnapshot(table, branch).allManifests(table.io()).get(0),
ids(id3),
files(FILE_B),
statuses(Status.ADDED));
validateManifestEntries(
- table.currentSnapshot().allManifests(table.io()).get(1),
+ latestSnapshot(table, branch).allManifests(table.io()).get(1),
ids(id1),
files(FILE_A),
statuses(Status.ADDED));
validateDeleteManifest(
- table.currentSnapshot().allManifests(table.io()).get(2),
+ latestSnapshot(table, branch).allManifests(table.io()).get(2),
dataSeqs(2L),
fileSeqs(2L),
ids(id2),
@@ -614,13 +657,13 @@ public class TestReplacePartitions extends TableTestBase {
@Test
public void testOverwriteReplaceConflict() {
Assume.assumeTrue(formatVersion == 2);
- table.newFastAppend().appendFile(FILE_A).commit();
+ table.newFastAppend().appendFile(FILE_A).toBranch(branch).commit();
TableMetadata base = readMetadata();
- long baseId = base.currentSnapshot().snapshotId();
+ long baseId = latestSnapshot(base, branch).snapshotId();
// Concurrent Overwrite and ReplacePartition should fail with ValidationException
- table.newOverwrite().deleteFile(FILE_A).commit();
+ table.newOverwrite().deleteFile(FILE_A).toBranch(branch).commit();
AssertHelpers.assertThrows(
"Should reject commit with file matching partitions replaced",
@@ -634,20 +677,21 @@ public class TestReplacePartitions extends TableTestBase {
.validateNoConflictingData()
.validateNoConflictingDeletes()
.addFile(FILE_A)
+ .toBranch(branch)
.commit());
}
@Test
public void testOverwriteReplaceNoConflict() {
Assume.assumeTrue(formatVersion == 2);
- table.newFastAppend().appendFile(FILE_A).appendFile(FILE_B).commit();
+ table.newFastAppend().appendFile(FILE_A).appendFile(FILE_B).toBranch(branch).commit();
TableMetadata base = readMetadata();
- long baseId = base.currentSnapshot().snapshotId();
+ long baseId = latestSnapshot(base, branch).snapshotId();
// Concurrent Overwrite and ReplacePartition should not fail with if concerning different
// partitions
- table.newOverwrite().deleteFile(FILE_A).commit();
+ table.newOverwrite().deleteFile(FILE_A).toBranch(branch).commit();
table
.newReplacePartitions()
@@ -655,19 +699,22 @@ public class TestReplacePartitions extends TableTestBase {
.validateNoConflictingDeletes()
.validateFromSnapshot(baseId)
.addFile(FILE_B)
+ .toBranch(branch)
.commit();
- long finalId = readMetadata().currentSnapshot().snapshotId();
+ long finalId = latestSnapshot(readMetadata(), branch).snapshotId();
Assert.assertEquals(
- "Table should have 2 manifest", 2, table.currentSnapshot().allManifests(table.io()).size());
+ "Table should have 2 manifest",
+ 2,
+ latestSnapshot(table, branch).allManifests(table.io()).size());
validateManifestEntries(
- table.currentSnapshot().allManifests(table.io()).get(0),
+ latestSnapshot(table, branch).allManifests(table.io()).get(0),
ids(finalId),
files(FILE_B),
statuses(Status.ADDED));
validateManifestEntries(
- table.currentSnapshot().allManifests(table.io()).get(1),
+ latestSnapshot(table, branch).allManifests(table.io()).get(1),
ids(finalId),
files(FILE_B),
statuses(Status.DELETED));
@@ -681,13 +728,13 @@ public class TestReplacePartitions extends TableTestBase {
TestTables.create(
tableDir, "unpartitioned", SCHEMA, PartitionSpec.unpartitioned(), formatVersion);
- unpartitioned.newAppend().appendFile(FILE_UNPARTITIONED_A).commit();
+ unpartitioned.newAppend().appendFile(FILE_UNPARTITIONED_A).toBranch(branch).commit();
TableMetadata replaceMetadata = TestTables.readMetadata("unpartitioned");
- long replaceBaseId = replaceMetadata.currentSnapshot().snapshotId();
+ long replaceBaseId = latestSnapshot(replaceMetadata, branch).snapshotId();
// Concurrent Overwrite and ReplacePartitions should fail with ValidationException
- unpartitioned.newOverwrite().deleteFile(FILE_UNPARTITIONED_A).commit();
+ unpartitioned.newOverwrite().deleteFile(FILE_UNPARTITIONED_A).toBranch(branch).commit();
AssertHelpers.assertThrows(
"Should reject commit with file matching partitions replaced",
@@ -701,39 +748,43 @@ public class TestReplacePartitions extends TableTestBase {
.validateNoConflictingData()
.validateNoConflictingDeletes()
.addFile(FILE_UNPARTITIONED_A)
+ .toBranch(branch)
.commit());
}
@Test
public void testValidateOnlyDeletes() {
- table.newAppend().appendFile(FILE_A).commit();
- long baseId = readMetadata().currentSnapshot().snapshotId();
+ table.newAppend().appendFile(FILE_A).toBranch(branch).commit();
+ long baseId = latestSnapshot(readMetadata(), branch).snapshotId();
// Snapshot Isolation mode: appends do not conflict with replace
- table.newAppend().appendFile(FILE_B).commit();
+ table.newAppend().appendFile(FILE_B).toBranch(branch).commit();
table
.newReplacePartitions()
.validateFromSnapshot(baseId)
.validateNoConflictingDeletes()
.addFile(FILE_B)
+ .toBranch(branch)
.commit();
- long finalId = readMetadata().currentSnapshot().snapshotId();
+ long finalId = latestSnapshot(readMetadata(), branch).snapshotId();
Assert.assertEquals(
- "Table should have 3 manifest", 3, table.currentSnapshot().allManifests(table.io()).size());
+ "Table should have 3 manifest",
+ 3,
+ latestSnapshot(table, branch).allManifests(table.io()).size());
validateManifestEntries(
- table.currentSnapshot().allManifests(table.io()).get(0),
+ latestSnapshot(table, branch).allManifests(table.io()).get(0),
ids(finalId),
files(FILE_B),
statuses(Status.ADDED));
validateManifestEntries(
- table.currentSnapshot().allManifests(table.io()).get(1),
+ latestSnapshot(table, branch).allManifests(table.io()).get(1),
ids(finalId),
files(FILE_B),
statuses(Status.DELETED));
validateManifestEntries(
- table.currentSnapshot().allManifests(table.io()).get(2),
+ latestSnapshot(table, branch).allManifests(table.io()).get(2),
ids(baseId),
files(FILE_A),
statuses(Status.ADDED));
@@ -743,13 +794,4 @@ public class TestReplacePartitions extends TableTestBase {
public void testEmptyPartitionPathWithUnpartitionedTable() {
DataFiles.builder(PartitionSpec.unpartitioned()).withPartitionPath("");
}
-
- @Test
- public void testReplacePartitionsOnBranchUnsupported() {
- AssertHelpers.assertThrows(
- "Should reject committing rewrite manifests to branch",
- UnsupportedOperationException.class,
- "Cannot commit to branch someBranch: org.apache.iceberg.BaseReplacePartitions does not support branch commits",
- () -> table.newReplacePartitions().addFile(FILE_UNPARTITIONED_A).toBranch("someBranch"));
- }
}
diff --git a/core/src/test/java/org/apache/iceberg/TestRewriteFiles.java b/core/src/test/java/org/apache/iceberg/TestRewriteFiles.java
index 4af7fc887a..5f126678fe 100644
--- a/core/src/test/java/org/apache/iceberg/TestRewriteFiles.java
+++ b/core/src/test/java/org/apache/iceberg/TestRewriteFiles.java
@@ -38,13 +38,22 @@ import org.mockito.internal.util.collections.Sets;
@RunWith(Parameterized.class)
public class TestRewriteFiles extends TableTestBase {
- @Parameterized.Parameters(name = "formatVersion = {0}")
+
+ private final String branch;
+
+ @Parameterized.Parameters(name = "formatVersion = {0}, branch = {1}")
public static Object[] parameters() {
- return new Object[] {1, 2};
+ return new Object[][] {
+ new Object[] {1, "main"},
+ new Object[] {1, "testBranch"},
+ new Object[] {2, "main"},
+ new Object[] {2, "testBranch"}
+ };
}
- public TestRewriteFiles(int formatVersion) {
+ public TestRewriteFiles(int formatVersion, String branch) {
super(formatVersion);
+ this.branch = branch;
}
@Test
@@ -52,27 +61,33 @@ public class TestRewriteFiles extends TableTestBase {
Assert.assertEquals("Table should start empty", 0, listManifestFiles().size());
TableMetadata base = readMetadata();
- Assert.assertNull("Should not have a current snapshot", base.currentSnapshot());
+ Assert.assertNull("Should not have a current snapshot", base.ref(branch));
AssertHelpers.assertThrows(
"Expected an exception",
ValidationException.class,
"Missing required files to delete: /path/to/data-a.parquet",
- () -> table.newRewrite().rewriteFiles(Sets.newSet(FILE_A), Sets.newSet(FILE_B)).commit());
+ () ->
+ commit(
+ table,
+ table.newRewrite().rewriteFiles(Sets.newSet(FILE_A), Sets.newSet(FILE_B)),
+ branch));
AssertHelpers.assertThrows(
"Expected an exception",
ValidationException.class,
"Missing required files to delete: /path/to/data-a-deletes.parquet",
() ->
- table
- .newRewrite()
- .rewriteFiles(
- ImmutableSet.of(),
- ImmutableSet.of(FILE_A_DELETES),
- ImmutableSet.of(FILE_A),
- ImmutableSet.of(FILE_B_DELETES))
- .commit());
+ commit(
+ table,
+ table
+ .newRewrite()
+ .rewriteFiles(
+ ImmutableSet.of(),
+ ImmutableSet.of(FILE_A_DELETES),
+ ImmutableSet.of(FILE_A),
+ ImmutableSet.of(FILE_B_DELETES)),
+ branch));
}
@Test
@@ -83,35 +98,40 @@ public class TestRewriteFiles extends TableTestBase {
"Expected an exception",
ValidationException.class,
"Missing required files to delete: /path/to/data-a.parquet",
- () -> table.newRewrite().rewriteFiles(Sets.newSet(FILE_A), Collections.emptySet()).apply());
+ () ->
+ apply(
+ table.newRewrite().rewriteFiles(Sets.newSet(FILE_A), Collections.emptySet()),
+ branch));
AssertHelpers.assertThrows(
"Expected an exception",
IllegalArgumentException.class,
"Delete files to add must be empty because there's no delete file to be rewritten",
() ->
- table
- .newRewrite()
- .rewriteFiles(
- ImmutableSet.of(FILE_A),
- ImmutableSet.of(),
- ImmutableSet.of(),
- ImmutableSet.of(FILE_A_DELETES))
- .apply());
+ apply(
+ table
+ .newRewrite()
+ .rewriteFiles(
+ ImmutableSet.of(FILE_A),
+ ImmutableSet.of(),
+ ImmutableSet.of(),
+ ImmutableSet.of(FILE_A_DELETES)),
+ branch));
AssertHelpers.assertThrows(
"Expected an exception",
IllegalArgumentException.class,
"Delete files to add must be empty because there's no delete file to be rewritten",
() ->
- table
- .newRewrite()
- .rewriteFiles(
- ImmutableSet.of(FILE_A),
- ImmutableSet.of(),
- ImmutableSet.of(FILE_B),
- ImmutableSet.of(FILE_B_DELETES))
- .apply());
+ apply(
+ table
+ .newRewrite()
+ .rewriteFiles(
+ ImmutableSet.of(FILE_A),
+ ImmutableSet.of(),
+ ImmutableSet.of(FILE_B),
+ ImmutableSet.of(FILE_B_DELETES)),
+ branch));
}
@Test
@@ -122,53 +142,59 @@ public class TestRewriteFiles extends TableTestBase {
"Expected an exception",
IllegalArgumentException.class,
"Files to delete cannot be null or empty",
- () -> table.newRewrite().rewriteFiles(Collections.emptySet(), Sets.newSet(FILE_A)).apply());
+ () ->
+ apply(
+ table.newRewrite().rewriteFiles(Collections.emptySet(), Sets.newSet(FILE_A)),
+ branch));
AssertHelpers.assertThrows(
"Expected an exception",
IllegalArgumentException.class,
"Files to delete cannot be null or empty",
() ->
- table
- .newRewrite()
- .rewriteFiles(
- ImmutableSet.of(),
- ImmutableSet.of(),
- ImmutableSet.of(),
- ImmutableSet.of(FILE_A_DELETES))
- .apply());
+ apply(
+ table
+ .newRewrite()
+ .rewriteFiles(
+ ImmutableSet.of(),
+ ImmutableSet.of(),
+ ImmutableSet.of(),
+ ImmutableSet.of(FILE_A_DELETES)),
+ branch));
AssertHelpers.assertThrows(
"Expected an exception",
IllegalArgumentException.class,
"Files to delete cannot be null or empty",
() ->
- table
- .newRewrite()
- .rewriteFiles(
- ImmutableSet.of(),
- ImmutableSet.of(),
- ImmutableSet.of(FILE_A),
- ImmutableSet.of(FILE_A_DELETES))
- .apply());
+ apply(
+ table
+ .newRewrite()
+ .rewriteFiles(
+ ImmutableSet.of(),
+ ImmutableSet.of(),
+ ImmutableSet.of(FILE_A),
+ ImmutableSet.of(FILE_A_DELETES)),
+ branch));
}
@Test
public void testDeleteWithDuplicateEntriesInManifest() {
Assert.assertEquals("Table should start empty", 0, listManifestFiles().size());
- table.newAppend().appendFile(FILE_A).appendFile(FILE_A).appendFile(FILE_B).commit();
+ commit(
+ table, table.newAppend().appendFile(FILE_A).appendFile(FILE_A).appendFile(FILE_B), branch);
TableMetadata base = readMetadata();
- long baseSnapshotId = base.currentSnapshot().snapshotId();
+ long baseSnapshotId = latestSnapshot(base, branch).snapshotId();
Assert.assertEquals(
"Should create 1 manifest for initial write",
1,
- base.currentSnapshot().allManifests(table.io()).size());
- ManifestFile initialManifest = base.currentSnapshot().allManifests(table.io()).get(0);
+ latestSnapshot(base, branch).allManifests(table.io()).size());
+ ManifestFile initialManifest = latestSnapshot(base, branch).allManifests(table.io()).get(0);
Snapshot pending =
- table.newRewrite().rewriteFiles(Sets.newSet(FILE_A), Sets.newSet(FILE_C)).apply();
+ apply(table.newRewrite().rewriteFiles(Sets.newSet(FILE_A), Sets.newSet(FILE_C)), branch);
Assert.assertEquals("Should contain 2 manifest", 2, pending.allManifests(table.io()).size());
Assert.assertFalse(
@@ -194,18 +220,18 @@ public class TestRewriteFiles extends TableTestBase {
public void testAddAndDelete() {
Assert.assertEquals("Table should start empty", 0, listManifestFiles().size());
- table.newAppend().appendFile(FILE_A).appendFile(FILE_B).commit();
+ commit(table, table.newAppend().appendFile(FILE_A).appendFile(FILE_B), branch);
TableMetadata base = readMetadata();
- long baseSnapshotId = base.currentSnapshot().snapshotId();
+ long baseSnapshotId = latestSnapshot(base, branch).snapshotId();
Assert.assertEquals(
"Should create 1 manifest for initial write",
1,
- base.currentSnapshot().allManifests(table.io()).size());
- ManifestFile initialManifest = base.currentSnapshot().allManifests(table.io()).get(0);
+ latestSnapshot(table, branch).allManifests(table.io()).size());
+ ManifestFile initialManifest = latestSnapshot(table, branch).allManifests(table.io()).get(0);
Snapshot pending =
- table.newRewrite().rewriteFiles(Sets.newSet(FILE_A), Sets.newSet(FILE_C)).apply();
+ apply(table.newRewrite().rewriteFiles(Sets.newSet(FILE_A), Sets.newSet(FILE_C)), branch);
Assert.assertEquals("Should contain 2 manifest", 2, pending.allManifests(table.io()).size());
Assert.assertFalse(
@@ -233,17 +259,19 @@ public class TestRewriteFiles extends TableTestBase {
"Rewriting delete files is only supported in iceberg format v2. ", formatVersion > 1);
Assert.assertEquals("Table should start empty", 0, listManifestFiles().size());
- table
- .newRowDelta()
- .addRows(FILE_A)
- .addRows(FILE_B)
- .addRows(FILE_C)
- .addDeletes(FILE_A_DELETES)
- .addDeletes(FILE_B_DELETES)
- .commit();
+ commit(
+ table,
+ table
+ .newRowDelta()
+ .addRows(FILE_A)
+ .addRows(FILE_B)
+ .addRows(FILE_C)
+ .addDeletes(FILE_A_DELETES)
+ .addDeletes(FILE_B_DELETES),
+ branch);
TableMetadata base = readMetadata();
- Snapshot baseSnap = base.currentSnapshot();
+ Snapshot baseSnap = latestSnapshot(base, branch);
long baseSnapshotId = baseSnap.snapshotId();
Assert.assertEquals(
"Should create 2 manifests for initial write", 2, baseSnap.allManifests(table.io()).size());
@@ -264,15 +292,16 @@ public class TestRewriteFiles extends TableTestBase {
// Rewrite the files.
Snapshot pending =
- table
- .newRewrite()
- .validateFromSnapshot(table.currentSnapshot().snapshotId())
- .rewriteFiles(
- ImmutableSet.of(FILE_A),
- ImmutableSet.of(FILE_A_DELETES),
- ImmutableSet.of(FILE_D),
- ImmutableSet.of())
- .apply();
+ apply(
+ table
+ .newRewrite()
+ .validateFromSnapshot(latestSnapshot(table, branch).snapshotId())
+ .rewriteFiles(
+ ImmutableSet.of(FILE_A),
+ ImmutableSet.of(FILE_A_DELETES),
+ ImmutableSet.of(FILE_D),
+ ImmutableSet.of()),
+ branch);
Assert.assertEquals("Should contain 3 manifest", 3, pending.allManifests(table.io()).size());
Assert.assertFalse(
@@ -307,17 +336,19 @@ public class TestRewriteFiles extends TableTestBase {
"Sequence number is only supported in iceberg format v2. ", formatVersion > 1);
Assert.assertEquals("Table should start empty", 0, listManifestFiles().size());
- table
- .newRowDelta()
- .addRows(FILE_A)
- .addRows(FILE_B)
- .addRows(FILE_C)
- .addDeletes(FILE_A_DELETES)
- .addDeletes(FILE_B_DELETES)
- .commit();
+ commit(
+ table,
+ table
+ .newRowDelta()
+ .addRows(FILE_A)
+ .addRows(FILE_B)
+ .addRows(FILE_C)
+ .addDeletes(FILE_A_DELETES)
+ .addDeletes(FILE_B_DELETES),
+ branch);
TableMetadata base = readMetadata();
- Snapshot baseSnap = base.currentSnapshot();
+ Snapshot baseSnap = latestSnapshot(base, branch);
long baseSnapshotId = baseSnap.snapshotId();
Assert.assertEquals(
"Should create 2 manifests for initial write", 2, baseSnap.allManifests(table.io()).size());
@@ -337,13 +368,14 @@ public class TestRewriteFiles extends TableTestBase {
statuses(ADDED, ADDED));
// Rewrite the files.
- long oldSequenceNumber = table.currentSnapshot().sequenceNumber();
+ long oldSequenceNumber = latestSnapshot(table, branch).sequenceNumber();
Snapshot pending =
- table
- .newRewrite()
- .validateFromSnapshot(table.currentSnapshot().snapshotId())
- .rewriteFiles(ImmutableSet.of(FILE_A), ImmutableSet.of(FILE_D), oldSequenceNumber)
- .apply();
+ apply(
+ table
+ .newRewrite()
+ .validateFromSnapshot(latestSnapshot(table, branch).snapshotId())
+ .rewriteFiles(ImmutableSet.of(FILE_A), ImmutableSet.of(FILE_D), oldSequenceNumber),
+ branch);
Assert.assertEquals("Should contain 3 manifest", 3, pending.allManifests(table.io()).size());
Assert.assertFalse(
@@ -384,13 +416,13 @@ public class TestRewriteFiles extends TableTestBase {
@Test
public void testFailure() {
- table.newAppend().appendFile(FILE_A).commit();
+ commit(table, table.newAppend().appendFile(FILE_A), branch);
table.ops().failCommits(5);
RewriteFiles rewrite =
table.newRewrite().rewriteFiles(Sets.newSet(FILE_A), Sets.newSet(FILE_B));
- Snapshot pending = rewrite.apply();
+ Snapshot pending = apply(rewrite, branch);
Assert.assertEquals("Should produce 2 manifests", 2, pending.allManifests(table.io()).size());
ManifestFile manifest1 = pending.allManifests(table.io()).get(0);
@@ -403,7 +435,7 @@ public class TestRewriteFiles extends TableTestBase {
"Should retry 4 times and throw last failure",
CommitFailedException.class,
"Injected failure",
- rewrite::commit);
+ () -> commit(table, rewrite, branch));
Assert.assertFalse("Should clean up new manifest", new File(manifest1.path()).exists());
Assert.assertFalse("Should clean up new manifest", new File(manifest2.path()).exists());
@@ -417,28 +449,30 @@ public class TestRewriteFiles extends TableTestBase {
Assume.assumeTrue(
"Rewriting delete files is only supported in iceberg format v2. ", formatVersion > 1);
- table
- .newRowDelta()
- .addRows(FILE_A)
- .addRows(FILE_B)
- .addRows(FILE_C)
- .addDeletes(FILE_A_DELETES)
- .addDeletes(FILE_B_DELETES)
- .commit();
-
- long baseSnapshotId = readMetadata().currentSnapshot().snapshotId();
+ commit(
+ table,
+ table
+ .newRowDelta()
+ .addRows(FILE_A)
+ .addRows(FILE_B)
+ .addRows(FILE_C)
+ .addDeletes(FILE_A_DELETES)
+ .addDeletes(FILE_B_DELETES),
+ branch);
+
+ long baseSnapshotId = latestSnapshot(readMetadata(), branch).snapshotId();
table.ops().failCommits(5);
RewriteFiles rewrite =
table
.newRewrite()
- .validateFromSnapshot(table.currentSnapshot().snapshotId())
+ .validateFromSnapshot(latestSnapshot(table, branch).snapshotId())
.rewriteFiles(
ImmutableSet.of(FILE_A),
ImmutableSet.of(FILE_A_DELETES, FILE_B_DELETES),
ImmutableSet.of(FILE_D),
ImmutableSet.of());
- Snapshot pending = rewrite.apply();
+ Snapshot pending = apply(rewrite, branch);
Assert.assertEquals("Should produce 3 manifests", 3, pending.allManifests(table.io()).size());
ManifestFile manifest1 = pending.allManifests(table.io()).get(0);
@@ -481,13 +515,13 @@ public class TestRewriteFiles extends TableTestBase {
@Test
public void testRecovery() {
- table.newAppend().appendFile(FILE_A).commit();
+ commit(table, table.newAppend().appendFile(FILE_A), branch);
table.ops().failCommits(3);
RewriteFiles rewrite =
table.newRewrite().rewriteFiles(Sets.newSet(FILE_A), Sets.newSet(FILE_B));
- Snapshot pending = rewrite.apply();
+ Snapshot pending = apply(rewrite, branch);
Assert.assertEquals("Should produce 2 manifests", 2, pending.allManifests(table.io()).size());
ManifestFile manifest1 = pending.allManifests(table.io()).get(0);
@@ -496,7 +530,7 @@ public class TestRewriteFiles extends TableTestBase {
validateManifestEntries(manifest1, ids(pending.snapshotId()), files(FILE_B), statuses(ADDED));
validateManifestEntries(manifest2, ids(pending.snapshotId()), files(FILE_A), statuses(DELETED));
- rewrite.commit();
+ commit(table, rewrite, branch);
Assert.assertTrue("Should reuse the manifest for appends", new File(manifest1.path()).exists());
Assert.assertTrue(
@@ -505,7 +539,7 @@ public class TestRewriteFiles extends TableTestBase {
TableMetadata metadata = readMetadata();
Assert.assertTrue(
"Should commit the manifest for append",
- metadata.currentSnapshot().allManifests(table.io()).contains(manifest2));
+ latestSnapshot(metadata, branch).allManifests(table.io()).contains(manifest2));
// 2 manifests added by rewrite and 1 original manifest should be found.
Assert.assertEquals("Only 3 manifests should exist", 3, listManifestFiles().size());
@@ -516,28 +550,30 @@ public class TestRewriteFiles extends TableTestBase {
Assume.assumeTrue(
"Rewriting delete files is only supported in iceberg format v2. ", formatVersion > 1);
- table
- .newRowDelta()
- .addRows(FILE_A)
- .addRows(FILE_B)
- .addRows(FILE_C)
- .addDeletes(FILE_A_DELETES)
- .addDeletes(FILE_B_DELETES)
- .commit();
-
- long baseSnapshotId = readMetadata().currentSnapshot().snapshotId();
+ commit(
+ table,
+ table
+ .newRowDelta()
+ .addRows(FILE_A)
+ .addRows(FILE_B)
+ .addRows(FILE_C)
+ .addDeletes(FILE_A_DELETES)
+ .addDeletes(FILE_B_DELETES),
+ branch);
+
+ long baseSnapshotId = latestSnapshot(readMetadata(), branch).snapshotId();
table.ops().failCommits(3);
RewriteFiles rewrite =
table
.newRewrite()
- .validateFromSnapshot(table.currentSnapshot().snapshotId())
+ .validateFromSnapshot(latestSnapshot(table, branch).snapshotId())
.rewriteFiles(
ImmutableSet.of(FILE_A),
ImmutableSet.of(FILE_A_DELETES, FILE_B_DELETES),
ImmutableSet.of(FILE_D),
ImmutableSet.of());
- Snapshot pending = rewrite.apply();
+ Snapshot pending = apply(rewrite, branch);
Assert.assertEquals("Should produce 3 manifests", 3, pending.allManifests(table.io()).size());
ManifestFile manifest1 = pending.allManifests(table.io()).get(0);
@@ -560,7 +596,7 @@ public class TestRewriteFiles extends TableTestBase {
files(FILE_A_DELETES, FILE_B_DELETES),
statuses(DELETED, DELETED));
- rewrite.commit();
+ commit(table, rewrite, branch);
Assert.assertTrue("Should reuse new manifest", new File(manifest1.path()).exists());
Assert.assertTrue("Should reuse new manifest", new File(manifest2.path()).exists());
@@ -570,7 +606,7 @@ public class TestRewriteFiles extends TableTestBase {
List<ManifestFile> committedManifests = Lists.newArrayList(manifest1, manifest2, manifest3);
Assert.assertEquals(
"Should committed the manifests",
- metadata.currentSnapshot().allManifests(table.io()),
+ latestSnapshot(metadata, branch).allManifests(table.io()),
committedManifests);
// As commit success all the manifests added with rewrite should be available.
@@ -582,10 +618,10 @@ public class TestRewriteFiles extends TableTestBase {
Assume.assumeTrue(
"Rewriting delete files is only supported in iceberg format v2. ", formatVersion > 1);
- table.newRowDelta().addRows(FILE_A2).addDeletes(FILE_A2_DELETES).commit();
+ commit(table, table.newRowDelta().addRows(FILE_A2).addDeletes(FILE_A2_DELETES), branch);
TableMetadata metadata = readMetadata();
- long baseSnapshotId = metadata.currentSnapshot().snapshotId();
+ long baseSnapshotId = latestSnapshot(metadata, branch).snapshotId();
// Apply and commit the rewrite transaction.
RewriteFiles rewrite =
@@ -594,7 +630,7 @@ public class TestRewriteFiles extends TableTestBase {
.rewriteFiles(
ImmutableSet.of(), ImmutableSet.of(FILE_A2_DELETES),
ImmutableSet.of(), ImmutableSet.of(FILE_B_DELETES));
- Snapshot pending = rewrite.apply();
+ Snapshot pending = apply(rewrite, branch);
Assert.assertEquals("Should produce 3 manifests", 3, pending.allManifests(table.io()).size());
ManifestFile manifest1 = pending.allManifests(table.io()).get(0);
@@ -619,7 +655,7 @@ public class TestRewriteFiles extends TableTestBase {
files(FILE_A2_DELETES),
statuses(DELETED));
- rewrite.commit();
+ commit(table, rewrite, branch);
Assert.assertTrue("Should reuse new manifest", new File(manifest1.path()).exists());
Assert.assertTrue("Should reuse new manifest", new File(manifest2.path()).exists());
@@ -629,7 +665,7 @@ public class TestRewriteFiles extends TableTestBase {
List<ManifestFile> committedManifests = Lists.newArrayList(manifest1, manifest2, manifest3);
Assert.assertEquals(
"Should committed the manifests",
- metadata.currentSnapshot().allManifests(table.io()),
+ latestSnapshot(metadata, branch).allManifests(table.io()),
committedManifests);
// As commit success all the manifests added with rewrite should be available.
@@ -641,17 +677,17 @@ public class TestRewriteFiles extends TableTestBase {
Assume.assumeTrue(
"Rewriting delete files is only supported in iceberg format v2. ", formatVersion > 1);
- table.newRowDelta().addRows(FILE_A).addDeletes(FILE_A_DELETES).commit();
+ commit(table, table.newRowDelta().addRows(FILE_A).addDeletes(FILE_A_DELETES), branch);
// Apply and commit the rewrite transaction.
RewriteFiles rewrite =
table
.newRewrite()
- .validateFromSnapshot(table.currentSnapshot().snapshotId())
+ .validateFromSnapshot(latestSnapshot(table, branch).snapshotId())
.rewriteFiles(
ImmutableSet.of(FILE_A), ImmutableSet.of(FILE_A_DELETES),
ImmutableSet.of(), ImmutableSet.of());
- Snapshot pending = rewrite.apply();
+ Snapshot pending = apply(rewrite, branch);
Assert.assertEquals("Should produce 2 manifests", 2, pending.allManifests(table.io()).size());
ManifestFile manifest1 = pending.allManifests(table.io()).get(0);
@@ -667,7 +703,7 @@ public class TestRewriteFiles extends TableTestBase {
files(FILE_A_DELETES),
statuses(DELETED));
- rewrite.commit();
+ commit(table, rewrite, branch);
Assert.assertTrue("Should reuse the new manifest", new File(manifest1.path()).exists());
Assert.assertTrue("Should reuse the new manifest", new File(manifest2.path()).exists());
@@ -676,7 +712,7 @@ public class TestRewriteFiles extends TableTestBase {
List<ManifestFile> committedManifests = Lists.newArrayList(manifest1, manifest2);
Assert.assertTrue(
"Should committed the manifests",
- metadata.currentSnapshot().allManifests(table.io()).containsAll(committedManifests));
+ latestSnapshot(metadata, branch).allManifests(table.io()).containsAll(committedManifests));
// As commit success all the manifests added with rewrite should be available.
Assert.assertEquals("4 manifests should exist", 4, listManifestFiles().size());
@@ -686,19 +722,23 @@ public class TestRewriteFiles extends TableTestBase {
public void testDeleteNonExistentFile() {
Assert.assertEquals("Table should start empty", 0, listManifestFiles().size());
- table.newAppend().appendFile(FILE_A).appendFile(FILE_B).commit();
+ commit(table, table.newAppend().appendFile(FILE_A).appendFile(FILE_B), branch);
TableMetadata base = readMetadata();
Assert.assertEquals(
"Should create 1 manifest for initial write",
1,
- base.currentSnapshot().allManifests(table.io()).size());
+ latestSnapshot(base, branch).allManifests(table.io()).size());
AssertHelpers.assertThrows(
"Expected an exception",
ValidationException.class,
"Missing required files to delete: /path/to/data-c.parquet",
- () -> table.newRewrite().rewriteFiles(Sets.newSet(FILE_C), Sets.newSet(FILE_D)).commit());
+ () ->
+ commit(
+ table,
+ table.newRewrite().rewriteFiles(Sets.newSet(FILE_C), Sets.newSet(FILE_D)),
+ branch));
Assert.assertEquals("Only 1 manifests should exist", 1, listManifestFiles().size());
}
@@ -707,16 +747,17 @@ public class TestRewriteFiles extends TableTestBase {
public void testAlreadyDeletedFile() {
Assert.assertEquals("Table should start empty", 0, listManifestFiles().size());
- table.newAppend().appendFile(FILE_A).commit();
+ commit(table, table.newAppend().appendFile(FILE_A), branch);
TableMetadata base = readMetadata();
Assert.assertEquals(
"Should create 1 manifest for initial write",
1,
- base.currentSnapshot().allManifests(table.io()).size());
+ latestSnapshot(base, branch).allManifests(table.io()).size());
RewriteFiles rewrite = table.newRewrite();
- Snapshot pending = rewrite.rewriteFiles(Sets.newSet(FILE_A), Sets.newSet(FILE_B)).apply();
+ Snapshot pending =
+ apply(rewrite.rewriteFiles(Sets.newSet(FILE_A), Sets.newSet(FILE_B)), branch);
Assert.assertEquals("Should contain 2 manifest", 2, pending.allManifests(table.io()).size());
@@ -727,17 +768,21 @@ public class TestRewriteFiles extends TableTestBase {
validateManifestEntries(
pending.allManifests(table.io()).get(1),
- ids(pendingId, base.currentSnapshot().snapshotId()),
+ ids(pendingId, latestSnapshot(table, branch).snapshotId()),
files(FILE_A),
statuses(DELETED));
- rewrite.commit();
+ commit(table, rewrite, branch);
AssertHelpers.assertThrows(
"Expected an exception",
ValidationException.class,
"Missing required files to delete: /path/to/data-a.parquet",
- () -> table.newRewrite().rewriteFiles(Sets.newSet(FILE_A), Sets.newSet(FILE_D)).commit());
+ () ->
+ commit(
+ table,
+ table.newRewrite().rewriteFiles(Sets.newSet(FILE_A), Sets.newSet(FILE_D)),
+ branch));
Assert.assertEquals("Only 3 manifests should exist", 3, listManifestFiles().size());
}
@@ -746,30 +791,32 @@ public class TestRewriteFiles extends TableTestBase {
public void testNewDeleteFile() {
Assume.assumeTrue("Delete files are only supported in v2", formatVersion > 1);
- table.newAppend().appendFile(FILE_A).commit();
+ commit(table, table.newAppend().appendFile(FILE_A), branch);
- long snapshotBeforeDeletes = table.currentSnapshot().snapshotId();
+ long snapshotBeforeDeletes = latestSnapshot(table, branch).snapshotId();
- table.newRowDelta().addDeletes(FILE_A_DELETES).commit();
+ commit(table, table.newRowDelta().addDeletes(FILE_A_DELETES), branch);
- long snapshotAfterDeletes = table.currentSnapshot().snapshotId();
+ long snapshotAfterDeletes = latestSnapshot(table, branch).snapshotId();
AssertHelpers.assertThrows(
"Should fail because deletes were added after the starting snapshot",
ValidationException.class,
"Cannot commit, found new delete for replaced data file",
() ->
- table
- .newRewrite()
- .validateFromSnapshot(snapshotBeforeDeletes)
- .rewriteFiles(Sets.newSet(FILE_A), Sets.newSet(FILE_A2))
- .apply());
+ apply(
+ table
+ .newRewrite()
+ .validateFromSnapshot(snapshotBeforeDeletes)
+ .rewriteFiles(Sets.newSet(FILE_A), Sets.newSet(FILE_A2)),
+ branch));
// the rewrite should be valid when validating from the snapshot after the deletes
- table
- .newRewrite()
- .validateFromSnapshot(snapshotAfterDeletes)
- .rewriteFiles(Sets.newSet(FILE_A), Sets.newSet(FILE_A2))
- .apply();
+ apply(
+ table
+ .newRewrite()
+ .validateFromSnapshot(snapshotAfterDeletes)
+ .rewriteFiles(Sets.newSet(FILE_A), Sets.newSet(FILE_A2)),
+ branch);
}
}
diff --git a/core/src/test/java/org/apache/iceberg/TestRowDelta.java b/core/src/test/java/org/apache/iceberg/TestRowDelta.java
index 4e09316bd1..e0db24df22 100644
--- a/core/src/test/java/org/apache/iceberg/TestRowDelta.java
+++ b/core/src/test/java/org/apache/iceberg/TestRowDelta.java
@@ -39,18 +39,32 @@ import org.apache.iceberg.relocated.com.google.common.collect.ImmutableSet;
import org.apache.iceberg.relocated.com.google.common.collect.Sets;
import org.junit.Assert;
import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+@RunWith(Parameterized.class)
public class TestRowDelta extends V2TableTestBase {
+
+ private final String branch;
+
+ @Parameterized.Parameters(name = "branch = {0}")
+ public static Object[] parameters() {
+ return new Object[][] {
+ new Object[] {"main"}, new Object[] {"testBranch"},
+ };
+ }
+
+ public TestRowDelta(String branch) {
+ this.branch = branch;
+ }
+
@Test
public void testAddDeleteFile() {
- table
- .newRowDelta()
- .addRows(FILE_A)
- .addDeletes(FILE_A_DELETES)
- .addDeletes(FILE_B_DELETES)
- .commit();
+ SnapshotUpdate rowDelta =
+ table.newRowDelta().addRows(FILE_A).addDeletes(FILE_A_DELETES).addDeletes(FILE_B_DELETES);
- Snapshot snap = table.currentSnapshot();
+ commit(table, rowDelta, branch);
+ Snapshot snap = latestSnapshot(table, branch);
Assert.assertEquals("Commit should produce sequence number 1", 1, snap.sequenceNumber());
Assert.assertEquals(
"Last sequence number should be 1", 1, table.ops().current().lastSequenceNumber());
@@ -81,155 +95,171 @@ public class TestRowDelta extends V2TableTestBase {
@Test
public void testValidateDataFilesExistDefaults() {
- table.newAppend().appendFile(FILE_A).appendFile(FILE_B).commit();
+ SnapshotUpdate rowDelta1 = table.newAppend().appendFile(FILE_A).appendFile(FILE_B);
+
+ commit(table, rowDelta1, branch);
// test changes to the table back to the snapshot where FILE_A and FILE_B existed
- long validateFromSnapshotId = table.currentSnapshot().snapshotId();
+ long validateFromSnapshotId = latestSnapshot(table, branch).snapshotId();
// overwrite FILE_A
- table.newOverwrite().deleteFile(FILE_A).addFile(FILE_A2).commit();
+ SnapshotUpdate rowDelta2 = table.newOverwrite().deleteFile(FILE_A).addFile(FILE_A2);
+
+ commit(table, rowDelta2, branch);
// delete FILE_B
- table.newDelete().deleteFile(FILE_B).commit();
+ SnapshotUpdate rowDelta3 = table.newDelete().deleteFile(FILE_B);
- long deleteSnapshotId = table.currentSnapshot().snapshotId();
+ commit(table, rowDelta3, branch);
+
+ long deleteSnapshotId = latestSnapshot(table, branch).snapshotId();
AssertHelpers.assertThrows(
"Should fail to add FILE_A_DELETES because FILE_A is missing",
ValidationException.class,
"Cannot commit, missing data files",
() ->
- table
- .newRowDelta()
- .addDeletes(FILE_A_DELETES)
- .validateFromSnapshot(validateFromSnapshotId)
- .validateDataFilesExist(ImmutableList.of(FILE_A.path()))
- .commit());
+ commit(
+ table,
+ table
+ .newRowDelta()
+ .addDeletes(FILE_A_DELETES)
+ .validateFromSnapshot(validateFromSnapshotId)
+ .validateDataFilesExist(ImmutableList.of(FILE_A.path())),
+ branch));
Assert.assertEquals(
"Table state should not be modified by failed RowDelta operation",
deleteSnapshotId,
- table.currentSnapshot().snapshotId());
+ latestSnapshot(table, branch).snapshotId());
Assert.assertEquals(
"Table should not have any delete manifests",
0,
- table.currentSnapshot().deleteManifests(table.io()).size());
+ latestSnapshot(table, branch).deleteManifests(table.io()).size());
- table
- .newRowDelta()
- .addDeletes(FILE_B_DELETES)
- .validateDataFilesExist(ImmutableList.of(FILE_B.path()))
- .validateFromSnapshot(validateFromSnapshotId)
- .commit();
+ commit(
+ table,
+ table
+ .newRowDelta()
+ .addDeletes(FILE_B_DELETES)
+ .validateDataFilesExist(ImmutableList.of(FILE_B.path()))
+ .validateFromSnapshot(validateFromSnapshotId),
+ branch);
Assert.assertEquals(
"Table should have one new delete manifest",
1,
- table.currentSnapshot().deleteManifests(table.io()).size());
- ManifestFile deletes = table.currentSnapshot().deleteManifests(table.io()).get(0);
+ latestSnapshot(table, branch).deleteManifests(table.io()).size());
+ ManifestFile deletes = latestSnapshot(table, branch).deleteManifests(table.io()).get(0);
validateDeleteManifest(
deletes,
dataSeqs(4L),
fileSeqs(4L),
- ids(table.currentSnapshot().snapshotId()),
+ ids(latestSnapshot(table, branch).snapshotId()),
files(FILE_B_DELETES),
statuses(Status.ADDED));
}
@Test
public void testValidateDataFilesExistOverwrite() {
- table.newAppend().appendFile(FILE_A).appendFile(FILE_B).commit();
+ commit(table, table.newAppend().appendFile(FILE_A).appendFile(FILE_B), branch);
// test changes to the table back to the snapshot where FILE_A and FILE_B existed
- long validateFromSnapshotId = table.currentSnapshot().snapshotId();
+ long validateFromSnapshotId = latestSnapshot(table, branch).snapshotId();
// overwrite FILE_A
- table.newOverwrite().deleteFile(FILE_A).addFile(FILE_A2).commit();
+ commit(table, table.newOverwrite().deleteFile(FILE_A).addFile(FILE_A2), branch);
- long deleteSnapshotId = table.currentSnapshot().snapshotId();
+ long deleteSnapshotId = latestSnapshot(table, branch).snapshotId();
AssertHelpers.assertThrows(
"Should fail to add FILE_A_DELETES because FILE_A is missing",
ValidationException.class,
"Cannot commit, missing data files",
() ->
- table
- .newRowDelta()
- .addDeletes(FILE_A_DELETES)
- .validateFromSnapshot(validateFromSnapshotId)
- .validateDataFilesExist(ImmutableList.of(FILE_A.path()))
- .commit());
+ commit(
+ table,
+ table
+ .newRowDelta()
+ .addDeletes(FILE_A_DELETES)
+ .validateFromSnapshot(validateFromSnapshotId)
+ .validateDataFilesExist(ImmutableList.of(FILE_A.path())),
+ branch));
Assert.assertEquals(
"Table state should not be modified by failed RowDelta operation",
deleteSnapshotId,
- table.currentSnapshot().snapshotId());
+ latestSnapshot(table, branch).snapshotId());
Assert.assertEquals(
"Table should not have any delete manifests",
0,
- table.currentSnapshot().deleteManifests(table.io()).size());
+ latestSnapshot(table, branch).deleteManifests(table.io()).size());
}
@Test
public void testValidateDataFilesExistReplacePartitions() {
- table.newAppend().appendFile(FILE_A).appendFile(FILE_B).commit();
+ commit(table, table.newAppend().appendFile(FILE_A).appendFile(FILE_B), branch);
// test changes to the table back to the snapshot where FILE_A and FILE_B existed
- long validateFromSnapshotId = table.currentSnapshot().snapshotId();
+ long validateFromSnapshotId = latestSnapshot(table, branch).snapshotId();
// overwrite FILE_A's partition
- table.newReplacePartitions().addFile(FILE_A2).commit();
+ commit(table, table.newReplacePartitions().addFile(FILE_A2), branch);
- long deleteSnapshotId = table.currentSnapshot().snapshotId();
+ long deleteSnapshotId = latestSnapshot(table, branch).snapshotId();
AssertHelpers.assertThrows(
"Should fail to add FILE_A_DELETES because FILE_A is missing",
ValidationException.class,
"Cannot commit, missing data files",
() ->
- table
- .newRowDelta()
- .addDeletes(FILE_A_DELETES)
- .validateFromSnapshot(validateFromSnapshotId)
- .validateDataFilesExist(ImmutableList.of(FILE_A.path()))
- .commit());
+ commit(
+ table,
+ table
+ .newRowDelta()
+ .addDeletes(FILE_A_DELETES)
+ .validateFromSnapshot(validateFromSnapshotId)
+ .validateDataFilesExist(ImmutableList.of(FILE_A.path())),
+ branch));
Assert.assertEquals(
"Table state should not be modified by failed RowDelta operation",
deleteSnapshotId,
- table.currentSnapshot().snapshotId());
+ latestSnapshot(table, branch).snapshotId());
Assert.assertEquals(
"Table should not have any delete manifests",
0,
- table.currentSnapshot().deleteManifests(table.io()).size());
+ latestSnapshot(table, branch).deleteManifests(table.io()).size());
}
@Test
public void testValidateDataFilesExistFromSnapshot() {
- table.newAppend().appendFile(FILE_A).appendFile(FILE_B).commit();
+ commit(table, table.newAppend().appendFile(FILE_A).appendFile(FILE_B), branch);
- long appendSnapshotId = table.currentSnapshot().snapshotId();
+ long appendSnapshotId = latestSnapshot(table, branch).snapshotId();
// overwrite FILE_A's partition
- table.newReplacePartitions().addFile(FILE_A2).commit();
+ commit(table, table.newReplacePartitions().addFile(FILE_A2), branch);
// test changes to the table back to the snapshot where FILE_A was overwritten
- long validateFromSnapshotId = table.currentSnapshot().snapshotId();
- long replaceSnapshotId = table.currentSnapshot().snapshotId();
+ long validateFromSnapshotId = latestSnapshot(table, branch).snapshotId();
+ long replaceSnapshotId = latestSnapshot(table, branch).snapshotId();
// even though FILE_A was deleted, it happened before the "from" snapshot, so the validation
// allows it
- table
- .newRowDelta()
- .addDeletes(FILE_A_DELETES)
- .validateFromSnapshot(validateFromSnapshotId)
- .validateDataFilesExist(ImmutableList.of(FILE_A.path()))
- .commit();
+ commit(
+ table,
+ table
+ .newRowDelta()
+ .addDeletes(FILE_A_DELETES)
+ .validateFromSnapshot(validateFromSnapshotId)
+ .validateDataFilesExist(ImmutableList.of(FILE_A.path())),
+ branch);
- Snapshot snap = table.currentSnapshot();
+ Snapshot snap = latestSnapshot(table, branch);
Assert.assertEquals("Commit should produce sequence number 2", 3, snap.sequenceNumber());
Assert.assertEquals(
"Last sequence number should be 3", 3, table.ops().current().lastSequenceNumber());
@@ -266,135 +296,146 @@ public class TestRowDelta extends V2TableTestBase {
@Test
public void testValidateDataFilesExistRewrite() {
- table.newAppend().appendFile(FILE_A).appendFile(FILE_B).commit();
+ commit(table, table.newAppend().appendFile(FILE_A).appendFile(FILE_B), branch);
// test changes to the table back to the snapshot where FILE_A and FILE_B existed
- long validateFromSnapshotId = table.currentSnapshot().snapshotId();
+ long validateFromSnapshotId = latestSnapshot(table, branch).snapshotId();
// rewrite FILE_A
- table.newRewrite().rewriteFiles(Sets.newHashSet(FILE_A), Sets.newHashSet(FILE_A2)).commit();
+ commit(
+ table,
+ table.newRewrite().rewriteFiles(Sets.newHashSet(FILE_A), Sets.newHashSet(FILE_A2)),
+ branch);
- long deleteSnapshotId = table.currentSnapshot().snapshotId();
+ long deleteSnapshotId = latestSnapshot(table, branch).snapshotId();
AssertHelpers.assertThrows(
"Should fail to add FILE_A_DELETES because FILE_A is missing",
ValidationException.class,
"Cannot commit, missing data files",
() ->
- table
- .newRowDelta()
- .addDeletes(FILE_A_DELETES)
- .validateFromSnapshot(validateFromSnapshotId)
- .validateDataFilesExist(ImmutableList.of(FILE_A.path()))
- .commit());
+ commit(
+ table,
+ table
+ .newRowDelta()
+ .addDeletes(FILE_A_DELETES)
+ .validateFromSnapshot(validateFromSnapshotId)
+ .validateDataFilesExist(ImmutableList.of(FILE_A.path())),
+ branch));
Assert.assertEquals(
"Table state should not be modified by failed RowDelta operation",
deleteSnapshotId,
- table.currentSnapshot().snapshotId());
+ latestSnapshot(table, branch).snapshotId());
Assert.assertEquals(
"Table should not have any delete manifests",
0,
- table.currentSnapshot().deleteManifests(table.io()).size());
+ latestSnapshot(table, branch).deleteManifests(table.io()).size());
}
@Test
public void testValidateDataFilesExistValidateDeletes() {
- table.newAppend().appendFile(FILE_A).appendFile(FILE_B).commit();
+ commit(table, table.newAppend().appendFile(FILE_A).appendFile(FILE_B), branch);
// test changes to the table back to the snapshot where FILE_A and FILE_B existed
- long validateFromSnapshotId = table.currentSnapshot().snapshotId();
+ long validateFromSnapshotId = latestSnapshot(table, branch).snapshotId();
// delete FILE_A
- table.newDelete().deleteFile(FILE_A).commit();
+ commit(table, table.newDelete().deleteFile(FILE_A), branch);
- long deleteSnapshotId = table.currentSnapshot().snapshotId();
+ long deleteSnapshotId = latestSnapshot(table, branch).snapshotId();
AssertHelpers.assertThrows(
"Should fail to add FILE_A_DELETES because FILE_A is missing",
ValidationException.class,
"Cannot commit, missing data files",
() ->
- table
- .newRowDelta()
- .addDeletes(FILE_A_DELETES)
- .validateDeletedFiles()
- .validateFromSnapshot(validateFromSnapshotId)
- .validateDataFilesExist(ImmutableList.of(FILE_A.path()))
- .commit());
+ commit(
+ table,
+ table
+ .newRowDelta()
+ .addDeletes(FILE_A_DELETES)
+ .validateDeletedFiles()
+ .validateFromSnapshot(validateFromSnapshotId)
+ .validateDataFilesExist(ImmutableList.of(FILE_A.path())),
+ branch));
Assert.assertEquals(
"Table state should not be modified by failed RowDelta operation",
deleteSnapshotId,
- table.currentSnapshot().snapshotId());
+ latestSnapshot(table, branch).snapshotId());
Assert.assertEquals(
"Table should not have any delete manifests",
0,
- table.currentSnapshot().deleteManifests(table.io()).size());
+ latestSnapshot(table, branch).deleteManifests(table.io()).size());
}
@Test
public void testValidateNoConflicts() {
- table.newAppend().appendFile(FILE_A).commit();
+ commit(table, table.newAppend().appendFile(FILE_A), branch);
// test changes to the table back to the snapshot where FILE_A and FILE_B existed
- long validateFromSnapshotId = table.currentSnapshot().snapshotId();
+ long validateFromSnapshotId = latestSnapshot(table, branch).snapshotId();
// delete FILE_A
- table.newAppend().appendFile(FILE_A2).commit();
+ commit(table, table.newAppend().appendFile(FILE_A2), branch);
- long appendSnapshotId = table.currentSnapshot().snapshotId();
+ long appendSnapshotId = latestSnapshot(table, branch).snapshotId();
AssertHelpers.assertThrows(
"Should fail to add FILE_A_DELETES because FILE_A2 was added",
ValidationException.class,
"Found conflicting files",
() ->
- table
- .newRowDelta()
- .addDeletes(FILE_A_DELETES)
- .validateFromSnapshot(validateFromSnapshotId)
- .conflictDetectionFilter(Expressions.equal("data", "u")) // bucket16("u") -> 0
- .validateNoConflictingDataFiles()
- .commit());
+ commit(
+ table,
+ table
+ .newRowDelta()
+ .addDeletes(FILE_A_DELETES)
+ .validateFromSnapshot(validateFromSnapshotId)
+ .conflictDetectionFilter(Expressions.equal("data", "u")) // bucket16("u") -> 0
+ .validateNoConflictingDataFiles(),
+ branch));
Assert.assertEquals(
"Table state should not be modified by failed RowDelta operation",
appendSnapshotId,
- table.currentSnapshot().snapshotId());
+ latestSnapshot(table, branch).snapshotId());
Assert.assertEquals(
"Table should not have any delete manifests",
0,
- table.currentSnapshot().deleteManifests(table.io()).size());
+ latestSnapshot(table, branch).deleteManifests(table.io()).size());
}
@Test
public void testValidateNoConflictsFromSnapshot() {
- table.newAppend().appendFile(FILE_A).commit();
+ commit(table, table.newAppend().appendFile(FILE_A), branch);
- long appendSnapshotId = table.currentSnapshot().snapshotId();
+ long appendSnapshotId = latestSnapshot(table, branch).snapshotId();
// delete FILE_A
- table.newAppend().appendFile(FILE_A2).commit();
+ commit(table, table.newAppend().appendFile(FILE_A2), branch);
// even though FILE_A2 was added, it happened before the "from" snapshot, so the validation
// allows it
- long validateFromSnapshotId = table.currentSnapshot().snapshotId();
+ long validateFromSnapshotId = latestSnapshot(table, branch).snapshotId();
- table
- .newRowDelta()
- .addDeletes(FILE_A_DELETES)
- .validateDeletedFiles()
- .validateFromSnapshot(validateFromSnapshotId)
- .validateDataFilesExist(ImmutableList.of(FILE_A.path()))
- .conflictDetectionFilter(Expressions.equal("data", "u")) // bucket16("u") -> 0
- .validateNoConflictingDataFiles()
- .commit();
+ commit(
+ table,
+ table
+ .newRowDelta()
+ .addDeletes(FILE_A_DELETES)
+ .validateDeletedFiles()
+ .validateFromSnapshot(validateFromSnapshotId)
+ .validateDataFilesExist(ImmutableList.of(FILE_A.path()))
+ .conflictDetectionFilter(Expressions.equal("data", "u")) // bucket16("u") -> 0
+ .validateNoConflictingDataFiles(),
+ branch);
- Snapshot snap = table.currentSnapshot();
+ Snapshot snap = latestSnapshot(table, branch);
Assert.assertEquals("Commit should produce sequence number 2", 3, snap.sequenceNumber());
Assert.assertEquals(
"Last sequence number should be 3", 3, table.ops().current().lastSequenceNumber());
@@ -431,27 +472,29 @@ public class TestRowDelta extends V2TableTestBase {
@Test
public void testOverwriteWithDeleteFile() {
- table
- .newRowDelta()
- .addRows(FILE_A)
- .addDeletes(FILE_A_DELETES)
- .addDeletes(FILE_B_DELETES)
- .commit();
+ commit(
+ table,
+ table.newRowDelta().addRows(FILE_A).addDeletes(FILE_A_DELETES).addDeletes(FILE_B_DELETES),
+ branch);
- long deltaSnapshotId = table.currentSnapshot().snapshotId();
+ long deltaSnapshotId = latestSnapshot(table, branch).snapshotId();
Assert.assertEquals(
- "Commit should produce sequence number 1", 1, table.currentSnapshot().sequenceNumber());
+ "Commit should produce sequence number 1",
+ 1,
+ latestSnapshot(table, branch).sequenceNumber());
Assert.assertEquals(
"Last sequence number should be 1", 1, table.ops().current().lastSequenceNumber());
// overwriting by a filter will also remove delete files that match because all matching data
// files are removed.
- table
- .newOverwrite()
- .overwriteByRowFilter(Expressions.equal(Expressions.bucket("data", 16), 0))
- .commit();
+ commit(
+ table,
+ table
+ .newOverwrite()
+ .overwriteByRowFilter(Expressions.equal(Expressions.bucket("data", 16), 0)),
+ branch);
- Snapshot snap = table.currentSnapshot();
+ Snapshot snap = latestSnapshot(table, branch);
Assert.assertEquals("Commit should produce sequence number 2", 2, snap.sequenceNumber());
Assert.assertEquals(
"Last sequence number should be 2", 2, table.ops().current().lastSequenceNumber());
@@ -478,24 +521,24 @@ public class TestRowDelta extends V2TableTestBase {
@Test
public void testReplacePartitionsWithDeleteFile() {
- table
- .newRowDelta()
- .addRows(FILE_A)
- .addDeletes(FILE_A_DELETES)
- .addDeletes(FILE_B_DELETES)
- .commit();
+ commit(
+ table,
+ table.newRowDelta().addRows(FILE_A).addDeletes(FILE_A_DELETES).addDeletes(FILE_B_DELETES),
+ branch);
- long deltaSnapshotId = table.currentSnapshot().snapshotId();
+ long deltaSnapshotId = latestSnapshot(table, branch).snapshotId();
Assert.assertEquals(
- "Commit should produce sequence number 1", 1, table.currentSnapshot().sequenceNumber());
+ "Commit should produce sequence number 1",
+ 1,
+ latestSnapshot(table, branch).sequenceNumber());
Assert.assertEquals(
"Last sequence number should be 1", 1, table.ops().current().lastSequenceNumber());
// overwriting the partition will also remove delete files that match because all matching data
// files are removed.
- table.newReplacePartitions().addFile(FILE_A2).commit();
+ commit(table, table.newReplacePartitions().addFile(FILE_A2), branch);
- Snapshot snap = table.currentSnapshot();
+ Snapshot snap = latestSnapshot(table, branch);
Assert.assertEquals("Commit should produce sequence number 2", 2, snap.sequenceNumber());
Assert.assertEquals(
"Last sequence number should be 2", 2, table.ops().current().lastSequenceNumber());
@@ -532,24 +575,24 @@ public class TestRowDelta extends V2TableTestBase {
@Test
public void testDeleteByExpressionWithDeleteFile() {
- table
- .newRowDelta()
- .addRows(FILE_A)
- .addDeletes(FILE_A_DELETES)
- .addDeletes(FILE_B_DELETES)
- .commit();
+ commit(
+ table,
+ table.newRowDelta().addRows(FILE_A).addDeletes(FILE_A_DELETES).addDeletes(FILE_B_DELETES),
+ branch);
- long deltaSnapshotId = table.currentSnapshot().snapshotId();
+ long deltaSnapshotId = latestSnapshot(table, branch).snapshotId();
Assert.assertEquals(
- "Commit should produce sequence number 1", 1, table.currentSnapshot().sequenceNumber());
+ "Commit should produce sequence number 1",
+ 1,
+ latestSnapshot(table, branch).sequenceNumber());
Assert.assertEquals(
"Last sequence number should be 1", 1, table.ops().current().lastSequenceNumber());
// deleting with a filter will also remove delete files that match because all matching data
// files are removed.
- table.newDelete().deleteFromRowFilter(Expressions.alwaysTrue()).commit();
+ commit(table, table.newDelete().deleteFromRowFilter(Expressions.alwaysTrue()), branch);
- Snapshot snap = table.currentSnapshot();
+ Snapshot snap = latestSnapshot(table, branch);
Assert.assertEquals("Commit should produce sequence number 2", 2, snap.sequenceNumber());
Assert.assertEquals(
"Last sequence number should be 2", 2, table.ops().current().lastSequenceNumber());
@@ -576,18 +619,20 @@ public class TestRowDelta extends V2TableTestBase {
@Test
public void testDeleteDataFileWithDeleteFile() {
- table.newRowDelta().addRows(FILE_A).addDeletes(FILE_A_DELETES).commit();
+ commit(table, table.newRowDelta().addRows(FILE_A).addDeletes(FILE_A_DELETES), branch);
- long deltaSnapshotId = table.currentSnapshot().snapshotId();
+ long deltaSnapshotId = latestSnapshot(table, branch).snapshotId();
Assert.assertEquals(
- "Commit should produce sequence number 1", 1, table.currentSnapshot().sequenceNumber());
+ "Commit should produce sequence number 1",
+ 1,
+ latestSnapshot(table, branch).sequenceNumber());
Assert.assertEquals(
"Last sequence number should be 1", 1, table.ops().current().lastSequenceNumber());
// deleting a specific data file will not affect a delete file
- table.newDelete().deleteFile(FILE_A).commit();
+ commit(table, table.newDelete().deleteFile(FILE_A), branch);
- Snapshot deleteSnap = table.currentSnapshot();
+ Snapshot deleteSnap = latestSnapshot(table, branch);
Assert.assertEquals("Commit should produce sequence number 2", 2, deleteSnap.sequenceNumber());
Assert.assertEquals(
"Last sequence number should be 2", 2, table.ops().current().lastSequenceNumber());
@@ -617,9 +662,9 @@ public class TestRowDelta extends V2TableTestBase {
// to be 2, the largest known sequence number. this will cause FILE_A_DELETES to be removed
// because it is too old
// to apply to any data files.
- table.newDelete().deleteFile("no-such-file").commit();
+ commit(table, table.newDelete().deleteFile("no-such-file"), branch);
- Snapshot nextSnap = table.currentSnapshot();
+ Snapshot nextSnap = latestSnapshot(table, branch);
Assert.assertEquals("Append should produce sequence number 3", 3, nextSnap.sequenceNumber());
Assert.assertEquals(
"Last sequence number should be 3", 3, table.ops().current().lastSequenceNumber());
@@ -639,18 +684,20 @@ public class TestRowDelta extends V2TableTestBase {
@Test
public void testFastAppendDoesNotRemoveStaleDeleteFiles() {
- table.newRowDelta().addRows(FILE_A).addDeletes(FILE_A_DELETES).commit();
+ commit(table, table.newRowDelta().addRows(FILE_A).addDeletes(FILE_A_DELETES), branch);
- long deltaSnapshotId = table.currentSnapshot().snapshotId();
+ long deltaSnapshotId = latestSnapshot(table, branch).snapshotId();
Assert.assertEquals(
- "Commit should produce sequence number 1", 1, table.currentSnapshot().sequenceNumber());
+ "Commit should produce sequence number 1",
+ 1,
+ latestSnapshot(table, branch).sequenceNumber());
Assert.assertEquals(
"Last sequence number should be 1", 1, table.ops().current().lastSequenceNumber());
// deleting a specific data file will not affect a delete file
- table.newDelete().deleteFile(FILE_A).commit();
+ commit(table, table.newDelete().deleteFile(FILE_A), branch);
- Snapshot deleteSnap = table.currentSnapshot();
+ Snapshot deleteSnap = latestSnapshot(table, branch);
Assert.assertEquals("Commit should produce sequence number 2", 2, deleteSnap.sequenceNumber());
Assert.assertEquals(
"Last sequence number should be 2", 2, table.ops().current().lastSequenceNumber());
@@ -677,9 +724,9 @@ public class TestRowDelta extends V2TableTestBase {
// the manifest that removed FILE_A will be dropped next merging commit, but FastAppend will not
// remove it
- table.newFastAppend().appendFile(FILE_B).commit();
+ commit(table, table.newFastAppend().appendFile(FILE_B), branch);
- Snapshot nextSnap = table.currentSnapshot();
+ Snapshot nextSnap = latestSnapshot(table, branch);
Assert.assertEquals("Append should produce sequence number 3", 3, nextSnap.sequenceNumber());
Assert.assertEquals(
"Last sequence number should be 3", 3, table.ops().current().lastSequenceNumber());
@@ -733,7 +780,7 @@ public class TestRowDelta extends V2TableTestBase {
.withRecordCount(1)
.build();
- table.newAppend().appendFile(dataFile1).commit();
+ commit(table, table.newAppend().appendFile(dataFile1), branch);
// add a data file to partition B
DataFile dataFile2 =
@@ -744,10 +791,10 @@ public class TestRowDelta extends V2TableTestBase {
.withRecordCount(1)
.build();
- table.newAppend().appendFile(dataFile2).commit();
+ commit(table, table.newAppend().appendFile(dataFile2), branch);
// use this snapshot as the starting snapshot in rowDelta
- Snapshot baseSnapshot = table.currentSnapshot();
+ Snapshot baseSnapshot = latestSnapshot(table, branch);
// add a delete file for partition A
DeleteFile deleteFile =
@@ -771,21 +818,21 @@ public class TestRowDelta extends V2TableTestBase {
.validateNoConflictingDataFiles();
// concurrently delete the file for partition B
- table.newDelete().deleteFile(dataFile2).commit();
+ commit(table, table.newDelete().deleteFile(dataFile2), branch);
// commit the delta for partition A
- rowDelta.commit();
+ commit(table, rowDelta, branch);
Assert.assertEquals(
"Table should have one new delete manifest",
1,
- table.currentSnapshot().deleteManifests(table.io()).size());
- ManifestFile deletes = table.currentSnapshot().deleteManifests(table.io()).get(0);
+ latestSnapshot(table, branch).deleteManifests(table.io()).size());
+ ManifestFile deletes = latestSnapshot(table, branch).deleteManifests(table.io()).get(0);
validateDeleteManifest(
deletes,
dataSeqs(4L),
fileSeqs(4L),
- ids(table.currentSnapshot().snapshotId()),
+ ids(latestSnapshot(table, branch).snapshotId()),
files(deleteFile),
statuses(Status.ADDED));
}
@@ -808,10 +855,10 @@ public class TestRowDelta extends V2TableTestBase {
.withRecordCount(1)
.build();
- table.newAppend().appendFile(dataFile1).commit();
+ commit(table, table.newAppend().appendFile(dataFile1), branch);
// use this snapshot as the starting snapshot in rowDelta
- Snapshot baseSnapshot = table.currentSnapshot();
+ Snapshot baseSnapshot = latestSnapshot(table, branch);
// add a delete file for partition A
DeleteFile deleteFile =
@@ -835,13 +882,13 @@ public class TestRowDelta extends V2TableTestBase {
.validateNoConflictingDataFiles();
// concurrently delete the file for partition A
- table.newDelete().deleteFile(dataFile1).commit();
+ commit(table, table.newDelete().deleteFile(dataFile1), branch);
AssertHelpers.assertThrows(
"Should fail to add deletes because data file is missing",
ValidationException.class,
"Cannot commit, missing data files",
- rowDelta::commit);
+ () -> commit(table, rowDelta, branch));
}
@Test
@@ -851,7 +898,7 @@ public class TestRowDelta extends V2TableTestBase {
// append a partitioned data file
DataFile firstSnapshotDataFile = newDataFile("data_bucket=0");
- table.newAppend().appendFile(firstSnapshotDataFile).commit();
+ commit(table, table.newAppend().appendFile(firstSnapshotDataFile), branch);
// remove the only partition field to make the spec unpartitioned
table.updateSpec().removeField(Expressions.bucket("data", 16)).commit();
@@ -860,14 +907,14 @@ public class TestRowDelta extends V2TableTestBase {
// append an unpartitioned data file
DataFile secondSnapshotDataFile = newDataFile("");
- table.newAppend().appendFile(secondSnapshotDataFile).commit();
+ commit(table, table.newAppend().appendFile(secondSnapshotDataFile), branch);
// evolve the spec and add a new partition field
table.updateSpec().addField("data").commit();
// append a data file with the new spec
DataFile thirdSnapshotDataFile = newDataFile("data=abc");
- table.newAppend().appendFile(thirdSnapshotDataFile).commit();
+ commit(table, table.newAppend().appendFile(thirdSnapshotDataFile), branch);
Assert.assertEquals("Should have 3 specs", 3, table.specs().size());
@@ -878,15 +925,17 @@ public class TestRowDelta extends V2TableTestBase {
DeleteFile secondDeleteFile = newDeleteFile(secondSnapshotDataFile.specId(), "");
DeleteFile thirdDeleteFile = newDeleteFile(thirdSnapshotDataFile.specId(), "data=abc");
- table
- .newRowDelta()
- .addRows(dataFile)
- .addDeletes(firstDeleteFile)
- .addDeletes(secondDeleteFile)
- .addDeletes(thirdDeleteFile)
- .commit();
+ commit(
+ table,
+ table
+ .newRowDelta()
+ .addRows(dataFile)
+ .addDeletes(firstDeleteFile)
+ .addDeletes(secondDeleteFile)
+ .addDeletes(thirdDeleteFile),
+ branch);
- Snapshot snapshot = table.currentSnapshot();
+ Snapshot snapshot = latestSnapshot(table, branch);
Assert.assertEquals("Commit should produce sequence number 4", 4, snapshot.sequenceNumber());
Assert.assertEquals(
"Last sequence number should be 4", 4, table.ops().current().lastSequenceNumber());
@@ -978,7 +1027,7 @@ public class TestRowDelta extends V2TableTestBase {
// append a partitioned data file
DataFile firstSnapshotDataFile = newDataFile("data_bucket=0");
- table.newAppend().appendFile(firstSnapshotDataFile).commit();
+ commit(table, table.newAppend().appendFile(firstSnapshotDataFile), branch);
// remove the only partition field to make the spec unpartitioned
table.updateSpec().removeField(Expressions.bucket("data", 16)).commit();
@@ -987,15 +1036,18 @@ public class TestRowDelta extends V2TableTestBase {
// append an unpartitioned data file
DataFile secondSnapshotDataFile = newDataFile("");
- table.newAppend().appendFile(secondSnapshotDataFile).commit();
+ commit(table, table.newAppend().appendFile(secondSnapshotDataFile), branch);
// commit two delete files to two specs in a single operation
DeleteFile firstDeleteFile = newDeleteFile(firstSnapshotDataFile.specId(), "data_bucket=0");
DeleteFile secondDeleteFile = newDeleteFile(secondSnapshotDataFile.specId(), "");
- table.newRowDelta().addDeletes(firstDeleteFile).addDeletes(secondDeleteFile).commit();
+ commit(
+ table,
+ table.newRowDelta().addDeletes(firstDeleteFile).addDeletes(secondDeleteFile),
+ branch);
- Snapshot thirdSnapshot = table.currentSnapshot();
+ Snapshot thirdSnapshot = latestSnapshot(table, branch);
// 2 appends and 1 row delta where delete files belong to different specs
Assert.assertEquals(
@@ -1007,9 +1059,12 @@ public class TestRowDelta extends V2TableTestBase {
DeleteFile thirdDeleteFile = newDeleteFile(firstSnapshotDataFile.specId(), "data_bucket=0");
DeleteFile fourthDeleteFile = newDeleteFile(secondSnapshotDataFile.specId(), "");
- table.newRowDelta().addDeletes(thirdDeleteFile).addDeletes(fourthDeleteFile).commit();
+ commit(
+ table,
+ table.newRowDelta().addDeletes(thirdDeleteFile).addDeletes(fourthDeleteFile),
+ branch);
- Snapshot fourthSnapshot = table.currentSnapshot();
+ Snapshot fourthSnapshot = latestSnapshot(table, branch);
// make sure merging respects spec boundaries
Assert.assertEquals(
@@ -1044,7 +1099,7 @@ public class TestRowDelta extends V2TableTestBase {
public void testAbortMultipleSpecs() {
// append a partitioned data file
DataFile firstSnapshotDataFile = newDataFile("data_bucket=0");
- table.newAppend().appendFile(firstSnapshotDataFile).commit();
+ commit(table, table.newAppend().appendFile(firstSnapshotDataFile), branch);
// remove the only partition field to make the spec unpartitioned
table.updateSpec().removeField(Expressions.bucket("data", 16)).commit();
@@ -1053,7 +1108,7 @@ public class TestRowDelta extends V2TableTestBase {
// append an unpartitioned data file
DataFile secondSnapshotDataFile = newDataFile("");
- table.newAppend().appendFile(secondSnapshotDataFile).commit();
+ commit(table, table.newAppend().appendFile(secondSnapshotDataFile), branch);
// prepare two delete files that belong to different specs
DeleteFile firstDeleteFile = newDeleteFile(firstSnapshotDataFile.specId(), "data_bucket=0");
@@ -1065,6 +1120,7 @@ public class TestRowDelta extends V2TableTestBase {
RowDelta rowDelta =
table
.newRowDelta()
+ .toBranch(branch)
.addDeletes(firstDeleteFile)
.addDeletes(secondDeleteFile)
.deleteWith(deletedFiles::add)
@@ -1074,13 +1130,13 @@ public class TestRowDelta extends V2TableTestBase {
rowDelta.apply();
// perform a conflicting concurrent operation
- table.newDelete().deleteFile(firstSnapshotDataFile).commit();
+ commit(table, table.newDelete().deleteFile(firstSnapshotDataFile), branch);
AssertHelpers.assertThrows(
"Should fail to commit row delta",
ValidationException.class,
"Cannot commit, missing data files",
- rowDelta::commit);
+ () -> commit(table, rowDelta, branch));
// we should clean up 1 manifest list and 2 delete manifests
Assert.assertEquals("Should delete 3 files", 3, deletedFiles.size());
@@ -1088,9 +1144,9 @@ public class TestRowDelta extends V2TableTestBase {
@Test
public void testConcurrentConflictingRowDelta() {
- table.newAppend().appendFile(FILE_A).commit();
+ commit(table, table.newAppend().appendFile(FILE_A), branch);
- Snapshot firstSnapshot = table.currentSnapshot();
+ Snapshot firstSnapshot = latestSnapshot(table, branch);
Expression conflictDetectionFilter = Expressions.alwaysTrue();
@@ -1098,6 +1154,7 @@ public class TestRowDelta extends V2TableTestBase {
RowDelta rowDelta =
table
.newRowDelta()
+ .toBranch(branch)
.addRows(FILE_B)
.addDeletes(FILE_A_DELETES)
.validateFromSnapshot(firstSnapshot.snapshotId())
@@ -1107,6 +1164,7 @@ public class TestRowDelta extends V2TableTestBase {
table
.newRowDelta()
+ .toBranch(branch)
.addDeletes(FILE_A_DELETES)
.validateFromSnapshot(firstSnapshot.snapshotId())
.conflictDetectionFilter(conflictDetectionFilter)
@@ -1117,14 +1175,14 @@ public class TestRowDelta extends V2TableTestBase {
"Should reject commit",
ValidationException.class,
"Found new conflicting delete files",
- rowDelta::commit);
+ () -> commit(table, rowDelta, branch));
}
@Test
public void testConcurrentConflictingRowDeltaWithoutAppendValidation() {
- table.newAppend().appendFile(FILE_A).commit();
+ commit(table, table.newAppend().appendFile(FILE_A), branch);
- Snapshot firstSnapshot = table.currentSnapshot();
+ Snapshot firstSnapshot = latestSnapshot(table, branch);
Expression conflictDetectionFilter = Expressions.alwaysTrue();
@@ -1139,6 +1197,7 @@ public class TestRowDelta extends V2TableTestBase {
table
.newRowDelta()
+ .toBranch(branch)
.addDeletes(FILE_A_DELETES)
.validateFromSnapshot(firstSnapshot.snapshotId())
.conflictDetectionFilter(conflictDetectionFilter)
@@ -1149,7 +1208,7 @@ public class TestRowDelta extends V2TableTestBase {
"Should reject commit",
ValidationException.class,
"Found new conflicting delete files",
- rowDelta::commit);
+ () -> commit(table, rowDelta, branch));
}
@Test
@@ -1170,7 +1229,7 @@ public class TestRowDelta extends V2TableTestBase {
.withRecordCount(1)
.build();
- table.newAppend().appendFile(dataFile1).commit();
+ commit(table, table.newAppend().appendFile(dataFile1), branch);
// add a data file to partition B
DataFile dataFile2 =
@@ -1181,9 +1240,9 @@ public class TestRowDelta extends V2TableTestBase {
.withRecordCount(1)
.build();
- table.newAppend().appendFile(dataFile2).commit();
+ commit(table, table.newAppend().appendFile(dataFile2), branch);
- Snapshot baseSnapshot = table.currentSnapshot();
+ Snapshot baseSnapshot = latestSnapshot(table, branch);
Expression conflictDetectionFilter = Expressions.equal("data", "a");
@@ -1201,6 +1260,7 @@ public class TestRowDelta extends V2TableTestBase {
RowDelta rowDelta =
table
.newRowDelta()
+ .toBranch(branch)
.addDeletes(deleteFile1)
.validateFromSnapshot(baseSnapshot.snapshotId())
.conflictDetectionFilter(conflictDetectionFilter)
@@ -1219,13 +1279,14 @@ public class TestRowDelta extends V2TableTestBase {
table
.newRowDelta()
+ .toBranch(branch)
.addDeletes(deleteFile2)
.validateFromSnapshot(baseSnapshot.snapshotId())
.commit();
- rowDelta.commit();
+ commit(table, rowDelta, branch);
- validateTableDeleteFiles(table, deleteFile1, deleteFile2);
+ validateBranchDeleteFiles(table, branch, deleteFile1, deleteFile2);
}
@Test
@@ -1240,9 +1301,9 @@ public class TestRowDelta extends V2TableTestBase {
// add a data file to partition A
DataFile dataFile1 = newDataFile("data=a");
- table.newAppend().appendFile(dataFile1).commit();
+ commit(table, table.newAppend().appendFile(dataFile1), branch);
- Snapshot baseSnapshot = table.currentSnapshot();
+ Snapshot baseSnapshot = latestSnapshot(table, branch);
// add an equality delete file
DeleteFile deleteFile1 =
@@ -1253,6 +1314,7 @@ public class TestRowDelta extends V2TableTestBase {
RowDelta rowDelta =
table
.newRowDelta()
+ .toBranch(branch)
.addDeletes(deleteFile1)
.validateFromSnapshot(baseSnapshot.snapshotId())
.validateNoConflictingDataFiles()
@@ -1270,11 +1332,11 @@ public class TestRowDelta extends V2TableTestBase {
baseSnapshot.sequenceNumber())
.validateFromSnapshot(baseSnapshot.snapshotId());
- rowDelta.commit();
- rewriteFiles.commit();
+ commit(table, rowDelta, branch);
+ commit(table, rewriteFiles, branch);
- validateTableDeleteFiles(table, deleteFile1);
- validateTableFiles(table, dataFile2);
+ validateBranchDeleteFiles(table, branch, deleteFile1);
+ validateBranchFiles(table, branch, dataFile2);
}
@Test
@@ -1290,9 +1352,9 @@ public class TestRowDelta extends V2TableTestBase {
// add a data file to partition A
DataFile dataFile1 = newDataFile("data=a");
- table.newAppend().appendFile(dataFile1).commit();
+ commit(table, table.newAppend().appendFile(dataFile1), branch);
- Snapshot baseSnapshot = table.currentSnapshot();
+ Snapshot baseSnapshot = latestSnapshot(table, branch);
// add an equality delete file
DeleteFile deleteFile1 =
@@ -1320,16 +1382,16 @@ public class TestRowDelta extends V2TableTestBase {
baseSnapshot.sequenceNumber())
.validateFromSnapshot(baseSnapshot.snapshotId());
- rowDelta.commit();
- rewriteFiles.commit();
+ commit(table, rowDelta, branch);
+ commit(table, rewriteFiles, branch);
table.refresh();
- List<ManifestFile> dataManifests = table.currentSnapshot().dataManifests(table.io());
+ List<ManifestFile> dataManifests = latestSnapshot(table, branch).dataManifests(table.io());
Assert.assertEquals("should have 1 data manifest", 1, dataManifests.size());
ManifestFile mergedDataManifest = dataManifests.get(0);
Assert.assertEquals("Manifest seq number must match", 3L, mergedDataManifest.sequenceNumber());
- long currentSnapshotId = table.currentSnapshot().snapshotId();
+ long currentSnapshotId = latestSnapshot(table, branch).snapshotId();
validateManifest(
mergedDataManifest,
@@ -1352,9 +1414,9 @@ public class TestRowDelta extends V2TableTestBase {
// add a data file to partition A
DataFile dataFile1 = newDataFile("data=a");
- table.newAppend().appendFile(dataFile1).commit();
+ commit(table, table.newAppend().appendFile(dataFile1), branch);
- Snapshot baseSnapshot = table.currentSnapshot();
+ Snapshot baseSnapshot = latestSnapshot(table, branch);
// add an position delete file
DeleteFile deleteFile1 = newDeleteFile(table.spec().specId(), "data=a");
@@ -1380,22 +1442,22 @@ public class TestRowDelta extends V2TableTestBase {
baseSnapshot.sequenceNumber())
.validateFromSnapshot(baseSnapshot.snapshotId());
- rowDelta.commit();
+ commit(table, rowDelta, branch);
AssertHelpers.assertThrows(
"Should not allow any new position delete associated with the data file",
ValidationException.class,
"Cannot commit, found new position delete for replaced data file",
- rewriteFiles::commit);
+ () -> commit(table, rewriteFiles, branch));
}
@Test
public void testRowDeltaCaseSensitivity() {
- table.newAppend().appendFile(FILE_A).appendFile(FILE_A2).commit();
+ commit(table, table.newAppend().appendFile(FILE_A).appendFile(FILE_A2), branch);
- Snapshot firstSnapshot = table.currentSnapshot();
+ Snapshot firstSnapshot = latestSnapshot(table, branch);
- table.newRowDelta().addDeletes(FILE_A_DELETES).commit();
+ commit(table, table.newRowDelta().addDeletes(FILE_A_DELETES), branch);
Expression conflictDetectionFilter = Expressions.equal(Expressions.bucket("dAtA", 16), 0);
@@ -1406,6 +1468,7 @@ public class TestRowDelta extends V2TableTestBase {
() ->
table
.newRowDelta()
+ .toBranch(branch)
.addRows(FILE_B)
.addDeletes(FILE_A2_DELETES)
.validateFromSnapshot(firstSnapshot.snapshotId())
@@ -1421,6 +1484,7 @@ public class TestRowDelta extends V2TableTestBase {
() ->
table
.newRowDelta()
+ .toBranch(branch)
.caseSensitive(true)
.addRows(FILE_B)
.addDeletes(FILE_A2_DELETES)
@@ -1438,6 +1502,7 @@ public class TestRowDelta extends V2TableTestBase {
() ->
table
.newRowDelta()
+ .toBranch(branch)
.caseSensitive(false)
.addRows(FILE_B)
.addDeletes(FILE_A2_DELETES)
@@ -1447,20 +1512,4 @@ public class TestRowDelta extends V2TableTestBase {
.validateNoConflictingDeleteFiles()
.commit());
}
-
- @Test
- public void testRowDeltaToBranchUnsupported() {
- AssertHelpers.assertThrows(
- "Should reject committing row delta to branch",
- UnsupportedOperationException.class,
- "Cannot commit to branch someBranch: org.apache.iceberg.BaseRowDelta does not support branch commits",
- () ->
- table
- .newRowDelta()
- .caseSensitive(false)
- .addRows(FILE_B)
- .addDeletes(FILE_A2_DELETES)
- .toBranch("someBranch")
- .commit());
- }
}