3636import static org .elasticsearch .compute .gen .AggregatorImplementer .capitalize ;
3737import static org .elasticsearch .compute .gen .Methods .findMethod ;
3838import static org .elasticsearch .compute .gen .Methods .findRequiredMethod ;
39+ import static org .elasticsearch .compute .gen .Methods .requireAnyArgs ;
40+ import static org .elasticsearch .compute .gen .Methods .requireName ;
41+ import static org .elasticsearch .compute .gen .Methods .requirePrimitiveOrImplements ;
42+ import static org .elasticsearch .compute .gen .Methods .requireStaticMethod ;
3943import static org .elasticsearch .compute .gen .Methods .vectorAccessorName ;
4044import static org .elasticsearch .compute .gen .Types .BIG_ARRAYS ;
4145import static org .elasticsearch .compute .gen .Types .BLOCK_ARRAY ;
@@ -73,7 +77,6 @@ public class GroupingAggregatorImplementer {
7377 private final ExecutableElement combine ;
7478 private final ExecutableElement combineStates ;
7579 private final ExecutableElement evaluateFinal ;
76- private final ExecutableElement combineIntermediate ;
7780 private final List <Parameter > createParameters ;
7881 private final ClassName implementation ;
7982 private final List <AggregatorImplementer .IntermediateStateDesc > intermediateState ;
@@ -92,9 +95,16 @@ public GroupingAggregatorImplementer(
9295 this .declarationType = declarationType ;
9396 this .warnExceptions = warnExceptions ;
9497
95- this .init = findRequiredMethod (declarationType , new String [] { "init" , "initGrouping" }, e -> true );
98+ this .init = requireStaticMethod (
99+ declarationType ,
100+ // This should be more restrictive and require org.elasticsearch.compute.aggregation.AggregatorState
101+ requirePrimitiveOrImplements (elements , Types .RELEASABLE ),
102+ requireName ("init" , "initGrouping" ),
103+ requireAnyArgs ("<arbitrary init arguments>" )
104+ );
96105 this .aggState = AggregationState .create (elements , init .getReturnType (), warnExceptions .isEmpty () == false , true );
97106
107+ // TODO optional timestamp
98108 this .combine = findRequiredMethod (declarationType , new String [] { "combine" }, e -> {
99109 if (e .getParameters ().size () == 0 ) {
100110 return false ;
@@ -106,7 +116,6 @@ public GroupingAggregatorImplementer(
106116 this .aggParam = AggregationParameter .create (combine .getParameters ().get (combine .getParameters ().size () - 1 ).asType ());
107117
108118 this .combineStates = findMethod (declarationType , "combineStates" );
109- this .combineIntermediate = findMethod (declarationType , "combineIntermediate" );
110119 this .evaluateFinal = findMethod (declarationType , "evaluateFinal" );
111120 this .createParameters = init .getParameters ()
112121 .stream ()
@@ -557,6 +566,7 @@ private MethodSpec addIntermediateInput() {
557566 });
558567 builder .endControlFlow ();
559568 } else {
569+ // TODO combineIntermediate with optional block parameter
560570 builder .addStatement ("$T.combineIntermediate(state, groupId, " + intermediateStateRowAccess () + ")" , declarationType );
561571 }
562572 builder .endControlFlow ();
0 commit comments