1919
2020use std:: sync:: Arc ;
2121
22- use arrow:: array:: Int64Array ;
22+ use arrow:: array:: { ArrayRef , Int64Array } ;
2323use arrow:: datatypes:: { DataType , Field , Schema } ;
2424use arrow:: record_batch:: RecordBatch ;
2525use datafusion_common:: test_util:: batches_to_string;
@@ -38,7 +38,7 @@ use datafusion_physical_expr::expressions::col;
3838use datafusion_physical_expr_common:: sort_expr:: LexOrdering ;
3939use futures:: StreamExt ;
4040
41- use super :: { AggregateExec , AggregateMode , GroupClusteringMode , PhysicalGroupBy } ;
41+ use super :: { AggregateExec , AggregateMode , PhysicalGroupBy } ;
4242use crate :: ExecutionPlan ;
4343use crate :: test:: TestMemoryExec ;
4444
@@ -48,16 +48,6 @@ pub(super) fn full_batches() -> Vec<Vec<Vec<i64>>> {
4848 vec ! [ vec![ ( 0 ..=256 ) . collect( ) ] , vec![ ( 256 ..=512 ) . collect( ) ] ]
4949}
5050
51- /// Key columns `(a, b)` of batches sorted on `a` only, with 256 groups for each
52- /// `a` spread over two batches. The groups of one `a` complete together when the
53- /// next `a` starts.
54- pub ( super ) fn partial_batches ( ) -> Vec < Vec < Vec < i64 > > > {
55- [ 0 , 0 , 1 , 1 , 2 , 2 ]
56- . into_iter ( )
57- . map ( |a| vec ! [ vec![ a; 256 ] , ( 0 ..256 ) . collect( ) ] )
58- . collect ( )
59- }
60-
6151/// Key column of two batches that hold the same single key, so no group
6252/// completes before the input ends.
6353pub ( super ) fn single_key_batches ( ) -> Vec < Vec < Vec < i64 > > > {
@@ -75,7 +65,7 @@ pub(super) fn sum_over_sorted_input(
7565 mode : AggregateMode ,
7666 keys : & [ & str ] ,
7767 batches : Vec < Vec < Vec < i64 > > > ,
78- ) -> Result < ( Arc < dyn ExecutionPlan > , GroupClusteringMode ) > {
68+ ) -> Result < AggregateExec > {
7969 let fields = keys
8070 . iter ( )
8171 . chain ( & [ "v" ] )
@@ -112,12 +102,11 @@ pub(super) fn sum_over_sorted_input(
112102 let batches = batches
113103 . into_iter ( )
114104 . map ( |columns| {
115- let v = columns. last ( ) . cloned ( ) . unwrap_or_default ( ) ;
116- let columns = columns
105+ let mut columns = columns
117106 . into_iter ( )
118- . chain ( [ v ] )
119- . map ( |values| Arc :: new ( Int64Array :: from ( values ) ) as _ )
120- . collect ( ) ;
107+ . map ( |values| Arc :: new ( Int64Array :: from ( values ) ) as ArrayRef )
108+ . collect :: < Vec < _ > > ( ) ;
109+ columns . push ( Arc :: clone ( columns . last ( ) . unwrap ( ) ) ) ;
121110 RecordBatch :: try_new ( Arc :: clone ( & input_schema) , columns)
122111 } )
123112 . collect :: < Result < Vec < _ > , _ > > ( ) ?;
@@ -126,23 +115,21 @@ pub(super) fn sum_over_sorted_input(
126115 . unwrap ( ) ;
127116 let input = TestMemoryExec :: try_new ( & [ batches] , Arc :: clone ( & input_schema) , None ) ?
128117 . try_with_sort_information ( vec ! [ ordering] ) ?;
129- let aggregate = AggregateExec :: try_new (
118+ AggregateExec :: try_new (
130119 mode,
131120 group_by,
132121 aggregate_exprs,
133122 vec ! [ None ] ,
134123 Arc :: new ( TestMemoryExec :: update_cache ( & Arc :: new ( input) ) ) ,
135124 schema,
136- ) ?;
137- let group_clustering_mode = aggregate. group_clustering_mode ( ) . clone ( ) ;
138- Ok ( ( Arc :: new ( aggregate) , group_clustering_mode) )
125+ )
139126}
140127
141128/// Executes partition 0 of `plan` on the clustered aggregate path, with `pool`
142129/// and temporary files disabled. Returns the output and the most memory the
143130/// plan held when it handed off a batch, including its initial reservation.
144- pub ( super ) async fn collect_with_held_memory (
145- plan : & Arc < dyn ExecutionPlan > ,
131+ async fn collect_with_held_memory (
132+ plan : & AggregateExec ,
146133 pool : Arc < dyn MemoryPool > ,
147134) -> Result < ( Vec < RecordBatch > , usize ) > {
148135 let context = Arc :: new (
@@ -174,7 +161,7 @@ pub(super) async fn collect_with_held_memory(
174161}
175162
176163/// Returns the memory `plan` holds when handing off output without a limit.
177- pub ( super ) async fn held_memory ( plan : & Arc < dyn ExecutionPlan > ) -> Result < usize > {
164+ pub ( super ) async fn held_memory ( plan : & AggregateExec ) -> Result < usize > {
178165 let ( _, held) =
179166 collect_with_held_memory ( plan, Arc :: new ( UnboundedMemoryPool :: default ( ) ) ) . await ?;
180167 Ok ( held)
@@ -184,7 +171,7 @@ pub(super) async fn held_memory(plan: &Arc<dyn ExecutionPlan>) -> Result<usize>
184171/// with only the active groups, but not the table before completed groups are
185172/// emitted. The result must not change.
186173pub ( super ) async fn assert_completed_groups_emitted_under_limit (
187- plan : & Arc < dyn ExecutionPlan > ,
174+ plan : & AggregateExec ,
188175) -> Result < ( ) > {
189176 let ( expected, held) =
190177 collect_with_held_memory ( plan, Arc :: new ( UnboundedMemoryPool :: default ( ) ) ) . await ?;
@@ -197,7 +184,7 @@ pub(super) async fn assert_completed_groups_emitted_under_limit(
197184/// Runs `plan` under `limit`, where emitting completed groups cannot bring the
198185/// table under the limit, so the refused reservation must be returned.
199186pub ( super ) async fn assert_resources_exhausted_under_limit (
200- plan : & Arc < dyn ExecutionPlan > ,
187+ plan : & AggregateExec ,
201188 limit : usize ,
202189) -> Result < ( ) > {
203190 let result =
0 commit comments