fvaleye commented on code in PR #1620: URL: https://github.com/apache/iceberg-rust/pull/1620#discussion_r2306836325
########## crates/integrations/datafusion/src/physical_plan/repartition.rs: ########## @@ -0,0 +1,906 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +use std::any::Any; +use std::sync::Arc; + +use datafusion::error::Result as DFResult; +use datafusion::execution::{SendableRecordBatchStream, TaskContext}; +use datafusion::physical_expr::{EquivalenceProperties, PhysicalExpr}; +use datafusion::physical_plan::execution_plan::{Boundedness, EmissionType}; +use datafusion::physical_plan::expressions::Column; +use datafusion::physical_plan::repartition::RepartitionExec; +use datafusion::physical_plan::{ + DisplayAs, DisplayFormatType, ExecutionPlan, Partitioning, PlanProperties, +}; +use iceberg::spec::{SchemaRef, TableMetadata, TableMetadataRef, Transform}; + +/// Iceberg-specific repartition execution plan that optimizes data distribution +/// for parallel processing while respecting Iceberg table partitioning semantics. +/// +/// This execution plan automatically determines the optimal partitioning strategy based on +/// the table's partition specification and the configured write distribution mode: +/// +/// ## Partitioning Strategies +/// +/// - **Unpartitioned tables**: Uses round-robin distribution to ensure balanced load +/// across all workers, maximizing parallelism for write operations. +/// +/// - **Partitioned tables**: Uses hash partitioning on partition columns (identity transforms) +/// and bucket columns to maintain data co-location. This ensures: +/// - Better file clustering within partitions +/// - Improved query pruning performance +/// - Optimal join performance on partitioned columns +/// +/// - **Range-distributed tables**: Approximates range distribution by hashing on sort order +/// columns since DataFusion lacks native range exchange. Falls back to partition/bucket +/// column hashing when available. +/// +/// ## Write Distribution Modes +/// +/// Respects the table's `write.distribution-mode` property: +/// - `hash` (default): Distributes by partition and bucket columns +/// - `range`: Distributes by sort order columns +/// - `none`: Uses round-robin distribution +/// +/// ## Performance notes +/// +/// - Only repartitions when the input partitioning scheme differs from the desired strategy +/// - Only repartitions when the input partition count differs from the target +/// - Automatically detects optimal partition count from DataFusion's SessionConfig +/// - Preserves column order (partitions first, then buckets) for consistent file layout +#[derive(Debug)] +pub struct IcebergRepartitionExec { Review Comment: All right, let's follow the KISS principle. That makes perfect sense. I'll rework that! -- 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