@@ -103,18 +103,10 @@ func (n *countPlanExpression) NewBuffer() (types.AggregationBuffer, error) {
103
103
return NewAggCountBuffer (n ), nil
104
104
}
105
105
106
- func (n * countPlanExpression ) AggType () types.AggregateFunctionType {
107
- return types .AGGREGATE_COUNT
108
- }
109
-
110
- func (n * countPlanExpression ) AggExpression () types.PlanExpression {
106
+ func (n * countPlanExpression ) FirstChildExpr () types.PlanExpression {
111
107
return n .arg
112
108
}
113
109
114
- func (n * countPlanExpression ) AggAdditionalExpr () []types.PlanExpression {
115
- return []types.PlanExpression {}
116
- }
117
-
118
110
func (n * countPlanExpression ) Type () parser.ExprDataType {
119
111
return n .returnDataType
120
112
}
@@ -172,18 +164,10 @@ func (n *countDistinctPlanExpression) NewBuffer() (types.AggregationBuffer, erro
172
164
return NewAggCountDistinctBuffer (n ), nil
173
165
}
174
166
175
- func (n * countDistinctPlanExpression ) AggType () types.AggregateFunctionType {
176
- return types .AGGREGATE_COUNT_DISTINCT
177
- }
178
-
179
- func (n * countDistinctPlanExpression ) AggExpression () types.PlanExpression {
167
+ func (n * countDistinctPlanExpression ) FirstChildExpr () types.PlanExpression {
180
168
return n .arg
181
169
}
182
170
183
- func (n * countDistinctPlanExpression ) AggAdditionalExpr () []types.PlanExpression {
184
- return []types.PlanExpression {}
185
- }
186
-
187
171
func (n * countDistinctPlanExpression ) Type () parser.ExprDataType {
188
172
return n .returnDataType
189
173
}
@@ -320,29 +304,21 @@ func newSumPlanExpression(arg types.PlanExpression, returnDataType parser.ExprDa
320
304
}
321
305
322
306
func (n * sumPlanExpression ) Evaluate (currentRow []interface {}) (interface {}, error ) {
323
- arg , ok := n .arg .( * qualifiedRefPlanExpression )
324
- if ! ok {
325
- return nil , sql3 . NewErrInternalf ( "unexpected aggregate function arg type '%T'" , n . arg )
307
+ arg , err := n .arg .Evaluate ( currentRow )
308
+ if err != nil {
309
+ return nil , err
326
310
}
327
- return currentRow [ arg . columnIndex ] , nil
311
+ return arg , nil
328
312
}
329
313
330
314
func (n * sumPlanExpression ) NewBuffer () (types.AggregationBuffer , error ) {
331
315
return NewAggSumBuffer (n ), nil
332
316
}
333
317
334
- func (n * sumPlanExpression ) AggType () types.AggregateFunctionType {
335
- return types .AGGREGATE_SUM
336
- }
337
-
338
- func (n * sumPlanExpression ) AggExpression () types.PlanExpression {
318
+ func (n * sumPlanExpression ) FirstChildExpr () types.PlanExpression {
339
319
return n .arg
340
320
}
341
321
342
- func (n * sumPlanExpression ) AggAdditionalExpr () []types.PlanExpression {
343
- return []types.PlanExpression {}
344
- }
345
-
346
322
func (n * sumPlanExpression ) Type () parser.ExprDataType {
347
323
return n .returnDataType
348
324
}
@@ -426,7 +402,7 @@ func (a *aggregateAvg) Update(ctx context.Context, row types.Row) error {
426
402
427
403
a .sum = pql .AddDecimal (thisVal , aggVal )
428
404
429
- case * parser.DataTypeInt :
405
+ case * parser.DataTypeInt , * parser. DataTypeID :
430
406
thisIVal , ok := v .(int64 )
431
407
if ! ok {
432
408
return sql3 .NewErrInternalf ("unexpected type conversion '%T'" , v )
@@ -435,15 +411,6 @@ func (a *aggregateAvg) Update(ctx context.Context, row types.Row) error {
435
411
thisVal := pql .FromInt64 (thisIVal , returnType .Scale )
436
412
a .sum = pql .AddDecimal (thisVal , aggVal )
437
413
438
- case * parser.DataTypeID :
439
- thisIVal , ok := v .(uint64 )
440
- if ! ok {
441
- return sql3 .NewErrInternalf ("unexpected type conversion '%T'" , v )
442
- }
443
-
444
- thisVal := pql .FromInt64 (int64 (thisIVal ), returnType .Scale )
445
- a .sum = pql .AddDecimal (thisVal , aggVal )
446
-
447
414
default :
448
415
return sql3 .NewErrInternalf ("unhandled aggregate expression datatype '%T'" , dataType )
449
416
}
@@ -503,29 +470,21 @@ func newAvgPlanExpression(arg types.PlanExpression, returnDataType parser.ExprDa
503
470
}
504
471
505
472
func (n * avgPlanExpression ) Evaluate (currentRow []interface {}) (interface {}, error ) {
506
- arg , ok := n .arg .( * qualifiedRefPlanExpression )
507
- if ! ok {
508
- return nil , sql3 . NewErrInternalf ( "unexpected aggregate function arg type '%T'" , n . arg )
473
+ arg , err := n .arg .Evaluate ( currentRow )
474
+ if err != nil {
475
+ return nil , err
509
476
}
510
- return currentRow [ arg . columnIndex ] , nil
477
+ return arg , nil
511
478
}
512
479
513
480
func (n * avgPlanExpression ) NewBuffer () (types.AggregationBuffer , error ) {
514
481
return NewAggAvgBuffer (n ), nil
515
482
}
516
483
517
- func (n * avgPlanExpression ) AggType () types.AggregateFunctionType {
518
- return types .AGGREGATE_AVG
519
- }
520
-
521
- func (n * avgPlanExpression ) AggExpression () types.PlanExpression {
484
+ func (n * avgPlanExpression ) FirstChildExpr () types.PlanExpression {
522
485
return n .arg
523
486
}
524
487
525
- func (n * avgPlanExpression ) AggAdditionalExpr () []types.PlanExpression {
526
- return []types.PlanExpression {}
527
- }
528
-
529
488
func (n * avgPlanExpression ) Type () parser.ExprDataType {
530
489
return n .returnDataType
531
490
}
@@ -660,29 +619,21 @@ func newMinPlanExpression(arg types.PlanExpression, returnDataType parser.ExprDa
660
619
}
661
620
662
621
func (n * minPlanExpression ) Evaluate (currentRow []interface {}) (interface {}, error ) {
663
- arg , ok := n .arg .( * qualifiedRefPlanExpression )
664
- if ! ok {
665
- return nil , sql3 . NewErrInternalf ( "unexpected aggregate function arg type '%T'" , n . arg )
622
+ arg , err := n .arg .Evaluate ( currentRow )
623
+ if err != nil {
624
+ return nil , err
666
625
}
667
- return currentRow [ arg . columnIndex ] , nil
626
+ return arg , nil
668
627
}
669
628
670
629
func (n * minPlanExpression ) NewBuffer () (types.AggregationBuffer , error ) {
671
630
return NewAggMinBuffer (n ), nil
672
631
}
673
632
674
- func (n * minPlanExpression ) AggType () types.AggregateFunctionType {
675
- return types .AGGREGATE_MIN
676
- }
677
-
678
- func (n * minPlanExpression ) AggExpression () types.PlanExpression {
633
+ func (n * minPlanExpression ) FirstChildExpr () types.PlanExpression {
679
634
return n .arg
680
635
}
681
636
682
- func (n * minPlanExpression ) AggAdditionalExpr () []types.PlanExpression {
683
- return []types.PlanExpression {}
684
- }
685
-
686
637
func (n * minPlanExpression ) Type () parser.ExprDataType {
687
638
return n .returnDataType
688
639
}
@@ -818,29 +769,21 @@ func newMaxPlanExpression(arg types.PlanExpression, returnDataType parser.ExprDa
818
769
}
819
770
820
771
func (n * maxPlanExpression ) Evaluate (currentRow []interface {}) (interface {}, error ) {
821
- arg , ok := n .arg .( * qualifiedRefPlanExpression )
822
- if ! ok {
823
- return nil , sql3 . NewErrInternalf ( "unexpected aggregate function arg type '%T'" , n . arg )
772
+ arg , err := n .arg .Evaluate ( currentRow )
773
+ if err != nil {
774
+ return nil , err
824
775
}
825
- return currentRow [ arg . columnIndex ] , nil
776
+ return arg , nil
826
777
}
827
778
828
779
func (n * maxPlanExpression ) NewBuffer () (types.AggregationBuffer , error ) {
829
780
return NewAggMaxBuffer (n ), nil
830
781
}
831
782
832
- func (n * maxPlanExpression ) AggType () types.AggregateFunctionType {
833
- return types .AGGREGATE_MAX
834
- }
835
-
836
- func (n * maxPlanExpression ) AggExpression () types.PlanExpression {
783
+ func (n * maxPlanExpression ) FirstChildExpr () types.PlanExpression {
837
784
return n .arg
838
785
}
839
786
840
- func (n * maxPlanExpression ) AggAdditionalExpr () []types.PlanExpression {
841
- return []types.PlanExpression {}
842
- }
843
-
844
787
func (n * maxPlanExpression ) Type () parser.ExprDataType {
845
788
return n .returnDataType
846
789
}
@@ -900,20 +843,10 @@ func (n *percentilePlanExpression) NewBuffer() (types.AggregationBuffer, error)
900
843
return NewAggCountBuffer (n ), nil
901
844
}
902
845
903
- func (n * percentilePlanExpression ) AggType () types.AggregateFunctionType {
904
- return types .AGGREGATE_PERCENTILE
905
- }
906
-
907
- func (n * percentilePlanExpression ) AggExpression () types.PlanExpression {
846
+ func (n * percentilePlanExpression ) FirstChildExpr () types.PlanExpression {
908
847
return n .arg
909
848
}
910
849
911
- func (n * percentilePlanExpression ) AggAdditionalExpr () []types.PlanExpression {
912
- return []types.PlanExpression {
913
- n .nthArg ,
914
- }
915
- }
916
-
917
850
func (n * percentilePlanExpression ) Type () parser.ExprDataType {
918
851
return n .returnDataType
919
852
}
0 commit comments