RussellSpitzer commented on code in PR #16910:
URL: https://github.com/apache/iceberg/pull/16910#discussion_r3844753705
##########
core/src/test/java/org/apache/iceberg/TestRewriteTablePathUtil.java:
##########
@@ -376,4 +386,121 @@ private ManifestFile
deleteManifestWithLiveAndDeletedEntry(DeleteFile live, Dele
return writer.toManifestFile();
}
+
+ @TestTemplate
+ public void testRewriteManifestListStampsMeasuredManifestLengths() throws
IOException {
+ table.newFastAppend().appendFile(FILE_A).commit();
+ table.newFastAppend().appendFile(FILE_B).commit();
+ Snapshot snapshot = table.currentSnapshot();
+ List<ManifestFile> manifests = snapshot.allManifests(table.io());
+ assertThat(manifests).hasSize(2);
+ ManifestFile measured = manifests.get(0);
+ ManifestFile unmeasured = manifests.get(1);
+
+ String manifestPath = measured.path();
+ String sourcePrefix = manifestPath.substring(0,
manifestPath.lastIndexOf("/metadata/"));
+ String targetPrefix = sourcePrefix + "/relocated";
+ String stagingDir = temp.resolve("staging").toString();
+ String outputPath = temp.resolve("rewritten-list-" + System.nanoTime() +
".avro").toString();
+
+ long rewrittenLength = measured.length() + 4242L;
+
+ RewriteTablePathUtil.RewriteResult<ManifestFile> result =
+ RewriteTablePathUtil.rewriteManifestList(
+ snapshot,
+ table.io(),
+ table.ops().current(),
+ ImmutableMap.of(measured.path(), rewrittenLength),
+ sourcePrefix,
+ targetPrefix,
+ stagingDir,
+ outputPath);
+
+ List<ManifestFile> rewritten =
ManifestLists.read(table.io().newInputFile(outputPath));
+ assertThat(rewritten).hasSize(2);
+ Map<String, Long> lengthByPath =
+ rewritten.stream().collect(Collectors.toMap(ManifestFile::path,
ManifestFile::length));
+
+ String measuredTargetPath =
+ RewriteTablePathUtil.newPath(measured.path(), sourcePrefix,
targetPrefix);
+ String unmeasuredTargetPath =
+ RewriteTablePathUtil.newPath(unmeasured.path(), sourcePrefix,
targetPrefix);
+ assertThat(lengthByPath)
+ .as("measured manifest should take the mapped length, keyed by its
source path")
+ .containsEntry(measuredTargetPath, rewrittenLength);
+ assertThat(lengthByPath)
+ .as("unmeasured manifest should keep its source length")
+ .containsEntry(unmeasuredTargetPath, unmeasured.length());
+
+ assertThat(result.toRewrite())
+ .as("only manifests with a measured length should be rewritten")
+ .extracting(ManifestFile::path)
+ .containsExactly(measured.path());
+ assertThat(result.copyPlan())
+ .as("the copy plan should cover the staged copy of that manifest only")
+ .containsExactly(
+ Pair.of(
+ RewriteTablePathUtil.stagingPath(measured.path(),
sourcePrefix, stagingDir),
+ measuredTargetPath));
+ }
+
+ @TestTemplate
Review Comment:
How is this related to this change?
--
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]