diff --git a/x-pack/plugin/esql/compute/ann/src/main/java/org/elasticsearch/compute/ann/Aggregator.java b/x-pack/plugin/esql/compute/ann/src/main/java/org/elasticsearch/compute/ann/Aggregator.java index 794baf1759204..54d57626707cd 100644 --- a/x-pack/plugin/esql/compute/ann/src/main/java/org/elasticsearch/compute/ann/Aggregator.java +++ b/x-pack/plugin/esql/compute/ann/src/main/java/org/elasticsearch/compute/ann/Aggregator.java @@ -39,11 +39,8 @@ *

* The generation code also looks for the optional methods {@code combineIntermediate} * and {@code evaluateFinal} which are used to combine intermediate states and - * produce the final output. If the first is missing then the generated code will - * call the {@code combine} method to combine intermediate states. If the second - * is missing the generated code will make a block containing the primitive from - * the state. If either of those don't have sensible interpretations then the code - * generation code will throw an error, aborting the compilation. + * produce the final output. Please note, those are auto-generated when aggregating + * primitive types such as boolean, int, long, float, double. *

*/ @Target(ElementType.TYPE) diff --git a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/aggregate/package-info.java b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/aggregate/package-info.java index 9f08401a42dd1..4115386882207 100644 --- a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/aggregate/package-info.java +++ b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/aggregate/package-info.java @@ -85,10 +85,6 @@ * To introduce your aggregation to the engine: * * @@ -105,8 +101,84 @@ * *

Creating aggregators for your function

*

- * Aggregators contain the core logic of your aggregation. That is, how to combine values, what to store, how to process data, etc. + * Aggregators contain the core logic of how to combine values, what to store, how to process data, etc. + * Currently, we rely on code generation (per aggregation per type) in order to implement such functionality. + * This approach was picked for performance reasons (namely to avoid virtual method calls and boxing types). + * As a result we could not rely on interfaces implementation and generics. + *

+ *

+ * In order to implement aggregation logic create your class (typically named "${FunctionName}${Type}Aggregator"). + * It must be placed in `org.elasticsearch.compute.aggregation` in order to be picked up by code generation. + * Annotate it with {@link org.elasticsearch.compute.ann.Aggregator} and {@link org.elasticsearch.compute.ann.GroupingAggregator} + * The first one is responsible for an entire data set aggregation, while the second one is responsible for grouping within buckets. *

+ *

Before you start implementing it, please note that:

+ * + *

Aggregation expects:

+ * + *

Grouping aggregation expects:

+ * *
    *
  1. * Copy an existing aggregator to use as a base. You'll usually make one per type. Check other classes to see the naming pattern. @@ -117,31 +189,8 @@ *

    *
  2. *
  3. - * The methods in the aggregator will define how it will work: - * - * Depending on the way you use, adapt your `combine*()` methods to receive one or other type as their first parameters. - *
  4. - *
  5. - * If it's also a {@link org.elasticsearch.compute.ann.GroupingAggregator}, you should provide the same methods as commented before: - * + * Implement (or create an empty) methods according to the above list. + * Also check {@link org.elasticsearch.compute.ann.Aggregator} JavaDoc as it contains generated method usage. *
  6. *
  7. * Make a test for your aggregator. @@ -152,16 +201,8 @@ *

    *
  8. *
  9. - * Check the Javadoc of the {@link org.elasticsearch.compute.ann.Aggregator} - * and {@link org.elasticsearch.compute.ann.GroupingAggregator} annotations. - * Add/Modify them on your aggregator. - *
  10. - *
  11. - * The {@link org.elasticsearch.compute.ann.Aggregator} JavaDoc explains the static methods you should add. - *
  12. - *
  13. - * After implementing the required methods (Even if they have a dummy implementation), - * run the CsvTests to generate some extra required classes. + * Code generation is triggered when running the tests. + * Run the CsvTests to generate the code. Generated code should include: *

    * One of them will be the {@code AggregatorFunctionSupplier} for your aggregator. * Find it by its name ({@code AggregatorFunctionSupplier}),