wombatu-kun commented on code in PR #16910:
URL: https://github.com/apache/iceberg/pull/16910#discussion_r3849109622
##########
spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/actions/TestRewriteTablePathsAction.java:
##########
@@ -363,6 +363,96 @@ public void testFullTableRewritePath() throws Exception {
checkFileNum(3, 2, 2, 9, result);
}
+ @TestTemplate
+ public void testManifestLengthAfterRewrite() throws Exception {
+ String sourceLocation = newTableLocation();
+ Table sourceTable =
+ TABLES.create(
+ SCHEMA,
+ PartitionSpec.unpartitioned(),
+ ImmutableMap.of(TableProperties.FORMAT_VERSION,
String.valueOf(formatVersion)),
+ sourceLocation);
+
+ appendManifestLengthRecords(sourceLocation, 0);
+ appendManifestLengthRecords(sourceLocation, 1);
+ sourceTable.refresh();
+ assertThat(sourceTable.snapshots()).hasSize(2);
+
+ String targetLocation =
+ targetTableLocation() +
"this/is/a/much/longer/nested/target/prefix/than/the/source";
+
+ RewriteTablePath.Result result =
+ actions()
+ .rewriteTablePath(sourceTable)
+ .stagingLocation(stagingLocation())
+ .rewriteLocationPrefix(sourceTable.location(), targetLocation)
+ .execute();
+ copyTableFiles(result);
+
+ Table targetTable = TABLES.load(targetLocation);
+ // snapshot 1 references its own manifest, snapshot 2 references both
+ assertThat(assertManifestLengthsMatchOnDisk(targetTable))
+ .as("should validate manifests across all (current and historical)
snapshots")
+ .isEqualTo(3);
+ assertRewriteChangedManifestLength(sourceTable, targetTable);
+ }
+
+ private void appendManifestLengthRecords(String location, int batch) {
+ List<ThreeColumnRecord> records = Lists.newArrayList();
+ for (int i = 0; i < 30; i++) {
+ int id = batch * 100 + i;
+ records.add(new ThreeColumnRecord(id, "row-" + id, "data-" + id));
+ }
+ spark
+ .createDataFrame(records, ThreeColumnRecord.class)
+ .repartition(30)
+ .select("c1", "c2", "c3")
+ .write()
+ .format("iceberg")
+ .mode("append")
+ .save(location);
+ }
+
+ private int assertManifestLengthsMatchOnDisk(Table targetTable) {
+ FileIO io = targetTable.io();
+ int checkedManifests = 0;
+ for (Snapshot snapshot : targetTable.snapshots()) {
+ for (ManifestFile manifest : snapshot.allManifests(io)) {
+ assertThat(manifest.length())
+ .as(
+ "manifest_length in the rewritten manifest list of snapshot %s
must match the"
+ + " on-disk size of %s",
+ snapshot.snapshotId(), manifest.path())
+ .isEqualTo(io.newInputFile(manifest.path()).getLength());
+ checkedManifests++;
+ }
+ }
+ return checkedManifests;
+ }
+
+ /** Guards the length assertions against a prefix change that moved no
manifest's byte size. */
+ private void assertRewriteChangedManifestLength(Table sourceTable, Table
targetTable) {
Review Comment:
Done fdb242220
--
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]