Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions core/src/main/java/org/apache/iceberg/SnapshotProducer.java
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,8 @@ private Map<String, String> summary(TableMetadata previous) {

ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();

builder.put(SnapshotSummary.TARGET_BRANCH_PROP, targetBranch);

// copy all summary properties from the implementation
builder.putAll(summary);

Expand Down
1 change: 1 addition & 0 deletions core/src/main/java/org/apache/iceberg/SnapshotSummary.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public class SnapshotSummary {
public static final String REPLACED_MANIFESTS_COUNT = "manifests-replaced";
public static final String KEPT_MANIFESTS_COUNT = "manifests-kept";
public static final String PROCESSED_MANIFEST_ENTRY_COUNT = "entries-processed";
public static final String TARGET_BRANCH_PROP = "target-branch";

public static final MapJoiner MAP_JOINER = Joiner.on(",").withKeyValueSeparator("=");

Expand Down
31 changes: 31 additions & 0 deletions core/src/test/java/org/apache/iceberg/TestSnapshotProducer.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.apache.iceberg;

import static org.apache.iceberg.SnapshotSummary.PUBLISHED_WAP_ID_PROP;
import static org.apache.iceberg.SnapshotSummary.TARGET_BRANCH_PROP;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

Expand Down Expand Up @@ -158,4 +159,34 @@ public void testCommitValidationWithCustomSummaryProperties() throws IOException
// Verify the table wasn't updated
assertThat(table.snapshots()).hasSize(1);
}

@TestTemplate
public void testPopulateTargetBranchSnapshotProperty() {
// Commit to main branch
table.newAppend().appendFile(FILE_A).commit();
Snapshot mainSnapshot = table.currentSnapshot();
assertThat(mainSnapshot.summary()).containsEntry(TARGET_BRANCH_PROP, SnapshotRef.MAIN_BRANCH);

// Create and commit to branch1
String branch1 = "branch1";
table.manageSnapshots().createBranch(branch1, mainSnapshot.snapshotId()).commit();
table.newAppend().appendFile(FILE_B).toBranch(branch1).commit();
Snapshot branch1Snapshot = table.snapshot(branch1);
assertThat(branch1Snapshot.summary()).containsEntry(TARGET_BRANCH_PROP, branch1);

// Create and commit to branch2
String branch2 = "branch2";
table.manageSnapshots().createBranch(branch2, mainSnapshot.snapshotId()).commit();
table.newAppend().appendFile(FILE_C).toBranch(branch2).commit();
Snapshot branch2Snapshot = table.snapshot(branch2);
assertThat(branch2Snapshot.summary()).containsEntry(TARGET_BRANCH_PROP, branch2);

// Verify all snapshots have correct target branch
assertThat(table.snapshot(mainSnapshot.snapshotId()).summary())
.containsEntry(TARGET_BRANCH_PROP, SnapshotRef.MAIN_BRANCH);
assertThat(table.snapshot(branch1Snapshot.snapshotId()).summary())
.containsEntry(TARGET_BRANCH_PROP, branch1);
assertThat(table.snapshot(branch2Snapshot.snapshotId()).summary())
.containsEntry(TARGET_BRANCH_PROP, branch2);
}
}
60 changes: 36 additions & 24 deletions core/src/test/java/org/apache/iceberg/TestSnapshotSummary.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public void fastAppendWithDuplicates() {
.commit();

assertThat(table.currentSnapshot().summary())
.hasSize(11)
.hasSize(12)
.containsEntry(SnapshotSummary.ADDED_FILES_PROP, "1")
.containsEntry(SnapshotSummary.ADDED_FILE_SIZE_PROP, "10")
.containsEntry(SnapshotSummary.ADDED_RECORDS_PROP, "1")
Expand All @@ -111,7 +111,8 @@ public void fastAppendWithDuplicates() {
.containsEntry(SnapshotSummary.TOTAL_EQ_DELETES_PROP, "0")
.containsEntry(SnapshotSummary.TOTAL_POS_DELETES_PROP, "0")
.containsEntry(SnapshotSummary.TOTAL_FILE_SIZE_PROP, "10")
.containsEntry(SnapshotSummary.TOTAL_RECORDS_PROP, "1");
.containsEntry(SnapshotSummary.TOTAL_RECORDS_PROP, "1")
.containsEntry(SnapshotSummary.TARGET_BRANCH_PROP, "main");
}

@TestTemplate
Expand All @@ -126,7 +127,7 @@ public void mergeAppendWithDuplicates() {
.commit();

assertThat(table.currentSnapshot().summary())
.hasSize(11)
.hasSize(12)
.containsEntry(SnapshotSummary.ADDED_FILES_PROP, "1")
.containsEntry(SnapshotSummary.ADDED_FILE_SIZE_PROP, "10")
.containsEntry(SnapshotSummary.ADDED_RECORDS_PROP, "1")
Expand All @@ -136,7 +137,8 @@ public void mergeAppendWithDuplicates() {
.containsEntry(SnapshotSummary.TOTAL_EQ_DELETES_PROP, "0")
.containsEntry(SnapshotSummary.TOTAL_POS_DELETES_PROP, "0")
.containsEntry(SnapshotSummary.TOTAL_FILE_SIZE_PROP, "10")
.containsEntry(SnapshotSummary.TOTAL_RECORDS_PROP, "1");
.containsEntry(SnapshotSummary.TOTAL_RECORDS_PROP, "1")
.containsEntry(SnapshotSummary.TARGET_BRANCH_PROP, "main");
}

@TestTemplate
Expand All @@ -155,7 +157,7 @@ public void overwriteWithDuplicates() {
.commit();

assertThat(table.currentSnapshot().summary())
.hasSize(14)
.hasSize(15)
.containsEntry(SnapshotSummary.ADDED_FILES_PROP, "1")
.containsEntry(SnapshotSummary.ADDED_FILE_SIZE_PROP, "10")
.containsEntry(SnapshotSummary.ADDED_RECORDS_PROP, "1")
Expand All @@ -168,7 +170,8 @@ public void overwriteWithDuplicates() {
.containsEntry(SnapshotSummary.TOTAL_EQ_DELETES_PROP, "0")
.containsEntry(SnapshotSummary.TOTAL_POS_DELETES_PROP, "0")
.containsEntry(SnapshotSummary.TOTAL_FILE_SIZE_PROP, "10")
.containsEntry(SnapshotSummary.TOTAL_RECORDS_PROP, "1");
.containsEntry(SnapshotSummary.TOTAL_RECORDS_PROP, "1")
.containsEntry(SnapshotSummary.TARGET_BRANCH_PROP, "main");
}

@TestTemplate
Expand All @@ -187,7 +190,7 @@ public void deleteWithDuplicates() {
.commit();

assertThat(table.currentSnapshot().summary())
.hasSize(11)
.hasSize(12)
.containsEntry(SnapshotSummary.CHANGED_PARTITION_COUNT_PROP, "2")
.containsEntry(SnapshotSummary.DELETED_FILES_PROP, "2")
.containsEntry(SnapshotSummary.DELETED_RECORDS_PROP, "2")
Expand All @@ -197,7 +200,8 @@ public void deleteWithDuplicates() {
.containsEntry(SnapshotSummary.TOTAL_EQ_DELETES_PROP, "0")
.containsEntry(SnapshotSummary.TOTAL_POS_DELETES_PROP, "0")
.containsEntry(SnapshotSummary.TOTAL_FILE_SIZE_PROP, "0")
.containsEntry(SnapshotSummary.TOTAL_RECORDS_PROP, "0");
.containsEntry(SnapshotSummary.TOTAL_RECORDS_PROP, "0")
.containsEntry(SnapshotSummary.TARGET_BRANCH_PROP, "main");
}

@TestTemplate
Expand All @@ -212,7 +216,7 @@ public void replacePartitionsWithDuplicates() {
.commit();

assertThat(table.currentSnapshot().summary())
.hasSize(12)
.hasSize(13)
.containsEntry(SnapshotSummary.ADDED_FILES_PROP, "1")
.containsEntry(SnapshotSummary.ADDED_FILE_SIZE_PROP, "10")
.containsEntry(SnapshotSummary.ADDED_RECORDS_PROP, "1")
Expand All @@ -223,7 +227,8 @@ public void replacePartitionsWithDuplicates() {
.containsEntry(SnapshotSummary.TOTAL_EQ_DELETES_PROP, "0")
.containsEntry(SnapshotSummary.TOTAL_POS_DELETES_PROP, "0")
.containsEntry(SnapshotSummary.TOTAL_FILE_SIZE_PROP, "10")
.containsEntry(SnapshotSummary.TOTAL_RECORDS_PROP, "1");
.containsEntry(SnapshotSummary.TOTAL_RECORDS_PROP, "1")
.containsEntry(SnapshotSummary.TARGET_BRANCH_PROP, "main");
}

@TestTemplate
Expand All @@ -238,7 +243,7 @@ public void rowDeltaWithDuplicates() {
.commit();

assertThat(table.currentSnapshot().summary())
.hasSize(11)
.hasSize(12)
.containsEntry(SnapshotSummary.ADDED_FILES_PROP, "1")
.containsEntry(SnapshotSummary.ADDED_FILE_SIZE_PROP, "10")
.containsEntry(SnapshotSummary.ADDED_RECORDS_PROP, "1")
Expand All @@ -248,7 +253,8 @@ public void rowDeltaWithDuplicates() {
.containsEntry(SnapshotSummary.TOTAL_EQ_DELETES_PROP, "0")
.containsEntry(SnapshotSummary.TOTAL_POS_DELETES_PROP, "0")
.containsEntry(SnapshotSummary.TOTAL_FILE_SIZE_PROP, "10")
.containsEntry(SnapshotSummary.TOTAL_RECORDS_PROP, "1");
.containsEntry(SnapshotSummary.TOTAL_RECORDS_PROP, "1")
.containsEntry(SnapshotSummary.TARGET_BRANCH_PROP, "main");
}

@TestTemplate
Expand All @@ -267,7 +273,7 @@ public void rowDeltaWithDeletesAndDuplicates() {
.commit();

assertThat(table.currentSnapshot().summary())
.hasSize(14)
.hasSize(15)
.containsEntry(SnapshotSummary.ADDED_FILES_PROP, "1")
.containsEntry(SnapshotSummary.ADDED_DELETE_FILES_PROP, "1")
.containsEntry(SnapshotSummary.ADDED_FILE_SIZE_PROP, "20") // size of data + delete file
Expand All @@ -280,7 +286,8 @@ public void rowDeltaWithDeletesAndDuplicates() {
.containsEntry(SnapshotSummary.TOTAL_EQ_DELETES_PROP, "0")
.containsEntry(SnapshotSummary.TOTAL_POS_DELETES_PROP, "1")
.containsEntry(SnapshotSummary.TOTAL_FILE_SIZE_PROP, "20")
.containsEntry(SnapshotSummary.TOTAL_RECORDS_PROP, "1");
.containsEntry(SnapshotSummary.TOTAL_RECORDS_PROP, "1")
.containsEntry(SnapshotSummary.TARGET_BRANCH_PROP, "main");
}

@TestTemplate
Expand All @@ -300,7 +307,7 @@ public void rewriteWithDuplicateFiles() {
.commit();

assertThat(table.currentSnapshot().summary())
.hasSize(14)
.hasSize(15)
.containsEntry(SnapshotSummary.ADDED_FILES_PROP, "1")
.containsEntry(SnapshotSummary.ADDED_FILE_SIZE_PROP, "10")
.containsEntry(SnapshotSummary.ADDED_RECORDS_PROP, "1")
Expand All @@ -313,7 +320,8 @@ public void rewriteWithDuplicateFiles() {
.containsEntry(SnapshotSummary.TOTAL_EQ_DELETES_PROP, "0")
.containsEntry(SnapshotSummary.TOTAL_POS_DELETES_PROP, "0")
.containsEntry(SnapshotSummary.TOTAL_FILE_SIZE_PROP, "10")
.containsEntry(SnapshotSummary.TOTAL_RECORDS_PROP, "1");
.containsEntry(SnapshotSummary.TOTAL_RECORDS_PROP, "1")
.containsEntry(SnapshotSummary.TARGET_BRANCH_PROP, "main");
}

@TestTemplate
Expand All @@ -334,7 +342,7 @@ public void rewriteWithDeletesAndDuplicates() {
.commit();

assertThat(table.currentSnapshot().summary())
.hasSize(16)
.hasSize(17)
.containsEntry(SnapshotSummary.ADDED_DELETE_FILES_PROP, "1")
.containsEntry(SnapshotSummary.ADDED_FILE_SIZE_PROP, "10")
.containsEntry(SnapshotSummary.ADD_POS_DELETE_FILES_PROP, "1")
Expand All @@ -349,7 +357,8 @@ public void rewriteWithDeletesAndDuplicates() {
.containsEntry(SnapshotSummary.TOTAL_EQ_DELETES_PROP, "0")
.containsEntry(SnapshotSummary.TOTAL_POS_DELETES_PROP, "1")
.containsEntry(SnapshotSummary.TOTAL_FILE_SIZE_PROP, "20")
.containsEntry(SnapshotSummary.TOTAL_RECORDS_PROP, "1");
.containsEntry(SnapshotSummary.TOTAL_RECORDS_PROP, "1")
.containsEntry(SnapshotSummary.TARGET_BRANCH_PROP, "main");
}

@TestTemplate
Expand All @@ -368,7 +377,7 @@ public void testFileSizeSummaryWithDVs() {
long totalPosDeletes1 = dv1.recordCount() + dv2.recordCount();
long totalFileSize1 = dv1.contentSizeInBytes() + dv2.contentSizeInBytes();
assertThat(summary1)
.hasSize(12)
.hasSize(13)
.doesNotContainKey(SnapshotSummary.ADD_POS_DELETE_FILES_PROP)
.doesNotContainKey(SnapshotSummary.REMOVED_POS_DELETE_FILES_PROP)
.containsEntry(SnapshotSummary.ADDED_DELETE_FILES_PROP, "1")
Expand All @@ -385,7 +394,8 @@ public void testFileSizeSummaryWithDVs() {
.containsEntry(SnapshotSummary.TOTAL_DATA_FILES_PROP, "0")
.containsEntry(SnapshotSummary.TOTAL_EQ_DELETES_PROP, "0")
.containsEntry(SnapshotSummary.TOTAL_RECORDS_PROP, "0")
.containsEntry(SnapshotSummary.CHANGED_PARTITION_COUNT_PROP, "1");
.containsEntry(SnapshotSummary.CHANGED_PARTITION_COUNT_PROP, "1")
.containsEntry(SnapshotSummary.TARGET_BRANCH_PROP, "main");

DeleteFile dv3 = newDV(FILE_A);
table
Expand All @@ -404,7 +414,7 @@ public void testFileSizeSummaryWithDVs() {
long totalPosDeletes2 = dv3.recordCount();
long totalFileSize2 = dv3.contentSizeInBytes();
assertThat(summary2)
.hasSize(16)
.hasSize(17)
.doesNotContainKey(SnapshotSummary.ADD_POS_DELETE_FILES_PROP)
.doesNotContainKey(SnapshotSummary.REMOVED_POS_DELETE_FILES_PROP)
.containsEntry(SnapshotSummary.ADDED_DELETE_FILES_PROP, "1")
Expand All @@ -421,7 +431,8 @@ public void testFileSizeSummaryWithDVs() {
.containsEntry(SnapshotSummary.TOTAL_DATA_FILES_PROP, "0")
.containsEntry(SnapshotSummary.TOTAL_EQ_DELETES_PROP, "0")
.containsEntry(SnapshotSummary.TOTAL_RECORDS_PROP, "0")
.containsEntry(SnapshotSummary.CHANGED_PARTITION_COUNT_PROP, "2");
.containsEntry(SnapshotSummary.CHANGED_PARTITION_COUNT_PROP, "2")
.containsEntry(SnapshotSummary.TARGET_BRANCH_PROP, "main");
}

@TestTemplate
Expand All @@ -435,7 +446,7 @@ public void rewriteManifestsWithDuplicateFiles() {
table.rewriteManifests().clusterBy(file -> "file").rewriteIf(ignored -> true).commit();

assertThat(table.currentSnapshot().summary())
.hasSize(12)
.hasSize(13)
.containsEntry(SnapshotSummary.CHANGED_PARTITION_COUNT_PROP, "0")
.containsEntry(SnapshotSummary.TOTAL_DATA_FILES_PROP, "3")
.containsEntry(SnapshotSummary.TOTAL_DELETE_FILES_PROP, "0")
Expand All @@ -446,6 +457,7 @@ public void rewriteManifestsWithDuplicateFiles() {
.containsEntry(SnapshotSummary.PROCESSED_MANIFEST_ENTRY_COUNT, "3")
.containsEntry(SnapshotSummary.CREATED_MANIFESTS_COUNT, "1")
.containsEntry(SnapshotSummary.KEPT_MANIFESTS_COUNT, "0")
.containsEntry(SnapshotSummary.REPLACED_MANIFESTS_COUNT, "3");
.containsEntry(SnapshotSummary.REPLACED_MANIFESTS_COUNT, "3")
.containsEntry(SnapshotSummary.TARGET_BRANCH_PROP, "main");
}
}