dramaticlly commented on code in PR #17039:
URL: https://github.com/apache/iceberg/pull/17039#discussion_r3530775106
##########
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: since the second column represents `_last_updated_sequence_number`,
could we use committedDataSequence here instead? Even though the values are
equal, referencing the sequence at commit time reads more naturally for that
column.
--
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]