This is an automated email from the ASF dual-hosted git repository.
rdblue pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/iceberg.git
The following commit(s) were added to refs/heads/main by this push:
new 21153b1ff4 Core: Assign first-row-id to pre-v3 manifests carried into
v4 root (#19105)
21153b1ff4 is described below
commit 21153b1ff4b23bc2c362b14149c721ef363d0741
Author: Steven Zhen Wu <[email protected]>
AuthorDate: Mon Nov 23 18:32:53 2026 -0800
Core: Assign first-row-id to pre-v3 manifests carried into v4 root (#19105)
Data manifests written by v1/v2 tables have no first_row_id. When such a
table is upgraded directly to v4, these manifests are carried into the root
as EXISTING entries and should be assigned a first_row_id.
The root manifest writer already assigns it and counts the rows, but
RootTrackedFileWrapper rejects the assignment with "Missing first-row-id
for EXISTING file", so the first append after the upgrade fails. This fixes
RootTrackedFileWrapper to allow the assignment for EXISTING data manifests
without a first_row_id; other entries without one are still rejected.
Generated-by: Cursor (Claude Opus 5.5)
Co-authored-by: Cursor <[email protected]>
---
.../main/java/org/apache/iceberg/V4Metadata.java | 9 +++++
.../test/java/org/apache/iceberg/TestAppend.java | 36 +++++++++++++++++++
.../apache/iceberg/TestV4TrackedFileWrappers.java | 42 ++++++++++++++++++++++
3 files changed, 87 insertions(+)
diff --git a/core/src/main/java/org/apache/iceberg/V4Metadata.java
b/core/src/main/java/org/apache/iceberg/V4Metadata.java
index 1b7ff3e658..b246a0d451 100644
--- a/core/src/main/java/org/apache/iceberg/V4Metadata.java
+++ b/core/src/main/java/org/apache/iceberg/V4Metadata.java
@@ -369,6 +369,15 @@ class V4Metadata {
assignedFirstRowId != null,
"Missing first-row-id assignment for ADDED file: %s",
file.location());
+ } else if (tracking.firstRowId() == null
+ && content == FileContent.DATA_MANIFEST
+ && tracking.status() == EntryStatus.EXISTING) {
+ // data manifests written before v3 have no first-row-id and are
assigned one when
+ // they are first written to a root manifest
+ Preconditions.checkArgument(
+ assignedFirstRowId != null,
+ "Missing first-row-id assignment for EXISTING manifest: %s",
+ file.location());
} else {
Preconditions.checkArgument(
tracking.firstRowId() != null,
diff --git a/core/src/test/java/org/apache/iceberg/TestAppend.java
b/core/src/test/java/org/apache/iceberg/TestAppend.java
index ad791d1df7..bee06bb9a4 100644
--- a/core/src/test/java/org/apache/iceberg/TestAppend.java
+++ b/core/src/test/java/org/apache/iceberg/TestAppend.java
@@ -28,6 +28,7 @@ import org.apache.iceberg.io.OutputFile;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.FieldSource;
+import org.junit.jupiter.params.provider.ValueSource;
public class TestAppend extends AdaptiveMetadataTestBase {
private static final List<String> BRANCHES = List.of("main", "branch");
@@ -230,6 +231,41 @@ public class TestAppend extends AdaptiveMetadataTestBase {
statuses(EntryStatus.ADDED, EntryStatus.EXISTING));
}
+ @ParameterizedTest
+ @ValueSource(ints = {1, 2})
+ void appendToTableUpgradedFromPreV3(int formatVersion) throws IOException {
+ Table table = create("upgraded_table", SCHEMA, SPEC, formatVersion);
+ table.updateProperties().set(TableProperties.MANIFEST_MIN_MERGE_COUNT,
"1").commit();
+ table.newAppend().appendFile(FILE_A).commit();
+ table.newAppend().appendFile(FILE_B).commit();
+
+ assertThat(table.currentSnapshot().allManifests(io)).hasSize(1);
+ ManifestFile preV3Manifest =
table.currentSnapshot().allManifests(io).get(0);
+
+ InMemoryTables.Table upgraded = upgrade("upgraded_table", 4);
+ long firstRowId = upgraded.ops().current().nextRowId();
+
+ upgraded.newAppend().commit();
+ Snapshot snapshot = upgraded.currentSnapshot();
+ assertThat(snapshot.firstRowId()).isEqualTo(firstRowId);
+ assertThat(upgraded.ops().current().nextRowId())
+ .isEqualTo(firstRowId + preV3Manifest.existingRowsCount() +
preV3Manifest.addedRowsCount());
+
+ List<TrackedFile> rootFiles = readRoot(upgraded, snapshot);
+ validateFiles(
+ rootFiles,
+ contents(FileContent.DATA_MANIFEST),
+ dataSeqs(preV3Manifest.sequenceNumber()),
+ fileSeqs(preV3Manifest.sequenceNumber()),
+ ids(preV3Manifest.snapshotId()),
+ locations(preV3Manifest.path()),
+ statuses(EntryStatus.EXISTING));
+
+ assertThat(rootFiles)
+ .extracting(file -> file.tracking().firstRowId())
+ .containsExactly(firstRowId);
+ }
+
@Test
public void failureCleanup() throws IOException {
assertThat(readMetadata().lastSequenceNumber()).isEqualTo(0);
diff --git
a/core/src/test/java/org/apache/iceberg/TestV4TrackedFileWrappers.java
b/core/src/test/java/org/apache/iceberg/TestV4TrackedFileWrappers.java
index afddd4f1bf..fb09160fbc 100644
--- a/core/src/test/java/org/apache/iceberg/TestV4TrackedFileWrappers.java
+++ b/core/src/test/java/org/apache/iceberg/TestV4TrackedFileWrappers.java
@@ -637,6 +637,48 @@ class TestV4TrackedFileWrappers {
.hasMessage("Missing first-row-id for %s file: %s", status,
file.location());
}
+ @Test
+ void rootAssignsFirstRowIdToExistingManifestWithoutFirstRowId() {
+ TrackedFile manifest = mock(TrackedFile.class);
+ when(manifest.contentType()).thenReturn(FileContent.DATA_MANIFEST);
+ when(manifest.location()).thenReturn(MANIFEST_LOCATION);
+ when(manifest.manifestInfo()).thenReturn(mock(ManifestInfo.class));
+
+ Tracking tracking = mock(Tracking.class);
+ when(tracking.status()).thenReturn(EntryStatus.EXISTING);
+ when(tracking.firstRowId()).thenReturn(null);
+
+ RootTrackedFileWrapper wrapper =
+ new RootTrackedFileWrapper(
+ COMMIT_SNAPSHOT_ID, COMMIT_SEQ, UNPARTITIONED_SPECS,
UNPARTITIONED_TYPE, NO_STATS_TYPE);
+ StructLike row = wrapper.wrap(manifest, tracking, FIRST_ROW_ID);
+
+ assertThat(get(row, TRACKED_FILE_SCHEMA,
Tracking.FIRST_ROW_ID)).isEqualTo(FIRST_ROW_ID);
+ }
+
+ @ParameterizedTest
+ @EnumSource(
+ value = EntryStatus.class,
+ mode = EnumSource.Mode.EXCLUDE,
+ names = {"ADDED", "EXISTING"})
+ void rootRejectsMissingFirstRowIdForNonExistingManifest(EntryStatus status) {
+ TrackedFile manifest = mock(TrackedFile.class);
+ when(manifest.contentType()).thenReturn(FileContent.DATA_MANIFEST);
+ when(manifest.location()).thenReturn(MANIFEST_LOCATION);
+
+ Tracking tracking = mock(Tracking.class);
+ when(tracking.status()).thenReturn(status);
+ when(tracking.firstRowId()).thenReturn(null);
+
+ RootTrackedFileWrapper wrapper =
+ new RootTrackedFileWrapper(
+ COMMIT_SNAPSHOT_ID, COMMIT_SEQ, UNPARTITIONED_SPECS,
UNPARTITIONED_TYPE, NO_STATS_TYPE);
+
+ assertThatThrownBy(() -> wrapper.wrap(manifest, tracking, FIRST_ROW_ID))
+ .isInstanceOf(IllegalArgumentException.class)
+ .hasMessage("Missing first-row-id for %s file: %s", status,
MANIFEST_LOCATION);
+ }
+
@ParameterizedTest
@EnumSource(
value = FileContent.class,