ZachDischner commented on code in PR #9731: URL: https://github.com/apache/iceberg/pull/9731#discussion_r1802300866
########## spark/v3.5/spark/src/main/java/org/apache/iceberg/spark/actions/RewriteManifestsSparkAction.java: ########## @@ -250,12 +288,59 @@ private List<ManifestFile> writeUnpartitionedManifests( private List<ManifestFile> writePartitionedManifests( ManifestContent content, Dataset<Row> manifestEntryDF, int numManifests) { + // Extract desired clustering criteria into a dedicated column + Dataset<Row> clusteredManifestEntryDF; + + if (partitionClusteringFunction != null) { + LOG.info( + "Sorting manifests for specId {} using custom clustering function", + spec.specId(), + partitionClusteringFunction); + Types.StructType partitionType = DataFile.getType(table.spec().partitionType()); + StructType dataFileSchema = manifestEntryDF.select("data_file.*").schema(); + + // Create a UDF to wrap the custom partitionClusteringFunction call + UserDefinedFunction clusteringUdf = + functions.udf( + new CustomDataFileClusteringUdf( + this.partitionClusteringFunction, partitionType, dataFileSchema), + DataTypes.StringType); + // Apply supplied partitionSortFunction function to the data_file datums within this dataframe + // The results are stored as a String in the new __clustering_column__ + clusteredManifestEntryDF = + manifestEntryDF.withColumn( + CUSTOM_CLUSTERING_COLUMN_NAME, clusteringUdf.apply(col("data_file"))); + } else if (partitionFieldClustering != null) { + LOG.info( + "Clustering manifests for specId {} by partition columns by {} ", + spec.specId(), + partitionFieldClustering); + + // Map the top level partition column names to the column name referenced within the manifest + // entry dataframe + Column[] actualPartitionColumns = + partitionFieldClustering.stream() + .map(p -> col("data_file.partition." + p)) + .toArray(Column[]::new); + + // Form a new temporary column to cluster manifests on, based on the custom clustering columns + // order provided + clusteredManifestEntryDF = + manifestEntryDF.withColumn( + CUSTOM_CLUSTERING_COLUMN_NAME, functions.struct(actualPartitionColumns)); + } else { + clusteredManifestEntryDF = Review Comment: I'll give it a shot. -- 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