zachdisc commented on code in PR #9731: URL: https://github.com/apache/iceberg/pull/9731#discussion_r1500927289
########## spark/v3.5/spark/src/main/java/org/apache/iceberg/spark/actions/RewriteManifestsSparkAction.java: ########## @@ -250,12 +282,40 @@ private List<ManifestFile> writeUnpartitionedManifests( private List<ManifestFile> writePartitionedManifests( ManifestContent content, Dataset<Row> manifestEntryDF, int numManifests) { + // Extract desired clustering/sorting criteria into a dedicated column + Dataset<Row> clusteredManifestEntryDF; + String clusteringColumnName = "__clustering_column__"; + + if (partitionSortColumns != null) { + LOG.info( + "Sorting manifests for specId {} by partition columns in order of {} ", + spec.specId(), + partitionSortColumns); + + // Map the top level partition column names to the column name referenced within the manifest + // entry dataframe + Column[] actualPartitionColumns = + partitionSortColumns.stream() + .map(p -> col("data_file.partition." + p)) + .toArray(Column[]::new); + + // Form a new temporary column to sort/cluster manifests on, based on the custom sort + // order provided + clusteredManifestEntryDF = + manifestEntryDF.withColumn( + clusteringColumnName, functions.struct(actualPartitionColumns)); + } else { + clusteredManifestEntryDF = + manifestEntryDF.withColumn(clusteringColumnName, col("data_file.partition")); + } + return withReusableDS( - manifestEntryDF, + clusteredManifestEntryDF, df -> { WriteManifests<?> writeFunc = newWriteManifestsFunc(content, df.schema()); - Column partitionColumn = df.col("data_file.partition"); - Dataset<Row> transformedDF = repartitionAndSort(df, partitionColumn, numManifests); + Column partitionColumn = df.col(clusteringColumnName); + Dataset<Row> transformedDF = + repartitionAndSort(df, partitionColumn, numManifests).drop(clusteringColumnName); Review Comment: Happy to make that change, but IMHO the API is indicating how the entire forest of manifests is sorted, not necessarily how each tree is sorted. Like, its sorting the `manifest_list` entries in the end, while the `manifest_files` are sorted further within that. Thoughts? Though, I suppose it isn't really `sort`ing the whole forest, it is `clustering`. -- 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