mxm commented on code in PR #19242:
URL: https://github.com/apache/iceberg/pull/19242#discussion_r4801067202
##########
core/src/test/java/org/apache/iceberg/TestRewriteTablePathUtil.java:
##########
@@ -476,6 +476,125 @@ public void testFileName() {
assertThat(RewriteTablePathUtil.fileName("file.parquet")).isEqualTo("file.parquet");
}
+ @Test
+ void rewriteDataManifestCopiesEntriesAfterStartSequenceNumber() throws
IOException {
+ assumeThat(formatVersion)
+ .as("Sequence numbers require format version 2+")
+ .isGreaterThanOrEqualTo(2);
+
+ // FILE_B keeps an old data sequence number but was committed after the
start, like a
+ // compaction output
+ ManifestFile manifest =
+ writeManifest(
+ 3L,
+ manifestEntry(ManifestEntry.Status.EXISTING, 1L, 1L, 1L, FILE_A),
+ manifestEntry(ManifestEntry.Status.EXISTING, 2L, 1L, 2L, FILE_B),
+ manifestEntry(ManifestEntry.Status.DELETED, 3L, 3L, 3L, FILE_C));
+
+ RewriteTablePathUtil.RewriteResult<DataFile> result =
+ RewriteTablePathUtil.rewriteDataManifest(
+ manifest,
+ 1L,
+ Set.of(),
+ Files.localOutput(temp.resolve("rewritten.avro").toFile()),
+ table.io(),
+ formatVersion,
+ table.specs(),
+ "/path/to/",
+ "/path/new/");
+
+ assertThat(result.copyPlan())
+ .containsExactly(Pair.of(FILE_B.location(),
"/path/new/data-b.parquet"));
+ }
+
+ @Test
+ void rewriteDataManifestFallsBackToSnapshotIdsWithoutFileSequenceNumber()
throws IOException {
+ assumeThat(formatVersion)
+ .as("Sequence numbers require format version 2+")
+ .isGreaterThanOrEqualTo(2);
+
+ ManifestFile manifest =
+ writeManifest(
+ 2L,
+ manifestEntry(ManifestEntry.Status.EXISTING, 1L, 1L, null, FILE_A),
+ manifestEntry(ManifestEntry.Status.EXISTING, 2L, 1L, null,
FILE_B));
+
+ RewriteTablePathUtil.RewriteResult<DataFile> result =
+ RewriteTablePathUtil.rewriteDataManifest(
+ manifest,
+ 5L,
+ Set.of(1L),
+ Files.localOutput(temp.resolve("rewritten.avro").toFile()),
+ table.io(),
+ formatVersion,
+ table.specs(),
+ "/path/to/",
+ "/path/new/");
+
+ assertThat(result.copyPlan())
+ .containsExactly(Pair.of(FILE_B.location(),
"/path/new/data-b.parquet"));
+ }
+
+ @Test
+ void rewriteDeleteManifestCopiesEntriesAfterStartSequenceNumber() throws
IOException {
+ assumeThat(formatVersion)
+ .as("Delete files require format version 2+")
+ .isGreaterThanOrEqualTo(2);
+
+ ManifestFile manifest =
+ writeManifest(
+ 2L,
+ manifestEntry(ManifestEntry.Status.EXISTING, 1L, 1L, 1L,
FILE_A_DELETES),
+ manifestEntry(ManifestEntry.Status.EXISTING, 2L, 2L, 2L,
FILE_A_EQUALITY_DELETES));
+
+ RewriteTablePathUtil.RewriteResult<DeleteFile> result =
+ RewriteTablePathUtil.rewriteDeleteManifest(
+ manifest,
+ 1L,
+ Set.of(),
+ Files.localOutput(temp.resolve("rewritten.avro").toFile()),
+ table.io(),
+ formatVersion,
+ table.specs(),
+ "/path/to/",
+ "/path/new/",
+ "/staging/",
+ ImmutableMap.of());
+
+ assertThat(result.copyPlan())
+ .containsExactly(
+ Pair.of(
+ FILE_A_EQUALITY_DELETES.location(),
"/path/new/data-a-equality-deletes.parquet"));
+ }
+
+ @Test
+ void rewriteDataManifestWithoutStartSequenceNumberSkipsStartSnapshots()
throws IOException {
+ assumeThat(formatVersion)
+ .as("Uncommitted v1 manifests have no sequence number for entries to
inherit")
+ .isGreaterThanOrEqualTo(2);
Review Comment:
Do we have a test that copies a v1 table incrementally, so the snapshot ID
path with start sequence number 0 is covered?
##########
spark/v4.2/spark/src/main/java/org/apache/iceberg/spark/actions/RewriteTablePathSparkAction.java:
##########
@@ -535,26 +530,11 @@ private RewriteResult<ManifestFile> rewriteManifestList(
return result;
}
- private Set<String> manifestsToRewrite(
- Set<Snapshot> deltaSnapshots, TableMetadata startMetadata) {
+ private void validateEndVersionManifests() {
try {
Table endStaticTable = newStaticTable(endVersionName, table.io());
- Dataset<Row> lastVersionFiles =
manifestDS(endStaticTable).select("path");
- if (startMetadata == null) {
- return
Sets.newHashSet(lastVersionFiles.distinct().as(Encoders.STRING()).collectAsList());
- } else {
- Set<Long> deltaSnapshotIds =
-
deltaSnapshots.stream().map(Snapshot::snapshotId).collect(Collectors.toSet());
- return Sets.newHashSet(
- lastVersionFiles
- .distinct()
- .filter(
- functions
- .column(ManifestFile.SNAPSHOT_ID.name())
- .isInCollection(deltaSnapshotIds))
- .as(Encoders.STRING())
- .collectAsList());
- }
+ // read all manifest lists to fail fast on a missing one, without
collecting to the driver
+ manifestDS(endStaticTable).select("path").count();
Review Comment:
+1 for dropping the extra job. Could we instead catch the failure of the
`snapshot.allManifests` read in `rebuildMetadata` and throw the same exception
there? We read those manifest lists anyway.
--
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]