palaska opened a new issue, #12611: URL: https://github.com/apache/datafusion/issues/12611
### Describe the bug target_partitions execution option is ignored when the input has 1 partition. The introduced condition [here](https://github.com/apache/datafusion/blob/main/datafusion/core/src/physical_optimizer/enforce_distribution.rs#L1242) is the root cause. ### To Reproduce ```rs use datafusion::execution::context::{SessionConfig, SessionContext}; use datafusion::arrow::datatypes::{DataType, Schema}; use datafusion::prelude::col; use datafusion::functions_aggregate::sum::sum; use datafusion::physical_plan::display::DisplayableExecutionPlan; use datafusion::test_util::scan_empty; let config = SessionConfig::new().with_target_partitions(4); let ctx = Arc::new(SessionContext::new_with_config(config)); let session_state = ctx.state(); let schema = Schema::new(vec![ Field::new("a", DataType::Utf8, false), Field::new("b", DataType::UInt64, false), ]); let logical_plan = scan_empty(None, &schema, Some(vec![0, 1])) .unwrap() .aggregate(vec![col("a")], vec![sum(col("b"))]) .unwrap() .build() .unwrap(); let optimized_plan = session_state.optimize(&logical_plan).unwrap(); let plan = session_state .create_physical_plan(&optimized_plan) .await .unwrap(); println!( "{}", DisplayableExecutionPlan::new(plan.as_ref()).indent(false) ); ``` Above code produces a physical plan with a single output partition and the plan doesn't contain a RepartitionExec. ```rs use datafusion::execution::context::{SessionConfig, SessionContext}; use datafusion::arrow::datatypes::{DataType, Schema}; use datafusion::prelude::col; use datafusion::functions_aggregate::sum::sum; use datafusion::physical_plan::display::DisplayableExecutionPlan; use datafusion::test_util::scan_empty_with_partitions; let config = SessionConfig::new().with_target_partitions(4); let ctx = Arc::new(SessionContext::new_with_config(config)); let session_state = ctx.state(); let schema = Schema::new(vec![ Field::new("a", DataType::Utf8, false), Field::new("b", DataType::UInt64, false), ]); // setting the number of input partitions to 2 instead of 1 let logical_plan = scan_empty_with_partitions(None, &schema, Some(vec![0, 1]), 2) .unwrap() .aggregate(vec![col("a")], vec![sum(col("b"))]) .unwrap() .build() .unwrap(); let optimized_plan = session_state.optimize(&logical_plan).unwrap(); let plan = session_state .create_physical_plan(&optimized_plan) .await .unwrap(); println!( "{}", DisplayableExecutionPlan::new(plan.as_ref()).indent(false) ); ``` When the input partition number is set to a value > 1, it works as expected. (`multi_partitions` becomes `true` [here](https://github.com/apache/datafusion/blob/main/datafusion/core/src/physical_optimizer/enforce_distribution.rs#L1103)) ### Expected behavior _No response_ ### Additional context _No response_ -- 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]
