Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions datafusion/proto/proto/datafusion.proto
Original file line number Diff line number Diff line change
Expand Up @@ -1353,6 +1353,7 @@ message RepartitionExecNode{
// uint64 unknown = 4;
// }
Partitioning partitioning = 5;
bool preserve_order = 6;
}

message Partitioning {
Expand Down
18 changes: 18 additions & 0 deletions datafusion/proto/src/generated/pbjson.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions datafusion/proto/src/generated/prost.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions datafusion/proto/src/physical_plan/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1011,10 +1011,11 @@ impl protobuf::PhysicalPlanNode {
codec,
proto_converter,
)?;
Ok(Arc::new(RepartitionExec::try_new(
input,
partitioning.unwrap(),
)?))
let mut repart_exec = RepartitionExec::try_new(input, partitioning.unwrap())?;
if repart.preserve_order {
repart_exec = repart_exec.with_preserve_order();
}
Ok(Arc::new(repart_exec))
}

fn try_into_global_limit_physical_plan(
Expand Down Expand Up @@ -3056,6 +3057,7 @@ impl protobuf::PhysicalPlanNode {
protobuf::RepartitionExecNode {
input: Some(Box::new(input)),
partitioning: Some(pb_partitioning),
preserve_order: exec.preserve_order(),
},
))),
})
Expand Down
29 changes: 29 additions & 0 deletions datafusion/proto/tests/cases/roundtrip_physical_plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1781,6 +1781,35 @@ fn roundtrip_union() -> Result<()> {
roundtrip_test(union)
}

#[test]
fn roundtrip_repartition_preserve_order() -> Result<()> {
let field_a = Field::new("a", DataType::Int64, false);
let schema = Arc::new(Schema::new(vec![field_a]));
let sort_exprs: LexOrdering = [PhysicalSortExpr {
expr: col("a", &schema)?,
options: SortOptions::default(),
}]
.into();

// Create two sorted single-partition inputs, then union them to get
// a sorted input with 2 partitions.
let source1 = SortExec::new(
sort_exprs.clone(),
Arc::new(EmptyExec::new(Arc::clone(&schema))),
);
let source2 = SortExec::new(sort_exprs, Arc::new(EmptyExec::new(schema)));
let union = UnionExec::try_new(vec![
Arc::new(source1) as Arc<dyn ExecutionPlan>,
Arc::new(source2) as Arc<dyn ExecutionPlan>,
])?;

let repartition = RepartitionExec::try_new(union, Partitioning::RoundRobinBatch(10))?
.with_preserve_order();
assert!(repartition.preserve_order());

roundtrip_test(Arc::new(repartition))
}

#[test]
fn roundtrip_interleave() -> Result<()> {
let field_a = Field::new("col", DataType::Int64, false);
Expand Down
Loading