zachdisc commented on code in PR #12840: URL: https://github.com/apache/iceberg/pull/12840#discussion_r2054905511
########## spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/actions/TestRewriteManifestsAction.java: ########## @@ -531,6 +536,158 @@ public void testRewriteLargeManifestsPartitionedTable() throws IOException { assertThat(newManifests).hasSizeGreaterThanOrEqualTo(2); } + @TestTemplate + public void testRewriteManifestsPartitionedTableWithInvalidClusteringColumns() + throws IOException { + PartitionSpec spec = PartitionSpec.builderFor(SCHEMA).identity("c1").bucket("c3", 10).build(); + Map<String, String> options = Maps.newHashMap(); + options.put(TableProperties.FORMAT_VERSION, String.valueOf(formatVersion)); + options.put(TableProperties.SNAPSHOT_ID_INHERITANCE_ENABLED, snapshotIdInheritanceEnabled); + Table table = TABLES.create(SCHEMA, spec, options, tableLocation); + + SparkActions actions = org.apache.iceberg.spark.actions.SparkActions.get(); + + List<String> hasNonexistentFields = ImmutableList.of("c1", "c2"); + assertThatThrownBy( + () -> + actions + .rewriteManifests(table) + .rewriteIf(manifest -> true) + .clusterBy(hasNonexistentFields) + .execute()) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage( + "Cannot set manifest clustering because specified field(s) [c2] were not found in " + + "current partition spec 0."); + + // c3_bucket is the correct internal partition name to use, c3 is the untransformed column name, + // clusterBy() expects the hidden partition column names + List<String> hasIncorrectPartitionFieldNames = ImmutableList.of("c1", "c3"); + assertThatThrownBy( + () -> + actions + .rewriteManifests(table) + .rewriteIf(manifest -> true) + .clusterBy(hasIncorrectPartitionFieldNames) + .execute()) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage( + "Cannot set manifest clustering because specified field(s) [c3] were not found in " + + "current partition spec 0."); + } + + @TestTemplate + public void testRewriteManifestsPartitionedTableWithCustomClustering() throws IOException { + Random random = new Random(); + + PartitionSpec spec = + PartitionSpec.builderFor(SCHEMA).identity("c1").truncate("c2", 3).bucket("c3", 10).build(); + Table table = TABLES.create(SCHEMA, spec, tableLocation); + + List<DataFile> dataFiles = Lists.newArrayList(); + for (int fileOrdinal = 0; fileOrdinal < 1000; fileOrdinal++) { + dataFiles.add( + newDataFile( + table, + TestHelpers.Row.of( + new Object[] { + fileOrdinal, String.valueOf(random.nextInt() * 100), random.nextInt(10) + }))); + } + ManifestFile appendManifest = writeManifest(table, dataFiles); + table.newFastAppend().appendManifest(appendManifest).commit(); + + List<ManifestFile> manifests = table.currentSnapshot().allManifests(table.io()); + assertThat(manifests).as("Should have 1 manifests before rewrite").hasSize(1); + + // Capture the c3 partition's lower and upper bounds - used for later test assertions Review Comment: I'll see what I can do. Contents can still be sorted locally, but not globally sorted without the `clusterBy`. I think you're suggesting to just say "sorted but different" is sufficient? -- 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: issues-unsubscr...@iceberg.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org For additional commands, e-mail: issues-h...@iceberg.apache.org