@@ -36,7 +36,7 @@ use datafusion::execution::context::{
36
36
ExecutionConfig , ExecutionContextState , ExecutionProps ,
37
37
} ;
38
38
use datafusion:: logical_plan:: { DFSchema , Expr } ;
39
- use datafusion:: physical_plan:: aggregates:: { create_aggregate_expr , AggregateFunction } ;
39
+ use datafusion:: physical_plan:: aggregates:: AggregateFunction ;
40
40
use datafusion:: physical_plan:: expressions:: col;
41
41
use datafusion:: physical_plan:: hash_aggregate:: { AggregateMode , HashAggregateExec } ;
42
42
use datafusion:: physical_plan:: hash_join:: PartitionMode ;
@@ -45,7 +45,6 @@ use datafusion::physical_plan::planner::DefaultPhysicalPlanner;
45
45
use datafusion:: physical_plan:: window_functions:: {
46
46
BuiltInWindowFunction , WindowFunction ,
47
47
} ;
48
- use datafusion:: physical_plan:: windows:: create_window_expr;
49
48
use datafusion:: physical_plan:: windows:: WindowAggExec ;
50
49
use datafusion:: physical_plan:: {
51
50
coalesce_batches:: CoalesceBatchesExec ,
@@ -205,76 +204,27 @@ impl TryInto<Arc<dyn ExecutionPlan>> for &protobuf::PhysicalPlanNode {
205
204
)
206
205
} ) ?
207
206
. clone ( ) ;
208
-
209
207
let physical_schema: SchemaRef =
210
208
SchemaRef :: new ( ( & input_schema) . try_into ( ) ?) ;
211
-
212
- let catalog_list =
213
- Arc :: new ( MemoryCatalogList :: new ( ) ) as Arc < dyn CatalogList > ;
214
- let ctx_state = ExecutionContextState {
215
- catalog_list,
216
- scalar_functions : Default :: default ( ) ,
217
- var_provider : Default :: default ( ) ,
218
- aggregate_functions : Default :: default ( ) ,
219
- config : ExecutionConfig :: new ( ) ,
220
- execution_props : ExecutionProps :: new ( ) ,
221
- } ;
222
-
209
+ let ctx_state = ExecutionContextState :: new ( ) ;
223
210
let window_agg_expr: Vec < ( Expr , String ) > = window_agg
224
211
. window_expr
225
212
. iter ( )
226
213
. zip ( window_agg. window_expr_name . iter ( ) )
227
214
. map ( |( expr, name) | expr. try_into ( ) . map ( |expr| ( expr, name. clone ( ) ) ) )
228
215
. collect :: < Result < Vec < _ > , _ > > ( ) ?;
229
-
230
- let mut physical_window_expr = vec ! [ ] ;
231
-
232
216
let df_planner = DefaultPhysicalPlanner :: default ( ) ;
233
-
234
- for ( expr, name) in & window_agg_expr {
235
- match expr {
236
- Expr :: WindowFunction {
237
- fun,
238
- args,
239
- partition_by,
240
- order_by,
241
- window_frame,
242
- ..
243
- } => {
244
- let arg = df_planner
245
- . create_physical_expr (
246
- & args[ 0 ] ,
247
- & physical_schema,
248
- & ctx_state,
249
- )
250
- . map_err ( |e| {
251
- BallistaError :: General ( format ! ( "{:?}" , e) )
252
- } ) ?;
253
- if !partition_by. is_empty ( ) {
254
- return Err ( BallistaError :: NotImplemented ( "Window function with partition by is not yet implemented" . to_owned ( ) ) ) ;
255
- }
256
- if !order_by. is_empty ( ) {
257
- return Err ( BallistaError :: NotImplemented ( "Window function with order by is not yet implemented" . to_owned ( ) ) ) ;
258
- }
259
- if window_frame. is_some ( ) {
260
- return Err ( BallistaError :: NotImplemented ( "Window function with window frame is not yet implemented" . to_owned ( ) ) ) ;
261
- }
262
- let window_expr = create_window_expr (
263
- & fun,
264
- & [ arg] ,
265
- & physical_schema,
266
- name. to_owned ( ) ,
267
- ) ?;
268
- physical_window_expr. push ( window_expr) ;
269
- }
270
- _ => {
271
- return Err ( BallistaError :: General (
272
- "Invalid expression for WindowAggrExec" . to_string ( ) ,
273
- ) ) ;
274
- }
275
- }
276
- }
277
-
217
+ let physical_window_expr = window_agg_expr
218
+ . iter ( )
219
+ . map ( |( expr, name) | {
220
+ df_planner. create_window_expr_with_name (
221
+ expr,
222
+ name. to_string ( ) ,
223
+ & physical_schema,
224
+ & ctx_state,
225
+ )
226
+ } )
227
+ . collect :: < Result < Vec < _ > , _ > > ( ) ?;
278
228
Ok ( Arc :: new ( WindowAggExec :: try_new (
279
229
physical_window_expr,
280
230
input,
@@ -297,7 +247,6 @@ impl TryInto<Arc<dyn ExecutionPlan>> for &protobuf::PhysicalPlanNode {
297
247
AggregateMode :: FinalPartitioned
298
248
}
299
249
} ;
300
-
301
250
let group = hash_agg
302
251
. group_expr
303
252
. iter ( )
@@ -306,25 +255,13 @@ impl TryInto<Arc<dyn ExecutionPlan>> for &protobuf::PhysicalPlanNode {
306
255
compile_expr ( expr, & input. schema ( ) ) . map ( |e| ( e, name. to_string ( ) ) )
307
256
} )
308
257
. collect :: < Result < Vec < _ > , _ > > ( ) ?;
309
-
310
258
let logical_agg_expr: Vec < ( Expr , String ) > = hash_agg
311
259
. aggr_expr
312
260
. iter ( )
313
261
. zip ( hash_agg. aggr_expr_name . iter ( ) )
314
262
. map ( |( expr, name) | expr. try_into ( ) . map ( |expr| ( expr, name. clone ( ) ) ) )
315
263
. collect :: < Result < Vec < _ > , _ > > ( ) ?;
316
-
317
- let catalog_list =
318
- Arc :: new ( MemoryCatalogList :: new ( ) ) as Arc < dyn CatalogList > ;
319
- let ctx_state = ExecutionContextState {
320
- catalog_list,
321
- scalar_functions : Default :: default ( ) ,
322
- var_provider : Default :: default ( ) ,
323
- aggregate_functions : Default :: default ( ) ,
324
- config : ExecutionConfig :: new ( ) ,
325
- execution_props : ExecutionProps :: new ( ) ,
326
- } ;
327
-
264
+ let ctx_state = ExecutionContextState :: new ( ) ;
328
265
let input_schema = hash_agg
329
266
. input_schema
330
267
. as_ref ( )
@@ -336,37 +273,18 @@ impl TryInto<Arc<dyn ExecutionPlan>> for &protobuf::PhysicalPlanNode {
336
273
. clone ( ) ;
337
274
let physical_schema: SchemaRef =
338
275
SchemaRef :: new ( ( & input_schema) . try_into ( ) ?) ;
339
-
340
- let mut physical_aggr_expr = vec ! [ ] ;
341
-
342
276
let df_planner = DefaultPhysicalPlanner :: default ( ) ;
343
- for ( expr, name) in & logical_agg_expr {
344
- match expr {
345
- Expr :: AggregateFunction { fun, args, .. } => {
346
- let arg = df_planner
347
- . create_physical_expr (
348
- & args[ 0 ] ,
349
- & physical_schema,
350
- & ctx_state,
351
- )
352
- . map_err ( |e| {
353
- BallistaError :: General ( format ! ( "{:?}" , e) )
354
- } ) ?;
355
- physical_aggr_expr. push ( create_aggregate_expr (
356
- & fun,
357
- false ,
358
- & [ arg] ,
359
- & physical_schema,
360
- name. to_string ( ) ,
361
- ) ?) ;
362
- }
363
- _ => {
364
- return Err ( BallistaError :: General (
365
- "Invalid expression for HashAggregateExec" . to_string ( ) ,
366
- ) )
367
- }
368
- }
369
- }
277
+ let physical_aggr_expr = logical_agg_expr
278
+ . iter ( )
279
+ . map ( |( expr, name) | {
280
+ df_planner. create_aggregate_expr_with_name (
281
+ expr,
282
+ name. to_string ( ) ,
283
+ & physical_schema,
284
+ & ctx_state,
285
+ )
286
+ } )
287
+ . collect :: < Result < Vec < _ > , _ > > ( ) ?;
370
288
Ok ( Arc :: new ( HashAggregateExec :: try_new (
371
289
agg_mode,
372
290
group,
@@ -484,15 +402,7 @@ fn compile_expr(
484
402
schema : & Schema ,
485
403
) -> Result < Arc < dyn PhysicalExpr > , BallistaError > {
486
404
let df_planner = DefaultPhysicalPlanner :: default ( ) ;
487
- let catalog_list = Arc :: new ( MemoryCatalogList :: new ( ) ) as Arc < dyn CatalogList > ;
488
- let state = ExecutionContextState {
489
- catalog_list,
490
- scalar_functions : HashMap :: new ( ) ,
491
- var_provider : HashMap :: new ( ) ,
492
- aggregate_functions : HashMap :: new ( ) ,
493
- config : ExecutionConfig :: new ( ) ,
494
- execution_props : ExecutionProps :: new ( ) ,
495
- } ;
405
+ let state = ExecutionContextState :: new ( ) ;
496
406
let expr: Expr = expr. try_into ( ) ?;
497
407
df_planner
498
408
. create_physical_expr ( & expr, schema, & state)
0 commit comments