@@ -310,6 +310,12 @@ fn _apply_network_boundaries(
310310 }
311311 ctx. plan = Arc :: new ( NetworkShuffleExec :: try_new ( ctx. plan , task_count) ?) ;
312312 return Ok ( ctx) ;
313+ } else if let Some ( coalesce_batches) = ctx. plan . as_any ( ) . downcast_ref :: < CoalesceBatchesExec > ( ) {
314+ // If the batch coalescing is before the network boundary, remove it, as we don't
315+ // want it there, we want it after, and the code that adds it lives just some lines above.
316+ if coalesce_batches. input ( ) . is_network_boundary ( ) {
317+ ctx. plan = Arc :: clone ( coalesce_batches. input ( ) ) ;
318+ }
313319 }
314320
315321 // If this is a CoalescePartitionsExec, it means that the original plan is trying to
@@ -556,8 +562,7 @@ mod tests {
556562 │ SortExec: expr=[count(*)@0 ASC NULLS LAST], preserve_partitioning=[true]
557563 │ ProjectionExec: expr=[count(Int64(1))@1 as count(*), RainToday@0 as RainToday, count(Int64(1))@1 as count(Int64(1))]
558564 │ AggregateExec: mode=FinalPartitioned, gby=[RainToday@0 as RainToday], aggr=[count(Int64(1))]
559- │ CoalesceBatchesExec: target_batch_size=8192
560- │ [Stage 1] => NetworkShuffleExec: output_partitions=4, input_tasks=3
565+ │ [Stage 1] => NetworkShuffleExec: output_partitions=4, input_tasks=3
561566 └──────────────────────────────────────────────────
562567 ┌───── Stage 1 ── Tasks: t0:[p0..p7] t1:[p0..p7] t2:[p0..p7]
563568 │ CoalesceBatchesExec: target_batch_size=8192
@@ -589,8 +594,7 @@ mod tests {
589594 │ SortExec: expr=[count(*)@0 ASC NULLS LAST], preserve_partitioning=[true]
590595 │ ProjectionExec: expr=[count(Int64(1))@1 as count(*), RainToday@0 as RainToday, count(Int64(1))@1 as count(Int64(1))]
591596 │ AggregateExec: mode=FinalPartitioned, gby=[RainToday@0 as RainToday], aggr=[count(Int64(1))]
592- │ CoalesceBatchesExec: target_batch_size=8192
593- │ [Stage 1] => NetworkShuffleExec: output_partitions=4, input_tasks=2
597+ │ [Stage 1] => NetworkShuffleExec: output_partitions=4, input_tasks=2
594598 └──────────────────────────────────────────────────
595599 ┌───── Stage 1 ── Tasks: t0:[p0..p7] t1:[p0..p7]
596600 │ CoalesceBatchesExec: target_batch_size=8192
@@ -644,8 +648,7 @@ mod tests {
644648 │ SortExec: expr=[count(*)@0 ASC NULLS LAST], preserve_partitioning=[true]
645649 │ ProjectionExec: expr=[count(Int64(1))@1 as count(*), RainToday@0 as RainToday, count(Int64(1))@1 as count(Int64(1))]
646650 │ AggregateExec: mode=FinalPartitioned, gby=[RainToday@0 as RainToday], aggr=[count(Int64(1))]
647- │ CoalesceBatchesExec: target_batch_size=8192
648- │ [Stage 1] => NetworkShuffleExec: output_partitions=4, input_tasks=3
651+ │ [Stage 1] => NetworkShuffleExec: output_partitions=4, input_tasks=3
649652 └──────────────────────────────────────────────────
650653 ┌───── Stage 1 ── Tasks: t0:[p0..p3] t1:[p0..p3] t2:[p0..p3]
651654 │ CoalesceBatchesExec: target_batch_size=8192
@@ -702,8 +705,7 @@ mod tests {
702705 │ SortExec: expr=[count(*)@0 ASC NULLS LAST], preserve_partitioning=[true]
703706 │ ProjectionExec: expr=[count(Int64(1))@1 as count(*), RainToday@0 as RainToday, count(Int64(1))@1 as count(Int64(1))]
704707 │ AggregateExec: mode=FinalPartitioned, gby=[RainToday@0 as RainToday], aggr=[count(Int64(1))]
705- │ CoalesceBatchesExec: target_batch_size=8192
706- │ [Stage 1] => NetworkShuffleExec: output_partitions=4, input_tasks=3
708+ │ [Stage 1] => NetworkShuffleExec: output_partitions=4, input_tasks=3
707709 └──────────────────────────────────────────────────
708710 ┌───── Stage 1 ── Tasks: t0:[p0..p7] t1:[p0..p7] t2:[p0..p7]
709711 │ CoalesceBatchesExec: target_batch_size=8192
@@ -772,14 +774,12 @@ mod tests {
772774 │ [Stage 2] => NetworkCoalesceExec: output_partitions=8, input_tasks=2
773775 │ ProjectionExec: expr=[avg(weather.MaxTemp)@1 as MaxTemp, RainTomorrow@0 as RainTomorrow]
774776 │ AggregateExec: mode=FinalPartitioned, gby=[RainTomorrow@0 as RainTomorrow], aggr=[avg(weather.MaxTemp)]
775- │ CoalesceBatchesExec: target_batch_size=8192
776- │ [Stage 3] => NetworkShuffleExec: output_partitions=4, input_tasks=3
777+ │ [Stage 3] => NetworkShuffleExec: output_partitions=4, input_tasks=3
777778 └──────────────────────────────────────────────────
778779 ┌───── Stage 2 ── Tasks: t0:[p0..p3] t1:[p0..p3]
779780 │ ProjectionExec: expr=[avg(weather.MinTemp)@1 as MinTemp, RainTomorrow@0 as RainTomorrow]
780781 │ AggregateExec: mode=FinalPartitioned, gby=[RainTomorrow@0 as RainTomorrow], aggr=[avg(weather.MinTemp)]
781- │ CoalesceBatchesExec: target_batch_size=8192
782- │ [Stage 1] => NetworkShuffleExec: output_partitions=4, input_tasks=3
782+ │ [Stage 1] => NetworkShuffleExec: output_partitions=4, input_tasks=3
783783 └──────────────────────────────────────────────────
784784 ┌───── Stage 1 ── Tasks: t0:[p0..p7] t1:[p0..p7] t2:[p0..p7]
785785 │ CoalesceBatchesExec: target_batch_size=8192
@@ -842,8 +842,7 @@ mod tests {
842842 └──────────────────────────────────────────────────
843843 ┌───── Stage 2 ── Tasks: t0:[p0..p3] t1:[p0..p3]
844844 │ AggregateExec: mode=FinalPartitioned, gby=[RainToday@0 as RainToday, WindGustDir@1 as WindGustDir], aggr=[]
845- │ CoalesceBatchesExec: target_batch_size=8192
846- │ [Stage 1] => NetworkShuffleExec: output_partitions=4, input_tasks=3
845+ │ [Stage 1] => NetworkShuffleExec: output_partitions=4, input_tasks=3
847846 └──────────────────────────────────────────────────
848847 ┌───── Stage 1 ── Tasks: t0:[p0..p7] t1:[p0..p7] t2:[p0..p7]
849848 │ CoalesceBatchesExec: target_batch_size=8192
0 commit comments