|
112 | 112 | * </p> |
113 | 113 | * <p> |
114 | 114 | * In order to implement aggregation logic create your class (typically named "${FunctionName}${Type}Aggregator"). |
| 115 | + * It must be placed in `org.elasticsearch.compute.aggregation` in order to be picked up by code generation. |
115 | 116 | * Annotate it with {@link org.elasticsearch.compute.ann.Aggregator} and {@link org.elasticsearch.compute.ann.GroupingAggregator} |
116 | 117 | * The first one is responsible for an entire data set aggregation, while the second one is responsible for grouping within buckets. |
117 | 118 | * </p> |
118 | 119 | * <h4>Before you start implementing it, please note that:</h4> |
119 | 120 | * <ul> |
120 | 121 | * <li>All methods must be public static</li> |
121 | 122 | * <li> |
122 | | - * init, initSingle, initGrouping could declare optional BigArrays, DriverContext arguments that are going to be injected automatically. |
| 123 | + * init/initSingle/initGrouping could have optional BigArrays, DriverContext arguments that are going to be injected automatically. |
123 | 124 | * It is also possible to declare any number of arbitrary arguments that must be provided via generated Supplier. |
124 | 125 | * </li> |
125 | 126 | * <li> |
126 | 127 | * combine, combineStates, combineIntermediate, evaluateFinal methods (see below) could be omitted and generated automatically |
127 | 128 | * when both input type I and mutable accumulator state SS and GS are primitive (DOUBLE, INT). |
128 | 129 | * </li> |
129 | 130 | * <li> |
| 131 | + * Code generation expects at least one IntermediateState field that is going to be used to keep |
| 132 | + * the serialized state of the aggregation (eg AggregatorState and GroupingAggregatorState). |
| 133 | + * It must be defined even if you rely on autogenerated implementation for the primitive types. |
130 | 134 | * </li> |
131 | | - * <li>TBD explain {@code IntermediateState}</li> |
132 | | - * <li>TBD explain special internal state `seen`</li> |
133 | 135 | * </ul> |
134 | 136 | * <h4>Aggregation expects:</h4> |
135 | 137 | * <ul> |
136 | | - * <li>type SS (a mutable state used to accumulate result of the aggregation) to be public, not inner and implements {@link org.elasticsearch.compute.aggregation.AggregatorState}</li> |
| 138 | + * <li> |
| 139 | + * type SS (a mutable state used to accumulate result of the aggregation) to be public, not inner and implements |
| 140 | + * {@link org.elasticsearch.compute.aggregation.AggregatorState} |
| 141 | + * </li> |
137 | 142 | * <li>type I (input to your aggregation function), usually primitive types and {@link org.apache.lucene.util.BytesRef}</li> |
138 | 143 | * <li>{@code SS init()} or {@code SS initSingle()} returns empty initialized aggregation state</li> |
139 | 144 | * <li>{@code void combine(SS state, I input)} or {@code SS combine(SS state, I input)} adds input entry to the aggregation state</li> |
140 | | - * <li>{@code void combineIntermediate(SS state, intermediate states)} adds serialized aggregation state to the current aggregation state (used to combine results across different nodes)</li> |
| 145 | + * <li> |
| 146 | + * {@code void combineIntermediate(SS state, intermediate states)} adds serialized aggregation state |
| 147 | + * to the current aggregation state (used to combine results across different nodes) |
| 148 | + * </li> |
141 | 149 | * <li>{@code Block evaluateFinal(SS state, DriverContext)} converts the inner state of the aggregation to the result column</li> |
142 | 150 | * </ul> |
143 | 151 | * <h4>Grouping aggregation expects:</h4> |
144 | 152 | * <ul> |
145 | | - * <li>type GS (a mutable state used to accumulate result of the grouping aggregation) to be public, not inner and implements {@link org.elasticsearch.compute.aggregation.GroupingAggregatorState}</li> |
| 153 | + * <li> |
| 154 | + * type GS (a mutable state used to accumulate result of the grouping aggregation) to be public, not inner and implements |
| 155 | + * {@link org.elasticsearch.compute.aggregation.GroupingAggregatorState} |
| 156 | + * </li> |
146 | 157 | * <li>type I (input to your aggregation function), usually primitive types and {@link org.apache.lucene.util.BytesRef}</li> |
147 | 158 | * <li>{@code GS init()} or {@code GS initGrouping()} returns empty initialized grouping aggregation state</li> |
148 | | - * <li>{@code void combine(GS state, int groupId, T input)} adds input entry to the corresponding group (bucket) of the grouping aggregation state</li> |
149 | | - * <li>{@code void combineStates(GS targetState, int targetGroupId, GS otherState, int otherGroupId)} merges other grouped aggregation state into the first one</li> |
150 | | - * <li>{@code void combineIntermediate(GS current, int groupId, intermediate states)} adds serialized aggregation state to the current grouped aggregation state (used to combine results across different nodes)</li> |
151 | | - * <li>{@code Block evaluateFinal(GS state, IntVectorSelected, DriverContext)} converts the inner state of the grouping aggregation to the result column</li> |
| 159 | + * <li> |
| 160 | + * {@code void combine(GS state, int groupId, I input)} adds input entry to the corresponding group (bucket) |
| 161 | + * of the grouping aggregation state |
| 162 | + * </li> |
| 163 | + * <li> |
| 164 | + * {@code void combineStates(GS targetState, int targetGroupId, GS otherState, int otherGroupId)} merges other grouped |
| 165 | + * aggregation state into the first one |
| 166 | + * </li> |
| 167 | + * <li> |
| 168 | + * {@code void combineIntermediate(GS current, int groupId, intermediate states)} adds serialized aggregation state |
| 169 | + * to the current grouped aggregation state (used to combine results across different nodes) |
| 170 | + * </li> |
| 171 | + * <li> |
| 172 | + * {@code Block evaluateFinal(GS state, IntVectorSelected, DriverContext)} converts the inner state |
| 173 | + * of the grouping aggregation to the result column |
| 174 | + * </li> |
152 | 175 | * </ul> |
153 | 176 | * <ol> |
154 | 177 | * <li> |
|
160 | 183 | * </p> |
161 | 184 | * </li> |
162 | 185 | * <li> |
163 | | - * The methods in the aggregator will define how it will work: |
164 | | - * <ul> |
165 | | - * <li> |
166 | | - * Adding the `type init()` method will autogenerate the code to manage the state, using your returned value |
167 | | - * as the initial value for each group. |
168 | | - * </li> |
169 | | - * <li> |
170 | | - * Adding the `type initSingle()` or `type initGrouping()` methods will use the state object you return there instead. |
171 | | - * <p> |
172 | | - * You will also have to provide `evaluateIntermediate()` and `evaluateFinal()` methods this way. |
173 | | - * </p> |
174 | | - * </li> |
175 | | - * </ul> |
176 | | - * Depending on the way you use, adapt your `combine*()` methods to receive one or other type as their first parameters. |
177 | | - * </li> |
178 | | - * <li> |
179 | | - * If it's also a {@link org.elasticsearch.compute.ann.GroupingAggregator}, you should provide the same methods as commented before: |
180 | | - * <ul> |
181 | | - * <li> |
182 | | - * Add an `initGrouping()`, unless you're using the `init()` method |
183 | | - * </li> |
184 | | - * <li> |
185 | | - * Add all the other methods, with the state parameter of the type of your `initGrouping()`. |
186 | | - * </li> |
187 | | - * </ul> |
| 186 | + * Implement (or create an empty) methods according to the above list. |
| 187 | + * Also check {@link org.elasticsearch.compute.ann.Aggregator} JavaDoc as it contains generated method usage. |
188 | 188 | * </li> |
189 | 189 | * <li> |
190 | 190 | * Make a test for your aggregator. |
|
195 | 195 | * </p> |
196 | 196 | * </li> |
197 | 197 | * <li> |
198 | | - * Check the Javadoc of the {@link org.elasticsearch.compute.ann.Aggregator} |
199 | | - * and {@link org.elasticsearch.compute.ann.GroupingAggregator} annotations. |
200 | | - * Add/Modify them on your aggregator. |
201 | | - * </li> |
202 | | - * <li> |
203 | | - * The {@link org.elasticsearch.compute.ann.Aggregator} JavaDoc explains the static methods you should add. |
204 | | - * </li> |
205 | | - * <li> |
206 | | - * After implementing the required methods (Even if they have a dummy implementation), |
207 | | - * run the CsvTests to generate some extra required classes. |
| 198 | + * Code generation is triggered when running the tests. |
| 199 | + * Run the CsvTests to generate the code. Generated code should include: |
208 | 200 | * <p> |
209 | 201 | * One of them will be the {@code AggregatorFunctionSupplier} for your aggregator. |
210 | 202 | * Find it by its name ({@code <Aggregation-name><Type>AggregatorFunctionSupplier}), |
|
0 commit comments