dramaticlly commented on code in PR #17039:
URL: https://github.com/apache/iceberg/pull/17039#discussion_r3530800448


##########
spark/v4.1/spark/src/test/java/org/apache/iceberg/spark/actions/TestRewriteDataFilesAction.java:
##########
@@ -2069,6 +2069,48 @@ public void 
testUnpartitionedRewriteDataFilesPreservesLineage() throws NoSuchTab
     assertEquals("Rows must match", expectedRecordsWithLineage, 
actualRecordsWithLineage);
   }
 
+  @TestTemplate
+  public void testUpgradePreservesDataSequence() throws NoSuchTableException {
+    assumeThat(formatVersion).isEqualTo(2);
+
+    Table table = createTable();
+    writeRecords(2, 4);
+    table.refresh();
+    shouldHaveFiles(table, 2);
+    long committedDataSequence = table.currentSnapshot().sequenceNumber();
+
+    Result result = basicRewrite(table).execute();
+    assertThat(result.rewrittenDataFilesCount()).isEqualTo(2);
+    assertThat(result.addedDataFilesCount()).isOne();
+    table.refresh();
+    shouldHaveFiles(table, 1);
+
+    DataFile compactedFile = Iterables.getOnlyElement(currentDataFiles(table));
+    long dataSequenceNumber = compactedFile.dataSequenceNumber();
+    assertThat(dataSequenceNumber)
+        .as("Compaction must preserve the original data sequence number")
+        .isEqualTo(committedDataSequence);
+    assertThat(compactedFile.fileSequenceNumber())
+        .as("Compaction must bump the file sequence above the preserved data 
sequence")
+        .isGreaterThan(dataSequenceNumber);
+
+    table.updateProperties().set(TableProperties.FORMAT_VERSION, "3").commit();
+    table.rewriteManifests().rewriteIf(manifest -> true).commit();
+    table.refresh();
+
+    List<Object[]> expectedLineage =
+        Lists.newArrayList(
+            row(0L, dataSequenceNumber, ANY, ANY, ANY),
+            row(1L, dataSequenceNumber, ANY, ANY, ANY),
+            row(2L, dataSequenceNumber, ANY, ANY, ANY),
+            row(3L, dataSequenceNumber, ANY, ANY, ANY));
+
+    assertEquals(
+        "Row IDs must be 0..3 and last-updated must inherit the data sequence",

Review Comment:
   nit: First snapshot after upgrade to v3 assigns row id and preserve the 
committed data sequence number as last updated sequence number. 



##########
spark/v4.1/spark/src/test/java/org/apache/iceberg/spark/actions/TestRewriteDataFilesAction.java:
##########
@@ -2069,6 +2069,48 @@ public void 
testUnpartitionedRewriteDataFilesPreservesLineage() throws NoSuchTab
     assertEquals("Rows must match", expectedRecordsWithLineage, 
actualRecordsWithLineage);
   }
 
+  @TestTemplate
+  public void testUpgradePreservesDataSequence() throws NoSuchTableException {
+    assumeThat(formatVersion).isEqualTo(2);
+
+    Table table = createTable();
+    writeRecords(2, 4);
+    table.refresh();
+    shouldHaveFiles(table, 2);
+    long committedDataSequence = table.currentSnapshot().sequenceNumber();
+
+    Result result = basicRewrite(table).execute();
+    assertThat(result.rewrittenDataFilesCount()).isEqualTo(2);
+    assertThat(result.addedDataFilesCount()).isOne();
+    table.refresh();
+    shouldHaveFiles(table, 1);
+
+    DataFile compactedFile = Iterables.getOnlyElement(currentDataFiles(table));
+    long dataSequenceNumber = compactedFile.dataSequenceNumber();
+    assertThat(dataSequenceNumber)
+        .as("Compaction must preserve the original data sequence number")
+        .isEqualTo(committedDataSequence);
+    assertThat(compactedFile.fileSequenceNumber())
+        .as("Compaction must bump the file sequence above the preserved data 
sequence")
+        .isGreaterThan(dataSequenceNumber);
+
+    table.updateProperties().set(TableProperties.FORMAT_VERSION, "3").commit();
+    table.rewriteManifests().rewriteIf(manifest -> true).commit();
+    table.refresh();
+
+    List<Object[]> expectedLineage =
+        Lists.newArrayList(
+            row(0L, dataSequenceNumber, ANY, ANY, ANY),
+            row(1L, dataSequenceNumber, ANY, ANY, ANY),
+            row(2L, dataSequenceNumber, ANY, ANY, ANY),
+            row(3L, dataSequenceNumber, ANY, ANY, ANY));

Review Comment:
   Nit: I am thinking if we shall use committedDataSequence instead of 
dataSequenceNumber here even though it has the same value?
   
   As the second column is the value of `_last_updated_sequence_number`, so 
equal to sequence of row when it gets committed to the table seem to make more 
sence.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to