From e319dab2c152202f4922d4cf8b5f42084ad27b0e Mon Sep 17 00:00:00 2001 From: Przemyslaw Witek Date: Thu, 25 Sep 2025 14:24:03 +0200 Subject: [PATCH 01/16] Support extra field in TOP function --- .../_snippets/functions/parameters/top.md | 3 + .../esql/_snippets/functions/types/top.md | 36 +- .../esql/images/functions/top.svg | 2 +- x-pack/plugin/esql/compute/build.gradle | 210 ++++++++- .../aggregation/TopBooleanAggregator.java | 5 +- .../aggregation/TopBytesRefAggregator.java | 5 +- .../aggregation/TopDoubleAggregator.java | 5 +- .../TopDoubleDoubleAggregator.java | 140 ++++++ .../aggregation/TopDoubleFloatAggregator.java | 140 ++++++ .../aggregation/TopDoubleIntAggregator.java | 140 ++++++ .../aggregation/TopDoubleLongAggregator.java | 140 ++++++ .../aggregation/TopFloatAggregator.java | 5 +- .../aggregation/TopFloatDoubleAggregator.java | 140 ++++++ .../aggregation/TopFloatFloatAggregator.java | 140 ++++++ .../aggregation/TopFloatIntAggregator.java | 140 ++++++ .../aggregation/TopFloatLongAggregator.java | 140 ++++++ .../compute/aggregation/TopIntAggregator.java | 5 +- .../aggregation/TopIntDoubleAggregator.java | 140 ++++++ .../aggregation/TopIntFloatAggregator.java | 140 ++++++ .../aggregation/TopIntIntAggregator.java | 140 ++++++ .../aggregation/TopIntLongAggregator.java | 140 ++++++ .../compute/aggregation/TopIpAggregator.java | 5 +- .../aggregation/TopLongAggregator.java | 5 +- .../aggregation/TopLongDoubleAggregator.java | 140 ++++++ .../aggregation/TopLongFloatAggregator.java | 140 ++++++ .../aggregation/TopLongIntAggregator.java | 140 ++++++ .../aggregation/TopLongLongAggregator.java | 140 ++++++ .../compute/data/sort/DoubleBucketedSort.java | 27 +- .../data/sort/DoubleDoubleBucketedSort.java | 406 ++++++++++++++++++ .../data/sort/DoubleFloatBucketedSort.java | 406 ++++++++++++++++++ .../data/sort/DoubleIntBucketedSort.java | 406 ++++++++++++++++++ .../data/sort/DoubleLongBucketedSort.java | 406 ++++++++++++++++++ .../compute/data/sort/FloatBucketedSort.java | 27 +- .../data/sort/FloatDoubleBucketedSort.java | 406 ++++++++++++++++++ .../data/sort/FloatFloatBucketedSort.java | 406 ++++++++++++++++++ .../data/sort/FloatIntBucketedSort.java | 406 ++++++++++++++++++ .../data/sort/FloatLongBucketedSort.java | 406 ++++++++++++++++++ .../compute/data/sort/IntBucketedSort.java | 27 +- .../data/sort/IntDoubleBucketedSort.java | 406 ++++++++++++++++++ .../data/sort/IntFloatBucketedSort.java | 406 ++++++++++++++++++ .../compute/data/sort/IntIntBucketedSort.java | 406 ++++++++++++++++++ .../data/sort/IntLongBucketedSort.java | 406 ++++++++++++++++++ .../compute/data/sort/LongBucketedSort.java | 27 +- .../data/sort/LongDoubleBucketedSort.java | 406 ++++++++++++++++++ .../data/sort/LongFloatBucketedSort.java | 406 ++++++++++++++++++ .../data/sort/LongIntBucketedSort.java | 406 ++++++++++++++++++ .../data/sort/LongLongBucketedSort.java | 405 +++++++++++++++++ .../TopDoubleDoubleAggregatorFunction.java | 213 +++++++++ ...oubleDoubleAggregatorFunctionSupplier.java | 53 +++ ...oubleDoubleGroupingAggregatorFunction.java | 395 +++++++++++++++++ .../TopDoubleFloatAggregatorFunction.java | 215 ++++++++++ ...DoubleFloatAggregatorFunctionSupplier.java | 53 +++ ...DoubleFloatGroupingAggregatorFunction.java | 397 +++++++++++++++++ .../TopDoubleIntAggregatorFunction.java | 215 ++++++++++ ...opDoubleIntAggregatorFunctionSupplier.java | 53 +++ ...opDoubleIntGroupingAggregatorFunction.java | 396 +++++++++++++++++ .../TopDoubleLongAggregatorFunction.java | 215 ++++++++++ ...pDoubleLongAggregatorFunctionSupplier.java | 53 +++ ...pDoubleLongGroupingAggregatorFunction.java | 397 +++++++++++++++++ .../TopFloatDoubleAggregatorFunction.java | 215 ++++++++++ ...FloatDoubleAggregatorFunctionSupplier.java | 53 +++ ...FloatDoubleGroupingAggregatorFunction.java | 397 +++++++++++++++++ .../TopFloatFloatAggregatorFunction.java | 213 +++++++++ ...pFloatFloatAggregatorFunctionSupplier.java | 53 +++ ...pFloatFloatGroupingAggregatorFunction.java | 395 +++++++++++++++++ .../TopFloatIntAggregatorFunction.java | 215 ++++++++++ ...TopFloatIntAggregatorFunctionSupplier.java | 53 +++ ...TopFloatIntGroupingAggregatorFunction.java | 396 +++++++++++++++++ .../TopFloatLongAggregatorFunction.java | 215 ++++++++++ ...opFloatLongAggregatorFunctionSupplier.java | 53 +++ ...opFloatLongGroupingAggregatorFunction.java | 397 +++++++++++++++++ .../TopIntDoubleAggregatorFunction.java | 215 ++++++++++ ...opIntDoubleAggregatorFunctionSupplier.java | 53 +++ ...opIntDoubleGroupingAggregatorFunction.java | 396 +++++++++++++++++ .../TopIntFloatAggregatorFunction.java | 215 ++++++++++ ...TopIntFloatAggregatorFunctionSupplier.java | 53 +++ ...TopIntFloatGroupingAggregatorFunction.java | 396 +++++++++++++++++ .../TopIntIntAggregatorFunction.java | 213 +++++++++ .../TopIntIntAggregatorFunctionSupplier.java | 53 +++ .../TopIntIntGroupingAggregatorFunction.java | 394 +++++++++++++++++ .../TopIntLongAggregatorFunction.java | 215 ++++++++++ .../TopIntLongAggregatorFunctionSupplier.java | 53 +++ .../TopIntLongGroupingAggregatorFunction.java | 396 +++++++++++++++++ .../TopLongDoubleAggregatorFunction.java | 215 ++++++++++ ...pLongDoubleAggregatorFunctionSupplier.java | 53 +++ ...pLongDoubleGroupingAggregatorFunction.java | 397 +++++++++++++++++ .../TopLongFloatAggregatorFunction.java | 215 ++++++++++ ...opLongFloatAggregatorFunctionSupplier.java | 53 +++ ...opLongFloatGroupingAggregatorFunction.java | 397 +++++++++++++++++ .../TopLongIntAggregatorFunction.java | 215 ++++++++++ .../TopLongIntAggregatorFunctionSupplier.java | 53 +++ .../TopLongIntGroupingAggregatorFunction.java | 396 +++++++++++++++++ .../TopLongLongAggregatorFunction.java | 213 +++++++++ ...TopLongLongAggregatorFunctionSupplier.java | 53 +++ ...TopLongLongGroupingAggregatorFunction.java | 395 +++++++++++++++++ .../aggregation/X-TopAggregator.java.st | 62 ++- .../compute/data/sort/X-BucketedSort.java.st | 149 ++++++- .../src/main/resources/stats_top_map.csv-spec | 53 +++ .../esql/EsqlIllegalArgumentException.java | 4 + .../xpack/esql/action/EsqlCapabilities.java | 5 + .../function/EsqlFunctionRegistry.java | 2 +- .../expression/function/aggregate/Top.java | 143 ++++-- .../aggregate/TopSerializationTests.java | 9 +- .../function/aggregate/TopTests.java | 2 +- .../logical/AggregateSerializationTests.java | 16 +- .../esql/tree/EsqlNodeSubclassTests.java | 2 +- 106 files changed, 20023 insertions(+), 170 deletions(-) create mode 100644 x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopDoubleDoubleAggregator.java create mode 100644 x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopDoubleFloatAggregator.java create mode 100644 x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopDoubleIntAggregator.java create mode 100644 x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopDoubleLongAggregator.java create mode 100644 x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopFloatDoubleAggregator.java create mode 100644 x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopFloatFloatAggregator.java create mode 100644 x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopFloatIntAggregator.java create mode 100644 x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopFloatLongAggregator.java create mode 100644 x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopIntDoubleAggregator.java create mode 100644 x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopIntFloatAggregator.java create mode 100644 x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopIntIntAggregator.java create mode 100644 x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopIntLongAggregator.java create mode 100644 x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopLongDoubleAggregator.java create mode 100644 x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopLongFloatAggregator.java create mode 100644 x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopLongIntAggregator.java create mode 100644 x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopLongLongAggregator.java create mode 100644 x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleDoubleBucketedSort.java create mode 100644 x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleFloatBucketedSort.java create mode 100644 x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleIntBucketedSort.java create mode 100644 x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleLongBucketedSort.java create mode 100644 x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/FloatDoubleBucketedSort.java create mode 100644 x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/FloatFloatBucketedSort.java create mode 100644 x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/FloatIntBucketedSort.java create mode 100644 x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/FloatLongBucketedSort.java create mode 100644 x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/IntDoubleBucketedSort.java create mode 100644 x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/IntFloatBucketedSort.java create mode 100644 x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/IntIntBucketedSort.java create mode 100644 x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/IntLongBucketedSort.java create mode 100644 x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/LongDoubleBucketedSort.java create mode 100644 x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/LongFloatBucketedSort.java create mode 100644 x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/LongIntBucketedSort.java create mode 100644 x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/LongLongBucketedSort.java create mode 100644 x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleDoubleAggregatorFunction.java create mode 100644 x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleDoubleAggregatorFunctionSupplier.java create mode 100644 x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleDoubleGroupingAggregatorFunction.java create mode 100644 x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleFloatAggregatorFunction.java create mode 100644 x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleFloatAggregatorFunctionSupplier.java create mode 100644 x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleFloatGroupingAggregatorFunction.java create mode 100644 x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleIntAggregatorFunction.java create mode 100644 x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleIntAggregatorFunctionSupplier.java create mode 100644 x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleIntGroupingAggregatorFunction.java create mode 100644 x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleLongAggregatorFunction.java create mode 100644 x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleLongAggregatorFunctionSupplier.java create mode 100644 x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleLongGroupingAggregatorFunction.java create mode 100644 x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatDoubleAggregatorFunction.java create mode 100644 x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatDoubleAggregatorFunctionSupplier.java create mode 100644 x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatDoubleGroupingAggregatorFunction.java create mode 100644 x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatFloatAggregatorFunction.java create mode 100644 x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatFloatAggregatorFunctionSupplier.java create mode 100644 x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatFloatGroupingAggregatorFunction.java create mode 100644 x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatIntAggregatorFunction.java create mode 100644 x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatIntAggregatorFunctionSupplier.java create mode 100644 x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatIntGroupingAggregatorFunction.java create mode 100644 x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatLongAggregatorFunction.java create mode 100644 x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatLongAggregatorFunctionSupplier.java create mode 100644 x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatLongGroupingAggregatorFunction.java create mode 100644 x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntDoubleAggregatorFunction.java create mode 100644 x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntDoubleAggregatorFunctionSupplier.java create mode 100644 x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntDoubleGroupingAggregatorFunction.java create mode 100644 x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntFloatAggregatorFunction.java create mode 100644 x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntFloatAggregatorFunctionSupplier.java create mode 100644 x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntFloatGroupingAggregatorFunction.java create mode 100644 x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntIntAggregatorFunction.java create mode 100644 x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntIntAggregatorFunctionSupplier.java create mode 100644 x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntIntGroupingAggregatorFunction.java create mode 100644 x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntLongAggregatorFunction.java create mode 100644 x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntLongAggregatorFunctionSupplier.java create mode 100644 x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntLongGroupingAggregatorFunction.java create mode 100644 x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongDoubleAggregatorFunction.java create mode 100644 x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongDoubleAggregatorFunctionSupplier.java create mode 100644 x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongDoubleGroupingAggregatorFunction.java create mode 100644 x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongFloatAggregatorFunction.java create mode 100644 x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongFloatAggregatorFunctionSupplier.java create mode 100644 x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongFloatGroupingAggregatorFunction.java create mode 100644 x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongIntAggregatorFunction.java create mode 100644 x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongIntAggregatorFunctionSupplier.java create mode 100644 x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongIntGroupingAggregatorFunction.java create mode 100644 x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongLongAggregatorFunction.java create mode 100644 x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongLongAggregatorFunctionSupplier.java create mode 100644 x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongLongGroupingAggregatorFunction.java create mode 100644 x-pack/plugin/esql/qa/testFixtures/src/main/resources/stats_top_map.csv-spec diff --git a/docs/reference/query-languages/esql/_snippets/functions/parameters/top.md b/docs/reference/query-languages/esql/_snippets/functions/parameters/top.md index 057bd91855a1a..86eb630c410b4 100644 --- a/docs/reference/query-languages/esql/_snippets/functions/parameters/top.md +++ b/docs/reference/query-languages/esql/_snippets/functions/parameters/top.md @@ -11,3 +11,6 @@ `order` : The order to calculate the top values. Either `asc` or `desc`, and defaults to `asc` if omitted. +`mapToField` +: The extra field that the result of the TOP call is mapped to. + diff --git a/docs/reference/query-languages/esql/_snippets/functions/types/top.md b/docs/reference/query-languages/esql/_snippets/functions/types/top.md index 559a779cd1d9d..15e7642227cb9 100644 --- a/docs/reference/query-languages/esql/_snippets/functions/types/top.md +++ b/docs/reference/query-languages/esql/_snippets/functions/types/top.md @@ -2,22 +2,22 @@ **Supported types** -| field | limit | order | result | -| --- | --- | --- | --- | -| boolean | integer | keyword | boolean | -| boolean | integer | | boolean | -| date | integer | keyword | date | -| date | integer | | date | -| double | integer | keyword | double | -| double | integer | | double | -| integer | integer | keyword | integer | -| integer | integer | | integer | -| ip | integer | keyword | ip | -| ip | integer | | ip | -| keyword | integer | keyword | keyword | -| keyword | integer | | keyword | -| long | integer | keyword | long | -| long | integer | | long | -| text | integer | keyword | keyword | -| text | integer | | keyword | +| field | limit | order | mapToField | result | +| --- | --- | --- | --- | --- | +| boolean | integer | keyword | | boolean | +| boolean | integer | | | boolean | +| date | integer | keyword | | date | +| date | integer | | | date | +| double | integer | keyword | | double | +| double | integer | | | double | +| integer | integer | keyword | | integer | +| integer | integer | | | integer | +| ip | integer | keyword | | ip | +| ip | integer | | | ip | +| keyword | integer | keyword | | keyword | +| keyword | integer | | | keyword | +| long | integer | keyword | | long | +| long | integer | | | long | +| text | integer | keyword | | keyword | +| text | integer | | | keyword | diff --git a/docs/reference/query-languages/esql/images/functions/top.svg b/docs/reference/query-languages/esql/images/functions/top.svg index 947890a49f31c..da1fb07dbc3ab 100644 --- a/docs/reference/query-languages/esql/images/functions/top.svg +++ b/docs/reference/query-languages/esql/images/functions/top.svg @@ -1 +1 @@ -TOP(field,limit,order) \ No newline at end of file +TOP(field,limit,order,mapToField) \ No newline at end of file diff --git a/x-pack/plugin/esql/compute/build.gradle b/x-pack/plugin/esql/compute/build.gradle index bd4bb33873be5..5d2fd550b2a70 100644 --- a/x-pack/plugin/esql/compute/build.gradle +++ b/x-pack/plugin/esql/compute/build.gradle @@ -51,7 +51,7 @@ spotless { * Generated files go here. */ toggleOffOn('begin generated imports', 'end generated imports') - targetExclude "src/main/generated/**/*.java" + targetExclude "src/main/generated*/**/*.java" } } @@ -81,6 +81,26 @@ def prop(Name, Type, type, Wrapper, TYPE, BYTES, Array, Hash) { ] } +def propWithoutExtra(prop1) { + def res = [ "hasExtra": "" ] + for ( e in prop1 ) { + res.put(e.key, e.value) + res.put("Extra" + e.key, "") + } + return res +} + +def propWithExtra(prop1, prop2) { + def res = [ "hasExtra": "true" ] + for ( e in prop1 ) { + res.put(e.key, e.value) + } + for ( e in prop2 ) { + res.put("Extra" + e.key, e.value) + } + return res +} + def addOccurrence(props, Occurrence) { def newProps = props.collectEntries { [(it.key): it.value] } newProps["Occurrence"] = Occurrence @@ -723,41 +743,127 @@ tasks.named('stringTemplates').configure { } File topAggregatorInputFile = new File("${projectDir}/src/main/java/org/elasticsearch/compute/aggregation/X-TopAggregator.java.st") + // Simple TOP when the sort field and the output field are the same field template { - it.properties = intProperties + it.properties = propWithoutExtra(intProperties) it.inputFile = topAggregatorInputFile it.outputFile = "org/elasticsearch/compute/aggregation/TopIntAggregator.java" } template { - it.properties = longProperties + it.properties = propWithoutExtra(longProperties) it.inputFile = topAggregatorInputFile it.outputFile = "org/elasticsearch/compute/aggregation/TopLongAggregator.java" } template { - it.properties = floatProperties + it.properties = propWithoutExtra(floatProperties) it.inputFile = topAggregatorInputFile it.outputFile = "org/elasticsearch/compute/aggregation/TopFloatAggregator.java" } template { - it.properties = doubleProperties + it.properties = propWithoutExtra(doubleProperties) it.inputFile = topAggregatorInputFile it.outputFile = "org/elasticsearch/compute/aggregation/TopDoubleAggregator.java" } template { - it.properties = booleanProperties + it.properties = propWithoutExtra(booleanProperties) it.inputFile = topAggregatorInputFile it.outputFile = "org/elasticsearch/compute/aggregation/TopBooleanAggregator.java" } template { - it.properties = bytesRefProperties + it.properties = propWithoutExtra(bytesRefProperties) it.inputFile = topAggregatorInputFile it.outputFile = "org/elasticsearch/compute/aggregation/TopBytesRefAggregator.java" } template { - it.properties = ipProperties + it.properties = propWithoutExtra(ipProperties) it.inputFile = topAggregatorInputFile it.outputFile = "org/elasticsearch/compute/aggregation/TopIpAggregator.java" } + // TOP when the sort field and the output (extra) field are *different* fields + // 16 (4x4) combinations are listed here + template { + it.properties = propWithExtra(intProperties, intProperties) + it.inputFile = topAggregatorInputFile + it.outputFile = "org/elasticsearch/compute/aggregation/TopIntIntAggregator.java" + } + template { + it.properties = propWithExtra(intProperties, longProperties) + it.inputFile = topAggregatorInputFile + it.outputFile = "org/elasticsearch/compute/aggregation/TopIntLongAggregator.java" + } + template { + it.properties = propWithExtra(intProperties, floatProperties) + it.inputFile = topAggregatorInputFile + it.outputFile = "org/elasticsearch/compute/aggregation/TopIntFloatAggregator.java" + } + template { + it.properties = propWithExtra(intProperties, doubleProperties) + it.inputFile = topAggregatorInputFile + it.outputFile = "org/elasticsearch/compute/aggregation/TopIntDoubleAggregator.java" + } + + template { + it.properties = propWithExtra(longProperties, intProperties) + it.inputFile = topAggregatorInputFile + it.outputFile = "org/elasticsearch/compute/aggregation/TopLongIntAggregator.java" + } + template { + it.properties = propWithExtra(longProperties, longProperties) + it.inputFile = topAggregatorInputFile + it.outputFile = "org/elasticsearch/compute/aggregation/TopLongLongAggregator.java" + } + template { + it.properties = propWithExtra(longProperties, floatProperties) + it.inputFile = topAggregatorInputFile + it.outputFile = "org/elasticsearch/compute/aggregation/TopLongFloatAggregator.java" + } + template { + it.properties = propWithExtra(longProperties, doubleProperties) + it.inputFile = topAggregatorInputFile + it.outputFile = "org/elasticsearch/compute/aggregation/TopLongDoubleAggregator.java" + } + + template { + it.properties = propWithExtra(floatProperties, intProperties) + it.inputFile = topAggregatorInputFile + it.outputFile = "org/elasticsearch/compute/aggregation/TopFloatIntAggregator.java" + } + template { + it.properties = propWithExtra(floatProperties, longProperties) + it.inputFile = topAggregatorInputFile + it.outputFile = "org/elasticsearch/compute/aggregation/TopFloatLongAggregator.java" + } + template { + it.properties = propWithExtra(floatProperties, floatProperties) + it.inputFile = topAggregatorInputFile + it.outputFile = "org/elasticsearch/compute/aggregation/TopFloatFloatAggregator.java" + } + template { + it.properties = propWithExtra(floatProperties, doubleProperties) + it.inputFile = topAggregatorInputFile + it.outputFile = "org/elasticsearch/compute/aggregation/TopFloatDoubleAggregator.java" + } + + template { + it.properties = propWithExtra(doubleProperties, intProperties) + it.inputFile = topAggregatorInputFile + it.outputFile = "org/elasticsearch/compute/aggregation/TopDoubleIntAggregator.java" + } + template { + it.properties = propWithExtra(doubleProperties, longProperties) + it.inputFile = topAggregatorInputFile + it.outputFile = "org/elasticsearch/compute/aggregation/TopDoubleLongAggregator.java" + } + template { + it.properties = propWithExtra(doubleProperties, floatProperties) + it.inputFile = topAggregatorInputFile + it.outputFile = "org/elasticsearch/compute/aggregation/TopDoubleFloatAggregator.java" + } + template { + it.properties = propWithExtra(doubleProperties, doubleProperties) + it.inputFile = topAggregatorInputFile + it.outputFile = "org/elasticsearch/compute/aggregation/TopDoubleDoubleAggregator.java" + } File multivalueDedupeInputFile = file("src/main/java/org/elasticsearch/compute/operator/mvdedupe/X-MultivalueDedupe.java.st") template { @@ -897,25 +1003,105 @@ tasks.named('stringTemplates').configure { File bucketedSortInputFile = new File("${projectDir}/src/main/java/org/elasticsearch/compute/data/sort/X-BucketedSort.java.st") template { - it.properties = intProperties + it.properties = propWithoutExtra(intProperties) it.inputFile = bucketedSortInputFile it.outputFile = "org/elasticsearch/compute/data/sort/IntBucketedSort.java" } template { - it.properties = longProperties + it.properties = propWithoutExtra(longProperties) it.inputFile = bucketedSortInputFile it.outputFile = "org/elasticsearch/compute/data/sort/LongBucketedSort.java" } template { - it.properties = floatProperties + it.properties = propWithoutExtra(floatProperties) it.inputFile = bucketedSortInputFile it.outputFile = "org/elasticsearch/compute/data/sort/FloatBucketedSort.java" } template { - it.properties = doubleProperties + it.properties = propWithoutExtra(doubleProperties) it.inputFile = bucketedSortInputFile it.outputFile = "org/elasticsearch/compute/data/sort/DoubleBucketedSort.java" } + template { + it.properties = propWithExtra(intProperties, intProperties) + it.inputFile = bucketedSortInputFile + it.outputFile = "org/elasticsearch/compute/data/sort/IntIntBucketedSort.java" + } + template { + it.properties = propWithExtra(intProperties, longProperties) + it.inputFile = bucketedSortInputFile + it.outputFile = "org/elasticsearch/compute/data/sort/IntLongBucketedSort.java" + } + template { + it.properties = propWithExtra(intProperties, floatProperties) + it.inputFile = bucketedSortInputFile + it.outputFile = "org/elasticsearch/compute/data/sort/IntFloatBucketedSort.java" + } + template { + it.properties = propWithExtra(intProperties, doubleProperties) + it.inputFile = bucketedSortInputFile + it.outputFile = "org/elasticsearch/compute/data/sort/IntDoubleBucketedSort.java" + } + template { + it.properties = propWithExtra(longProperties, intProperties) + it.inputFile = bucketedSortInputFile + it.outputFile = "org/elasticsearch/compute/data/sort/LongIntBucketedSort.java" + } + template { + it.properties = propWithExtra(longProperties, longProperties) + it.inputFile = bucketedSortInputFile + it.outputFile = "org/elasticsearch/compute/data/sort/LongLongBucketedSort.java" + } + template { + it.properties = propWithExtra(longProperties, floatProperties) + it.inputFile = bucketedSortInputFile + it.outputFile = "org/elasticsearch/compute/data/sort/LongFloatBucketedSort.java" + } + template { + it.properties = propWithExtra(longProperties, doubleProperties) + it.inputFile = bucketedSortInputFile + it.outputFile = "org/elasticsearch/compute/data/sort/LongDoubleBucketedSort.java" + } + template { + it.properties = propWithExtra(floatProperties, intProperties) + it.inputFile = bucketedSortInputFile + it.outputFile = "org/elasticsearch/compute/data/sort/FloatIntBucketedSort.java" + } + template { + it.properties = propWithExtra(floatProperties, longProperties) + it.inputFile = bucketedSortInputFile + it.outputFile = "org/elasticsearch/compute/data/sort/FloatLongBucketedSort.java" + } + template { + it.properties = propWithExtra(floatProperties, floatProperties) + it.inputFile = bucketedSortInputFile + it.outputFile = "org/elasticsearch/compute/data/sort/FloatFloatBucketedSort.java" + } + template { + it.properties = propWithExtra(floatProperties, doubleProperties) + it.inputFile = bucketedSortInputFile + it.outputFile = "org/elasticsearch/compute/data/sort/FloatDoubleBucketedSort.java" + } + template { + it.properties = propWithExtra(doubleProperties, intProperties) + it.inputFile = bucketedSortInputFile + it.outputFile = "org/elasticsearch/compute/data/sort/DoubleIntBucketedSort.java" + } + template { + it.properties = propWithExtra(doubleProperties, longProperties) + it.inputFile = bucketedSortInputFile + it.outputFile = "org/elasticsearch/compute/data/sort/DoubleLongBucketedSort.java" + } + template { + it.properties = propWithExtra(doubleProperties, floatProperties) + it.inputFile = bucketedSortInputFile + it.outputFile = "org/elasticsearch/compute/data/sort/DoubleFloatBucketedSort.java" + } + template { + it.properties = propWithExtra(doubleProperties, doubleProperties) + it.inputFile = bucketedSortInputFile + it.outputFile = "org/elasticsearch/compute/data/sort/DoubleDoubleBucketedSort.java" + } File enrichResultBuilderInput = file("src/main/java/org/elasticsearch/compute/operator/lookup/X-EnrichResultBuilder.java.st") template { diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopBooleanAggregator.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopBooleanAggregator.java index f93e3095524c4..05964998003ea 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopBooleanAggregator.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopBooleanAggregator.java @@ -18,7 +18,6 @@ import org.elasticsearch.compute.data.BlockFactory; import org.elasticsearch.compute.data.BooleanBlock; import org.elasticsearch.compute.data.IntVector; -import org.elasticsearch.compute.data.BooleanBlock; import org.elasticsearch.compute.data.sort.BooleanBucketedSort; import org.elasticsearch.compute.operator.DriverContext; import org.elasticsearch.core.Releasables; @@ -118,7 +117,9 @@ public void add(boolean value) { @Override public void toIntermediate(Block[] blocks, int offset, DriverContext driverContext) { - blocks[offset] = toBlock(driverContext.blockFactory()); + try (var intValues = driverContext.blockFactory().newConstantIntVector(0, 1)) { + internalState.toIntermediate(blocks, offset, intValues, driverContext); + } } Block toBlock(BlockFactory blockFactory) { diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopBytesRefAggregator.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopBytesRefAggregator.java index ecc68e7d8a992..88a5d5021983f 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopBytesRefAggregator.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopBytesRefAggregator.java @@ -18,7 +18,6 @@ import org.elasticsearch.compute.data.BlockFactory; import org.elasticsearch.compute.data.BytesRefBlock; import org.elasticsearch.compute.data.IntVector; -import org.elasticsearch.compute.data.BytesRefBlock; import org.elasticsearch.compute.data.sort.BytesRefBucketedSort; import org.elasticsearch.compute.operator.DriverContext; import org.elasticsearch.core.Releasables; @@ -122,7 +121,9 @@ public void add(BytesRef value) { @Override public void toIntermediate(Block[] blocks, int offset, DriverContext driverContext) { - blocks[offset] = toBlock(driverContext.blockFactory()); + try (var intValues = driverContext.blockFactory().newConstantIntVector(0, 1)) { + internalState.toIntermediate(blocks, offset, intValues, driverContext); + } } Block toBlock(BlockFactory blockFactory) { diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopDoubleAggregator.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopDoubleAggregator.java index e9e1803e36fff..df1294c610ed5 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopDoubleAggregator.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopDoubleAggregator.java @@ -18,7 +18,6 @@ import org.elasticsearch.compute.data.BlockFactory; import org.elasticsearch.compute.data.DoubleBlock; import org.elasticsearch.compute.data.IntVector; -import org.elasticsearch.compute.data.DoubleBlock; import org.elasticsearch.compute.data.sort.DoubleBucketedSort; import org.elasticsearch.compute.operator.DriverContext; import org.elasticsearch.core.Releasables; @@ -118,7 +117,9 @@ public void add(double value) { @Override public void toIntermediate(Block[] blocks, int offset, DriverContext driverContext) { - blocks[offset] = toBlock(driverContext.blockFactory()); + try (var intValues = driverContext.blockFactory().newConstantIntVector(0, 1)) { + internalState.toIntermediate(blocks, offset, intValues, driverContext); + } } Block toBlock(BlockFactory blockFactory) { diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopDoubleDoubleAggregator.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopDoubleDoubleAggregator.java new file mode 100644 index 0000000000000..15fbe5345df09 --- /dev/null +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopDoubleDoubleAggregator.java @@ -0,0 +1,140 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +package org.elasticsearch.compute.aggregation; + +// begin generated imports +import org.apache.lucene.util.BytesRef; +import org.elasticsearch.common.breaker.CircuitBreaker; +import org.elasticsearch.common.util.BigArrays; +import org.elasticsearch.compute.ann.Aggregator; +import org.elasticsearch.compute.ann.GroupingAggregator; +import org.elasticsearch.compute.ann.IntermediateState; +import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.BlockFactory; +import org.elasticsearch.compute.data.DoubleBlock; +import org.elasticsearch.compute.data.DoubleBlock; +import org.elasticsearch.compute.data.IntVector; +import org.elasticsearch.compute.data.sort.DoubleDoubleBucketedSort; +import org.elasticsearch.compute.operator.DriverContext; +import org.elasticsearch.core.Releasables; +import org.elasticsearch.search.sort.SortOrder; +// end generated imports + +/** + * Aggregates the top N field values for double. + *

+ * This class is generated. Edit `X-TopAggregator.java.st` to edit this file. + *

+ */ +@Aggregator({ @IntermediateState(name = "top", type = "DOUBLE_BLOCK"), @IntermediateState(name = "extra", type = "DOUBLE_BLOCK") }) +@GroupingAggregator +class TopDoubleDoubleAggregator { + public static SingleState initSingle(BigArrays bigArrays, int limit, boolean ascending) { + return new SingleState(bigArrays, limit, ascending); + } + + public static void combine(SingleState state, double v, double extra) { + state.add(v, extra); + } + + public static void combineIntermediate(SingleState state, DoubleBlock values, DoubleBlock extras) { + int start = values.getFirstValueIndex(0); + int end = start + values.getValueCount(0); + for (int i = start; i < end; i++) { + combine(state, values.getDouble(i), extras.getDouble(i)); + } + } + + public static Block evaluateFinal(SingleState state, DriverContext driverContext) { + return state.toBlock(driverContext.blockFactory()); + } + + public static GroupingState initGrouping(BigArrays bigArrays, int limit, boolean ascending) { + return new GroupingState(bigArrays, limit, ascending); + } + + public static void combine(GroupingState state, int groupId, double v, double extra) { + state.add(groupId, v, extra); + } + + public static void combineIntermediate(GroupingState state, int groupId, DoubleBlock values, DoubleBlock extras, int valuesPosition) { + int start = values.getFirstValueIndex(valuesPosition); + int end = start + values.getValueCount(valuesPosition); + for (int i = start; i < end; i++) { + combine(state, groupId, values.getDouble(i), extras.getDouble(i)); + } + } + + public static Block evaluateFinal(GroupingState state, IntVector selected, GroupingAggregatorEvaluationContext ctx) { + return state.toBlock(ctx.blockFactory(), selected); + } + + public static class GroupingState implements GroupingAggregatorState { + private final DoubleDoubleBucketedSort sort; + + private GroupingState(BigArrays bigArrays, int limit, boolean ascending) { + this.sort = new DoubleDoubleBucketedSort(bigArrays, ascending ? SortOrder.ASC : SortOrder.DESC, limit); + } + + public void add(int groupId, double value, double extra) { + sort.collect(value, extra, groupId); + } + + @Override + public void toIntermediate(Block[] blocks, int offset, IntVector selected, DriverContext driverContext) { + sort.toBlocks(driverContext.blockFactory(), blocks, offset, selected); + } + + Block toBlock(BlockFactory blockFactory, IntVector selected) { + Block[] blocks = new Block[2]; + sort.toBlocks(blockFactory, blocks, 0, selected); + Releasables.close(blocks[0]); + return blocks[1]; + } + + @Override + public void enableGroupIdTracking(SeenGroupIds seen) { + // we figure out seen values from nulls on the values block + } + + @Override + public void close() { + Releasables.closeExpectNoException(sort); + } + } + + public static class SingleState implements AggregatorState { + private final GroupingState internalState; + + private SingleState(BigArrays bigArrays, int limit, boolean ascending) { + this.internalState = new GroupingState(bigArrays, limit, ascending); + } + + public void add(double value, double extra) { + internalState.add(0, value, extra); + } + + @Override + public void toIntermediate(Block[] blocks, int offset, DriverContext driverContext) { + try (var intValues = driverContext.blockFactory().newConstantIntVector(0, 1)) { + internalState.toIntermediate(blocks, offset, intValues, driverContext); + } + } + + Block toBlock(BlockFactory blockFactory) { + try (var intValues = blockFactory.newConstantIntVector(0, 1)) { + return internalState.toBlock(blockFactory, intValues); + } + } + + @Override + public void close() { + Releasables.closeExpectNoException(internalState); + } + } +} diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopDoubleFloatAggregator.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopDoubleFloatAggregator.java new file mode 100644 index 0000000000000..9cd0f08747930 --- /dev/null +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopDoubleFloatAggregator.java @@ -0,0 +1,140 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +package org.elasticsearch.compute.aggregation; + +// begin generated imports +import org.apache.lucene.util.BytesRef; +import org.elasticsearch.common.breaker.CircuitBreaker; +import org.elasticsearch.common.util.BigArrays; +import org.elasticsearch.compute.ann.Aggregator; +import org.elasticsearch.compute.ann.GroupingAggregator; +import org.elasticsearch.compute.ann.IntermediateState; +import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.BlockFactory; +import org.elasticsearch.compute.data.DoubleBlock; +import org.elasticsearch.compute.data.FloatBlock; +import org.elasticsearch.compute.data.IntVector; +import org.elasticsearch.compute.data.sort.DoubleFloatBucketedSort; +import org.elasticsearch.compute.operator.DriverContext; +import org.elasticsearch.core.Releasables; +import org.elasticsearch.search.sort.SortOrder; +// end generated imports + +/** + * Aggregates the top N field values for double. + *

+ * This class is generated. Edit `X-TopAggregator.java.st` to edit this file. + *

+ */ +@Aggregator({ @IntermediateState(name = "top", type = "DOUBLE_BLOCK"), @IntermediateState(name = "extra", type = "FLOAT_BLOCK") }) +@GroupingAggregator +class TopDoubleFloatAggregator { + public static SingleState initSingle(BigArrays bigArrays, int limit, boolean ascending) { + return new SingleState(bigArrays, limit, ascending); + } + + public static void combine(SingleState state, double v, float extra) { + state.add(v, extra); + } + + public static void combineIntermediate(SingleState state, DoubleBlock values, FloatBlock extras) { + int start = values.getFirstValueIndex(0); + int end = start + values.getValueCount(0); + for (int i = start; i < end; i++) { + combine(state, values.getDouble(i), extras.getFloat(i)); + } + } + + public static Block evaluateFinal(SingleState state, DriverContext driverContext) { + return state.toBlock(driverContext.blockFactory()); + } + + public static GroupingState initGrouping(BigArrays bigArrays, int limit, boolean ascending) { + return new GroupingState(bigArrays, limit, ascending); + } + + public static void combine(GroupingState state, int groupId, double v, float extra) { + state.add(groupId, v, extra); + } + + public static void combineIntermediate(GroupingState state, int groupId, DoubleBlock values, FloatBlock extras, int valuesPosition) { + int start = values.getFirstValueIndex(valuesPosition); + int end = start + values.getValueCount(valuesPosition); + for (int i = start; i < end; i++) { + combine(state, groupId, values.getDouble(i), extras.getFloat(i)); + } + } + + public static Block evaluateFinal(GroupingState state, IntVector selected, GroupingAggregatorEvaluationContext ctx) { + return state.toBlock(ctx.blockFactory(), selected); + } + + public static class GroupingState implements GroupingAggregatorState { + private final DoubleFloatBucketedSort sort; + + private GroupingState(BigArrays bigArrays, int limit, boolean ascending) { + this.sort = new DoubleFloatBucketedSort(bigArrays, ascending ? SortOrder.ASC : SortOrder.DESC, limit); + } + + public void add(int groupId, double value, float extra) { + sort.collect(value, extra, groupId); + } + + @Override + public void toIntermediate(Block[] blocks, int offset, IntVector selected, DriverContext driverContext) { + sort.toBlocks(driverContext.blockFactory(), blocks, offset, selected); + } + + Block toBlock(BlockFactory blockFactory, IntVector selected) { + Block[] blocks = new Block[2]; + sort.toBlocks(blockFactory, blocks, 0, selected); + Releasables.close(blocks[0]); + return blocks[1]; + } + + @Override + public void enableGroupIdTracking(SeenGroupIds seen) { + // we figure out seen values from nulls on the values block + } + + @Override + public void close() { + Releasables.closeExpectNoException(sort); + } + } + + public static class SingleState implements AggregatorState { + private final GroupingState internalState; + + private SingleState(BigArrays bigArrays, int limit, boolean ascending) { + this.internalState = new GroupingState(bigArrays, limit, ascending); + } + + public void add(double value, float extra) { + internalState.add(0, value, extra); + } + + @Override + public void toIntermediate(Block[] blocks, int offset, DriverContext driverContext) { + try (var intValues = driverContext.blockFactory().newConstantIntVector(0, 1)) { + internalState.toIntermediate(blocks, offset, intValues, driverContext); + } + } + + Block toBlock(BlockFactory blockFactory) { + try (var intValues = blockFactory.newConstantIntVector(0, 1)) { + return internalState.toBlock(blockFactory, intValues); + } + } + + @Override + public void close() { + Releasables.closeExpectNoException(internalState); + } + } +} diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopDoubleIntAggregator.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopDoubleIntAggregator.java new file mode 100644 index 0000000000000..fe1ce903b2d6c --- /dev/null +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopDoubleIntAggregator.java @@ -0,0 +1,140 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +package org.elasticsearch.compute.aggregation; + +// begin generated imports +import org.apache.lucene.util.BytesRef; +import org.elasticsearch.common.breaker.CircuitBreaker; +import org.elasticsearch.common.util.BigArrays; +import org.elasticsearch.compute.ann.Aggregator; +import org.elasticsearch.compute.ann.GroupingAggregator; +import org.elasticsearch.compute.ann.IntermediateState; +import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.BlockFactory; +import org.elasticsearch.compute.data.DoubleBlock; +import org.elasticsearch.compute.data.IntBlock; +import org.elasticsearch.compute.data.IntVector; +import org.elasticsearch.compute.data.sort.DoubleIntBucketedSort; +import org.elasticsearch.compute.operator.DriverContext; +import org.elasticsearch.core.Releasables; +import org.elasticsearch.search.sort.SortOrder; +// end generated imports + +/** + * Aggregates the top N field values for double. + *

+ * This class is generated. Edit `X-TopAggregator.java.st` to edit this file. + *

+ */ +@Aggregator({ @IntermediateState(name = "top", type = "DOUBLE_BLOCK"), @IntermediateState(name = "extra", type = "INT_BLOCK") }) +@GroupingAggregator +class TopDoubleIntAggregator { + public static SingleState initSingle(BigArrays bigArrays, int limit, boolean ascending) { + return new SingleState(bigArrays, limit, ascending); + } + + public static void combine(SingleState state, double v, int extra) { + state.add(v, extra); + } + + public static void combineIntermediate(SingleState state, DoubleBlock values, IntBlock extras) { + int start = values.getFirstValueIndex(0); + int end = start + values.getValueCount(0); + for (int i = start; i < end; i++) { + combine(state, values.getDouble(i), extras.getInt(i)); + } + } + + public static Block evaluateFinal(SingleState state, DriverContext driverContext) { + return state.toBlock(driverContext.blockFactory()); + } + + public static GroupingState initGrouping(BigArrays bigArrays, int limit, boolean ascending) { + return new GroupingState(bigArrays, limit, ascending); + } + + public static void combine(GroupingState state, int groupId, double v, int extra) { + state.add(groupId, v, extra); + } + + public static void combineIntermediate(GroupingState state, int groupId, DoubleBlock values, IntBlock extras, int valuesPosition) { + int start = values.getFirstValueIndex(valuesPosition); + int end = start + values.getValueCount(valuesPosition); + for (int i = start; i < end; i++) { + combine(state, groupId, values.getDouble(i), extras.getInt(i)); + } + } + + public static Block evaluateFinal(GroupingState state, IntVector selected, GroupingAggregatorEvaluationContext ctx) { + return state.toBlock(ctx.blockFactory(), selected); + } + + public static class GroupingState implements GroupingAggregatorState { + private final DoubleIntBucketedSort sort; + + private GroupingState(BigArrays bigArrays, int limit, boolean ascending) { + this.sort = new DoubleIntBucketedSort(bigArrays, ascending ? SortOrder.ASC : SortOrder.DESC, limit); + } + + public void add(int groupId, double value, int extra) { + sort.collect(value, extra, groupId); + } + + @Override + public void toIntermediate(Block[] blocks, int offset, IntVector selected, DriverContext driverContext) { + sort.toBlocks(driverContext.blockFactory(), blocks, offset, selected); + } + + Block toBlock(BlockFactory blockFactory, IntVector selected) { + Block[] blocks = new Block[2]; + sort.toBlocks(blockFactory, blocks, 0, selected); + Releasables.close(blocks[0]); + return blocks[1]; + } + + @Override + public void enableGroupIdTracking(SeenGroupIds seen) { + // we figure out seen values from nulls on the values block + } + + @Override + public void close() { + Releasables.closeExpectNoException(sort); + } + } + + public static class SingleState implements AggregatorState { + private final GroupingState internalState; + + private SingleState(BigArrays bigArrays, int limit, boolean ascending) { + this.internalState = new GroupingState(bigArrays, limit, ascending); + } + + public void add(double value, int extra) { + internalState.add(0, value, extra); + } + + @Override + public void toIntermediate(Block[] blocks, int offset, DriverContext driverContext) { + try (var intValues = driverContext.blockFactory().newConstantIntVector(0, 1)) { + internalState.toIntermediate(blocks, offset, intValues, driverContext); + } + } + + Block toBlock(BlockFactory blockFactory) { + try (var intValues = blockFactory.newConstantIntVector(0, 1)) { + return internalState.toBlock(blockFactory, intValues); + } + } + + @Override + public void close() { + Releasables.closeExpectNoException(internalState); + } + } +} diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopDoubleLongAggregator.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopDoubleLongAggregator.java new file mode 100644 index 0000000000000..4546acdd1dd6f --- /dev/null +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopDoubleLongAggregator.java @@ -0,0 +1,140 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +package org.elasticsearch.compute.aggregation; + +// begin generated imports +import org.apache.lucene.util.BytesRef; +import org.elasticsearch.common.breaker.CircuitBreaker; +import org.elasticsearch.common.util.BigArrays; +import org.elasticsearch.compute.ann.Aggregator; +import org.elasticsearch.compute.ann.GroupingAggregator; +import org.elasticsearch.compute.ann.IntermediateState; +import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.BlockFactory; +import org.elasticsearch.compute.data.DoubleBlock; +import org.elasticsearch.compute.data.LongBlock; +import org.elasticsearch.compute.data.IntVector; +import org.elasticsearch.compute.data.sort.DoubleLongBucketedSort; +import org.elasticsearch.compute.operator.DriverContext; +import org.elasticsearch.core.Releasables; +import org.elasticsearch.search.sort.SortOrder; +// end generated imports + +/** + * Aggregates the top N field values for double. + *

+ * This class is generated. Edit `X-TopAggregator.java.st` to edit this file. + *

+ */ +@Aggregator({ @IntermediateState(name = "top", type = "DOUBLE_BLOCK"), @IntermediateState(name = "extra", type = "LONG_BLOCK") }) +@GroupingAggregator +class TopDoubleLongAggregator { + public static SingleState initSingle(BigArrays bigArrays, int limit, boolean ascending) { + return new SingleState(bigArrays, limit, ascending); + } + + public static void combine(SingleState state, double v, long extra) { + state.add(v, extra); + } + + public static void combineIntermediate(SingleState state, DoubleBlock values, LongBlock extras) { + int start = values.getFirstValueIndex(0); + int end = start + values.getValueCount(0); + for (int i = start; i < end; i++) { + combine(state, values.getDouble(i), extras.getLong(i)); + } + } + + public static Block evaluateFinal(SingleState state, DriverContext driverContext) { + return state.toBlock(driverContext.blockFactory()); + } + + public static GroupingState initGrouping(BigArrays bigArrays, int limit, boolean ascending) { + return new GroupingState(bigArrays, limit, ascending); + } + + public static void combine(GroupingState state, int groupId, double v, long extra) { + state.add(groupId, v, extra); + } + + public static void combineIntermediate(GroupingState state, int groupId, DoubleBlock values, LongBlock extras, int valuesPosition) { + int start = values.getFirstValueIndex(valuesPosition); + int end = start + values.getValueCount(valuesPosition); + for (int i = start; i < end; i++) { + combine(state, groupId, values.getDouble(i), extras.getLong(i)); + } + } + + public static Block evaluateFinal(GroupingState state, IntVector selected, GroupingAggregatorEvaluationContext ctx) { + return state.toBlock(ctx.blockFactory(), selected); + } + + public static class GroupingState implements GroupingAggregatorState { + private final DoubleLongBucketedSort sort; + + private GroupingState(BigArrays bigArrays, int limit, boolean ascending) { + this.sort = new DoubleLongBucketedSort(bigArrays, ascending ? SortOrder.ASC : SortOrder.DESC, limit); + } + + public void add(int groupId, double value, long extra) { + sort.collect(value, extra, groupId); + } + + @Override + public void toIntermediate(Block[] blocks, int offset, IntVector selected, DriverContext driverContext) { + sort.toBlocks(driverContext.blockFactory(), blocks, offset, selected); + } + + Block toBlock(BlockFactory blockFactory, IntVector selected) { + Block[] blocks = new Block[2]; + sort.toBlocks(blockFactory, blocks, 0, selected); + Releasables.close(blocks[0]); + return blocks[1]; + } + + @Override + public void enableGroupIdTracking(SeenGroupIds seen) { + // we figure out seen values from nulls on the values block + } + + @Override + public void close() { + Releasables.closeExpectNoException(sort); + } + } + + public static class SingleState implements AggregatorState { + private final GroupingState internalState; + + private SingleState(BigArrays bigArrays, int limit, boolean ascending) { + this.internalState = new GroupingState(bigArrays, limit, ascending); + } + + public void add(double value, long extra) { + internalState.add(0, value, extra); + } + + @Override + public void toIntermediate(Block[] blocks, int offset, DriverContext driverContext) { + try (var intValues = driverContext.blockFactory().newConstantIntVector(0, 1)) { + internalState.toIntermediate(blocks, offset, intValues, driverContext); + } + } + + Block toBlock(BlockFactory blockFactory) { + try (var intValues = blockFactory.newConstantIntVector(0, 1)) { + return internalState.toBlock(blockFactory, intValues); + } + } + + @Override + public void close() { + Releasables.closeExpectNoException(internalState); + } + } +} diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopFloatAggregator.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopFloatAggregator.java index 1b5fddc0b0038..25e20ec26ffa0 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopFloatAggregator.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopFloatAggregator.java @@ -18,7 +18,6 @@ import org.elasticsearch.compute.data.BlockFactory; import org.elasticsearch.compute.data.FloatBlock; import org.elasticsearch.compute.data.IntVector; -import org.elasticsearch.compute.data.FloatBlock; import org.elasticsearch.compute.data.sort.FloatBucketedSort; import org.elasticsearch.compute.operator.DriverContext; import org.elasticsearch.core.Releasables; @@ -118,7 +117,9 @@ public void add(float value) { @Override public void toIntermediate(Block[] blocks, int offset, DriverContext driverContext) { - blocks[offset] = toBlock(driverContext.blockFactory()); + try (var intValues = driverContext.blockFactory().newConstantIntVector(0, 1)) { + internalState.toIntermediate(blocks, offset, intValues, driverContext); + } } Block toBlock(BlockFactory blockFactory) { diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopFloatDoubleAggregator.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopFloatDoubleAggregator.java new file mode 100644 index 0000000000000..7d085fc37cf02 --- /dev/null +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopFloatDoubleAggregator.java @@ -0,0 +1,140 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +package org.elasticsearch.compute.aggregation; + +// begin generated imports +import org.apache.lucene.util.BytesRef; +import org.elasticsearch.common.breaker.CircuitBreaker; +import org.elasticsearch.common.util.BigArrays; +import org.elasticsearch.compute.ann.Aggregator; +import org.elasticsearch.compute.ann.GroupingAggregator; +import org.elasticsearch.compute.ann.IntermediateState; +import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.BlockFactory; +import org.elasticsearch.compute.data.FloatBlock; +import org.elasticsearch.compute.data.DoubleBlock; +import org.elasticsearch.compute.data.IntVector; +import org.elasticsearch.compute.data.sort.FloatDoubleBucketedSort; +import org.elasticsearch.compute.operator.DriverContext; +import org.elasticsearch.core.Releasables; +import org.elasticsearch.search.sort.SortOrder; +// end generated imports + +/** + * Aggregates the top N field values for float. + *

+ * This class is generated. Edit `X-TopAggregator.java.st` to edit this file. + *

+ */ +@Aggregator({ @IntermediateState(name = "top", type = "FLOAT_BLOCK"), @IntermediateState(name = "extra", type = "DOUBLE_BLOCK") }) +@GroupingAggregator +class TopFloatDoubleAggregator { + public static SingleState initSingle(BigArrays bigArrays, int limit, boolean ascending) { + return new SingleState(bigArrays, limit, ascending); + } + + public static void combine(SingleState state, float v, double extra) { + state.add(v, extra); + } + + public static void combineIntermediate(SingleState state, FloatBlock values, DoubleBlock extras) { + int start = values.getFirstValueIndex(0); + int end = start + values.getValueCount(0); + for (int i = start; i < end; i++) { + combine(state, values.getFloat(i), extras.getDouble(i)); + } + } + + public static Block evaluateFinal(SingleState state, DriverContext driverContext) { + return state.toBlock(driverContext.blockFactory()); + } + + public static GroupingState initGrouping(BigArrays bigArrays, int limit, boolean ascending) { + return new GroupingState(bigArrays, limit, ascending); + } + + public static void combine(GroupingState state, int groupId, float v, double extra) { + state.add(groupId, v, extra); + } + + public static void combineIntermediate(GroupingState state, int groupId, FloatBlock values, DoubleBlock extras, int valuesPosition) { + int start = values.getFirstValueIndex(valuesPosition); + int end = start + values.getValueCount(valuesPosition); + for (int i = start; i < end; i++) { + combine(state, groupId, values.getFloat(i), extras.getDouble(i)); + } + } + + public static Block evaluateFinal(GroupingState state, IntVector selected, GroupingAggregatorEvaluationContext ctx) { + return state.toBlock(ctx.blockFactory(), selected); + } + + public static class GroupingState implements GroupingAggregatorState { + private final FloatDoubleBucketedSort sort; + + private GroupingState(BigArrays bigArrays, int limit, boolean ascending) { + this.sort = new FloatDoubleBucketedSort(bigArrays, ascending ? SortOrder.ASC : SortOrder.DESC, limit); + } + + public void add(int groupId, float value, double extra) { + sort.collect(value, extra, groupId); + } + + @Override + public void toIntermediate(Block[] blocks, int offset, IntVector selected, DriverContext driverContext) { + sort.toBlocks(driverContext.blockFactory(), blocks, offset, selected); + } + + Block toBlock(BlockFactory blockFactory, IntVector selected) { + Block[] blocks = new Block[2]; + sort.toBlocks(blockFactory, blocks, 0, selected); + Releasables.close(blocks[0]); + return blocks[1]; + } + + @Override + public void enableGroupIdTracking(SeenGroupIds seen) { + // we figure out seen values from nulls on the values block + } + + @Override + public void close() { + Releasables.closeExpectNoException(sort); + } + } + + public static class SingleState implements AggregatorState { + private final GroupingState internalState; + + private SingleState(BigArrays bigArrays, int limit, boolean ascending) { + this.internalState = new GroupingState(bigArrays, limit, ascending); + } + + public void add(float value, double extra) { + internalState.add(0, value, extra); + } + + @Override + public void toIntermediate(Block[] blocks, int offset, DriverContext driverContext) { + try (var intValues = driverContext.blockFactory().newConstantIntVector(0, 1)) { + internalState.toIntermediate(blocks, offset, intValues, driverContext); + } + } + + Block toBlock(BlockFactory blockFactory) { + try (var intValues = blockFactory.newConstantIntVector(0, 1)) { + return internalState.toBlock(blockFactory, intValues); + } + } + + @Override + public void close() { + Releasables.closeExpectNoException(internalState); + } + } +} diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopFloatFloatAggregator.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopFloatFloatAggregator.java new file mode 100644 index 0000000000000..cdc0014b14edf --- /dev/null +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopFloatFloatAggregator.java @@ -0,0 +1,140 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +package org.elasticsearch.compute.aggregation; + +// begin generated imports +import org.apache.lucene.util.BytesRef; +import org.elasticsearch.common.breaker.CircuitBreaker; +import org.elasticsearch.common.util.BigArrays; +import org.elasticsearch.compute.ann.Aggregator; +import org.elasticsearch.compute.ann.GroupingAggregator; +import org.elasticsearch.compute.ann.IntermediateState; +import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.BlockFactory; +import org.elasticsearch.compute.data.FloatBlock; +import org.elasticsearch.compute.data.FloatBlock; +import org.elasticsearch.compute.data.IntVector; +import org.elasticsearch.compute.data.sort.FloatFloatBucketedSort; +import org.elasticsearch.compute.operator.DriverContext; +import org.elasticsearch.core.Releasables; +import org.elasticsearch.search.sort.SortOrder; +// end generated imports + +/** + * Aggregates the top N field values for float. + *

+ * This class is generated. Edit `X-TopAggregator.java.st` to edit this file. + *

+ */ +@Aggregator({ @IntermediateState(name = "top", type = "FLOAT_BLOCK"), @IntermediateState(name = "extra", type = "FLOAT_BLOCK") }) +@GroupingAggregator +class TopFloatFloatAggregator { + public static SingleState initSingle(BigArrays bigArrays, int limit, boolean ascending) { + return new SingleState(bigArrays, limit, ascending); + } + + public static void combine(SingleState state, float v, float extra) { + state.add(v, extra); + } + + public static void combineIntermediate(SingleState state, FloatBlock values, FloatBlock extras) { + int start = values.getFirstValueIndex(0); + int end = start + values.getValueCount(0); + for (int i = start; i < end; i++) { + combine(state, values.getFloat(i), extras.getFloat(i)); + } + } + + public static Block evaluateFinal(SingleState state, DriverContext driverContext) { + return state.toBlock(driverContext.blockFactory()); + } + + public static GroupingState initGrouping(BigArrays bigArrays, int limit, boolean ascending) { + return new GroupingState(bigArrays, limit, ascending); + } + + public static void combine(GroupingState state, int groupId, float v, float extra) { + state.add(groupId, v, extra); + } + + public static void combineIntermediate(GroupingState state, int groupId, FloatBlock values, FloatBlock extras, int valuesPosition) { + int start = values.getFirstValueIndex(valuesPosition); + int end = start + values.getValueCount(valuesPosition); + for (int i = start; i < end; i++) { + combine(state, groupId, values.getFloat(i), extras.getFloat(i)); + } + } + + public static Block evaluateFinal(GroupingState state, IntVector selected, GroupingAggregatorEvaluationContext ctx) { + return state.toBlock(ctx.blockFactory(), selected); + } + + public static class GroupingState implements GroupingAggregatorState { + private final FloatFloatBucketedSort sort; + + private GroupingState(BigArrays bigArrays, int limit, boolean ascending) { + this.sort = new FloatFloatBucketedSort(bigArrays, ascending ? SortOrder.ASC : SortOrder.DESC, limit); + } + + public void add(int groupId, float value, float extra) { + sort.collect(value, extra, groupId); + } + + @Override + public void toIntermediate(Block[] blocks, int offset, IntVector selected, DriverContext driverContext) { + sort.toBlocks(driverContext.blockFactory(), blocks, offset, selected); + } + + Block toBlock(BlockFactory blockFactory, IntVector selected) { + Block[] blocks = new Block[2]; + sort.toBlocks(blockFactory, blocks, 0, selected); + Releasables.close(blocks[0]); + return blocks[1]; + } + + @Override + public void enableGroupIdTracking(SeenGroupIds seen) { + // we figure out seen values from nulls on the values block + } + + @Override + public void close() { + Releasables.closeExpectNoException(sort); + } + } + + public static class SingleState implements AggregatorState { + private final GroupingState internalState; + + private SingleState(BigArrays bigArrays, int limit, boolean ascending) { + this.internalState = new GroupingState(bigArrays, limit, ascending); + } + + public void add(float value, float extra) { + internalState.add(0, value, extra); + } + + @Override + public void toIntermediate(Block[] blocks, int offset, DriverContext driverContext) { + try (var intValues = driverContext.blockFactory().newConstantIntVector(0, 1)) { + internalState.toIntermediate(blocks, offset, intValues, driverContext); + } + } + + Block toBlock(BlockFactory blockFactory) { + try (var intValues = blockFactory.newConstantIntVector(0, 1)) { + return internalState.toBlock(blockFactory, intValues); + } + } + + @Override + public void close() { + Releasables.closeExpectNoException(internalState); + } + } +} diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopFloatIntAggregator.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopFloatIntAggregator.java new file mode 100644 index 0000000000000..ff443fd451503 --- /dev/null +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopFloatIntAggregator.java @@ -0,0 +1,140 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +package org.elasticsearch.compute.aggregation; + +// begin generated imports +import org.apache.lucene.util.BytesRef; +import org.elasticsearch.common.breaker.CircuitBreaker; +import org.elasticsearch.common.util.BigArrays; +import org.elasticsearch.compute.ann.Aggregator; +import org.elasticsearch.compute.ann.GroupingAggregator; +import org.elasticsearch.compute.ann.IntermediateState; +import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.BlockFactory; +import org.elasticsearch.compute.data.FloatBlock; +import org.elasticsearch.compute.data.IntBlock; +import org.elasticsearch.compute.data.IntVector; +import org.elasticsearch.compute.data.sort.FloatIntBucketedSort; +import org.elasticsearch.compute.operator.DriverContext; +import org.elasticsearch.core.Releasables; +import org.elasticsearch.search.sort.SortOrder; +// end generated imports + +/** + * Aggregates the top N field values for float. + *

+ * This class is generated. Edit `X-TopAggregator.java.st` to edit this file. + *

+ */ +@Aggregator({ @IntermediateState(name = "top", type = "FLOAT_BLOCK"), @IntermediateState(name = "extra", type = "INT_BLOCK") }) +@GroupingAggregator +class TopFloatIntAggregator { + public static SingleState initSingle(BigArrays bigArrays, int limit, boolean ascending) { + return new SingleState(bigArrays, limit, ascending); + } + + public static void combine(SingleState state, float v, int extra) { + state.add(v, extra); + } + + public static void combineIntermediate(SingleState state, FloatBlock values, IntBlock extras) { + int start = values.getFirstValueIndex(0); + int end = start + values.getValueCount(0); + for (int i = start; i < end; i++) { + combine(state, values.getFloat(i), extras.getInt(i)); + } + } + + public static Block evaluateFinal(SingleState state, DriverContext driverContext) { + return state.toBlock(driverContext.blockFactory()); + } + + public static GroupingState initGrouping(BigArrays bigArrays, int limit, boolean ascending) { + return new GroupingState(bigArrays, limit, ascending); + } + + public static void combine(GroupingState state, int groupId, float v, int extra) { + state.add(groupId, v, extra); + } + + public static void combineIntermediate(GroupingState state, int groupId, FloatBlock values, IntBlock extras, int valuesPosition) { + int start = values.getFirstValueIndex(valuesPosition); + int end = start + values.getValueCount(valuesPosition); + for (int i = start; i < end; i++) { + combine(state, groupId, values.getFloat(i), extras.getInt(i)); + } + } + + public static Block evaluateFinal(GroupingState state, IntVector selected, GroupingAggregatorEvaluationContext ctx) { + return state.toBlock(ctx.blockFactory(), selected); + } + + public static class GroupingState implements GroupingAggregatorState { + private final FloatIntBucketedSort sort; + + private GroupingState(BigArrays bigArrays, int limit, boolean ascending) { + this.sort = new FloatIntBucketedSort(bigArrays, ascending ? SortOrder.ASC : SortOrder.DESC, limit); + } + + public void add(int groupId, float value, int extra) { + sort.collect(value, extra, groupId); + } + + @Override + public void toIntermediate(Block[] blocks, int offset, IntVector selected, DriverContext driverContext) { + sort.toBlocks(driverContext.blockFactory(), blocks, offset, selected); + } + + Block toBlock(BlockFactory blockFactory, IntVector selected) { + Block[] blocks = new Block[2]; + sort.toBlocks(blockFactory, blocks, 0, selected); + Releasables.close(blocks[0]); + return blocks[1]; + } + + @Override + public void enableGroupIdTracking(SeenGroupIds seen) { + // we figure out seen values from nulls on the values block + } + + @Override + public void close() { + Releasables.closeExpectNoException(sort); + } + } + + public static class SingleState implements AggregatorState { + private final GroupingState internalState; + + private SingleState(BigArrays bigArrays, int limit, boolean ascending) { + this.internalState = new GroupingState(bigArrays, limit, ascending); + } + + public void add(float value, int extra) { + internalState.add(0, value, extra); + } + + @Override + public void toIntermediate(Block[] blocks, int offset, DriverContext driverContext) { + try (var intValues = driverContext.blockFactory().newConstantIntVector(0, 1)) { + internalState.toIntermediate(blocks, offset, intValues, driverContext); + } + } + + Block toBlock(BlockFactory blockFactory) { + try (var intValues = blockFactory.newConstantIntVector(0, 1)) { + return internalState.toBlock(blockFactory, intValues); + } + } + + @Override + public void close() { + Releasables.closeExpectNoException(internalState); + } + } +} diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopFloatLongAggregator.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopFloatLongAggregator.java new file mode 100644 index 0000000000000..896ef0caf115f --- /dev/null +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopFloatLongAggregator.java @@ -0,0 +1,140 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +package org.elasticsearch.compute.aggregation; + +// begin generated imports +import org.apache.lucene.util.BytesRef; +import org.elasticsearch.common.breaker.CircuitBreaker; +import org.elasticsearch.common.util.BigArrays; +import org.elasticsearch.compute.ann.Aggregator; +import org.elasticsearch.compute.ann.GroupingAggregator; +import org.elasticsearch.compute.ann.IntermediateState; +import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.BlockFactory; +import org.elasticsearch.compute.data.FloatBlock; +import org.elasticsearch.compute.data.LongBlock; +import org.elasticsearch.compute.data.IntVector; +import org.elasticsearch.compute.data.sort.FloatLongBucketedSort; +import org.elasticsearch.compute.operator.DriverContext; +import org.elasticsearch.core.Releasables; +import org.elasticsearch.search.sort.SortOrder; +// end generated imports + +/** + * Aggregates the top N field values for float. + *

+ * This class is generated. Edit `X-TopAggregator.java.st` to edit this file. + *

+ */ +@Aggregator({ @IntermediateState(name = "top", type = "FLOAT_BLOCK"), @IntermediateState(name = "extra", type = "LONG_BLOCK") }) +@GroupingAggregator +class TopFloatLongAggregator { + public static SingleState initSingle(BigArrays bigArrays, int limit, boolean ascending) { + return new SingleState(bigArrays, limit, ascending); + } + + public static void combine(SingleState state, float v, long extra) { + state.add(v, extra); + } + + public static void combineIntermediate(SingleState state, FloatBlock values, LongBlock extras) { + int start = values.getFirstValueIndex(0); + int end = start + values.getValueCount(0); + for (int i = start; i < end; i++) { + combine(state, values.getFloat(i), extras.getLong(i)); + } + } + + public static Block evaluateFinal(SingleState state, DriverContext driverContext) { + return state.toBlock(driverContext.blockFactory()); + } + + public static GroupingState initGrouping(BigArrays bigArrays, int limit, boolean ascending) { + return new GroupingState(bigArrays, limit, ascending); + } + + public static void combine(GroupingState state, int groupId, float v, long extra) { + state.add(groupId, v, extra); + } + + public static void combineIntermediate(GroupingState state, int groupId, FloatBlock values, LongBlock extras, int valuesPosition) { + int start = values.getFirstValueIndex(valuesPosition); + int end = start + values.getValueCount(valuesPosition); + for (int i = start; i < end; i++) { + combine(state, groupId, values.getFloat(i), extras.getLong(i)); + } + } + + public static Block evaluateFinal(GroupingState state, IntVector selected, GroupingAggregatorEvaluationContext ctx) { + return state.toBlock(ctx.blockFactory(), selected); + } + + public static class GroupingState implements GroupingAggregatorState { + private final FloatLongBucketedSort sort; + + private GroupingState(BigArrays bigArrays, int limit, boolean ascending) { + this.sort = new FloatLongBucketedSort(bigArrays, ascending ? SortOrder.ASC : SortOrder.DESC, limit); + } + + public void add(int groupId, float value, long extra) { + sort.collect(value, extra, groupId); + } + + @Override + public void toIntermediate(Block[] blocks, int offset, IntVector selected, DriverContext driverContext) { + sort.toBlocks(driverContext.blockFactory(), blocks, offset, selected); + } + + Block toBlock(BlockFactory blockFactory, IntVector selected) { + Block[] blocks = new Block[2]; + sort.toBlocks(blockFactory, blocks, 0, selected); + Releasables.close(blocks[0]); + return blocks[1]; + } + + @Override + public void enableGroupIdTracking(SeenGroupIds seen) { + // we figure out seen values from nulls on the values block + } + + @Override + public void close() { + Releasables.closeExpectNoException(sort); + } + } + + public static class SingleState implements AggregatorState { + private final GroupingState internalState; + + private SingleState(BigArrays bigArrays, int limit, boolean ascending) { + this.internalState = new GroupingState(bigArrays, limit, ascending); + } + + public void add(float value, long extra) { + internalState.add(0, value, extra); + } + + @Override + public void toIntermediate(Block[] blocks, int offset, DriverContext driverContext) { + try (var intValues = driverContext.blockFactory().newConstantIntVector(0, 1)) { + internalState.toIntermediate(blocks, offset, intValues, driverContext); + } + } + + Block toBlock(BlockFactory blockFactory) { + try (var intValues = blockFactory.newConstantIntVector(0, 1)) { + return internalState.toBlock(blockFactory, intValues); + } + } + + @Override + public void close() { + Releasables.closeExpectNoException(internalState); + } + } +} diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopIntAggregator.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopIntAggregator.java index aa8c5e8e1bf3f..7fc6053bf7681 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopIntAggregator.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopIntAggregator.java @@ -18,7 +18,6 @@ import org.elasticsearch.compute.data.BlockFactory; import org.elasticsearch.compute.data.IntBlock; import org.elasticsearch.compute.data.IntVector; -import org.elasticsearch.compute.data.IntBlock; import org.elasticsearch.compute.data.sort.IntBucketedSort; import org.elasticsearch.compute.operator.DriverContext; import org.elasticsearch.core.Releasables; @@ -118,7 +117,9 @@ public void add(int value) { @Override public void toIntermediate(Block[] blocks, int offset, DriverContext driverContext) { - blocks[offset] = toBlock(driverContext.blockFactory()); + try (var intValues = driverContext.blockFactory().newConstantIntVector(0, 1)) { + internalState.toIntermediate(blocks, offset, intValues, driverContext); + } } Block toBlock(BlockFactory blockFactory) { diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopIntDoubleAggregator.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopIntDoubleAggregator.java new file mode 100644 index 0000000000000..d099c29c55a13 --- /dev/null +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopIntDoubleAggregator.java @@ -0,0 +1,140 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +package org.elasticsearch.compute.aggregation; + +// begin generated imports +import org.apache.lucene.util.BytesRef; +import org.elasticsearch.common.breaker.CircuitBreaker; +import org.elasticsearch.common.util.BigArrays; +import org.elasticsearch.compute.ann.Aggregator; +import org.elasticsearch.compute.ann.GroupingAggregator; +import org.elasticsearch.compute.ann.IntermediateState; +import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.BlockFactory; +import org.elasticsearch.compute.data.IntBlock; +import org.elasticsearch.compute.data.DoubleBlock; +import org.elasticsearch.compute.data.IntVector; +import org.elasticsearch.compute.data.sort.IntDoubleBucketedSort; +import org.elasticsearch.compute.operator.DriverContext; +import org.elasticsearch.core.Releasables; +import org.elasticsearch.search.sort.SortOrder; +// end generated imports + +/** + * Aggregates the top N field values for int. + *

+ * This class is generated. Edit `X-TopAggregator.java.st` to edit this file. + *

+ */ +@Aggregator({ @IntermediateState(name = "top", type = "INT_BLOCK"), @IntermediateState(name = "extra", type = "DOUBLE_BLOCK") }) +@GroupingAggregator +class TopIntDoubleAggregator { + public static SingleState initSingle(BigArrays bigArrays, int limit, boolean ascending) { + return new SingleState(bigArrays, limit, ascending); + } + + public static void combine(SingleState state, int v, double extra) { + state.add(v, extra); + } + + public static void combineIntermediate(SingleState state, IntBlock values, DoubleBlock extras) { + int start = values.getFirstValueIndex(0); + int end = start + values.getValueCount(0); + for (int i = start; i < end; i++) { + combine(state, values.getInt(i), extras.getDouble(i)); + } + } + + public static Block evaluateFinal(SingleState state, DriverContext driverContext) { + return state.toBlock(driverContext.blockFactory()); + } + + public static GroupingState initGrouping(BigArrays bigArrays, int limit, boolean ascending) { + return new GroupingState(bigArrays, limit, ascending); + } + + public static void combine(GroupingState state, int groupId, int v, double extra) { + state.add(groupId, v, extra); + } + + public static void combineIntermediate(GroupingState state, int groupId, IntBlock values, DoubleBlock extras, int valuesPosition) { + int start = values.getFirstValueIndex(valuesPosition); + int end = start + values.getValueCount(valuesPosition); + for (int i = start; i < end; i++) { + combine(state, groupId, values.getInt(i), extras.getDouble(i)); + } + } + + public static Block evaluateFinal(GroupingState state, IntVector selected, GroupingAggregatorEvaluationContext ctx) { + return state.toBlock(ctx.blockFactory(), selected); + } + + public static class GroupingState implements GroupingAggregatorState { + private final IntDoubleBucketedSort sort; + + private GroupingState(BigArrays bigArrays, int limit, boolean ascending) { + this.sort = new IntDoubleBucketedSort(bigArrays, ascending ? SortOrder.ASC : SortOrder.DESC, limit); + } + + public void add(int groupId, int value, double extra) { + sort.collect(value, extra, groupId); + } + + @Override + public void toIntermediate(Block[] blocks, int offset, IntVector selected, DriverContext driverContext) { + sort.toBlocks(driverContext.blockFactory(), blocks, offset, selected); + } + + Block toBlock(BlockFactory blockFactory, IntVector selected) { + Block[] blocks = new Block[2]; + sort.toBlocks(blockFactory, blocks, 0, selected); + Releasables.close(blocks[0]); + return blocks[1]; + } + + @Override + public void enableGroupIdTracking(SeenGroupIds seen) { + // we figure out seen values from nulls on the values block + } + + @Override + public void close() { + Releasables.closeExpectNoException(sort); + } + } + + public static class SingleState implements AggregatorState { + private final GroupingState internalState; + + private SingleState(BigArrays bigArrays, int limit, boolean ascending) { + this.internalState = new GroupingState(bigArrays, limit, ascending); + } + + public void add(int value, double extra) { + internalState.add(0, value, extra); + } + + @Override + public void toIntermediate(Block[] blocks, int offset, DriverContext driverContext) { + try (var intValues = driverContext.blockFactory().newConstantIntVector(0, 1)) { + internalState.toIntermediate(blocks, offset, intValues, driverContext); + } + } + + Block toBlock(BlockFactory blockFactory) { + try (var intValues = blockFactory.newConstantIntVector(0, 1)) { + return internalState.toBlock(blockFactory, intValues); + } + } + + @Override + public void close() { + Releasables.closeExpectNoException(internalState); + } + } +} diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopIntFloatAggregator.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopIntFloatAggregator.java new file mode 100644 index 0000000000000..8332fdb7042cb --- /dev/null +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopIntFloatAggregator.java @@ -0,0 +1,140 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +package org.elasticsearch.compute.aggregation; + +// begin generated imports +import org.apache.lucene.util.BytesRef; +import org.elasticsearch.common.breaker.CircuitBreaker; +import org.elasticsearch.common.util.BigArrays; +import org.elasticsearch.compute.ann.Aggregator; +import org.elasticsearch.compute.ann.GroupingAggregator; +import org.elasticsearch.compute.ann.IntermediateState; +import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.BlockFactory; +import org.elasticsearch.compute.data.IntBlock; +import org.elasticsearch.compute.data.FloatBlock; +import org.elasticsearch.compute.data.IntVector; +import org.elasticsearch.compute.data.sort.IntFloatBucketedSort; +import org.elasticsearch.compute.operator.DriverContext; +import org.elasticsearch.core.Releasables; +import org.elasticsearch.search.sort.SortOrder; +// end generated imports + +/** + * Aggregates the top N field values for int. + *

+ * This class is generated. Edit `X-TopAggregator.java.st` to edit this file. + *

+ */ +@Aggregator({ @IntermediateState(name = "top", type = "INT_BLOCK"), @IntermediateState(name = "extra", type = "FLOAT_BLOCK") }) +@GroupingAggregator +class TopIntFloatAggregator { + public static SingleState initSingle(BigArrays bigArrays, int limit, boolean ascending) { + return new SingleState(bigArrays, limit, ascending); + } + + public static void combine(SingleState state, int v, float extra) { + state.add(v, extra); + } + + public static void combineIntermediate(SingleState state, IntBlock values, FloatBlock extras) { + int start = values.getFirstValueIndex(0); + int end = start + values.getValueCount(0); + for (int i = start; i < end; i++) { + combine(state, values.getInt(i), extras.getFloat(i)); + } + } + + public static Block evaluateFinal(SingleState state, DriverContext driverContext) { + return state.toBlock(driverContext.blockFactory()); + } + + public static GroupingState initGrouping(BigArrays bigArrays, int limit, boolean ascending) { + return new GroupingState(bigArrays, limit, ascending); + } + + public static void combine(GroupingState state, int groupId, int v, float extra) { + state.add(groupId, v, extra); + } + + public static void combineIntermediate(GroupingState state, int groupId, IntBlock values, FloatBlock extras, int valuesPosition) { + int start = values.getFirstValueIndex(valuesPosition); + int end = start + values.getValueCount(valuesPosition); + for (int i = start; i < end; i++) { + combine(state, groupId, values.getInt(i), extras.getFloat(i)); + } + } + + public static Block evaluateFinal(GroupingState state, IntVector selected, GroupingAggregatorEvaluationContext ctx) { + return state.toBlock(ctx.blockFactory(), selected); + } + + public static class GroupingState implements GroupingAggregatorState { + private final IntFloatBucketedSort sort; + + private GroupingState(BigArrays bigArrays, int limit, boolean ascending) { + this.sort = new IntFloatBucketedSort(bigArrays, ascending ? SortOrder.ASC : SortOrder.DESC, limit); + } + + public void add(int groupId, int value, float extra) { + sort.collect(value, extra, groupId); + } + + @Override + public void toIntermediate(Block[] blocks, int offset, IntVector selected, DriverContext driverContext) { + sort.toBlocks(driverContext.blockFactory(), blocks, offset, selected); + } + + Block toBlock(BlockFactory blockFactory, IntVector selected) { + Block[] blocks = new Block[2]; + sort.toBlocks(blockFactory, blocks, 0, selected); + Releasables.close(blocks[0]); + return blocks[1]; + } + + @Override + public void enableGroupIdTracking(SeenGroupIds seen) { + // we figure out seen values from nulls on the values block + } + + @Override + public void close() { + Releasables.closeExpectNoException(sort); + } + } + + public static class SingleState implements AggregatorState { + private final GroupingState internalState; + + private SingleState(BigArrays bigArrays, int limit, boolean ascending) { + this.internalState = new GroupingState(bigArrays, limit, ascending); + } + + public void add(int value, float extra) { + internalState.add(0, value, extra); + } + + @Override + public void toIntermediate(Block[] blocks, int offset, DriverContext driverContext) { + try (var intValues = driverContext.blockFactory().newConstantIntVector(0, 1)) { + internalState.toIntermediate(blocks, offset, intValues, driverContext); + } + } + + Block toBlock(BlockFactory blockFactory) { + try (var intValues = blockFactory.newConstantIntVector(0, 1)) { + return internalState.toBlock(blockFactory, intValues); + } + } + + @Override + public void close() { + Releasables.closeExpectNoException(internalState); + } + } +} diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopIntIntAggregator.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopIntIntAggregator.java new file mode 100644 index 0000000000000..98577abc4a094 --- /dev/null +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopIntIntAggregator.java @@ -0,0 +1,140 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +package org.elasticsearch.compute.aggregation; + +// begin generated imports +import org.apache.lucene.util.BytesRef; +import org.elasticsearch.common.breaker.CircuitBreaker; +import org.elasticsearch.common.util.BigArrays; +import org.elasticsearch.compute.ann.Aggregator; +import org.elasticsearch.compute.ann.GroupingAggregator; +import org.elasticsearch.compute.ann.IntermediateState; +import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.BlockFactory; +import org.elasticsearch.compute.data.IntBlock; +import org.elasticsearch.compute.data.IntBlock; +import org.elasticsearch.compute.data.IntVector; +import org.elasticsearch.compute.data.sort.IntIntBucketedSort; +import org.elasticsearch.compute.operator.DriverContext; +import org.elasticsearch.core.Releasables; +import org.elasticsearch.search.sort.SortOrder; +// end generated imports + +/** + * Aggregates the top N field values for int. + *

+ * This class is generated. Edit `X-TopAggregator.java.st` to edit this file. + *

+ */ +@Aggregator({ @IntermediateState(name = "top", type = "INT_BLOCK"), @IntermediateState(name = "extra", type = "INT_BLOCK") }) +@GroupingAggregator +class TopIntIntAggregator { + public static SingleState initSingle(BigArrays bigArrays, int limit, boolean ascending) { + return new SingleState(bigArrays, limit, ascending); + } + + public static void combine(SingleState state, int v, int extra) { + state.add(v, extra); + } + + public static void combineIntermediate(SingleState state, IntBlock values, IntBlock extras) { + int start = values.getFirstValueIndex(0); + int end = start + values.getValueCount(0); + for (int i = start; i < end; i++) { + combine(state, values.getInt(i), extras.getInt(i)); + } + } + + public static Block evaluateFinal(SingleState state, DriverContext driverContext) { + return state.toBlock(driverContext.blockFactory()); + } + + public static GroupingState initGrouping(BigArrays bigArrays, int limit, boolean ascending) { + return new GroupingState(bigArrays, limit, ascending); + } + + public static void combine(GroupingState state, int groupId, int v, int extra) { + state.add(groupId, v, extra); + } + + public static void combineIntermediate(GroupingState state, int groupId, IntBlock values, IntBlock extras, int valuesPosition) { + int start = values.getFirstValueIndex(valuesPosition); + int end = start + values.getValueCount(valuesPosition); + for (int i = start; i < end; i++) { + combine(state, groupId, values.getInt(i), extras.getInt(i)); + } + } + + public static Block evaluateFinal(GroupingState state, IntVector selected, GroupingAggregatorEvaluationContext ctx) { + return state.toBlock(ctx.blockFactory(), selected); + } + + public static class GroupingState implements GroupingAggregatorState { + private final IntIntBucketedSort sort; + + private GroupingState(BigArrays bigArrays, int limit, boolean ascending) { + this.sort = new IntIntBucketedSort(bigArrays, ascending ? SortOrder.ASC : SortOrder.DESC, limit); + } + + public void add(int groupId, int value, int extra) { + sort.collect(value, extra, groupId); + } + + @Override + public void toIntermediate(Block[] blocks, int offset, IntVector selected, DriverContext driverContext) { + sort.toBlocks(driverContext.blockFactory(), blocks, offset, selected); + } + + Block toBlock(BlockFactory blockFactory, IntVector selected) { + Block[] blocks = new Block[2]; + sort.toBlocks(blockFactory, blocks, 0, selected); + Releasables.close(blocks[0]); + return blocks[1]; + } + + @Override + public void enableGroupIdTracking(SeenGroupIds seen) { + // we figure out seen values from nulls on the values block + } + + @Override + public void close() { + Releasables.closeExpectNoException(sort); + } + } + + public static class SingleState implements AggregatorState { + private final GroupingState internalState; + + private SingleState(BigArrays bigArrays, int limit, boolean ascending) { + this.internalState = new GroupingState(bigArrays, limit, ascending); + } + + public void add(int value, int extra) { + internalState.add(0, value, extra); + } + + @Override + public void toIntermediate(Block[] blocks, int offset, DriverContext driverContext) { + try (var intValues = driverContext.blockFactory().newConstantIntVector(0, 1)) { + internalState.toIntermediate(blocks, offset, intValues, driverContext); + } + } + + Block toBlock(BlockFactory blockFactory) { + try (var intValues = blockFactory.newConstantIntVector(0, 1)) { + return internalState.toBlock(blockFactory, intValues); + } + } + + @Override + public void close() { + Releasables.closeExpectNoException(internalState); + } + } +} diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopIntLongAggregator.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopIntLongAggregator.java new file mode 100644 index 0000000000000..823928bcf09bf --- /dev/null +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopIntLongAggregator.java @@ -0,0 +1,140 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +package org.elasticsearch.compute.aggregation; + +// begin generated imports +import org.apache.lucene.util.BytesRef; +import org.elasticsearch.common.breaker.CircuitBreaker; +import org.elasticsearch.common.util.BigArrays; +import org.elasticsearch.compute.ann.Aggregator; +import org.elasticsearch.compute.ann.GroupingAggregator; +import org.elasticsearch.compute.ann.IntermediateState; +import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.BlockFactory; +import org.elasticsearch.compute.data.IntBlock; +import org.elasticsearch.compute.data.LongBlock; +import org.elasticsearch.compute.data.IntVector; +import org.elasticsearch.compute.data.sort.IntLongBucketedSort; +import org.elasticsearch.compute.operator.DriverContext; +import org.elasticsearch.core.Releasables; +import org.elasticsearch.search.sort.SortOrder; +// end generated imports + +/** + * Aggregates the top N field values for int. + *

+ * This class is generated. Edit `X-TopAggregator.java.st` to edit this file. + *

+ */ +@Aggregator({ @IntermediateState(name = "top", type = "INT_BLOCK"), @IntermediateState(name = "extra", type = "LONG_BLOCK") }) +@GroupingAggregator +class TopIntLongAggregator { + public static SingleState initSingle(BigArrays bigArrays, int limit, boolean ascending) { + return new SingleState(bigArrays, limit, ascending); + } + + public static void combine(SingleState state, int v, long extra) { + state.add(v, extra); + } + + public static void combineIntermediate(SingleState state, IntBlock values, LongBlock extras) { + int start = values.getFirstValueIndex(0); + int end = start + values.getValueCount(0); + for (int i = start; i < end; i++) { + combine(state, values.getInt(i), extras.getLong(i)); + } + } + + public static Block evaluateFinal(SingleState state, DriverContext driverContext) { + return state.toBlock(driverContext.blockFactory()); + } + + public static GroupingState initGrouping(BigArrays bigArrays, int limit, boolean ascending) { + return new GroupingState(bigArrays, limit, ascending); + } + + public static void combine(GroupingState state, int groupId, int v, long extra) { + state.add(groupId, v, extra); + } + + public static void combineIntermediate(GroupingState state, int groupId, IntBlock values, LongBlock extras, int valuesPosition) { + int start = values.getFirstValueIndex(valuesPosition); + int end = start + values.getValueCount(valuesPosition); + for (int i = start; i < end; i++) { + combine(state, groupId, values.getInt(i), extras.getLong(i)); + } + } + + public static Block evaluateFinal(GroupingState state, IntVector selected, GroupingAggregatorEvaluationContext ctx) { + return state.toBlock(ctx.blockFactory(), selected); + } + + public static class GroupingState implements GroupingAggregatorState { + private final IntLongBucketedSort sort; + + private GroupingState(BigArrays bigArrays, int limit, boolean ascending) { + this.sort = new IntLongBucketedSort(bigArrays, ascending ? SortOrder.ASC : SortOrder.DESC, limit); + } + + public void add(int groupId, int value, long extra) { + sort.collect(value, extra, groupId); + } + + @Override + public void toIntermediate(Block[] blocks, int offset, IntVector selected, DriverContext driverContext) { + sort.toBlocks(driverContext.blockFactory(), blocks, offset, selected); + } + + Block toBlock(BlockFactory blockFactory, IntVector selected) { + Block[] blocks = new Block[2]; + sort.toBlocks(blockFactory, blocks, 0, selected); + Releasables.close(blocks[0]); + return blocks[1]; + } + + @Override + public void enableGroupIdTracking(SeenGroupIds seen) { + // we figure out seen values from nulls on the values block + } + + @Override + public void close() { + Releasables.closeExpectNoException(sort); + } + } + + public static class SingleState implements AggregatorState { + private final GroupingState internalState; + + private SingleState(BigArrays bigArrays, int limit, boolean ascending) { + this.internalState = new GroupingState(bigArrays, limit, ascending); + } + + public void add(int value, long extra) { + internalState.add(0, value, extra); + } + + @Override + public void toIntermediate(Block[] blocks, int offset, DriverContext driverContext) { + try (var intValues = driverContext.blockFactory().newConstantIntVector(0, 1)) { + internalState.toIntermediate(blocks, offset, intValues, driverContext); + } + } + + Block toBlock(BlockFactory blockFactory) { + try (var intValues = blockFactory.newConstantIntVector(0, 1)) { + return internalState.toBlock(blockFactory, intValues); + } + } + + @Override + public void close() { + Releasables.closeExpectNoException(internalState); + } + } +} diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopIpAggregator.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopIpAggregator.java index 831f573cb3cd0..118aa86b43dbe 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopIpAggregator.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopIpAggregator.java @@ -18,7 +18,6 @@ import org.elasticsearch.compute.data.BlockFactory; import org.elasticsearch.compute.data.BytesRefBlock; import org.elasticsearch.compute.data.IntVector; -import org.elasticsearch.compute.data.BytesRefBlock; import org.elasticsearch.compute.data.sort.IpBucketedSort; import org.elasticsearch.compute.operator.DriverContext; import org.elasticsearch.core.Releasables; @@ -120,7 +119,9 @@ public void add(BytesRef value) { @Override public void toIntermediate(Block[] blocks, int offset, DriverContext driverContext) { - blocks[offset] = toBlock(driverContext.blockFactory()); + try (var intValues = driverContext.blockFactory().newConstantIntVector(0, 1)) { + internalState.toIntermediate(blocks, offset, intValues, driverContext); + } } Block toBlock(BlockFactory blockFactory) { diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopLongAggregator.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopLongAggregator.java index a31ee1afd8a07..a066ac3d779e0 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopLongAggregator.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopLongAggregator.java @@ -18,7 +18,6 @@ import org.elasticsearch.compute.data.BlockFactory; import org.elasticsearch.compute.data.LongBlock; import org.elasticsearch.compute.data.IntVector; -import org.elasticsearch.compute.data.LongBlock; import org.elasticsearch.compute.data.sort.LongBucketedSort; import org.elasticsearch.compute.operator.DriverContext; import org.elasticsearch.core.Releasables; @@ -118,7 +117,9 @@ public void add(long value) { @Override public void toIntermediate(Block[] blocks, int offset, DriverContext driverContext) { - blocks[offset] = toBlock(driverContext.blockFactory()); + try (var intValues = driverContext.blockFactory().newConstantIntVector(0, 1)) { + internalState.toIntermediate(blocks, offset, intValues, driverContext); + } } Block toBlock(BlockFactory blockFactory) { diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopLongDoubleAggregator.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopLongDoubleAggregator.java new file mode 100644 index 0000000000000..a8c1c56adb95b --- /dev/null +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopLongDoubleAggregator.java @@ -0,0 +1,140 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +package org.elasticsearch.compute.aggregation; + +// begin generated imports +import org.apache.lucene.util.BytesRef; +import org.elasticsearch.common.breaker.CircuitBreaker; +import org.elasticsearch.common.util.BigArrays; +import org.elasticsearch.compute.ann.Aggregator; +import org.elasticsearch.compute.ann.GroupingAggregator; +import org.elasticsearch.compute.ann.IntermediateState; +import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.BlockFactory; +import org.elasticsearch.compute.data.LongBlock; +import org.elasticsearch.compute.data.DoubleBlock; +import org.elasticsearch.compute.data.IntVector; +import org.elasticsearch.compute.data.sort.LongDoubleBucketedSort; +import org.elasticsearch.compute.operator.DriverContext; +import org.elasticsearch.core.Releasables; +import org.elasticsearch.search.sort.SortOrder; +// end generated imports + +/** + * Aggregates the top N field values for long. + *

+ * This class is generated. Edit `X-TopAggregator.java.st` to edit this file. + *

+ */ +@Aggregator({ @IntermediateState(name = "top", type = "LONG_BLOCK"), @IntermediateState(name = "extra", type = "DOUBLE_BLOCK") }) +@GroupingAggregator +class TopLongDoubleAggregator { + public static SingleState initSingle(BigArrays bigArrays, int limit, boolean ascending) { + return new SingleState(bigArrays, limit, ascending); + } + + public static void combine(SingleState state, long v, double extra) { + state.add(v, extra); + } + + public static void combineIntermediate(SingleState state, LongBlock values, DoubleBlock extras) { + int start = values.getFirstValueIndex(0); + int end = start + values.getValueCount(0); + for (int i = start; i < end; i++) { + combine(state, values.getLong(i), extras.getDouble(i)); + } + } + + public static Block evaluateFinal(SingleState state, DriverContext driverContext) { + return state.toBlock(driverContext.blockFactory()); + } + + public static GroupingState initGrouping(BigArrays bigArrays, int limit, boolean ascending) { + return new GroupingState(bigArrays, limit, ascending); + } + + public static void combine(GroupingState state, int groupId, long v, double extra) { + state.add(groupId, v, extra); + } + + public static void combineIntermediate(GroupingState state, int groupId, LongBlock values, DoubleBlock extras, int valuesPosition) { + int start = values.getFirstValueIndex(valuesPosition); + int end = start + values.getValueCount(valuesPosition); + for (int i = start; i < end; i++) { + combine(state, groupId, values.getLong(i), extras.getDouble(i)); + } + } + + public static Block evaluateFinal(GroupingState state, IntVector selected, GroupingAggregatorEvaluationContext ctx) { + return state.toBlock(ctx.blockFactory(), selected); + } + + public static class GroupingState implements GroupingAggregatorState { + private final LongDoubleBucketedSort sort; + + private GroupingState(BigArrays bigArrays, int limit, boolean ascending) { + this.sort = new LongDoubleBucketedSort(bigArrays, ascending ? SortOrder.ASC : SortOrder.DESC, limit); + } + + public void add(int groupId, long value, double extra) { + sort.collect(value, extra, groupId); + } + + @Override + public void toIntermediate(Block[] blocks, int offset, IntVector selected, DriverContext driverContext) { + sort.toBlocks(driverContext.blockFactory(), blocks, offset, selected); + } + + Block toBlock(BlockFactory blockFactory, IntVector selected) { + Block[] blocks = new Block[2]; + sort.toBlocks(blockFactory, blocks, 0, selected); + Releasables.close(blocks[0]); + return blocks[1]; + } + + @Override + public void enableGroupIdTracking(SeenGroupIds seen) { + // we figure out seen values from nulls on the values block + } + + @Override + public void close() { + Releasables.closeExpectNoException(sort); + } + } + + public static class SingleState implements AggregatorState { + private final GroupingState internalState; + + private SingleState(BigArrays bigArrays, int limit, boolean ascending) { + this.internalState = new GroupingState(bigArrays, limit, ascending); + } + + public void add(long value, double extra) { + internalState.add(0, value, extra); + } + + @Override + public void toIntermediate(Block[] blocks, int offset, DriverContext driverContext) { + try (var intValues = driverContext.blockFactory().newConstantIntVector(0, 1)) { + internalState.toIntermediate(blocks, offset, intValues, driverContext); + } + } + + Block toBlock(BlockFactory blockFactory) { + try (var intValues = blockFactory.newConstantIntVector(0, 1)) { + return internalState.toBlock(blockFactory, intValues); + } + } + + @Override + public void close() { + Releasables.closeExpectNoException(internalState); + } + } +} diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopLongFloatAggregator.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopLongFloatAggregator.java new file mode 100644 index 0000000000000..dce908d0adc28 --- /dev/null +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopLongFloatAggregator.java @@ -0,0 +1,140 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +package org.elasticsearch.compute.aggregation; + +// begin generated imports +import org.apache.lucene.util.BytesRef; +import org.elasticsearch.common.breaker.CircuitBreaker; +import org.elasticsearch.common.util.BigArrays; +import org.elasticsearch.compute.ann.Aggregator; +import org.elasticsearch.compute.ann.GroupingAggregator; +import org.elasticsearch.compute.ann.IntermediateState; +import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.BlockFactory; +import org.elasticsearch.compute.data.LongBlock; +import org.elasticsearch.compute.data.FloatBlock; +import org.elasticsearch.compute.data.IntVector; +import org.elasticsearch.compute.data.sort.LongFloatBucketedSort; +import org.elasticsearch.compute.operator.DriverContext; +import org.elasticsearch.core.Releasables; +import org.elasticsearch.search.sort.SortOrder; +// end generated imports + +/** + * Aggregates the top N field values for long. + *

+ * This class is generated. Edit `X-TopAggregator.java.st` to edit this file. + *

+ */ +@Aggregator({ @IntermediateState(name = "top", type = "LONG_BLOCK"), @IntermediateState(name = "extra", type = "FLOAT_BLOCK") }) +@GroupingAggregator +class TopLongFloatAggregator { + public static SingleState initSingle(BigArrays bigArrays, int limit, boolean ascending) { + return new SingleState(bigArrays, limit, ascending); + } + + public static void combine(SingleState state, long v, float extra) { + state.add(v, extra); + } + + public static void combineIntermediate(SingleState state, LongBlock values, FloatBlock extras) { + int start = values.getFirstValueIndex(0); + int end = start + values.getValueCount(0); + for (int i = start; i < end; i++) { + combine(state, values.getLong(i), extras.getFloat(i)); + } + } + + public static Block evaluateFinal(SingleState state, DriverContext driverContext) { + return state.toBlock(driverContext.blockFactory()); + } + + public static GroupingState initGrouping(BigArrays bigArrays, int limit, boolean ascending) { + return new GroupingState(bigArrays, limit, ascending); + } + + public static void combine(GroupingState state, int groupId, long v, float extra) { + state.add(groupId, v, extra); + } + + public static void combineIntermediate(GroupingState state, int groupId, LongBlock values, FloatBlock extras, int valuesPosition) { + int start = values.getFirstValueIndex(valuesPosition); + int end = start + values.getValueCount(valuesPosition); + for (int i = start; i < end; i++) { + combine(state, groupId, values.getLong(i), extras.getFloat(i)); + } + } + + public static Block evaluateFinal(GroupingState state, IntVector selected, GroupingAggregatorEvaluationContext ctx) { + return state.toBlock(ctx.blockFactory(), selected); + } + + public static class GroupingState implements GroupingAggregatorState { + private final LongFloatBucketedSort sort; + + private GroupingState(BigArrays bigArrays, int limit, boolean ascending) { + this.sort = new LongFloatBucketedSort(bigArrays, ascending ? SortOrder.ASC : SortOrder.DESC, limit); + } + + public void add(int groupId, long value, float extra) { + sort.collect(value, extra, groupId); + } + + @Override + public void toIntermediate(Block[] blocks, int offset, IntVector selected, DriverContext driverContext) { + sort.toBlocks(driverContext.blockFactory(), blocks, offset, selected); + } + + Block toBlock(BlockFactory blockFactory, IntVector selected) { + Block[] blocks = new Block[2]; + sort.toBlocks(blockFactory, blocks, 0, selected); + Releasables.close(blocks[0]); + return blocks[1]; + } + + @Override + public void enableGroupIdTracking(SeenGroupIds seen) { + // we figure out seen values from nulls on the values block + } + + @Override + public void close() { + Releasables.closeExpectNoException(sort); + } + } + + public static class SingleState implements AggregatorState { + private final GroupingState internalState; + + private SingleState(BigArrays bigArrays, int limit, boolean ascending) { + this.internalState = new GroupingState(bigArrays, limit, ascending); + } + + public void add(long value, float extra) { + internalState.add(0, value, extra); + } + + @Override + public void toIntermediate(Block[] blocks, int offset, DriverContext driverContext) { + try (var intValues = driverContext.blockFactory().newConstantIntVector(0, 1)) { + internalState.toIntermediate(blocks, offset, intValues, driverContext); + } + } + + Block toBlock(BlockFactory blockFactory) { + try (var intValues = blockFactory.newConstantIntVector(0, 1)) { + return internalState.toBlock(blockFactory, intValues); + } + } + + @Override + public void close() { + Releasables.closeExpectNoException(internalState); + } + } +} diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopLongIntAggregator.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopLongIntAggregator.java new file mode 100644 index 0000000000000..495dea450d119 --- /dev/null +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopLongIntAggregator.java @@ -0,0 +1,140 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +package org.elasticsearch.compute.aggregation; + +// begin generated imports +import org.apache.lucene.util.BytesRef; +import org.elasticsearch.common.breaker.CircuitBreaker; +import org.elasticsearch.common.util.BigArrays; +import org.elasticsearch.compute.ann.Aggregator; +import org.elasticsearch.compute.ann.GroupingAggregator; +import org.elasticsearch.compute.ann.IntermediateState; +import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.BlockFactory; +import org.elasticsearch.compute.data.LongBlock; +import org.elasticsearch.compute.data.IntBlock; +import org.elasticsearch.compute.data.IntVector; +import org.elasticsearch.compute.data.sort.LongIntBucketedSort; +import org.elasticsearch.compute.operator.DriverContext; +import org.elasticsearch.core.Releasables; +import org.elasticsearch.search.sort.SortOrder; +// end generated imports + +/** + * Aggregates the top N field values for long. + *

+ * This class is generated. Edit `X-TopAggregator.java.st` to edit this file. + *

+ */ +@Aggregator({ @IntermediateState(name = "top", type = "LONG_BLOCK"), @IntermediateState(name = "extra", type = "INT_BLOCK") }) +@GroupingAggregator +class TopLongIntAggregator { + public static SingleState initSingle(BigArrays bigArrays, int limit, boolean ascending) { + return new SingleState(bigArrays, limit, ascending); + } + + public static void combine(SingleState state, long v, int extra) { + state.add(v, extra); + } + + public static void combineIntermediate(SingleState state, LongBlock values, IntBlock extras) { + int start = values.getFirstValueIndex(0); + int end = start + values.getValueCount(0); + for (int i = start; i < end; i++) { + combine(state, values.getLong(i), extras.getInt(i)); + } + } + + public static Block evaluateFinal(SingleState state, DriverContext driverContext) { + return state.toBlock(driverContext.blockFactory()); + } + + public static GroupingState initGrouping(BigArrays bigArrays, int limit, boolean ascending) { + return new GroupingState(bigArrays, limit, ascending); + } + + public static void combine(GroupingState state, int groupId, long v, int extra) { + state.add(groupId, v, extra); + } + + public static void combineIntermediate(GroupingState state, int groupId, LongBlock values, IntBlock extras, int valuesPosition) { + int start = values.getFirstValueIndex(valuesPosition); + int end = start + values.getValueCount(valuesPosition); + for (int i = start; i < end; i++) { + combine(state, groupId, values.getLong(i), extras.getInt(i)); + } + } + + public static Block evaluateFinal(GroupingState state, IntVector selected, GroupingAggregatorEvaluationContext ctx) { + return state.toBlock(ctx.blockFactory(), selected); + } + + public static class GroupingState implements GroupingAggregatorState { + private final LongIntBucketedSort sort; + + private GroupingState(BigArrays bigArrays, int limit, boolean ascending) { + this.sort = new LongIntBucketedSort(bigArrays, ascending ? SortOrder.ASC : SortOrder.DESC, limit); + } + + public void add(int groupId, long value, int extra) { + sort.collect(value, extra, groupId); + } + + @Override + public void toIntermediate(Block[] blocks, int offset, IntVector selected, DriverContext driverContext) { + sort.toBlocks(driverContext.blockFactory(), blocks, offset, selected); + } + + Block toBlock(BlockFactory blockFactory, IntVector selected) { + Block[] blocks = new Block[2]; + sort.toBlocks(blockFactory, blocks, 0, selected); + Releasables.close(blocks[0]); + return blocks[1]; + } + + @Override + public void enableGroupIdTracking(SeenGroupIds seen) { + // we figure out seen values from nulls on the values block + } + + @Override + public void close() { + Releasables.closeExpectNoException(sort); + } + } + + public static class SingleState implements AggregatorState { + private final GroupingState internalState; + + private SingleState(BigArrays bigArrays, int limit, boolean ascending) { + this.internalState = new GroupingState(bigArrays, limit, ascending); + } + + public void add(long value, int extra) { + internalState.add(0, value, extra); + } + + @Override + public void toIntermediate(Block[] blocks, int offset, DriverContext driverContext) { + try (var intValues = driverContext.blockFactory().newConstantIntVector(0, 1)) { + internalState.toIntermediate(blocks, offset, intValues, driverContext); + } + } + + Block toBlock(BlockFactory blockFactory) { + try (var intValues = blockFactory.newConstantIntVector(0, 1)) { + return internalState.toBlock(blockFactory, intValues); + } + } + + @Override + public void close() { + Releasables.closeExpectNoException(internalState); + } + } +} diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopLongLongAggregator.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopLongLongAggregator.java new file mode 100644 index 0000000000000..e47e478ac0dac --- /dev/null +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopLongLongAggregator.java @@ -0,0 +1,140 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +package org.elasticsearch.compute.aggregation; + +// begin generated imports +import org.apache.lucene.util.BytesRef; +import org.elasticsearch.common.breaker.CircuitBreaker; +import org.elasticsearch.common.util.BigArrays; +import org.elasticsearch.compute.ann.Aggregator; +import org.elasticsearch.compute.ann.GroupingAggregator; +import org.elasticsearch.compute.ann.IntermediateState; +import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.BlockFactory; +import org.elasticsearch.compute.data.LongBlock; +import org.elasticsearch.compute.data.LongBlock; +import org.elasticsearch.compute.data.IntVector; +import org.elasticsearch.compute.data.sort.LongLongBucketedSort; +import org.elasticsearch.compute.operator.DriverContext; +import org.elasticsearch.core.Releasables; +import org.elasticsearch.search.sort.SortOrder; +// end generated imports + +/** + * Aggregates the top N field values for long. + *

+ * This class is generated. Edit `X-TopAggregator.java.st` to edit this file. + *

+ */ +@Aggregator({ @IntermediateState(name = "top", type = "LONG_BLOCK"), @IntermediateState(name = "extra", type = "LONG_BLOCK") }) +@GroupingAggregator +class TopLongLongAggregator { + public static SingleState initSingle(BigArrays bigArrays, int limit, boolean ascending) { + return new SingleState(bigArrays, limit, ascending); + } + + public static void combine(SingleState state, long v, long extra) { + state.add(v, extra); + } + + public static void combineIntermediate(SingleState state, LongBlock values, LongBlock extras) { + int start = values.getFirstValueIndex(0); + int end = start + values.getValueCount(0); + for (int i = start; i < end; i++) { + combine(state, values.getLong(i), extras.getLong(i)); + } + } + + public static Block evaluateFinal(SingleState state, DriverContext driverContext) { + return state.toBlock(driverContext.blockFactory()); + } + + public static GroupingState initGrouping(BigArrays bigArrays, int limit, boolean ascending) { + return new GroupingState(bigArrays, limit, ascending); + } + + public static void combine(GroupingState state, int groupId, long v, long extra) { + state.add(groupId, v, extra); + } + + public static void combineIntermediate(GroupingState state, int groupId, LongBlock values, LongBlock extras, int valuesPosition) { + int start = values.getFirstValueIndex(valuesPosition); + int end = start + values.getValueCount(valuesPosition); + for (int i = start; i < end; i++) { + combine(state, groupId, values.getLong(i), extras.getLong(i)); + } + } + + public static Block evaluateFinal(GroupingState state, IntVector selected, GroupingAggregatorEvaluationContext ctx) { + return state.toBlock(ctx.blockFactory(), selected); + } + + public static class GroupingState implements GroupingAggregatorState { + private final LongLongBucketedSort sort; + + private GroupingState(BigArrays bigArrays, int limit, boolean ascending) { + this.sort = new LongLongBucketedSort(bigArrays, ascending ? SortOrder.ASC : SortOrder.DESC, limit); + } + + public void add(int groupId, long value, long extra) { + sort.collect(value, extra, groupId); + } + + @Override + public void toIntermediate(Block[] blocks, int offset, IntVector selected, DriverContext driverContext) { + sort.toBlocks(driverContext.blockFactory(), blocks, offset, selected); + } + + Block toBlock(BlockFactory blockFactory, IntVector selected) { + Block[] blocks = new Block[2]; + sort.toBlocks(blockFactory, blocks, 0, selected); + Releasables.close(blocks[0]); + return blocks[1]; + } + + @Override + public void enableGroupIdTracking(SeenGroupIds seen) { + // we figure out seen values from nulls on the values block + } + + @Override + public void close() { + Releasables.closeExpectNoException(sort); + } + } + + public static class SingleState implements AggregatorState { + private final GroupingState internalState; + + private SingleState(BigArrays bigArrays, int limit, boolean ascending) { + this.internalState = new GroupingState(bigArrays, limit, ascending); + } + + public void add(long value, long extra) { + internalState.add(0, value, extra); + } + + @Override + public void toIntermediate(Block[] blocks, int offset, DriverContext driverContext) { + try (var intValues = driverContext.blockFactory().newConstantIntVector(0, 1)) { + internalState.toIntermediate(blocks, offset, intValues, driverContext); + } + } + + Block toBlock(BlockFactory blockFactory) { + try (var intValues = blockFactory.newConstantIntVector(0, 1)) { + return internalState.toBlock(blockFactory, intValues); + } + } + + @Override + public void close() { + Releasables.closeExpectNoException(internalState); + } + } +} diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleBucketedSort.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleBucketedSort.java index c8c6701e68e4a..995cf68cd6a50 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleBucketedSort.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleBucketedSort.java @@ -23,7 +23,7 @@ import java.util.stream.IntStream; /** - * Aggregates the top N double values per bucket. + * Aggregates the top N {@code double} values per bucket. * See {@link BucketedSort} for more information. * This class is generated. Edit @{code X-BucketedSort.java.st} instead of this file. */ @@ -162,12 +162,7 @@ public void merge(int groupId, DoubleBucketedSort other, int otherGroupId) { */ public Block toBlock(BlockFactory blockFactory, IntVector selected) { // Check if the selected groups are all empty, to avoid allocating extra memory - if (IntStream.range(0, selected.getPositionCount()).map(selected::getInt).noneMatch(bucket -> { - var bounds = this.getBucketValuesIndexes(bucket); - var size = bounds.v2() - bounds.v1(); - - return size > 0; - })) { + if (allSelectedGroupsAreEmpty(selected)) { return blockFactory.newConstantNullBlock(selected.getPositionCount()); } @@ -185,7 +180,7 @@ public Block toBlock(BlockFactory blockFactory, IntVector selected) { } if (size == 1) { - builder.appendDouble(values.get(bounds.v1())); + builder.appendDouble(values.get(rootIndex)); continue; } @@ -197,7 +192,7 @@ public Block toBlock(BlockFactory blockFactory, IntVector selected) { builder.beginPositionEntry(); for (int i = 0; i < size; i++) { - builder.appendDouble(values.get(bounds.v1() + i)); + builder.appendDouble(values.get(rootIndex + i)); } builder.endPositionEntry(); } @@ -205,6 +200,17 @@ public Block toBlock(BlockFactory blockFactory, IntVector selected) { } } + /** + * Checks if the selected groups are all empty. + */ + private boolean allSelectedGroupsAreEmpty(IntVector selected) { + return IntStream.range(0, selected.getPositionCount()).map(selected::getInt).noneMatch(bucket -> { + var bounds = this.getBucketValuesIndexes(bucket); + var size = bounds.v2() - bounds.v1(); + return size > 0; + }); + } + /** * Is this bucket a min heap {@code true} or in gathering mode {@code false}? */ @@ -234,7 +240,8 @@ private void setNextGatherOffset(long rootIndex, int offset) { * {@link SortOrder#ASC} and "higher" for {@link SortOrder#DESC}. */ private boolean betterThan(double lhs, double rhs) { - return getOrder().reverseMul() * Double.compare(lhs, rhs) < 0; + int res = Double.compare(lhs, rhs); + return getOrder().reverseMul() * res < 0; } /** diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleDoubleBucketedSort.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleDoubleBucketedSort.java new file mode 100644 index 0000000000000..0794a3712ee1d --- /dev/null +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleDoubleBucketedSort.java @@ -0,0 +1,406 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +package org.elasticsearch.compute.data.sort; + +import org.elasticsearch.common.util.BigArrays; +import org.elasticsearch.common.util.BitArray; +import org.elasticsearch.common.util.DoubleArray; +import org.elasticsearch.common.util.DoubleArray; +import org.elasticsearch.common.util.PageCacheRecycler; +import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.BlockFactory; +import org.elasticsearch.compute.data.IntVector; +import org.elasticsearch.core.Releasable; +import org.elasticsearch.core.Releasables; +import org.elasticsearch.core.Tuple; +import org.elasticsearch.search.sort.BucketedSort; +import org.elasticsearch.search.sort.SortOrder; + +import java.util.stream.IntStream; + +/** + * Aggregates the top N {@code double} values per bucket. + * See {@link BucketedSort} for more information. + * This class is generated. Edit @{code X-BucketedSort.java.st} instead of this file. + */ +public class DoubleDoubleBucketedSort implements Releasable { + + private final BigArrays bigArrays; + private final SortOrder order; + private final int bucketSize; + /** + * {@code true} if the bucket is in heap mode, {@code false} if + * it is still gathering. + */ + private final BitArray heapMode; + /** + * An array containing all the values on all buckets. The structure is as follows: + *

+ * For each bucket, there are bucketSize elements, based on the bucket id (0, 1, 2...). + * Then, for each bucket, it can be in 2 states: + *

+ * + */ + private DoubleArray values; + private DoubleArray extraValues; + + public DoubleDoubleBucketedSort(BigArrays bigArrays, SortOrder order, int bucketSize) { + this.bigArrays = bigArrays; + this.order = order; + this.bucketSize = bucketSize; + heapMode = new BitArray(0, bigArrays); + + boolean success = false; + try { + values = bigArrays.newDoubleArray(0, false); + extraValues = bigArrays.newDoubleArray(0, false); + success = true; + } finally { + if (success == false) { + close(); + } + } + } + + /** + * Collects a {@code value} into a {@code bucket}. + *

+ * It may or may not be inserted in the heap, depending on if it is better than the current root. + *

+ */ + public void collect(double value, double extraValue, int bucket) { + long rootIndex = (long) bucket * bucketSize; + if (inHeapMode(bucket)) { + if (betterThan(value, values.get(rootIndex), extraValue, extraValues.get(rootIndex))) { + values.set(rootIndex, value); + extraValues.set(rootIndex, extraValue); + downHeap(rootIndex, 0, bucketSize); + } + return; + } + // Gathering mode + long requiredSize = rootIndex + bucketSize; + if (values.size() < requiredSize) { + grow(bucket); + } + int next = getNextGatherOffset(rootIndex); + assert 0 <= next && next < bucketSize + : "Expected next to be in the range of valid buckets [0 <= " + next + " < " + bucketSize + "]"; + long index = next + rootIndex; + values.set(index, value); + extraValues.set(index, extraValue); + if (next == 0) { + heapMode.set(bucket); + heapify(rootIndex, bucketSize); + } else { + setNextGatherOffset(rootIndex, next - 1); + } + } + + /** + * The order of the sort. + */ + public SortOrder getOrder() { + return order; + } + + /** + * The number of values to store per bucket. + */ + public int getBucketSize() { + return bucketSize; + } + + /** + * Get the first and last indexes (inclusive, exclusive) of the values for a bucket. + * Returns [0, 0] if the bucket has never been collected. + */ + private Tuple getBucketValuesIndexes(int bucket) { + long rootIndex = (long) bucket * bucketSize; + if (rootIndex >= values.size()) { + // We've never seen this bucket. + return Tuple.tuple(0L, 0L); + } + long start = inHeapMode(bucket) ? rootIndex : (rootIndex + getNextGatherOffset(rootIndex) + 1); + long end = rootIndex + bucketSize; + return Tuple.tuple(start, end); + } + + /** + * Merge the values from {@code other}'s {@code otherGroupId} into {@code groupId}. + */ + public void merge(int groupId, DoubleDoubleBucketedSort other, int otherGroupId) { + var otherBounds = other.getBucketValuesIndexes(otherGroupId); + + // TODO: This can be improved for heapified buckets by making use of the heap structures + for (long i = otherBounds.v1(); i < otherBounds.v2(); i++) { + collect(other.values.get(i), other.extraValues.get(i), groupId); + } + } + + /** + * Creates a block with the values from the {@code selected} groups. + */ + public void toBlocks(BlockFactory blockFactory, Block[] blocks, int offset, IntVector selected) { + // Check if the selected groups are all empty, to avoid allocating extra memory + if (allSelectedGroupsAreEmpty(selected)) { + blocks[offset] = blockFactory.newConstantNullBlock(selected.getPositionCount()); + blocks[offset + 1] = blockFactory.newConstantNullBlock(selected.getPositionCount()); + return; + } + + try ( + var builder = blockFactory.newDoubleBlockBuilder(selected.getPositionCount()); + var extraBuilder = blockFactory.newDoubleBlockBuilder(selected.getPositionCount()) + ) { + for (int s = 0; s < selected.getPositionCount(); s++) { + int bucket = selected.getInt(s); + + var bounds = getBucketValuesIndexes(bucket); + var rootIndex = bounds.v1(); + var size = bounds.v2() - bounds.v1(); + + if (size == 0) { + builder.appendNull(); + extraBuilder.appendNull(); + continue; + } + + if (size == 1) { + builder.appendDouble(values.get(rootIndex)); + extraBuilder.appendDouble(extraValues.get(rootIndex)); + continue; + } + + // If we are in the gathering mode, we need to heapify before sorting. + if (inHeapMode(bucket) == false) { + heapify(rootIndex, (int) size); + } + heapSort(rootIndex, (int) size); + + builder.beginPositionEntry(); + extraBuilder.beginPositionEntry(); + for (int i = 0; i < size; i++) { + builder.appendDouble(values.get(rootIndex + i)); + extraBuilder.appendDouble(extraValues.get(rootIndex + i)); + } + builder.endPositionEntry(); + extraBuilder.endPositionEntry(); + } + blocks[offset] = builder.build(); + blocks[offset + 1] = extraBuilder.build(); + } + } + + /** + * Checks if the selected groups are all empty. + */ + private boolean allSelectedGroupsAreEmpty(IntVector selected) { + return IntStream.range(0, selected.getPositionCount()).map(selected::getInt).noneMatch(bucket -> { + var bounds = this.getBucketValuesIndexes(bucket); + var size = bounds.v2() - bounds.v1(); + return size > 0; + }); + } + + /** + * Is this bucket a min heap {@code true} or in gathering mode {@code false}? + */ + private boolean inHeapMode(int bucket) { + return heapMode.get(bucket); + } + + /** + * Get the next index that should be "gathered" for a bucket rooted + * at {@code rootIndex}. + */ + private int getNextGatherOffset(long rootIndex) { + return (int) values.get(rootIndex); + } + + /** + * Set the next index that should be "gathered" for a bucket rooted + * at {@code rootIndex}. + */ + private void setNextGatherOffset(long rootIndex, int offset) { + values.set(rootIndex, offset); + } + + /** + * {@code true} if the entry at index {@code lhs} is "better" than + * the entry at {@code rhs}. "Better" in this means "lower" for + * {@link SortOrder#ASC} and "higher" for {@link SortOrder#DESC}. + */ + private boolean betterThan(double lhs, double rhs, double lhsExtra, double rhsExtra) { + int res = Double.compare(lhs, rhs); + if (res != 0) { + return getOrder().reverseMul() * res < 0; + } + res = Double.compare(lhsExtra, rhsExtra); + return getOrder().reverseMul() * res < 0; + } + + /** + * Swap the data at two indices. + */ + private void swap(long lhs, long rhs) { + var tmp = values.get(lhs); + values.set(lhs, values.get(rhs)); + values.set(rhs, tmp); + var tmpExtra = extraValues.get(lhs); + extraValues.set(lhs, extraValues.get(rhs)); + extraValues.set(rhs, tmpExtra); + } + + /** + * Allocate storage for more buckets and store the "next gather offset" + * for those new buckets. We always grow the storage by whole bucket's + * worth of slots at a time. We never allocate space for partial buckets. + */ + private void grow(int bucket) { + long oldMax = values.size(); + assert oldMax % bucketSize == 0; + + long newSize = BigArrays.overSize(((long) bucket + 1) * bucketSize, PageCacheRecycler.DOUBLE_PAGE_SIZE, Double.BYTES); + // Round up to the next full bucket. + newSize = (newSize + bucketSize - 1) / bucketSize; + values = bigArrays.resize(values, newSize * bucketSize); + long newExtraSize = BigArrays.overSize(((long) bucket + 1) * bucketSize, PageCacheRecycler.DOUBLE_PAGE_SIZE, Double.BYTES); + // Round up to the next full bucket. + newExtraSize = (newExtraSize + bucketSize - 1) / bucketSize; + extraValues = bigArrays.resize(extraValues, newExtraSize * bucketSize); + // Set the next gather offsets for all newly allocated buckets. + fillGatherOffsets(oldMax); + } + + /** + * Maintain the "next gather offsets" for newly allocated buckets. + */ + private void fillGatherOffsets(long startingAt) { + int nextOffset = getBucketSize() - 1; + for (long bucketRoot = startingAt; bucketRoot < values.size(); bucketRoot += getBucketSize()) { + setNextGatherOffset(bucketRoot, nextOffset); + } + } + + /** + * Heapify a bucket whose entries are in random order. + *

+ * This works by validating the heap property on each node, iterating + * "upwards", pushing any out of order parents "down". Check out the + * wikipedia + * entry on binary heaps for more about this. + *

+ *

+ * While this *looks* like it could easily be {@code O(n * log n)}, it is + * a fairly well studied algorithm attributed to Floyd. There's + * been a bunch of work that puts this at {@code O(n)}, close to 1.88n worst + * case. + *

+ * + * @param rootIndex the index the start of the bucket + */ + private void heapify(long rootIndex, int heapSize) { + int maxParent = heapSize / 2 - 1; + for (int parent = maxParent; parent >= 0; parent--) { + downHeap(rootIndex, parent, heapSize); + } + } + + /** + * Sorts all the values in the heap using heap sort algorithm. + * This runs in {@code O(n log n)} time. + * @param rootIndex index of the start of the bucket + * @param heapSize Number of values that belong to the heap. + * Can be less than bucketSize. + * In such a case, the remaining values in range + * (rootIndex + heapSize, rootIndex + bucketSize) + * are *not* considered part of the heap. + */ + private void heapSort(long rootIndex, int heapSize) { + while (heapSize > 0) { + swap(rootIndex, rootIndex + heapSize - 1); + heapSize--; + downHeap(rootIndex, 0, heapSize); + } + } + + /** + * Correct the heap invariant of a parent and its children. This + * runs in {@code O(log n)} time. + * @param rootIndex index of the start of the bucket + * @param parent Index within the bucket of the parent to check. + * For example, 0 is the "root". + * @param heapSize Number of values that belong to the heap. + * Can be less than bucketSize. + * In such a case, the remaining values in range + * (rootIndex + heapSize, rootIndex + bucketSize) + * are *not* considered part of the heap. + */ + private void downHeap(long rootIndex, int parent, int heapSize) { + while (true) { + long parentIndex = rootIndex + parent; + int worst = parent; + long worstIndex = parentIndex; + int leftChild = parent * 2 + 1; + long leftIndex = rootIndex + leftChild; + if (leftChild < heapSize) { + if (betterThan(values.get(worstIndex), values.get(leftIndex), extraValues.get(worstIndex), extraValues.get(leftIndex))) { + worst = leftChild; + worstIndex = leftIndex; + } + int rightChild = leftChild + 1; + long rightIndex = rootIndex + rightChild; + if (rightChild < heapSize + && betterThan( + values.get(worstIndex), + values.get(rightIndex), + extraValues.get(worstIndex), + extraValues.get(rightIndex) + )) { + worst = rightChild; + worstIndex = rightIndex; + } + } + if (worst == parent) { + break; + } + swap(worstIndex, parentIndex); + parent = worst; + } + } + + @Override + public final void close() { + Releasables.close(values, extraValues, heapMode); + } +} diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleFloatBucketedSort.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleFloatBucketedSort.java new file mode 100644 index 0000000000000..f86b3dfefa08f --- /dev/null +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleFloatBucketedSort.java @@ -0,0 +1,406 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +package org.elasticsearch.compute.data.sort; + +import org.elasticsearch.common.util.BigArrays; +import org.elasticsearch.common.util.BitArray; +import org.elasticsearch.common.util.FloatArray; +import org.elasticsearch.common.util.DoubleArray; +import org.elasticsearch.common.util.PageCacheRecycler; +import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.BlockFactory; +import org.elasticsearch.compute.data.IntVector; +import org.elasticsearch.core.Releasable; +import org.elasticsearch.core.Releasables; +import org.elasticsearch.core.Tuple; +import org.elasticsearch.search.sort.BucketedSort; +import org.elasticsearch.search.sort.SortOrder; + +import java.util.stream.IntStream; + +/** + * Aggregates the top N {@code double} values per bucket. + * See {@link BucketedSort} for more information. + * This class is generated. Edit @{code X-BucketedSort.java.st} instead of this file. + */ +public class DoubleFloatBucketedSort implements Releasable { + + private final BigArrays bigArrays; + private final SortOrder order; + private final int bucketSize; + /** + * {@code true} if the bucket is in heap mode, {@code false} if + * it is still gathering. + */ + private final BitArray heapMode; + /** + * An array containing all the values on all buckets. The structure is as follows: + *

+ * For each bucket, there are bucketSize elements, based on the bucket id (0, 1, 2...). + * Then, for each bucket, it can be in 2 states: + *

+ * + */ + private DoubleArray values; + private FloatArray extraValues; + + public DoubleFloatBucketedSort(BigArrays bigArrays, SortOrder order, int bucketSize) { + this.bigArrays = bigArrays; + this.order = order; + this.bucketSize = bucketSize; + heapMode = new BitArray(0, bigArrays); + + boolean success = false; + try { + values = bigArrays.newDoubleArray(0, false); + extraValues = bigArrays.newFloatArray(0, false); + success = true; + } finally { + if (success == false) { + close(); + } + } + } + + /** + * Collects a {@code value} into a {@code bucket}. + *

+ * It may or may not be inserted in the heap, depending on if it is better than the current root. + *

+ */ + public void collect(double value, float extraValue, int bucket) { + long rootIndex = (long) bucket * bucketSize; + if (inHeapMode(bucket)) { + if (betterThan(value, values.get(rootIndex), extraValue, extraValues.get(rootIndex))) { + values.set(rootIndex, value); + extraValues.set(rootIndex, extraValue); + downHeap(rootIndex, 0, bucketSize); + } + return; + } + // Gathering mode + long requiredSize = rootIndex + bucketSize; + if (values.size() < requiredSize) { + grow(bucket); + } + int next = getNextGatherOffset(rootIndex); + assert 0 <= next && next < bucketSize + : "Expected next to be in the range of valid buckets [0 <= " + next + " < " + bucketSize + "]"; + long index = next + rootIndex; + values.set(index, value); + extraValues.set(index, extraValue); + if (next == 0) { + heapMode.set(bucket); + heapify(rootIndex, bucketSize); + } else { + setNextGatherOffset(rootIndex, next - 1); + } + } + + /** + * The order of the sort. + */ + public SortOrder getOrder() { + return order; + } + + /** + * The number of values to store per bucket. + */ + public int getBucketSize() { + return bucketSize; + } + + /** + * Get the first and last indexes (inclusive, exclusive) of the values for a bucket. + * Returns [0, 0] if the bucket has never been collected. + */ + private Tuple getBucketValuesIndexes(int bucket) { + long rootIndex = (long) bucket * bucketSize; + if (rootIndex >= values.size()) { + // We've never seen this bucket. + return Tuple.tuple(0L, 0L); + } + long start = inHeapMode(bucket) ? rootIndex : (rootIndex + getNextGatherOffset(rootIndex) + 1); + long end = rootIndex + bucketSize; + return Tuple.tuple(start, end); + } + + /** + * Merge the values from {@code other}'s {@code otherGroupId} into {@code groupId}. + */ + public void merge(int groupId, DoubleFloatBucketedSort other, int otherGroupId) { + var otherBounds = other.getBucketValuesIndexes(otherGroupId); + + // TODO: This can be improved for heapified buckets by making use of the heap structures + for (long i = otherBounds.v1(); i < otherBounds.v2(); i++) { + collect(other.values.get(i), other.extraValues.get(i), groupId); + } + } + + /** + * Creates a block with the values from the {@code selected} groups. + */ + public void toBlocks(BlockFactory blockFactory, Block[] blocks, int offset, IntVector selected) { + // Check if the selected groups are all empty, to avoid allocating extra memory + if (allSelectedGroupsAreEmpty(selected)) { + blocks[offset] = blockFactory.newConstantNullBlock(selected.getPositionCount()); + blocks[offset + 1] = blockFactory.newConstantNullBlock(selected.getPositionCount()); + return; + } + + try ( + var builder = blockFactory.newDoubleBlockBuilder(selected.getPositionCount()); + var extraBuilder = blockFactory.newFloatBlockBuilder(selected.getPositionCount()) + ) { + for (int s = 0; s < selected.getPositionCount(); s++) { + int bucket = selected.getInt(s); + + var bounds = getBucketValuesIndexes(bucket); + var rootIndex = bounds.v1(); + var size = bounds.v2() - bounds.v1(); + + if (size == 0) { + builder.appendNull(); + extraBuilder.appendNull(); + continue; + } + + if (size == 1) { + builder.appendDouble(values.get(rootIndex)); + extraBuilder.appendFloat(extraValues.get(rootIndex)); + continue; + } + + // If we are in the gathering mode, we need to heapify before sorting. + if (inHeapMode(bucket) == false) { + heapify(rootIndex, (int) size); + } + heapSort(rootIndex, (int) size); + + builder.beginPositionEntry(); + extraBuilder.beginPositionEntry(); + for (int i = 0; i < size; i++) { + builder.appendDouble(values.get(rootIndex + i)); + extraBuilder.appendFloat(extraValues.get(rootIndex + i)); + } + builder.endPositionEntry(); + extraBuilder.endPositionEntry(); + } + blocks[offset] = builder.build(); + blocks[offset + 1] = extraBuilder.build(); + } + } + + /** + * Checks if the selected groups are all empty. + */ + private boolean allSelectedGroupsAreEmpty(IntVector selected) { + return IntStream.range(0, selected.getPositionCount()).map(selected::getInt).noneMatch(bucket -> { + var bounds = this.getBucketValuesIndexes(bucket); + var size = bounds.v2() - bounds.v1(); + return size > 0; + }); + } + + /** + * Is this bucket a min heap {@code true} or in gathering mode {@code false}? + */ + private boolean inHeapMode(int bucket) { + return heapMode.get(bucket); + } + + /** + * Get the next index that should be "gathered" for a bucket rooted + * at {@code rootIndex}. + */ + private int getNextGatherOffset(long rootIndex) { + return (int) values.get(rootIndex); + } + + /** + * Set the next index that should be "gathered" for a bucket rooted + * at {@code rootIndex}. + */ + private void setNextGatherOffset(long rootIndex, int offset) { + values.set(rootIndex, offset); + } + + /** + * {@code true} if the entry at index {@code lhs} is "better" than + * the entry at {@code rhs}. "Better" in this means "lower" for + * {@link SortOrder#ASC} and "higher" for {@link SortOrder#DESC}. + */ + private boolean betterThan(double lhs, double rhs, float lhsExtra, float rhsExtra) { + int res = Double.compare(lhs, rhs); + if (res != 0) { + return getOrder().reverseMul() * res < 0; + } + res = Float.compare(lhsExtra, rhsExtra); + return getOrder().reverseMul() * res < 0; + } + + /** + * Swap the data at two indices. + */ + private void swap(long lhs, long rhs) { + var tmp = values.get(lhs); + values.set(lhs, values.get(rhs)); + values.set(rhs, tmp); + var tmpExtra = extraValues.get(lhs); + extraValues.set(lhs, extraValues.get(rhs)); + extraValues.set(rhs, tmpExtra); + } + + /** + * Allocate storage for more buckets and store the "next gather offset" + * for those new buckets. We always grow the storage by whole bucket's + * worth of slots at a time. We never allocate space for partial buckets. + */ + private void grow(int bucket) { + long oldMax = values.size(); + assert oldMax % bucketSize == 0; + + long newSize = BigArrays.overSize(((long) bucket + 1) * bucketSize, PageCacheRecycler.DOUBLE_PAGE_SIZE, Double.BYTES); + // Round up to the next full bucket. + newSize = (newSize + bucketSize - 1) / bucketSize; + values = bigArrays.resize(values, newSize * bucketSize); + long newExtraSize = BigArrays.overSize(((long) bucket + 1) * bucketSize, PageCacheRecycler.FLOAT_PAGE_SIZE, Float.BYTES); + // Round up to the next full bucket. + newExtraSize = (newExtraSize + bucketSize - 1) / bucketSize; + extraValues = bigArrays.resize(extraValues, newExtraSize * bucketSize); + // Set the next gather offsets for all newly allocated buckets. + fillGatherOffsets(oldMax); + } + + /** + * Maintain the "next gather offsets" for newly allocated buckets. + */ + private void fillGatherOffsets(long startingAt) { + int nextOffset = getBucketSize() - 1; + for (long bucketRoot = startingAt; bucketRoot < values.size(); bucketRoot += getBucketSize()) { + setNextGatherOffset(bucketRoot, nextOffset); + } + } + + /** + * Heapify a bucket whose entries are in random order. + *

+ * This works by validating the heap property on each node, iterating + * "upwards", pushing any out of order parents "down". Check out the + * wikipedia + * entry on binary heaps for more about this. + *

+ *

+ * While this *looks* like it could easily be {@code O(n * log n)}, it is + * a fairly well studied algorithm attributed to Floyd. There's + * been a bunch of work that puts this at {@code O(n)}, close to 1.88n worst + * case. + *

+ * + * @param rootIndex the index the start of the bucket + */ + private void heapify(long rootIndex, int heapSize) { + int maxParent = heapSize / 2 - 1; + for (int parent = maxParent; parent >= 0; parent--) { + downHeap(rootIndex, parent, heapSize); + } + } + + /** + * Sorts all the values in the heap using heap sort algorithm. + * This runs in {@code O(n log n)} time. + * @param rootIndex index of the start of the bucket + * @param heapSize Number of values that belong to the heap. + * Can be less than bucketSize. + * In such a case, the remaining values in range + * (rootIndex + heapSize, rootIndex + bucketSize) + * are *not* considered part of the heap. + */ + private void heapSort(long rootIndex, int heapSize) { + while (heapSize > 0) { + swap(rootIndex, rootIndex + heapSize - 1); + heapSize--; + downHeap(rootIndex, 0, heapSize); + } + } + + /** + * Correct the heap invariant of a parent and its children. This + * runs in {@code O(log n)} time. + * @param rootIndex index of the start of the bucket + * @param parent Index within the bucket of the parent to check. + * For example, 0 is the "root". + * @param heapSize Number of values that belong to the heap. + * Can be less than bucketSize. + * In such a case, the remaining values in range + * (rootIndex + heapSize, rootIndex + bucketSize) + * are *not* considered part of the heap. + */ + private void downHeap(long rootIndex, int parent, int heapSize) { + while (true) { + long parentIndex = rootIndex + parent; + int worst = parent; + long worstIndex = parentIndex; + int leftChild = parent * 2 + 1; + long leftIndex = rootIndex + leftChild; + if (leftChild < heapSize) { + if (betterThan(values.get(worstIndex), values.get(leftIndex), extraValues.get(worstIndex), extraValues.get(leftIndex))) { + worst = leftChild; + worstIndex = leftIndex; + } + int rightChild = leftChild + 1; + long rightIndex = rootIndex + rightChild; + if (rightChild < heapSize + && betterThan( + values.get(worstIndex), + values.get(rightIndex), + extraValues.get(worstIndex), + extraValues.get(rightIndex) + )) { + worst = rightChild; + worstIndex = rightIndex; + } + } + if (worst == parent) { + break; + } + swap(worstIndex, parentIndex); + parent = worst; + } + } + + @Override + public final void close() { + Releasables.close(values, extraValues, heapMode); + } +} diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleIntBucketedSort.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleIntBucketedSort.java new file mode 100644 index 0000000000000..44c51b34c0d39 --- /dev/null +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleIntBucketedSort.java @@ -0,0 +1,406 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +package org.elasticsearch.compute.data.sort; + +import org.elasticsearch.common.util.BigArrays; +import org.elasticsearch.common.util.BitArray; +import org.elasticsearch.common.util.IntArray; +import org.elasticsearch.common.util.DoubleArray; +import org.elasticsearch.common.util.PageCacheRecycler; +import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.BlockFactory; +import org.elasticsearch.compute.data.IntVector; +import org.elasticsearch.core.Releasable; +import org.elasticsearch.core.Releasables; +import org.elasticsearch.core.Tuple; +import org.elasticsearch.search.sort.BucketedSort; +import org.elasticsearch.search.sort.SortOrder; + +import java.util.stream.IntStream; + +/** + * Aggregates the top N {@code double} values per bucket. + * See {@link BucketedSort} for more information. + * This class is generated. Edit @{code X-BucketedSort.java.st} instead of this file. + */ +public class DoubleIntBucketedSort implements Releasable { + + private final BigArrays bigArrays; + private final SortOrder order; + private final int bucketSize; + /** + * {@code true} if the bucket is in heap mode, {@code false} if + * it is still gathering. + */ + private final BitArray heapMode; + /** + * An array containing all the values on all buckets. The structure is as follows: + *

+ * For each bucket, there are bucketSize elements, based on the bucket id (0, 1, 2...). + * Then, for each bucket, it can be in 2 states: + *

+ *
    + *
  • + * Gather mode: All buckets start in gather mode, and remain here while they have less than bucketSize elements. + * In gather mode, the elements are stored in the array from the highest index to the lowest index. + * The lowest index contains the offset to the next slot to be filled. + *

    + * This allows us to insert elements in O(1) time. + *

    + *

    + * When the bucketSize-th element is collected, the bucket transitions to heap mode, by heapifying its contents. + *

    + *
  • + *
  • + * Heap mode: The bucket slots are organized as a min heap structure. + *

    + * The root of the heap is the minimum value in the bucket, + * which allows us to quickly discard new values that are not in the top N. + *

    + *
  • + *
+ */ + private DoubleArray values; + private IntArray extraValues; + + public DoubleIntBucketedSort(BigArrays bigArrays, SortOrder order, int bucketSize) { + this.bigArrays = bigArrays; + this.order = order; + this.bucketSize = bucketSize; + heapMode = new BitArray(0, bigArrays); + + boolean success = false; + try { + values = bigArrays.newDoubleArray(0, false); + extraValues = bigArrays.newIntArray(0, false); + success = true; + } finally { + if (success == false) { + close(); + } + } + } + + /** + * Collects a {@code value} into a {@code bucket}. + *

+ * It may or may not be inserted in the heap, depending on if it is better than the current root. + *

+ */ + public void collect(double value, int extraValue, int bucket) { + long rootIndex = (long) bucket * bucketSize; + if (inHeapMode(bucket)) { + if (betterThan(value, values.get(rootIndex), extraValue, extraValues.get(rootIndex))) { + values.set(rootIndex, value); + extraValues.set(rootIndex, extraValue); + downHeap(rootIndex, 0, bucketSize); + } + return; + } + // Gathering mode + long requiredSize = rootIndex + bucketSize; + if (values.size() < requiredSize) { + grow(bucket); + } + int next = getNextGatherOffset(rootIndex); + assert 0 <= next && next < bucketSize + : "Expected next to be in the range of valid buckets [0 <= " + next + " < " + bucketSize + "]"; + long index = next + rootIndex; + values.set(index, value); + extraValues.set(index, extraValue); + if (next == 0) { + heapMode.set(bucket); + heapify(rootIndex, bucketSize); + } else { + setNextGatherOffset(rootIndex, next - 1); + } + } + + /** + * The order of the sort. + */ + public SortOrder getOrder() { + return order; + } + + /** + * The number of values to store per bucket. + */ + public int getBucketSize() { + return bucketSize; + } + + /** + * Get the first and last indexes (inclusive, exclusive) of the values for a bucket. + * Returns [0, 0] if the bucket has never been collected. + */ + private Tuple getBucketValuesIndexes(int bucket) { + long rootIndex = (long) bucket * bucketSize; + if (rootIndex >= values.size()) { + // We've never seen this bucket. + return Tuple.tuple(0L, 0L); + } + long start = inHeapMode(bucket) ? rootIndex : (rootIndex + getNextGatherOffset(rootIndex) + 1); + long end = rootIndex + bucketSize; + return Tuple.tuple(start, end); + } + + /** + * Merge the values from {@code other}'s {@code otherGroupId} into {@code groupId}. + */ + public void merge(int groupId, DoubleIntBucketedSort other, int otherGroupId) { + var otherBounds = other.getBucketValuesIndexes(otherGroupId); + + // TODO: This can be improved for heapified buckets by making use of the heap structures + for (long i = otherBounds.v1(); i < otherBounds.v2(); i++) { + collect(other.values.get(i), other.extraValues.get(i), groupId); + } + } + + /** + * Creates a block with the values from the {@code selected} groups. + */ + public void toBlocks(BlockFactory blockFactory, Block[] blocks, int offset, IntVector selected) { + // Check if the selected groups are all empty, to avoid allocating extra memory + if (allSelectedGroupsAreEmpty(selected)) { + blocks[offset] = blockFactory.newConstantNullBlock(selected.getPositionCount()); + blocks[offset + 1] = blockFactory.newConstantNullBlock(selected.getPositionCount()); + return; + } + + try ( + var builder = blockFactory.newDoubleBlockBuilder(selected.getPositionCount()); + var extraBuilder = blockFactory.newIntBlockBuilder(selected.getPositionCount()) + ) { + for (int s = 0; s < selected.getPositionCount(); s++) { + int bucket = selected.getInt(s); + + var bounds = getBucketValuesIndexes(bucket); + var rootIndex = bounds.v1(); + var size = bounds.v2() - bounds.v1(); + + if (size == 0) { + builder.appendNull(); + extraBuilder.appendNull(); + continue; + } + + if (size == 1) { + builder.appendDouble(values.get(rootIndex)); + extraBuilder.appendInt(extraValues.get(rootIndex)); + continue; + } + + // If we are in the gathering mode, we need to heapify before sorting. + if (inHeapMode(bucket) == false) { + heapify(rootIndex, (int) size); + } + heapSort(rootIndex, (int) size); + + builder.beginPositionEntry(); + extraBuilder.beginPositionEntry(); + for (int i = 0; i < size; i++) { + builder.appendDouble(values.get(rootIndex + i)); + extraBuilder.appendInt(extraValues.get(rootIndex + i)); + } + builder.endPositionEntry(); + extraBuilder.endPositionEntry(); + } + blocks[offset] = builder.build(); + blocks[offset + 1] = extraBuilder.build(); + } + } + + /** + * Checks if the selected groups are all empty. + */ + private boolean allSelectedGroupsAreEmpty(IntVector selected) { + return IntStream.range(0, selected.getPositionCount()).map(selected::getInt).noneMatch(bucket -> { + var bounds = this.getBucketValuesIndexes(bucket); + var size = bounds.v2() - bounds.v1(); + return size > 0; + }); + } + + /** + * Is this bucket a min heap {@code true} or in gathering mode {@code false}? + */ + private boolean inHeapMode(int bucket) { + return heapMode.get(bucket); + } + + /** + * Get the next index that should be "gathered" for a bucket rooted + * at {@code rootIndex}. + */ + private int getNextGatherOffset(long rootIndex) { + return (int) values.get(rootIndex); + } + + /** + * Set the next index that should be "gathered" for a bucket rooted + * at {@code rootIndex}. + */ + private void setNextGatherOffset(long rootIndex, int offset) { + values.set(rootIndex, offset); + } + + /** + * {@code true} if the entry at index {@code lhs} is "better" than + * the entry at {@code rhs}. "Better" in this means "lower" for + * {@link SortOrder#ASC} and "higher" for {@link SortOrder#DESC}. + */ + private boolean betterThan(double lhs, double rhs, int lhsExtra, int rhsExtra) { + int res = Double.compare(lhs, rhs); + if (res != 0) { + return getOrder().reverseMul() * res < 0; + } + res = Integer.compare(lhsExtra, rhsExtra); + return getOrder().reverseMul() * res < 0; + } + + /** + * Swap the data at two indices. + */ + private void swap(long lhs, long rhs) { + var tmp = values.get(lhs); + values.set(lhs, values.get(rhs)); + values.set(rhs, tmp); + var tmpExtra = extraValues.get(lhs); + extraValues.set(lhs, extraValues.get(rhs)); + extraValues.set(rhs, tmpExtra); + } + + /** + * Allocate storage for more buckets and store the "next gather offset" + * for those new buckets. We always grow the storage by whole bucket's + * worth of slots at a time. We never allocate space for partial buckets. + */ + private void grow(int bucket) { + long oldMax = values.size(); + assert oldMax % bucketSize == 0; + + long newSize = BigArrays.overSize(((long) bucket + 1) * bucketSize, PageCacheRecycler.DOUBLE_PAGE_SIZE, Double.BYTES); + // Round up to the next full bucket. + newSize = (newSize + bucketSize - 1) / bucketSize; + values = bigArrays.resize(values, newSize * bucketSize); + long newExtraSize = BigArrays.overSize(((long) bucket + 1) * bucketSize, PageCacheRecycler.INT_PAGE_SIZE, Integer.BYTES); + // Round up to the next full bucket. + newExtraSize = (newExtraSize + bucketSize - 1) / bucketSize; + extraValues = bigArrays.resize(extraValues, newExtraSize * bucketSize); + // Set the next gather offsets for all newly allocated buckets. + fillGatherOffsets(oldMax); + } + + /** + * Maintain the "next gather offsets" for newly allocated buckets. + */ + private void fillGatherOffsets(long startingAt) { + int nextOffset = getBucketSize() - 1; + for (long bucketRoot = startingAt; bucketRoot < values.size(); bucketRoot += getBucketSize()) { + setNextGatherOffset(bucketRoot, nextOffset); + } + } + + /** + * Heapify a bucket whose entries are in random order. + *

+ * This works by validating the heap property on each node, iterating + * "upwards", pushing any out of order parents "down". Check out the + * wikipedia + * entry on binary heaps for more about this. + *

+ *

+ * While this *looks* like it could easily be {@code O(n * log n)}, it is + * a fairly well studied algorithm attributed to Floyd. There's + * been a bunch of work that puts this at {@code O(n)}, close to 1.88n worst + * case. + *

+ * + * @param rootIndex the index the start of the bucket + */ + private void heapify(long rootIndex, int heapSize) { + int maxParent = heapSize / 2 - 1; + for (int parent = maxParent; parent >= 0; parent--) { + downHeap(rootIndex, parent, heapSize); + } + } + + /** + * Sorts all the values in the heap using heap sort algorithm. + * This runs in {@code O(n log n)} time. + * @param rootIndex index of the start of the bucket + * @param heapSize Number of values that belong to the heap. + * Can be less than bucketSize. + * In such a case, the remaining values in range + * (rootIndex + heapSize, rootIndex + bucketSize) + * are *not* considered part of the heap. + */ + private void heapSort(long rootIndex, int heapSize) { + while (heapSize > 0) { + swap(rootIndex, rootIndex + heapSize - 1); + heapSize--; + downHeap(rootIndex, 0, heapSize); + } + } + + /** + * Correct the heap invariant of a parent and its children. This + * runs in {@code O(log n)} time. + * @param rootIndex index of the start of the bucket + * @param parent Index within the bucket of the parent to check. + * For example, 0 is the "root". + * @param heapSize Number of values that belong to the heap. + * Can be less than bucketSize. + * In such a case, the remaining values in range + * (rootIndex + heapSize, rootIndex + bucketSize) + * are *not* considered part of the heap. + */ + private void downHeap(long rootIndex, int parent, int heapSize) { + while (true) { + long parentIndex = rootIndex + parent; + int worst = parent; + long worstIndex = parentIndex; + int leftChild = parent * 2 + 1; + long leftIndex = rootIndex + leftChild; + if (leftChild < heapSize) { + if (betterThan(values.get(worstIndex), values.get(leftIndex), extraValues.get(worstIndex), extraValues.get(leftIndex))) { + worst = leftChild; + worstIndex = leftIndex; + } + int rightChild = leftChild + 1; + long rightIndex = rootIndex + rightChild; + if (rightChild < heapSize + && betterThan( + values.get(worstIndex), + values.get(rightIndex), + extraValues.get(worstIndex), + extraValues.get(rightIndex) + )) { + worst = rightChild; + worstIndex = rightIndex; + } + } + if (worst == parent) { + break; + } + swap(worstIndex, parentIndex); + parent = worst; + } + } + + @Override + public final void close() { + Releasables.close(values, extraValues, heapMode); + } +} diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleLongBucketedSort.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleLongBucketedSort.java new file mode 100644 index 0000000000000..519c03f59f5be --- /dev/null +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleLongBucketedSort.java @@ -0,0 +1,406 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +package org.elasticsearch.compute.data.sort; + +import org.elasticsearch.common.util.BigArrays; +import org.elasticsearch.common.util.BitArray; +import org.elasticsearch.common.util.LongArray; +import org.elasticsearch.common.util.DoubleArray; +import org.elasticsearch.common.util.PageCacheRecycler; +import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.BlockFactory; +import org.elasticsearch.compute.data.IntVector; +import org.elasticsearch.core.Releasable; +import org.elasticsearch.core.Releasables; +import org.elasticsearch.core.Tuple; +import org.elasticsearch.search.sort.BucketedSort; +import org.elasticsearch.search.sort.SortOrder; + +import java.util.stream.IntStream; + +/** + * Aggregates the top N {@code double} values per bucket. + * See {@link BucketedSort} for more information. + * This class is generated. Edit @{code X-BucketedSort.java.st} instead of this file. + */ +public class DoubleLongBucketedSort implements Releasable { + + private final BigArrays bigArrays; + private final SortOrder order; + private final int bucketSize; + /** + * {@code true} if the bucket is in heap mode, {@code false} if + * it is still gathering. + */ + private final BitArray heapMode; + /** + * An array containing all the values on all buckets. The structure is as follows: + *

+ * For each bucket, there are bucketSize elements, based on the bucket id (0, 1, 2...). + * Then, for each bucket, it can be in 2 states: + *

+ *
    + *
  • + * Gather mode: All buckets start in gather mode, and remain here while they have less than bucketSize elements. + * In gather mode, the elements are stored in the array from the highest index to the lowest index. + * The lowest index contains the offset to the next slot to be filled. + *

    + * This allows us to insert elements in O(1) time. + *

    + *

    + * When the bucketSize-th element is collected, the bucket transitions to heap mode, by heapifying its contents. + *

    + *
  • + *
  • + * Heap mode: The bucket slots are organized as a min heap structure. + *

    + * The root of the heap is the minimum value in the bucket, + * which allows us to quickly discard new values that are not in the top N. + *

    + *
  • + *
+ */ + private DoubleArray values; + private LongArray extraValues; + + public DoubleLongBucketedSort(BigArrays bigArrays, SortOrder order, int bucketSize) { + this.bigArrays = bigArrays; + this.order = order; + this.bucketSize = bucketSize; + heapMode = new BitArray(0, bigArrays); + + boolean success = false; + try { + values = bigArrays.newDoubleArray(0, false); + extraValues = bigArrays.newLongArray(0, false); + success = true; + } finally { + if (success == false) { + close(); + } + } + } + + /** + * Collects a {@code value} into a {@code bucket}. + *

+ * It may or may not be inserted in the heap, depending on if it is better than the current root. + *

+ */ + public void collect(double value, long extraValue, int bucket) { + long rootIndex = (long) bucket * bucketSize; + if (inHeapMode(bucket)) { + if (betterThan(value, values.get(rootIndex), extraValue, extraValues.get(rootIndex))) { + values.set(rootIndex, value); + extraValues.set(rootIndex, extraValue); + downHeap(rootIndex, 0, bucketSize); + } + return; + } + // Gathering mode + long requiredSize = rootIndex + bucketSize; + if (values.size() < requiredSize) { + grow(bucket); + } + int next = getNextGatherOffset(rootIndex); + assert 0 <= next && next < bucketSize + : "Expected next to be in the range of valid buckets [0 <= " + next + " < " + bucketSize + "]"; + long index = next + rootIndex; + values.set(index, value); + extraValues.set(index, extraValue); + if (next == 0) { + heapMode.set(bucket); + heapify(rootIndex, bucketSize); + } else { + setNextGatherOffset(rootIndex, next - 1); + } + } + + /** + * The order of the sort. + */ + public SortOrder getOrder() { + return order; + } + + /** + * The number of values to store per bucket. + */ + public int getBucketSize() { + return bucketSize; + } + + /** + * Get the first and last indexes (inclusive, exclusive) of the values for a bucket. + * Returns [0, 0] if the bucket has never been collected. + */ + private Tuple getBucketValuesIndexes(int bucket) { + long rootIndex = (long) bucket * bucketSize; + if (rootIndex >= values.size()) { + // We've never seen this bucket. + return Tuple.tuple(0L, 0L); + } + long start = inHeapMode(bucket) ? rootIndex : (rootIndex + getNextGatherOffset(rootIndex) + 1); + long end = rootIndex + bucketSize; + return Tuple.tuple(start, end); + } + + /** + * Merge the values from {@code other}'s {@code otherGroupId} into {@code groupId}. + */ + public void merge(int groupId, DoubleLongBucketedSort other, int otherGroupId) { + var otherBounds = other.getBucketValuesIndexes(otherGroupId); + + // TODO: This can be improved for heapified buckets by making use of the heap structures + for (long i = otherBounds.v1(); i < otherBounds.v2(); i++) { + collect(other.values.get(i), other.extraValues.get(i), groupId); + } + } + + /** + * Creates a block with the values from the {@code selected} groups. + */ + public void toBlocks(BlockFactory blockFactory, Block[] blocks, int offset, IntVector selected) { + // Check if the selected groups are all empty, to avoid allocating extra memory + if (allSelectedGroupsAreEmpty(selected)) { + blocks[offset] = blockFactory.newConstantNullBlock(selected.getPositionCount()); + blocks[offset + 1] = blockFactory.newConstantNullBlock(selected.getPositionCount()); + return; + } + + try ( + var builder = blockFactory.newDoubleBlockBuilder(selected.getPositionCount()); + var extraBuilder = blockFactory.newLongBlockBuilder(selected.getPositionCount()) + ) { + for (int s = 0; s < selected.getPositionCount(); s++) { + int bucket = selected.getInt(s); + + var bounds = getBucketValuesIndexes(bucket); + var rootIndex = bounds.v1(); + var size = bounds.v2() - bounds.v1(); + + if (size == 0) { + builder.appendNull(); + extraBuilder.appendNull(); + continue; + } + + if (size == 1) { + builder.appendDouble(values.get(rootIndex)); + extraBuilder.appendLong(extraValues.get(rootIndex)); + continue; + } + + // If we are in the gathering mode, we need to heapify before sorting. + if (inHeapMode(bucket) == false) { + heapify(rootIndex, (int) size); + } + heapSort(rootIndex, (int) size); + + builder.beginPositionEntry(); + extraBuilder.beginPositionEntry(); + for (int i = 0; i < size; i++) { + builder.appendDouble(values.get(rootIndex + i)); + extraBuilder.appendLong(extraValues.get(rootIndex + i)); + } + builder.endPositionEntry(); + extraBuilder.endPositionEntry(); + } + blocks[offset] = builder.build(); + blocks[offset + 1] = extraBuilder.build(); + } + } + + /** + * Checks if the selected groups are all empty. + */ + private boolean allSelectedGroupsAreEmpty(IntVector selected) { + return IntStream.range(0, selected.getPositionCount()).map(selected::getInt).noneMatch(bucket -> { + var bounds = this.getBucketValuesIndexes(bucket); + var size = bounds.v2() - bounds.v1(); + return size > 0; + }); + } + + /** + * Is this bucket a min heap {@code true} or in gathering mode {@code false}? + */ + private boolean inHeapMode(int bucket) { + return heapMode.get(bucket); + } + + /** + * Get the next index that should be "gathered" for a bucket rooted + * at {@code rootIndex}. + */ + private int getNextGatherOffset(long rootIndex) { + return (int) values.get(rootIndex); + } + + /** + * Set the next index that should be "gathered" for a bucket rooted + * at {@code rootIndex}. + */ + private void setNextGatherOffset(long rootIndex, int offset) { + values.set(rootIndex, offset); + } + + /** + * {@code true} if the entry at index {@code lhs} is "better" than + * the entry at {@code rhs}. "Better" in this means "lower" for + * {@link SortOrder#ASC} and "higher" for {@link SortOrder#DESC}. + */ + private boolean betterThan(double lhs, double rhs, long lhsExtra, long rhsExtra) { + int res = Double.compare(lhs, rhs); + if (res != 0) { + return getOrder().reverseMul() * res < 0; + } + res = Long.compare(lhsExtra, rhsExtra); + return getOrder().reverseMul() * res < 0; + } + + /** + * Swap the data at two indices. + */ + private void swap(long lhs, long rhs) { + var tmp = values.get(lhs); + values.set(lhs, values.get(rhs)); + values.set(rhs, tmp); + var tmpExtra = extraValues.get(lhs); + extraValues.set(lhs, extraValues.get(rhs)); + extraValues.set(rhs, tmpExtra); + } + + /** + * Allocate storage for more buckets and store the "next gather offset" + * for those new buckets. We always grow the storage by whole bucket's + * worth of slots at a time. We never allocate space for partial buckets. + */ + private void grow(int bucket) { + long oldMax = values.size(); + assert oldMax % bucketSize == 0; + + long newSize = BigArrays.overSize(((long) bucket + 1) * bucketSize, PageCacheRecycler.DOUBLE_PAGE_SIZE, Double.BYTES); + // Round up to the next full bucket. + newSize = (newSize + bucketSize - 1) / bucketSize; + values = bigArrays.resize(values, newSize * bucketSize); + long newExtraSize = BigArrays.overSize(((long) bucket + 1) * bucketSize, PageCacheRecycler.LONG_PAGE_SIZE, Long.BYTES); + // Round up to the next full bucket. + newExtraSize = (newExtraSize + bucketSize - 1) / bucketSize; + extraValues = bigArrays.resize(extraValues, newExtraSize * bucketSize); + // Set the next gather offsets for all newly allocated buckets. + fillGatherOffsets(oldMax); + } + + /** + * Maintain the "next gather offsets" for newly allocated buckets. + */ + private void fillGatherOffsets(long startingAt) { + int nextOffset = getBucketSize() - 1; + for (long bucketRoot = startingAt; bucketRoot < values.size(); bucketRoot += getBucketSize()) { + setNextGatherOffset(bucketRoot, nextOffset); + } + } + + /** + * Heapify a bucket whose entries are in random order. + *

+ * This works by validating the heap property on each node, iterating + * "upwards", pushing any out of order parents "down". Check out the + * wikipedia + * entry on binary heaps for more about this. + *

+ *

+ * While this *looks* like it could easily be {@code O(n * log n)}, it is + * a fairly well studied algorithm attributed to Floyd. There's + * been a bunch of work that puts this at {@code O(n)}, close to 1.88n worst + * case. + *

+ * + * @param rootIndex the index the start of the bucket + */ + private void heapify(long rootIndex, int heapSize) { + int maxParent = heapSize / 2 - 1; + for (int parent = maxParent; parent >= 0; parent--) { + downHeap(rootIndex, parent, heapSize); + } + } + + /** + * Sorts all the values in the heap using heap sort algorithm. + * This runs in {@code O(n log n)} time. + * @param rootIndex index of the start of the bucket + * @param heapSize Number of values that belong to the heap. + * Can be less than bucketSize. + * In such a case, the remaining values in range + * (rootIndex + heapSize, rootIndex + bucketSize) + * are *not* considered part of the heap. + */ + private void heapSort(long rootIndex, int heapSize) { + while (heapSize > 0) { + swap(rootIndex, rootIndex + heapSize - 1); + heapSize--; + downHeap(rootIndex, 0, heapSize); + } + } + + /** + * Correct the heap invariant of a parent and its children. This + * runs in {@code O(log n)} time. + * @param rootIndex index of the start of the bucket + * @param parent Index within the bucket of the parent to check. + * For example, 0 is the "root". + * @param heapSize Number of values that belong to the heap. + * Can be less than bucketSize. + * In such a case, the remaining values in range + * (rootIndex + heapSize, rootIndex + bucketSize) + * are *not* considered part of the heap. + */ + private void downHeap(long rootIndex, int parent, int heapSize) { + while (true) { + long parentIndex = rootIndex + parent; + int worst = parent; + long worstIndex = parentIndex; + int leftChild = parent * 2 + 1; + long leftIndex = rootIndex + leftChild; + if (leftChild < heapSize) { + if (betterThan(values.get(worstIndex), values.get(leftIndex), extraValues.get(worstIndex), extraValues.get(leftIndex))) { + worst = leftChild; + worstIndex = leftIndex; + } + int rightChild = leftChild + 1; + long rightIndex = rootIndex + rightChild; + if (rightChild < heapSize + && betterThan( + values.get(worstIndex), + values.get(rightIndex), + extraValues.get(worstIndex), + extraValues.get(rightIndex) + )) { + worst = rightChild; + worstIndex = rightIndex; + } + } + if (worst == parent) { + break; + } + swap(worstIndex, parentIndex); + parent = worst; + } + } + + @Override + public final void close() { + Releasables.close(values, extraValues, heapMode); + } +} diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/FloatBucketedSort.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/FloatBucketedSort.java index 4afaa818855e4..5dee9e1555526 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/FloatBucketedSort.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/FloatBucketedSort.java @@ -23,7 +23,7 @@ import java.util.stream.IntStream; /** - * Aggregates the top N float values per bucket. + * Aggregates the top N {@code float} values per bucket. * See {@link BucketedSort} for more information. * This class is generated. Edit @{code X-BucketedSort.java.st} instead of this file. */ @@ -162,12 +162,7 @@ public void merge(int groupId, FloatBucketedSort other, int otherGroupId) { */ public Block toBlock(BlockFactory blockFactory, IntVector selected) { // Check if the selected groups are all empty, to avoid allocating extra memory - if (IntStream.range(0, selected.getPositionCount()).map(selected::getInt).noneMatch(bucket -> { - var bounds = this.getBucketValuesIndexes(bucket); - var size = bounds.v2() - bounds.v1(); - - return size > 0; - })) { + if (allSelectedGroupsAreEmpty(selected)) { return blockFactory.newConstantNullBlock(selected.getPositionCount()); } @@ -185,7 +180,7 @@ public Block toBlock(BlockFactory blockFactory, IntVector selected) { } if (size == 1) { - builder.appendFloat(values.get(bounds.v1())); + builder.appendFloat(values.get(rootIndex)); continue; } @@ -197,7 +192,7 @@ public Block toBlock(BlockFactory blockFactory, IntVector selected) { builder.beginPositionEntry(); for (int i = 0; i < size; i++) { - builder.appendFloat(values.get(bounds.v1() + i)); + builder.appendFloat(values.get(rootIndex + i)); } builder.endPositionEntry(); } @@ -205,6 +200,17 @@ public Block toBlock(BlockFactory blockFactory, IntVector selected) { } } + /** + * Checks if the selected groups are all empty. + */ + private boolean allSelectedGroupsAreEmpty(IntVector selected) { + return IntStream.range(0, selected.getPositionCount()).map(selected::getInt).noneMatch(bucket -> { + var bounds = this.getBucketValuesIndexes(bucket); + var size = bounds.v2() - bounds.v1(); + return size > 0; + }); + } + /** * Is this bucket a min heap {@code true} or in gathering mode {@code false}? */ @@ -234,7 +240,8 @@ private void setNextGatherOffset(long rootIndex, int offset) { * {@link SortOrder#ASC} and "higher" for {@link SortOrder#DESC}. */ private boolean betterThan(float lhs, float rhs) { - return getOrder().reverseMul() * Float.compare(lhs, rhs) < 0; + int res = Float.compare(lhs, rhs); + return getOrder().reverseMul() * res < 0; } /** diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/FloatDoubleBucketedSort.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/FloatDoubleBucketedSort.java new file mode 100644 index 0000000000000..a09d1e5220046 --- /dev/null +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/FloatDoubleBucketedSort.java @@ -0,0 +1,406 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +package org.elasticsearch.compute.data.sort; + +import org.elasticsearch.common.util.BigArrays; +import org.elasticsearch.common.util.BitArray; +import org.elasticsearch.common.util.DoubleArray; +import org.elasticsearch.common.util.FloatArray; +import org.elasticsearch.common.util.PageCacheRecycler; +import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.BlockFactory; +import org.elasticsearch.compute.data.IntVector; +import org.elasticsearch.core.Releasable; +import org.elasticsearch.core.Releasables; +import org.elasticsearch.core.Tuple; +import org.elasticsearch.search.sort.BucketedSort; +import org.elasticsearch.search.sort.SortOrder; + +import java.util.stream.IntStream; + +/** + * Aggregates the top N {@code float} values per bucket. + * See {@link BucketedSort} for more information. + * This class is generated. Edit @{code X-BucketedSort.java.st} instead of this file. + */ +public class FloatDoubleBucketedSort implements Releasable { + + private final BigArrays bigArrays; + private final SortOrder order; + private final int bucketSize; + /** + * {@code true} if the bucket is in heap mode, {@code false} if + * it is still gathering. + */ + private final BitArray heapMode; + /** + * An array containing all the values on all buckets. The structure is as follows: + *

+ * For each bucket, there are bucketSize elements, based on the bucket id (0, 1, 2...). + * Then, for each bucket, it can be in 2 states: + *

+ *
    + *
  • + * Gather mode: All buckets start in gather mode, and remain here while they have less than bucketSize elements. + * In gather mode, the elements are stored in the array from the highest index to the lowest index. + * The lowest index contains the offset to the next slot to be filled. + *

    + * This allows us to insert elements in O(1) time. + *

    + *

    + * When the bucketSize-th element is collected, the bucket transitions to heap mode, by heapifying its contents. + *

    + *
  • + *
  • + * Heap mode: The bucket slots are organized as a min heap structure. + *

    + * The root of the heap is the minimum value in the bucket, + * which allows us to quickly discard new values that are not in the top N. + *

    + *
  • + *
+ */ + private FloatArray values; + private DoubleArray extraValues; + + public FloatDoubleBucketedSort(BigArrays bigArrays, SortOrder order, int bucketSize) { + this.bigArrays = bigArrays; + this.order = order; + this.bucketSize = bucketSize; + heapMode = new BitArray(0, bigArrays); + + boolean success = false; + try { + values = bigArrays.newFloatArray(0, false); + extraValues = bigArrays.newDoubleArray(0, false); + success = true; + } finally { + if (success == false) { + close(); + } + } + } + + /** + * Collects a {@code value} into a {@code bucket}. + *

+ * It may or may not be inserted in the heap, depending on if it is better than the current root. + *

+ */ + public void collect(float value, double extraValue, int bucket) { + long rootIndex = (long) bucket * bucketSize; + if (inHeapMode(bucket)) { + if (betterThan(value, values.get(rootIndex), extraValue, extraValues.get(rootIndex))) { + values.set(rootIndex, value); + extraValues.set(rootIndex, extraValue); + downHeap(rootIndex, 0, bucketSize); + } + return; + } + // Gathering mode + long requiredSize = rootIndex + bucketSize; + if (values.size() < requiredSize) { + grow(bucket); + } + int next = getNextGatherOffset(rootIndex); + assert 0 <= next && next < bucketSize + : "Expected next to be in the range of valid buckets [0 <= " + next + " < " + bucketSize + "]"; + long index = next + rootIndex; + values.set(index, value); + extraValues.set(index, extraValue); + if (next == 0) { + heapMode.set(bucket); + heapify(rootIndex, bucketSize); + } else { + setNextGatherOffset(rootIndex, next - 1); + } + } + + /** + * The order of the sort. + */ + public SortOrder getOrder() { + return order; + } + + /** + * The number of values to store per bucket. + */ + public int getBucketSize() { + return bucketSize; + } + + /** + * Get the first and last indexes (inclusive, exclusive) of the values for a bucket. + * Returns [0, 0] if the bucket has never been collected. + */ + private Tuple getBucketValuesIndexes(int bucket) { + long rootIndex = (long) bucket * bucketSize; + if (rootIndex >= values.size()) { + // We've never seen this bucket. + return Tuple.tuple(0L, 0L); + } + long start = inHeapMode(bucket) ? rootIndex : (rootIndex + getNextGatherOffset(rootIndex) + 1); + long end = rootIndex + bucketSize; + return Tuple.tuple(start, end); + } + + /** + * Merge the values from {@code other}'s {@code otherGroupId} into {@code groupId}. + */ + public void merge(int groupId, FloatDoubleBucketedSort other, int otherGroupId) { + var otherBounds = other.getBucketValuesIndexes(otherGroupId); + + // TODO: This can be improved for heapified buckets by making use of the heap structures + for (long i = otherBounds.v1(); i < otherBounds.v2(); i++) { + collect(other.values.get(i), other.extraValues.get(i), groupId); + } + } + + /** + * Creates a block with the values from the {@code selected} groups. + */ + public void toBlocks(BlockFactory blockFactory, Block[] blocks, int offset, IntVector selected) { + // Check if the selected groups are all empty, to avoid allocating extra memory + if (allSelectedGroupsAreEmpty(selected)) { + blocks[offset] = blockFactory.newConstantNullBlock(selected.getPositionCount()); + blocks[offset + 1] = blockFactory.newConstantNullBlock(selected.getPositionCount()); + return; + } + + try ( + var builder = blockFactory.newFloatBlockBuilder(selected.getPositionCount()); + var extraBuilder = blockFactory.newDoubleBlockBuilder(selected.getPositionCount()) + ) { + for (int s = 0; s < selected.getPositionCount(); s++) { + int bucket = selected.getInt(s); + + var bounds = getBucketValuesIndexes(bucket); + var rootIndex = bounds.v1(); + var size = bounds.v2() - bounds.v1(); + + if (size == 0) { + builder.appendNull(); + extraBuilder.appendNull(); + continue; + } + + if (size == 1) { + builder.appendFloat(values.get(rootIndex)); + extraBuilder.appendDouble(extraValues.get(rootIndex)); + continue; + } + + // If we are in the gathering mode, we need to heapify before sorting. + if (inHeapMode(bucket) == false) { + heapify(rootIndex, (int) size); + } + heapSort(rootIndex, (int) size); + + builder.beginPositionEntry(); + extraBuilder.beginPositionEntry(); + for (int i = 0; i < size; i++) { + builder.appendFloat(values.get(rootIndex + i)); + extraBuilder.appendDouble(extraValues.get(rootIndex + i)); + } + builder.endPositionEntry(); + extraBuilder.endPositionEntry(); + } + blocks[offset] = builder.build(); + blocks[offset + 1] = extraBuilder.build(); + } + } + + /** + * Checks if the selected groups are all empty. + */ + private boolean allSelectedGroupsAreEmpty(IntVector selected) { + return IntStream.range(0, selected.getPositionCount()).map(selected::getInt).noneMatch(bucket -> { + var bounds = this.getBucketValuesIndexes(bucket); + var size = bounds.v2() - bounds.v1(); + return size > 0; + }); + } + + /** + * Is this bucket a min heap {@code true} or in gathering mode {@code false}? + */ + private boolean inHeapMode(int bucket) { + return heapMode.get(bucket); + } + + /** + * Get the next index that should be "gathered" for a bucket rooted + * at {@code rootIndex}. + */ + private int getNextGatherOffset(long rootIndex) { + return (int) values.get(rootIndex); + } + + /** + * Set the next index that should be "gathered" for a bucket rooted + * at {@code rootIndex}. + */ + private void setNextGatherOffset(long rootIndex, int offset) { + values.set(rootIndex, offset); + } + + /** + * {@code true} if the entry at index {@code lhs} is "better" than + * the entry at {@code rhs}. "Better" in this means "lower" for + * {@link SortOrder#ASC} and "higher" for {@link SortOrder#DESC}. + */ + private boolean betterThan(float lhs, float rhs, double lhsExtra, double rhsExtra) { + int res = Float.compare(lhs, rhs); + if (res != 0) { + return getOrder().reverseMul() * res < 0; + } + res = Double.compare(lhsExtra, rhsExtra); + return getOrder().reverseMul() * res < 0; + } + + /** + * Swap the data at two indices. + */ + private void swap(long lhs, long rhs) { + var tmp = values.get(lhs); + values.set(lhs, values.get(rhs)); + values.set(rhs, tmp); + var tmpExtra = extraValues.get(lhs); + extraValues.set(lhs, extraValues.get(rhs)); + extraValues.set(rhs, tmpExtra); + } + + /** + * Allocate storage for more buckets and store the "next gather offset" + * for those new buckets. We always grow the storage by whole bucket's + * worth of slots at a time. We never allocate space for partial buckets. + */ + private void grow(int bucket) { + long oldMax = values.size(); + assert oldMax % bucketSize == 0; + + long newSize = BigArrays.overSize(((long) bucket + 1) * bucketSize, PageCacheRecycler.FLOAT_PAGE_SIZE, Float.BYTES); + // Round up to the next full bucket. + newSize = (newSize + bucketSize - 1) / bucketSize; + values = bigArrays.resize(values, newSize * bucketSize); + long newExtraSize = BigArrays.overSize(((long) bucket + 1) * bucketSize, PageCacheRecycler.DOUBLE_PAGE_SIZE, Double.BYTES); + // Round up to the next full bucket. + newExtraSize = (newExtraSize + bucketSize - 1) / bucketSize; + extraValues = bigArrays.resize(extraValues, newExtraSize * bucketSize); + // Set the next gather offsets for all newly allocated buckets. + fillGatherOffsets(oldMax); + } + + /** + * Maintain the "next gather offsets" for newly allocated buckets. + */ + private void fillGatherOffsets(long startingAt) { + int nextOffset = getBucketSize() - 1; + for (long bucketRoot = startingAt; bucketRoot < values.size(); bucketRoot += getBucketSize()) { + setNextGatherOffset(bucketRoot, nextOffset); + } + } + + /** + * Heapify a bucket whose entries are in random order. + *

+ * This works by validating the heap property on each node, iterating + * "upwards", pushing any out of order parents "down". Check out the + * wikipedia + * entry on binary heaps for more about this. + *

+ *

+ * While this *looks* like it could easily be {@code O(n * log n)}, it is + * a fairly well studied algorithm attributed to Floyd. There's + * been a bunch of work that puts this at {@code O(n)}, close to 1.88n worst + * case. + *

+ * + * @param rootIndex the index the start of the bucket + */ + private void heapify(long rootIndex, int heapSize) { + int maxParent = heapSize / 2 - 1; + for (int parent = maxParent; parent >= 0; parent--) { + downHeap(rootIndex, parent, heapSize); + } + } + + /** + * Sorts all the values in the heap using heap sort algorithm. + * This runs in {@code O(n log n)} time. + * @param rootIndex index of the start of the bucket + * @param heapSize Number of values that belong to the heap. + * Can be less than bucketSize. + * In such a case, the remaining values in range + * (rootIndex + heapSize, rootIndex + bucketSize) + * are *not* considered part of the heap. + */ + private void heapSort(long rootIndex, int heapSize) { + while (heapSize > 0) { + swap(rootIndex, rootIndex + heapSize - 1); + heapSize--; + downHeap(rootIndex, 0, heapSize); + } + } + + /** + * Correct the heap invariant of a parent and its children. This + * runs in {@code O(log n)} time. + * @param rootIndex index of the start of the bucket + * @param parent Index within the bucket of the parent to check. + * For example, 0 is the "root". + * @param heapSize Number of values that belong to the heap. + * Can be less than bucketSize. + * In such a case, the remaining values in range + * (rootIndex + heapSize, rootIndex + bucketSize) + * are *not* considered part of the heap. + */ + private void downHeap(long rootIndex, int parent, int heapSize) { + while (true) { + long parentIndex = rootIndex + parent; + int worst = parent; + long worstIndex = parentIndex; + int leftChild = parent * 2 + 1; + long leftIndex = rootIndex + leftChild; + if (leftChild < heapSize) { + if (betterThan(values.get(worstIndex), values.get(leftIndex), extraValues.get(worstIndex), extraValues.get(leftIndex))) { + worst = leftChild; + worstIndex = leftIndex; + } + int rightChild = leftChild + 1; + long rightIndex = rootIndex + rightChild; + if (rightChild < heapSize + && betterThan( + values.get(worstIndex), + values.get(rightIndex), + extraValues.get(worstIndex), + extraValues.get(rightIndex) + )) { + worst = rightChild; + worstIndex = rightIndex; + } + } + if (worst == parent) { + break; + } + swap(worstIndex, parentIndex); + parent = worst; + } + } + + @Override + public final void close() { + Releasables.close(values, extraValues, heapMode); + } +} diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/FloatFloatBucketedSort.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/FloatFloatBucketedSort.java new file mode 100644 index 0000000000000..f5057a1ec57e5 --- /dev/null +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/FloatFloatBucketedSort.java @@ -0,0 +1,406 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +package org.elasticsearch.compute.data.sort; + +import org.elasticsearch.common.util.BigArrays; +import org.elasticsearch.common.util.BitArray; +import org.elasticsearch.common.util.FloatArray; +import org.elasticsearch.common.util.FloatArray; +import org.elasticsearch.common.util.PageCacheRecycler; +import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.BlockFactory; +import org.elasticsearch.compute.data.IntVector; +import org.elasticsearch.core.Releasable; +import org.elasticsearch.core.Releasables; +import org.elasticsearch.core.Tuple; +import org.elasticsearch.search.sort.BucketedSort; +import org.elasticsearch.search.sort.SortOrder; + +import java.util.stream.IntStream; + +/** + * Aggregates the top N {@code float} values per bucket. + * See {@link BucketedSort} for more information. + * This class is generated. Edit @{code X-BucketedSort.java.st} instead of this file. + */ +public class FloatFloatBucketedSort implements Releasable { + + private final BigArrays bigArrays; + private final SortOrder order; + private final int bucketSize; + /** + * {@code true} if the bucket is in heap mode, {@code false} if + * it is still gathering. + */ + private final BitArray heapMode; + /** + * An array containing all the values on all buckets. The structure is as follows: + *

+ * For each bucket, there are bucketSize elements, based on the bucket id (0, 1, 2...). + * Then, for each bucket, it can be in 2 states: + *

+ *
    + *
  • + * Gather mode: All buckets start in gather mode, and remain here while they have less than bucketSize elements. + * In gather mode, the elements are stored in the array from the highest index to the lowest index. + * The lowest index contains the offset to the next slot to be filled. + *

    + * This allows us to insert elements in O(1) time. + *

    + *

    + * When the bucketSize-th element is collected, the bucket transitions to heap mode, by heapifying its contents. + *

    + *
  • + *
  • + * Heap mode: The bucket slots are organized as a min heap structure. + *

    + * The root of the heap is the minimum value in the bucket, + * which allows us to quickly discard new values that are not in the top N. + *

    + *
  • + *
+ */ + private FloatArray values; + private FloatArray extraValues; + + public FloatFloatBucketedSort(BigArrays bigArrays, SortOrder order, int bucketSize) { + this.bigArrays = bigArrays; + this.order = order; + this.bucketSize = bucketSize; + heapMode = new BitArray(0, bigArrays); + + boolean success = false; + try { + values = bigArrays.newFloatArray(0, false); + extraValues = bigArrays.newFloatArray(0, false); + success = true; + } finally { + if (success == false) { + close(); + } + } + } + + /** + * Collects a {@code value} into a {@code bucket}. + *

+ * It may or may not be inserted in the heap, depending on if it is better than the current root. + *

+ */ + public void collect(float value, float extraValue, int bucket) { + long rootIndex = (long) bucket * bucketSize; + if (inHeapMode(bucket)) { + if (betterThan(value, values.get(rootIndex), extraValue, extraValues.get(rootIndex))) { + values.set(rootIndex, value); + extraValues.set(rootIndex, extraValue); + downHeap(rootIndex, 0, bucketSize); + } + return; + } + // Gathering mode + long requiredSize = rootIndex + bucketSize; + if (values.size() < requiredSize) { + grow(bucket); + } + int next = getNextGatherOffset(rootIndex); + assert 0 <= next && next < bucketSize + : "Expected next to be in the range of valid buckets [0 <= " + next + " < " + bucketSize + "]"; + long index = next + rootIndex; + values.set(index, value); + extraValues.set(index, extraValue); + if (next == 0) { + heapMode.set(bucket); + heapify(rootIndex, bucketSize); + } else { + setNextGatherOffset(rootIndex, next - 1); + } + } + + /** + * The order of the sort. + */ + public SortOrder getOrder() { + return order; + } + + /** + * The number of values to store per bucket. + */ + public int getBucketSize() { + return bucketSize; + } + + /** + * Get the first and last indexes (inclusive, exclusive) of the values for a bucket. + * Returns [0, 0] if the bucket has never been collected. + */ + private Tuple getBucketValuesIndexes(int bucket) { + long rootIndex = (long) bucket * bucketSize; + if (rootIndex >= values.size()) { + // We've never seen this bucket. + return Tuple.tuple(0L, 0L); + } + long start = inHeapMode(bucket) ? rootIndex : (rootIndex + getNextGatherOffset(rootIndex) + 1); + long end = rootIndex + bucketSize; + return Tuple.tuple(start, end); + } + + /** + * Merge the values from {@code other}'s {@code otherGroupId} into {@code groupId}. + */ + public void merge(int groupId, FloatFloatBucketedSort other, int otherGroupId) { + var otherBounds = other.getBucketValuesIndexes(otherGroupId); + + // TODO: This can be improved for heapified buckets by making use of the heap structures + for (long i = otherBounds.v1(); i < otherBounds.v2(); i++) { + collect(other.values.get(i), other.extraValues.get(i), groupId); + } + } + + /** + * Creates a block with the values from the {@code selected} groups. + */ + public void toBlocks(BlockFactory blockFactory, Block[] blocks, int offset, IntVector selected) { + // Check if the selected groups are all empty, to avoid allocating extra memory + if (allSelectedGroupsAreEmpty(selected)) { + blocks[offset] = blockFactory.newConstantNullBlock(selected.getPositionCount()); + blocks[offset + 1] = blockFactory.newConstantNullBlock(selected.getPositionCount()); + return; + } + + try ( + var builder = blockFactory.newFloatBlockBuilder(selected.getPositionCount()); + var extraBuilder = blockFactory.newFloatBlockBuilder(selected.getPositionCount()) + ) { + for (int s = 0; s < selected.getPositionCount(); s++) { + int bucket = selected.getInt(s); + + var bounds = getBucketValuesIndexes(bucket); + var rootIndex = bounds.v1(); + var size = bounds.v2() - bounds.v1(); + + if (size == 0) { + builder.appendNull(); + extraBuilder.appendNull(); + continue; + } + + if (size == 1) { + builder.appendFloat(values.get(rootIndex)); + extraBuilder.appendFloat(extraValues.get(rootIndex)); + continue; + } + + // If we are in the gathering mode, we need to heapify before sorting. + if (inHeapMode(bucket) == false) { + heapify(rootIndex, (int) size); + } + heapSort(rootIndex, (int) size); + + builder.beginPositionEntry(); + extraBuilder.beginPositionEntry(); + for (int i = 0; i < size; i++) { + builder.appendFloat(values.get(rootIndex + i)); + extraBuilder.appendFloat(extraValues.get(rootIndex + i)); + } + builder.endPositionEntry(); + extraBuilder.endPositionEntry(); + } + blocks[offset] = builder.build(); + blocks[offset + 1] = extraBuilder.build(); + } + } + + /** + * Checks if the selected groups are all empty. + */ + private boolean allSelectedGroupsAreEmpty(IntVector selected) { + return IntStream.range(0, selected.getPositionCount()).map(selected::getInt).noneMatch(bucket -> { + var bounds = this.getBucketValuesIndexes(bucket); + var size = bounds.v2() - bounds.v1(); + return size > 0; + }); + } + + /** + * Is this bucket a min heap {@code true} or in gathering mode {@code false}? + */ + private boolean inHeapMode(int bucket) { + return heapMode.get(bucket); + } + + /** + * Get the next index that should be "gathered" for a bucket rooted + * at {@code rootIndex}. + */ + private int getNextGatherOffset(long rootIndex) { + return (int) values.get(rootIndex); + } + + /** + * Set the next index that should be "gathered" for a bucket rooted + * at {@code rootIndex}. + */ + private void setNextGatherOffset(long rootIndex, int offset) { + values.set(rootIndex, offset); + } + + /** + * {@code true} if the entry at index {@code lhs} is "better" than + * the entry at {@code rhs}. "Better" in this means "lower" for + * {@link SortOrder#ASC} and "higher" for {@link SortOrder#DESC}. + */ + private boolean betterThan(float lhs, float rhs, float lhsExtra, float rhsExtra) { + int res = Float.compare(lhs, rhs); + if (res != 0) { + return getOrder().reverseMul() * res < 0; + } + res = Float.compare(lhsExtra, rhsExtra); + return getOrder().reverseMul() * res < 0; + } + + /** + * Swap the data at two indices. + */ + private void swap(long lhs, long rhs) { + var tmp = values.get(lhs); + values.set(lhs, values.get(rhs)); + values.set(rhs, tmp); + var tmpExtra = extraValues.get(lhs); + extraValues.set(lhs, extraValues.get(rhs)); + extraValues.set(rhs, tmpExtra); + } + + /** + * Allocate storage for more buckets and store the "next gather offset" + * for those new buckets. We always grow the storage by whole bucket's + * worth of slots at a time. We never allocate space for partial buckets. + */ + private void grow(int bucket) { + long oldMax = values.size(); + assert oldMax % bucketSize == 0; + + long newSize = BigArrays.overSize(((long) bucket + 1) * bucketSize, PageCacheRecycler.FLOAT_PAGE_SIZE, Float.BYTES); + // Round up to the next full bucket. + newSize = (newSize + bucketSize - 1) / bucketSize; + values = bigArrays.resize(values, newSize * bucketSize); + long newExtraSize = BigArrays.overSize(((long) bucket + 1) * bucketSize, PageCacheRecycler.FLOAT_PAGE_SIZE, Float.BYTES); + // Round up to the next full bucket. + newExtraSize = (newExtraSize + bucketSize - 1) / bucketSize; + extraValues = bigArrays.resize(extraValues, newExtraSize * bucketSize); + // Set the next gather offsets for all newly allocated buckets. + fillGatherOffsets(oldMax); + } + + /** + * Maintain the "next gather offsets" for newly allocated buckets. + */ + private void fillGatherOffsets(long startingAt) { + int nextOffset = getBucketSize() - 1; + for (long bucketRoot = startingAt; bucketRoot < values.size(); bucketRoot += getBucketSize()) { + setNextGatherOffset(bucketRoot, nextOffset); + } + } + + /** + * Heapify a bucket whose entries are in random order. + *

+ * This works by validating the heap property on each node, iterating + * "upwards", pushing any out of order parents "down". Check out the + * wikipedia + * entry on binary heaps for more about this. + *

+ *

+ * While this *looks* like it could easily be {@code O(n * log n)}, it is + * a fairly well studied algorithm attributed to Floyd. There's + * been a bunch of work that puts this at {@code O(n)}, close to 1.88n worst + * case. + *

+ * + * @param rootIndex the index the start of the bucket + */ + private void heapify(long rootIndex, int heapSize) { + int maxParent = heapSize / 2 - 1; + for (int parent = maxParent; parent >= 0; parent--) { + downHeap(rootIndex, parent, heapSize); + } + } + + /** + * Sorts all the values in the heap using heap sort algorithm. + * This runs in {@code O(n log n)} time. + * @param rootIndex index of the start of the bucket + * @param heapSize Number of values that belong to the heap. + * Can be less than bucketSize. + * In such a case, the remaining values in range + * (rootIndex + heapSize, rootIndex + bucketSize) + * are *not* considered part of the heap. + */ + private void heapSort(long rootIndex, int heapSize) { + while (heapSize > 0) { + swap(rootIndex, rootIndex + heapSize - 1); + heapSize--; + downHeap(rootIndex, 0, heapSize); + } + } + + /** + * Correct the heap invariant of a parent and its children. This + * runs in {@code O(log n)} time. + * @param rootIndex index of the start of the bucket + * @param parent Index within the bucket of the parent to check. + * For example, 0 is the "root". + * @param heapSize Number of values that belong to the heap. + * Can be less than bucketSize. + * In such a case, the remaining values in range + * (rootIndex + heapSize, rootIndex + bucketSize) + * are *not* considered part of the heap. + */ + private void downHeap(long rootIndex, int parent, int heapSize) { + while (true) { + long parentIndex = rootIndex + parent; + int worst = parent; + long worstIndex = parentIndex; + int leftChild = parent * 2 + 1; + long leftIndex = rootIndex + leftChild; + if (leftChild < heapSize) { + if (betterThan(values.get(worstIndex), values.get(leftIndex), extraValues.get(worstIndex), extraValues.get(leftIndex))) { + worst = leftChild; + worstIndex = leftIndex; + } + int rightChild = leftChild + 1; + long rightIndex = rootIndex + rightChild; + if (rightChild < heapSize + && betterThan( + values.get(worstIndex), + values.get(rightIndex), + extraValues.get(worstIndex), + extraValues.get(rightIndex) + )) { + worst = rightChild; + worstIndex = rightIndex; + } + } + if (worst == parent) { + break; + } + swap(worstIndex, parentIndex); + parent = worst; + } + } + + @Override + public final void close() { + Releasables.close(values, extraValues, heapMode); + } +} diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/FloatIntBucketedSort.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/FloatIntBucketedSort.java new file mode 100644 index 0000000000000..e8e5b8cc7bf8e --- /dev/null +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/FloatIntBucketedSort.java @@ -0,0 +1,406 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +package org.elasticsearch.compute.data.sort; + +import org.elasticsearch.common.util.BigArrays; +import org.elasticsearch.common.util.BitArray; +import org.elasticsearch.common.util.IntArray; +import org.elasticsearch.common.util.FloatArray; +import org.elasticsearch.common.util.PageCacheRecycler; +import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.BlockFactory; +import org.elasticsearch.compute.data.IntVector; +import org.elasticsearch.core.Releasable; +import org.elasticsearch.core.Releasables; +import org.elasticsearch.core.Tuple; +import org.elasticsearch.search.sort.BucketedSort; +import org.elasticsearch.search.sort.SortOrder; + +import java.util.stream.IntStream; + +/** + * Aggregates the top N {@code float} values per bucket. + * See {@link BucketedSort} for more information. + * This class is generated. Edit @{code X-BucketedSort.java.st} instead of this file. + */ +public class FloatIntBucketedSort implements Releasable { + + private final BigArrays bigArrays; + private final SortOrder order; + private final int bucketSize; + /** + * {@code true} if the bucket is in heap mode, {@code false} if + * it is still gathering. + */ + private final BitArray heapMode; + /** + * An array containing all the values on all buckets. The structure is as follows: + *

+ * For each bucket, there are bucketSize elements, based on the bucket id (0, 1, 2...). + * Then, for each bucket, it can be in 2 states: + *

+ *
    + *
  • + * Gather mode: All buckets start in gather mode, and remain here while they have less than bucketSize elements. + * In gather mode, the elements are stored in the array from the highest index to the lowest index. + * The lowest index contains the offset to the next slot to be filled. + *

    + * This allows us to insert elements in O(1) time. + *

    + *

    + * When the bucketSize-th element is collected, the bucket transitions to heap mode, by heapifying its contents. + *

    + *
  • + *
  • + * Heap mode: The bucket slots are organized as a min heap structure. + *

    + * The root of the heap is the minimum value in the bucket, + * which allows us to quickly discard new values that are not in the top N. + *

    + *
  • + *
+ */ + private FloatArray values; + private IntArray extraValues; + + public FloatIntBucketedSort(BigArrays bigArrays, SortOrder order, int bucketSize) { + this.bigArrays = bigArrays; + this.order = order; + this.bucketSize = bucketSize; + heapMode = new BitArray(0, bigArrays); + + boolean success = false; + try { + values = bigArrays.newFloatArray(0, false); + extraValues = bigArrays.newIntArray(0, false); + success = true; + } finally { + if (success == false) { + close(); + } + } + } + + /** + * Collects a {@code value} into a {@code bucket}. + *

+ * It may or may not be inserted in the heap, depending on if it is better than the current root. + *

+ */ + public void collect(float value, int extraValue, int bucket) { + long rootIndex = (long) bucket * bucketSize; + if (inHeapMode(bucket)) { + if (betterThan(value, values.get(rootIndex), extraValue, extraValues.get(rootIndex))) { + values.set(rootIndex, value); + extraValues.set(rootIndex, extraValue); + downHeap(rootIndex, 0, bucketSize); + } + return; + } + // Gathering mode + long requiredSize = rootIndex + bucketSize; + if (values.size() < requiredSize) { + grow(bucket); + } + int next = getNextGatherOffset(rootIndex); + assert 0 <= next && next < bucketSize + : "Expected next to be in the range of valid buckets [0 <= " + next + " < " + bucketSize + "]"; + long index = next + rootIndex; + values.set(index, value); + extraValues.set(index, extraValue); + if (next == 0) { + heapMode.set(bucket); + heapify(rootIndex, bucketSize); + } else { + setNextGatherOffset(rootIndex, next - 1); + } + } + + /** + * The order of the sort. + */ + public SortOrder getOrder() { + return order; + } + + /** + * The number of values to store per bucket. + */ + public int getBucketSize() { + return bucketSize; + } + + /** + * Get the first and last indexes (inclusive, exclusive) of the values for a bucket. + * Returns [0, 0] if the bucket has never been collected. + */ + private Tuple getBucketValuesIndexes(int bucket) { + long rootIndex = (long) bucket * bucketSize; + if (rootIndex >= values.size()) { + // We've never seen this bucket. + return Tuple.tuple(0L, 0L); + } + long start = inHeapMode(bucket) ? rootIndex : (rootIndex + getNextGatherOffset(rootIndex) + 1); + long end = rootIndex + bucketSize; + return Tuple.tuple(start, end); + } + + /** + * Merge the values from {@code other}'s {@code otherGroupId} into {@code groupId}. + */ + public void merge(int groupId, FloatIntBucketedSort other, int otherGroupId) { + var otherBounds = other.getBucketValuesIndexes(otherGroupId); + + // TODO: This can be improved for heapified buckets by making use of the heap structures + for (long i = otherBounds.v1(); i < otherBounds.v2(); i++) { + collect(other.values.get(i), other.extraValues.get(i), groupId); + } + } + + /** + * Creates a block with the values from the {@code selected} groups. + */ + public void toBlocks(BlockFactory blockFactory, Block[] blocks, int offset, IntVector selected) { + // Check if the selected groups are all empty, to avoid allocating extra memory + if (allSelectedGroupsAreEmpty(selected)) { + blocks[offset] = blockFactory.newConstantNullBlock(selected.getPositionCount()); + blocks[offset + 1] = blockFactory.newConstantNullBlock(selected.getPositionCount()); + return; + } + + try ( + var builder = blockFactory.newFloatBlockBuilder(selected.getPositionCount()); + var extraBuilder = blockFactory.newIntBlockBuilder(selected.getPositionCount()) + ) { + for (int s = 0; s < selected.getPositionCount(); s++) { + int bucket = selected.getInt(s); + + var bounds = getBucketValuesIndexes(bucket); + var rootIndex = bounds.v1(); + var size = bounds.v2() - bounds.v1(); + + if (size == 0) { + builder.appendNull(); + extraBuilder.appendNull(); + continue; + } + + if (size == 1) { + builder.appendFloat(values.get(rootIndex)); + extraBuilder.appendInt(extraValues.get(rootIndex)); + continue; + } + + // If we are in the gathering mode, we need to heapify before sorting. + if (inHeapMode(bucket) == false) { + heapify(rootIndex, (int) size); + } + heapSort(rootIndex, (int) size); + + builder.beginPositionEntry(); + extraBuilder.beginPositionEntry(); + for (int i = 0; i < size; i++) { + builder.appendFloat(values.get(rootIndex + i)); + extraBuilder.appendInt(extraValues.get(rootIndex + i)); + } + builder.endPositionEntry(); + extraBuilder.endPositionEntry(); + } + blocks[offset] = builder.build(); + blocks[offset + 1] = extraBuilder.build(); + } + } + + /** + * Checks if the selected groups are all empty. + */ + private boolean allSelectedGroupsAreEmpty(IntVector selected) { + return IntStream.range(0, selected.getPositionCount()).map(selected::getInt).noneMatch(bucket -> { + var bounds = this.getBucketValuesIndexes(bucket); + var size = bounds.v2() - bounds.v1(); + return size > 0; + }); + } + + /** + * Is this bucket a min heap {@code true} or in gathering mode {@code false}? + */ + private boolean inHeapMode(int bucket) { + return heapMode.get(bucket); + } + + /** + * Get the next index that should be "gathered" for a bucket rooted + * at {@code rootIndex}. + */ + private int getNextGatherOffset(long rootIndex) { + return (int) values.get(rootIndex); + } + + /** + * Set the next index that should be "gathered" for a bucket rooted + * at {@code rootIndex}. + */ + private void setNextGatherOffset(long rootIndex, int offset) { + values.set(rootIndex, offset); + } + + /** + * {@code true} if the entry at index {@code lhs} is "better" than + * the entry at {@code rhs}. "Better" in this means "lower" for + * {@link SortOrder#ASC} and "higher" for {@link SortOrder#DESC}. + */ + private boolean betterThan(float lhs, float rhs, int lhsExtra, int rhsExtra) { + int res = Float.compare(lhs, rhs); + if (res != 0) { + return getOrder().reverseMul() * res < 0; + } + res = Integer.compare(lhsExtra, rhsExtra); + return getOrder().reverseMul() * res < 0; + } + + /** + * Swap the data at two indices. + */ + private void swap(long lhs, long rhs) { + var tmp = values.get(lhs); + values.set(lhs, values.get(rhs)); + values.set(rhs, tmp); + var tmpExtra = extraValues.get(lhs); + extraValues.set(lhs, extraValues.get(rhs)); + extraValues.set(rhs, tmpExtra); + } + + /** + * Allocate storage for more buckets and store the "next gather offset" + * for those new buckets. We always grow the storage by whole bucket's + * worth of slots at a time. We never allocate space for partial buckets. + */ + private void grow(int bucket) { + long oldMax = values.size(); + assert oldMax % bucketSize == 0; + + long newSize = BigArrays.overSize(((long) bucket + 1) * bucketSize, PageCacheRecycler.FLOAT_PAGE_SIZE, Float.BYTES); + // Round up to the next full bucket. + newSize = (newSize + bucketSize - 1) / bucketSize; + values = bigArrays.resize(values, newSize * bucketSize); + long newExtraSize = BigArrays.overSize(((long) bucket + 1) * bucketSize, PageCacheRecycler.INT_PAGE_SIZE, Integer.BYTES); + // Round up to the next full bucket. + newExtraSize = (newExtraSize + bucketSize - 1) / bucketSize; + extraValues = bigArrays.resize(extraValues, newExtraSize * bucketSize); + // Set the next gather offsets for all newly allocated buckets. + fillGatherOffsets(oldMax); + } + + /** + * Maintain the "next gather offsets" for newly allocated buckets. + */ + private void fillGatherOffsets(long startingAt) { + int nextOffset = getBucketSize() - 1; + for (long bucketRoot = startingAt; bucketRoot < values.size(); bucketRoot += getBucketSize()) { + setNextGatherOffset(bucketRoot, nextOffset); + } + } + + /** + * Heapify a bucket whose entries are in random order. + *

+ * This works by validating the heap property on each node, iterating + * "upwards", pushing any out of order parents "down". Check out the + * wikipedia + * entry on binary heaps for more about this. + *

+ *

+ * While this *looks* like it could easily be {@code O(n * log n)}, it is + * a fairly well studied algorithm attributed to Floyd. There's + * been a bunch of work that puts this at {@code O(n)}, close to 1.88n worst + * case. + *

+ * + * @param rootIndex the index the start of the bucket + */ + private void heapify(long rootIndex, int heapSize) { + int maxParent = heapSize / 2 - 1; + for (int parent = maxParent; parent >= 0; parent--) { + downHeap(rootIndex, parent, heapSize); + } + } + + /** + * Sorts all the values in the heap using heap sort algorithm. + * This runs in {@code O(n log n)} time. + * @param rootIndex index of the start of the bucket + * @param heapSize Number of values that belong to the heap. + * Can be less than bucketSize. + * In such a case, the remaining values in range + * (rootIndex + heapSize, rootIndex + bucketSize) + * are *not* considered part of the heap. + */ + private void heapSort(long rootIndex, int heapSize) { + while (heapSize > 0) { + swap(rootIndex, rootIndex + heapSize - 1); + heapSize--; + downHeap(rootIndex, 0, heapSize); + } + } + + /** + * Correct the heap invariant of a parent and its children. This + * runs in {@code O(log n)} time. + * @param rootIndex index of the start of the bucket + * @param parent Index within the bucket of the parent to check. + * For example, 0 is the "root". + * @param heapSize Number of values that belong to the heap. + * Can be less than bucketSize. + * In such a case, the remaining values in range + * (rootIndex + heapSize, rootIndex + bucketSize) + * are *not* considered part of the heap. + */ + private void downHeap(long rootIndex, int parent, int heapSize) { + while (true) { + long parentIndex = rootIndex + parent; + int worst = parent; + long worstIndex = parentIndex; + int leftChild = parent * 2 + 1; + long leftIndex = rootIndex + leftChild; + if (leftChild < heapSize) { + if (betterThan(values.get(worstIndex), values.get(leftIndex), extraValues.get(worstIndex), extraValues.get(leftIndex))) { + worst = leftChild; + worstIndex = leftIndex; + } + int rightChild = leftChild + 1; + long rightIndex = rootIndex + rightChild; + if (rightChild < heapSize + && betterThan( + values.get(worstIndex), + values.get(rightIndex), + extraValues.get(worstIndex), + extraValues.get(rightIndex) + )) { + worst = rightChild; + worstIndex = rightIndex; + } + } + if (worst == parent) { + break; + } + swap(worstIndex, parentIndex); + parent = worst; + } + } + + @Override + public final void close() { + Releasables.close(values, extraValues, heapMode); + } +} diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/FloatLongBucketedSort.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/FloatLongBucketedSort.java new file mode 100644 index 0000000000000..dc5813fbd4e35 --- /dev/null +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/FloatLongBucketedSort.java @@ -0,0 +1,406 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +package org.elasticsearch.compute.data.sort; + +import org.elasticsearch.common.util.BigArrays; +import org.elasticsearch.common.util.BitArray; +import org.elasticsearch.common.util.LongArray; +import org.elasticsearch.common.util.FloatArray; +import org.elasticsearch.common.util.PageCacheRecycler; +import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.BlockFactory; +import org.elasticsearch.compute.data.IntVector; +import org.elasticsearch.core.Releasable; +import org.elasticsearch.core.Releasables; +import org.elasticsearch.core.Tuple; +import org.elasticsearch.search.sort.BucketedSort; +import org.elasticsearch.search.sort.SortOrder; + +import java.util.stream.IntStream; + +/** + * Aggregates the top N {@code float} values per bucket. + * See {@link BucketedSort} for more information. + * This class is generated. Edit @{code X-BucketedSort.java.st} instead of this file. + */ +public class FloatLongBucketedSort implements Releasable { + + private final BigArrays bigArrays; + private final SortOrder order; + private final int bucketSize; + /** + * {@code true} if the bucket is in heap mode, {@code false} if + * it is still gathering. + */ + private final BitArray heapMode; + /** + * An array containing all the values on all buckets. The structure is as follows: + *

+ * For each bucket, there are bucketSize elements, based on the bucket id (0, 1, 2...). + * Then, for each bucket, it can be in 2 states: + *

+ *
    + *
  • + * Gather mode: All buckets start in gather mode, and remain here while they have less than bucketSize elements. + * In gather mode, the elements are stored in the array from the highest index to the lowest index. + * The lowest index contains the offset to the next slot to be filled. + *

    + * This allows us to insert elements in O(1) time. + *

    + *

    + * When the bucketSize-th element is collected, the bucket transitions to heap mode, by heapifying its contents. + *

    + *
  • + *
  • + * Heap mode: The bucket slots are organized as a min heap structure. + *

    + * The root of the heap is the minimum value in the bucket, + * which allows us to quickly discard new values that are not in the top N. + *

    + *
  • + *
+ */ + private FloatArray values; + private LongArray extraValues; + + public FloatLongBucketedSort(BigArrays bigArrays, SortOrder order, int bucketSize) { + this.bigArrays = bigArrays; + this.order = order; + this.bucketSize = bucketSize; + heapMode = new BitArray(0, bigArrays); + + boolean success = false; + try { + values = bigArrays.newFloatArray(0, false); + extraValues = bigArrays.newLongArray(0, false); + success = true; + } finally { + if (success == false) { + close(); + } + } + } + + /** + * Collects a {@code value} into a {@code bucket}. + *

+ * It may or may not be inserted in the heap, depending on if it is better than the current root. + *

+ */ + public void collect(float value, long extraValue, int bucket) { + long rootIndex = (long) bucket * bucketSize; + if (inHeapMode(bucket)) { + if (betterThan(value, values.get(rootIndex), extraValue, extraValues.get(rootIndex))) { + values.set(rootIndex, value); + extraValues.set(rootIndex, extraValue); + downHeap(rootIndex, 0, bucketSize); + } + return; + } + // Gathering mode + long requiredSize = rootIndex + bucketSize; + if (values.size() < requiredSize) { + grow(bucket); + } + int next = getNextGatherOffset(rootIndex); + assert 0 <= next && next < bucketSize + : "Expected next to be in the range of valid buckets [0 <= " + next + " < " + bucketSize + "]"; + long index = next + rootIndex; + values.set(index, value); + extraValues.set(index, extraValue); + if (next == 0) { + heapMode.set(bucket); + heapify(rootIndex, bucketSize); + } else { + setNextGatherOffset(rootIndex, next - 1); + } + } + + /** + * The order of the sort. + */ + public SortOrder getOrder() { + return order; + } + + /** + * The number of values to store per bucket. + */ + public int getBucketSize() { + return bucketSize; + } + + /** + * Get the first and last indexes (inclusive, exclusive) of the values for a bucket. + * Returns [0, 0] if the bucket has never been collected. + */ + private Tuple getBucketValuesIndexes(int bucket) { + long rootIndex = (long) bucket * bucketSize; + if (rootIndex >= values.size()) { + // We've never seen this bucket. + return Tuple.tuple(0L, 0L); + } + long start = inHeapMode(bucket) ? rootIndex : (rootIndex + getNextGatherOffset(rootIndex) + 1); + long end = rootIndex + bucketSize; + return Tuple.tuple(start, end); + } + + /** + * Merge the values from {@code other}'s {@code otherGroupId} into {@code groupId}. + */ + public void merge(int groupId, FloatLongBucketedSort other, int otherGroupId) { + var otherBounds = other.getBucketValuesIndexes(otherGroupId); + + // TODO: This can be improved for heapified buckets by making use of the heap structures + for (long i = otherBounds.v1(); i < otherBounds.v2(); i++) { + collect(other.values.get(i), other.extraValues.get(i), groupId); + } + } + + /** + * Creates a block with the values from the {@code selected} groups. + */ + public void toBlocks(BlockFactory blockFactory, Block[] blocks, int offset, IntVector selected) { + // Check if the selected groups are all empty, to avoid allocating extra memory + if (allSelectedGroupsAreEmpty(selected)) { + blocks[offset] = blockFactory.newConstantNullBlock(selected.getPositionCount()); + blocks[offset + 1] = blockFactory.newConstantNullBlock(selected.getPositionCount()); + return; + } + + try ( + var builder = blockFactory.newFloatBlockBuilder(selected.getPositionCount()); + var extraBuilder = blockFactory.newLongBlockBuilder(selected.getPositionCount()) + ) { + for (int s = 0; s < selected.getPositionCount(); s++) { + int bucket = selected.getInt(s); + + var bounds = getBucketValuesIndexes(bucket); + var rootIndex = bounds.v1(); + var size = bounds.v2() - bounds.v1(); + + if (size == 0) { + builder.appendNull(); + extraBuilder.appendNull(); + continue; + } + + if (size == 1) { + builder.appendFloat(values.get(rootIndex)); + extraBuilder.appendLong(extraValues.get(rootIndex)); + continue; + } + + // If we are in the gathering mode, we need to heapify before sorting. + if (inHeapMode(bucket) == false) { + heapify(rootIndex, (int) size); + } + heapSort(rootIndex, (int) size); + + builder.beginPositionEntry(); + extraBuilder.beginPositionEntry(); + for (int i = 0; i < size; i++) { + builder.appendFloat(values.get(rootIndex + i)); + extraBuilder.appendLong(extraValues.get(rootIndex + i)); + } + builder.endPositionEntry(); + extraBuilder.endPositionEntry(); + } + blocks[offset] = builder.build(); + blocks[offset + 1] = extraBuilder.build(); + } + } + + /** + * Checks if the selected groups are all empty. + */ + private boolean allSelectedGroupsAreEmpty(IntVector selected) { + return IntStream.range(0, selected.getPositionCount()).map(selected::getInt).noneMatch(bucket -> { + var bounds = this.getBucketValuesIndexes(bucket); + var size = bounds.v2() - bounds.v1(); + return size > 0; + }); + } + + /** + * Is this bucket a min heap {@code true} or in gathering mode {@code false}? + */ + private boolean inHeapMode(int bucket) { + return heapMode.get(bucket); + } + + /** + * Get the next index that should be "gathered" for a bucket rooted + * at {@code rootIndex}. + */ + private int getNextGatherOffset(long rootIndex) { + return (int) values.get(rootIndex); + } + + /** + * Set the next index that should be "gathered" for a bucket rooted + * at {@code rootIndex}. + */ + private void setNextGatherOffset(long rootIndex, int offset) { + values.set(rootIndex, offset); + } + + /** + * {@code true} if the entry at index {@code lhs} is "better" than + * the entry at {@code rhs}. "Better" in this means "lower" for + * {@link SortOrder#ASC} and "higher" for {@link SortOrder#DESC}. + */ + private boolean betterThan(float lhs, float rhs, long lhsExtra, long rhsExtra) { + int res = Float.compare(lhs, rhs); + if (res != 0) { + return getOrder().reverseMul() * res < 0; + } + res = Long.compare(lhsExtra, rhsExtra); + return getOrder().reverseMul() * res < 0; + } + + /** + * Swap the data at two indices. + */ + private void swap(long lhs, long rhs) { + var tmp = values.get(lhs); + values.set(lhs, values.get(rhs)); + values.set(rhs, tmp); + var tmpExtra = extraValues.get(lhs); + extraValues.set(lhs, extraValues.get(rhs)); + extraValues.set(rhs, tmpExtra); + } + + /** + * Allocate storage for more buckets and store the "next gather offset" + * for those new buckets. We always grow the storage by whole bucket's + * worth of slots at a time. We never allocate space for partial buckets. + */ + private void grow(int bucket) { + long oldMax = values.size(); + assert oldMax % bucketSize == 0; + + long newSize = BigArrays.overSize(((long) bucket + 1) * bucketSize, PageCacheRecycler.FLOAT_PAGE_SIZE, Float.BYTES); + // Round up to the next full bucket. + newSize = (newSize + bucketSize - 1) / bucketSize; + values = bigArrays.resize(values, newSize * bucketSize); + long newExtraSize = BigArrays.overSize(((long) bucket + 1) * bucketSize, PageCacheRecycler.LONG_PAGE_SIZE, Long.BYTES); + // Round up to the next full bucket. + newExtraSize = (newExtraSize + bucketSize - 1) / bucketSize; + extraValues = bigArrays.resize(extraValues, newExtraSize * bucketSize); + // Set the next gather offsets for all newly allocated buckets. + fillGatherOffsets(oldMax); + } + + /** + * Maintain the "next gather offsets" for newly allocated buckets. + */ + private void fillGatherOffsets(long startingAt) { + int nextOffset = getBucketSize() - 1; + for (long bucketRoot = startingAt; bucketRoot < values.size(); bucketRoot += getBucketSize()) { + setNextGatherOffset(bucketRoot, nextOffset); + } + } + + /** + * Heapify a bucket whose entries are in random order. + *

+ * This works by validating the heap property on each node, iterating + * "upwards", pushing any out of order parents "down". Check out the + * wikipedia + * entry on binary heaps for more about this. + *

+ *

+ * While this *looks* like it could easily be {@code O(n * log n)}, it is + * a fairly well studied algorithm attributed to Floyd. There's + * been a bunch of work that puts this at {@code O(n)}, close to 1.88n worst + * case. + *

+ * + * @param rootIndex the index the start of the bucket + */ + private void heapify(long rootIndex, int heapSize) { + int maxParent = heapSize / 2 - 1; + for (int parent = maxParent; parent >= 0; parent--) { + downHeap(rootIndex, parent, heapSize); + } + } + + /** + * Sorts all the values in the heap using heap sort algorithm. + * This runs in {@code O(n log n)} time. + * @param rootIndex index of the start of the bucket + * @param heapSize Number of values that belong to the heap. + * Can be less than bucketSize. + * In such a case, the remaining values in range + * (rootIndex + heapSize, rootIndex + bucketSize) + * are *not* considered part of the heap. + */ + private void heapSort(long rootIndex, int heapSize) { + while (heapSize > 0) { + swap(rootIndex, rootIndex + heapSize - 1); + heapSize--; + downHeap(rootIndex, 0, heapSize); + } + } + + /** + * Correct the heap invariant of a parent and its children. This + * runs in {@code O(log n)} time. + * @param rootIndex index of the start of the bucket + * @param parent Index within the bucket of the parent to check. + * For example, 0 is the "root". + * @param heapSize Number of values that belong to the heap. + * Can be less than bucketSize. + * In such a case, the remaining values in range + * (rootIndex + heapSize, rootIndex + bucketSize) + * are *not* considered part of the heap. + */ + private void downHeap(long rootIndex, int parent, int heapSize) { + while (true) { + long parentIndex = rootIndex + parent; + int worst = parent; + long worstIndex = parentIndex; + int leftChild = parent * 2 + 1; + long leftIndex = rootIndex + leftChild; + if (leftChild < heapSize) { + if (betterThan(values.get(worstIndex), values.get(leftIndex), extraValues.get(worstIndex), extraValues.get(leftIndex))) { + worst = leftChild; + worstIndex = leftIndex; + } + int rightChild = leftChild + 1; + long rightIndex = rootIndex + rightChild; + if (rightChild < heapSize + && betterThan( + values.get(worstIndex), + values.get(rightIndex), + extraValues.get(worstIndex), + extraValues.get(rightIndex) + )) { + worst = rightChild; + worstIndex = rightIndex; + } + } + if (worst == parent) { + break; + } + swap(worstIndex, parentIndex); + parent = worst; + } + } + + @Override + public final void close() { + Releasables.close(values, extraValues, heapMode); + } +} diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/IntBucketedSort.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/IntBucketedSort.java index 5ba1a3f7138a3..7dcec4461f0a5 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/IntBucketedSort.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/IntBucketedSort.java @@ -23,7 +23,7 @@ import java.util.stream.IntStream; /** - * Aggregates the top N int values per bucket. + * Aggregates the top N {@code int} values per bucket. * See {@link BucketedSort} for more information. * This class is generated. Edit @{code X-BucketedSort.java.st} instead of this file. */ @@ -162,12 +162,7 @@ public void merge(int groupId, IntBucketedSort other, int otherGroupId) { */ public Block toBlock(BlockFactory blockFactory, IntVector selected) { // Check if the selected groups are all empty, to avoid allocating extra memory - if (IntStream.range(0, selected.getPositionCount()).map(selected::getInt).noneMatch(bucket -> { - var bounds = this.getBucketValuesIndexes(bucket); - var size = bounds.v2() - bounds.v1(); - - return size > 0; - })) { + if (allSelectedGroupsAreEmpty(selected)) { return blockFactory.newConstantNullBlock(selected.getPositionCount()); } @@ -185,7 +180,7 @@ public Block toBlock(BlockFactory blockFactory, IntVector selected) { } if (size == 1) { - builder.appendInt(values.get(bounds.v1())); + builder.appendInt(values.get(rootIndex)); continue; } @@ -197,7 +192,7 @@ public Block toBlock(BlockFactory blockFactory, IntVector selected) { builder.beginPositionEntry(); for (int i = 0; i < size; i++) { - builder.appendInt(values.get(bounds.v1() + i)); + builder.appendInt(values.get(rootIndex + i)); } builder.endPositionEntry(); } @@ -205,6 +200,17 @@ public Block toBlock(BlockFactory blockFactory, IntVector selected) { } } + /** + * Checks if the selected groups are all empty. + */ + private boolean allSelectedGroupsAreEmpty(IntVector selected) { + return IntStream.range(0, selected.getPositionCount()).map(selected::getInt).noneMatch(bucket -> { + var bounds = this.getBucketValuesIndexes(bucket); + var size = bounds.v2() - bounds.v1(); + return size > 0; + }); + } + /** * Is this bucket a min heap {@code true} or in gathering mode {@code false}? */ @@ -234,7 +240,8 @@ private void setNextGatherOffset(long rootIndex, int offset) { * {@link SortOrder#ASC} and "higher" for {@link SortOrder#DESC}. */ private boolean betterThan(int lhs, int rhs) { - return getOrder().reverseMul() * Integer.compare(lhs, rhs) < 0; + int res = Integer.compare(lhs, rhs); + return getOrder().reverseMul() * res < 0; } /** diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/IntDoubleBucketedSort.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/IntDoubleBucketedSort.java new file mode 100644 index 0000000000000..5adbea93cc978 --- /dev/null +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/IntDoubleBucketedSort.java @@ -0,0 +1,406 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +package org.elasticsearch.compute.data.sort; + +import org.elasticsearch.common.util.BigArrays; +import org.elasticsearch.common.util.BitArray; +import org.elasticsearch.common.util.DoubleArray; +import org.elasticsearch.common.util.IntArray; +import org.elasticsearch.common.util.PageCacheRecycler; +import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.BlockFactory; +import org.elasticsearch.compute.data.IntVector; +import org.elasticsearch.core.Releasable; +import org.elasticsearch.core.Releasables; +import org.elasticsearch.core.Tuple; +import org.elasticsearch.search.sort.BucketedSort; +import org.elasticsearch.search.sort.SortOrder; + +import java.util.stream.IntStream; + +/** + * Aggregates the top N {@code int} values per bucket. + * See {@link BucketedSort} for more information. + * This class is generated. Edit @{code X-BucketedSort.java.st} instead of this file. + */ +public class IntDoubleBucketedSort implements Releasable { + + private final BigArrays bigArrays; + private final SortOrder order; + private final int bucketSize; + /** + * {@code true} if the bucket is in heap mode, {@code false} if + * it is still gathering. + */ + private final BitArray heapMode; + /** + * An array containing all the values on all buckets. The structure is as follows: + *

+ * For each bucket, there are bucketSize elements, based on the bucket id (0, 1, 2...). + * Then, for each bucket, it can be in 2 states: + *

+ *
    + *
  • + * Gather mode: All buckets start in gather mode, and remain here while they have less than bucketSize elements. + * In gather mode, the elements are stored in the array from the highest index to the lowest index. + * The lowest index contains the offset to the next slot to be filled. + *

    + * This allows us to insert elements in O(1) time. + *

    + *

    + * When the bucketSize-th element is collected, the bucket transitions to heap mode, by heapifying its contents. + *

    + *
  • + *
  • + * Heap mode: The bucket slots are organized as a min heap structure. + *

    + * The root of the heap is the minimum value in the bucket, + * which allows us to quickly discard new values that are not in the top N. + *

    + *
  • + *
+ */ + private IntArray values; + private DoubleArray extraValues; + + public IntDoubleBucketedSort(BigArrays bigArrays, SortOrder order, int bucketSize) { + this.bigArrays = bigArrays; + this.order = order; + this.bucketSize = bucketSize; + heapMode = new BitArray(0, bigArrays); + + boolean success = false; + try { + values = bigArrays.newIntArray(0, false); + extraValues = bigArrays.newDoubleArray(0, false); + success = true; + } finally { + if (success == false) { + close(); + } + } + } + + /** + * Collects a {@code value} into a {@code bucket}. + *

+ * It may or may not be inserted in the heap, depending on if it is better than the current root. + *

+ */ + public void collect(int value, double extraValue, int bucket) { + long rootIndex = (long) bucket * bucketSize; + if (inHeapMode(bucket)) { + if (betterThan(value, values.get(rootIndex), extraValue, extraValues.get(rootIndex))) { + values.set(rootIndex, value); + extraValues.set(rootIndex, extraValue); + downHeap(rootIndex, 0, bucketSize); + } + return; + } + // Gathering mode + long requiredSize = rootIndex + bucketSize; + if (values.size() < requiredSize) { + grow(bucket); + } + int next = getNextGatherOffset(rootIndex); + assert 0 <= next && next < bucketSize + : "Expected next to be in the range of valid buckets [0 <= " + next + " < " + bucketSize + "]"; + long index = next + rootIndex; + values.set(index, value); + extraValues.set(index, extraValue); + if (next == 0) { + heapMode.set(bucket); + heapify(rootIndex, bucketSize); + } else { + setNextGatherOffset(rootIndex, next - 1); + } + } + + /** + * The order of the sort. + */ + public SortOrder getOrder() { + return order; + } + + /** + * The number of values to store per bucket. + */ + public int getBucketSize() { + return bucketSize; + } + + /** + * Get the first and last indexes (inclusive, exclusive) of the values for a bucket. + * Returns [0, 0] if the bucket has never been collected. + */ + private Tuple getBucketValuesIndexes(int bucket) { + long rootIndex = (long) bucket * bucketSize; + if (rootIndex >= values.size()) { + // We've never seen this bucket. + return Tuple.tuple(0L, 0L); + } + long start = inHeapMode(bucket) ? rootIndex : (rootIndex + getNextGatherOffset(rootIndex) + 1); + long end = rootIndex + bucketSize; + return Tuple.tuple(start, end); + } + + /** + * Merge the values from {@code other}'s {@code otherGroupId} into {@code groupId}. + */ + public void merge(int groupId, IntDoubleBucketedSort other, int otherGroupId) { + var otherBounds = other.getBucketValuesIndexes(otherGroupId); + + // TODO: This can be improved for heapified buckets by making use of the heap structures + for (long i = otherBounds.v1(); i < otherBounds.v2(); i++) { + collect(other.values.get(i), other.extraValues.get(i), groupId); + } + } + + /** + * Creates a block with the values from the {@code selected} groups. + */ + public void toBlocks(BlockFactory blockFactory, Block[] blocks, int offset, IntVector selected) { + // Check if the selected groups are all empty, to avoid allocating extra memory + if (allSelectedGroupsAreEmpty(selected)) { + blocks[offset] = blockFactory.newConstantNullBlock(selected.getPositionCount()); + blocks[offset + 1] = blockFactory.newConstantNullBlock(selected.getPositionCount()); + return; + } + + try ( + var builder = blockFactory.newIntBlockBuilder(selected.getPositionCount()); + var extraBuilder = blockFactory.newDoubleBlockBuilder(selected.getPositionCount()) + ) { + for (int s = 0; s < selected.getPositionCount(); s++) { + int bucket = selected.getInt(s); + + var bounds = getBucketValuesIndexes(bucket); + var rootIndex = bounds.v1(); + var size = bounds.v2() - bounds.v1(); + + if (size == 0) { + builder.appendNull(); + extraBuilder.appendNull(); + continue; + } + + if (size == 1) { + builder.appendInt(values.get(rootIndex)); + extraBuilder.appendDouble(extraValues.get(rootIndex)); + continue; + } + + // If we are in the gathering mode, we need to heapify before sorting. + if (inHeapMode(bucket) == false) { + heapify(rootIndex, (int) size); + } + heapSort(rootIndex, (int) size); + + builder.beginPositionEntry(); + extraBuilder.beginPositionEntry(); + for (int i = 0; i < size; i++) { + builder.appendInt(values.get(rootIndex + i)); + extraBuilder.appendDouble(extraValues.get(rootIndex + i)); + } + builder.endPositionEntry(); + extraBuilder.endPositionEntry(); + } + blocks[offset] = builder.build(); + blocks[offset + 1] = extraBuilder.build(); + } + } + + /** + * Checks if the selected groups are all empty. + */ + private boolean allSelectedGroupsAreEmpty(IntVector selected) { + return IntStream.range(0, selected.getPositionCount()).map(selected::getInt).noneMatch(bucket -> { + var bounds = this.getBucketValuesIndexes(bucket); + var size = bounds.v2() - bounds.v1(); + return size > 0; + }); + } + + /** + * Is this bucket a min heap {@code true} or in gathering mode {@code false}? + */ + private boolean inHeapMode(int bucket) { + return heapMode.get(bucket); + } + + /** + * Get the next index that should be "gathered" for a bucket rooted + * at {@code rootIndex}. + */ + private int getNextGatherOffset(long rootIndex) { + return values.get(rootIndex); + } + + /** + * Set the next index that should be "gathered" for a bucket rooted + * at {@code rootIndex}. + */ + private void setNextGatherOffset(long rootIndex, int offset) { + values.set(rootIndex, offset); + } + + /** + * {@code true} if the entry at index {@code lhs} is "better" than + * the entry at {@code rhs}. "Better" in this means "lower" for + * {@link SortOrder#ASC} and "higher" for {@link SortOrder#DESC}. + */ + private boolean betterThan(int lhs, int rhs, double lhsExtra, double rhsExtra) { + int res = Integer.compare(lhs, rhs); + if (res != 0) { + return getOrder().reverseMul() * res < 0; + } + res = Double.compare(lhsExtra, rhsExtra); + return getOrder().reverseMul() * res < 0; + } + + /** + * Swap the data at two indices. + */ + private void swap(long lhs, long rhs) { + var tmp = values.get(lhs); + values.set(lhs, values.get(rhs)); + values.set(rhs, tmp); + var tmpExtra = extraValues.get(lhs); + extraValues.set(lhs, extraValues.get(rhs)); + extraValues.set(rhs, tmpExtra); + } + + /** + * Allocate storage for more buckets and store the "next gather offset" + * for those new buckets. We always grow the storage by whole bucket's + * worth of slots at a time. We never allocate space for partial buckets. + */ + private void grow(int bucket) { + long oldMax = values.size(); + assert oldMax % bucketSize == 0; + + long newSize = BigArrays.overSize(((long) bucket + 1) * bucketSize, PageCacheRecycler.INT_PAGE_SIZE, Integer.BYTES); + // Round up to the next full bucket. + newSize = (newSize + bucketSize - 1) / bucketSize; + values = bigArrays.resize(values, newSize * bucketSize); + long newExtraSize = BigArrays.overSize(((long) bucket + 1) * bucketSize, PageCacheRecycler.DOUBLE_PAGE_SIZE, Double.BYTES); + // Round up to the next full bucket. + newExtraSize = (newExtraSize + bucketSize - 1) / bucketSize; + extraValues = bigArrays.resize(extraValues, newExtraSize * bucketSize); + // Set the next gather offsets for all newly allocated buckets. + fillGatherOffsets(oldMax); + } + + /** + * Maintain the "next gather offsets" for newly allocated buckets. + */ + private void fillGatherOffsets(long startingAt) { + int nextOffset = getBucketSize() - 1; + for (long bucketRoot = startingAt; bucketRoot < values.size(); bucketRoot += getBucketSize()) { + setNextGatherOffset(bucketRoot, nextOffset); + } + } + + /** + * Heapify a bucket whose entries are in random order. + *

+ * This works by validating the heap property on each node, iterating + * "upwards", pushing any out of order parents "down". Check out the + * wikipedia + * entry on binary heaps for more about this. + *

+ *

+ * While this *looks* like it could easily be {@code O(n * log n)}, it is + * a fairly well studied algorithm attributed to Floyd. There's + * been a bunch of work that puts this at {@code O(n)}, close to 1.88n worst + * case. + *

+ * + * @param rootIndex the index the start of the bucket + */ + private void heapify(long rootIndex, int heapSize) { + int maxParent = heapSize / 2 - 1; + for (int parent = maxParent; parent >= 0; parent--) { + downHeap(rootIndex, parent, heapSize); + } + } + + /** + * Sorts all the values in the heap using heap sort algorithm. + * This runs in {@code O(n log n)} time. + * @param rootIndex index of the start of the bucket + * @param heapSize Number of values that belong to the heap. + * Can be less than bucketSize. + * In such a case, the remaining values in range + * (rootIndex + heapSize, rootIndex + bucketSize) + * are *not* considered part of the heap. + */ + private void heapSort(long rootIndex, int heapSize) { + while (heapSize > 0) { + swap(rootIndex, rootIndex + heapSize - 1); + heapSize--; + downHeap(rootIndex, 0, heapSize); + } + } + + /** + * Correct the heap invariant of a parent and its children. This + * runs in {@code O(log n)} time. + * @param rootIndex index of the start of the bucket + * @param parent Index within the bucket of the parent to check. + * For example, 0 is the "root". + * @param heapSize Number of values that belong to the heap. + * Can be less than bucketSize. + * In such a case, the remaining values in range + * (rootIndex + heapSize, rootIndex + bucketSize) + * are *not* considered part of the heap. + */ + private void downHeap(long rootIndex, int parent, int heapSize) { + while (true) { + long parentIndex = rootIndex + parent; + int worst = parent; + long worstIndex = parentIndex; + int leftChild = parent * 2 + 1; + long leftIndex = rootIndex + leftChild; + if (leftChild < heapSize) { + if (betterThan(values.get(worstIndex), values.get(leftIndex), extraValues.get(worstIndex), extraValues.get(leftIndex))) { + worst = leftChild; + worstIndex = leftIndex; + } + int rightChild = leftChild + 1; + long rightIndex = rootIndex + rightChild; + if (rightChild < heapSize + && betterThan( + values.get(worstIndex), + values.get(rightIndex), + extraValues.get(worstIndex), + extraValues.get(rightIndex) + )) { + worst = rightChild; + worstIndex = rightIndex; + } + } + if (worst == parent) { + break; + } + swap(worstIndex, parentIndex); + parent = worst; + } + } + + @Override + public final void close() { + Releasables.close(values, extraValues, heapMode); + } +} diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/IntFloatBucketedSort.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/IntFloatBucketedSort.java new file mode 100644 index 0000000000000..5e4d278fa27fc --- /dev/null +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/IntFloatBucketedSort.java @@ -0,0 +1,406 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +package org.elasticsearch.compute.data.sort; + +import org.elasticsearch.common.util.BigArrays; +import org.elasticsearch.common.util.BitArray; +import org.elasticsearch.common.util.FloatArray; +import org.elasticsearch.common.util.IntArray; +import org.elasticsearch.common.util.PageCacheRecycler; +import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.BlockFactory; +import org.elasticsearch.compute.data.IntVector; +import org.elasticsearch.core.Releasable; +import org.elasticsearch.core.Releasables; +import org.elasticsearch.core.Tuple; +import org.elasticsearch.search.sort.BucketedSort; +import org.elasticsearch.search.sort.SortOrder; + +import java.util.stream.IntStream; + +/** + * Aggregates the top N {@code int} values per bucket. + * See {@link BucketedSort} for more information. + * This class is generated. Edit @{code X-BucketedSort.java.st} instead of this file. + */ +public class IntFloatBucketedSort implements Releasable { + + private final BigArrays bigArrays; + private final SortOrder order; + private final int bucketSize; + /** + * {@code true} if the bucket is in heap mode, {@code false} if + * it is still gathering. + */ + private final BitArray heapMode; + /** + * An array containing all the values on all buckets. The structure is as follows: + *

+ * For each bucket, there are bucketSize elements, based on the bucket id (0, 1, 2...). + * Then, for each bucket, it can be in 2 states: + *

+ *
    + *
  • + * Gather mode: All buckets start in gather mode, and remain here while they have less than bucketSize elements. + * In gather mode, the elements are stored in the array from the highest index to the lowest index. + * The lowest index contains the offset to the next slot to be filled. + *

    + * This allows us to insert elements in O(1) time. + *

    + *

    + * When the bucketSize-th element is collected, the bucket transitions to heap mode, by heapifying its contents. + *

    + *
  • + *
  • + * Heap mode: The bucket slots are organized as a min heap structure. + *

    + * The root of the heap is the minimum value in the bucket, + * which allows us to quickly discard new values that are not in the top N. + *

    + *
  • + *
+ */ + private IntArray values; + private FloatArray extraValues; + + public IntFloatBucketedSort(BigArrays bigArrays, SortOrder order, int bucketSize) { + this.bigArrays = bigArrays; + this.order = order; + this.bucketSize = bucketSize; + heapMode = new BitArray(0, bigArrays); + + boolean success = false; + try { + values = bigArrays.newIntArray(0, false); + extraValues = bigArrays.newFloatArray(0, false); + success = true; + } finally { + if (success == false) { + close(); + } + } + } + + /** + * Collects a {@code value} into a {@code bucket}. + *

+ * It may or may not be inserted in the heap, depending on if it is better than the current root. + *

+ */ + public void collect(int value, float extraValue, int bucket) { + long rootIndex = (long) bucket * bucketSize; + if (inHeapMode(bucket)) { + if (betterThan(value, values.get(rootIndex), extraValue, extraValues.get(rootIndex))) { + values.set(rootIndex, value); + extraValues.set(rootIndex, extraValue); + downHeap(rootIndex, 0, bucketSize); + } + return; + } + // Gathering mode + long requiredSize = rootIndex + bucketSize; + if (values.size() < requiredSize) { + grow(bucket); + } + int next = getNextGatherOffset(rootIndex); + assert 0 <= next && next < bucketSize + : "Expected next to be in the range of valid buckets [0 <= " + next + " < " + bucketSize + "]"; + long index = next + rootIndex; + values.set(index, value); + extraValues.set(index, extraValue); + if (next == 0) { + heapMode.set(bucket); + heapify(rootIndex, bucketSize); + } else { + setNextGatherOffset(rootIndex, next - 1); + } + } + + /** + * The order of the sort. + */ + public SortOrder getOrder() { + return order; + } + + /** + * The number of values to store per bucket. + */ + public int getBucketSize() { + return bucketSize; + } + + /** + * Get the first and last indexes (inclusive, exclusive) of the values for a bucket. + * Returns [0, 0] if the bucket has never been collected. + */ + private Tuple getBucketValuesIndexes(int bucket) { + long rootIndex = (long) bucket * bucketSize; + if (rootIndex >= values.size()) { + // We've never seen this bucket. + return Tuple.tuple(0L, 0L); + } + long start = inHeapMode(bucket) ? rootIndex : (rootIndex + getNextGatherOffset(rootIndex) + 1); + long end = rootIndex + bucketSize; + return Tuple.tuple(start, end); + } + + /** + * Merge the values from {@code other}'s {@code otherGroupId} into {@code groupId}. + */ + public void merge(int groupId, IntFloatBucketedSort other, int otherGroupId) { + var otherBounds = other.getBucketValuesIndexes(otherGroupId); + + // TODO: This can be improved for heapified buckets by making use of the heap structures + for (long i = otherBounds.v1(); i < otherBounds.v2(); i++) { + collect(other.values.get(i), other.extraValues.get(i), groupId); + } + } + + /** + * Creates a block with the values from the {@code selected} groups. + */ + public void toBlocks(BlockFactory blockFactory, Block[] blocks, int offset, IntVector selected) { + // Check if the selected groups are all empty, to avoid allocating extra memory + if (allSelectedGroupsAreEmpty(selected)) { + blocks[offset] = blockFactory.newConstantNullBlock(selected.getPositionCount()); + blocks[offset + 1] = blockFactory.newConstantNullBlock(selected.getPositionCount()); + return; + } + + try ( + var builder = blockFactory.newIntBlockBuilder(selected.getPositionCount()); + var extraBuilder = blockFactory.newFloatBlockBuilder(selected.getPositionCount()) + ) { + for (int s = 0; s < selected.getPositionCount(); s++) { + int bucket = selected.getInt(s); + + var bounds = getBucketValuesIndexes(bucket); + var rootIndex = bounds.v1(); + var size = bounds.v2() - bounds.v1(); + + if (size == 0) { + builder.appendNull(); + extraBuilder.appendNull(); + continue; + } + + if (size == 1) { + builder.appendInt(values.get(rootIndex)); + extraBuilder.appendFloat(extraValues.get(rootIndex)); + continue; + } + + // If we are in the gathering mode, we need to heapify before sorting. + if (inHeapMode(bucket) == false) { + heapify(rootIndex, (int) size); + } + heapSort(rootIndex, (int) size); + + builder.beginPositionEntry(); + extraBuilder.beginPositionEntry(); + for (int i = 0; i < size; i++) { + builder.appendInt(values.get(rootIndex + i)); + extraBuilder.appendFloat(extraValues.get(rootIndex + i)); + } + builder.endPositionEntry(); + extraBuilder.endPositionEntry(); + } + blocks[offset] = builder.build(); + blocks[offset + 1] = extraBuilder.build(); + } + } + + /** + * Checks if the selected groups are all empty. + */ + private boolean allSelectedGroupsAreEmpty(IntVector selected) { + return IntStream.range(0, selected.getPositionCount()).map(selected::getInt).noneMatch(bucket -> { + var bounds = this.getBucketValuesIndexes(bucket); + var size = bounds.v2() - bounds.v1(); + return size > 0; + }); + } + + /** + * Is this bucket a min heap {@code true} or in gathering mode {@code false}? + */ + private boolean inHeapMode(int bucket) { + return heapMode.get(bucket); + } + + /** + * Get the next index that should be "gathered" for a bucket rooted + * at {@code rootIndex}. + */ + private int getNextGatherOffset(long rootIndex) { + return values.get(rootIndex); + } + + /** + * Set the next index that should be "gathered" for a bucket rooted + * at {@code rootIndex}. + */ + private void setNextGatherOffset(long rootIndex, int offset) { + values.set(rootIndex, offset); + } + + /** + * {@code true} if the entry at index {@code lhs} is "better" than + * the entry at {@code rhs}. "Better" in this means "lower" for + * {@link SortOrder#ASC} and "higher" for {@link SortOrder#DESC}. + */ + private boolean betterThan(int lhs, int rhs, float lhsExtra, float rhsExtra) { + int res = Integer.compare(lhs, rhs); + if (res != 0) { + return getOrder().reverseMul() * res < 0; + } + res = Float.compare(lhsExtra, rhsExtra); + return getOrder().reverseMul() * res < 0; + } + + /** + * Swap the data at two indices. + */ + private void swap(long lhs, long rhs) { + var tmp = values.get(lhs); + values.set(lhs, values.get(rhs)); + values.set(rhs, tmp); + var tmpExtra = extraValues.get(lhs); + extraValues.set(lhs, extraValues.get(rhs)); + extraValues.set(rhs, tmpExtra); + } + + /** + * Allocate storage for more buckets and store the "next gather offset" + * for those new buckets. We always grow the storage by whole bucket's + * worth of slots at a time. We never allocate space for partial buckets. + */ + private void grow(int bucket) { + long oldMax = values.size(); + assert oldMax % bucketSize == 0; + + long newSize = BigArrays.overSize(((long) bucket + 1) * bucketSize, PageCacheRecycler.INT_PAGE_SIZE, Integer.BYTES); + // Round up to the next full bucket. + newSize = (newSize + bucketSize - 1) / bucketSize; + values = bigArrays.resize(values, newSize * bucketSize); + long newExtraSize = BigArrays.overSize(((long) bucket + 1) * bucketSize, PageCacheRecycler.FLOAT_PAGE_SIZE, Float.BYTES); + // Round up to the next full bucket. + newExtraSize = (newExtraSize + bucketSize - 1) / bucketSize; + extraValues = bigArrays.resize(extraValues, newExtraSize * bucketSize); + // Set the next gather offsets for all newly allocated buckets. + fillGatherOffsets(oldMax); + } + + /** + * Maintain the "next gather offsets" for newly allocated buckets. + */ + private void fillGatherOffsets(long startingAt) { + int nextOffset = getBucketSize() - 1; + for (long bucketRoot = startingAt; bucketRoot < values.size(); bucketRoot += getBucketSize()) { + setNextGatherOffset(bucketRoot, nextOffset); + } + } + + /** + * Heapify a bucket whose entries are in random order. + *

+ * This works by validating the heap property on each node, iterating + * "upwards", pushing any out of order parents "down". Check out the + * wikipedia + * entry on binary heaps for more about this. + *

+ *

+ * While this *looks* like it could easily be {@code O(n * log n)}, it is + * a fairly well studied algorithm attributed to Floyd. There's + * been a bunch of work that puts this at {@code O(n)}, close to 1.88n worst + * case. + *

+ * + * @param rootIndex the index the start of the bucket + */ + private void heapify(long rootIndex, int heapSize) { + int maxParent = heapSize / 2 - 1; + for (int parent = maxParent; parent >= 0; parent--) { + downHeap(rootIndex, parent, heapSize); + } + } + + /** + * Sorts all the values in the heap using heap sort algorithm. + * This runs in {@code O(n log n)} time. + * @param rootIndex index of the start of the bucket + * @param heapSize Number of values that belong to the heap. + * Can be less than bucketSize. + * In such a case, the remaining values in range + * (rootIndex + heapSize, rootIndex + bucketSize) + * are *not* considered part of the heap. + */ + private void heapSort(long rootIndex, int heapSize) { + while (heapSize > 0) { + swap(rootIndex, rootIndex + heapSize - 1); + heapSize--; + downHeap(rootIndex, 0, heapSize); + } + } + + /** + * Correct the heap invariant of a parent and its children. This + * runs in {@code O(log n)} time. + * @param rootIndex index of the start of the bucket + * @param parent Index within the bucket of the parent to check. + * For example, 0 is the "root". + * @param heapSize Number of values that belong to the heap. + * Can be less than bucketSize. + * In such a case, the remaining values in range + * (rootIndex + heapSize, rootIndex + bucketSize) + * are *not* considered part of the heap. + */ + private void downHeap(long rootIndex, int parent, int heapSize) { + while (true) { + long parentIndex = rootIndex + parent; + int worst = parent; + long worstIndex = parentIndex; + int leftChild = parent * 2 + 1; + long leftIndex = rootIndex + leftChild; + if (leftChild < heapSize) { + if (betterThan(values.get(worstIndex), values.get(leftIndex), extraValues.get(worstIndex), extraValues.get(leftIndex))) { + worst = leftChild; + worstIndex = leftIndex; + } + int rightChild = leftChild + 1; + long rightIndex = rootIndex + rightChild; + if (rightChild < heapSize + && betterThan( + values.get(worstIndex), + values.get(rightIndex), + extraValues.get(worstIndex), + extraValues.get(rightIndex) + )) { + worst = rightChild; + worstIndex = rightIndex; + } + } + if (worst == parent) { + break; + } + swap(worstIndex, parentIndex); + parent = worst; + } + } + + @Override + public final void close() { + Releasables.close(values, extraValues, heapMode); + } +} diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/IntIntBucketedSort.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/IntIntBucketedSort.java new file mode 100644 index 0000000000000..0ed8bb94a8022 --- /dev/null +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/IntIntBucketedSort.java @@ -0,0 +1,406 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +package org.elasticsearch.compute.data.sort; + +import org.elasticsearch.common.util.BigArrays; +import org.elasticsearch.common.util.BitArray; +import org.elasticsearch.common.util.IntArray; +import org.elasticsearch.common.util.IntArray; +import org.elasticsearch.common.util.PageCacheRecycler; +import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.BlockFactory; +import org.elasticsearch.compute.data.IntVector; +import org.elasticsearch.core.Releasable; +import org.elasticsearch.core.Releasables; +import org.elasticsearch.core.Tuple; +import org.elasticsearch.search.sort.BucketedSort; +import org.elasticsearch.search.sort.SortOrder; + +import java.util.stream.IntStream; + +/** + * Aggregates the top N {@code int} values per bucket. + * See {@link BucketedSort} for more information. + * This class is generated. Edit @{code X-BucketedSort.java.st} instead of this file. + */ +public class IntIntBucketedSort implements Releasable { + + private final BigArrays bigArrays; + private final SortOrder order; + private final int bucketSize; + /** + * {@code true} if the bucket is in heap mode, {@code false} if + * it is still gathering. + */ + private final BitArray heapMode; + /** + * An array containing all the values on all buckets. The structure is as follows: + *

+ * For each bucket, there are bucketSize elements, based on the bucket id (0, 1, 2...). + * Then, for each bucket, it can be in 2 states: + *

+ *
    + *
  • + * Gather mode: All buckets start in gather mode, and remain here while they have less than bucketSize elements. + * In gather mode, the elements are stored in the array from the highest index to the lowest index. + * The lowest index contains the offset to the next slot to be filled. + *

    + * This allows us to insert elements in O(1) time. + *

    + *

    + * When the bucketSize-th element is collected, the bucket transitions to heap mode, by heapifying its contents. + *

    + *
  • + *
  • + * Heap mode: The bucket slots are organized as a min heap structure. + *

    + * The root of the heap is the minimum value in the bucket, + * which allows us to quickly discard new values that are not in the top N. + *

    + *
  • + *
+ */ + private IntArray values; + private IntArray extraValues; + + public IntIntBucketedSort(BigArrays bigArrays, SortOrder order, int bucketSize) { + this.bigArrays = bigArrays; + this.order = order; + this.bucketSize = bucketSize; + heapMode = new BitArray(0, bigArrays); + + boolean success = false; + try { + values = bigArrays.newIntArray(0, false); + extraValues = bigArrays.newIntArray(0, false); + success = true; + } finally { + if (success == false) { + close(); + } + } + } + + /** + * Collects a {@code value} into a {@code bucket}. + *

+ * It may or may not be inserted in the heap, depending on if it is better than the current root. + *

+ */ + public void collect(int value, int extraValue, int bucket) { + long rootIndex = (long) bucket * bucketSize; + if (inHeapMode(bucket)) { + if (betterThan(value, values.get(rootIndex), extraValue, extraValues.get(rootIndex))) { + values.set(rootIndex, value); + extraValues.set(rootIndex, extraValue); + downHeap(rootIndex, 0, bucketSize); + } + return; + } + // Gathering mode + long requiredSize = rootIndex + bucketSize; + if (values.size() < requiredSize) { + grow(bucket); + } + int next = getNextGatherOffset(rootIndex); + assert 0 <= next && next < bucketSize + : "Expected next to be in the range of valid buckets [0 <= " + next + " < " + bucketSize + "]"; + long index = next + rootIndex; + values.set(index, value); + extraValues.set(index, extraValue); + if (next == 0) { + heapMode.set(bucket); + heapify(rootIndex, bucketSize); + } else { + setNextGatherOffset(rootIndex, next - 1); + } + } + + /** + * The order of the sort. + */ + public SortOrder getOrder() { + return order; + } + + /** + * The number of values to store per bucket. + */ + public int getBucketSize() { + return bucketSize; + } + + /** + * Get the first and last indexes (inclusive, exclusive) of the values for a bucket. + * Returns [0, 0] if the bucket has never been collected. + */ + private Tuple getBucketValuesIndexes(int bucket) { + long rootIndex = (long) bucket * bucketSize; + if (rootIndex >= values.size()) { + // We've never seen this bucket. + return Tuple.tuple(0L, 0L); + } + long start = inHeapMode(bucket) ? rootIndex : (rootIndex + getNextGatherOffset(rootIndex) + 1); + long end = rootIndex + bucketSize; + return Tuple.tuple(start, end); + } + + /** + * Merge the values from {@code other}'s {@code otherGroupId} into {@code groupId}. + */ + public void merge(int groupId, IntIntBucketedSort other, int otherGroupId) { + var otherBounds = other.getBucketValuesIndexes(otherGroupId); + + // TODO: This can be improved for heapified buckets by making use of the heap structures + for (long i = otherBounds.v1(); i < otherBounds.v2(); i++) { + collect(other.values.get(i), other.extraValues.get(i), groupId); + } + } + + /** + * Creates a block with the values from the {@code selected} groups. + */ + public void toBlocks(BlockFactory blockFactory, Block[] blocks, int offset, IntVector selected) { + // Check if the selected groups are all empty, to avoid allocating extra memory + if (allSelectedGroupsAreEmpty(selected)) { + blocks[offset] = blockFactory.newConstantNullBlock(selected.getPositionCount()); + blocks[offset + 1] = blockFactory.newConstantNullBlock(selected.getPositionCount()); + return; + } + + try ( + var builder = blockFactory.newIntBlockBuilder(selected.getPositionCount()); + var extraBuilder = blockFactory.newIntBlockBuilder(selected.getPositionCount()) + ) { + for (int s = 0; s < selected.getPositionCount(); s++) { + int bucket = selected.getInt(s); + + var bounds = getBucketValuesIndexes(bucket); + var rootIndex = bounds.v1(); + var size = bounds.v2() - bounds.v1(); + + if (size == 0) { + builder.appendNull(); + extraBuilder.appendNull(); + continue; + } + + if (size == 1) { + builder.appendInt(values.get(rootIndex)); + extraBuilder.appendInt(extraValues.get(rootIndex)); + continue; + } + + // If we are in the gathering mode, we need to heapify before sorting. + if (inHeapMode(bucket) == false) { + heapify(rootIndex, (int) size); + } + heapSort(rootIndex, (int) size); + + builder.beginPositionEntry(); + extraBuilder.beginPositionEntry(); + for (int i = 0; i < size; i++) { + builder.appendInt(values.get(rootIndex + i)); + extraBuilder.appendInt(extraValues.get(rootIndex + i)); + } + builder.endPositionEntry(); + extraBuilder.endPositionEntry(); + } + blocks[offset] = builder.build(); + blocks[offset + 1] = extraBuilder.build(); + } + } + + /** + * Checks if the selected groups are all empty. + */ + private boolean allSelectedGroupsAreEmpty(IntVector selected) { + return IntStream.range(0, selected.getPositionCount()).map(selected::getInt).noneMatch(bucket -> { + var bounds = this.getBucketValuesIndexes(bucket); + var size = bounds.v2() - bounds.v1(); + return size > 0; + }); + } + + /** + * Is this bucket a min heap {@code true} or in gathering mode {@code false}? + */ + private boolean inHeapMode(int bucket) { + return heapMode.get(bucket); + } + + /** + * Get the next index that should be "gathered" for a bucket rooted + * at {@code rootIndex}. + */ + private int getNextGatherOffset(long rootIndex) { + return values.get(rootIndex); + } + + /** + * Set the next index that should be "gathered" for a bucket rooted + * at {@code rootIndex}. + */ + private void setNextGatherOffset(long rootIndex, int offset) { + values.set(rootIndex, offset); + } + + /** + * {@code true} if the entry at index {@code lhs} is "better" than + * the entry at {@code rhs}. "Better" in this means "lower" for + * {@link SortOrder#ASC} and "higher" for {@link SortOrder#DESC}. + */ + private boolean betterThan(int lhs, int rhs, int lhsExtra, int rhsExtra) { + int res = Integer.compare(lhs, rhs); + if (res != 0) { + return getOrder().reverseMul() * res < 0; + } + res = Integer.compare(lhsExtra, rhsExtra); + return getOrder().reverseMul() * res < 0; + } + + /** + * Swap the data at two indices. + */ + private void swap(long lhs, long rhs) { + var tmp = values.get(lhs); + values.set(lhs, values.get(rhs)); + values.set(rhs, tmp); + var tmpExtra = extraValues.get(lhs); + extraValues.set(lhs, extraValues.get(rhs)); + extraValues.set(rhs, tmpExtra); + } + + /** + * Allocate storage for more buckets and store the "next gather offset" + * for those new buckets. We always grow the storage by whole bucket's + * worth of slots at a time. We never allocate space for partial buckets. + */ + private void grow(int bucket) { + long oldMax = values.size(); + assert oldMax % bucketSize == 0; + + long newSize = BigArrays.overSize(((long) bucket + 1) * bucketSize, PageCacheRecycler.INT_PAGE_SIZE, Integer.BYTES); + // Round up to the next full bucket. + newSize = (newSize + bucketSize - 1) / bucketSize; + values = bigArrays.resize(values, newSize * bucketSize); + long newExtraSize = BigArrays.overSize(((long) bucket + 1) * bucketSize, PageCacheRecycler.INT_PAGE_SIZE, Integer.BYTES); + // Round up to the next full bucket. + newExtraSize = (newExtraSize + bucketSize - 1) / bucketSize; + extraValues = bigArrays.resize(extraValues, newExtraSize * bucketSize); + // Set the next gather offsets for all newly allocated buckets. + fillGatherOffsets(oldMax); + } + + /** + * Maintain the "next gather offsets" for newly allocated buckets. + */ + private void fillGatherOffsets(long startingAt) { + int nextOffset = getBucketSize() - 1; + for (long bucketRoot = startingAt; bucketRoot < values.size(); bucketRoot += getBucketSize()) { + setNextGatherOffset(bucketRoot, nextOffset); + } + } + + /** + * Heapify a bucket whose entries are in random order. + *

+ * This works by validating the heap property on each node, iterating + * "upwards", pushing any out of order parents "down". Check out the + * wikipedia + * entry on binary heaps for more about this. + *

+ *

+ * While this *looks* like it could easily be {@code O(n * log n)}, it is + * a fairly well studied algorithm attributed to Floyd. There's + * been a bunch of work that puts this at {@code O(n)}, close to 1.88n worst + * case. + *

+ * + * @param rootIndex the index the start of the bucket + */ + private void heapify(long rootIndex, int heapSize) { + int maxParent = heapSize / 2 - 1; + for (int parent = maxParent; parent >= 0; parent--) { + downHeap(rootIndex, parent, heapSize); + } + } + + /** + * Sorts all the values in the heap using heap sort algorithm. + * This runs in {@code O(n log n)} time. + * @param rootIndex index of the start of the bucket + * @param heapSize Number of values that belong to the heap. + * Can be less than bucketSize. + * In such a case, the remaining values in range + * (rootIndex + heapSize, rootIndex + bucketSize) + * are *not* considered part of the heap. + */ + private void heapSort(long rootIndex, int heapSize) { + while (heapSize > 0) { + swap(rootIndex, rootIndex + heapSize - 1); + heapSize--; + downHeap(rootIndex, 0, heapSize); + } + } + + /** + * Correct the heap invariant of a parent and its children. This + * runs in {@code O(log n)} time. + * @param rootIndex index of the start of the bucket + * @param parent Index within the bucket of the parent to check. + * For example, 0 is the "root". + * @param heapSize Number of values that belong to the heap. + * Can be less than bucketSize. + * In such a case, the remaining values in range + * (rootIndex + heapSize, rootIndex + bucketSize) + * are *not* considered part of the heap. + */ + private void downHeap(long rootIndex, int parent, int heapSize) { + while (true) { + long parentIndex = rootIndex + parent; + int worst = parent; + long worstIndex = parentIndex; + int leftChild = parent * 2 + 1; + long leftIndex = rootIndex + leftChild; + if (leftChild < heapSize) { + if (betterThan(values.get(worstIndex), values.get(leftIndex), extraValues.get(worstIndex), extraValues.get(leftIndex))) { + worst = leftChild; + worstIndex = leftIndex; + } + int rightChild = leftChild + 1; + long rightIndex = rootIndex + rightChild; + if (rightChild < heapSize + && betterThan( + values.get(worstIndex), + values.get(rightIndex), + extraValues.get(worstIndex), + extraValues.get(rightIndex) + )) { + worst = rightChild; + worstIndex = rightIndex; + } + } + if (worst == parent) { + break; + } + swap(worstIndex, parentIndex); + parent = worst; + } + } + + @Override + public final void close() { + Releasables.close(values, extraValues, heapMode); + } +} diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/IntLongBucketedSort.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/IntLongBucketedSort.java new file mode 100644 index 0000000000000..7b7d3d3d76be2 --- /dev/null +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/IntLongBucketedSort.java @@ -0,0 +1,406 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +package org.elasticsearch.compute.data.sort; + +import org.elasticsearch.common.util.BigArrays; +import org.elasticsearch.common.util.BitArray; +import org.elasticsearch.common.util.LongArray; +import org.elasticsearch.common.util.IntArray; +import org.elasticsearch.common.util.PageCacheRecycler; +import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.BlockFactory; +import org.elasticsearch.compute.data.IntVector; +import org.elasticsearch.core.Releasable; +import org.elasticsearch.core.Releasables; +import org.elasticsearch.core.Tuple; +import org.elasticsearch.search.sort.BucketedSort; +import org.elasticsearch.search.sort.SortOrder; + +import java.util.stream.IntStream; + +/** + * Aggregates the top N {@code int} values per bucket. + * See {@link BucketedSort} for more information. + * This class is generated. Edit @{code X-BucketedSort.java.st} instead of this file. + */ +public class IntLongBucketedSort implements Releasable { + + private final BigArrays bigArrays; + private final SortOrder order; + private final int bucketSize; + /** + * {@code true} if the bucket is in heap mode, {@code false} if + * it is still gathering. + */ + private final BitArray heapMode; + /** + * An array containing all the values on all buckets. The structure is as follows: + *

+ * For each bucket, there are bucketSize elements, based on the bucket id (0, 1, 2...). + * Then, for each bucket, it can be in 2 states: + *

+ *
    + *
  • + * Gather mode: All buckets start in gather mode, and remain here while they have less than bucketSize elements. + * In gather mode, the elements are stored in the array from the highest index to the lowest index. + * The lowest index contains the offset to the next slot to be filled. + *

    + * This allows us to insert elements in O(1) time. + *

    + *

    + * When the bucketSize-th element is collected, the bucket transitions to heap mode, by heapifying its contents. + *

    + *
  • + *
  • + * Heap mode: The bucket slots are organized as a min heap structure. + *

    + * The root of the heap is the minimum value in the bucket, + * which allows us to quickly discard new values that are not in the top N. + *

    + *
  • + *
+ */ + private IntArray values; + private LongArray extraValues; + + public IntLongBucketedSort(BigArrays bigArrays, SortOrder order, int bucketSize) { + this.bigArrays = bigArrays; + this.order = order; + this.bucketSize = bucketSize; + heapMode = new BitArray(0, bigArrays); + + boolean success = false; + try { + values = bigArrays.newIntArray(0, false); + extraValues = bigArrays.newLongArray(0, false); + success = true; + } finally { + if (success == false) { + close(); + } + } + } + + /** + * Collects a {@code value} into a {@code bucket}. + *

+ * It may or may not be inserted in the heap, depending on if it is better than the current root. + *

+ */ + public void collect(int value, long extraValue, int bucket) { + long rootIndex = (long) bucket * bucketSize; + if (inHeapMode(bucket)) { + if (betterThan(value, values.get(rootIndex), extraValue, extraValues.get(rootIndex))) { + values.set(rootIndex, value); + extraValues.set(rootIndex, extraValue); + downHeap(rootIndex, 0, bucketSize); + } + return; + } + // Gathering mode + long requiredSize = rootIndex + bucketSize; + if (values.size() < requiredSize) { + grow(bucket); + } + int next = getNextGatherOffset(rootIndex); + assert 0 <= next && next < bucketSize + : "Expected next to be in the range of valid buckets [0 <= " + next + " < " + bucketSize + "]"; + long index = next + rootIndex; + values.set(index, value); + extraValues.set(index, extraValue); + if (next == 0) { + heapMode.set(bucket); + heapify(rootIndex, bucketSize); + } else { + setNextGatherOffset(rootIndex, next - 1); + } + } + + /** + * The order of the sort. + */ + public SortOrder getOrder() { + return order; + } + + /** + * The number of values to store per bucket. + */ + public int getBucketSize() { + return bucketSize; + } + + /** + * Get the first and last indexes (inclusive, exclusive) of the values for a bucket. + * Returns [0, 0] if the bucket has never been collected. + */ + private Tuple getBucketValuesIndexes(int bucket) { + long rootIndex = (long) bucket * bucketSize; + if (rootIndex >= values.size()) { + // We've never seen this bucket. + return Tuple.tuple(0L, 0L); + } + long start = inHeapMode(bucket) ? rootIndex : (rootIndex + getNextGatherOffset(rootIndex) + 1); + long end = rootIndex + bucketSize; + return Tuple.tuple(start, end); + } + + /** + * Merge the values from {@code other}'s {@code otherGroupId} into {@code groupId}. + */ + public void merge(int groupId, IntLongBucketedSort other, int otherGroupId) { + var otherBounds = other.getBucketValuesIndexes(otherGroupId); + + // TODO: This can be improved for heapified buckets by making use of the heap structures + for (long i = otherBounds.v1(); i < otherBounds.v2(); i++) { + collect(other.values.get(i), other.extraValues.get(i), groupId); + } + } + + /** + * Creates a block with the values from the {@code selected} groups. + */ + public void toBlocks(BlockFactory blockFactory, Block[] blocks, int offset, IntVector selected) { + // Check if the selected groups are all empty, to avoid allocating extra memory + if (allSelectedGroupsAreEmpty(selected)) { + blocks[offset] = blockFactory.newConstantNullBlock(selected.getPositionCount()); + blocks[offset + 1] = blockFactory.newConstantNullBlock(selected.getPositionCount()); + return; + } + + try ( + var builder = blockFactory.newIntBlockBuilder(selected.getPositionCount()); + var extraBuilder = blockFactory.newLongBlockBuilder(selected.getPositionCount()) + ) { + for (int s = 0; s < selected.getPositionCount(); s++) { + int bucket = selected.getInt(s); + + var bounds = getBucketValuesIndexes(bucket); + var rootIndex = bounds.v1(); + var size = bounds.v2() - bounds.v1(); + + if (size == 0) { + builder.appendNull(); + extraBuilder.appendNull(); + continue; + } + + if (size == 1) { + builder.appendInt(values.get(rootIndex)); + extraBuilder.appendLong(extraValues.get(rootIndex)); + continue; + } + + // If we are in the gathering mode, we need to heapify before sorting. + if (inHeapMode(bucket) == false) { + heapify(rootIndex, (int) size); + } + heapSort(rootIndex, (int) size); + + builder.beginPositionEntry(); + extraBuilder.beginPositionEntry(); + for (int i = 0; i < size; i++) { + builder.appendInt(values.get(rootIndex + i)); + extraBuilder.appendLong(extraValues.get(rootIndex + i)); + } + builder.endPositionEntry(); + extraBuilder.endPositionEntry(); + } + blocks[offset] = builder.build(); + blocks[offset + 1] = extraBuilder.build(); + } + } + + /** + * Checks if the selected groups are all empty. + */ + private boolean allSelectedGroupsAreEmpty(IntVector selected) { + return IntStream.range(0, selected.getPositionCount()).map(selected::getInt).noneMatch(bucket -> { + var bounds = this.getBucketValuesIndexes(bucket); + var size = bounds.v2() - bounds.v1(); + return size > 0; + }); + } + + /** + * Is this bucket a min heap {@code true} or in gathering mode {@code false}? + */ + private boolean inHeapMode(int bucket) { + return heapMode.get(bucket); + } + + /** + * Get the next index that should be "gathered" for a bucket rooted + * at {@code rootIndex}. + */ + private int getNextGatherOffset(long rootIndex) { + return values.get(rootIndex); + } + + /** + * Set the next index that should be "gathered" for a bucket rooted + * at {@code rootIndex}. + */ + private void setNextGatherOffset(long rootIndex, int offset) { + values.set(rootIndex, offset); + } + + /** + * {@code true} if the entry at index {@code lhs} is "better" than + * the entry at {@code rhs}. "Better" in this means "lower" for + * {@link SortOrder#ASC} and "higher" for {@link SortOrder#DESC}. + */ + private boolean betterThan(int lhs, int rhs, long lhsExtra, long rhsExtra) { + int res = Integer.compare(lhs, rhs); + if (res != 0) { + return getOrder().reverseMul() * res < 0; + } + res = Long.compare(lhsExtra, rhsExtra); + return getOrder().reverseMul() * res < 0; + } + + /** + * Swap the data at two indices. + */ + private void swap(long lhs, long rhs) { + var tmp = values.get(lhs); + values.set(lhs, values.get(rhs)); + values.set(rhs, tmp); + var tmpExtra = extraValues.get(lhs); + extraValues.set(lhs, extraValues.get(rhs)); + extraValues.set(rhs, tmpExtra); + } + + /** + * Allocate storage for more buckets and store the "next gather offset" + * for those new buckets. We always grow the storage by whole bucket's + * worth of slots at a time. We never allocate space for partial buckets. + */ + private void grow(int bucket) { + long oldMax = values.size(); + assert oldMax % bucketSize == 0; + + long newSize = BigArrays.overSize(((long) bucket + 1) * bucketSize, PageCacheRecycler.INT_PAGE_SIZE, Integer.BYTES); + // Round up to the next full bucket. + newSize = (newSize + bucketSize - 1) / bucketSize; + values = bigArrays.resize(values, newSize * bucketSize); + long newExtraSize = BigArrays.overSize(((long) bucket + 1) * bucketSize, PageCacheRecycler.LONG_PAGE_SIZE, Long.BYTES); + // Round up to the next full bucket. + newExtraSize = (newExtraSize + bucketSize - 1) / bucketSize; + extraValues = bigArrays.resize(extraValues, newExtraSize * bucketSize); + // Set the next gather offsets for all newly allocated buckets. + fillGatherOffsets(oldMax); + } + + /** + * Maintain the "next gather offsets" for newly allocated buckets. + */ + private void fillGatherOffsets(long startingAt) { + int nextOffset = getBucketSize() - 1; + for (long bucketRoot = startingAt; bucketRoot < values.size(); bucketRoot += getBucketSize()) { + setNextGatherOffset(bucketRoot, nextOffset); + } + } + + /** + * Heapify a bucket whose entries are in random order. + *

+ * This works by validating the heap property on each node, iterating + * "upwards", pushing any out of order parents "down". Check out the + * wikipedia + * entry on binary heaps for more about this. + *

+ *

+ * While this *looks* like it could easily be {@code O(n * log n)}, it is + * a fairly well studied algorithm attributed to Floyd. There's + * been a bunch of work that puts this at {@code O(n)}, close to 1.88n worst + * case. + *

+ * + * @param rootIndex the index the start of the bucket + */ + private void heapify(long rootIndex, int heapSize) { + int maxParent = heapSize / 2 - 1; + for (int parent = maxParent; parent >= 0; parent--) { + downHeap(rootIndex, parent, heapSize); + } + } + + /** + * Sorts all the values in the heap using heap sort algorithm. + * This runs in {@code O(n log n)} time. + * @param rootIndex index of the start of the bucket + * @param heapSize Number of values that belong to the heap. + * Can be less than bucketSize. + * In such a case, the remaining values in range + * (rootIndex + heapSize, rootIndex + bucketSize) + * are *not* considered part of the heap. + */ + private void heapSort(long rootIndex, int heapSize) { + while (heapSize > 0) { + swap(rootIndex, rootIndex + heapSize - 1); + heapSize--; + downHeap(rootIndex, 0, heapSize); + } + } + + /** + * Correct the heap invariant of a parent and its children. This + * runs in {@code O(log n)} time. + * @param rootIndex index of the start of the bucket + * @param parent Index within the bucket of the parent to check. + * For example, 0 is the "root". + * @param heapSize Number of values that belong to the heap. + * Can be less than bucketSize. + * In such a case, the remaining values in range + * (rootIndex + heapSize, rootIndex + bucketSize) + * are *not* considered part of the heap. + */ + private void downHeap(long rootIndex, int parent, int heapSize) { + while (true) { + long parentIndex = rootIndex + parent; + int worst = parent; + long worstIndex = parentIndex; + int leftChild = parent * 2 + 1; + long leftIndex = rootIndex + leftChild; + if (leftChild < heapSize) { + if (betterThan(values.get(worstIndex), values.get(leftIndex), extraValues.get(worstIndex), extraValues.get(leftIndex))) { + worst = leftChild; + worstIndex = leftIndex; + } + int rightChild = leftChild + 1; + long rightIndex = rootIndex + rightChild; + if (rightChild < heapSize + && betterThan( + values.get(worstIndex), + values.get(rightIndex), + extraValues.get(worstIndex), + extraValues.get(rightIndex) + )) { + worst = rightChild; + worstIndex = rightIndex; + } + } + if (worst == parent) { + break; + } + swap(worstIndex, parentIndex); + parent = worst; + } + } + + @Override + public final void close() { + Releasables.close(values, extraValues, heapMode); + } +} diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/LongBucketedSort.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/LongBucketedSort.java index ac472cc411668..e10ce05017d23 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/LongBucketedSort.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/LongBucketedSort.java @@ -23,7 +23,7 @@ import java.util.stream.IntStream; /** - * Aggregates the top N long values per bucket. + * Aggregates the top N {@code long} values per bucket. * See {@link BucketedSort} for more information. * This class is generated. Edit @{code X-BucketedSort.java.st} instead of this file. */ @@ -162,12 +162,7 @@ public void merge(int groupId, LongBucketedSort other, int otherGroupId) { */ public Block toBlock(BlockFactory blockFactory, IntVector selected) { // Check if the selected groups are all empty, to avoid allocating extra memory - if (IntStream.range(0, selected.getPositionCount()).map(selected::getInt).noneMatch(bucket -> { - var bounds = this.getBucketValuesIndexes(bucket); - var size = bounds.v2() - bounds.v1(); - - return size > 0; - })) { + if (allSelectedGroupsAreEmpty(selected)) { return blockFactory.newConstantNullBlock(selected.getPositionCount()); } @@ -185,7 +180,7 @@ public Block toBlock(BlockFactory blockFactory, IntVector selected) { } if (size == 1) { - builder.appendLong(values.get(bounds.v1())); + builder.appendLong(values.get(rootIndex)); continue; } @@ -197,7 +192,7 @@ public Block toBlock(BlockFactory blockFactory, IntVector selected) { builder.beginPositionEntry(); for (int i = 0; i < size; i++) { - builder.appendLong(values.get(bounds.v1() + i)); + builder.appendLong(values.get(rootIndex + i)); } builder.endPositionEntry(); } @@ -205,6 +200,17 @@ public Block toBlock(BlockFactory blockFactory, IntVector selected) { } } + /** + * Checks if the selected groups are all empty. + */ + private boolean allSelectedGroupsAreEmpty(IntVector selected) { + return IntStream.range(0, selected.getPositionCount()).map(selected::getInt).noneMatch(bucket -> { + var bounds = this.getBucketValuesIndexes(bucket); + var size = bounds.v2() - bounds.v1(); + return size > 0; + }); + } + /** * Is this bucket a min heap {@code true} or in gathering mode {@code false}? */ @@ -234,7 +240,8 @@ private void setNextGatherOffset(long rootIndex, int offset) { * {@link SortOrder#ASC} and "higher" for {@link SortOrder#DESC}. */ private boolean betterThan(long lhs, long rhs) { - return getOrder().reverseMul() * Long.compare(lhs, rhs) < 0; + int res = Long.compare(lhs, rhs); + return getOrder().reverseMul() * res < 0; } /** diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/LongDoubleBucketedSort.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/LongDoubleBucketedSort.java new file mode 100644 index 0000000000000..41f644affe51b --- /dev/null +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/LongDoubleBucketedSort.java @@ -0,0 +1,406 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +package org.elasticsearch.compute.data.sort; + +import org.elasticsearch.common.util.BigArrays; +import org.elasticsearch.common.util.BitArray; +import org.elasticsearch.common.util.DoubleArray; +import org.elasticsearch.common.util.LongArray; +import org.elasticsearch.common.util.PageCacheRecycler; +import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.BlockFactory; +import org.elasticsearch.compute.data.IntVector; +import org.elasticsearch.core.Releasable; +import org.elasticsearch.core.Releasables; +import org.elasticsearch.core.Tuple; +import org.elasticsearch.search.sort.BucketedSort; +import org.elasticsearch.search.sort.SortOrder; + +import java.util.stream.IntStream; + +/** + * Aggregates the top N {@code long} values per bucket. + * See {@link BucketedSort} for more information. + * This class is generated. Edit @{code X-BucketedSort.java.st} instead of this file. + */ +public class LongDoubleBucketedSort implements Releasable { + + private final BigArrays bigArrays; + private final SortOrder order; + private final int bucketSize; + /** + * {@code true} if the bucket is in heap mode, {@code false} if + * it is still gathering. + */ + private final BitArray heapMode; + /** + * An array containing all the values on all buckets. The structure is as follows: + *

+ * For each bucket, there are bucketSize elements, based on the bucket id (0, 1, 2...). + * Then, for each bucket, it can be in 2 states: + *

+ *
    + *
  • + * Gather mode: All buckets start in gather mode, and remain here while they have less than bucketSize elements. + * In gather mode, the elements are stored in the array from the highest index to the lowest index. + * The lowest index contains the offset to the next slot to be filled. + *

    + * This allows us to insert elements in O(1) time. + *

    + *

    + * When the bucketSize-th element is collected, the bucket transitions to heap mode, by heapifying its contents. + *

    + *
  • + *
  • + * Heap mode: The bucket slots are organized as a min heap structure. + *

    + * The root of the heap is the minimum value in the bucket, + * which allows us to quickly discard new values that are not in the top N. + *

    + *
  • + *
+ */ + private LongArray values; + private DoubleArray extraValues; + + public LongDoubleBucketedSort(BigArrays bigArrays, SortOrder order, int bucketSize) { + this.bigArrays = bigArrays; + this.order = order; + this.bucketSize = bucketSize; + heapMode = new BitArray(0, bigArrays); + + boolean success = false; + try { + values = bigArrays.newLongArray(0, false); + extraValues = bigArrays.newDoubleArray(0, false); + success = true; + } finally { + if (success == false) { + close(); + } + } + } + + /** + * Collects a {@code value} into a {@code bucket}. + *

+ * It may or may not be inserted in the heap, depending on if it is better than the current root. + *

+ */ + public void collect(long value, double extraValue, int bucket) { + long rootIndex = (long) bucket * bucketSize; + if (inHeapMode(bucket)) { + if (betterThan(value, values.get(rootIndex), extraValue, extraValues.get(rootIndex))) { + values.set(rootIndex, value); + extraValues.set(rootIndex, extraValue); + downHeap(rootIndex, 0, bucketSize); + } + return; + } + // Gathering mode + long requiredSize = rootIndex + bucketSize; + if (values.size() < requiredSize) { + grow(bucket); + } + int next = getNextGatherOffset(rootIndex); + assert 0 <= next && next < bucketSize + : "Expected next to be in the range of valid buckets [0 <= " + next + " < " + bucketSize + "]"; + long index = next + rootIndex; + values.set(index, value); + extraValues.set(index, extraValue); + if (next == 0) { + heapMode.set(bucket); + heapify(rootIndex, bucketSize); + } else { + setNextGatherOffset(rootIndex, next - 1); + } + } + + /** + * The order of the sort. + */ + public SortOrder getOrder() { + return order; + } + + /** + * The number of values to store per bucket. + */ + public int getBucketSize() { + return bucketSize; + } + + /** + * Get the first and last indexes (inclusive, exclusive) of the values for a bucket. + * Returns [0, 0] if the bucket has never been collected. + */ + private Tuple getBucketValuesIndexes(int bucket) { + long rootIndex = (long) bucket * bucketSize; + if (rootIndex >= values.size()) { + // We've never seen this bucket. + return Tuple.tuple(0L, 0L); + } + long start = inHeapMode(bucket) ? rootIndex : (rootIndex + getNextGatherOffset(rootIndex) + 1); + long end = rootIndex + bucketSize; + return Tuple.tuple(start, end); + } + + /** + * Merge the values from {@code other}'s {@code otherGroupId} into {@code groupId}. + */ + public void merge(int groupId, LongDoubleBucketedSort other, int otherGroupId) { + var otherBounds = other.getBucketValuesIndexes(otherGroupId); + + // TODO: This can be improved for heapified buckets by making use of the heap structures + for (long i = otherBounds.v1(); i < otherBounds.v2(); i++) { + collect(other.values.get(i), other.extraValues.get(i), groupId); + } + } + + /** + * Creates a block with the values from the {@code selected} groups. + */ + public void toBlocks(BlockFactory blockFactory, Block[] blocks, int offset, IntVector selected) { + // Check if the selected groups are all empty, to avoid allocating extra memory + if (allSelectedGroupsAreEmpty(selected)) { + blocks[offset] = blockFactory.newConstantNullBlock(selected.getPositionCount()); + blocks[offset + 1] = blockFactory.newConstantNullBlock(selected.getPositionCount()); + return; + } + + try ( + var builder = blockFactory.newLongBlockBuilder(selected.getPositionCount()); + var extraBuilder = blockFactory.newDoubleBlockBuilder(selected.getPositionCount()) + ) { + for (int s = 0; s < selected.getPositionCount(); s++) { + int bucket = selected.getInt(s); + + var bounds = getBucketValuesIndexes(bucket); + var rootIndex = bounds.v1(); + var size = bounds.v2() - bounds.v1(); + + if (size == 0) { + builder.appendNull(); + extraBuilder.appendNull(); + continue; + } + + if (size == 1) { + builder.appendLong(values.get(rootIndex)); + extraBuilder.appendDouble(extraValues.get(rootIndex)); + continue; + } + + // If we are in the gathering mode, we need to heapify before sorting. + if (inHeapMode(bucket) == false) { + heapify(rootIndex, (int) size); + } + heapSort(rootIndex, (int) size); + + builder.beginPositionEntry(); + extraBuilder.beginPositionEntry(); + for (int i = 0; i < size; i++) { + builder.appendLong(values.get(rootIndex + i)); + extraBuilder.appendDouble(extraValues.get(rootIndex + i)); + } + builder.endPositionEntry(); + extraBuilder.endPositionEntry(); + } + blocks[offset] = builder.build(); + blocks[offset + 1] = extraBuilder.build(); + } + } + + /** + * Checks if the selected groups are all empty. + */ + private boolean allSelectedGroupsAreEmpty(IntVector selected) { + return IntStream.range(0, selected.getPositionCount()).map(selected::getInt).noneMatch(bucket -> { + var bounds = this.getBucketValuesIndexes(bucket); + var size = bounds.v2() - bounds.v1(); + return size > 0; + }); + } + + /** + * Is this bucket a min heap {@code true} or in gathering mode {@code false}? + */ + private boolean inHeapMode(int bucket) { + return heapMode.get(bucket); + } + + /** + * Get the next index that should be "gathered" for a bucket rooted + * at {@code rootIndex}. + */ + private int getNextGatherOffset(long rootIndex) { + return (int) values.get(rootIndex); + } + + /** + * Set the next index that should be "gathered" for a bucket rooted + * at {@code rootIndex}. + */ + private void setNextGatherOffset(long rootIndex, int offset) { + values.set(rootIndex, offset); + } + + /** + * {@code true} if the entry at index {@code lhs} is "better" than + * the entry at {@code rhs}. "Better" in this means "lower" for + * {@link SortOrder#ASC} and "higher" for {@link SortOrder#DESC}. + */ + private boolean betterThan(long lhs, long rhs, double lhsExtra, double rhsExtra) { + int res = Long.compare(lhs, rhs); + if (res != 0) { + return getOrder().reverseMul() * res < 0; + } + res = Double.compare(lhsExtra, rhsExtra); + return getOrder().reverseMul() * res < 0; + } + + /** + * Swap the data at two indices. + */ + private void swap(long lhs, long rhs) { + var tmp = values.get(lhs); + values.set(lhs, values.get(rhs)); + values.set(rhs, tmp); + var tmpExtra = extraValues.get(lhs); + extraValues.set(lhs, extraValues.get(rhs)); + extraValues.set(rhs, tmpExtra); + } + + /** + * Allocate storage for more buckets and store the "next gather offset" + * for those new buckets. We always grow the storage by whole bucket's + * worth of slots at a time. We never allocate space for partial buckets. + */ + private void grow(int bucket) { + long oldMax = values.size(); + assert oldMax % bucketSize == 0; + + long newSize = BigArrays.overSize(((long) bucket + 1) * bucketSize, PageCacheRecycler.LONG_PAGE_SIZE, Long.BYTES); + // Round up to the next full bucket. + newSize = (newSize + bucketSize - 1) / bucketSize; + values = bigArrays.resize(values, newSize * bucketSize); + long newExtraSize = BigArrays.overSize(((long) bucket + 1) * bucketSize, PageCacheRecycler.DOUBLE_PAGE_SIZE, Double.BYTES); + // Round up to the next full bucket. + newExtraSize = (newExtraSize + bucketSize - 1) / bucketSize; + extraValues = bigArrays.resize(extraValues, newExtraSize * bucketSize); + // Set the next gather offsets for all newly allocated buckets. + fillGatherOffsets(oldMax); + } + + /** + * Maintain the "next gather offsets" for newly allocated buckets. + */ + private void fillGatherOffsets(long startingAt) { + int nextOffset = getBucketSize() - 1; + for (long bucketRoot = startingAt; bucketRoot < values.size(); bucketRoot += getBucketSize()) { + setNextGatherOffset(bucketRoot, nextOffset); + } + } + + /** + * Heapify a bucket whose entries are in random order. + *

+ * This works by validating the heap property on each node, iterating + * "upwards", pushing any out of order parents "down". Check out the + * wikipedia + * entry on binary heaps for more about this. + *

+ *

+ * While this *looks* like it could easily be {@code O(n * log n)}, it is + * a fairly well studied algorithm attributed to Floyd. There's + * been a bunch of work that puts this at {@code O(n)}, close to 1.88n worst + * case. + *

+ * + * @param rootIndex the index the start of the bucket + */ + private void heapify(long rootIndex, int heapSize) { + int maxParent = heapSize / 2 - 1; + for (int parent = maxParent; parent >= 0; parent--) { + downHeap(rootIndex, parent, heapSize); + } + } + + /** + * Sorts all the values in the heap using heap sort algorithm. + * This runs in {@code O(n log n)} time. + * @param rootIndex index of the start of the bucket + * @param heapSize Number of values that belong to the heap. + * Can be less than bucketSize. + * In such a case, the remaining values in range + * (rootIndex + heapSize, rootIndex + bucketSize) + * are *not* considered part of the heap. + */ + private void heapSort(long rootIndex, int heapSize) { + while (heapSize > 0) { + swap(rootIndex, rootIndex + heapSize - 1); + heapSize--; + downHeap(rootIndex, 0, heapSize); + } + } + + /** + * Correct the heap invariant of a parent and its children. This + * runs in {@code O(log n)} time. + * @param rootIndex index of the start of the bucket + * @param parent Index within the bucket of the parent to check. + * For example, 0 is the "root". + * @param heapSize Number of values that belong to the heap. + * Can be less than bucketSize. + * In such a case, the remaining values in range + * (rootIndex + heapSize, rootIndex + bucketSize) + * are *not* considered part of the heap. + */ + private void downHeap(long rootIndex, int parent, int heapSize) { + while (true) { + long parentIndex = rootIndex + parent; + int worst = parent; + long worstIndex = parentIndex; + int leftChild = parent * 2 + 1; + long leftIndex = rootIndex + leftChild; + if (leftChild < heapSize) { + if (betterThan(values.get(worstIndex), values.get(leftIndex), extraValues.get(worstIndex), extraValues.get(leftIndex))) { + worst = leftChild; + worstIndex = leftIndex; + } + int rightChild = leftChild + 1; + long rightIndex = rootIndex + rightChild; + if (rightChild < heapSize + && betterThan( + values.get(worstIndex), + values.get(rightIndex), + extraValues.get(worstIndex), + extraValues.get(rightIndex) + )) { + worst = rightChild; + worstIndex = rightIndex; + } + } + if (worst == parent) { + break; + } + swap(worstIndex, parentIndex); + parent = worst; + } + } + + @Override + public final void close() { + Releasables.close(values, extraValues, heapMode); + } +} diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/LongFloatBucketedSort.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/LongFloatBucketedSort.java new file mode 100644 index 0000000000000..21428226458ac --- /dev/null +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/LongFloatBucketedSort.java @@ -0,0 +1,406 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +package org.elasticsearch.compute.data.sort; + +import org.elasticsearch.common.util.BigArrays; +import org.elasticsearch.common.util.BitArray; +import org.elasticsearch.common.util.FloatArray; +import org.elasticsearch.common.util.LongArray; +import org.elasticsearch.common.util.PageCacheRecycler; +import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.BlockFactory; +import org.elasticsearch.compute.data.IntVector; +import org.elasticsearch.core.Releasable; +import org.elasticsearch.core.Releasables; +import org.elasticsearch.core.Tuple; +import org.elasticsearch.search.sort.BucketedSort; +import org.elasticsearch.search.sort.SortOrder; + +import java.util.stream.IntStream; + +/** + * Aggregates the top N {@code long} values per bucket. + * See {@link BucketedSort} for more information. + * This class is generated. Edit @{code X-BucketedSort.java.st} instead of this file. + */ +public class LongFloatBucketedSort implements Releasable { + + private final BigArrays bigArrays; + private final SortOrder order; + private final int bucketSize; + /** + * {@code true} if the bucket is in heap mode, {@code false} if + * it is still gathering. + */ + private final BitArray heapMode; + /** + * An array containing all the values on all buckets. The structure is as follows: + *

+ * For each bucket, there are bucketSize elements, based on the bucket id (0, 1, 2...). + * Then, for each bucket, it can be in 2 states: + *

+ *
    + *
  • + * Gather mode: All buckets start in gather mode, and remain here while they have less than bucketSize elements. + * In gather mode, the elements are stored in the array from the highest index to the lowest index. + * The lowest index contains the offset to the next slot to be filled. + *

    + * This allows us to insert elements in O(1) time. + *

    + *

    + * When the bucketSize-th element is collected, the bucket transitions to heap mode, by heapifying its contents. + *

    + *
  • + *
  • + * Heap mode: The bucket slots are organized as a min heap structure. + *

    + * The root of the heap is the minimum value in the bucket, + * which allows us to quickly discard new values that are not in the top N. + *

    + *
  • + *
+ */ + private LongArray values; + private FloatArray extraValues; + + public LongFloatBucketedSort(BigArrays bigArrays, SortOrder order, int bucketSize) { + this.bigArrays = bigArrays; + this.order = order; + this.bucketSize = bucketSize; + heapMode = new BitArray(0, bigArrays); + + boolean success = false; + try { + values = bigArrays.newLongArray(0, false); + extraValues = bigArrays.newFloatArray(0, false); + success = true; + } finally { + if (success == false) { + close(); + } + } + } + + /** + * Collects a {@code value} into a {@code bucket}. + *

+ * It may or may not be inserted in the heap, depending on if it is better than the current root. + *

+ */ + public void collect(long value, float extraValue, int bucket) { + long rootIndex = (long) bucket * bucketSize; + if (inHeapMode(bucket)) { + if (betterThan(value, values.get(rootIndex), extraValue, extraValues.get(rootIndex))) { + values.set(rootIndex, value); + extraValues.set(rootIndex, extraValue); + downHeap(rootIndex, 0, bucketSize); + } + return; + } + // Gathering mode + long requiredSize = rootIndex + bucketSize; + if (values.size() < requiredSize) { + grow(bucket); + } + int next = getNextGatherOffset(rootIndex); + assert 0 <= next && next < bucketSize + : "Expected next to be in the range of valid buckets [0 <= " + next + " < " + bucketSize + "]"; + long index = next + rootIndex; + values.set(index, value); + extraValues.set(index, extraValue); + if (next == 0) { + heapMode.set(bucket); + heapify(rootIndex, bucketSize); + } else { + setNextGatherOffset(rootIndex, next - 1); + } + } + + /** + * The order of the sort. + */ + public SortOrder getOrder() { + return order; + } + + /** + * The number of values to store per bucket. + */ + public int getBucketSize() { + return bucketSize; + } + + /** + * Get the first and last indexes (inclusive, exclusive) of the values for a bucket. + * Returns [0, 0] if the bucket has never been collected. + */ + private Tuple getBucketValuesIndexes(int bucket) { + long rootIndex = (long) bucket * bucketSize; + if (rootIndex >= values.size()) { + // We've never seen this bucket. + return Tuple.tuple(0L, 0L); + } + long start = inHeapMode(bucket) ? rootIndex : (rootIndex + getNextGatherOffset(rootIndex) + 1); + long end = rootIndex + bucketSize; + return Tuple.tuple(start, end); + } + + /** + * Merge the values from {@code other}'s {@code otherGroupId} into {@code groupId}. + */ + public void merge(int groupId, LongFloatBucketedSort other, int otherGroupId) { + var otherBounds = other.getBucketValuesIndexes(otherGroupId); + + // TODO: This can be improved for heapified buckets by making use of the heap structures + for (long i = otherBounds.v1(); i < otherBounds.v2(); i++) { + collect(other.values.get(i), other.extraValues.get(i), groupId); + } + } + + /** + * Creates a block with the values from the {@code selected} groups. + */ + public void toBlocks(BlockFactory blockFactory, Block[] blocks, int offset, IntVector selected) { + // Check if the selected groups are all empty, to avoid allocating extra memory + if (allSelectedGroupsAreEmpty(selected)) { + blocks[offset] = blockFactory.newConstantNullBlock(selected.getPositionCount()); + blocks[offset + 1] = blockFactory.newConstantNullBlock(selected.getPositionCount()); + return; + } + + try ( + var builder = blockFactory.newLongBlockBuilder(selected.getPositionCount()); + var extraBuilder = blockFactory.newFloatBlockBuilder(selected.getPositionCount()) + ) { + for (int s = 0; s < selected.getPositionCount(); s++) { + int bucket = selected.getInt(s); + + var bounds = getBucketValuesIndexes(bucket); + var rootIndex = bounds.v1(); + var size = bounds.v2() - bounds.v1(); + + if (size == 0) { + builder.appendNull(); + extraBuilder.appendNull(); + continue; + } + + if (size == 1) { + builder.appendLong(values.get(rootIndex)); + extraBuilder.appendFloat(extraValues.get(rootIndex)); + continue; + } + + // If we are in the gathering mode, we need to heapify before sorting. + if (inHeapMode(bucket) == false) { + heapify(rootIndex, (int) size); + } + heapSort(rootIndex, (int) size); + + builder.beginPositionEntry(); + extraBuilder.beginPositionEntry(); + for (int i = 0; i < size; i++) { + builder.appendLong(values.get(rootIndex + i)); + extraBuilder.appendFloat(extraValues.get(rootIndex + i)); + } + builder.endPositionEntry(); + extraBuilder.endPositionEntry(); + } + blocks[offset] = builder.build(); + blocks[offset + 1] = extraBuilder.build(); + } + } + + /** + * Checks if the selected groups are all empty. + */ + private boolean allSelectedGroupsAreEmpty(IntVector selected) { + return IntStream.range(0, selected.getPositionCount()).map(selected::getInt).noneMatch(bucket -> { + var bounds = this.getBucketValuesIndexes(bucket); + var size = bounds.v2() - bounds.v1(); + return size > 0; + }); + } + + /** + * Is this bucket a min heap {@code true} or in gathering mode {@code false}? + */ + private boolean inHeapMode(int bucket) { + return heapMode.get(bucket); + } + + /** + * Get the next index that should be "gathered" for a bucket rooted + * at {@code rootIndex}. + */ + private int getNextGatherOffset(long rootIndex) { + return (int) values.get(rootIndex); + } + + /** + * Set the next index that should be "gathered" for a bucket rooted + * at {@code rootIndex}. + */ + private void setNextGatherOffset(long rootIndex, int offset) { + values.set(rootIndex, offset); + } + + /** + * {@code true} if the entry at index {@code lhs} is "better" than + * the entry at {@code rhs}. "Better" in this means "lower" for + * {@link SortOrder#ASC} and "higher" for {@link SortOrder#DESC}. + */ + private boolean betterThan(long lhs, long rhs, float lhsExtra, float rhsExtra) { + int res = Long.compare(lhs, rhs); + if (res != 0) { + return getOrder().reverseMul() * res < 0; + } + res = Float.compare(lhsExtra, rhsExtra); + return getOrder().reverseMul() * res < 0; + } + + /** + * Swap the data at two indices. + */ + private void swap(long lhs, long rhs) { + var tmp = values.get(lhs); + values.set(lhs, values.get(rhs)); + values.set(rhs, tmp); + var tmpExtra = extraValues.get(lhs); + extraValues.set(lhs, extraValues.get(rhs)); + extraValues.set(rhs, tmpExtra); + } + + /** + * Allocate storage for more buckets and store the "next gather offset" + * for those new buckets. We always grow the storage by whole bucket's + * worth of slots at a time. We never allocate space for partial buckets. + */ + private void grow(int bucket) { + long oldMax = values.size(); + assert oldMax % bucketSize == 0; + + long newSize = BigArrays.overSize(((long) bucket + 1) * bucketSize, PageCacheRecycler.LONG_PAGE_SIZE, Long.BYTES); + // Round up to the next full bucket. + newSize = (newSize + bucketSize - 1) / bucketSize; + values = bigArrays.resize(values, newSize * bucketSize); + long newExtraSize = BigArrays.overSize(((long) bucket + 1) * bucketSize, PageCacheRecycler.FLOAT_PAGE_SIZE, Float.BYTES); + // Round up to the next full bucket. + newExtraSize = (newExtraSize + bucketSize - 1) / bucketSize; + extraValues = bigArrays.resize(extraValues, newExtraSize * bucketSize); + // Set the next gather offsets for all newly allocated buckets. + fillGatherOffsets(oldMax); + } + + /** + * Maintain the "next gather offsets" for newly allocated buckets. + */ + private void fillGatherOffsets(long startingAt) { + int nextOffset = getBucketSize() - 1; + for (long bucketRoot = startingAt; bucketRoot < values.size(); bucketRoot += getBucketSize()) { + setNextGatherOffset(bucketRoot, nextOffset); + } + } + + /** + * Heapify a bucket whose entries are in random order. + *

+ * This works by validating the heap property on each node, iterating + * "upwards", pushing any out of order parents "down". Check out the + * wikipedia + * entry on binary heaps for more about this. + *

+ *

+ * While this *looks* like it could easily be {@code O(n * log n)}, it is + * a fairly well studied algorithm attributed to Floyd. There's + * been a bunch of work that puts this at {@code O(n)}, close to 1.88n worst + * case. + *

+ * + * @param rootIndex the index the start of the bucket + */ + private void heapify(long rootIndex, int heapSize) { + int maxParent = heapSize / 2 - 1; + for (int parent = maxParent; parent >= 0; parent--) { + downHeap(rootIndex, parent, heapSize); + } + } + + /** + * Sorts all the values in the heap using heap sort algorithm. + * This runs in {@code O(n log n)} time. + * @param rootIndex index of the start of the bucket + * @param heapSize Number of values that belong to the heap. + * Can be less than bucketSize. + * In such a case, the remaining values in range + * (rootIndex + heapSize, rootIndex + bucketSize) + * are *not* considered part of the heap. + */ + private void heapSort(long rootIndex, int heapSize) { + while (heapSize > 0) { + swap(rootIndex, rootIndex + heapSize - 1); + heapSize--; + downHeap(rootIndex, 0, heapSize); + } + } + + /** + * Correct the heap invariant of a parent and its children. This + * runs in {@code O(log n)} time. + * @param rootIndex index of the start of the bucket + * @param parent Index within the bucket of the parent to check. + * For example, 0 is the "root". + * @param heapSize Number of values that belong to the heap. + * Can be less than bucketSize. + * In such a case, the remaining values in range + * (rootIndex + heapSize, rootIndex + bucketSize) + * are *not* considered part of the heap. + */ + private void downHeap(long rootIndex, int parent, int heapSize) { + while (true) { + long parentIndex = rootIndex + parent; + int worst = parent; + long worstIndex = parentIndex; + int leftChild = parent * 2 + 1; + long leftIndex = rootIndex + leftChild; + if (leftChild < heapSize) { + if (betterThan(values.get(worstIndex), values.get(leftIndex), extraValues.get(worstIndex), extraValues.get(leftIndex))) { + worst = leftChild; + worstIndex = leftIndex; + } + int rightChild = leftChild + 1; + long rightIndex = rootIndex + rightChild; + if (rightChild < heapSize + && betterThan( + values.get(worstIndex), + values.get(rightIndex), + extraValues.get(worstIndex), + extraValues.get(rightIndex) + )) { + worst = rightChild; + worstIndex = rightIndex; + } + } + if (worst == parent) { + break; + } + swap(worstIndex, parentIndex); + parent = worst; + } + } + + @Override + public final void close() { + Releasables.close(values, extraValues, heapMode); + } +} diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/LongIntBucketedSort.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/LongIntBucketedSort.java new file mode 100644 index 0000000000000..cfec149bc558f --- /dev/null +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/LongIntBucketedSort.java @@ -0,0 +1,406 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +package org.elasticsearch.compute.data.sort; + +import org.elasticsearch.common.util.BigArrays; +import org.elasticsearch.common.util.BitArray; +import org.elasticsearch.common.util.IntArray; +import org.elasticsearch.common.util.LongArray; +import org.elasticsearch.common.util.PageCacheRecycler; +import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.BlockFactory; +import org.elasticsearch.compute.data.IntVector; +import org.elasticsearch.core.Releasable; +import org.elasticsearch.core.Releasables; +import org.elasticsearch.core.Tuple; +import org.elasticsearch.search.sort.BucketedSort; +import org.elasticsearch.search.sort.SortOrder; + +import java.util.stream.IntStream; + +/** + * Aggregates the top N {@code long} values per bucket. + * See {@link BucketedSort} for more information. + * This class is generated. Edit @{code X-BucketedSort.java.st} instead of this file. + */ +public class LongIntBucketedSort implements Releasable { + + private final BigArrays bigArrays; + private final SortOrder order; + private final int bucketSize; + /** + * {@code true} if the bucket is in heap mode, {@code false} if + * it is still gathering. + */ + private final BitArray heapMode; + /** + * An array containing all the values on all buckets. The structure is as follows: + *

+ * For each bucket, there are bucketSize elements, based on the bucket id (0, 1, 2...). + * Then, for each bucket, it can be in 2 states: + *

+ *
    + *
  • + * Gather mode: All buckets start in gather mode, and remain here while they have less than bucketSize elements. + * In gather mode, the elements are stored in the array from the highest index to the lowest index. + * The lowest index contains the offset to the next slot to be filled. + *

    + * This allows us to insert elements in O(1) time. + *

    + *

    + * When the bucketSize-th element is collected, the bucket transitions to heap mode, by heapifying its contents. + *

    + *
  • + *
  • + * Heap mode: The bucket slots are organized as a min heap structure. + *

    + * The root of the heap is the minimum value in the bucket, + * which allows us to quickly discard new values that are not in the top N. + *

    + *
  • + *
+ */ + private LongArray values; + private IntArray extraValues; + + public LongIntBucketedSort(BigArrays bigArrays, SortOrder order, int bucketSize) { + this.bigArrays = bigArrays; + this.order = order; + this.bucketSize = bucketSize; + heapMode = new BitArray(0, bigArrays); + + boolean success = false; + try { + values = bigArrays.newLongArray(0, false); + extraValues = bigArrays.newIntArray(0, false); + success = true; + } finally { + if (success == false) { + close(); + } + } + } + + /** + * Collects a {@code value} into a {@code bucket}. + *

+ * It may or may not be inserted in the heap, depending on if it is better than the current root. + *

+ */ + public void collect(long value, int extraValue, int bucket) { + long rootIndex = (long) bucket * bucketSize; + if (inHeapMode(bucket)) { + if (betterThan(value, values.get(rootIndex), extraValue, extraValues.get(rootIndex))) { + values.set(rootIndex, value); + extraValues.set(rootIndex, extraValue); + downHeap(rootIndex, 0, bucketSize); + } + return; + } + // Gathering mode + long requiredSize = rootIndex + bucketSize; + if (values.size() < requiredSize) { + grow(bucket); + } + int next = getNextGatherOffset(rootIndex); + assert 0 <= next && next < bucketSize + : "Expected next to be in the range of valid buckets [0 <= " + next + " < " + bucketSize + "]"; + long index = next + rootIndex; + values.set(index, value); + extraValues.set(index, extraValue); + if (next == 0) { + heapMode.set(bucket); + heapify(rootIndex, bucketSize); + } else { + setNextGatherOffset(rootIndex, next - 1); + } + } + + /** + * The order of the sort. + */ + public SortOrder getOrder() { + return order; + } + + /** + * The number of values to store per bucket. + */ + public int getBucketSize() { + return bucketSize; + } + + /** + * Get the first and last indexes (inclusive, exclusive) of the values for a bucket. + * Returns [0, 0] if the bucket has never been collected. + */ + private Tuple getBucketValuesIndexes(int bucket) { + long rootIndex = (long) bucket * bucketSize; + if (rootIndex >= values.size()) { + // We've never seen this bucket. + return Tuple.tuple(0L, 0L); + } + long start = inHeapMode(bucket) ? rootIndex : (rootIndex + getNextGatherOffset(rootIndex) + 1); + long end = rootIndex + bucketSize; + return Tuple.tuple(start, end); + } + + /** + * Merge the values from {@code other}'s {@code otherGroupId} into {@code groupId}. + */ + public void merge(int groupId, LongIntBucketedSort other, int otherGroupId) { + var otherBounds = other.getBucketValuesIndexes(otherGroupId); + + // TODO: This can be improved for heapified buckets by making use of the heap structures + for (long i = otherBounds.v1(); i < otherBounds.v2(); i++) { + collect(other.values.get(i), other.extraValues.get(i), groupId); + } + } + + /** + * Creates a block with the values from the {@code selected} groups. + */ + public void toBlocks(BlockFactory blockFactory, Block[] blocks, int offset, IntVector selected) { + // Check if the selected groups are all empty, to avoid allocating extra memory + if (allSelectedGroupsAreEmpty(selected)) { + blocks[offset] = blockFactory.newConstantNullBlock(selected.getPositionCount()); + blocks[offset + 1] = blockFactory.newConstantNullBlock(selected.getPositionCount()); + return; + } + + try ( + var builder = blockFactory.newLongBlockBuilder(selected.getPositionCount()); + var extraBuilder = blockFactory.newIntBlockBuilder(selected.getPositionCount()) + ) { + for (int s = 0; s < selected.getPositionCount(); s++) { + int bucket = selected.getInt(s); + + var bounds = getBucketValuesIndexes(bucket); + var rootIndex = bounds.v1(); + var size = bounds.v2() - bounds.v1(); + + if (size == 0) { + builder.appendNull(); + extraBuilder.appendNull(); + continue; + } + + if (size == 1) { + builder.appendLong(values.get(rootIndex)); + extraBuilder.appendInt(extraValues.get(rootIndex)); + continue; + } + + // If we are in the gathering mode, we need to heapify before sorting. + if (inHeapMode(bucket) == false) { + heapify(rootIndex, (int) size); + } + heapSort(rootIndex, (int) size); + + builder.beginPositionEntry(); + extraBuilder.beginPositionEntry(); + for (int i = 0; i < size; i++) { + builder.appendLong(values.get(rootIndex + i)); + extraBuilder.appendInt(extraValues.get(rootIndex + i)); + } + builder.endPositionEntry(); + extraBuilder.endPositionEntry(); + } + blocks[offset] = builder.build(); + blocks[offset + 1] = extraBuilder.build(); + } + } + + /** + * Checks if the selected groups are all empty. + */ + private boolean allSelectedGroupsAreEmpty(IntVector selected) { + return IntStream.range(0, selected.getPositionCount()).map(selected::getInt).noneMatch(bucket -> { + var bounds = this.getBucketValuesIndexes(bucket); + var size = bounds.v2() - bounds.v1(); + return size > 0; + }); + } + + /** + * Is this bucket a min heap {@code true} or in gathering mode {@code false}? + */ + private boolean inHeapMode(int bucket) { + return heapMode.get(bucket); + } + + /** + * Get the next index that should be "gathered" for a bucket rooted + * at {@code rootIndex}. + */ + private int getNextGatherOffset(long rootIndex) { + return (int) values.get(rootIndex); + } + + /** + * Set the next index that should be "gathered" for a bucket rooted + * at {@code rootIndex}. + */ + private void setNextGatherOffset(long rootIndex, int offset) { + values.set(rootIndex, offset); + } + + /** + * {@code true} if the entry at index {@code lhs} is "better" than + * the entry at {@code rhs}. "Better" in this means "lower" for + * {@link SortOrder#ASC} and "higher" for {@link SortOrder#DESC}. + */ + private boolean betterThan(long lhs, long rhs, int lhsExtra, int rhsExtra) { + int res = Long.compare(lhs, rhs); + if (res != 0) { + return getOrder().reverseMul() * res < 0; + } + res = Integer.compare(lhsExtra, rhsExtra); + return getOrder().reverseMul() * res < 0; + } + + /** + * Swap the data at two indices. + */ + private void swap(long lhs, long rhs) { + var tmp = values.get(lhs); + values.set(lhs, values.get(rhs)); + values.set(rhs, tmp); + var tmpExtra = extraValues.get(lhs); + extraValues.set(lhs, extraValues.get(rhs)); + extraValues.set(rhs, tmpExtra); + } + + /** + * Allocate storage for more buckets and store the "next gather offset" + * for those new buckets. We always grow the storage by whole bucket's + * worth of slots at a time. We never allocate space for partial buckets. + */ + private void grow(int bucket) { + long oldMax = values.size(); + assert oldMax % bucketSize == 0; + + long newSize = BigArrays.overSize(((long) bucket + 1) * bucketSize, PageCacheRecycler.LONG_PAGE_SIZE, Long.BYTES); + // Round up to the next full bucket. + newSize = (newSize + bucketSize - 1) / bucketSize; + values = bigArrays.resize(values, newSize * bucketSize); + long newExtraSize = BigArrays.overSize(((long) bucket + 1) * bucketSize, PageCacheRecycler.INT_PAGE_SIZE, Integer.BYTES); + // Round up to the next full bucket. + newExtraSize = (newExtraSize + bucketSize - 1) / bucketSize; + extraValues = bigArrays.resize(extraValues, newExtraSize * bucketSize); + // Set the next gather offsets for all newly allocated buckets. + fillGatherOffsets(oldMax); + } + + /** + * Maintain the "next gather offsets" for newly allocated buckets. + */ + private void fillGatherOffsets(long startingAt) { + int nextOffset = getBucketSize() - 1; + for (long bucketRoot = startingAt; bucketRoot < values.size(); bucketRoot += getBucketSize()) { + setNextGatherOffset(bucketRoot, nextOffset); + } + } + + /** + * Heapify a bucket whose entries are in random order. + *

+ * This works by validating the heap property on each node, iterating + * "upwards", pushing any out of order parents "down". Check out the + * wikipedia + * entry on binary heaps for more about this. + *

+ *

+ * While this *looks* like it could easily be {@code O(n * log n)}, it is + * a fairly well studied algorithm attributed to Floyd. There's + * been a bunch of work that puts this at {@code O(n)}, close to 1.88n worst + * case. + *

+ * + * @param rootIndex the index the start of the bucket + */ + private void heapify(long rootIndex, int heapSize) { + int maxParent = heapSize / 2 - 1; + for (int parent = maxParent; parent >= 0; parent--) { + downHeap(rootIndex, parent, heapSize); + } + } + + /** + * Sorts all the values in the heap using heap sort algorithm. + * This runs in {@code O(n log n)} time. + * @param rootIndex index of the start of the bucket + * @param heapSize Number of values that belong to the heap. + * Can be less than bucketSize. + * In such a case, the remaining values in range + * (rootIndex + heapSize, rootIndex + bucketSize) + * are *not* considered part of the heap. + */ + private void heapSort(long rootIndex, int heapSize) { + while (heapSize > 0) { + swap(rootIndex, rootIndex + heapSize - 1); + heapSize--; + downHeap(rootIndex, 0, heapSize); + } + } + + /** + * Correct the heap invariant of a parent and its children. This + * runs in {@code O(log n)} time. + * @param rootIndex index of the start of the bucket + * @param parent Index within the bucket of the parent to check. + * For example, 0 is the "root". + * @param heapSize Number of values that belong to the heap. + * Can be less than bucketSize. + * In such a case, the remaining values in range + * (rootIndex + heapSize, rootIndex + bucketSize) + * are *not* considered part of the heap. + */ + private void downHeap(long rootIndex, int parent, int heapSize) { + while (true) { + long parentIndex = rootIndex + parent; + int worst = parent; + long worstIndex = parentIndex; + int leftChild = parent * 2 + 1; + long leftIndex = rootIndex + leftChild; + if (leftChild < heapSize) { + if (betterThan(values.get(worstIndex), values.get(leftIndex), extraValues.get(worstIndex), extraValues.get(leftIndex))) { + worst = leftChild; + worstIndex = leftIndex; + } + int rightChild = leftChild + 1; + long rightIndex = rootIndex + rightChild; + if (rightChild < heapSize + && betterThan( + values.get(worstIndex), + values.get(rightIndex), + extraValues.get(worstIndex), + extraValues.get(rightIndex) + )) { + worst = rightChild; + worstIndex = rightIndex; + } + } + if (worst == parent) { + break; + } + swap(worstIndex, parentIndex); + parent = worst; + } + } + + @Override + public final void close() { + Releasables.close(values, extraValues, heapMode); + } +} diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/LongLongBucketedSort.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/LongLongBucketedSort.java new file mode 100644 index 0000000000000..adef179bd9de6 --- /dev/null +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/LongLongBucketedSort.java @@ -0,0 +1,405 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +package org.elasticsearch.compute.data.sort; + +import org.elasticsearch.common.util.BigArrays; +import org.elasticsearch.common.util.BitArray; +import org.elasticsearch.common.util.LongArray; +import org.elasticsearch.common.util.PageCacheRecycler; +import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.BlockFactory; +import org.elasticsearch.compute.data.IntVector; +import org.elasticsearch.core.Releasable; +import org.elasticsearch.core.Releasables; +import org.elasticsearch.core.Tuple; +import org.elasticsearch.search.sort.BucketedSort; +import org.elasticsearch.search.sort.SortOrder; + +import java.util.stream.IntStream; + +/** + * Aggregates the top N {@code long} values per bucket. + * See {@link BucketedSort} for more information. + * This class is generated. Edit @{code X-BucketedSort.java.st} instead of this file. + */ +public class LongLongBucketedSort implements Releasable { + + private final BigArrays bigArrays; + private final SortOrder order; + private final int bucketSize; + /** + * {@code true} if the bucket is in heap mode, {@code false} if + * it is still gathering. + */ + private final BitArray heapMode; + /** + * An array containing all the values on all buckets. The structure is as follows: + *

+ * For each bucket, there are bucketSize elements, based on the bucket id (0, 1, 2...). + * Then, for each bucket, it can be in 2 states: + *

+ *
    + *
  • + * Gather mode: All buckets start in gather mode, and remain here while they have less than bucketSize elements. + * In gather mode, the elements are stored in the array from the highest index to the lowest index. + * The lowest index contains the offset to the next slot to be filled. + *

    + * This allows us to insert elements in O(1) time. + *

    + *

    + * When the bucketSize-th element is collected, the bucket transitions to heap mode, by heapifying its contents. + *

    + *
  • + *
  • + * Heap mode: The bucket slots are organized as a min heap structure. + *

    + * The root of the heap is the minimum value in the bucket, + * which allows us to quickly discard new values that are not in the top N. + *

    + *
  • + *
+ */ + private LongArray values; + private LongArray extraValues; + + public LongLongBucketedSort(BigArrays bigArrays, SortOrder order, int bucketSize) { + this.bigArrays = bigArrays; + this.order = order; + this.bucketSize = bucketSize; + heapMode = new BitArray(0, bigArrays); + + boolean success = false; + try { + values = bigArrays.newLongArray(0, false); + extraValues = bigArrays.newLongArray(0, false); + success = true; + } finally { + if (success == false) { + close(); + } + } + } + + /** + * Collects a {@code value} into a {@code bucket}. + *

+ * It may or may not be inserted in the heap, depending on if it is better than the current root. + *

+ */ + public void collect(long value, long extraValue, int bucket) { + long rootIndex = (long) bucket * bucketSize; + if (inHeapMode(bucket)) { + if (betterThan(value, values.get(rootIndex), extraValue, extraValues.get(rootIndex))) { + values.set(rootIndex, value); + extraValues.set(rootIndex, extraValue); + downHeap(rootIndex, 0, bucketSize); + } + return; + } + // Gathering mode + long requiredSize = rootIndex + bucketSize; + if (values.size() < requiredSize) { + grow(bucket); + } + int next = getNextGatherOffset(rootIndex); + assert 0 <= next && next < bucketSize + : "Expected next to be in the range of valid buckets [0 <= " + next + " < " + bucketSize + "]"; + long index = next + rootIndex; + values.set(index, value); + extraValues.set(index, extraValue); + if (next == 0) { + heapMode.set(bucket); + heapify(rootIndex, bucketSize); + } else { + setNextGatherOffset(rootIndex, next - 1); + } + } + + /** + * The order of the sort. + */ + public SortOrder getOrder() { + return order; + } + + /** + * The number of values to store per bucket. + */ + public int getBucketSize() { + return bucketSize; + } + + /** + * Get the first and last indexes (inclusive, exclusive) of the values for a bucket. + * Returns [0, 0] if the bucket has never been collected. + */ + private Tuple getBucketValuesIndexes(int bucket) { + long rootIndex = (long) bucket * bucketSize; + if (rootIndex >= values.size()) { + // We've never seen this bucket. + return Tuple.tuple(0L, 0L); + } + long start = inHeapMode(bucket) ? rootIndex : (rootIndex + getNextGatherOffset(rootIndex) + 1); + long end = rootIndex + bucketSize; + return Tuple.tuple(start, end); + } + + /** + * Merge the values from {@code other}'s {@code otherGroupId} into {@code groupId}. + */ + public void merge(int groupId, LongLongBucketedSort other, int otherGroupId) { + var otherBounds = other.getBucketValuesIndexes(otherGroupId); + + // TODO: This can be improved for heapified buckets by making use of the heap structures + for (long i = otherBounds.v1(); i < otherBounds.v2(); i++) { + collect(other.values.get(i), other.extraValues.get(i), groupId); + } + } + + /** + * Creates a block with the values from the {@code selected} groups. + */ + public void toBlocks(BlockFactory blockFactory, Block[] blocks, int offset, IntVector selected) { + // Check if the selected groups are all empty, to avoid allocating extra memory + if (allSelectedGroupsAreEmpty(selected)) { + blocks[offset] = blockFactory.newConstantNullBlock(selected.getPositionCount()); + blocks[offset + 1] = blockFactory.newConstantNullBlock(selected.getPositionCount()); + return; + } + + try ( + var builder = blockFactory.newLongBlockBuilder(selected.getPositionCount()); + var extraBuilder = blockFactory.newLongBlockBuilder(selected.getPositionCount()) + ) { + for (int s = 0; s < selected.getPositionCount(); s++) { + int bucket = selected.getInt(s); + + var bounds = getBucketValuesIndexes(bucket); + var rootIndex = bounds.v1(); + var size = bounds.v2() - bounds.v1(); + + if (size == 0) { + builder.appendNull(); + extraBuilder.appendNull(); + continue; + } + + if (size == 1) { + builder.appendLong(values.get(rootIndex)); + extraBuilder.appendLong(extraValues.get(rootIndex)); + continue; + } + + // If we are in the gathering mode, we need to heapify before sorting. + if (inHeapMode(bucket) == false) { + heapify(rootIndex, (int) size); + } + heapSort(rootIndex, (int) size); + + builder.beginPositionEntry(); + extraBuilder.beginPositionEntry(); + for (int i = 0; i < size; i++) { + builder.appendLong(values.get(rootIndex + i)); + extraBuilder.appendLong(extraValues.get(rootIndex + i)); + } + builder.endPositionEntry(); + extraBuilder.endPositionEntry(); + } + blocks[offset] = builder.build(); + blocks[offset + 1] = extraBuilder.build(); + } + } + + /** + * Checks if the selected groups are all empty. + */ + private boolean allSelectedGroupsAreEmpty(IntVector selected) { + return IntStream.range(0, selected.getPositionCount()).map(selected::getInt).noneMatch(bucket -> { + var bounds = this.getBucketValuesIndexes(bucket); + var size = bounds.v2() - bounds.v1(); + return size > 0; + }); + } + + /** + * Is this bucket a min heap {@code true} or in gathering mode {@code false}? + */ + private boolean inHeapMode(int bucket) { + return heapMode.get(bucket); + } + + /** + * Get the next index that should be "gathered" for a bucket rooted + * at {@code rootIndex}. + */ + private int getNextGatherOffset(long rootIndex) { + return (int) values.get(rootIndex); + } + + /** + * Set the next index that should be "gathered" for a bucket rooted + * at {@code rootIndex}. + */ + private void setNextGatherOffset(long rootIndex, int offset) { + values.set(rootIndex, offset); + } + + /** + * {@code true} if the entry at index {@code lhs} is "better" than + * the entry at {@code rhs}. "Better" in this means "lower" for + * {@link SortOrder#ASC} and "higher" for {@link SortOrder#DESC}. + */ + private boolean betterThan(long lhs, long rhs, long lhsExtra, long rhsExtra) { + int res = Long.compare(lhs, rhs); + if (res != 0) { + return getOrder().reverseMul() * res < 0; + } + res = Long.compare(lhsExtra, rhsExtra); + return getOrder().reverseMul() * res < 0; + } + + /** + * Swap the data at two indices. + */ + private void swap(long lhs, long rhs) { + var tmp = values.get(lhs); + values.set(lhs, values.get(rhs)); + values.set(rhs, tmp); + var tmpExtra = extraValues.get(lhs); + extraValues.set(lhs, extraValues.get(rhs)); + extraValues.set(rhs, tmpExtra); + } + + /** + * Allocate storage for more buckets and store the "next gather offset" + * for those new buckets. We always grow the storage by whole bucket's + * worth of slots at a time. We never allocate space for partial buckets. + */ + private void grow(int bucket) { + long oldMax = values.size(); + assert oldMax % bucketSize == 0; + + long newSize = BigArrays.overSize(((long) bucket + 1) * bucketSize, PageCacheRecycler.LONG_PAGE_SIZE, Long.BYTES); + // Round up to the next full bucket. + newSize = (newSize + bucketSize - 1) / bucketSize; + values = bigArrays.resize(values, newSize * bucketSize); + long newExtraSize = BigArrays.overSize(((long) bucket + 1) * bucketSize, PageCacheRecycler.LONG_PAGE_SIZE, Long.BYTES); + // Round up to the next full bucket. + newExtraSize = (newExtraSize + bucketSize - 1) / bucketSize; + extraValues = bigArrays.resize(extraValues, newExtraSize * bucketSize); + // Set the next gather offsets for all newly allocated buckets. + fillGatherOffsets(oldMax); + } + + /** + * Maintain the "next gather offsets" for newly allocated buckets. + */ + private void fillGatherOffsets(long startingAt) { + int nextOffset = getBucketSize() - 1; + for (long bucketRoot = startingAt; bucketRoot < values.size(); bucketRoot += getBucketSize()) { + setNextGatherOffset(bucketRoot, nextOffset); + } + } + + /** + * Heapify a bucket whose entries are in random order. + *

+ * This works by validating the heap property on each node, iterating + * "upwards", pushing any out of order parents "down". Check out the + * wikipedia + * entry on binary heaps for more about this. + *

+ *

+ * While this *looks* like it could easily be {@code O(n * log n)}, it is + * a fairly well studied algorithm attributed to Floyd. There's + * been a bunch of work that puts this at {@code O(n)}, close to 1.88n worst + * case. + *

+ * + * @param rootIndex the index the start of the bucket + */ + private void heapify(long rootIndex, int heapSize) { + int maxParent = heapSize / 2 - 1; + for (int parent = maxParent; parent >= 0; parent--) { + downHeap(rootIndex, parent, heapSize); + } + } + + /** + * Sorts all the values in the heap using heap sort algorithm. + * This runs in {@code O(n log n)} time. + * @param rootIndex index of the start of the bucket + * @param heapSize Number of values that belong to the heap. + * Can be less than bucketSize. + * In such a case, the remaining values in range + * (rootIndex + heapSize, rootIndex + bucketSize) + * are *not* considered part of the heap. + */ + private void heapSort(long rootIndex, int heapSize) { + while (heapSize > 0) { + swap(rootIndex, rootIndex + heapSize - 1); + heapSize--; + downHeap(rootIndex, 0, heapSize); + } + } + + /** + * Correct the heap invariant of a parent and its children. This + * runs in {@code O(log n)} time. + * @param rootIndex index of the start of the bucket + * @param parent Index within the bucket of the parent to check. + * For example, 0 is the "root". + * @param heapSize Number of values that belong to the heap. + * Can be less than bucketSize. + * In such a case, the remaining values in range + * (rootIndex + heapSize, rootIndex + bucketSize) + * are *not* considered part of the heap. + */ + private void downHeap(long rootIndex, int parent, int heapSize) { + while (true) { + long parentIndex = rootIndex + parent; + int worst = parent; + long worstIndex = parentIndex; + int leftChild = parent * 2 + 1; + long leftIndex = rootIndex + leftChild; + if (leftChild < heapSize) { + if (betterThan(values.get(worstIndex), values.get(leftIndex), extraValues.get(worstIndex), extraValues.get(leftIndex))) { + worst = leftChild; + worstIndex = leftIndex; + } + int rightChild = leftChild + 1; + long rightIndex = rootIndex + rightChild; + if (rightChild < heapSize + && betterThan( + values.get(worstIndex), + values.get(rightIndex), + extraValues.get(worstIndex), + extraValues.get(rightIndex) + )) { + worst = rightChild; + worstIndex = rightIndex; + } + } + if (worst == parent) { + break; + } + swap(worstIndex, parentIndex); + parent = worst; + } + } + + @Override + public final void close() { + Releasables.close(values, extraValues, heapMode); + } +} diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleDoubleAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleDoubleAggregatorFunction.java new file mode 100644 index 0000000000000..f6716250a5d5a --- /dev/null +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleDoubleAggregatorFunction.java @@ -0,0 +1,213 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License +// 2.0; you may not use this file except in compliance with the Elastic License +// 2.0. +package org.elasticsearch.compute.aggregation; + +import java.lang.Integer; +import java.lang.Override; +import java.lang.String; +import java.lang.StringBuilder; +import java.util.List; +import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.BooleanVector; +import org.elasticsearch.compute.data.DoubleBlock; +import org.elasticsearch.compute.data.DoubleVector; +import org.elasticsearch.compute.data.ElementType; +import org.elasticsearch.compute.data.Page; +import org.elasticsearch.compute.operator.DriverContext; + +/** + * {@link AggregatorFunction} implementation for {@link TopDoubleDoubleAggregator}. + * This class is generated. Edit {@code AggregatorImplementer} instead. + */ +public final class TopDoubleDoubleAggregatorFunction implements AggregatorFunction { + private static final List INTERMEDIATE_STATE_DESC = List.of( + new IntermediateStateDesc("top", ElementType.DOUBLE), + new IntermediateStateDesc("extra", ElementType.DOUBLE) ); + + private final DriverContext driverContext; + + private final TopDoubleDoubleAggregator.SingleState state; + + private final List channels; + + private final int limit; + + private final boolean ascending; + + public TopDoubleDoubleAggregatorFunction(DriverContext driverContext, List channels, + TopDoubleDoubleAggregator.SingleState state, int limit, boolean ascending) { + this.driverContext = driverContext; + this.channels = channels; + this.state = state; + this.limit = limit; + this.ascending = ascending; + } + + public static TopDoubleDoubleAggregatorFunction create(DriverContext driverContext, + List channels, int limit, boolean ascending) { + return new TopDoubleDoubleAggregatorFunction(driverContext, channels, TopDoubleDoubleAggregator.initSingle(driverContext.bigArrays(), limit, ascending), limit, ascending); + } + + public static List intermediateStateDesc() { + return INTERMEDIATE_STATE_DESC; + } + + @Override + public int intermediateBlockCount() { + return INTERMEDIATE_STATE_DESC.size(); + } + + @Override + public void addRawInput(Page page, BooleanVector mask) { + if (mask.allFalse()) { + // Entire page masked away + } else if (mask.allTrue()) { + addRawInputNotMasked(page); + } else { + addRawInputMasked(page, mask); + } + } + + private void addRawInputMasked(Page page, BooleanVector mask) { + DoubleBlock vBlock = page.getBlock(channels.get(0)); + DoubleBlock extraBlock = page.getBlock(channels.get(1)); + DoubleVector vVector = vBlock.asVector(); + if (vVector == null) { + addRawBlock(vBlock, extraBlock, mask); + return; + } + DoubleVector extraVector = extraBlock.asVector(); + if (extraVector == null) { + addRawBlock(vBlock, extraBlock, mask); + return; + } + addRawVector(vVector, extraVector, mask); + } + + private void addRawInputNotMasked(Page page) { + DoubleBlock vBlock = page.getBlock(channels.get(0)); + DoubleBlock extraBlock = page.getBlock(channels.get(1)); + DoubleVector vVector = vBlock.asVector(); + if (vVector == null) { + addRawBlock(vBlock, extraBlock); + return; + } + DoubleVector extraVector = extraBlock.asVector(); + if (extraVector == null) { + addRawBlock(vBlock, extraBlock); + return; + } + addRawVector(vVector, extraVector); + } + + private void addRawVector(DoubleVector vVector, DoubleVector extraVector) { + for (int valuesPosition = 0; valuesPosition < vVector.getPositionCount(); valuesPosition++) { + double vValue = vVector.getDouble(valuesPosition); + double extraValue = extraVector.getDouble(valuesPosition); + TopDoubleDoubleAggregator.combine(state, vValue, extraValue); + } + } + + private void addRawVector(DoubleVector vVector, DoubleVector extraVector, BooleanVector mask) { + for (int valuesPosition = 0; valuesPosition < vVector.getPositionCount(); valuesPosition++) { + if (mask.getBoolean(valuesPosition) == false) { + continue; + } + double vValue = vVector.getDouble(valuesPosition); + double extraValue = extraVector.getDouble(valuesPosition); + TopDoubleDoubleAggregator.combine(state, vValue, extraValue); + } + } + + private void addRawBlock(DoubleBlock vBlock, DoubleBlock extraBlock) { + for (int p = 0; p < vBlock.getPositionCount(); p++) { + if (vBlock.isNull(p)) { + continue; + } + if (extraBlock.isNull(p)) { + continue; + } + int vStart = vBlock.getFirstValueIndex(p); + int vEnd = vStart + vBlock.getValueCount(p); + for (int vOffset = vStart; vOffset < vEnd; vOffset++) { + double vValue = vBlock.getDouble(vOffset); + int extraStart = extraBlock.getFirstValueIndex(p); + int extraEnd = extraStart + extraBlock.getValueCount(p); + for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { + double extraValue = extraBlock.getDouble(extraOffset); + TopDoubleDoubleAggregator.combine(state, vValue, extraValue); + } + } + } + } + + private void addRawBlock(DoubleBlock vBlock, DoubleBlock extraBlock, BooleanVector mask) { + for (int p = 0; p < vBlock.getPositionCount(); p++) { + if (mask.getBoolean(p) == false) { + continue; + } + if (vBlock.isNull(p)) { + continue; + } + if (extraBlock.isNull(p)) { + continue; + } + int vStart = vBlock.getFirstValueIndex(p); + int vEnd = vStart + vBlock.getValueCount(p); + for (int vOffset = vStart; vOffset < vEnd; vOffset++) { + double vValue = vBlock.getDouble(vOffset); + int extraStart = extraBlock.getFirstValueIndex(p); + int extraEnd = extraStart + extraBlock.getValueCount(p); + for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { + double extraValue = extraBlock.getDouble(extraOffset); + TopDoubleDoubleAggregator.combine(state, vValue, extraValue); + } + } + } + } + + @Override + public void addIntermediateInput(Page page) { + assert channels.size() == intermediateBlockCount(); + assert page.getBlockCount() >= channels.get(0) + intermediateStateDesc().size(); + Block topUncast = page.getBlock(channels.get(0)); + if (topUncast.areAllValuesNull()) { + return; + } + DoubleBlock top = (DoubleBlock) topUncast; + assert top.getPositionCount() == 1; + Block extraUncast = page.getBlock(channels.get(1)); + if (extraUncast.areAllValuesNull()) { + return; + } + DoubleBlock extra = (DoubleBlock) extraUncast; + assert extra.getPositionCount() == 1; + TopDoubleDoubleAggregator.combineIntermediate(state, top, extra); + } + + @Override + public void evaluateIntermediate(Block[] blocks, int offset, DriverContext driverContext) { + state.toIntermediate(blocks, offset, driverContext); + } + + @Override + public void evaluateFinal(Block[] blocks, int offset, DriverContext driverContext) { + blocks[offset] = TopDoubleDoubleAggregator.evaluateFinal(state, driverContext); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append(getClass().getSimpleName()).append("["); + sb.append("channels=").append(channels); + sb.append("]"); + return sb.toString(); + } + + @Override + public void close() { + state.close(); + } +} diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleDoubleAggregatorFunctionSupplier.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleDoubleAggregatorFunctionSupplier.java new file mode 100644 index 0000000000000..0c5a1aea81c7b --- /dev/null +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleDoubleAggregatorFunctionSupplier.java @@ -0,0 +1,53 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License +// 2.0; you may not use this file except in compliance with the Elastic License +// 2.0. +package org.elasticsearch.compute.aggregation; + +import java.lang.Integer; +import java.lang.Override; +import java.lang.String; +import java.util.List; +import org.elasticsearch.compute.operator.DriverContext; + +/** + * {@link AggregatorFunctionSupplier} implementation for {@link TopDoubleDoubleAggregator}. + * This class is generated. Edit {@code AggregatorFunctionSupplierImplementer} instead. + */ +public final class TopDoubleDoubleAggregatorFunctionSupplier implements AggregatorFunctionSupplier { + private final int limit; + + private final boolean ascending; + + public TopDoubleDoubleAggregatorFunctionSupplier(int limit, boolean ascending) { + this.limit = limit; + this.ascending = ascending; + } + + @Override + public List nonGroupingIntermediateStateDesc() { + return TopDoubleDoubleAggregatorFunction.intermediateStateDesc(); + } + + @Override + public List groupingIntermediateStateDesc() { + return TopDoubleDoubleGroupingAggregatorFunction.intermediateStateDesc(); + } + + @Override + public TopDoubleDoubleAggregatorFunction aggregator(DriverContext driverContext, + List channels) { + return TopDoubleDoubleAggregatorFunction.create(driverContext, channels, limit, ascending); + } + + @Override + public TopDoubleDoubleGroupingAggregatorFunction groupingAggregator(DriverContext driverContext, + List channels) { + return TopDoubleDoubleGroupingAggregatorFunction.create(channels, driverContext, limit, ascending); + } + + @Override + public String describe() { + return "top_double of doubles"; + } +} diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleDoubleGroupingAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleDoubleGroupingAggregatorFunction.java new file mode 100644 index 0000000000000..42bd15d5a2f69 --- /dev/null +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleDoubleGroupingAggregatorFunction.java @@ -0,0 +1,395 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License +// 2.0; you may not use this file except in compliance with the Elastic License +// 2.0. +package org.elasticsearch.compute.aggregation; + +import java.lang.Integer; +import java.lang.Override; +import java.lang.String; +import java.lang.StringBuilder; +import java.util.List; +import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.DoubleBlock; +import org.elasticsearch.compute.data.DoubleVector; +import org.elasticsearch.compute.data.ElementType; +import org.elasticsearch.compute.data.IntArrayBlock; +import org.elasticsearch.compute.data.IntBigArrayBlock; +import org.elasticsearch.compute.data.IntVector; +import org.elasticsearch.compute.data.Page; +import org.elasticsearch.compute.operator.DriverContext; + +/** + * {@link GroupingAggregatorFunction} implementation for {@link TopDoubleDoubleAggregator}. + * This class is generated. Edit {@code GroupingAggregatorImplementer} instead. + */ +public final class TopDoubleDoubleGroupingAggregatorFunction implements GroupingAggregatorFunction { + private static final List INTERMEDIATE_STATE_DESC = List.of( + new IntermediateStateDesc("top", ElementType.DOUBLE), + new IntermediateStateDesc("extra", ElementType.DOUBLE) ); + + private final TopDoubleDoubleAggregator.GroupingState state; + + private final List channels; + + private final DriverContext driverContext; + + private final int limit; + + private final boolean ascending; + + public TopDoubleDoubleGroupingAggregatorFunction(List channels, + TopDoubleDoubleAggregator.GroupingState state, DriverContext driverContext, int limit, + boolean ascending) { + this.channels = channels; + this.state = state; + this.driverContext = driverContext; + this.limit = limit; + this.ascending = ascending; + } + + public static TopDoubleDoubleGroupingAggregatorFunction create(List channels, + DriverContext driverContext, int limit, boolean ascending) { + return new TopDoubleDoubleGroupingAggregatorFunction(channels, TopDoubleDoubleAggregator.initGrouping(driverContext.bigArrays(), limit, ascending), driverContext, limit, ascending); + } + + public static List intermediateStateDesc() { + return INTERMEDIATE_STATE_DESC; + } + + @Override + public int intermediateBlockCount() { + return INTERMEDIATE_STATE_DESC.size(); + } + + @Override + public GroupingAggregatorFunction.AddInput prepareProcessRawInputPage(SeenGroupIds seenGroupIds, + Page page) { + DoubleBlock vBlock = page.getBlock(channels.get(0)); + DoubleBlock extraBlock = page.getBlock(channels.get(1)); + DoubleVector vVector = vBlock.asVector(); + if (vVector == null) { + maybeEnableGroupIdTracking(seenGroupIds, vBlock, extraBlock); + return new GroupingAggregatorFunction.AddInput() { + @Override + public void add(int positionOffset, IntArrayBlock groupIds) { + addRawInput(positionOffset, groupIds, vBlock, extraBlock); + } + + @Override + public void add(int positionOffset, IntBigArrayBlock groupIds) { + addRawInput(positionOffset, groupIds, vBlock, extraBlock); + } + + @Override + public void add(int positionOffset, IntVector groupIds) { + addRawInput(positionOffset, groupIds, vBlock, extraBlock); + } + + @Override + public void close() { + } + }; + } + DoubleVector extraVector = extraBlock.asVector(); + if (extraVector == null) { + maybeEnableGroupIdTracking(seenGroupIds, vBlock, extraBlock); + return new GroupingAggregatorFunction.AddInput() { + @Override + public void add(int positionOffset, IntArrayBlock groupIds) { + addRawInput(positionOffset, groupIds, vBlock, extraBlock); + } + + @Override + public void add(int positionOffset, IntBigArrayBlock groupIds) { + addRawInput(positionOffset, groupIds, vBlock, extraBlock); + } + + @Override + public void add(int positionOffset, IntVector groupIds) { + addRawInput(positionOffset, groupIds, vBlock, extraBlock); + } + + @Override + public void close() { + } + }; + } + return new GroupingAggregatorFunction.AddInput() { + @Override + public void add(int positionOffset, IntArrayBlock groupIds) { + addRawInput(positionOffset, groupIds, vVector, extraVector); + } + + @Override + public void add(int positionOffset, IntBigArrayBlock groupIds) { + addRawInput(positionOffset, groupIds, vVector, extraVector); + } + + @Override + public void add(int positionOffset, IntVector groupIds) { + addRawInput(positionOffset, groupIds, vVector, extraVector); + } + + @Override + public void close() { + } + }; + } + + private void addRawInput(int positionOffset, IntArrayBlock groups, DoubleBlock vBlock, + DoubleBlock extraBlock) { + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + if (groups.isNull(groupPosition)) { + continue; + } + int valuesPosition = groupPosition + positionOffset; + if (vBlock.isNull(valuesPosition)) { + continue; + } + if (extraBlock.isNull(valuesPosition)) { + continue; + } + int groupStart = groups.getFirstValueIndex(groupPosition); + int groupEnd = groupStart + groups.getValueCount(groupPosition); + for (int g = groupStart; g < groupEnd; g++) { + int groupId = groups.getInt(g); + int vStart = vBlock.getFirstValueIndex(valuesPosition); + int vEnd = vStart + vBlock.getValueCount(valuesPosition); + for (int vOffset = vStart; vOffset < vEnd; vOffset++) { + double vValue = vBlock.getDouble(vOffset); + int extraStart = extraBlock.getFirstValueIndex(valuesPosition); + int extraEnd = extraStart + extraBlock.getValueCount(valuesPosition); + for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { + double extraValue = extraBlock.getDouble(extraOffset); + TopDoubleDoubleAggregator.combine(state, groupId, vValue, extraValue); + } + } + } + } + } + + private void addRawInput(int positionOffset, IntArrayBlock groups, DoubleVector vVector, + DoubleVector extraVector) { + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + if (groups.isNull(groupPosition)) { + continue; + } + int valuesPosition = groupPosition + positionOffset; + int groupStart = groups.getFirstValueIndex(groupPosition); + int groupEnd = groupStart + groups.getValueCount(groupPosition); + for (int g = groupStart; g < groupEnd; g++) { + int groupId = groups.getInt(g); + double vValue = vVector.getDouble(valuesPosition); + double extraValue = extraVector.getDouble(valuesPosition); + TopDoubleDoubleAggregator.combine(state, groupId, vValue, extraValue); + } + } + } + + @Override + public void addIntermediateInput(int positionOffset, IntArrayBlock groups, Page page) { + state.enableGroupIdTracking(new SeenGroupIds.Empty()); + assert channels.size() == intermediateBlockCount(); + Block topUncast = page.getBlock(channels.get(0)); + if (topUncast.areAllValuesNull()) { + return; + } + DoubleBlock top = (DoubleBlock) topUncast; + Block extraUncast = page.getBlock(channels.get(1)); + if (extraUncast.areAllValuesNull()) { + return; + } + DoubleBlock extra = (DoubleBlock) extraUncast; + assert top.getPositionCount() == extra.getPositionCount(); + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + if (groups.isNull(groupPosition)) { + continue; + } + int groupStart = groups.getFirstValueIndex(groupPosition); + int groupEnd = groupStart + groups.getValueCount(groupPosition); + for (int g = groupStart; g < groupEnd; g++) { + int groupId = groups.getInt(g); + int valuesPosition = groupPosition + positionOffset; + TopDoubleDoubleAggregator.combineIntermediate(state, groupId, top, extra, valuesPosition); + } + } + } + + private void addRawInput(int positionOffset, IntBigArrayBlock groups, DoubleBlock vBlock, + DoubleBlock extraBlock) { + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + if (groups.isNull(groupPosition)) { + continue; + } + int valuesPosition = groupPosition + positionOffset; + if (vBlock.isNull(valuesPosition)) { + continue; + } + if (extraBlock.isNull(valuesPosition)) { + continue; + } + int groupStart = groups.getFirstValueIndex(groupPosition); + int groupEnd = groupStart + groups.getValueCount(groupPosition); + for (int g = groupStart; g < groupEnd; g++) { + int groupId = groups.getInt(g); + int vStart = vBlock.getFirstValueIndex(valuesPosition); + int vEnd = vStart + vBlock.getValueCount(valuesPosition); + for (int vOffset = vStart; vOffset < vEnd; vOffset++) { + double vValue = vBlock.getDouble(vOffset); + int extraStart = extraBlock.getFirstValueIndex(valuesPosition); + int extraEnd = extraStart + extraBlock.getValueCount(valuesPosition); + for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { + double extraValue = extraBlock.getDouble(extraOffset); + TopDoubleDoubleAggregator.combine(state, groupId, vValue, extraValue); + } + } + } + } + } + + private void addRawInput(int positionOffset, IntBigArrayBlock groups, DoubleVector vVector, + DoubleVector extraVector) { + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + if (groups.isNull(groupPosition)) { + continue; + } + int valuesPosition = groupPosition + positionOffset; + int groupStart = groups.getFirstValueIndex(groupPosition); + int groupEnd = groupStart + groups.getValueCount(groupPosition); + for (int g = groupStart; g < groupEnd; g++) { + int groupId = groups.getInt(g); + double vValue = vVector.getDouble(valuesPosition); + double extraValue = extraVector.getDouble(valuesPosition); + TopDoubleDoubleAggregator.combine(state, groupId, vValue, extraValue); + } + } + } + + @Override + public void addIntermediateInput(int positionOffset, IntBigArrayBlock groups, Page page) { + state.enableGroupIdTracking(new SeenGroupIds.Empty()); + assert channels.size() == intermediateBlockCount(); + Block topUncast = page.getBlock(channels.get(0)); + if (topUncast.areAllValuesNull()) { + return; + } + DoubleBlock top = (DoubleBlock) topUncast; + Block extraUncast = page.getBlock(channels.get(1)); + if (extraUncast.areAllValuesNull()) { + return; + } + DoubleBlock extra = (DoubleBlock) extraUncast; + assert top.getPositionCount() == extra.getPositionCount(); + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + if (groups.isNull(groupPosition)) { + continue; + } + int groupStart = groups.getFirstValueIndex(groupPosition); + int groupEnd = groupStart + groups.getValueCount(groupPosition); + for (int g = groupStart; g < groupEnd; g++) { + int groupId = groups.getInt(g); + int valuesPosition = groupPosition + positionOffset; + TopDoubleDoubleAggregator.combineIntermediate(state, groupId, top, extra, valuesPosition); + } + } + } + + private void addRawInput(int positionOffset, IntVector groups, DoubleBlock vBlock, + DoubleBlock extraBlock) { + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + int valuesPosition = groupPosition + positionOffset; + if (vBlock.isNull(valuesPosition)) { + continue; + } + if (extraBlock.isNull(valuesPosition)) { + continue; + } + int groupId = groups.getInt(groupPosition); + int vStart = vBlock.getFirstValueIndex(valuesPosition); + int vEnd = vStart + vBlock.getValueCount(valuesPosition); + for (int vOffset = vStart; vOffset < vEnd; vOffset++) { + double vValue = vBlock.getDouble(vOffset); + int extraStart = extraBlock.getFirstValueIndex(valuesPosition); + int extraEnd = extraStart + extraBlock.getValueCount(valuesPosition); + for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { + double extraValue = extraBlock.getDouble(extraOffset); + TopDoubleDoubleAggregator.combine(state, groupId, vValue, extraValue); + } + } + } + } + + private void addRawInput(int positionOffset, IntVector groups, DoubleVector vVector, + DoubleVector extraVector) { + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + int valuesPosition = groupPosition + positionOffset; + int groupId = groups.getInt(groupPosition); + double vValue = vVector.getDouble(valuesPosition); + double extraValue = extraVector.getDouble(valuesPosition); + TopDoubleDoubleAggregator.combine(state, groupId, vValue, extraValue); + } + } + + @Override + public void addIntermediateInput(int positionOffset, IntVector groups, Page page) { + state.enableGroupIdTracking(new SeenGroupIds.Empty()); + assert channels.size() == intermediateBlockCount(); + Block topUncast = page.getBlock(channels.get(0)); + if (topUncast.areAllValuesNull()) { + return; + } + DoubleBlock top = (DoubleBlock) topUncast; + Block extraUncast = page.getBlock(channels.get(1)); + if (extraUncast.areAllValuesNull()) { + return; + } + DoubleBlock extra = (DoubleBlock) extraUncast; + assert top.getPositionCount() == extra.getPositionCount(); + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + int groupId = groups.getInt(groupPosition); + int valuesPosition = groupPosition + positionOffset; + TopDoubleDoubleAggregator.combineIntermediate(state, groupId, top, extra, valuesPosition); + } + } + + private void maybeEnableGroupIdTracking(SeenGroupIds seenGroupIds, DoubleBlock vBlock, + DoubleBlock extraBlock) { + if (vBlock.mayHaveNulls()) { + state.enableGroupIdTracking(seenGroupIds); + } + if (extraBlock.mayHaveNulls()) { + state.enableGroupIdTracking(seenGroupIds); + } + } + + @Override + public void selectedMayContainUnseenGroups(SeenGroupIds seenGroupIds) { + state.enableGroupIdTracking(seenGroupIds); + } + + @Override + public void evaluateIntermediate(Block[] blocks, int offset, IntVector selected) { + state.toIntermediate(blocks, offset, selected, driverContext); + } + + @Override + public void evaluateFinal(Block[] blocks, int offset, IntVector selected, + GroupingAggregatorEvaluationContext ctx) { + blocks[offset] = TopDoubleDoubleAggregator.evaluateFinal(state, selected, ctx); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append(getClass().getSimpleName()).append("["); + sb.append("channels=").append(channels); + sb.append("]"); + return sb.toString(); + } + + @Override + public void close() { + state.close(); + } +} diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleFloatAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleFloatAggregatorFunction.java new file mode 100644 index 0000000000000..d68e1929a906b --- /dev/null +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleFloatAggregatorFunction.java @@ -0,0 +1,215 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License +// 2.0; you may not use this file except in compliance with the Elastic License +// 2.0. +package org.elasticsearch.compute.aggregation; + +import java.lang.Integer; +import java.lang.Override; +import java.lang.String; +import java.lang.StringBuilder; +import java.util.List; +import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.BooleanVector; +import org.elasticsearch.compute.data.DoubleBlock; +import org.elasticsearch.compute.data.DoubleVector; +import org.elasticsearch.compute.data.ElementType; +import org.elasticsearch.compute.data.FloatBlock; +import org.elasticsearch.compute.data.FloatVector; +import org.elasticsearch.compute.data.Page; +import org.elasticsearch.compute.operator.DriverContext; + +/** + * {@link AggregatorFunction} implementation for {@link TopDoubleFloatAggregator}. + * This class is generated. Edit {@code AggregatorImplementer} instead. + */ +public final class TopDoubleFloatAggregatorFunction implements AggregatorFunction { + private static final List INTERMEDIATE_STATE_DESC = List.of( + new IntermediateStateDesc("top", ElementType.DOUBLE), + new IntermediateStateDesc("extra", ElementType.FLOAT) ); + + private final DriverContext driverContext; + + private final TopDoubleFloatAggregator.SingleState state; + + private final List channels; + + private final int limit; + + private final boolean ascending; + + public TopDoubleFloatAggregatorFunction(DriverContext driverContext, List channels, + TopDoubleFloatAggregator.SingleState state, int limit, boolean ascending) { + this.driverContext = driverContext; + this.channels = channels; + this.state = state; + this.limit = limit; + this.ascending = ascending; + } + + public static TopDoubleFloatAggregatorFunction create(DriverContext driverContext, + List channels, int limit, boolean ascending) { + return new TopDoubleFloatAggregatorFunction(driverContext, channels, TopDoubleFloatAggregator.initSingle(driverContext.bigArrays(), limit, ascending), limit, ascending); + } + + public static List intermediateStateDesc() { + return INTERMEDIATE_STATE_DESC; + } + + @Override + public int intermediateBlockCount() { + return INTERMEDIATE_STATE_DESC.size(); + } + + @Override + public void addRawInput(Page page, BooleanVector mask) { + if (mask.allFalse()) { + // Entire page masked away + } else if (mask.allTrue()) { + addRawInputNotMasked(page); + } else { + addRawInputMasked(page, mask); + } + } + + private void addRawInputMasked(Page page, BooleanVector mask) { + DoubleBlock vBlock = page.getBlock(channels.get(0)); + FloatBlock extraBlock = page.getBlock(channels.get(1)); + DoubleVector vVector = vBlock.asVector(); + if (vVector == null) { + addRawBlock(vBlock, extraBlock, mask); + return; + } + FloatVector extraVector = extraBlock.asVector(); + if (extraVector == null) { + addRawBlock(vBlock, extraBlock, mask); + return; + } + addRawVector(vVector, extraVector, mask); + } + + private void addRawInputNotMasked(Page page) { + DoubleBlock vBlock = page.getBlock(channels.get(0)); + FloatBlock extraBlock = page.getBlock(channels.get(1)); + DoubleVector vVector = vBlock.asVector(); + if (vVector == null) { + addRawBlock(vBlock, extraBlock); + return; + } + FloatVector extraVector = extraBlock.asVector(); + if (extraVector == null) { + addRawBlock(vBlock, extraBlock); + return; + } + addRawVector(vVector, extraVector); + } + + private void addRawVector(DoubleVector vVector, FloatVector extraVector) { + for (int valuesPosition = 0; valuesPosition < vVector.getPositionCount(); valuesPosition++) { + double vValue = vVector.getDouble(valuesPosition); + float extraValue = extraVector.getFloat(valuesPosition); + TopDoubleFloatAggregator.combine(state, vValue, extraValue); + } + } + + private void addRawVector(DoubleVector vVector, FloatVector extraVector, BooleanVector mask) { + for (int valuesPosition = 0; valuesPosition < vVector.getPositionCount(); valuesPosition++) { + if (mask.getBoolean(valuesPosition) == false) { + continue; + } + double vValue = vVector.getDouble(valuesPosition); + float extraValue = extraVector.getFloat(valuesPosition); + TopDoubleFloatAggregator.combine(state, vValue, extraValue); + } + } + + private void addRawBlock(DoubleBlock vBlock, FloatBlock extraBlock) { + for (int p = 0; p < vBlock.getPositionCount(); p++) { + if (vBlock.isNull(p)) { + continue; + } + if (extraBlock.isNull(p)) { + continue; + } + int vStart = vBlock.getFirstValueIndex(p); + int vEnd = vStart + vBlock.getValueCount(p); + for (int vOffset = vStart; vOffset < vEnd; vOffset++) { + double vValue = vBlock.getDouble(vOffset); + int extraStart = extraBlock.getFirstValueIndex(p); + int extraEnd = extraStart + extraBlock.getValueCount(p); + for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { + float extraValue = extraBlock.getFloat(extraOffset); + TopDoubleFloatAggregator.combine(state, vValue, extraValue); + } + } + } + } + + private void addRawBlock(DoubleBlock vBlock, FloatBlock extraBlock, BooleanVector mask) { + for (int p = 0; p < vBlock.getPositionCount(); p++) { + if (mask.getBoolean(p) == false) { + continue; + } + if (vBlock.isNull(p)) { + continue; + } + if (extraBlock.isNull(p)) { + continue; + } + int vStart = vBlock.getFirstValueIndex(p); + int vEnd = vStart + vBlock.getValueCount(p); + for (int vOffset = vStart; vOffset < vEnd; vOffset++) { + double vValue = vBlock.getDouble(vOffset); + int extraStart = extraBlock.getFirstValueIndex(p); + int extraEnd = extraStart + extraBlock.getValueCount(p); + for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { + float extraValue = extraBlock.getFloat(extraOffset); + TopDoubleFloatAggregator.combine(state, vValue, extraValue); + } + } + } + } + + @Override + public void addIntermediateInput(Page page) { + assert channels.size() == intermediateBlockCount(); + assert page.getBlockCount() >= channels.get(0) + intermediateStateDesc().size(); + Block topUncast = page.getBlock(channels.get(0)); + if (topUncast.areAllValuesNull()) { + return; + } + DoubleBlock top = (DoubleBlock) topUncast; + assert top.getPositionCount() == 1; + Block extraUncast = page.getBlock(channels.get(1)); + if (extraUncast.areAllValuesNull()) { + return; + } + FloatBlock extra = (FloatBlock) extraUncast; + assert extra.getPositionCount() == 1; + TopDoubleFloatAggregator.combineIntermediate(state, top, extra); + } + + @Override + public void evaluateIntermediate(Block[] blocks, int offset, DriverContext driverContext) { + state.toIntermediate(blocks, offset, driverContext); + } + + @Override + public void evaluateFinal(Block[] blocks, int offset, DriverContext driverContext) { + blocks[offset] = TopDoubleFloatAggregator.evaluateFinal(state, driverContext); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append(getClass().getSimpleName()).append("["); + sb.append("channels=").append(channels); + sb.append("]"); + return sb.toString(); + } + + @Override + public void close() { + state.close(); + } +} diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleFloatAggregatorFunctionSupplier.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleFloatAggregatorFunctionSupplier.java new file mode 100644 index 0000000000000..db99d9135f9b8 --- /dev/null +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleFloatAggregatorFunctionSupplier.java @@ -0,0 +1,53 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License +// 2.0; you may not use this file except in compliance with the Elastic License +// 2.0. +package org.elasticsearch.compute.aggregation; + +import java.lang.Integer; +import java.lang.Override; +import java.lang.String; +import java.util.List; +import org.elasticsearch.compute.operator.DriverContext; + +/** + * {@link AggregatorFunctionSupplier} implementation for {@link TopDoubleFloatAggregator}. + * This class is generated. Edit {@code AggregatorFunctionSupplierImplementer} instead. + */ +public final class TopDoubleFloatAggregatorFunctionSupplier implements AggregatorFunctionSupplier { + private final int limit; + + private final boolean ascending; + + public TopDoubleFloatAggregatorFunctionSupplier(int limit, boolean ascending) { + this.limit = limit; + this.ascending = ascending; + } + + @Override + public List nonGroupingIntermediateStateDesc() { + return TopDoubleFloatAggregatorFunction.intermediateStateDesc(); + } + + @Override + public List groupingIntermediateStateDesc() { + return TopDoubleFloatGroupingAggregatorFunction.intermediateStateDesc(); + } + + @Override + public TopDoubleFloatAggregatorFunction aggregator(DriverContext driverContext, + List channels) { + return TopDoubleFloatAggregatorFunction.create(driverContext, channels, limit, ascending); + } + + @Override + public TopDoubleFloatGroupingAggregatorFunction groupingAggregator(DriverContext driverContext, + List channels) { + return TopDoubleFloatGroupingAggregatorFunction.create(channels, driverContext, limit, ascending); + } + + @Override + public String describe() { + return "top_double of floats"; + } +} diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleFloatGroupingAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleFloatGroupingAggregatorFunction.java new file mode 100644 index 0000000000000..7eb2ece1b1406 --- /dev/null +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleFloatGroupingAggregatorFunction.java @@ -0,0 +1,397 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License +// 2.0; you may not use this file except in compliance with the Elastic License +// 2.0. +package org.elasticsearch.compute.aggregation; + +import java.lang.Integer; +import java.lang.Override; +import java.lang.String; +import java.lang.StringBuilder; +import java.util.List; +import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.DoubleBlock; +import org.elasticsearch.compute.data.DoubleVector; +import org.elasticsearch.compute.data.ElementType; +import org.elasticsearch.compute.data.FloatBlock; +import org.elasticsearch.compute.data.FloatVector; +import org.elasticsearch.compute.data.IntArrayBlock; +import org.elasticsearch.compute.data.IntBigArrayBlock; +import org.elasticsearch.compute.data.IntVector; +import org.elasticsearch.compute.data.Page; +import org.elasticsearch.compute.operator.DriverContext; + +/** + * {@link GroupingAggregatorFunction} implementation for {@link TopDoubleFloatAggregator}. + * This class is generated. Edit {@code GroupingAggregatorImplementer} instead. + */ +public final class TopDoubleFloatGroupingAggregatorFunction implements GroupingAggregatorFunction { + private static final List INTERMEDIATE_STATE_DESC = List.of( + new IntermediateStateDesc("top", ElementType.DOUBLE), + new IntermediateStateDesc("extra", ElementType.FLOAT) ); + + private final TopDoubleFloatAggregator.GroupingState state; + + private final List channels; + + private final DriverContext driverContext; + + private final int limit; + + private final boolean ascending; + + public TopDoubleFloatGroupingAggregatorFunction(List channels, + TopDoubleFloatAggregator.GroupingState state, DriverContext driverContext, int limit, + boolean ascending) { + this.channels = channels; + this.state = state; + this.driverContext = driverContext; + this.limit = limit; + this.ascending = ascending; + } + + public static TopDoubleFloatGroupingAggregatorFunction create(List channels, + DriverContext driverContext, int limit, boolean ascending) { + return new TopDoubleFloatGroupingAggregatorFunction(channels, TopDoubleFloatAggregator.initGrouping(driverContext.bigArrays(), limit, ascending), driverContext, limit, ascending); + } + + public static List intermediateStateDesc() { + return INTERMEDIATE_STATE_DESC; + } + + @Override + public int intermediateBlockCount() { + return INTERMEDIATE_STATE_DESC.size(); + } + + @Override + public GroupingAggregatorFunction.AddInput prepareProcessRawInputPage(SeenGroupIds seenGroupIds, + Page page) { + DoubleBlock vBlock = page.getBlock(channels.get(0)); + FloatBlock extraBlock = page.getBlock(channels.get(1)); + DoubleVector vVector = vBlock.asVector(); + if (vVector == null) { + maybeEnableGroupIdTracking(seenGroupIds, vBlock, extraBlock); + return new GroupingAggregatorFunction.AddInput() { + @Override + public void add(int positionOffset, IntArrayBlock groupIds) { + addRawInput(positionOffset, groupIds, vBlock, extraBlock); + } + + @Override + public void add(int positionOffset, IntBigArrayBlock groupIds) { + addRawInput(positionOffset, groupIds, vBlock, extraBlock); + } + + @Override + public void add(int positionOffset, IntVector groupIds) { + addRawInput(positionOffset, groupIds, vBlock, extraBlock); + } + + @Override + public void close() { + } + }; + } + FloatVector extraVector = extraBlock.asVector(); + if (extraVector == null) { + maybeEnableGroupIdTracking(seenGroupIds, vBlock, extraBlock); + return new GroupingAggregatorFunction.AddInput() { + @Override + public void add(int positionOffset, IntArrayBlock groupIds) { + addRawInput(positionOffset, groupIds, vBlock, extraBlock); + } + + @Override + public void add(int positionOffset, IntBigArrayBlock groupIds) { + addRawInput(positionOffset, groupIds, vBlock, extraBlock); + } + + @Override + public void add(int positionOffset, IntVector groupIds) { + addRawInput(positionOffset, groupIds, vBlock, extraBlock); + } + + @Override + public void close() { + } + }; + } + return new GroupingAggregatorFunction.AddInput() { + @Override + public void add(int positionOffset, IntArrayBlock groupIds) { + addRawInput(positionOffset, groupIds, vVector, extraVector); + } + + @Override + public void add(int positionOffset, IntBigArrayBlock groupIds) { + addRawInput(positionOffset, groupIds, vVector, extraVector); + } + + @Override + public void add(int positionOffset, IntVector groupIds) { + addRawInput(positionOffset, groupIds, vVector, extraVector); + } + + @Override + public void close() { + } + }; + } + + private void addRawInput(int positionOffset, IntArrayBlock groups, DoubleBlock vBlock, + FloatBlock extraBlock) { + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + if (groups.isNull(groupPosition)) { + continue; + } + int valuesPosition = groupPosition + positionOffset; + if (vBlock.isNull(valuesPosition)) { + continue; + } + if (extraBlock.isNull(valuesPosition)) { + continue; + } + int groupStart = groups.getFirstValueIndex(groupPosition); + int groupEnd = groupStart + groups.getValueCount(groupPosition); + for (int g = groupStart; g < groupEnd; g++) { + int groupId = groups.getInt(g); + int vStart = vBlock.getFirstValueIndex(valuesPosition); + int vEnd = vStart + vBlock.getValueCount(valuesPosition); + for (int vOffset = vStart; vOffset < vEnd; vOffset++) { + double vValue = vBlock.getDouble(vOffset); + int extraStart = extraBlock.getFirstValueIndex(valuesPosition); + int extraEnd = extraStart + extraBlock.getValueCount(valuesPosition); + for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { + float extraValue = extraBlock.getFloat(extraOffset); + TopDoubleFloatAggregator.combine(state, groupId, vValue, extraValue); + } + } + } + } + } + + private void addRawInput(int positionOffset, IntArrayBlock groups, DoubleVector vVector, + FloatVector extraVector) { + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + if (groups.isNull(groupPosition)) { + continue; + } + int valuesPosition = groupPosition + positionOffset; + int groupStart = groups.getFirstValueIndex(groupPosition); + int groupEnd = groupStart + groups.getValueCount(groupPosition); + for (int g = groupStart; g < groupEnd; g++) { + int groupId = groups.getInt(g); + double vValue = vVector.getDouble(valuesPosition); + float extraValue = extraVector.getFloat(valuesPosition); + TopDoubleFloatAggregator.combine(state, groupId, vValue, extraValue); + } + } + } + + @Override + public void addIntermediateInput(int positionOffset, IntArrayBlock groups, Page page) { + state.enableGroupIdTracking(new SeenGroupIds.Empty()); + assert channels.size() == intermediateBlockCount(); + Block topUncast = page.getBlock(channels.get(0)); + if (topUncast.areAllValuesNull()) { + return; + } + DoubleBlock top = (DoubleBlock) topUncast; + Block extraUncast = page.getBlock(channels.get(1)); + if (extraUncast.areAllValuesNull()) { + return; + } + FloatBlock extra = (FloatBlock) extraUncast; + assert top.getPositionCount() == extra.getPositionCount(); + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + if (groups.isNull(groupPosition)) { + continue; + } + int groupStart = groups.getFirstValueIndex(groupPosition); + int groupEnd = groupStart + groups.getValueCount(groupPosition); + for (int g = groupStart; g < groupEnd; g++) { + int groupId = groups.getInt(g); + int valuesPosition = groupPosition + positionOffset; + TopDoubleFloatAggregator.combineIntermediate(state, groupId, top, extra, valuesPosition); + } + } + } + + private void addRawInput(int positionOffset, IntBigArrayBlock groups, DoubleBlock vBlock, + FloatBlock extraBlock) { + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + if (groups.isNull(groupPosition)) { + continue; + } + int valuesPosition = groupPosition + positionOffset; + if (vBlock.isNull(valuesPosition)) { + continue; + } + if (extraBlock.isNull(valuesPosition)) { + continue; + } + int groupStart = groups.getFirstValueIndex(groupPosition); + int groupEnd = groupStart + groups.getValueCount(groupPosition); + for (int g = groupStart; g < groupEnd; g++) { + int groupId = groups.getInt(g); + int vStart = vBlock.getFirstValueIndex(valuesPosition); + int vEnd = vStart + vBlock.getValueCount(valuesPosition); + for (int vOffset = vStart; vOffset < vEnd; vOffset++) { + double vValue = vBlock.getDouble(vOffset); + int extraStart = extraBlock.getFirstValueIndex(valuesPosition); + int extraEnd = extraStart + extraBlock.getValueCount(valuesPosition); + for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { + float extraValue = extraBlock.getFloat(extraOffset); + TopDoubleFloatAggregator.combine(state, groupId, vValue, extraValue); + } + } + } + } + } + + private void addRawInput(int positionOffset, IntBigArrayBlock groups, DoubleVector vVector, + FloatVector extraVector) { + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + if (groups.isNull(groupPosition)) { + continue; + } + int valuesPosition = groupPosition + positionOffset; + int groupStart = groups.getFirstValueIndex(groupPosition); + int groupEnd = groupStart + groups.getValueCount(groupPosition); + for (int g = groupStart; g < groupEnd; g++) { + int groupId = groups.getInt(g); + double vValue = vVector.getDouble(valuesPosition); + float extraValue = extraVector.getFloat(valuesPosition); + TopDoubleFloatAggregator.combine(state, groupId, vValue, extraValue); + } + } + } + + @Override + public void addIntermediateInput(int positionOffset, IntBigArrayBlock groups, Page page) { + state.enableGroupIdTracking(new SeenGroupIds.Empty()); + assert channels.size() == intermediateBlockCount(); + Block topUncast = page.getBlock(channels.get(0)); + if (topUncast.areAllValuesNull()) { + return; + } + DoubleBlock top = (DoubleBlock) topUncast; + Block extraUncast = page.getBlock(channels.get(1)); + if (extraUncast.areAllValuesNull()) { + return; + } + FloatBlock extra = (FloatBlock) extraUncast; + assert top.getPositionCount() == extra.getPositionCount(); + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + if (groups.isNull(groupPosition)) { + continue; + } + int groupStart = groups.getFirstValueIndex(groupPosition); + int groupEnd = groupStart + groups.getValueCount(groupPosition); + for (int g = groupStart; g < groupEnd; g++) { + int groupId = groups.getInt(g); + int valuesPosition = groupPosition + positionOffset; + TopDoubleFloatAggregator.combineIntermediate(state, groupId, top, extra, valuesPosition); + } + } + } + + private void addRawInput(int positionOffset, IntVector groups, DoubleBlock vBlock, + FloatBlock extraBlock) { + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + int valuesPosition = groupPosition + positionOffset; + if (vBlock.isNull(valuesPosition)) { + continue; + } + if (extraBlock.isNull(valuesPosition)) { + continue; + } + int groupId = groups.getInt(groupPosition); + int vStart = vBlock.getFirstValueIndex(valuesPosition); + int vEnd = vStart + vBlock.getValueCount(valuesPosition); + for (int vOffset = vStart; vOffset < vEnd; vOffset++) { + double vValue = vBlock.getDouble(vOffset); + int extraStart = extraBlock.getFirstValueIndex(valuesPosition); + int extraEnd = extraStart + extraBlock.getValueCount(valuesPosition); + for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { + float extraValue = extraBlock.getFloat(extraOffset); + TopDoubleFloatAggregator.combine(state, groupId, vValue, extraValue); + } + } + } + } + + private void addRawInput(int positionOffset, IntVector groups, DoubleVector vVector, + FloatVector extraVector) { + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + int valuesPosition = groupPosition + positionOffset; + int groupId = groups.getInt(groupPosition); + double vValue = vVector.getDouble(valuesPosition); + float extraValue = extraVector.getFloat(valuesPosition); + TopDoubleFloatAggregator.combine(state, groupId, vValue, extraValue); + } + } + + @Override + public void addIntermediateInput(int positionOffset, IntVector groups, Page page) { + state.enableGroupIdTracking(new SeenGroupIds.Empty()); + assert channels.size() == intermediateBlockCount(); + Block topUncast = page.getBlock(channels.get(0)); + if (topUncast.areAllValuesNull()) { + return; + } + DoubleBlock top = (DoubleBlock) topUncast; + Block extraUncast = page.getBlock(channels.get(1)); + if (extraUncast.areAllValuesNull()) { + return; + } + FloatBlock extra = (FloatBlock) extraUncast; + assert top.getPositionCount() == extra.getPositionCount(); + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + int groupId = groups.getInt(groupPosition); + int valuesPosition = groupPosition + positionOffset; + TopDoubleFloatAggregator.combineIntermediate(state, groupId, top, extra, valuesPosition); + } + } + + private void maybeEnableGroupIdTracking(SeenGroupIds seenGroupIds, DoubleBlock vBlock, + FloatBlock extraBlock) { + if (vBlock.mayHaveNulls()) { + state.enableGroupIdTracking(seenGroupIds); + } + if (extraBlock.mayHaveNulls()) { + state.enableGroupIdTracking(seenGroupIds); + } + } + + @Override + public void selectedMayContainUnseenGroups(SeenGroupIds seenGroupIds) { + state.enableGroupIdTracking(seenGroupIds); + } + + @Override + public void evaluateIntermediate(Block[] blocks, int offset, IntVector selected) { + state.toIntermediate(blocks, offset, selected, driverContext); + } + + @Override + public void evaluateFinal(Block[] blocks, int offset, IntVector selected, + GroupingAggregatorEvaluationContext ctx) { + blocks[offset] = TopDoubleFloatAggregator.evaluateFinal(state, selected, ctx); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append(getClass().getSimpleName()).append("["); + sb.append("channels=").append(channels); + sb.append("]"); + return sb.toString(); + } + + @Override + public void close() { + state.close(); + } +} diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleIntAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleIntAggregatorFunction.java new file mode 100644 index 0000000000000..c3b2bfee37db9 --- /dev/null +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleIntAggregatorFunction.java @@ -0,0 +1,215 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License +// 2.0; you may not use this file except in compliance with the Elastic License +// 2.0. +package org.elasticsearch.compute.aggregation; + +import java.lang.Integer; +import java.lang.Override; +import java.lang.String; +import java.lang.StringBuilder; +import java.util.List; +import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.BooleanVector; +import org.elasticsearch.compute.data.DoubleBlock; +import org.elasticsearch.compute.data.DoubleVector; +import org.elasticsearch.compute.data.ElementType; +import org.elasticsearch.compute.data.IntBlock; +import org.elasticsearch.compute.data.IntVector; +import org.elasticsearch.compute.data.Page; +import org.elasticsearch.compute.operator.DriverContext; + +/** + * {@link AggregatorFunction} implementation for {@link TopDoubleIntAggregator}. + * This class is generated. Edit {@code AggregatorImplementer} instead. + */ +public final class TopDoubleIntAggregatorFunction implements AggregatorFunction { + private static final List INTERMEDIATE_STATE_DESC = List.of( + new IntermediateStateDesc("top", ElementType.DOUBLE), + new IntermediateStateDesc("extra", ElementType.INT) ); + + private final DriverContext driverContext; + + private final TopDoubleIntAggregator.SingleState state; + + private final List channels; + + private final int limit; + + private final boolean ascending; + + public TopDoubleIntAggregatorFunction(DriverContext driverContext, List channels, + TopDoubleIntAggregator.SingleState state, int limit, boolean ascending) { + this.driverContext = driverContext; + this.channels = channels; + this.state = state; + this.limit = limit; + this.ascending = ascending; + } + + public static TopDoubleIntAggregatorFunction create(DriverContext driverContext, + List channels, int limit, boolean ascending) { + return new TopDoubleIntAggregatorFunction(driverContext, channels, TopDoubleIntAggregator.initSingle(driverContext.bigArrays(), limit, ascending), limit, ascending); + } + + public static List intermediateStateDesc() { + return INTERMEDIATE_STATE_DESC; + } + + @Override + public int intermediateBlockCount() { + return INTERMEDIATE_STATE_DESC.size(); + } + + @Override + public void addRawInput(Page page, BooleanVector mask) { + if (mask.allFalse()) { + // Entire page masked away + } else if (mask.allTrue()) { + addRawInputNotMasked(page); + } else { + addRawInputMasked(page, mask); + } + } + + private void addRawInputMasked(Page page, BooleanVector mask) { + DoubleBlock vBlock = page.getBlock(channels.get(0)); + IntBlock extraBlock = page.getBlock(channels.get(1)); + DoubleVector vVector = vBlock.asVector(); + if (vVector == null) { + addRawBlock(vBlock, extraBlock, mask); + return; + } + IntVector extraVector = extraBlock.asVector(); + if (extraVector == null) { + addRawBlock(vBlock, extraBlock, mask); + return; + } + addRawVector(vVector, extraVector, mask); + } + + private void addRawInputNotMasked(Page page) { + DoubleBlock vBlock = page.getBlock(channels.get(0)); + IntBlock extraBlock = page.getBlock(channels.get(1)); + DoubleVector vVector = vBlock.asVector(); + if (vVector == null) { + addRawBlock(vBlock, extraBlock); + return; + } + IntVector extraVector = extraBlock.asVector(); + if (extraVector == null) { + addRawBlock(vBlock, extraBlock); + return; + } + addRawVector(vVector, extraVector); + } + + private void addRawVector(DoubleVector vVector, IntVector extraVector) { + for (int valuesPosition = 0; valuesPosition < vVector.getPositionCount(); valuesPosition++) { + double vValue = vVector.getDouble(valuesPosition); + int extraValue = extraVector.getInt(valuesPosition); + TopDoubleIntAggregator.combine(state, vValue, extraValue); + } + } + + private void addRawVector(DoubleVector vVector, IntVector extraVector, BooleanVector mask) { + for (int valuesPosition = 0; valuesPosition < vVector.getPositionCount(); valuesPosition++) { + if (mask.getBoolean(valuesPosition) == false) { + continue; + } + double vValue = vVector.getDouble(valuesPosition); + int extraValue = extraVector.getInt(valuesPosition); + TopDoubleIntAggregator.combine(state, vValue, extraValue); + } + } + + private void addRawBlock(DoubleBlock vBlock, IntBlock extraBlock) { + for (int p = 0; p < vBlock.getPositionCount(); p++) { + if (vBlock.isNull(p)) { + continue; + } + if (extraBlock.isNull(p)) { + continue; + } + int vStart = vBlock.getFirstValueIndex(p); + int vEnd = vStart + vBlock.getValueCount(p); + for (int vOffset = vStart; vOffset < vEnd; vOffset++) { + double vValue = vBlock.getDouble(vOffset); + int extraStart = extraBlock.getFirstValueIndex(p); + int extraEnd = extraStart + extraBlock.getValueCount(p); + for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { + int extraValue = extraBlock.getInt(extraOffset); + TopDoubleIntAggregator.combine(state, vValue, extraValue); + } + } + } + } + + private void addRawBlock(DoubleBlock vBlock, IntBlock extraBlock, BooleanVector mask) { + for (int p = 0; p < vBlock.getPositionCount(); p++) { + if (mask.getBoolean(p) == false) { + continue; + } + if (vBlock.isNull(p)) { + continue; + } + if (extraBlock.isNull(p)) { + continue; + } + int vStart = vBlock.getFirstValueIndex(p); + int vEnd = vStart + vBlock.getValueCount(p); + for (int vOffset = vStart; vOffset < vEnd; vOffset++) { + double vValue = vBlock.getDouble(vOffset); + int extraStart = extraBlock.getFirstValueIndex(p); + int extraEnd = extraStart + extraBlock.getValueCount(p); + for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { + int extraValue = extraBlock.getInt(extraOffset); + TopDoubleIntAggregator.combine(state, vValue, extraValue); + } + } + } + } + + @Override + public void addIntermediateInput(Page page) { + assert channels.size() == intermediateBlockCount(); + assert page.getBlockCount() >= channels.get(0) + intermediateStateDesc().size(); + Block topUncast = page.getBlock(channels.get(0)); + if (topUncast.areAllValuesNull()) { + return; + } + DoubleBlock top = (DoubleBlock) topUncast; + assert top.getPositionCount() == 1; + Block extraUncast = page.getBlock(channels.get(1)); + if (extraUncast.areAllValuesNull()) { + return; + } + IntBlock extra = (IntBlock) extraUncast; + assert extra.getPositionCount() == 1; + TopDoubleIntAggregator.combineIntermediate(state, top, extra); + } + + @Override + public void evaluateIntermediate(Block[] blocks, int offset, DriverContext driverContext) { + state.toIntermediate(blocks, offset, driverContext); + } + + @Override + public void evaluateFinal(Block[] blocks, int offset, DriverContext driverContext) { + blocks[offset] = TopDoubleIntAggregator.evaluateFinal(state, driverContext); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append(getClass().getSimpleName()).append("["); + sb.append("channels=").append(channels); + sb.append("]"); + return sb.toString(); + } + + @Override + public void close() { + state.close(); + } +} diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleIntAggregatorFunctionSupplier.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleIntAggregatorFunctionSupplier.java new file mode 100644 index 0000000000000..4bb7632d5db7d --- /dev/null +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleIntAggregatorFunctionSupplier.java @@ -0,0 +1,53 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License +// 2.0; you may not use this file except in compliance with the Elastic License +// 2.0. +package org.elasticsearch.compute.aggregation; + +import java.lang.Integer; +import java.lang.Override; +import java.lang.String; +import java.util.List; +import org.elasticsearch.compute.operator.DriverContext; + +/** + * {@link AggregatorFunctionSupplier} implementation for {@link TopDoubleIntAggregator}. + * This class is generated. Edit {@code AggregatorFunctionSupplierImplementer} instead. + */ +public final class TopDoubleIntAggregatorFunctionSupplier implements AggregatorFunctionSupplier { + private final int limit; + + private final boolean ascending; + + public TopDoubleIntAggregatorFunctionSupplier(int limit, boolean ascending) { + this.limit = limit; + this.ascending = ascending; + } + + @Override + public List nonGroupingIntermediateStateDesc() { + return TopDoubleIntAggregatorFunction.intermediateStateDesc(); + } + + @Override + public List groupingIntermediateStateDesc() { + return TopDoubleIntGroupingAggregatorFunction.intermediateStateDesc(); + } + + @Override + public TopDoubleIntAggregatorFunction aggregator(DriverContext driverContext, + List channels) { + return TopDoubleIntAggregatorFunction.create(driverContext, channels, limit, ascending); + } + + @Override + public TopDoubleIntGroupingAggregatorFunction groupingAggregator(DriverContext driverContext, + List channels) { + return TopDoubleIntGroupingAggregatorFunction.create(channels, driverContext, limit, ascending); + } + + @Override + public String describe() { + return "top_double of ints"; + } +} diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleIntGroupingAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleIntGroupingAggregatorFunction.java new file mode 100644 index 0000000000000..0ef06a2136d4b --- /dev/null +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleIntGroupingAggregatorFunction.java @@ -0,0 +1,396 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License +// 2.0; you may not use this file except in compliance with the Elastic License +// 2.0. +package org.elasticsearch.compute.aggregation; + +import java.lang.Integer; +import java.lang.Override; +import java.lang.String; +import java.lang.StringBuilder; +import java.util.List; +import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.DoubleBlock; +import org.elasticsearch.compute.data.DoubleVector; +import org.elasticsearch.compute.data.ElementType; +import org.elasticsearch.compute.data.IntArrayBlock; +import org.elasticsearch.compute.data.IntBigArrayBlock; +import org.elasticsearch.compute.data.IntBlock; +import org.elasticsearch.compute.data.IntVector; +import org.elasticsearch.compute.data.Page; +import org.elasticsearch.compute.operator.DriverContext; + +/** + * {@link GroupingAggregatorFunction} implementation for {@link TopDoubleIntAggregator}. + * This class is generated. Edit {@code GroupingAggregatorImplementer} instead. + */ +public final class TopDoubleIntGroupingAggregatorFunction implements GroupingAggregatorFunction { + private static final List INTERMEDIATE_STATE_DESC = List.of( + new IntermediateStateDesc("top", ElementType.DOUBLE), + new IntermediateStateDesc("extra", ElementType.INT) ); + + private final TopDoubleIntAggregator.GroupingState state; + + private final List channels; + + private final DriverContext driverContext; + + private final int limit; + + private final boolean ascending; + + public TopDoubleIntGroupingAggregatorFunction(List channels, + TopDoubleIntAggregator.GroupingState state, DriverContext driverContext, int limit, + boolean ascending) { + this.channels = channels; + this.state = state; + this.driverContext = driverContext; + this.limit = limit; + this.ascending = ascending; + } + + public static TopDoubleIntGroupingAggregatorFunction create(List channels, + DriverContext driverContext, int limit, boolean ascending) { + return new TopDoubleIntGroupingAggregatorFunction(channels, TopDoubleIntAggregator.initGrouping(driverContext.bigArrays(), limit, ascending), driverContext, limit, ascending); + } + + public static List intermediateStateDesc() { + return INTERMEDIATE_STATE_DESC; + } + + @Override + public int intermediateBlockCount() { + return INTERMEDIATE_STATE_DESC.size(); + } + + @Override + public GroupingAggregatorFunction.AddInput prepareProcessRawInputPage(SeenGroupIds seenGroupIds, + Page page) { + DoubleBlock vBlock = page.getBlock(channels.get(0)); + IntBlock extraBlock = page.getBlock(channels.get(1)); + DoubleVector vVector = vBlock.asVector(); + if (vVector == null) { + maybeEnableGroupIdTracking(seenGroupIds, vBlock, extraBlock); + return new GroupingAggregatorFunction.AddInput() { + @Override + public void add(int positionOffset, IntArrayBlock groupIds) { + addRawInput(positionOffset, groupIds, vBlock, extraBlock); + } + + @Override + public void add(int positionOffset, IntBigArrayBlock groupIds) { + addRawInput(positionOffset, groupIds, vBlock, extraBlock); + } + + @Override + public void add(int positionOffset, IntVector groupIds) { + addRawInput(positionOffset, groupIds, vBlock, extraBlock); + } + + @Override + public void close() { + } + }; + } + IntVector extraVector = extraBlock.asVector(); + if (extraVector == null) { + maybeEnableGroupIdTracking(seenGroupIds, vBlock, extraBlock); + return new GroupingAggregatorFunction.AddInput() { + @Override + public void add(int positionOffset, IntArrayBlock groupIds) { + addRawInput(positionOffset, groupIds, vBlock, extraBlock); + } + + @Override + public void add(int positionOffset, IntBigArrayBlock groupIds) { + addRawInput(positionOffset, groupIds, vBlock, extraBlock); + } + + @Override + public void add(int positionOffset, IntVector groupIds) { + addRawInput(positionOffset, groupIds, vBlock, extraBlock); + } + + @Override + public void close() { + } + }; + } + return new GroupingAggregatorFunction.AddInput() { + @Override + public void add(int positionOffset, IntArrayBlock groupIds) { + addRawInput(positionOffset, groupIds, vVector, extraVector); + } + + @Override + public void add(int positionOffset, IntBigArrayBlock groupIds) { + addRawInput(positionOffset, groupIds, vVector, extraVector); + } + + @Override + public void add(int positionOffset, IntVector groupIds) { + addRawInput(positionOffset, groupIds, vVector, extraVector); + } + + @Override + public void close() { + } + }; + } + + private void addRawInput(int positionOffset, IntArrayBlock groups, DoubleBlock vBlock, + IntBlock extraBlock) { + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + if (groups.isNull(groupPosition)) { + continue; + } + int valuesPosition = groupPosition + positionOffset; + if (vBlock.isNull(valuesPosition)) { + continue; + } + if (extraBlock.isNull(valuesPosition)) { + continue; + } + int groupStart = groups.getFirstValueIndex(groupPosition); + int groupEnd = groupStart + groups.getValueCount(groupPosition); + for (int g = groupStart; g < groupEnd; g++) { + int groupId = groups.getInt(g); + int vStart = vBlock.getFirstValueIndex(valuesPosition); + int vEnd = vStart + vBlock.getValueCount(valuesPosition); + for (int vOffset = vStart; vOffset < vEnd; vOffset++) { + double vValue = vBlock.getDouble(vOffset); + int extraStart = extraBlock.getFirstValueIndex(valuesPosition); + int extraEnd = extraStart + extraBlock.getValueCount(valuesPosition); + for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { + int extraValue = extraBlock.getInt(extraOffset); + TopDoubleIntAggregator.combine(state, groupId, vValue, extraValue); + } + } + } + } + } + + private void addRawInput(int positionOffset, IntArrayBlock groups, DoubleVector vVector, + IntVector extraVector) { + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + if (groups.isNull(groupPosition)) { + continue; + } + int valuesPosition = groupPosition + positionOffset; + int groupStart = groups.getFirstValueIndex(groupPosition); + int groupEnd = groupStart + groups.getValueCount(groupPosition); + for (int g = groupStart; g < groupEnd; g++) { + int groupId = groups.getInt(g); + double vValue = vVector.getDouble(valuesPosition); + int extraValue = extraVector.getInt(valuesPosition); + TopDoubleIntAggregator.combine(state, groupId, vValue, extraValue); + } + } + } + + @Override + public void addIntermediateInput(int positionOffset, IntArrayBlock groups, Page page) { + state.enableGroupIdTracking(new SeenGroupIds.Empty()); + assert channels.size() == intermediateBlockCount(); + Block topUncast = page.getBlock(channels.get(0)); + if (topUncast.areAllValuesNull()) { + return; + } + DoubleBlock top = (DoubleBlock) topUncast; + Block extraUncast = page.getBlock(channels.get(1)); + if (extraUncast.areAllValuesNull()) { + return; + } + IntBlock extra = (IntBlock) extraUncast; + assert top.getPositionCount() == extra.getPositionCount(); + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + if (groups.isNull(groupPosition)) { + continue; + } + int groupStart = groups.getFirstValueIndex(groupPosition); + int groupEnd = groupStart + groups.getValueCount(groupPosition); + for (int g = groupStart; g < groupEnd; g++) { + int groupId = groups.getInt(g); + int valuesPosition = groupPosition + positionOffset; + TopDoubleIntAggregator.combineIntermediate(state, groupId, top, extra, valuesPosition); + } + } + } + + private void addRawInput(int positionOffset, IntBigArrayBlock groups, DoubleBlock vBlock, + IntBlock extraBlock) { + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + if (groups.isNull(groupPosition)) { + continue; + } + int valuesPosition = groupPosition + positionOffset; + if (vBlock.isNull(valuesPosition)) { + continue; + } + if (extraBlock.isNull(valuesPosition)) { + continue; + } + int groupStart = groups.getFirstValueIndex(groupPosition); + int groupEnd = groupStart + groups.getValueCount(groupPosition); + for (int g = groupStart; g < groupEnd; g++) { + int groupId = groups.getInt(g); + int vStart = vBlock.getFirstValueIndex(valuesPosition); + int vEnd = vStart + vBlock.getValueCount(valuesPosition); + for (int vOffset = vStart; vOffset < vEnd; vOffset++) { + double vValue = vBlock.getDouble(vOffset); + int extraStart = extraBlock.getFirstValueIndex(valuesPosition); + int extraEnd = extraStart + extraBlock.getValueCount(valuesPosition); + for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { + int extraValue = extraBlock.getInt(extraOffset); + TopDoubleIntAggregator.combine(state, groupId, vValue, extraValue); + } + } + } + } + } + + private void addRawInput(int positionOffset, IntBigArrayBlock groups, DoubleVector vVector, + IntVector extraVector) { + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + if (groups.isNull(groupPosition)) { + continue; + } + int valuesPosition = groupPosition + positionOffset; + int groupStart = groups.getFirstValueIndex(groupPosition); + int groupEnd = groupStart + groups.getValueCount(groupPosition); + for (int g = groupStart; g < groupEnd; g++) { + int groupId = groups.getInt(g); + double vValue = vVector.getDouble(valuesPosition); + int extraValue = extraVector.getInt(valuesPosition); + TopDoubleIntAggregator.combine(state, groupId, vValue, extraValue); + } + } + } + + @Override + public void addIntermediateInput(int positionOffset, IntBigArrayBlock groups, Page page) { + state.enableGroupIdTracking(new SeenGroupIds.Empty()); + assert channels.size() == intermediateBlockCount(); + Block topUncast = page.getBlock(channels.get(0)); + if (topUncast.areAllValuesNull()) { + return; + } + DoubleBlock top = (DoubleBlock) topUncast; + Block extraUncast = page.getBlock(channels.get(1)); + if (extraUncast.areAllValuesNull()) { + return; + } + IntBlock extra = (IntBlock) extraUncast; + assert top.getPositionCount() == extra.getPositionCount(); + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + if (groups.isNull(groupPosition)) { + continue; + } + int groupStart = groups.getFirstValueIndex(groupPosition); + int groupEnd = groupStart + groups.getValueCount(groupPosition); + for (int g = groupStart; g < groupEnd; g++) { + int groupId = groups.getInt(g); + int valuesPosition = groupPosition + positionOffset; + TopDoubleIntAggregator.combineIntermediate(state, groupId, top, extra, valuesPosition); + } + } + } + + private void addRawInput(int positionOffset, IntVector groups, DoubleBlock vBlock, + IntBlock extraBlock) { + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + int valuesPosition = groupPosition + positionOffset; + if (vBlock.isNull(valuesPosition)) { + continue; + } + if (extraBlock.isNull(valuesPosition)) { + continue; + } + int groupId = groups.getInt(groupPosition); + int vStart = vBlock.getFirstValueIndex(valuesPosition); + int vEnd = vStart + vBlock.getValueCount(valuesPosition); + for (int vOffset = vStart; vOffset < vEnd; vOffset++) { + double vValue = vBlock.getDouble(vOffset); + int extraStart = extraBlock.getFirstValueIndex(valuesPosition); + int extraEnd = extraStart + extraBlock.getValueCount(valuesPosition); + for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { + int extraValue = extraBlock.getInt(extraOffset); + TopDoubleIntAggregator.combine(state, groupId, vValue, extraValue); + } + } + } + } + + private void addRawInput(int positionOffset, IntVector groups, DoubleVector vVector, + IntVector extraVector) { + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + int valuesPosition = groupPosition + positionOffset; + int groupId = groups.getInt(groupPosition); + double vValue = vVector.getDouble(valuesPosition); + int extraValue = extraVector.getInt(valuesPosition); + TopDoubleIntAggregator.combine(state, groupId, vValue, extraValue); + } + } + + @Override + public void addIntermediateInput(int positionOffset, IntVector groups, Page page) { + state.enableGroupIdTracking(new SeenGroupIds.Empty()); + assert channels.size() == intermediateBlockCount(); + Block topUncast = page.getBlock(channels.get(0)); + if (topUncast.areAllValuesNull()) { + return; + } + DoubleBlock top = (DoubleBlock) topUncast; + Block extraUncast = page.getBlock(channels.get(1)); + if (extraUncast.areAllValuesNull()) { + return; + } + IntBlock extra = (IntBlock) extraUncast; + assert top.getPositionCount() == extra.getPositionCount(); + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + int groupId = groups.getInt(groupPosition); + int valuesPosition = groupPosition + positionOffset; + TopDoubleIntAggregator.combineIntermediate(state, groupId, top, extra, valuesPosition); + } + } + + private void maybeEnableGroupIdTracking(SeenGroupIds seenGroupIds, DoubleBlock vBlock, + IntBlock extraBlock) { + if (vBlock.mayHaveNulls()) { + state.enableGroupIdTracking(seenGroupIds); + } + if (extraBlock.mayHaveNulls()) { + state.enableGroupIdTracking(seenGroupIds); + } + } + + @Override + public void selectedMayContainUnseenGroups(SeenGroupIds seenGroupIds) { + state.enableGroupIdTracking(seenGroupIds); + } + + @Override + public void evaluateIntermediate(Block[] blocks, int offset, IntVector selected) { + state.toIntermediate(blocks, offset, selected, driverContext); + } + + @Override + public void evaluateFinal(Block[] blocks, int offset, IntVector selected, + GroupingAggregatorEvaluationContext ctx) { + blocks[offset] = TopDoubleIntAggregator.evaluateFinal(state, selected, ctx); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append(getClass().getSimpleName()).append("["); + sb.append("channels=").append(channels); + sb.append("]"); + return sb.toString(); + } + + @Override + public void close() { + state.close(); + } +} diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleLongAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleLongAggregatorFunction.java new file mode 100644 index 0000000000000..00ee94bfb7d4a --- /dev/null +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleLongAggregatorFunction.java @@ -0,0 +1,215 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License +// 2.0; you may not use this file except in compliance with the Elastic License +// 2.0. +package org.elasticsearch.compute.aggregation; + +import java.lang.Integer; +import java.lang.Override; +import java.lang.String; +import java.lang.StringBuilder; +import java.util.List; +import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.BooleanVector; +import org.elasticsearch.compute.data.DoubleBlock; +import org.elasticsearch.compute.data.DoubleVector; +import org.elasticsearch.compute.data.ElementType; +import org.elasticsearch.compute.data.LongBlock; +import org.elasticsearch.compute.data.LongVector; +import org.elasticsearch.compute.data.Page; +import org.elasticsearch.compute.operator.DriverContext; + +/** + * {@link AggregatorFunction} implementation for {@link TopDoubleLongAggregator}. + * This class is generated. Edit {@code AggregatorImplementer} instead. + */ +public final class TopDoubleLongAggregatorFunction implements AggregatorFunction { + private static final List INTERMEDIATE_STATE_DESC = List.of( + new IntermediateStateDesc("top", ElementType.DOUBLE), + new IntermediateStateDesc("extra", ElementType.LONG) ); + + private final DriverContext driverContext; + + private final TopDoubleLongAggregator.SingleState state; + + private final List channels; + + private final int limit; + + private final boolean ascending; + + public TopDoubleLongAggregatorFunction(DriverContext driverContext, List channels, + TopDoubleLongAggregator.SingleState state, int limit, boolean ascending) { + this.driverContext = driverContext; + this.channels = channels; + this.state = state; + this.limit = limit; + this.ascending = ascending; + } + + public static TopDoubleLongAggregatorFunction create(DriverContext driverContext, + List channels, int limit, boolean ascending) { + return new TopDoubleLongAggregatorFunction(driverContext, channels, TopDoubleLongAggregator.initSingle(driverContext.bigArrays(), limit, ascending), limit, ascending); + } + + public static List intermediateStateDesc() { + return INTERMEDIATE_STATE_DESC; + } + + @Override + public int intermediateBlockCount() { + return INTERMEDIATE_STATE_DESC.size(); + } + + @Override + public void addRawInput(Page page, BooleanVector mask) { + if (mask.allFalse()) { + // Entire page masked away + } else if (mask.allTrue()) { + addRawInputNotMasked(page); + } else { + addRawInputMasked(page, mask); + } + } + + private void addRawInputMasked(Page page, BooleanVector mask) { + DoubleBlock vBlock = page.getBlock(channels.get(0)); + LongBlock extraBlock = page.getBlock(channels.get(1)); + DoubleVector vVector = vBlock.asVector(); + if (vVector == null) { + addRawBlock(vBlock, extraBlock, mask); + return; + } + LongVector extraVector = extraBlock.asVector(); + if (extraVector == null) { + addRawBlock(vBlock, extraBlock, mask); + return; + } + addRawVector(vVector, extraVector, mask); + } + + private void addRawInputNotMasked(Page page) { + DoubleBlock vBlock = page.getBlock(channels.get(0)); + LongBlock extraBlock = page.getBlock(channels.get(1)); + DoubleVector vVector = vBlock.asVector(); + if (vVector == null) { + addRawBlock(vBlock, extraBlock); + return; + } + LongVector extraVector = extraBlock.asVector(); + if (extraVector == null) { + addRawBlock(vBlock, extraBlock); + return; + } + addRawVector(vVector, extraVector); + } + + private void addRawVector(DoubleVector vVector, LongVector extraVector) { + for (int valuesPosition = 0; valuesPosition < vVector.getPositionCount(); valuesPosition++) { + double vValue = vVector.getDouble(valuesPosition); + long extraValue = extraVector.getLong(valuesPosition); + TopDoubleLongAggregator.combine(state, vValue, extraValue); + } + } + + private void addRawVector(DoubleVector vVector, LongVector extraVector, BooleanVector mask) { + for (int valuesPosition = 0; valuesPosition < vVector.getPositionCount(); valuesPosition++) { + if (mask.getBoolean(valuesPosition) == false) { + continue; + } + double vValue = vVector.getDouble(valuesPosition); + long extraValue = extraVector.getLong(valuesPosition); + TopDoubleLongAggregator.combine(state, vValue, extraValue); + } + } + + private void addRawBlock(DoubleBlock vBlock, LongBlock extraBlock) { + for (int p = 0; p < vBlock.getPositionCount(); p++) { + if (vBlock.isNull(p)) { + continue; + } + if (extraBlock.isNull(p)) { + continue; + } + int vStart = vBlock.getFirstValueIndex(p); + int vEnd = vStart + vBlock.getValueCount(p); + for (int vOffset = vStart; vOffset < vEnd; vOffset++) { + double vValue = vBlock.getDouble(vOffset); + int extraStart = extraBlock.getFirstValueIndex(p); + int extraEnd = extraStart + extraBlock.getValueCount(p); + for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { + long extraValue = extraBlock.getLong(extraOffset); + TopDoubleLongAggregator.combine(state, vValue, extraValue); + } + } + } + } + + private void addRawBlock(DoubleBlock vBlock, LongBlock extraBlock, BooleanVector mask) { + for (int p = 0; p < vBlock.getPositionCount(); p++) { + if (mask.getBoolean(p) == false) { + continue; + } + if (vBlock.isNull(p)) { + continue; + } + if (extraBlock.isNull(p)) { + continue; + } + int vStart = vBlock.getFirstValueIndex(p); + int vEnd = vStart + vBlock.getValueCount(p); + for (int vOffset = vStart; vOffset < vEnd; vOffset++) { + double vValue = vBlock.getDouble(vOffset); + int extraStart = extraBlock.getFirstValueIndex(p); + int extraEnd = extraStart + extraBlock.getValueCount(p); + for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { + long extraValue = extraBlock.getLong(extraOffset); + TopDoubleLongAggregator.combine(state, vValue, extraValue); + } + } + } + } + + @Override + public void addIntermediateInput(Page page) { + assert channels.size() == intermediateBlockCount(); + assert page.getBlockCount() >= channels.get(0) + intermediateStateDesc().size(); + Block topUncast = page.getBlock(channels.get(0)); + if (topUncast.areAllValuesNull()) { + return; + } + DoubleBlock top = (DoubleBlock) topUncast; + assert top.getPositionCount() == 1; + Block extraUncast = page.getBlock(channels.get(1)); + if (extraUncast.areAllValuesNull()) { + return; + } + LongBlock extra = (LongBlock) extraUncast; + assert extra.getPositionCount() == 1; + TopDoubleLongAggregator.combineIntermediate(state, top, extra); + } + + @Override + public void evaluateIntermediate(Block[] blocks, int offset, DriverContext driverContext) { + state.toIntermediate(blocks, offset, driverContext); + } + + @Override + public void evaluateFinal(Block[] blocks, int offset, DriverContext driverContext) { + blocks[offset] = TopDoubleLongAggregator.evaluateFinal(state, driverContext); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append(getClass().getSimpleName()).append("["); + sb.append("channels=").append(channels); + sb.append("]"); + return sb.toString(); + } + + @Override + public void close() { + state.close(); + } +} diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleLongAggregatorFunctionSupplier.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleLongAggregatorFunctionSupplier.java new file mode 100644 index 0000000000000..948e23035f622 --- /dev/null +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleLongAggregatorFunctionSupplier.java @@ -0,0 +1,53 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License +// 2.0; you may not use this file except in compliance with the Elastic License +// 2.0. +package org.elasticsearch.compute.aggregation; + +import java.lang.Integer; +import java.lang.Override; +import java.lang.String; +import java.util.List; +import org.elasticsearch.compute.operator.DriverContext; + +/** + * {@link AggregatorFunctionSupplier} implementation for {@link TopDoubleLongAggregator}. + * This class is generated. Edit {@code AggregatorFunctionSupplierImplementer} instead. + */ +public final class TopDoubleLongAggregatorFunctionSupplier implements AggregatorFunctionSupplier { + private final int limit; + + private final boolean ascending; + + public TopDoubleLongAggregatorFunctionSupplier(int limit, boolean ascending) { + this.limit = limit; + this.ascending = ascending; + } + + @Override + public List nonGroupingIntermediateStateDesc() { + return TopDoubleLongAggregatorFunction.intermediateStateDesc(); + } + + @Override + public List groupingIntermediateStateDesc() { + return TopDoubleLongGroupingAggregatorFunction.intermediateStateDesc(); + } + + @Override + public TopDoubleLongAggregatorFunction aggregator(DriverContext driverContext, + List channels) { + return TopDoubleLongAggregatorFunction.create(driverContext, channels, limit, ascending); + } + + @Override + public TopDoubleLongGroupingAggregatorFunction groupingAggregator(DriverContext driverContext, + List channels) { + return TopDoubleLongGroupingAggregatorFunction.create(channels, driverContext, limit, ascending); + } + + @Override + public String describe() { + return "top_double of longs"; + } +} diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleLongGroupingAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleLongGroupingAggregatorFunction.java new file mode 100644 index 0000000000000..685c5172d0788 --- /dev/null +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleLongGroupingAggregatorFunction.java @@ -0,0 +1,397 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License +// 2.0; you may not use this file except in compliance with the Elastic License +// 2.0. +package org.elasticsearch.compute.aggregation; + +import java.lang.Integer; +import java.lang.Override; +import java.lang.String; +import java.lang.StringBuilder; +import java.util.List; +import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.DoubleBlock; +import org.elasticsearch.compute.data.DoubleVector; +import org.elasticsearch.compute.data.ElementType; +import org.elasticsearch.compute.data.IntArrayBlock; +import org.elasticsearch.compute.data.IntBigArrayBlock; +import org.elasticsearch.compute.data.IntVector; +import org.elasticsearch.compute.data.LongBlock; +import org.elasticsearch.compute.data.LongVector; +import org.elasticsearch.compute.data.Page; +import org.elasticsearch.compute.operator.DriverContext; + +/** + * {@link GroupingAggregatorFunction} implementation for {@link TopDoubleLongAggregator}. + * This class is generated. Edit {@code GroupingAggregatorImplementer} instead. + */ +public final class TopDoubleLongGroupingAggregatorFunction implements GroupingAggregatorFunction { + private static final List INTERMEDIATE_STATE_DESC = List.of( + new IntermediateStateDesc("top", ElementType.DOUBLE), + new IntermediateStateDesc("extra", ElementType.LONG) ); + + private final TopDoubleLongAggregator.GroupingState state; + + private final List channels; + + private final DriverContext driverContext; + + private final int limit; + + private final boolean ascending; + + public TopDoubleLongGroupingAggregatorFunction(List channels, + TopDoubleLongAggregator.GroupingState state, DriverContext driverContext, int limit, + boolean ascending) { + this.channels = channels; + this.state = state; + this.driverContext = driverContext; + this.limit = limit; + this.ascending = ascending; + } + + public static TopDoubleLongGroupingAggregatorFunction create(List channels, + DriverContext driverContext, int limit, boolean ascending) { + return new TopDoubleLongGroupingAggregatorFunction(channels, TopDoubleLongAggregator.initGrouping(driverContext.bigArrays(), limit, ascending), driverContext, limit, ascending); + } + + public static List intermediateStateDesc() { + return INTERMEDIATE_STATE_DESC; + } + + @Override + public int intermediateBlockCount() { + return INTERMEDIATE_STATE_DESC.size(); + } + + @Override + public GroupingAggregatorFunction.AddInput prepareProcessRawInputPage(SeenGroupIds seenGroupIds, + Page page) { + DoubleBlock vBlock = page.getBlock(channels.get(0)); + LongBlock extraBlock = page.getBlock(channels.get(1)); + DoubleVector vVector = vBlock.asVector(); + if (vVector == null) { + maybeEnableGroupIdTracking(seenGroupIds, vBlock, extraBlock); + return new GroupingAggregatorFunction.AddInput() { + @Override + public void add(int positionOffset, IntArrayBlock groupIds) { + addRawInput(positionOffset, groupIds, vBlock, extraBlock); + } + + @Override + public void add(int positionOffset, IntBigArrayBlock groupIds) { + addRawInput(positionOffset, groupIds, vBlock, extraBlock); + } + + @Override + public void add(int positionOffset, IntVector groupIds) { + addRawInput(positionOffset, groupIds, vBlock, extraBlock); + } + + @Override + public void close() { + } + }; + } + LongVector extraVector = extraBlock.asVector(); + if (extraVector == null) { + maybeEnableGroupIdTracking(seenGroupIds, vBlock, extraBlock); + return new GroupingAggregatorFunction.AddInput() { + @Override + public void add(int positionOffset, IntArrayBlock groupIds) { + addRawInput(positionOffset, groupIds, vBlock, extraBlock); + } + + @Override + public void add(int positionOffset, IntBigArrayBlock groupIds) { + addRawInput(positionOffset, groupIds, vBlock, extraBlock); + } + + @Override + public void add(int positionOffset, IntVector groupIds) { + addRawInput(positionOffset, groupIds, vBlock, extraBlock); + } + + @Override + public void close() { + } + }; + } + return new GroupingAggregatorFunction.AddInput() { + @Override + public void add(int positionOffset, IntArrayBlock groupIds) { + addRawInput(positionOffset, groupIds, vVector, extraVector); + } + + @Override + public void add(int positionOffset, IntBigArrayBlock groupIds) { + addRawInput(positionOffset, groupIds, vVector, extraVector); + } + + @Override + public void add(int positionOffset, IntVector groupIds) { + addRawInput(positionOffset, groupIds, vVector, extraVector); + } + + @Override + public void close() { + } + }; + } + + private void addRawInput(int positionOffset, IntArrayBlock groups, DoubleBlock vBlock, + LongBlock extraBlock) { + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + if (groups.isNull(groupPosition)) { + continue; + } + int valuesPosition = groupPosition + positionOffset; + if (vBlock.isNull(valuesPosition)) { + continue; + } + if (extraBlock.isNull(valuesPosition)) { + continue; + } + int groupStart = groups.getFirstValueIndex(groupPosition); + int groupEnd = groupStart + groups.getValueCount(groupPosition); + for (int g = groupStart; g < groupEnd; g++) { + int groupId = groups.getInt(g); + int vStart = vBlock.getFirstValueIndex(valuesPosition); + int vEnd = vStart + vBlock.getValueCount(valuesPosition); + for (int vOffset = vStart; vOffset < vEnd; vOffset++) { + double vValue = vBlock.getDouble(vOffset); + int extraStart = extraBlock.getFirstValueIndex(valuesPosition); + int extraEnd = extraStart + extraBlock.getValueCount(valuesPosition); + for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { + long extraValue = extraBlock.getLong(extraOffset); + TopDoubleLongAggregator.combine(state, groupId, vValue, extraValue); + } + } + } + } + } + + private void addRawInput(int positionOffset, IntArrayBlock groups, DoubleVector vVector, + LongVector extraVector) { + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + if (groups.isNull(groupPosition)) { + continue; + } + int valuesPosition = groupPosition + positionOffset; + int groupStart = groups.getFirstValueIndex(groupPosition); + int groupEnd = groupStart + groups.getValueCount(groupPosition); + for (int g = groupStart; g < groupEnd; g++) { + int groupId = groups.getInt(g); + double vValue = vVector.getDouble(valuesPosition); + long extraValue = extraVector.getLong(valuesPosition); + TopDoubleLongAggregator.combine(state, groupId, vValue, extraValue); + } + } + } + + @Override + public void addIntermediateInput(int positionOffset, IntArrayBlock groups, Page page) { + state.enableGroupIdTracking(new SeenGroupIds.Empty()); + assert channels.size() == intermediateBlockCount(); + Block topUncast = page.getBlock(channels.get(0)); + if (topUncast.areAllValuesNull()) { + return; + } + DoubleBlock top = (DoubleBlock) topUncast; + Block extraUncast = page.getBlock(channels.get(1)); + if (extraUncast.areAllValuesNull()) { + return; + } + LongBlock extra = (LongBlock) extraUncast; + assert top.getPositionCount() == extra.getPositionCount(); + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + if (groups.isNull(groupPosition)) { + continue; + } + int groupStart = groups.getFirstValueIndex(groupPosition); + int groupEnd = groupStart + groups.getValueCount(groupPosition); + for (int g = groupStart; g < groupEnd; g++) { + int groupId = groups.getInt(g); + int valuesPosition = groupPosition + positionOffset; + TopDoubleLongAggregator.combineIntermediate(state, groupId, top, extra, valuesPosition); + } + } + } + + private void addRawInput(int positionOffset, IntBigArrayBlock groups, DoubleBlock vBlock, + LongBlock extraBlock) { + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + if (groups.isNull(groupPosition)) { + continue; + } + int valuesPosition = groupPosition + positionOffset; + if (vBlock.isNull(valuesPosition)) { + continue; + } + if (extraBlock.isNull(valuesPosition)) { + continue; + } + int groupStart = groups.getFirstValueIndex(groupPosition); + int groupEnd = groupStart + groups.getValueCount(groupPosition); + for (int g = groupStart; g < groupEnd; g++) { + int groupId = groups.getInt(g); + int vStart = vBlock.getFirstValueIndex(valuesPosition); + int vEnd = vStart + vBlock.getValueCount(valuesPosition); + for (int vOffset = vStart; vOffset < vEnd; vOffset++) { + double vValue = vBlock.getDouble(vOffset); + int extraStart = extraBlock.getFirstValueIndex(valuesPosition); + int extraEnd = extraStart + extraBlock.getValueCount(valuesPosition); + for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { + long extraValue = extraBlock.getLong(extraOffset); + TopDoubleLongAggregator.combine(state, groupId, vValue, extraValue); + } + } + } + } + } + + private void addRawInput(int positionOffset, IntBigArrayBlock groups, DoubleVector vVector, + LongVector extraVector) { + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + if (groups.isNull(groupPosition)) { + continue; + } + int valuesPosition = groupPosition + positionOffset; + int groupStart = groups.getFirstValueIndex(groupPosition); + int groupEnd = groupStart + groups.getValueCount(groupPosition); + for (int g = groupStart; g < groupEnd; g++) { + int groupId = groups.getInt(g); + double vValue = vVector.getDouble(valuesPosition); + long extraValue = extraVector.getLong(valuesPosition); + TopDoubleLongAggregator.combine(state, groupId, vValue, extraValue); + } + } + } + + @Override + public void addIntermediateInput(int positionOffset, IntBigArrayBlock groups, Page page) { + state.enableGroupIdTracking(new SeenGroupIds.Empty()); + assert channels.size() == intermediateBlockCount(); + Block topUncast = page.getBlock(channels.get(0)); + if (topUncast.areAllValuesNull()) { + return; + } + DoubleBlock top = (DoubleBlock) topUncast; + Block extraUncast = page.getBlock(channels.get(1)); + if (extraUncast.areAllValuesNull()) { + return; + } + LongBlock extra = (LongBlock) extraUncast; + assert top.getPositionCount() == extra.getPositionCount(); + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + if (groups.isNull(groupPosition)) { + continue; + } + int groupStart = groups.getFirstValueIndex(groupPosition); + int groupEnd = groupStart + groups.getValueCount(groupPosition); + for (int g = groupStart; g < groupEnd; g++) { + int groupId = groups.getInt(g); + int valuesPosition = groupPosition + positionOffset; + TopDoubleLongAggregator.combineIntermediate(state, groupId, top, extra, valuesPosition); + } + } + } + + private void addRawInput(int positionOffset, IntVector groups, DoubleBlock vBlock, + LongBlock extraBlock) { + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + int valuesPosition = groupPosition + positionOffset; + if (vBlock.isNull(valuesPosition)) { + continue; + } + if (extraBlock.isNull(valuesPosition)) { + continue; + } + int groupId = groups.getInt(groupPosition); + int vStart = vBlock.getFirstValueIndex(valuesPosition); + int vEnd = vStart + vBlock.getValueCount(valuesPosition); + for (int vOffset = vStart; vOffset < vEnd; vOffset++) { + double vValue = vBlock.getDouble(vOffset); + int extraStart = extraBlock.getFirstValueIndex(valuesPosition); + int extraEnd = extraStart + extraBlock.getValueCount(valuesPosition); + for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { + long extraValue = extraBlock.getLong(extraOffset); + TopDoubleLongAggregator.combine(state, groupId, vValue, extraValue); + } + } + } + } + + private void addRawInput(int positionOffset, IntVector groups, DoubleVector vVector, + LongVector extraVector) { + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + int valuesPosition = groupPosition + positionOffset; + int groupId = groups.getInt(groupPosition); + double vValue = vVector.getDouble(valuesPosition); + long extraValue = extraVector.getLong(valuesPosition); + TopDoubleLongAggregator.combine(state, groupId, vValue, extraValue); + } + } + + @Override + public void addIntermediateInput(int positionOffset, IntVector groups, Page page) { + state.enableGroupIdTracking(new SeenGroupIds.Empty()); + assert channels.size() == intermediateBlockCount(); + Block topUncast = page.getBlock(channels.get(0)); + if (topUncast.areAllValuesNull()) { + return; + } + DoubleBlock top = (DoubleBlock) topUncast; + Block extraUncast = page.getBlock(channels.get(1)); + if (extraUncast.areAllValuesNull()) { + return; + } + LongBlock extra = (LongBlock) extraUncast; + assert top.getPositionCount() == extra.getPositionCount(); + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + int groupId = groups.getInt(groupPosition); + int valuesPosition = groupPosition + positionOffset; + TopDoubleLongAggregator.combineIntermediate(state, groupId, top, extra, valuesPosition); + } + } + + private void maybeEnableGroupIdTracking(SeenGroupIds seenGroupIds, DoubleBlock vBlock, + LongBlock extraBlock) { + if (vBlock.mayHaveNulls()) { + state.enableGroupIdTracking(seenGroupIds); + } + if (extraBlock.mayHaveNulls()) { + state.enableGroupIdTracking(seenGroupIds); + } + } + + @Override + public void selectedMayContainUnseenGroups(SeenGroupIds seenGroupIds) { + state.enableGroupIdTracking(seenGroupIds); + } + + @Override + public void evaluateIntermediate(Block[] blocks, int offset, IntVector selected) { + state.toIntermediate(blocks, offset, selected, driverContext); + } + + @Override + public void evaluateFinal(Block[] blocks, int offset, IntVector selected, + GroupingAggregatorEvaluationContext ctx) { + blocks[offset] = TopDoubleLongAggregator.evaluateFinal(state, selected, ctx); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append(getClass().getSimpleName()).append("["); + sb.append("channels=").append(channels); + sb.append("]"); + return sb.toString(); + } + + @Override + public void close() { + state.close(); + } +} diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatDoubleAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatDoubleAggregatorFunction.java new file mode 100644 index 0000000000000..7de2b10e4938e --- /dev/null +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatDoubleAggregatorFunction.java @@ -0,0 +1,215 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License +// 2.0; you may not use this file except in compliance with the Elastic License +// 2.0. +package org.elasticsearch.compute.aggregation; + +import java.lang.Integer; +import java.lang.Override; +import java.lang.String; +import java.lang.StringBuilder; +import java.util.List; +import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.BooleanVector; +import org.elasticsearch.compute.data.DoubleBlock; +import org.elasticsearch.compute.data.DoubleVector; +import org.elasticsearch.compute.data.ElementType; +import org.elasticsearch.compute.data.FloatBlock; +import org.elasticsearch.compute.data.FloatVector; +import org.elasticsearch.compute.data.Page; +import org.elasticsearch.compute.operator.DriverContext; + +/** + * {@link AggregatorFunction} implementation for {@link TopFloatDoubleAggregator}. + * This class is generated. Edit {@code AggregatorImplementer} instead. + */ +public final class TopFloatDoubleAggregatorFunction implements AggregatorFunction { + private static final List INTERMEDIATE_STATE_DESC = List.of( + new IntermediateStateDesc("top", ElementType.FLOAT), + new IntermediateStateDesc("extra", ElementType.DOUBLE) ); + + private final DriverContext driverContext; + + private final TopFloatDoubleAggregator.SingleState state; + + private final List channels; + + private final int limit; + + private final boolean ascending; + + public TopFloatDoubleAggregatorFunction(DriverContext driverContext, List channels, + TopFloatDoubleAggregator.SingleState state, int limit, boolean ascending) { + this.driverContext = driverContext; + this.channels = channels; + this.state = state; + this.limit = limit; + this.ascending = ascending; + } + + public static TopFloatDoubleAggregatorFunction create(DriverContext driverContext, + List channels, int limit, boolean ascending) { + return new TopFloatDoubleAggregatorFunction(driverContext, channels, TopFloatDoubleAggregator.initSingle(driverContext.bigArrays(), limit, ascending), limit, ascending); + } + + public static List intermediateStateDesc() { + return INTERMEDIATE_STATE_DESC; + } + + @Override + public int intermediateBlockCount() { + return INTERMEDIATE_STATE_DESC.size(); + } + + @Override + public void addRawInput(Page page, BooleanVector mask) { + if (mask.allFalse()) { + // Entire page masked away + } else if (mask.allTrue()) { + addRawInputNotMasked(page); + } else { + addRawInputMasked(page, mask); + } + } + + private void addRawInputMasked(Page page, BooleanVector mask) { + FloatBlock vBlock = page.getBlock(channels.get(0)); + DoubleBlock extraBlock = page.getBlock(channels.get(1)); + FloatVector vVector = vBlock.asVector(); + if (vVector == null) { + addRawBlock(vBlock, extraBlock, mask); + return; + } + DoubleVector extraVector = extraBlock.asVector(); + if (extraVector == null) { + addRawBlock(vBlock, extraBlock, mask); + return; + } + addRawVector(vVector, extraVector, mask); + } + + private void addRawInputNotMasked(Page page) { + FloatBlock vBlock = page.getBlock(channels.get(0)); + DoubleBlock extraBlock = page.getBlock(channels.get(1)); + FloatVector vVector = vBlock.asVector(); + if (vVector == null) { + addRawBlock(vBlock, extraBlock); + return; + } + DoubleVector extraVector = extraBlock.asVector(); + if (extraVector == null) { + addRawBlock(vBlock, extraBlock); + return; + } + addRawVector(vVector, extraVector); + } + + private void addRawVector(FloatVector vVector, DoubleVector extraVector) { + for (int valuesPosition = 0; valuesPosition < vVector.getPositionCount(); valuesPosition++) { + float vValue = vVector.getFloat(valuesPosition); + double extraValue = extraVector.getDouble(valuesPosition); + TopFloatDoubleAggregator.combine(state, vValue, extraValue); + } + } + + private void addRawVector(FloatVector vVector, DoubleVector extraVector, BooleanVector mask) { + for (int valuesPosition = 0; valuesPosition < vVector.getPositionCount(); valuesPosition++) { + if (mask.getBoolean(valuesPosition) == false) { + continue; + } + float vValue = vVector.getFloat(valuesPosition); + double extraValue = extraVector.getDouble(valuesPosition); + TopFloatDoubleAggregator.combine(state, vValue, extraValue); + } + } + + private void addRawBlock(FloatBlock vBlock, DoubleBlock extraBlock) { + for (int p = 0; p < vBlock.getPositionCount(); p++) { + if (vBlock.isNull(p)) { + continue; + } + if (extraBlock.isNull(p)) { + continue; + } + int vStart = vBlock.getFirstValueIndex(p); + int vEnd = vStart + vBlock.getValueCount(p); + for (int vOffset = vStart; vOffset < vEnd; vOffset++) { + float vValue = vBlock.getFloat(vOffset); + int extraStart = extraBlock.getFirstValueIndex(p); + int extraEnd = extraStart + extraBlock.getValueCount(p); + for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { + double extraValue = extraBlock.getDouble(extraOffset); + TopFloatDoubleAggregator.combine(state, vValue, extraValue); + } + } + } + } + + private void addRawBlock(FloatBlock vBlock, DoubleBlock extraBlock, BooleanVector mask) { + for (int p = 0; p < vBlock.getPositionCount(); p++) { + if (mask.getBoolean(p) == false) { + continue; + } + if (vBlock.isNull(p)) { + continue; + } + if (extraBlock.isNull(p)) { + continue; + } + int vStart = vBlock.getFirstValueIndex(p); + int vEnd = vStart + vBlock.getValueCount(p); + for (int vOffset = vStart; vOffset < vEnd; vOffset++) { + float vValue = vBlock.getFloat(vOffset); + int extraStart = extraBlock.getFirstValueIndex(p); + int extraEnd = extraStart + extraBlock.getValueCount(p); + for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { + double extraValue = extraBlock.getDouble(extraOffset); + TopFloatDoubleAggregator.combine(state, vValue, extraValue); + } + } + } + } + + @Override + public void addIntermediateInput(Page page) { + assert channels.size() == intermediateBlockCount(); + assert page.getBlockCount() >= channels.get(0) + intermediateStateDesc().size(); + Block topUncast = page.getBlock(channels.get(0)); + if (topUncast.areAllValuesNull()) { + return; + } + FloatBlock top = (FloatBlock) topUncast; + assert top.getPositionCount() == 1; + Block extraUncast = page.getBlock(channels.get(1)); + if (extraUncast.areAllValuesNull()) { + return; + } + DoubleBlock extra = (DoubleBlock) extraUncast; + assert extra.getPositionCount() == 1; + TopFloatDoubleAggregator.combineIntermediate(state, top, extra); + } + + @Override + public void evaluateIntermediate(Block[] blocks, int offset, DriverContext driverContext) { + state.toIntermediate(blocks, offset, driverContext); + } + + @Override + public void evaluateFinal(Block[] blocks, int offset, DriverContext driverContext) { + blocks[offset] = TopFloatDoubleAggregator.evaluateFinal(state, driverContext); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append(getClass().getSimpleName()).append("["); + sb.append("channels=").append(channels); + sb.append("]"); + return sb.toString(); + } + + @Override + public void close() { + state.close(); + } +} diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatDoubleAggregatorFunctionSupplier.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatDoubleAggregatorFunctionSupplier.java new file mode 100644 index 0000000000000..913f2087b2562 --- /dev/null +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatDoubleAggregatorFunctionSupplier.java @@ -0,0 +1,53 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License +// 2.0; you may not use this file except in compliance with the Elastic License +// 2.0. +package org.elasticsearch.compute.aggregation; + +import java.lang.Integer; +import java.lang.Override; +import java.lang.String; +import java.util.List; +import org.elasticsearch.compute.operator.DriverContext; + +/** + * {@link AggregatorFunctionSupplier} implementation for {@link TopFloatDoubleAggregator}. + * This class is generated. Edit {@code AggregatorFunctionSupplierImplementer} instead. + */ +public final class TopFloatDoubleAggregatorFunctionSupplier implements AggregatorFunctionSupplier { + private final int limit; + + private final boolean ascending; + + public TopFloatDoubleAggregatorFunctionSupplier(int limit, boolean ascending) { + this.limit = limit; + this.ascending = ascending; + } + + @Override + public List nonGroupingIntermediateStateDesc() { + return TopFloatDoubleAggregatorFunction.intermediateStateDesc(); + } + + @Override + public List groupingIntermediateStateDesc() { + return TopFloatDoubleGroupingAggregatorFunction.intermediateStateDesc(); + } + + @Override + public TopFloatDoubleAggregatorFunction aggregator(DriverContext driverContext, + List channels) { + return TopFloatDoubleAggregatorFunction.create(driverContext, channels, limit, ascending); + } + + @Override + public TopFloatDoubleGroupingAggregatorFunction groupingAggregator(DriverContext driverContext, + List channels) { + return TopFloatDoubleGroupingAggregatorFunction.create(channels, driverContext, limit, ascending); + } + + @Override + public String describe() { + return "top_float of doubles"; + } +} diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatDoubleGroupingAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatDoubleGroupingAggregatorFunction.java new file mode 100644 index 0000000000000..11d8bbe9c6ff2 --- /dev/null +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatDoubleGroupingAggregatorFunction.java @@ -0,0 +1,397 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License +// 2.0; you may not use this file except in compliance with the Elastic License +// 2.0. +package org.elasticsearch.compute.aggregation; + +import java.lang.Integer; +import java.lang.Override; +import java.lang.String; +import java.lang.StringBuilder; +import java.util.List; +import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.DoubleBlock; +import org.elasticsearch.compute.data.DoubleVector; +import org.elasticsearch.compute.data.ElementType; +import org.elasticsearch.compute.data.FloatBlock; +import org.elasticsearch.compute.data.FloatVector; +import org.elasticsearch.compute.data.IntArrayBlock; +import org.elasticsearch.compute.data.IntBigArrayBlock; +import org.elasticsearch.compute.data.IntVector; +import org.elasticsearch.compute.data.Page; +import org.elasticsearch.compute.operator.DriverContext; + +/** + * {@link GroupingAggregatorFunction} implementation for {@link TopFloatDoubleAggregator}. + * This class is generated. Edit {@code GroupingAggregatorImplementer} instead. + */ +public final class TopFloatDoubleGroupingAggregatorFunction implements GroupingAggregatorFunction { + private static final List INTERMEDIATE_STATE_DESC = List.of( + new IntermediateStateDesc("top", ElementType.FLOAT), + new IntermediateStateDesc("extra", ElementType.DOUBLE) ); + + private final TopFloatDoubleAggregator.GroupingState state; + + private final List channels; + + private final DriverContext driverContext; + + private final int limit; + + private final boolean ascending; + + public TopFloatDoubleGroupingAggregatorFunction(List channels, + TopFloatDoubleAggregator.GroupingState state, DriverContext driverContext, int limit, + boolean ascending) { + this.channels = channels; + this.state = state; + this.driverContext = driverContext; + this.limit = limit; + this.ascending = ascending; + } + + public static TopFloatDoubleGroupingAggregatorFunction create(List channels, + DriverContext driverContext, int limit, boolean ascending) { + return new TopFloatDoubleGroupingAggregatorFunction(channels, TopFloatDoubleAggregator.initGrouping(driverContext.bigArrays(), limit, ascending), driverContext, limit, ascending); + } + + public static List intermediateStateDesc() { + return INTERMEDIATE_STATE_DESC; + } + + @Override + public int intermediateBlockCount() { + return INTERMEDIATE_STATE_DESC.size(); + } + + @Override + public GroupingAggregatorFunction.AddInput prepareProcessRawInputPage(SeenGroupIds seenGroupIds, + Page page) { + FloatBlock vBlock = page.getBlock(channels.get(0)); + DoubleBlock extraBlock = page.getBlock(channels.get(1)); + FloatVector vVector = vBlock.asVector(); + if (vVector == null) { + maybeEnableGroupIdTracking(seenGroupIds, vBlock, extraBlock); + return new GroupingAggregatorFunction.AddInput() { + @Override + public void add(int positionOffset, IntArrayBlock groupIds) { + addRawInput(positionOffset, groupIds, vBlock, extraBlock); + } + + @Override + public void add(int positionOffset, IntBigArrayBlock groupIds) { + addRawInput(positionOffset, groupIds, vBlock, extraBlock); + } + + @Override + public void add(int positionOffset, IntVector groupIds) { + addRawInput(positionOffset, groupIds, vBlock, extraBlock); + } + + @Override + public void close() { + } + }; + } + DoubleVector extraVector = extraBlock.asVector(); + if (extraVector == null) { + maybeEnableGroupIdTracking(seenGroupIds, vBlock, extraBlock); + return new GroupingAggregatorFunction.AddInput() { + @Override + public void add(int positionOffset, IntArrayBlock groupIds) { + addRawInput(positionOffset, groupIds, vBlock, extraBlock); + } + + @Override + public void add(int positionOffset, IntBigArrayBlock groupIds) { + addRawInput(positionOffset, groupIds, vBlock, extraBlock); + } + + @Override + public void add(int positionOffset, IntVector groupIds) { + addRawInput(positionOffset, groupIds, vBlock, extraBlock); + } + + @Override + public void close() { + } + }; + } + return new GroupingAggregatorFunction.AddInput() { + @Override + public void add(int positionOffset, IntArrayBlock groupIds) { + addRawInput(positionOffset, groupIds, vVector, extraVector); + } + + @Override + public void add(int positionOffset, IntBigArrayBlock groupIds) { + addRawInput(positionOffset, groupIds, vVector, extraVector); + } + + @Override + public void add(int positionOffset, IntVector groupIds) { + addRawInput(positionOffset, groupIds, vVector, extraVector); + } + + @Override + public void close() { + } + }; + } + + private void addRawInput(int positionOffset, IntArrayBlock groups, FloatBlock vBlock, + DoubleBlock extraBlock) { + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + if (groups.isNull(groupPosition)) { + continue; + } + int valuesPosition = groupPosition + positionOffset; + if (vBlock.isNull(valuesPosition)) { + continue; + } + if (extraBlock.isNull(valuesPosition)) { + continue; + } + int groupStart = groups.getFirstValueIndex(groupPosition); + int groupEnd = groupStart + groups.getValueCount(groupPosition); + for (int g = groupStart; g < groupEnd; g++) { + int groupId = groups.getInt(g); + int vStart = vBlock.getFirstValueIndex(valuesPosition); + int vEnd = vStart + vBlock.getValueCount(valuesPosition); + for (int vOffset = vStart; vOffset < vEnd; vOffset++) { + float vValue = vBlock.getFloat(vOffset); + int extraStart = extraBlock.getFirstValueIndex(valuesPosition); + int extraEnd = extraStart + extraBlock.getValueCount(valuesPosition); + for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { + double extraValue = extraBlock.getDouble(extraOffset); + TopFloatDoubleAggregator.combine(state, groupId, vValue, extraValue); + } + } + } + } + } + + private void addRawInput(int positionOffset, IntArrayBlock groups, FloatVector vVector, + DoubleVector extraVector) { + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + if (groups.isNull(groupPosition)) { + continue; + } + int valuesPosition = groupPosition + positionOffset; + int groupStart = groups.getFirstValueIndex(groupPosition); + int groupEnd = groupStart + groups.getValueCount(groupPosition); + for (int g = groupStart; g < groupEnd; g++) { + int groupId = groups.getInt(g); + float vValue = vVector.getFloat(valuesPosition); + double extraValue = extraVector.getDouble(valuesPosition); + TopFloatDoubleAggregator.combine(state, groupId, vValue, extraValue); + } + } + } + + @Override + public void addIntermediateInput(int positionOffset, IntArrayBlock groups, Page page) { + state.enableGroupIdTracking(new SeenGroupIds.Empty()); + assert channels.size() == intermediateBlockCount(); + Block topUncast = page.getBlock(channels.get(0)); + if (topUncast.areAllValuesNull()) { + return; + } + FloatBlock top = (FloatBlock) topUncast; + Block extraUncast = page.getBlock(channels.get(1)); + if (extraUncast.areAllValuesNull()) { + return; + } + DoubleBlock extra = (DoubleBlock) extraUncast; + assert top.getPositionCount() == extra.getPositionCount(); + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + if (groups.isNull(groupPosition)) { + continue; + } + int groupStart = groups.getFirstValueIndex(groupPosition); + int groupEnd = groupStart + groups.getValueCount(groupPosition); + for (int g = groupStart; g < groupEnd; g++) { + int groupId = groups.getInt(g); + int valuesPosition = groupPosition + positionOffset; + TopFloatDoubleAggregator.combineIntermediate(state, groupId, top, extra, valuesPosition); + } + } + } + + private void addRawInput(int positionOffset, IntBigArrayBlock groups, FloatBlock vBlock, + DoubleBlock extraBlock) { + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + if (groups.isNull(groupPosition)) { + continue; + } + int valuesPosition = groupPosition + positionOffset; + if (vBlock.isNull(valuesPosition)) { + continue; + } + if (extraBlock.isNull(valuesPosition)) { + continue; + } + int groupStart = groups.getFirstValueIndex(groupPosition); + int groupEnd = groupStart + groups.getValueCount(groupPosition); + for (int g = groupStart; g < groupEnd; g++) { + int groupId = groups.getInt(g); + int vStart = vBlock.getFirstValueIndex(valuesPosition); + int vEnd = vStart + vBlock.getValueCount(valuesPosition); + for (int vOffset = vStart; vOffset < vEnd; vOffset++) { + float vValue = vBlock.getFloat(vOffset); + int extraStart = extraBlock.getFirstValueIndex(valuesPosition); + int extraEnd = extraStart + extraBlock.getValueCount(valuesPosition); + for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { + double extraValue = extraBlock.getDouble(extraOffset); + TopFloatDoubleAggregator.combine(state, groupId, vValue, extraValue); + } + } + } + } + } + + private void addRawInput(int positionOffset, IntBigArrayBlock groups, FloatVector vVector, + DoubleVector extraVector) { + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + if (groups.isNull(groupPosition)) { + continue; + } + int valuesPosition = groupPosition + positionOffset; + int groupStart = groups.getFirstValueIndex(groupPosition); + int groupEnd = groupStart + groups.getValueCount(groupPosition); + for (int g = groupStart; g < groupEnd; g++) { + int groupId = groups.getInt(g); + float vValue = vVector.getFloat(valuesPosition); + double extraValue = extraVector.getDouble(valuesPosition); + TopFloatDoubleAggregator.combine(state, groupId, vValue, extraValue); + } + } + } + + @Override + public void addIntermediateInput(int positionOffset, IntBigArrayBlock groups, Page page) { + state.enableGroupIdTracking(new SeenGroupIds.Empty()); + assert channels.size() == intermediateBlockCount(); + Block topUncast = page.getBlock(channels.get(0)); + if (topUncast.areAllValuesNull()) { + return; + } + FloatBlock top = (FloatBlock) topUncast; + Block extraUncast = page.getBlock(channels.get(1)); + if (extraUncast.areAllValuesNull()) { + return; + } + DoubleBlock extra = (DoubleBlock) extraUncast; + assert top.getPositionCount() == extra.getPositionCount(); + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + if (groups.isNull(groupPosition)) { + continue; + } + int groupStart = groups.getFirstValueIndex(groupPosition); + int groupEnd = groupStart + groups.getValueCount(groupPosition); + for (int g = groupStart; g < groupEnd; g++) { + int groupId = groups.getInt(g); + int valuesPosition = groupPosition + positionOffset; + TopFloatDoubleAggregator.combineIntermediate(state, groupId, top, extra, valuesPosition); + } + } + } + + private void addRawInput(int positionOffset, IntVector groups, FloatBlock vBlock, + DoubleBlock extraBlock) { + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + int valuesPosition = groupPosition + positionOffset; + if (vBlock.isNull(valuesPosition)) { + continue; + } + if (extraBlock.isNull(valuesPosition)) { + continue; + } + int groupId = groups.getInt(groupPosition); + int vStart = vBlock.getFirstValueIndex(valuesPosition); + int vEnd = vStart + vBlock.getValueCount(valuesPosition); + for (int vOffset = vStart; vOffset < vEnd; vOffset++) { + float vValue = vBlock.getFloat(vOffset); + int extraStart = extraBlock.getFirstValueIndex(valuesPosition); + int extraEnd = extraStart + extraBlock.getValueCount(valuesPosition); + for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { + double extraValue = extraBlock.getDouble(extraOffset); + TopFloatDoubleAggregator.combine(state, groupId, vValue, extraValue); + } + } + } + } + + private void addRawInput(int positionOffset, IntVector groups, FloatVector vVector, + DoubleVector extraVector) { + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + int valuesPosition = groupPosition + positionOffset; + int groupId = groups.getInt(groupPosition); + float vValue = vVector.getFloat(valuesPosition); + double extraValue = extraVector.getDouble(valuesPosition); + TopFloatDoubleAggregator.combine(state, groupId, vValue, extraValue); + } + } + + @Override + public void addIntermediateInput(int positionOffset, IntVector groups, Page page) { + state.enableGroupIdTracking(new SeenGroupIds.Empty()); + assert channels.size() == intermediateBlockCount(); + Block topUncast = page.getBlock(channels.get(0)); + if (topUncast.areAllValuesNull()) { + return; + } + FloatBlock top = (FloatBlock) topUncast; + Block extraUncast = page.getBlock(channels.get(1)); + if (extraUncast.areAllValuesNull()) { + return; + } + DoubleBlock extra = (DoubleBlock) extraUncast; + assert top.getPositionCount() == extra.getPositionCount(); + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + int groupId = groups.getInt(groupPosition); + int valuesPosition = groupPosition + positionOffset; + TopFloatDoubleAggregator.combineIntermediate(state, groupId, top, extra, valuesPosition); + } + } + + private void maybeEnableGroupIdTracking(SeenGroupIds seenGroupIds, FloatBlock vBlock, + DoubleBlock extraBlock) { + if (vBlock.mayHaveNulls()) { + state.enableGroupIdTracking(seenGroupIds); + } + if (extraBlock.mayHaveNulls()) { + state.enableGroupIdTracking(seenGroupIds); + } + } + + @Override + public void selectedMayContainUnseenGroups(SeenGroupIds seenGroupIds) { + state.enableGroupIdTracking(seenGroupIds); + } + + @Override + public void evaluateIntermediate(Block[] blocks, int offset, IntVector selected) { + state.toIntermediate(blocks, offset, selected, driverContext); + } + + @Override + public void evaluateFinal(Block[] blocks, int offset, IntVector selected, + GroupingAggregatorEvaluationContext ctx) { + blocks[offset] = TopFloatDoubleAggregator.evaluateFinal(state, selected, ctx); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append(getClass().getSimpleName()).append("["); + sb.append("channels=").append(channels); + sb.append("]"); + return sb.toString(); + } + + @Override + public void close() { + state.close(); + } +} diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatFloatAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatFloatAggregatorFunction.java new file mode 100644 index 0000000000000..0d5d4cf441d14 --- /dev/null +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatFloatAggregatorFunction.java @@ -0,0 +1,213 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License +// 2.0; you may not use this file except in compliance with the Elastic License +// 2.0. +package org.elasticsearch.compute.aggregation; + +import java.lang.Integer; +import java.lang.Override; +import java.lang.String; +import java.lang.StringBuilder; +import java.util.List; +import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.BooleanVector; +import org.elasticsearch.compute.data.ElementType; +import org.elasticsearch.compute.data.FloatBlock; +import org.elasticsearch.compute.data.FloatVector; +import org.elasticsearch.compute.data.Page; +import org.elasticsearch.compute.operator.DriverContext; + +/** + * {@link AggregatorFunction} implementation for {@link TopFloatFloatAggregator}. + * This class is generated. Edit {@code AggregatorImplementer} instead. + */ +public final class TopFloatFloatAggregatorFunction implements AggregatorFunction { + private static final List INTERMEDIATE_STATE_DESC = List.of( + new IntermediateStateDesc("top", ElementType.FLOAT), + new IntermediateStateDesc("extra", ElementType.FLOAT) ); + + private final DriverContext driverContext; + + private final TopFloatFloatAggregator.SingleState state; + + private final List channels; + + private final int limit; + + private final boolean ascending; + + public TopFloatFloatAggregatorFunction(DriverContext driverContext, List channels, + TopFloatFloatAggregator.SingleState state, int limit, boolean ascending) { + this.driverContext = driverContext; + this.channels = channels; + this.state = state; + this.limit = limit; + this.ascending = ascending; + } + + public static TopFloatFloatAggregatorFunction create(DriverContext driverContext, + List channels, int limit, boolean ascending) { + return new TopFloatFloatAggregatorFunction(driverContext, channels, TopFloatFloatAggregator.initSingle(driverContext.bigArrays(), limit, ascending), limit, ascending); + } + + public static List intermediateStateDesc() { + return INTERMEDIATE_STATE_DESC; + } + + @Override + public int intermediateBlockCount() { + return INTERMEDIATE_STATE_DESC.size(); + } + + @Override + public void addRawInput(Page page, BooleanVector mask) { + if (mask.allFalse()) { + // Entire page masked away + } else if (mask.allTrue()) { + addRawInputNotMasked(page); + } else { + addRawInputMasked(page, mask); + } + } + + private void addRawInputMasked(Page page, BooleanVector mask) { + FloatBlock vBlock = page.getBlock(channels.get(0)); + FloatBlock extraBlock = page.getBlock(channels.get(1)); + FloatVector vVector = vBlock.asVector(); + if (vVector == null) { + addRawBlock(vBlock, extraBlock, mask); + return; + } + FloatVector extraVector = extraBlock.asVector(); + if (extraVector == null) { + addRawBlock(vBlock, extraBlock, mask); + return; + } + addRawVector(vVector, extraVector, mask); + } + + private void addRawInputNotMasked(Page page) { + FloatBlock vBlock = page.getBlock(channels.get(0)); + FloatBlock extraBlock = page.getBlock(channels.get(1)); + FloatVector vVector = vBlock.asVector(); + if (vVector == null) { + addRawBlock(vBlock, extraBlock); + return; + } + FloatVector extraVector = extraBlock.asVector(); + if (extraVector == null) { + addRawBlock(vBlock, extraBlock); + return; + } + addRawVector(vVector, extraVector); + } + + private void addRawVector(FloatVector vVector, FloatVector extraVector) { + for (int valuesPosition = 0; valuesPosition < vVector.getPositionCount(); valuesPosition++) { + float vValue = vVector.getFloat(valuesPosition); + float extraValue = extraVector.getFloat(valuesPosition); + TopFloatFloatAggregator.combine(state, vValue, extraValue); + } + } + + private void addRawVector(FloatVector vVector, FloatVector extraVector, BooleanVector mask) { + for (int valuesPosition = 0; valuesPosition < vVector.getPositionCount(); valuesPosition++) { + if (mask.getBoolean(valuesPosition) == false) { + continue; + } + float vValue = vVector.getFloat(valuesPosition); + float extraValue = extraVector.getFloat(valuesPosition); + TopFloatFloatAggregator.combine(state, vValue, extraValue); + } + } + + private void addRawBlock(FloatBlock vBlock, FloatBlock extraBlock) { + for (int p = 0; p < vBlock.getPositionCount(); p++) { + if (vBlock.isNull(p)) { + continue; + } + if (extraBlock.isNull(p)) { + continue; + } + int vStart = vBlock.getFirstValueIndex(p); + int vEnd = vStart + vBlock.getValueCount(p); + for (int vOffset = vStart; vOffset < vEnd; vOffset++) { + float vValue = vBlock.getFloat(vOffset); + int extraStart = extraBlock.getFirstValueIndex(p); + int extraEnd = extraStart + extraBlock.getValueCount(p); + for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { + float extraValue = extraBlock.getFloat(extraOffset); + TopFloatFloatAggregator.combine(state, vValue, extraValue); + } + } + } + } + + private void addRawBlock(FloatBlock vBlock, FloatBlock extraBlock, BooleanVector mask) { + for (int p = 0; p < vBlock.getPositionCount(); p++) { + if (mask.getBoolean(p) == false) { + continue; + } + if (vBlock.isNull(p)) { + continue; + } + if (extraBlock.isNull(p)) { + continue; + } + int vStart = vBlock.getFirstValueIndex(p); + int vEnd = vStart + vBlock.getValueCount(p); + for (int vOffset = vStart; vOffset < vEnd; vOffset++) { + float vValue = vBlock.getFloat(vOffset); + int extraStart = extraBlock.getFirstValueIndex(p); + int extraEnd = extraStart + extraBlock.getValueCount(p); + for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { + float extraValue = extraBlock.getFloat(extraOffset); + TopFloatFloatAggregator.combine(state, vValue, extraValue); + } + } + } + } + + @Override + public void addIntermediateInput(Page page) { + assert channels.size() == intermediateBlockCount(); + assert page.getBlockCount() >= channels.get(0) + intermediateStateDesc().size(); + Block topUncast = page.getBlock(channels.get(0)); + if (topUncast.areAllValuesNull()) { + return; + } + FloatBlock top = (FloatBlock) topUncast; + assert top.getPositionCount() == 1; + Block extraUncast = page.getBlock(channels.get(1)); + if (extraUncast.areAllValuesNull()) { + return; + } + FloatBlock extra = (FloatBlock) extraUncast; + assert extra.getPositionCount() == 1; + TopFloatFloatAggregator.combineIntermediate(state, top, extra); + } + + @Override + public void evaluateIntermediate(Block[] blocks, int offset, DriverContext driverContext) { + state.toIntermediate(blocks, offset, driverContext); + } + + @Override + public void evaluateFinal(Block[] blocks, int offset, DriverContext driverContext) { + blocks[offset] = TopFloatFloatAggregator.evaluateFinal(state, driverContext); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append(getClass().getSimpleName()).append("["); + sb.append("channels=").append(channels); + sb.append("]"); + return sb.toString(); + } + + @Override + public void close() { + state.close(); + } +} diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatFloatAggregatorFunctionSupplier.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatFloatAggregatorFunctionSupplier.java new file mode 100644 index 0000000000000..673b05432a165 --- /dev/null +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatFloatAggregatorFunctionSupplier.java @@ -0,0 +1,53 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License +// 2.0; you may not use this file except in compliance with the Elastic License +// 2.0. +package org.elasticsearch.compute.aggregation; + +import java.lang.Integer; +import java.lang.Override; +import java.lang.String; +import java.util.List; +import org.elasticsearch.compute.operator.DriverContext; + +/** + * {@link AggregatorFunctionSupplier} implementation for {@link TopFloatFloatAggregator}. + * This class is generated. Edit {@code AggregatorFunctionSupplierImplementer} instead. + */ +public final class TopFloatFloatAggregatorFunctionSupplier implements AggregatorFunctionSupplier { + private final int limit; + + private final boolean ascending; + + public TopFloatFloatAggregatorFunctionSupplier(int limit, boolean ascending) { + this.limit = limit; + this.ascending = ascending; + } + + @Override + public List nonGroupingIntermediateStateDesc() { + return TopFloatFloatAggregatorFunction.intermediateStateDesc(); + } + + @Override + public List groupingIntermediateStateDesc() { + return TopFloatFloatGroupingAggregatorFunction.intermediateStateDesc(); + } + + @Override + public TopFloatFloatAggregatorFunction aggregator(DriverContext driverContext, + List channels) { + return TopFloatFloatAggregatorFunction.create(driverContext, channels, limit, ascending); + } + + @Override + public TopFloatFloatGroupingAggregatorFunction groupingAggregator(DriverContext driverContext, + List channels) { + return TopFloatFloatGroupingAggregatorFunction.create(channels, driverContext, limit, ascending); + } + + @Override + public String describe() { + return "top_float of floats"; + } +} diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatFloatGroupingAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatFloatGroupingAggregatorFunction.java new file mode 100644 index 0000000000000..25b900fe6b047 --- /dev/null +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatFloatGroupingAggregatorFunction.java @@ -0,0 +1,395 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License +// 2.0; you may not use this file except in compliance with the Elastic License +// 2.0. +package org.elasticsearch.compute.aggregation; + +import java.lang.Integer; +import java.lang.Override; +import java.lang.String; +import java.lang.StringBuilder; +import java.util.List; +import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.ElementType; +import org.elasticsearch.compute.data.FloatBlock; +import org.elasticsearch.compute.data.FloatVector; +import org.elasticsearch.compute.data.IntArrayBlock; +import org.elasticsearch.compute.data.IntBigArrayBlock; +import org.elasticsearch.compute.data.IntVector; +import org.elasticsearch.compute.data.Page; +import org.elasticsearch.compute.operator.DriverContext; + +/** + * {@link GroupingAggregatorFunction} implementation for {@link TopFloatFloatAggregator}. + * This class is generated. Edit {@code GroupingAggregatorImplementer} instead. + */ +public final class TopFloatFloatGroupingAggregatorFunction implements GroupingAggregatorFunction { + private static final List INTERMEDIATE_STATE_DESC = List.of( + new IntermediateStateDesc("top", ElementType.FLOAT), + new IntermediateStateDesc("extra", ElementType.FLOAT) ); + + private final TopFloatFloatAggregator.GroupingState state; + + private final List channels; + + private final DriverContext driverContext; + + private final int limit; + + private final boolean ascending; + + public TopFloatFloatGroupingAggregatorFunction(List channels, + TopFloatFloatAggregator.GroupingState state, DriverContext driverContext, int limit, + boolean ascending) { + this.channels = channels; + this.state = state; + this.driverContext = driverContext; + this.limit = limit; + this.ascending = ascending; + } + + public static TopFloatFloatGroupingAggregatorFunction create(List channels, + DriverContext driverContext, int limit, boolean ascending) { + return new TopFloatFloatGroupingAggregatorFunction(channels, TopFloatFloatAggregator.initGrouping(driverContext.bigArrays(), limit, ascending), driverContext, limit, ascending); + } + + public static List intermediateStateDesc() { + return INTERMEDIATE_STATE_DESC; + } + + @Override + public int intermediateBlockCount() { + return INTERMEDIATE_STATE_DESC.size(); + } + + @Override + public GroupingAggregatorFunction.AddInput prepareProcessRawInputPage(SeenGroupIds seenGroupIds, + Page page) { + FloatBlock vBlock = page.getBlock(channels.get(0)); + FloatBlock extraBlock = page.getBlock(channels.get(1)); + FloatVector vVector = vBlock.asVector(); + if (vVector == null) { + maybeEnableGroupIdTracking(seenGroupIds, vBlock, extraBlock); + return new GroupingAggregatorFunction.AddInput() { + @Override + public void add(int positionOffset, IntArrayBlock groupIds) { + addRawInput(positionOffset, groupIds, vBlock, extraBlock); + } + + @Override + public void add(int positionOffset, IntBigArrayBlock groupIds) { + addRawInput(positionOffset, groupIds, vBlock, extraBlock); + } + + @Override + public void add(int positionOffset, IntVector groupIds) { + addRawInput(positionOffset, groupIds, vBlock, extraBlock); + } + + @Override + public void close() { + } + }; + } + FloatVector extraVector = extraBlock.asVector(); + if (extraVector == null) { + maybeEnableGroupIdTracking(seenGroupIds, vBlock, extraBlock); + return new GroupingAggregatorFunction.AddInput() { + @Override + public void add(int positionOffset, IntArrayBlock groupIds) { + addRawInput(positionOffset, groupIds, vBlock, extraBlock); + } + + @Override + public void add(int positionOffset, IntBigArrayBlock groupIds) { + addRawInput(positionOffset, groupIds, vBlock, extraBlock); + } + + @Override + public void add(int positionOffset, IntVector groupIds) { + addRawInput(positionOffset, groupIds, vBlock, extraBlock); + } + + @Override + public void close() { + } + }; + } + return new GroupingAggregatorFunction.AddInput() { + @Override + public void add(int positionOffset, IntArrayBlock groupIds) { + addRawInput(positionOffset, groupIds, vVector, extraVector); + } + + @Override + public void add(int positionOffset, IntBigArrayBlock groupIds) { + addRawInput(positionOffset, groupIds, vVector, extraVector); + } + + @Override + public void add(int positionOffset, IntVector groupIds) { + addRawInput(positionOffset, groupIds, vVector, extraVector); + } + + @Override + public void close() { + } + }; + } + + private void addRawInput(int positionOffset, IntArrayBlock groups, FloatBlock vBlock, + FloatBlock extraBlock) { + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + if (groups.isNull(groupPosition)) { + continue; + } + int valuesPosition = groupPosition + positionOffset; + if (vBlock.isNull(valuesPosition)) { + continue; + } + if (extraBlock.isNull(valuesPosition)) { + continue; + } + int groupStart = groups.getFirstValueIndex(groupPosition); + int groupEnd = groupStart + groups.getValueCount(groupPosition); + for (int g = groupStart; g < groupEnd; g++) { + int groupId = groups.getInt(g); + int vStart = vBlock.getFirstValueIndex(valuesPosition); + int vEnd = vStart + vBlock.getValueCount(valuesPosition); + for (int vOffset = vStart; vOffset < vEnd; vOffset++) { + float vValue = vBlock.getFloat(vOffset); + int extraStart = extraBlock.getFirstValueIndex(valuesPosition); + int extraEnd = extraStart + extraBlock.getValueCount(valuesPosition); + for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { + float extraValue = extraBlock.getFloat(extraOffset); + TopFloatFloatAggregator.combine(state, groupId, vValue, extraValue); + } + } + } + } + } + + private void addRawInput(int positionOffset, IntArrayBlock groups, FloatVector vVector, + FloatVector extraVector) { + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + if (groups.isNull(groupPosition)) { + continue; + } + int valuesPosition = groupPosition + positionOffset; + int groupStart = groups.getFirstValueIndex(groupPosition); + int groupEnd = groupStart + groups.getValueCount(groupPosition); + for (int g = groupStart; g < groupEnd; g++) { + int groupId = groups.getInt(g); + float vValue = vVector.getFloat(valuesPosition); + float extraValue = extraVector.getFloat(valuesPosition); + TopFloatFloatAggregator.combine(state, groupId, vValue, extraValue); + } + } + } + + @Override + public void addIntermediateInput(int positionOffset, IntArrayBlock groups, Page page) { + state.enableGroupIdTracking(new SeenGroupIds.Empty()); + assert channels.size() == intermediateBlockCount(); + Block topUncast = page.getBlock(channels.get(0)); + if (topUncast.areAllValuesNull()) { + return; + } + FloatBlock top = (FloatBlock) topUncast; + Block extraUncast = page.getBlock(channels.get(1)); + if (extraUncast.areAllValuesNull()) { + return; + } + FloatBlock extra = (FloatBlock) extraUncast; + assert top.getPositionCount() == extra.getPositionCount(); + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + if (groups.isNull(groupPosition)) { + continue; + } + int groupStart = groups.getFirstValueIndex(groupPosition); + int groupEnd = groupStart + groups.getValueCount(groupPosition); + for (int g = groupStart; g < groupEnd; g++) { + int groupId = groups.getInt(g); + int valuesPosition = groupPosition + positionOffset; + TopFloatFloatAggregator.combineIntermediate(state, groupId, top, extra, valuesPosition); + } + } + } + + private void addRawInput(int positionOffset, IntBigArrayBlock groups, FloatBlock vBlock, + FloatBlock extraBlock) { + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + if (groups.isNull(groupPosition)) { + continue; + } + int valuesPosition = groupPosition + positionOffset; + if (vBlock.isNull(valuesPosition)) { + continue; + } + if (extraBlock.isNull(valuesPosition)) { + continue; + } + int groupStart = groups.getFirstValueIndex(groupPosition); + int groupEnd = groupStart + groups.getValueCount(groupPosition); + for (int g = groupStart; g < groupEnd; g++) { + int groupId = groups.getInt(g); + int vStart = vBlock.getFirstValueIndex(valuesPosition); + int vEnd = vStart + vBlock.getValueCount(valuesPosition); + for (int vOffset = vStart; vOffset < vEnd; vOffset++) { + float vValue = vBlock.getFloat(vOffset); + int extraStart = extraBlock.getFirstValueIndex(valuesPosition); + int extraEnd = extraStart + extraBlock.getValueCount(valuesPosition); + for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { + float extraValue = extraBlock.getFloat(extraOffset); + TopFloatFloatAggregator.combine(state, groupId, vValue, extraValue); + } + } + } + } + } + + private void addRawInput(int positionOffset, IntBigArrayBlock groups, FloatVector vVector, + FloatVector extraVector) { + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + if (groups.isNull(groupPosition)) { + continue; + } + int valuesPosition = groupPosition + positionOffset; + int groupStart = groups.getFirstValueIndex(groupPosition); + int groupEnd = groupStart + groups.getValueCount(groupPosition); + for (int g = groupStart; g < groupEnd; g++) { + int groupId = groups.getInt(g); + float vValue = vVector.getFloat(valuesPosition); + float extraValue = extraVector.getFloat(valuesPosition); + TopFloatFloatAggregator.combine(state, groupId, vValue, extraValue); + } + } + } + + @Override + public void addIntermediateInput(int positionOffset, IntBigArrayBlock groups, Page page) { + state.enableGroupIdTracking(new SeenGroupIds.Empty()); + assert channels.size() == intermediateBlockCount(); + Block topUncast = page.getBlock(channels.get(0)); + if (topUncast.areAllValuesNull()) { + return; + } + FloatBlock top = (FloatBlock) topUncast; + Block extraUncast = page.getBlock(channels.get(1)); + if (extraUncast.areAllValuesNull()) { + return; + } + FloatBlock extra = (FloatBlock) extraUncast; + assert top.getPositionCount() == extra.getPositionCount(); + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + if (groups.isNull(groupPosition)) { + continue; + } + int groupStart = groups.getFirstValueIndex(groupPosition); + int groupEnd = groupStart + groups.getValueCount(groupPosition); + for (int g = groupStart; g < groupEnd; g++) { + int groupId = groups.getInt(g); + int valuesPosition = groupPosition + positionOffset; + TopFloatFloatAggregator.combineIntermediate(state, groupId, top, extra, valuesPosition); + } + } + } + + private void addRawInput(int positionOffset, IntVector groups, FloatBlock vBlock, + FloatBlock extraBlock) { + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + int valuesPosition = groupPosition + positionOffset; + if (vBlock.isNull(valuesPosition)) { + continue; + } + if (extraBlock.isNull(valuesPosition)) { + continue; + } + int groupId = groups.getInt(groupPosition); + int vStart = vBlock.getFirstValueIndex(valuesPosition); + int vEnd = vStart + vBlock.getValueCount(valuesPosition); + for (int vOffset = vStart; vOffset < vEnd; vOffset++) { + float vValue = vBlock.getFloat(vOffset); + int extraStart = extraBlock.getFirstValueIndex(valuesPosition); + int extraEnd = extraStart + extraBlock.getValueCount(valuesPosition); + for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { + float extraValue = extraBlock.getFloat(extraOffset); + TopFloatFloatAggregator.combine(state, groupId, vValue, extraValue); + } + } + } + } + + private void addRawInput(int positionOffset, IntVector groups, FloatVector vVector, + FloatVector extraVector) { + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + int valuesPosition = groupPosition + positionOffset; + int groupId = groups.getInt(groupPosition); + float vValue = vVector.getFloat(valuesPosition); + float extraValue = extraVector.getFloat(valuesPosition); + TopFloatFloatAggregator.combine(state, groupId, vValue, extraValue); + } + } + + @Override + public void addIntermediateInput(int positionOffset, IntVector groups, Page page) { + state.enableGroupIdTracking(new SeenGroupIds.Empty()); + assert channels.size() == intermediateBlockCount(); + Block topUncast = page.getBlock(channels.get(0)); + if (topUncast.areAllValuesNull()) { + return; + } + FloatBlock top = (FloatBlock) topUncast; + Block extraUncast = page.getBlock(channels.get(1)); + if (extraUncast.areAllValuesNull()) { + return; + } + FloatBlock extra = (FloatBlock) extraUncast; + assert top.getPositionCount() == extra.getPositionCount(); + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + int groupId = groups.getInt(groupPosition); + int valuesPosition = groupPosition + positionOffset; + TopFloatFloatAggregator.combineIntermediate(state, groupId, top, extra, valuesPosition); + } + } + + private void maybeEnableGroupIdTracking(SeenGroupIds seenGroupIds, FloatBlock vBlock, + FloatBlock extraBlock) { + if (vBlock.mayHaveNulls()) { + state.enableGroupIdTracking(seenGroupIds); + } + if (extraBlock.mayHaveNulls()) { + state.enableGroupIdTracking(seenGroupIds); + } + } + + @Override + public void selectedMayContainUnseenGroups(SeenGroupIds seenGroupIds) { + state.enableGroupIdTracking(seenGroupIds); + } + + @Override + public void evaluateIntermediate(Block[] blocks, int offset, IntVector selected) { + state.toIntermediate(blocks, offset, selected, driverContext); + } + + @Override + public void evaluateFinal(Block[] blocks, int offset, IntVector selected, + GroupingAggregatorEvaluationContext ctx) { + blocks[offset] = TopFloatFloatAggregator.evaluateFinal(state, selected, ctx); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append(getClass().getSimpleName()).append("["); + sb.append("channels=").append(channels); + sb.append("]"); + return sb.toString(); + } + + @Override + public void close() { + state.close(); + } +} diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatIntAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatIntAggregatorFunction.java new file mode 100644 index 0000000000000..fef58724f4b9e --- /dev/null +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatIntAggregatorFunction.java @@ -0,0 +1,215 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License +// 2.0; you may not use this file except in compliance with the Elastic License +// 2.0. +package org.elasticsearch.compute.aggregation; + +import java.lang.Integer; +import java.lang.Override; +import java.lang.String; +import java.lang.StringBuilder; +import java.util.List; +import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.BooleanVector; +import org.elasticsearch.compute.data.ElementType; +import org.elasticsearch.compute.data.FloatBlock; +import org.elasticsearch.compute.data.FloatVector; +import org.elasticsearch.compute.data.IntBlock; +import org.elasticsearch.compute.data.IntVector; +import org.elasticsearch.compute.data.Page; +import org.elasticsearch.compute.operator.DriverContext; + +/** + * {@link AggregatorFunction} implementation for {@link TopFloatIntAggregator}. + * This class is generated. Edit {@code AggregatorImplementer} instead. + */ +public final class TopFloatIntAggregatorFunction implements AggregatorFunction { + private static final List INTERMEDIATE_STATE_DESC = List.of( + new IntermediateStateDesc("top", ElementType.FLOAT), + new IntermediateStateDesc("extra", ElementType.INT) ); + + private final DriverContext driverContext; + + private final TopFloatIntAggregator.SingleState state; + + private final List channels; + + private final int limit; + + private final boolean ascending; + + public TopFloatIntAggregatorFunction(DriverContext driverContext, List channels, + TopFloatIntAggregator.SingleState state, int limit, boolean ascending) { + this.driverContext = driverContext; + this.channels = channels; + this.state = state; + this.limit = limit; + this.ascending = ascending; + } + + public static TopFloatIntAggregatorFunction create(DriverContext driverContext, + List channels, int limit, boolean ascending) { + return new TopFloatIntAggregatorFunction(driverContext, channels, TopFloatIntAggregator.initSingle(driverContext.bigArrays(), limit, ascending), limit, ascending); + } + + public static List intermediateStateDesc() { + return INTERMEDIATE_STATE_DESC; + } + + @Override + public int intermediateBlockCount() { + return INTERMEDIATE_STATE_DESC.size(); + } + + @Override + public void addRawInput(Page page, BooleanVector mask) { + if (mask.allFalse()) { + // Entire page masked away + } else if (mask.allTrue()) { + addRawInputNotMasked(page); + } else { + addRawInputMasked(page, mask); + } + } + + private void addRawInputMasked(Page page, BooleanVector mask) { + FloatBlock vBlock = page.getBlock(channels.get(0)); + IntBlock extraBlock = page.getBlock(channels.get(1)); + FloatVector vVector = vBlock.asVector(); + if (vVector == null) { + addRawBlock(vBlock, extraBlock, mask); + return; + } + IntVector extraVector = extraBlock.asVector(); + if (extraVector == null) { + addRawBlock(vBlock, extraBlock, mask); + return; + } + addRawVector(vVector, extraVector, mask); + } + + private void addRawInputNotMasked(Page page) { + FloatBlock vBlock = page.getBlock(channels.get(0)); + IntBlock extraBlock = page.getBlock(channels.get(1)); + FloatVector vVector = vBlock.asVector(); + if (vVector == null) { + addRawBlock(vBlock, extraBlock); + return; + } + IntVector extraVector = extraBlock.asVector(); + if (extraVector == null) { + addRawBlock(vBlock, extraBlock); + return; + } + addRawVector(vVector, extraVector); + } + + private void addRawVector(FloatVector vVector, IntVector extraVector) { + for (int valuesPosition = 0; valuesPosition < vVector.getPositionCount(); valuesPosition++) { + float vValue = vVector.getFloat(valuesPosition); + int extraValue = extraVector.getInt(valuesPosition); + TopFloatIntAggregator.combine(state, vValue, extraValue); + } + } + + private void addRawVector(FloatVector vVector, IntVector extraVector, BooleanVector mask) { + for (int valuesPosition = 0; valuesPosition < vVector.getPositionCount(); valuesPosition++) { + if (mask.getBoolean(valuesPosition) == false) { + continue; + } + float vValue = vVector.getFloat(valuesPosition); + int extraValue = extraVector.getInt(valuesPosition); + TopFloatIntAggregator.combine(state, vValue, extraValue); + } + } + + private void addRawBlock(FloatBlock vBlock, IntBlock extraBlock) { + for (int p = 0; p < vBlock.getPositionCount(); p++) { + if (vBlock.isNull(p)) { + continue; + } + if (extraBlock.isNull(p)) { + continue; + } + int vStart = vBlock.getFirstValueIndex(p); + int vEnd = vStart + vBlock.getValueCount(p); + for (int vOffset = vStart; vOffset < vEnd; vOffset++) { + float vValue = vBlock.getFloat(vOffset); + int extraStart = extraBlock.getFirstValueIndex(p); + int extraEnd = extraStart + extraBlock.getValueCount(p); + for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { + int extraValue = extraBlock.getInt(extraOffset); + TopFloatIntAggregator.combine(state, vValue, extraValue); + } + } + } + } + + private void addRawBlock(FloatBlock vBlock, IntBlock extraBlock, BooleanVector mask) { + for (int p = 0; p < vBlock.getPositionCount(); p++) { + if (mask.getBoolean(p) == false) { + continue; + } + if (vBlock.isNull(p)) { + continue; + } + if (extraBlock.isNull(p)) { + continue; + } + int vStart = vBlock.getFirstValueIndex(p); + int vEnd = vStart + vBlock.getValueCount(p); + for (int vOffset = vStart; vOffset < vEnd; vOffset++) { + float vValue = vBlock.getFloat(vOffset); + int extraStart = extraBlock.getFirstValueIndex(p); + int extraEnd = extraStart + extraBlock.getValueCount(p); + for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { + int extraValue = extraBlock.getInt(extraOffset); + TopFloatIntAggregator.combine(state, vValue, extraValue); + } + } + } + } + + @Override + public void addIntermediateInput(Page page) { + assert channels.size() == intermediateBlockCount(); + assert page.getBlockCount() >= channels.get(0) + intermediateStateDesc().size(); + Block topUncast = page.getBlock(channels.get(0)); + if (topUncast.areAllValuesNull()) { + return; + } + FloatBlock top = (FloatBlock) topUncast; + assert top.getPositionCount() == 1; + Block extraUncast = page.getBlock(channels.get(1)); + if (extraUncast.areAllValuesNull()) { + return; + } + IntBlock extra = (IntBlock) extraUncast; + assert extra.getPositionCount() == 1; + TopFloatIntAggregator.combineIntermediate(state, top, extra); + } + + @Override + public void evaluateIntermediate(Block[] blocks, int offset, DriverContext driverContext) { + state.toIntermediate(blocks, offset, driverContext); + } + + @Override + public void evaluateFinal(Block[] blocks, int offset, DriverContext driverContext) { + blocks[offset] = TopFloatIntAggregator.evaluateFinal(state, driverContext); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append(getClass().getSimpleName()).append("["); + sb.append("channels=").append(channels); + sb.append("]"); + return sb.toString(); + } + + @Override + public void close() { + state.close(); + } +} diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatIntAggregatorFunctionSupplier.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatIntAggregatorFunctionSupplier.java new file mode 100644 index 0000000000000..2851342c630c7 --- /dev/null +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatIntAggregatorFunctionSupplier.java @@ -0,0 +1,53 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License +// 2.0; you may not use this file except in compliance with the Elastic License +// 2.0. +package org.elasticsearch.compute.aggregation; + +import java.lang.Integer; +import java.lang.Override; +import java.lang.String; +import java.util.List; +import org.elasticsearch.compute.operator.DriverContext; + +/** + * {@link AggregatorFunctionSupplier} implementation for {@link TopFloatIntAggregator}. + * This class is generated. Edit {@code AggregatorFunctionSupplierImplementer} instead. + */ +public final class TopFloatIntAggregatorFunctionSupplier implements AggregatorFunctionSupplier { + private final int limit; + + private final boolean ascending; + + public TopFloatIntAggregatorFunctionSupplier(int limit, boolean ascending) { + this.limit = limit; + this.ascending = ascending; + } + + @Override + public List nonGroupingIntermediateStateDesc() { + return TopFloatIntAggregatorFunction.intermediateStateDesc(); + } + + @Override + public List groupingIntermediateStateDesc() { + return TopFloatIntGroupingAggregatorFunction.intermediateStateDesc(); + } + + @Override + public TopFloatIntAggregatorFunction aggregator(DriverContext driverContext, + List channels) { + return TopFloatIntAggregatorFunction.create(driverContext, channels, limit, ascending); + } + + @Override + public TopFloatIntGroupingAggregatorFunction groupingAggregator(DriverContext driverContext, + List channels) { + return TopFloatIntGroupingAggregatorFunction.create(channels, driverContext, limit, ascending); + } + + @Override + public String describe() { + return "top_float of ints"; + } +} diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatIntGroupingAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatIntGroupingAggregatorFunction.java new file mode 100644 index 0000000000000..3f9485ce7c3b8 --- /dev/null +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatIntGroupingAggregatorFunction.java @@ -0,0 +1,396 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License +// 2.0; you may not use this file except in compliance with the Elastic License +// 2.0. +package org.elasticsearch.compute.aggregation; + +import java.lang.Integer; +import java.lang.Override; +import java.lang.String; +import java.lang.StringBuilder; +import java.util.List; +import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.ElementType; +import org.elasticsearch.compute.data.FloatBlock; +import org.elasticsearch.compute.data.FloatVector; +import org.elasticsearch.compute.data.IntArrayBlock; +import org.elasticsearch.compute.data.IntBigArrayBlock; +import org.elasticsearch.compute.data.IntBlock; +import org.elasticsearch.compute.data.IntVector; +import org.elasticsearch.compute.data.Page; +import org.elasticsearch.compute.operator.DriverContext; + +/** + * {@link GroupingAggregatorFunction} implementation for {@link TopFloatIntAggregator}. + * This class is generated. Edit {@code GroupingAggregatorImplementer} instead. + */ +public final class TopFloatIntGroupingAggregatorFunction implements GroupingAggregatorFunction { + private static final List INTERMEDIATE_STATE_DESC = List.of( + new IntermediateStateDesc("top", ElementType.FLOAT), + new IntermediateStateDesc("extra", ElementType.INT) ); + + private final TopFloatIntAggregator.GroupingState state; + + private final List channels; + + private final DriverContext driverContext; + + private final int limit; + + private final boolean ascending; + + public TopFloatIntGroupingAggregatorFunction(List channels, + TopFloatIntAggregator.GroupingState state, DriverContext driverContext, int limit, + boolean ascending) { + this.channels = channels; + this.state = state; + this.driverContext = driverContext; + this.limit = limit; + this.ascending = ascending; + } + + public static TopFloatIntGroupingAggregatorFunction create(List channels, + DriverContext driverContext, int limit, boolean ascending) { + return new TopFloatIntGroupingAggregatorFunction(channels, TopFloatIntAggregator.initGrouping(driverContext.bigArrays(), limit, ascending), driverContext, limit, ascending); + } + + public static List intermediateStateDesc() { + return INTERMEDIATE_STATE_DESC; + } + + @Override + public int intermediateBlockCount() { + return INTERMEDIATE_STATE_DESC.size(); + } + + @Override + public GroupingAggregatorFunction.AddInput prepareProcessRawInputPage(SeenGroupIds seenGroupIds, + Page page) { + FloatBlock vBlock = page.getBlock(channels.get(0)); + IntBlock extraBlock = page.getBlock(channels.get(1)); + FloatVector vVector = vBlock.asVector(); + if (vVector == null) { + maybeEnableGroupIdTracking(seenGroupIds, vBlock, extraBlock); + return new GroupingAggregatorFunction.AddInput() { + @Override + public void add(int positionOffset, IntArrayBlock groupIds) { + addRawInput(positionOffset, groupIds, vBlock, extraBlock); + } + + @Override + public void add(int positionOffset, IntBigArrayBlock groupIds) { + addRawInput(positionOffset, groupIds, vBlock, extraBlock); + } + + @Override + public void add(int positionOffset, IntVector groupIds) { + addRawInput(positionOffset, groupIds, vBlock, extraBlock); + } + + @Override + public void close() { + } + }; + } + IntVector extraVector = extraBlock.asVector(); + if (extraVector == null) { + maybeEnableGroupIdTracking(seenGroupIds, vBlock, extraBlock); + return new GroupingAggregatorFunction.AddInput() { + @Override + public void add(int positionOffset, IntArrayBlock groupIds) { + addRawInput(positionOffset, groupIds, vBlock, extraBlock); + } + + @Override + public void add(int positionOffset, IntBigArrayBlock groupIds) { + addRawInput(positionOffset, groupIds, vBlock, extraBlock); + } + + @Override + public void add(int positionOffset, IntVector groupIds) { + addRawInput(positionOffset, groupIds, vBlock, extraBlock); + } + + @Override + public void close() { + } + }; + } + return new GroupingAggregatorFunction.AddInput() { + @Override + public void add(int positionOffset, IntArrayBlock groupIds) { + addRawInput(positionOffset, groupIds, vVector, extraVector); + } + + @Override + public void add(int positionOffset, IntBigArrayBlock groupIds) { + addRawInput(positionOffset, groupIds, vVector, extraVector); + } + + @Override + public void add(int positionOffset, IntVector groupIds) { + addRawInput(positionOffset, groupIds, vVector, extraVector); + } + + @Override + public void close() { + } + }; + } + + private void addRawInput(int positionOffset, IntArrayBlock groups, FloatBlock vBlock, + IntBlock extraBlock) { + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + if (groups.isNull(groupPosition)) { + continue; + } + int valuesPosition = groupPosition + positionOffset; + if (vBlock.isNull(valuesPosition)) { + continue; + } + if (extraBlock.isNull(valuesPosition)) { + continue; + } + int groupStart = groups.getFirstValueIndex(groupPosition); + int groupEnd = groupStart + groups.getValueCount(groupPosition); + for (int g = groupStart; g < groupEnd; g++) { + int groupId = groups.getInt(g); + int vStart = vBlock.getFirstValueIndex(valuesPosition); + int vEnd = vStart + vBlock.getValueCount(valuesPosition); + for (int vOffset = vStart; vOffset < vEnd; vOffset++) { + float vValue = vBlock.getFloat(vOffset); + int extraStart = extraBlock.getFirstValueIndex(valuesPosition); + int extraEnd = extraStart + extraBlock.getValueCount(valuesPosition); + for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { + int extraValue = extraBlock.getInt(extraOffset); + TopFloatIntAggregator.combine(state, groupId, vValue, extraValue); + } + } + } + } + } + + private void addRawInput(int positionOffset, IntArrayBlock groups, FloatVector vVector, + IntVector extraVector) { + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + if (groups.isNull(groupPosition)) { + continue; + } + int valuesPosition = groupPosition + positionOffset; + int groupStart = groups.getFirstValueIndex(groupPosition); + int groupEnd = groupStart + groups.getValueCount(groupPosition); + for (int g = groupStart; g < groupEnd; g++) { + int groupId = groups.getInt(g); + float vValue = vVector.getFloat(valuesPosition); + int extraValue = extraVector.getInt(valuesPosition); + TopFloatIntAggregator.combine(state, groupId, vValue, extraValue); + } + } + } + + @Override + public void addIntermediateInput(int positionOffset, IntArrayBlock groups, Page page) { + state.enableGroupIdTracking(new SeenGroupIds.Empty()); + assert channels.size() == intermediateBlockCount(); + Block topUncast = page.getBlock(channels.get(0)); + if (topUncast.areAllValuesNull()) { + return; + } + FloatBlock top = (FloatBlock) topUncast; + Block extraUncast = page.getBlock(channels.get(1)); + if (extraUncast.areAllValuesNull()) { + return; + } + IntBlock extra = (IntBlock) extraUncast; + assert top.getPositionCount() == extra.getPositionCount(); + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + if (groups.isNull(groupPosition)) { + continue; + } + int groupStart = groups.getFirstValueIndex(groupPosition); + int groupEnd = groupStart + groups.getValueCount(groupPosition); + for (int g = groupStart; g < groupEnd; g++) { + int groupId = groups.getInt(g); + int valuesPosition = groupPosition + positionOffset; + TopFloatIntAggregator.combineIntermediate(state, groupId, top, extra, valuesPosition); + } + } + } + + private void addRawInput(int positionOffset, IntBigArrayBlock groups, FloatBlock vBlock, + IntBlock extraBlock) { + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + if (groups.isNull(groupPosition)) { + continue; + } + int valuesPosition = groupPosition + positionOffset; + if (vBlock.isNull(valuesPosition)) { + continue; + } + if (extraBlock.isNull(valuesPosition)) { + continue; + } + int groupStart = groups.getFirstValueIndex(groupPosition); + int groupEnd = groupStart + groups.getValueCount(groupPosition); + for (int g = groupStart; g < groupEnd; g++) { + int groupId = groups.getInt(g); + int vStart = vBlock.getFirstValueIndex(valuesPosition); + int vEnd = vStart + vBlock.getValueCount(valuesPosition); + for (int vOffset = vStart; vOffset < vEnd; vOffset++) { + float vValue = vBlock.getFloat(vOffset); + int extraStart = extraBlock.getFirstValueIndex(valuesPosition); + int extraEnd = extraStart + extraBlock.getValueCount(valuesPosition); + for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { + int extraValue = extraBlock.getInt(extraOffset); + TopFloatIntAggregator.combine(state, groupId, vValue, extraValue); + } + } + } + } + } + + private void addRawInput(int positionOffset, IntBigArrayBlock groups, FloatVector vVector, + IntVector extraVector) { + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + if (groups.isNull(groupPosition)) { + continue; + } + int valuesPosition = groupPosition + positionOffset; + int groupStart = groups.getFirstValueIndex(groupPosition); + int groupEnd = groupStart + groups.getValueCount(groupPosition); + for (int g = groupStart; g < groupEnd; g++) { + int groupId = groups.getInt(g); + float vValue = vVector.getFloat(valuesPosition); + int extraValue = extraVector.getInt(valuesPosition); + TopFloatIntAggregator.combine(state, groupId, vValue, extraValue); + } + } + } + + @Override + public void addIntermediateInput(int positionOffset, IntBigArrayBlock groups, Page page) { + state.enableGroupIdTracking(new SeenGroupIds.Empty()); + assert channels.size() == intermediateBlockCount(); + Block topUncast = page.getBlock(channels.get(0)); + if (topUncast.areAllValuesNull()) { + return; + } + FloatBlock top = (FloatBlock) topUncast; + Block extraUncast = page.getBlock(channels.get(1)); + if (extraUncast.areAllValuesNull()) { + return; + } + IntBlock extra = (IntBlock) extraUncast; + assert top.getPositionCount() == extra.getPositionCount(); + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + if (groups.isNull(groupPosition)) { + continue; + } + int groupStart = groups.getFirstValueIndex(groupPosition); + int groupEnd = groupStart + groups.getValueCount(groupPosition); + for (int g = groupStart; g < groupEnd; g++) { + int groupId = groups.getInt(g); + int valuesPosition = groupPosition + positionOffset; + TopFloatIntAggregator.combineIntermediate(state, groupId, top, extra, valuesPosition); + } + } + } + + private void addRawInput(int positionOffset, IntVector groups, FloatBlock vBlock, + IntBlock extraBlock) { + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + int valuesPosition = groupPosition + positionOffset; + if (vBlock.isNull(valuesPosition)) { + continue; + } + if (extraBlock.isNull(valuesPosition)) { + continue; + } + int groupId = groups.getInt(groupPosition); + int vStart = vBlock.getFirstValueIndex(valuesPosition); + int vEnd = vStart + vBlock.getValueCount(valuesPosition); + for (int vOffset = vStart; vOffset < vEnd; vOffset++) { + float vValue = vBlock.getFloat(vOffset); + int extraStart = extraBlock.getFirstValueIndex(valuesPosition); + int extraEnd = extraStart + extraBlock.getValueCount(valuesPosition); + for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { + int extraValue = extraBlock.getInt(extraOffset); + TopFloatIntAggregator.combine(state, groupId, vValue, extraValue); + } + } + } + } + + private void addRawInput(int positionOffset, IntVector groups, FloatVector vVector, + IntVector extraVector) { + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + int valuesPosition = groupPosition + positionOffset; + int groupId = groups.getInt(groupPosition); + float vValue = vVector.getFloat(valuesPosition); + int extraValue = extraVector.getInt(valuesPosition); + TopFloatIntAggregator.combine(state, groupId, vValue, extraValue); + } + } + + @Override + public void addIntermediateInput(int positionOffset, IntVector groups, Page page) { + state.enableGroupIdTracking(new SeenGroupIds.Empty()); + assert channels.size() == intermediateBlockCount(); + Block topUncast = page.getBlock(channels.get(0)); + if (topUncast.areAllValuesNull()) { + return; + } + FloatBlock top = (FloatBlock) topUncast; + Block extraUncast = page.getBlock(channels.get(1)); + if (extraUncast.areAllValuesNull()) { + return; + } + IntBlock extra = (IntBlock) extraUncast; + assert top.getPositionCount() == extra.getPositionCount(); + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + int groupId = groups.getInt(groupPosition); + int valuesPosition = groupPosition + positionOffset; + TopFloatIntAggregator.combineIntermediate(state, groupId, top, extra, valuesPosition); + } + } + + private void maybeEnableGroupIdTracking(SeenGroupIds seenGroupIds, FloatBlock vBlock, + IntBlock extraBlock) { + if (vBlock.mayHaveNulls()) { + state.enableGroupIdTracking(seenGroupIds); + } + if (extraBlock.mayHaveNulls()) { + state.enableGroupIdTracking(seenGroupIds); + } + } + + @Override + public void selectedMayContainUnseenGroups(SeenGroupIds seenGroupIds) { + state.enableGroupIdTracking(seenGroupIds); + } + + @Override + public void evaluateIntermediate(Block[] blocks, int offset, IntVector selected) { + state.toIntermediate(blocks, offset, selected, driverContext); + } + + @Override + public void evaluateFinal(Block[] blocks, int offset, IntVector selected, + GroupingAggregatorEvaluationContext ctx) { + blocks[offset] = TopFloatIntAggregator.evaluateFinal(state, selected, ctx); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append(getClass().getSimpleName()).append("["); + sb.append("channels=").append(channels); + sb.append("]"); + return sb.toString(); + } + + @Override + public void close() { + state.close(); + } +} diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatLongAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatLongAggregatorFunction.java new file mode 100644 index 0000000000000..81d52c5bd0a94 --- /dev/null +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatLongAggregatorFunction.java @@ -0,0 +1,215 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License +// 2.0; you may not use this file except in compliance with the Elastic License +// 2.0. +package org.elasticsearch.compute.aggregation; + +import java.lang.Integer; +import java.lang.Override; +import java.lang.String; +import java.lang.StringBuilder; +import java.util.List; +import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.BooleanVector; +import org.elasticsearch.compute.data.ElementType; +import org.elasticsearch.compute.data.FloatBlock; +import org.elasticsearch.compute.data.FloatVector; +import org.elasticsearch.compute.data.LongBlock; +import org.elasticsearch.compute.data.LongVector; +import org.elasticsearch.compute.data.Page; +import org.elasticsearch.compute.operator.DriverContext; + +/** + * {@link AggregatorFunction} implementation for {@link TopFloatLongAggregator}. + * This class is generated. Edit {@code AggregatorImplementer} instead. + */ +public final class TopFloatLongAggregatorFunction implements AggregatorFunction { + private static final List INTERMEDIATE_STATE_DESC = List.of( + new IntermediateStateDesc("top", ElementType.FLOAT), + new IntermediateStateDesc("extra", ElementType.LONG) ); + + private final DriverContext driverContext; + + private final TopFloatLongAggregator.SingleState state; + + private final List channels; + + private final int limit; + + private final boolean ascending; + + public TopFloatLongAggregatorFunction(DriverContext driverContext, List channels, + TopFloatLongAggregator.SingleState state, int limit, boolean ascending) { + this.driverContext = driverContext; + this.channels = channels; + this.state = state; + this.limit = limit; + this.ascending = ascending; + } + + public static TopFloatLongAggregatorFunction create(DriverContext driverContext, + List channels, int limit, boolean ascending) { + return new TopFloatLongAggregatorFunction(driverContext, channels, TopFloatLongAggregator.initSingle(driverContext.bigArrays(), limit, ascending), limit, ascending); + } + + public static List intermediateStateDesc() { + return INTERMEDIATE_STATE_DESC; + } + + @Override + public int intermediateBlockCount() { + return INTERMEDIATE_STATE_DESC.size(); + } + + @Override + public void addRawInput(Page page, BooleanVector mask) { + if (mask.allFalse()) { + // Entire page masked away + } else if (mask.allTrue()) { + addRawInputNotMasked(page); + } else { + addRawInputMasked(page, mask); + } + } + + private void addRawInputMasked(Page page, BooleanVector mask) { + FloatBlock vBlock = page.getBlock(channels.get(0)); + LongBlock extraBlock = page.getBlock(channels.get(1)); + FloatVector vVector = vBlock.asVector(); + if (vVector == null) { + addRawBlock(vBlock, extraBlock, mask); + return; + } + LongVector extraVector = extraBlock.asVector(); + if (extraVector == null) { + addRawBlock(vBlock, extraBlock, mask); + return; + } + addRawVector(vVector, extraVector, mask); + } + + private void addRawInputNotMasked(Page page) { + FloatBlock vBlock = page.getBlock(channels.get(0)); + LongBlock extraBlock = page.getBlock(channels.get(1)); + FloatVector vVector = vBlock.asVector(); + if (vVector == null) { + addRawBlock(vBlock, extraBlock); + return; + } + LongVector extraVector = extraBlock.asVector(); + if (extraVector == null) { + addRawBlock(vBlock, extraBlock); + return; + } + addRawVector(vVector, extraVector); + } + + private void addRawVector(FloatVector vVector, LongVector extraVector) { + for (int valuesPosition = 0; valuesPosition < vVector.getPositionCount(); valuesPosition++) { + float vValue = vVector.getFloat(valuesPosition); + long extraValue = extraVector.getLong(valuesPosition); + TopFloatLongAggregator.combine(state, vValue, extraValue); + } + } + + private void addRawVector(FloatVector vVector, LongVector extraVector, BooleanVector mask) { + for (int valuesPosition = 0; valuesPosition < vVector.getPositionCount(); valuesPosition++) { + if (mask.getBoolean(valuesPosition) == false) { + continue; + } + float vValue = vVector.getFloat(valuesPosition); + long extraValue = extraVector.getLong(valuesPosition); + TopFloatLongAggregator.combine(state, vValue, extraValue); + } + } + + private void addRawBlock(FloatBlock vBlock, LongBlock extraBlock) { + for (int p = 0; p < vBlock.getPositionCount(); p++) { + if (vBlock.isNull(p)) { + continue; + } + if (extraBlock.isNull(p)) { + continue; + } + int vStart = vBlock.getFirstValueIndex(p); + int vEnd = vStart + vBlock.getValueCount(p); + for (int vOffset = vStart; vOffset < vEnd; vOffset++) { + float vValue = vBlock.getFloat(vOffset); + int extraStart = extraBlock.getFirstValueIndex(p); + int extraEnd = extraStart + extraBlock.getValueCount(p); + for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { + long extraValue = extraBlock.getLong(extraOffset); + TopFloatLongAggregator.combine(state, vValue, extraValue); + } + } + } + } + + private void addRawBlock(FloatBlock vBlock, LongBlock extraBlock, BooleanVector mask) { + for (int p = 0; p < vBlock.getPositionCount(); p++) { + if (mask.getBoolean(p) == false) { + continue; + } + if (vBlock.isNull(p)) { + continue; + } + if (extraBlock.isNull(p)) { + continue; + } + int vStart = vBlock.getFirstValueIndex(p); + int vEnd = vStart + vBlock.getValueCount(p); + for (int vOffset = vStart; vOffset < vEnd; vOffset++) { + float vValue = vBlock.getFloat(vOffset); + int extraStart = extraBlock.getFirstValueIndex(p); + int extraEnd = extraStart + extraBlock.getValueCount(p); + for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { + long extraValue = extraBlock.getLong(extraOffset); + TopFloatLongAggregator.combine(state, vValue, extraValue); + } + } + } + } + + @Override + public void addIntermediateInput(Page page) { + assert channels.size() == intermediateBlockCount(); + assert page.getBlockCount() >= channels.get(0) + intermediateStateDesc().size(); + Block topUncast = page.getBlock(channels.get(0)); + if (topUncast.areAllValuesNull()) { + return; + } + FloatBlock top = (FloatBlock) topUncast; + assert top.getPositionCount() == 1; + Block extraUncast = page.getBlock(channels.get(1)); + if (extraUncast.areAllValuesNull()) { + return; + } + LongBlock extra = (LongBlock) extraUncast; + assert extra.getPositionCount() == 1; + TopFloatLongAggregator.combineIntermediate(state, top, extra); + } + + @Override + public void evaluateIntermediate(Block[] blocks, int offset, DriverContext driverContext) { + state.toIntermediate(blocks, offset, driverContext); + } + + @Override + public void evaluateFinal(Block[] blocks, int offset, DriverContext driverContext) { + blocks[offset] = TopFloatLongAggregator.evaluateFinal(state, driverContext); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append(getClass().getSimpleName()).append("["); + sb.append("channels=").append(channels); + sb.append("]"); + return sb.toString(); + } + + @Override + public void close() { + state.close(); + } +} diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatLongAggregatorFunctionSupplier.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatLongAggregatorFunctionSupplier.java new file mode 100644 index 0000000000000..d8667fddcb2e9 --- /dev/null +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatLongAggregatorFunctionSupplier.java @@ -0,0 +1,53 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License +// 2.0; you may not use this file except in compliance with the Elastic License +// 2.0. +package org.elasticsearch.compute.aggregation; + +import java.lang.Integer; +import java.lang.Override; +import java.lang.String; +import java.util.List; +import org.elasticsearch.compute.operator.DriverContext; + +/** + * {@link AggregatorFunctionSupplier} implementation for {@link TopFloatLongAggregator}. + * This class is generated. Edit {@code AggregatorFunctionSupplierImplementer} instead. + */ +public final class TopFloatLongAggregatorFunctionSupplier implements AggregatorFunctionSupplier { + private final int limit; + + private final boolean ascending; + + public TopFloatLongAggregatorFunctionSupplier(int limit, boolean ascending) { + this.limit = limit; + this.ascending = ascending; + } + + @Override + public List nonGroupingIntermediateStateDesc() { + return TopFloatLongAggregatorFunction.intermediateStateDesc(); + } + + @Override + public List groupingIntermediateStateDesc() { + return TopFloatLongGroupingAggregatorFunction.intermediateStateDesc(); + } + + @Override + public TopFloatLongAggregatorFunction aggregator(DriverContext driverContext, + List channels) { + return TopFloatLongAggregatorFunction.create(driverContext, channels, limit, ascending); + } + + @Override + public TopFloatLongGroupingAggregatorFunction groupingAggregator(DriverContext driverContext, + List channels) { + return TopFloatLongGroupingAggregatorFunction.create(channels, driverContext, limit, ascending); + } + + @Override + public String describe() { + return "top_float of longs"; + } +} diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatLongGroupingAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatLongGroupingAggregatorFunction.java new file mode 100644 index 0000000000000..844a07a80b60f --- /dev/null +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatLongGroupingAggregatorFunction.java @@ -0,0 +1,397 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License +// 2.0; you may not use this file except in compliance with the Elastic License +// 2.0. +package org.elasticsearch.compute.aggregation; + +import java.lang.Integer; +import java.lang.Override; +import java.lang.String; +import java.lang.StringBuilder; +import java.util.List; +import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.ElementType; +import org.elasticsearch.compute.data.FloatBlock; +import org.elasticsearch.compute.data.FloatVector; +import org.elasticsearch.compute.data.IntArrayBlock; +import org.elasticsearch.compute.data.IntBigArrayBlock; +import org.elasticsearch.compute.data.IntVector; +import org.elasticsearch.compute.data.LongBlock; +import org.elasticsearch.compute.data.LongVector; +import org.elasticsearch.compute.data.Page; +import org.elasticsearch.compute.operator.DriverContext; + +/** + * {@link GroupingAggregatorFunction} implementation for {@link TopFloatLongAggregator}. + * This class is generated. Edit {@code GroupingAggregatorImplementer} instead. + */ +public final class TopFloatLongGroupingAggregatorFunction implements GroupingAggregatorFunction { + private static final List INTERMEDIATE_STATE_DESC = List.of( + new IntermediateStateDesc("top", ElementType.FLOAT), + new IntermediateStateDesc("extra", ElementType.LONG) ); + + private final TopFloatLongAggregator.GroupingState state; + + private final List channels; + + private final DriverContext driverContext; + + private final int limit; + + private final boolean ascending; + + public TopFloatLongGroupingAggregatorFunction(List channels, + TopFloatLongAggregator.GroupingState state, DriverContext driverContext, int limit, + boolean ascending) { + this.channels = channels; + this.state = state; + this.driverContext = driverContext; + this.limit = limit; + this.ascending = ascending; + } + + public static TopFloatLongGroupingAggregatorFunction create(List channels, + DriverContext driverContext, int limit, boolean ascending) { + return new TopFloatLongGroupingAggregatorFunction(channels, TopFloatLongAggregator.initGrouping(driverContext.bigArrays(), limit, ascending), driverContext, limit, ascending); + } + + public static List intermediateStateDesc() { + return INTERMEDIATE_STATE_DESC; + } + + @Override + public int intermediateBlockCount() { + return INTERMEDIATE_STATE_DESC.size(); + } + + @Override + public GroupingAggregatorFunction.AddInput prepareProcessRawInputPage(SeenGroupIds seenGroupIds, + Page page) { + FloatBlock vBlock = page.getBlock(channels.get(0)); + LongBlock extraBlock = page.getBlock(channels.get(1)); + FloatVector vVector = vBlock.asVector(); + if (vVector == null) { + maybeEnableGroupIdTracking(seenGroupIds, vBlock, extraBlock); + return new GroupingAggregatorFunction.AddInput() { + @Override + public void add(int positionOffset, IntArrayBlock groupIds) { + addRawInput(positionOffset, groupIds, vBlock, extraBlock); + } + + @Override + public void add(int positionOffset, IntBigArrayBlock groupIds) { + addRawInput(positionOffset, groupIds, vBlock, extraBlock); + } + + @Override + public void add(int positionOffset, IntVector groupIds) { + addRawInput(positionOffset, groupIds, vBlock, extraBlock); + } + + @Override + public void close() { + } + }; + } + LongVector extraVector = extraBlock.asVector(); + if (extraVector == null) { + maybeEnableGroupIdTracking(seenGroupIds, vBlock, extraBlock); + return new GroupingAggregatorFunction.AddInput() { + @Override + public void add(int positionOffset, IntArrayBlock groupIds) { + addRawInput(positionOffset, groupIds, vBlock, extraBlock); + } + + @Override + public void add(int positionOffset, IntBigArrayBlock groupIds) { + addRawInput(positionOffset, groupIds, vBlock, extraBlock); + } + + @Override + public void add(int positionOffset, IntVector groupIds) { + addRawInput(positionOffset, groupIds, vBlock, extraBlock); + } + + @Override + public void close() { + } + }; + } + return new GroupingAggregatorFunction.AddInput() { + @Override + public void add(int positionOffset, IntArrayBlock groupIds) { + addRawInput(positionOffset, groupIds, vVector, extraVector); + } + + @Override + public void add(int positionOffset, IntBigArrayBlock groupIds) { + addRawInput(positionOffset, groupIds, vVector, extraVector); + } + + @Override + public void add(int positionOffset, IntVector groupIds) { + addRawInput(positionOffset, groupIds, vVector, extraVector); + } + + @Override + public void close() { + } + }; + } + + private void addRawInput(int positionOffset, IntArrayBlock groups, FloatBlock vBlock, + LongBlock extraBlock) { + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + if (groups.isNull(groupPosition)) { + continue; + } + int valuesPosition = groupPosition + positionOffset; + if (vBlock.isNull(valuesPosition)) { + continue; + } + if (extraBlock.isNull(valuesPosition)) { + continue; + } + int groupStart = groups.getFirstValueIndex(groupPosition); + int groupEnd = groupStart + groups.getValueCount(groupPosition); + for (int g = groupStart; g < groupEnd; g++) { + int groupId = groups.getInt(g); + int vStart = vBlock.getFirstValueIndex(valuesPosition); + int vEnd = vStart + vBlock.getValueCount(valuesPosition); + for (int vOffset = vStart; vOffset < vEnd; vOffset++) { + float vValue = vBlock.getFloat(vOffset); + int extraStart = extraBlock.getFirstValueIndex(valuesPosition); + int extraEnd = extraStart + extraBlock.getValueCount(valuesPosition); + for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { + long extraValue = extraBlock.getLong(extraOffset); + TopFloatLongAggregator.combine(state, groupId, vValue, extraValue); + } + } + } + } + } + + private void addRawInput(int positionOffset, IntArrayBlock groups, FloatVector vVector, + LongVector extraVector) { + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + if (groups.isNull(groupPosition)) { + continue; + } + int valuesPosition = groupPosition + positionOffset; + int groupStart = groups.getFirstValueIndex(groupPosition); + int groupEnd = groupStart + groups.getValueCount(groupPosition); + for (int g = groupStart; g < groupEnd; g++) { + int groupId = groups.getInt(g); + float vValue = vVector.getFloat(valuesPosition); + long extraValue = extraVector.getLong(valuesPosition); + TopFloatLongAggregator.combine(state, groupId, vValue, extraValue); + } + } + } + + @Override + public void addIntermediateInput(int positionOffset, IntArrayBlock groups, Page page) { + state.enableGroupIdTracking(new SeenGroupIds.Empty()); + assert channels.size() == intermediateBlockCount(); + Block topUncast = page.getBlock(channels.get(0)); + if (topUncast.areAllValuesNull()) { + return; + } + FloatBlock top = (FloatBlock) topUncast; + Block extraUncast = page.getBlock(channels.get(1)); + if (extraUncast.areAllValuesNull()) { + return; + } + LongBlock extra = (LongBlock) extraUncast; + assert top.getPositionCount() == extra.getPositionCount(); + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + if (groups.isNull(groupPosition)) { + continue; + } + int groupStart = groups.getFirstValueIndex(groupPosition); + int groupEnd = groupStart + groups.getValueCount(groupPosition); + for (int g = groupStart; g < groupEnd; g++) { + int groupId = groups.getInt(g); + int valuesPosition = groupPosition + positionOffset; + TopFloatLongAggregator.combineIntermediate(state, groupId, top, extra, valuesPosition); + } + } + } + + private void addRawInput(int positionOffset, IntBigArrayBlock groups, FloatBlock vBlock, + LongBlock extraBlock) { + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + if (groups.isNull(groupPosition)) { + continue; + } + int valuesPosition = groupPosition + positionOffset; + if (vBlock.isNull(valuesPosition)) { + continue; + } + if (extraBlock.isNull(valuesPosition)) { + continue; + } + int groupStart = groups.getFirstValueIndex(groupPosition); + int groupEnd = groupStart + groups.getValueCount(groupPosition); + for (int g = groupStart; g < groupEnd; g++) { + int groupId = groups.getInt(g); + int vStart = vBlock.getFirstValueIndex(valuesPosition); + int vEnd = vStart + vBlock.getValueCount(valuesPosition); + for (int vOffset = vStart; vOffset < vEnd; vOffset++) { + float vValue = vBlock.getFloat(vOffset); + int extraStart = extraBlock.getFirstValueIndex(valuesPosition); + int extraEnd = extraStart + extraBlock.getValueCount(valuesPosition); + for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { + long extraValue = extraBlock.getLong(extraOffset); + TopFloatLongAggregator.combine(state, groupId, vValue, extraValue); + } + } + } + } + } + + private void addRawInput(int positionOffset, IntBigArrayBlock groups, FloatVector vVector, + LongVector extraVector) { + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + if (groups.isNull(groupPosition)) { + continue; + } + int valuesPosition = groupPosition + positionOffset; + int groupStart = groups.getFirstValueIndex(groupPosition); + int groupEnd = groupStart + groups.getValueCount(groupPosition); + for (int g = groupStart; g < groupEnd; g++) { + int groupId = groups.getInt(g); + float vValue = vVector.getFloat(valuesPosition); + long extraValue = extraVector.getLong(valuesPosition); + TopFloatLongAggregator.combine(state, groupId, vValue, extraValue); + } + } + } + + @Override + public void addIntermediateInput(int positionOffset, IntBigArrayBlock groups, Page page) { + state.enableGroupIdTracking(new SeenGroupIds.Empty()); + assert channels.size() == intermediateBlockCount(); + Block topUncast = page.getBlock(channels.get(0)); + if (topUncast.areAllValuesNull()) { + return; + } + FloatBlock top = (FloatBlock) topUncast; + Block extraUncast = page.getBlock(channels.get(1)); + if (extraUncast.areAllValuesNull()) { + return; + } + LongBlock extra = (LongBlock) extraUncast; + assert top.getPositionCount() == extra.getPositionCount(); + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + if (groups.isNull(groupPosition)) { + continue; + } + int groupStart = groups.getFirstValueIndex(groupPosition); + int groupEnd = groupStart + groups.getValueCount(groupPosition); + for (int g = groupStart; g < groupEnd; g++) { + int groupId = groups.getInt(g); + int valuesPosition = groupPosition + positionOffset; + TopFloatLongAggregator.combineIntermediate(state, groupId, top, extra, valuesPosition); + } + } + } + + private void addRawInput(int positionOffset, IntVector groups, FloatBlock vBlock, + LongBlock extraBlock) { + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + int valuesPosition = groupPosition + positionOffset; + if (vBlock.isNull(valuesPosition)) { + continue; + } + if (extraBlock.isNull(valuesPosition)) { + continue; + } + int groupId = groups.getInt(groupPosition); + int vStart = vBlock.getFirstValueIndex(valuesPosition); + int vEnd = vStart + vBlock.getValueCount(valuesPosition); + for (int vOffset = vStart; vOffset < vEnd; vOffset++) { + float vValue = vBlock.getFloat(vOffset); + int extraStart = extraBlock.getFirstValueIndex(valuesPosition); + int extraEnd = extraStart + extraBlock.getValueCount(valuesPosition); + for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { + long extraValue = extraBlock.getLong(extraOffset); + TopFloatLongAggregator.combine(state, groupId, vValue, extraValue); + } + } + } + } + + private void addRawInput(int positionOffset, IntVector groups, FloatVector vVector, + LongVector extraVector) { + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + int valuesPosition = groupPosition + positionOffset; + int groupId = groups.getInt(groupPosition); + float vValue = vVector.getFloat(valuesPosition); + long extraValue = extraVector.getLong(valuesPosition); + TopFloatLongAggregator.combine(state, groupId, vValue, extraValue); + } + } + + @Override + public void addIntermediateInput(int positionOffset, IntVector groups, Page page) { + state.enableGroupIdTracking(new SeenGroupIds.Empty()); + assert channels.size() == intermediateBlockCount(); + Block topUncast = page.getBlock(channels.get(0)); + if (topUncast.areAllValuesNull()) { + return; + } + FloatBlock top = (FloatBlock) topUncast; + Block extraUncast = page.getBlock(channels.get(1)); + if (extraUncast.areAllValuesNull()) { + return; + } + LongBlock extra = (LongBlock) extraUncast; + assert top.getPositionCount() == extra.getPositionCount(); + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + int groupId = groups.getInt(groupPosition); + int valuesPosition = groupPosition + positionOffset; + TopFloatLongAggregator.combineIntermediate(state, groupId, top, extra, valuesPosition); + } + } + + private void maybeEnableGroupIdTracking(SeenGroupIds seenGroupIds, FloatBlock vBlock, + LongBlock extraBlock) { + if (vBlock.mayHaveNulls()) { + state.enableGroupIdTracking(seenGroupIds); + } + if (extraBlock.mayHaveNulls()) { + state.enableGroupIdTracking(seenGroupIds); + } + } + + @Override + public void selectedMayContainUnseenGroups(SeenGroupIds seenGroupIds) { + state.enableGroupIdTracking(seenGroupIds); + } + + @Override + public void evaluateIntermediate(Block[] blocks, int offset, IntVector selected) { + state.toIntermediate(blocks, offset, selected, driverContext); + } + + @Override + public void evaluateFinal(Block[] blocks, int offset, IntVector selected, + GroupingAggregatorEvaluationContext ctx) { + blocks[offset] = TopFloatLongAggregator.evaluateFinal(state, selected, ctx); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append(getClass().getSimpleName()).append("["); + sb.append("channels=").append(channels); + sb.append("]"); + return sb.toString(); + } + + @Override + public void close() { + state.close(); + } +} diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntDoubleAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntDoubleAggregatorFunction.java new file mode 100644 index 0000000000000..47923fda31567 --- /dev/null +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntDoubleAggregatorFunction.java @@ -0,0 +1,215 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License +// 2.0; you may not use this file except in compliance with the Elastic License +// 2.0. +package org.elasticsearch.compute.aggregation; + +import java.lang.Integer; +import java.lang.Override; +import java.lang.String; +import java.lang.StringBuilder; +import java.util.List; +import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.BooleanVector; +import org.elasticsearch.compute.data.DoubleBlock; +import org.elasticsearch.compute.data.DoubleVector; +import org.elasticsearch.compute.data.ElementType; +import org.elasticsearch.compute.data.IntBlock; +import org.elasticsearch.compute.data.IntVector; +import org.elasticsearch.compute.data.Page; +import org.elasticsearch.compute.operator.DriverContext; + +/** + * {@link AggregatorFunction} implementation for {@link TopIntDoubleAggregator}. + * This class is generated. Edit {@code AggregatorImplementer} instead. + */ +public final class TopIntDoubleAggregatorFunction implements AggregatorFunction { + private static final List INTERMEDIATE_STATE_DESC = List.of( + new IntermediateStateDesc("top", ElementType.INT), + new IntermediateStateDesc("extra", ElementType.DOUBLE) ); + + private final DriverContext driverContext; + + private final TopIntDoubleAggregator.SingleState state; + + private final List channels; + + private final int limit; + + private final boolean ascending; + + public TopIntDoubleAggregatorFunction(DriverContext driverContext, List channels, + TopIntDoubleAggregator.SingleState state, int limit, boolean ascending) { + this.driverContext = driverContext; + this.channels = channels; + this.state = state; + this.limit = limit; + this.ascending = ascending; + } + + public static TopIntDoubleAggregatorFunction create(DriverContext driverContext, + List channels, int limit, boolean ascending) { + return new TopIntDoubleAggregatorFunction(driverContext, channels, TopIntDoubleAggregator.initSingle(driverContext.bigArrays(), limit, ascending), limit, ascending); + } + + public static List intermediateStateDesc() { + return INTERMEDIATE_STATE_DESC; + } + + @Override + public int intermediateBlockCount() { + return INTERMEDIATE_STATE_DESC.size(); + } + + @Override + public void addRawInput(Page page, BooleanVector mask) { + if (mask.allFalse()) { + // Entire page masked away + } else if (mask.allTrue()) { + addRawInputNotMasked(page); + } else { + addRawInputMasked(page, mask); + } + } + + private void addRawInputMasked(Page page, BooleanVector mask) { + IntBlock vBlock = page.getBlock(channels.get(0)); + DoubleBlock extraBlock = page.getBlock(channels.get(1)); + IntVector vVector = vBlock.asVector(); + if (vVector == null) { + addRawBlock(vBlock, extraBlock, mask); + return; + } + DoubleVector extraVector = extraBlock.asVector(); + if (extraVector == null) { + addRawBlock(vBlock, extraBlock, mask); + return; + } + addRawVector(vVector, extraVector, mask); + } + + private void addRawInputNotMasked(Page page) { + IntBlock vBlock = page.getBlock(channels.get(0)); + DoubleBlock extraBlock = page.getBlock(channels.get(1)); + IntVector vVector = vBlock.asVector(); + if (vVector == null) { + addRawBlock(vBlock, extraBlock); + return; + } + DoubleVector extraVector = extraBlock.asVector(); + if (extraVector == null) { + addRawBlock(vBlock, extraBlock); + return; + } + addRawVector(vVector, extraVector); + } + + private void addRawVector(IntVector vVector, DoubleVector extraVector) { + for (int valuesPosition = 0; valuesPosition < vVector.getPositionCount(); valuesPosition++) { + int vValue = vVector.getInt(valuesPosition); + double extraValue = extraVector.getDouble(valuesPosition); + TopIntDoubleAggregator.combine(state, vValue, extraValue); + } + } + + private void addRawVector(IntVector vVector, DoubleVector extraVector, BooleanVector mask) { + for (int valuesPosition = 0; valuesPosition < vVector.getPositionCount(); valuesPosition++) { + if (mask.getBoolean(valuesPosition) == false) { + continue; + } + int vValue = vVector.getInt(valuesPosition); + double extraValue = extraVector.getDouble(valuesPosition); + TopIntDoubleAggregator.combine(state, vValue, extraValue); + } + } + + private void addRawBlock(IntBlock vBlock, DoubleBlock extraBlock) { + for (int p = 0; p < vBlock.getPositionCount(); p++) { + if (vBlock.isNull(p)) { + continue; + } + if (extraBlock.isNull(p)) { + continue; + } + int vStart = vBlock.getFirstValueIndex(p); + int vEnd = vStart + vBlock.getValueCount(p); + for (int vOffset = vStart; vOffset < vEnd; vOffset++) { + int vValue = vBlock.getInt(vOffset); + int extraStart = extraBlock.getFirstValueIndex(p); + int extraEnd = extraStart + extraBlock.getValueCount(p); + for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { + double extraValue = extraBlock.getDouble(extraOffset); + TopIntDoubleAggregator.combine(state, vValue, extraValue); + } + } + } + } + + private void addRawBlock(IntBlock vBlock, DoubleBlock extraBlock, BooleanVector mask) { + for (int p = 0; p < vBlock.getPositionCount(); p++) { + if (mask.getBoolean(p) == false) { + continue; + } + if (vBlock.isNull(p)) { + continue; + } + if (extraBlock.isNull(p)) { + continue; + } + int vStart = vBlock.getFirstValueIndex(p); + int vEnd = vStart + vBlock.getValueCount(p); + for (int vOffset = vStart; vOffset < vEnd; vOffset++) { + int vValue = vBlock.getInt(vOffset); + int extraStart = extraBlock.getFirstValueIndex(p); + int extraEnd = extraStart + extraBlock.getValueCount(p); + for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { + double extraValue = extraBlock.getDouble(extraOffset); + TopIntDoubleAggregator.combine(state, vValue, extraValue); + } + } + } + } + + @Override + public void addIntermediateInput(Page page) { + assert channels.size() == intermediateBlockCount(); + assert page.getBlockCount() >= channels.get(0) + intermediateStateDesc().size(); + Block topUncast = page.getBlock(channels.get(0)); + if (topUncast.areAllValuesNull()) { + return; + } + IntBlock top = (IntBlock) topUncast; + assert top.getPositionCount() == 1; + Block extraUncast = page.getBlock(channels.get(1)); + if (extraUncast.areAllValuesNull()) { + return; + } + DoubleBlock extra = (DoubleBlock) extraUncast; + assert extra.getPositionCount() == 1; + TopIntDoubleAggregator.combineIntermediate(state, top, extra); + } + + @Override + public void evaluateIntermediate(Block[] blocks, int offset, DriverContext driverContext) { + state.toIntermediate(blocks, offset, driverContext); + } + + @Override + public void evaluateFinal(Block[] blocks, int offset, DriverContext driverContext) { + blocks[offset] = TopIntDoubleAggregator.evaluateFinal(state, driverContext); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append(getClass().getSimpleName()).append("["); + sb.append("channels=").append(channels); + sb.append("]"); + return sb.toString(); + } + + @Override + public void close() { + state.close(); + } +} diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntDoubleAggregatorFunctionSupplier.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntDoubleAggregatorFunctionSupplier.java new file mode 100644 index 0000000000000..038447c14d235 --- /dev/null +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntDoubleAggregatorFunctionSupplier.java @@ -0,0 +1,53 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License +// 2.0; you may not use this file except in compliance with the Elastic License +// 2.0. +package org.elasticsearch.compute.aggregation; + +import java.lang.Integer; +import java.lang.Override; +import java.lang.String; +import java.util.List; +import org.elasticsearch.compute.operator.DriverContext; + +/** + * {@link AggregatorFunctionSupplier} implementation for {@link TopIntDoubleAggregator}. + * This class is generated. Edit {@code AggregatorFunctionSupplierImplementer} instead. + */ +public final class TopIntDoubleAggregatorFunctionSupplier implements AggregatorFunctionSupplier { + private final int limit; + + private final boolean ascending; + + public TopIntDoubleAggregatorFunctionSupplier(int limit, boolean ascending) { + this.limit = limit; + this.ascending = ascending; + } + + @Override + public List nonGroupingIntermediateStateDesc() { + return TopIntDoubleAggregatorFunction.intermediateStateDesc(); + } + + @Override + public List groupingIntermediateStateDesc() { + return TopIntDoubleGroupingAggregatorFunction.intermediateStateDesc(); + } + + @Override + public TopIntDoubleAggregatorFunction aggregator(DriverContext driverContext, + List channels) { + return TopIntDoubleAggregatorFunction.create(driverContext, channels, limit, ascending); + } + + @Override + public TopIntDoubleGroupingAggregatorFunction groupingAggregator(DriverContext driverContext, + List channels) { + return TopIntDoubleGroupingAggregatorFunction.create(channels, driverContext, limit, ascending); + } + + @Override + public String describe() { + return "top_int of doubles"; + } +} diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntDoubleGroupingAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntDoubleGroupingAggregatorFunction.java new file mode 100644 index 0000000000000..b7ecbb9588f79 --- /dev/null +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntDoubleGroupingAggregatorFunction.java @@ -0,0 +1,396 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License +// 2.0; you may not use this file except in compliance with the Elastic License +// 2.0. +package org.elasticsearch.compute.aggregation; + +import java.lang.Integer; +import java.lang.Override; +import java.lang.String; +import java.lang.StringBuilder; +import java.util.List; +import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.DoubleBlock; +import org.elasticsearch.compute.data.DoubleVector; +import org.elasticsearch.compute.data.ElementType; +import org.elasticsearch.compute.data.IntArrayBlock; +import org.elasticsearch.compute.data.IntBigArrayBlock; +import org.elasticsearch.compute.data.IntBlock; +import org.elasticsearch.compute.data.IntVector; +import org.elasticsearch.compute.data.Page; +import org.elasticsearch.compute.operator.DriverContext; + +/** + * {@link GroupingAggregatorFunction} implementation for {@link TopIntDoubleAggregator}. + * This class is generated. Edit {@code GroupingAggregatorImplementer} instead. + */ +public final class TopIntDoubleGroupingAggregatorFunction implements GroupingAggregatorFunction { + private static final List INTERMEDIATE_STATE_DESC = List.of( + new IntermediateStateDesc("top", ElementType.INT), + new IntermediateStateDesc("extra", ElementType.DOUBLE) ); + + private final TopIntDoubleAggregator.GroupingState state; + + private final List channels; + + private final DriverContext driverContext; + + private final int limit; + + private final boolean ascending; + + public TopIntDoubleGroupingAggregatorFunction(List channels, + TopIntDoubleAggregator.GroupingState state, DriverContext driverContext, int limit, + boolean ascending) { + this.channels = channels; + this.state = state; + this.driverContext = driverContext; + this.limit = limit; + this.ascending = ascending; + } + + public static TopIntDoubleGroupingAggregatorFunction create(List channels, + DriverContext driverContext, int limit, boolean ascending) { + return new TopIntDoubleGroupingAggregatorFunction(channels, TopIntDoubleAggregator.initGrouping(driverContext.bigArrays(), limit, ascending), driverContext, limit, ascending); + } + + public static List intermediateStateDesc() { + return INTERMEDIATE_STATE_DESC; + } + + @Override + public int intermediateBlockCount() { + return INTERMEDIATE_STATE_DESC.size(); + } + + @Override + public GroupingAggregatorFunction.AddInput prepareProcessRawInputPage(SeenGroupIds seenGroupIds, + Page page) { + IntBlock vBlock = page.getBlock(channels.get(0)); + DoubleBlock extraBlock = page.getBlock(channels.get(1)); + IntVector vVector = vBlock.asVector(); + if (vVector == null) { + maybeEnableGroupIdTracking(seenGroupIds, vBlock, extraBlock); + return new GroupingAggregatorFunction.AddInput() { + @Override + public void add(int positionOffset, IntArrayBlock groupIds) { + addRawInput(positionOffset, groupIds, vBlock, extraBlock); + } + + @Override + public void add(int positionOffset, IntBigArrayBlock groupIds) { + addRawInput(positionOffset, groupIds, vBlock, extraBlock); + } + + @Override + public void add(int positionOffset, IntVector groupIds) { + addRawInput(positionOffset, groupIds, vBlock, extraBlock); + } + + @Override + public void close() { + } + }; + } + DoubleVector extraVector = extraBlock.asVector(); + if (extraVector == null) { + maybeEnableGroupIdTracking(seenGroupIds, vBlock, extraBlock); + return new GroupingAggregatorFunction.AddInput() { + @Override + public void add(int positionOffset, IntArrayBlock groupIds) { + addRawInput(positionOffset, groupIds, vBlock, extraBlock); + } + + @Override + public void add(int positionOffset, IntBigArrayBlock groupIds) { + addRawInput(positionOffset, groupIds, vBlock, extraBlock); + } + + @Override + public void add(int positionOffset, IntVector groupIds) { + addRawInput(positionOffset, groupIds, vBlock, extraBlock); + } + + @Override + public void close() { + } + }; + } + return new GroupingAggregatorFunction.AddInput() { + @Override + public void add(int positionOffset, IntArrayBlock groupIds) { + addRawInput(positionOffset, groupIds, vVector, extraVector); + } + + @Override + public void add(int positionOffset, IntBigArrayBlock groupIds) { + addRawInput(positionOffset, groupIds, vVector, extraVector); + } + + @Override + public void add(int positionOffset, IntVector groupIds) { + addRawInput(positionOffset, groupIds, vVector, extraVector); + } + + @Override + public void close() { + } + }; + } + + private void addRawInput(int positionOffset, IntArrayBlock groups, IntBlock vBlock, + DoubleBlock extraBlock) { + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + if (groups.isNull(groupPosition)) { + continue; + } + int valuesPosition = groupPosition + positionOffset; + if (vBlock.isNull(valuesPosition)) { + continue; + } + if (extraBlock.isNull(valuesPosition)) { + continue; + } + int groupStart = groups.getFirstValueIndex(groupPosition); + int groupEnd = groupStart + groups.getValueCount(groupPosition); + for (int g = groupStart; g < groupEnd; g++) { + int groupId = groups.getInt(g); + int vStart = vBlock.getFirstValueIndex(valuesPosition); + int vEnd = vStart + vBlock.getValueCount(valuesPosition); + for (int vOffset = vStart; vOffset < vEnd; vOffset++) { + int vValue = vBlock.getInt(vOffset); + int extraStart = extraBlock.getFirstValueIndex(valuesPosition); + int extraEnd = extraStart + extraBlock.getValueCount(valuesPosition); + for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { + double extraValue = extraBlock.getDouble(extraOffset); + TopIntDoubleAggregator.combine(state, groupId, vValue, extraValue); + } + } + } + } + } + + private void addRawInput(int positionOffset, IntArrayBlock groups, IntVector vVector, + DoubleVector extraVector) { + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + if (groups.isNull(groupPosition)) { + continue; + } + int valuesPosition = groupPosition + positionOffset; + int groupStart = groups.getFirstValueIndex(groupPosition); + int groupEnd = groupStart + groups.getValueCount(groupPosition); + for (int g = groupStart; g < groupEnd; g++) { + int groupId = groups.getInt(g); + int vValue = vVector.getInt(valuesPosition); + double extraValue = extraVector.getDouble(valuesPosition); + TopIntDoubleAggregator.combine(state, groupId, vValue, extraValue); + } + } + } + + @Override + public void addIntermediateInput(int positionOffset, IntArrayBlock groups, Page page) { + state.enableGroupIdTracking(new SeenGroupIds.Empty()); + assert channels.size() == intermediateBlockCount(); + Block topUncast = page.getBlock(channels.get(0)); + if (topUncast.areAllValuesNull()) { + return; + } + IntBlock top = (IntBlock) topUncast; + Block extraUncast = page.getBlock(channels.get(1)); + if (extraUncast.areAllValuesNull()) { + return; + } + DoubleBlock extra = (DoubleBlock) extraUncast; + assert top.getPositionCount() == extra.getPositionCount(); + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + if (groups.isNull(groupPosition)) { + continue; + } + int groupStart = groups.getFirstValueIndex(groupPosition); + int groupEnd = groupStart + groups.getValueCount(groupPosition); + for (int g = groupStart; g < groupEnd; g++) { + int groupId = groups.getInt(g); + int valuesPosition = groupPosition + positionOffset; + TopIntDoubleAggregator.combineIntermediate(state, groupId, top, extra, valuesPosition); + } + } + } + + private void addRawInput(int positionOffset, IntBigArrayBlock groups, IntBlock vBlock, + DoubleBlock extraBlock) { + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + if (groups.isNull(groupPosition)) { + continue; + } + int valuesPosition = groupPosition + positionOffset; + if (vBlock.isNull(valuesPosition)) { + continue; + } + if (extraBlock.isNull(valuesPosition)) { + continue; + } + int groupStart = groups.getFirstValueIndex(groupPosition); + int groupEnd = groupStart + groups.getValueCount(groupPosition); + for (int g = groupStart; g < groupEnd; g++) { + int groupId = groups.getInt(g); + int vStart = vBlock.getFirstValueIndex(valuesPosition); + int vEnd = vStart + vBlock.getValueCount(valuesPosition); + for (int vOffset = vStart; vOffset < vEnd; vOffset++) { + int vValue = vBlock.getInt(vOffset); + int extraStart = extraBlock.getFirstValueIndex(valuesPosition); + int extraEnd = extraStart + extraBlock.getValueCount(valuesPosition); + for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { + double extraValue = extraBlock.getDouble(extraOffset); + TopIntDoubleAggregator.combine(state, groupId, vValue, extraValue); + } + } + } + } + } + + private void addRawInput(int positionOffset, IntBigArrayBlock groups, IntVector vVector, + DoubleVector extraVector) { + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + if (groups.isNull(groupPosition)) { + continue; + } + int valuesPosition = groupPosition + positionOffset; + int groupStart = groups.getFirstValueIndex(groupPosition); + int groupEnd = groupStart + groups.getValueCount(groupPosition); + for (int g = groupStart; g < groupEnd; g++) { + int groupId = groups.getInt(g); + int vValue = vVector.getInt(valuesPosition); + double extraValue = extraVector.getDouble(valuesPosition); + TopIntDoubleAggregator.combine(state, groupId, vValue, extraValue); + } + } + } + + @Override + public void addIntermediateInput(int positionOffset, IntBigArrayBlock groups, Page page) { + state.enableGroupIdTracking(new SeenGroupIds.Empty()); + assert channels.size() == intermediateBlockCount(); + Block topUncast = page.getBlock(channels.get(0)); + if (topUncast.areAllValuesNull()) { + return; + } + IntBlock top = (IntBlock) topUncast; + Block extraUncast = page.getBlock(channels.get(1)); + if (extraUncast.areAllValuesNull()) { + return; + } + DoubleBlock extra = (DoubleBlock) extraUncast; + assert top.getPositionCount() == extra.getPositionCount(); + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + if (groups.isNull(groupPosition)) { + continue; + } + int groupStart = groups.getFirstValueIndex(groupPosition); + int groupEnd = groupStart + groups.getValueCount(groupPosition); + for (int g = groupStart; g < groupEnd; g++) { + int groupId = groups.getInt(g); + int valuesPosition = groupPosition + positionOffset; + TopIntDoubleAggregator.combineIntermediate(state, groupId, top, extra, valuesPosition); + } + } + } + + private void addRawInput(int positionOffset, IntVector groups, IntBlock vBlock, + DoubleBlock extraBlock) { + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + int valuesPosition = groupPosition + positionOffset; + if (vBlock.isNull(valuesPosition)) { + continue; + } + if (extraBlock.isNull(valuesPosition)) { + continue; + } + int groupId = groups.getInt(groupPosition); + int vStart = vBlock.getFirstValueIndex(valuesPosition); + int vEnd = vStart + vBlock.getValueCount(valuesPosition); + for (int vOffset = vStart; vOffset < vEnd; vOffset++) { + int vValue = vBlock.getInt(vOffset); + int extraStart = extraBlock.getFirstValueIndex(valuesPosition); + int extraEnd = extraStart + extraBlock.getValueCount(valuesPosition); + for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { + double extraValue = extraBlock.getDouble(extraOffset); + TopIntDoubleAggregator.combine(state, groupId, vValue, extraValue); + } + } + } + } + + private void addRawInput(int positionOffset, IntVector groups, IntVector vVector, + DoubleVector extraVector) { + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + int valuesPosition = groupPosition + positionOffset; + int groupId = groups.getInt(groupPosition); + int vValue = vVector.getInt(valuesPosition); + double extraValue = extraVector.getDouble(valuesPosition); + TopIntDoubleAggregator.combine(state, groupId, vValue, extraValue); + } + } + + @Override + public void addIntermediateInput(int positionOffset, IntVector groups, Page page) { + state.enableGroupIdTracking(new SeenGroupIds.Empty()); + assert channels.size() == intermediateBlockCount(); + Block topUncast = page.getBlock(channels.get(0)); + if (topUncast.areAllValuesNull()) { + return; + } + IntBlock top = (IntBlock) topUncast; + Block extraUncast = page.getBlock(channels.get(1)); + if (extraUncast.areAllValuesNull()) { + return; + } + DoubleBlock extra = (DoubleBlock) extraUncast; + assert top.getPositionCount() == extra.getPositionCount(); + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + int groupId = groups.getInt(groupPosition); + int valuesPosition = groupPosition + positionOffset; + TopIntDoubleAggregator.combineIntermediate(state, groupId, top, extra, valuesPosition); + } + } + + private void maybeEnableGroupIdTracking(SeenGroupIds seenGroupIds, IntBlock vBlock, + DoubleBlock extraBlock) { + if (vBlock.mayHaveNulls()) { + state.enableGroupIdTracking(seenGroupIds); + } + if (extraBlock.mayHaveNulls()) { + state.enableGroupIdTracking(seenGroupIds); + } + } + + @Override + public void selectedMayContainUnseenGroups(SeenGroupIds seenGroupIds) { + state.enableGroupIdTracking(seenGroupIds); + } + + @Override + public void evaluateIntermediate(Block[] blocks, int offset, IntVector selected) { + state.toIntermediate(blocks, offset, selected, driverContext); + } + + @Override + public void evaluateFinal(Block[] blocks, int offset, IntVector selected, + GroupingAggregatorEvaluationContext ctx) { + blocks[offset] = TopIntDoubleAggregator.evaluateFinal(state, selected, ctx); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append(getClass().getSimpleName()).append("["); + sb.append("channels=").append(channels); + sb.append("]"); + return sb.toString(); + } + + @Override + public void close() { + state.close(); + } +} diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntFloatAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntFloatAggregatorFunction.java new file mode 100644 index 0000000000000..45001027d9a2c --- /dev/null +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntFloatAggregatorFunction.java @@ -0,0 +1,215 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License +// 2.0; you may not use this file except in compliance with the Elastic License +// 2.0. +package org.elasticsearch.compute.aggregation; + +import java.lang.Integer; +import java.lang.Override; +import java.lang.String; +import java.lang.StringBuilder; +import java.util.List; +import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.BooleanVector; +import org.elasticsearch.compute.data.ElementType; +import org.elasticsearch.compute.data.FloatBlock; +import org.elasticsearch.compute.data.FloatVector; +import org.elasticsearch.compute.data.IntBlock; +import org.elasticsearch.compute.data.IntVector; +import org.elasticsearch.compute.data.Page; +import org.elasticsearch.compute.operator.DriverContext; + +/** + * {@link AggregatorFunction} implementation for {@link TopIntFloatAggregator}. + * This class is generated. Edit {@code AggregatorImplementer} instead. + */ +public final class TopIntFloatAggregatorFunction implements AggregatorFunction { + private static final List INTERMEDIATE_STATE_DESC = List.of( + new IntermediateStateDesc("top", ElementType.INT), + new IntermediateStateDesc("extra", ElementType.FLOAT) ); + + private final DriverContext driverContext; + + private final TopIntFloatAggregator.SingleState state; + + private final List channels; + + private final int limit; + + private final boolean ascending; + + public TopIntFloatAggregatorFunction(DriverContext driverContext, List channels, + TopIntFloatAggregator.SingleState state, int limit, boolean ascending) { + this.driverContext = driverContext; + this.channels = channels; + this.state = state; + this.limit = limit; + this.ascending = ascending; + } + + public static TopIntFloatAggregatorFunction create(DriverContext driverContext, + List channels, int limit, boolean ascending) { + return new TopIntFloatAggregatorFunction(driverContext, channels, TopIntFloatAggregator.initSingle(driverContext.bigArrays(), limit, ascending), limit, ascending); + } + + public static List intermediateStateDesc() { + return INTERMEDIATE_STATE_DESC; + } + + @Override + public int intermediateBlockCount() { + return INTERMEDIATE_STATE_DESC.size(); + } + + @Override + public void addRawInput(Page page, BooleanVector mask) { + if (mask.allFalse()) { + // Entire page masked away + } else if (mask.allTrue()) { + addRawInputNotMasked(page); + } else { + addRawInputMasked(page, mask); + } + } + + private void addRawInputMasked(Page page, BooleanVector mask) { + IntBlock vBlock = page.getBlock(channels.get(0)); + FloatBlock extraBlock = page.getBlock(channels.get(1)); + IntVector vVector = vBlock.asVector(); + if (vVector == null) { + addRawBlock(vBlock, extraBlock, mask); + return; + } + FloatVector extraVector = extraBlock.asVector(); + if (extraVector == null) { + addRawBlock(vBlock, extraBlock, mask); + return; + } + addRawVector(vVector, extraVector, mask); + } + + private void addRawInputNotMasked(Page page) { + IntBlock vBlock = page.getBlock(channels.get(0)); + FloatBlock extraBlock = page.getBlock(channels.get(1)); + IntVector vVector = vBlock.asVector(); + if (vVector == null) { + addRawBlock(vBlock, extraBlock); + return; + } + FloatVector extraVector = extraBlock.asVector(); + if (extraVector == null) { + addRawBlock(vBlock, extraBlock); + return; + } + addRawVector(vVector, extraVector); + } + + private void addRawVector(IntVector vVector, FloatVector extraVector) { + for (int valuesPosition = 0; valuesPosition < vVector.getPositionCount(); valuesPosition++) { + int vValue = vVector.getInt(valuesPosition); + float extraValue = extraVector.getFloat(valuesPosition); + TopIntFloatAggregator.combine(state, vValue, extraValue); + } + } + + private void addRawVector(IntVector vVector, FloatVector extraVector, BooleanVector mask) { + for (int valuesPosition = 0; valuesPosition < vVector.getPositionCount(); valuesPosition++) { + if (mask.getBoolean(valuesPosition) == false) { + continue; + } + int vValue = vVector.getInt(valuesPosition); + float extraValue = extraVector.getFloat(valuesPosition); + TopIntFloatAggregator.combine(state, vValue, extraValue); + } + } + + private void addRawBlock(IntBlock vBlock, FloatBlock extraBlock) { + for (int p = 0; p < vBlock.getPositionCount(); p++) { + if (vBlock.isNull(p)) { + continue; + } + if (extraBlock.isNull(p)) { + continue; + } + int vStart = vBlock.getFirstValueIndex(p); + int vEnd = vStart + vBlock.getValueCount(p); + for (int vOffset = vStart; vOffset < vEnd; vOffset++) { + int vValue = vBlock.getInt(vOffset); + int extraStart = extraBlock.getFirstValueIndex(p); + int extraEnd = extraStart + extraBlock.getValueCount(p); + for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { + float extraValue = extraBlock.getFloat(extraOffset); + TopIntFloatAggregator.combine(state, vValue, extraValue); + } + } + } + } + + private void addRawBlock(IntBlock vBlock, FloatBlock extraBlock, BooleanVector mask) { + for (int p = 0; p < vBlock.getPositionCount(); p++) { + if (mask.getBoolean(p) == false) { + continue; + } + if (vBlock.isNull(p)) { + continue; + } + if (extraBlock.isNull(p)) { + continue; + } + int vStart = vBlock.getFirstValueIndex(p); + int vEnd = vStart + vBlock.getValueCount(p); + for (int vOffset = vStart; vOffset < vEnd; vOffset++) { + int vValue = vBlock.getInt(vOffset); + int extraStart = extraBlock.getFirstValueIndex(p); + int extraEnd = extraStart + extraBlock.getValueCount(p); + for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { + float extraValue = extraBlock.getFloat(extraOffset); + TopIntFloatAggregator.combine(state, vValue, extraValue); + } + } + } + } + + @Override + public void addIntermediateInput(Page page) { + assert channels.size() == intermediateBlockCount(); + assert page.getBlockCount() >= channels.get(0) + intermediateStateDesc().size(); + Block topUncast = page.getBlock(channels.get(0)); + if (topUncast.areAllValuesNull()) { + return; + } + IntBlock top = (IntBlock) topUncast; + assert top.getPositionCount() == 1; + Block extraUncast = page.getBlock(channels.get(1)); + if (extraUncast.areAllValuesNull()) { + return; + } + FloatBlock extra = (FloatBlock) extraUncast; + assert extra.getPositionCount() == 1; + TopIntFloatAggregator.combineIntermediate(state, top, extra); + } + + @Override + public void evaluateIntermediate(Block[] blocks, int offset, DriverContext driverContext) { + state.toIntermediate(blocks, offset, driverContext); + } + + @Override + public void evaluateFinal(Block[] blocks, int offset, DriverContext driverContext) { + blocks[offset] = TopIntFloatAggregator.evaluateFinal(state, driverContext); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append(getClass().getSimpleName()).append("["); + sb.append("channels=").append(channels); + sb.append("]"); + return sb.toString(); + } + + @Override + public void close() { + state.close(); + } +} diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntFloatAggregatorFunctionSupplier.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntFloatAggregatorFunctionSupplier.java new file mode 100644 index 0000000000000..a71fc5830b8fc --- /dev/null +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntFloatAggregatorFunctionSupplier.java @@ -0,0 +1,53 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License +// 2.0; you may not use this file except in compliance with the Elastic License +// 2.0. +package org.elasticsearch.compute.aggregation; + +import java.lang.Integer; +import java.lang.Override; +import java.lang.String; +import java.util.List; +import org.elasticsearch.compute.operator.DriverContext; + +/** + * {@link AggregatorFunctionSupplier} implementation for {@link TopIntFloatAggregator}. + * This class is generated. Edit {@code AggregatorFunctionSupplierImplementer} instead. + */ +public final class TopIntFloatAggregatorFunctionSupplier implements AggregatorFunctionSupplier { + private final int limit; + + private final boolean ascending; + + public TopIntFloatAggregatorFunctionSupplier(int limit, boolean ascending) { + this.limit = limit; + this.ascending = ascending; + } + + @Override + public List nonGroupingIntermediateStateDesc() { + return TopIntFloatAggregatorFunction.intermediateStateDesc(); + } + + @Override + public List groupingIntermediateStateDesc() { + return TopIntFloatGroupingAggregatorFunction.intermediateStateDesc(); + } + + @Override + public TopIntFloatAggregatorFunction aggregator(DriverContext driverContext, + List channels) { + return TopIntFloatAggregatorFunction.create(driverContext, channels, limit, ascending); + } + + @Override + public TopIntFloatGroupingAggregatorFunction groupingAggregator(DriverContext driverContext, + List channels) { + return TopIntFloatGroupingAggregatorFunction.create(channels, driverContext, limit, ascending); + } + + @Override + public String describe() { + return "top_int of floats"; + } +} diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntFloatGroupingAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntFloatGroupingAggregatorFunction.java new file mode 100644 index 0000000000000..aa8b624a8d9c3 --- /dev/null +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntFloatGroupingAggregatorFunction.java @@ -0,0 +1,396 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License +// 2.0; you may not use this file except in compliance with the Elastic License +// 2.0. +package org.elasticsearch.compute.aggregation; + +import java.lang.Integer; +import java.lang.Override; +import java.lang.String; +import java.lang.StringBuilder; +import java.util.List; +import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.ElementType; +import org.elasticsearch.compute.data.FloatBlock; +import org.elasticsearch.compute.data.FloatVector; +import org.elasticsearch.compute.data.IntArrayBlock; +import org.elasticsearch.compute.data.IntBigArrayBlock; +import org.elasticsearch.compute.data.IntBlock; +import org.elasticsearch.compute.data.IntVector; +import org.elasticsearch.compute.data.Page; +import org.elasticsearch.compute.operator.DriverContext; + +/** + * {@link GroupingAggregatorFunction} implementation for {@link TopIntFloatAggregator}. + * This class is generated. Edit {@code GroupingAggregatorImplementer} instead. + */ +public final class TopIntFloatGroupingAggregatorFunction implements GroupingAggregatorFunction { + private static final List INTERMEDIATE_STATE_DESC = List.of( + new IntermediateStateDesc("top", ElementType.INT), + new IntermediateStateDesc("extra", ElementType.FLOAT) ); + + private final TopIntFloatAggregator.GroupingState state; + + private final List channels; + + private final DriverContext driverContext; + + private final int limit; + + private final boolean ascending; + + public TopIntFloatGroupingAggregatorFunction(List channels, + TopIntFloatAggregator.GroupingState state, DriverContext driverContext, int limit, + boolean ascending) { + this.channels = channels; + this.state = state; + this.driverContext = driverContext; + this.limit = limit; + this.ascending = ascending; + } + + public static TopIntFloatGroupingAggregatorFunction create(List channels, + DriverContext driverContext, int limit, boolean ascending) { + return new TopIntFloatGroupingAggregatorFunction(channels, TopIntFloatAggregator.initGrouping(driverContext.bigArrays(), limit, ascending), driverContext, limit, ascending); + } + + public static List intermediateStateDesc() { + return INTERMEDIATE_STATE_DESC; + } + + @Override + public int intermediateBlockCount() { + return INTERMEDIATE_STATE_DESC.size(); + } + + @Override + public GroupingAggregatorFunction.AddInput prepareProcessRawInputPage(SeenGroupIds seenGroupIds, + Page page) { + IntBlock vBlock = page.getBlock(channels.get(0)); + FloatBlock extraBlock = page.getBlock(channels.get(1)); + IntVector vVector = vBlock.asVector(); + if (vVector == null) { + maybeEnableGroupIdTracking(seenGroupIds, vBlock, extraBlock); + return new GroupingAggregatorFunction.AddInput() { + @Override + public void add(int positionOffset, IntArrayBlock groupIds) { + addRawInput(positionOffset, groupIds, vBlock, extraBlock); + } + + @Override + public void add(int positionOffset, IntBigArrayBlock groupIds) { + addRawInput(positionOffset, groupIds, vBlock, extraBlock); + } + + @Override + public void add(int positionOffset, IntVector groupIds) { + addRawInput(positionOffset, groupIds, vBlock, extraBlock); + } + + @Override + public void close() { + } + }; + } + FloatVector extraVector = extraBlock.asVector(); + if (extraVector == null) { + maybeEnableGroupIdTracking(seenGroupIds, vBlock, extraBlock); + return new GroupingAggregatorFunction.AddInput() { + @Override + public void add(int positionOffset, IntArrayBlock groupIds) { + addRawInput(positionOffset, groupIds, vBlock, extraBlock); + } + + @Override + public void add(int positionOffset, IntBigArrayBlock groupIds) { + addRawInput(positionOffset, groupIds, vBlock, extraBlock); + } + + @Override + public void add(int positionOffset, IntVector groupIds) { + addRawInput(positionOffset, groupIds, vBlock, extraBlock); + } + + @Override + public void close() { + } + }; + } + return new GroupingAggregatorFunction.AddInput() { + @Override + public void add(int positionOffset, IntArrayBlock groupIds) { + addRawInput(positionOffset, groupIds, vVector, extraVector); + } + + @Override + public void add(int positionOffset, IntBigArrayBlock groupIds) { + addRawInput(positionOffset, groupIds, vVector, extraVector); + } + + @Override + public void add(int positionOffset, IntVector groupIds) { + addRawInput(positionOffset, groupIds, vVector, extraVector); + } + + @Override + public void close() { + } + }; + } + + private void addRawInput(int positionOffset, IntArrayBlock groups, IntBlock vBlock, + FloatBlock extraBlock) { + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + if (groups.isNull(groupPosition)) { + continue; + } + int valuesPosition = groupPosition + positionOffset; + if (vBlock.isNull(valuesPosition)) { + continue; + } + if (extraBlock.isNull(valuesPosition)) { + continue; + } + int groupStart = groups.getFirstValueIndex(groupPosition); + int groupEnd = groupStart + groups.getValueCount(groupPosition); + for (int g = groupStart; g < groupEnd; g++) { + int groupId = groups.getInt(g); + int vStart = vBlock.getFirstValueIndex(valuesPosition); + int vEnd = vStart + vBlock.getValueCount(valuesPosition); + for (int vOffset = vStart; vOffset < vEnd; vOffset++) { + int vValue = vBlock.getInt(vOffset); + int extraStart = extraBlock.getFirstValueIndex(valuesPosition); + int extraEnd = extraStart + extraBlock.getValueCount(valuesPosition); + for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { + float extraValue = extraBlock.getFloat(extraOffset); + TopIntFloatAggregator.combine(state, groupId, vValue, extraValue); + } + } + } + } + } + + private void addRawInput(int positionOffset, IntArrayBlock groups, IntVector vVector, + FloatVector extraVector) { + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + if (groups.isNull(groupPosition)) { + continue; + } + int valuesPosition = groupPosition + positionOffset; + int groupStart = groups.getFirstValueIndex(groupPosition); + int groupEnd = groupStart + groups.getValueCount(groupPosition); + for (int g = groupStart; g < groupEnd; g++) { + int groupId = groups.getInt(g); + int vValue = vVector.getInt(valuesPosition); + float extraValue = extraVector.getFloat(valuesPosition); + TopIntFloatAggregator.combine(state, groupId, vValue, extraValue); + } + } + } + + @Override + public void addIntermediateInput(int positionOffset, IntArrayBlock groups, Page page) { + state.enableGroupIdTracking(new SeenGroupIds.Empty()); + assert channels.size() == intermediateBlockCount(); + Block topUncast = page.getBlock(channels.get(0)); + if (topUncast.areAllValuesNull()) { + return; + } + IntBlock top = (IntBlock) topUncast; + Block extraUncast = page.getBlock(channels.get(1)); + if (extraUncast.areAllValuesNull()) { + return; + } + FloatBlock extra = (FloatBlock) extraUncast; + assert top.getPositionCount() == extra.getPositionCount(); + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + if (groups.isNull(groupPosition)) { + continue; + } + int groupStart = groups.getFirstValueIndex(groupPosition); + int groupEnd = groupStart + groups.getValueCount(groupPosition); + for (int g = groupStart; g < groupEnd; g++) { + int groupId = groups.getInt(g); + int valuesPosition = groupPosition + positionOffset; + TopIntFloatAggregator.combineIntermediate(state, groupId, top, extra, valuesPosition); + } + } + } + + private void addRawInput(int positionOffset, IntBigArrayBlock groups, IntBlock vBlock, + FloatBlock extraBlock) { + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + if (groups.isNull(groupPosition)) { + continue; + } + int valuesPosition = groupPosition + positionOffset; + if (vBlock.isNull(valuesPosition)) { + continue; + } + if (extraBlock.isNull(valuesPosition)) { + continue; + } + int groupStart = groups.getFirstValueIndex(groupPosition); + int groupEnd = groupStart + groups.getValueCount(groupPosition); + for (int g = groupStart; g < groupEnd; g++) { + int groupId = groups.getInt(g); + int vStart = vBlock.getFirstValueIndex(valuesPosition); + int vEnd = vStart + vBlock.getValueCount(valuesPosition); + for (int vOffset = vStart; vOffset < vEnd; vOffset++) { + int vValue = vBlock.getInt(vOffset); + int extraStart = extraBlock.getFirstValueIndex(valuesPosition); + int extraEnd = extraStart + extraBlock.getValueCount(valuesPosition); + for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { + float extraValue = extraBlock.getFloat(extraOffset); + TopIntFloatAggregator.combine(state, groupId, vValue, extraValue); + } + } + } + } + } + + private void addRawInput(int positionOffset, IntBigArrayBlock groups, IntVector vVector, + FloatVector extraVector) { + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + if (groups.isNull(groupPosition)) { + continue; + } + int valuesPosition = groupPosition + positionOffset; + int groupStart = groups.getFirstValueIndex(groupPosition); + int groupEnd = groupStart + groups.getValueCount(groupPosition); + for (int g = groupStart; g < groupEnd; g++) { + int groupId = groups.getInt(g); + int vValue = vVector.getInt(valuesPosition); + float extraValue = extraVector.getFloat(valuesPosition); + TopIntFloatAggregator.combine(state, groupId, vValue, extraValue); + } + } + } + + @Override + public void addIntermediateInput(int positionOffset, IntBigArrayBlock groups, Page page) { + state.enableGroupIdTracking(new SeenGroupIds.Empty()); + assert channels.size() == intermediateBlockCount(); + Block topUncast = page.getBlock(channels.get(0)); + if (topUncast.areAllValuesNull()) { + return; + } + IntBlock top = (IntBlock) topUncast; + Block extraUncast = page.getBlock(channels.get(1)); + if (extraUncast.areAllValuesNull()) { + return; + } + FloatBlock extra = (FloatBlock) extraUncast; + assert top.getPositionCount() == extra.getPositionCount(); + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + if (groups.isNull(groupPosition)) { + continue; + } + int groupStart = groups.getFirstValueIndex(groupPosition); + int groupEnd = groupStart + groups.getValueCount(groupPosition); + for (int g = groupStart; g < groupEnd; g++) { + int groupId = groups.getInt(g); + int valuesPosition = groupPosition + positionOffset; + TopIntFloatAggregator.combineIntermediate(state, groupId, top, extra, valuesPosition); + } + } + } + + private void addRawInput(int positionOffset, IntVector groups, IntBlock vBlock, + FloatBlock extraBlock) { + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + int valuesPosition = groupPosition + positionOffset; + if (vBlock.isNull(valuesPosition)) { + continue; + } + if (extraBlock.isNull(valuesPosition)) { + continue; + } + int groupId = groups.getInt(groupPosition); + int vStart = vBlock.getFirstValueIndex(valuesPosition); + int vEnd = vStart + vBlock.getValueCount(valuesPosition); + for (int vOffset = vStart; vOffset < vEnd; vOffset++) { + int vValue = vBlock.getInt(vOffset); + int extraStart = extraBlock.getFirstValueIndex(valuesPosition); + int extraEnd = extraStart + extraBlock.getValueCount(valuesPosition); + for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { + float extraValue = extraBlock.getFloat(extraOffset); + TopIntFloatAggregator.combine(state, groupId, vValue, extraValue); + } + } + } + } + + private void addRawInput(int positionOffset, IntVector groups, IntVector vVector, + FloatVector extraVector) { + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + int valuesPosition = groupPosition + positionOffset; + int groupId = groups.getInt(groupPosition); + int vValue = vVector.getInt(valuesPosition); + float extraValue = extraVector.getFloat(valuesPosition); + TopIntFloatAggregator.combine(state, groupId, vValue, extraValue); + } + } + + @Override + public void addIntermediateInput(int positionOffset, IntVector groups, Page page) { + state.enableGroupIdTracking(new SeenGroupIds.Empty()); + assert channels.size() == intermediateBlockCount(); + Block topUncast = page.getBlock(channels.get(0)); + if (topUncast.areAllValuesNull()) { + return; + } + IntBlock top = (IntBlock) topUncast; + Block extraUncast = page.getBlock(channels.get(1)); + if (extraUncast.areAllValuesNull()) { + return; + } + FloatBlock extra = (FloatBlock) extraUncast; + assert top.getPositionCount() == extra.getPositionCount(); + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + int groupId = groups.getInt(groupPosition); + int valuesPosition = groupPosition + positionOffset; + TopIntFloatAggregator.combineIntermediate(state, groupId, top, extra, valuesPosition); + } + } + + private void maybeEnableGroupIdTracking(SeenGroupIds seenGroupIds, IntBlock vBlock, + FloatBlock extraBlock) { + if (vBlock.mayHaveNulls()) { + state.enableGroupIdTracking(seenGroupIds); + } + if (extraBlock.mayHaveNulls()) { + state.enableGroupIdTracking(seenGroupIds); + } + } + + @Override + public void selectedMayContainUnseenGroups(SeenGroupIds seenGroupIds) { + state.enableGroupIdTracking(seenGroupIds); + } + + @Override + public void evaluateIntermediate(Block[] blocks, int offset, IntVector selected) { + state.toIntermediate(blocks, offset, selected, driverContext); + } + + @Override + public void evaluateFinal(Block[] blocks, int offset, IntVector selected, + GroupingAggregatorEvaluationContext ctx) { + blocks[offset] = TopIntFloatAggregator.evaluateFinal(state, selected, ctx); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append(getClass().getSimpleName()).append("["); + sb.append("channels=").append(channels); + sb.append("]"); + return sb.toString(); + } + + @Override + public void close() { + state.close(); + } +} diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntIntAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntIntAggregatorFunction.java new file mode 100644 index 0000000000000..e7bb2efc74f07 --- /dev/null +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntIntAggregatorFunction.java @@ -0,0 +1,213 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License +// 2.0; you may not use this file except in compliance with the Elastic License +// 2.0. +package org.elasticsearch.compute.aggregation; + +import java.lang.Integer; +import java.lang.Override; +import java.lang.String; +import java.lang.StringBuilder; +import java.util.List; +import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.BooleanVector; +import org.elasticsearch.compute.data.ElementType; +import org.elasticsearch.compute.data.IntBlock; +import org.elasticsearch.compute.data.IntVector; +import org.elasticsearch.compute.data.Page; +import org.elasticsearch.compute.operator.DriverContext; + +/** + * {@link AggregatorFunction} implementation for {@link TopIntIntAggregator}. + * This class is generated. Edit {@code AggregatorImplementer} instead. + */ +public final class TopIntIntAggregatorFunction implements AggregatorFunction { + private static final List INTERMEDIATE_STATE_DESC = List.of( + new IntermediateStateDesc("top", ElementType.INT), + new IntermediateStateDesc("extra", ElementType.INT) ); + + private final DriverContext driverContext; + + private final TopIntIntAggregator.SingleState state; + + private final List channels; + + private final int limit; + + private final boolean ascending; + + public TopIntIntAggregatorFunction(DriverContext driverContext, List channels, + TopIntIntAggregator.SingleState state, int limit, boolean ascending) { + this.driverContext = driverContext; + this.channels = channels; + this.state = state; + this.limit = limit; + this.ascending = ascending; + } + + public static TopIntIntAggregatorFunction create(DriverContext driverContext, + List channels, int limit, boolean ascending) { + return new TopIntIntAggregatorFunction(driverContext, channels, TopIntIntAggregator.initSingle(driverContext.bigArrays(), limit, ascending), limit, ascending); + } + + public static List intermediateStateDesc() { + return INTERMEDIATE_STATE_DESC; + } + + @Override + public int intermediateBlockCount() { + return INTERMEDIATE_STATE_DESC.size(); + } + + @Override + public void addRawInput(Page page, BooleanVector mask) { + if (mask.allFalse()) { + // Entire page masked away + } else if (mask.allTrue()) { + addRawInputNotMasked(page); + } else { + addRawInputMasked(page, mask); + } + } + + private void addRawInputMasked(Page page, BooleanVector mask) { + IntBlock vBlock = page.getBlock(channels.get(0)); + IntBlock extraBlock = page.getBlock(channels.get(1)); + IntVector vVector = vBlock.asVector(); + if (vVector == null) { + addRawBlock(vBlock, extraBlock, mask); + return; + } + IntVector extraVector = extraBlock.asVector(); + if (extraVector == null) { + addRawBlock(vBlock, extraBlock, mask); + return; + } + addRawVector(vVector, extraVector, mask); + } + + private void addRawInputNotMasked(Page page) { + IntBlock vBlock = page.getBlock(channels.get(0)); + IntBlock extraBlock = page.getBlock(channels.get(1)); + IntVector vVector = vBlock.asVector(); + if (vVector == null) { + addRawBlock(vBlock, extraBlock); + return; + } + IntVector extraVector = extraBlock.asVector(); + if (extraVector == null) { + addRawBlock(vBlock, extraBlock); + return; + } + addRawVector(vVector, extraVector); + } + + private void addRawVector(IntVector vVector, IntVector extraVector) { + for (int valuesPosition = 0; valuesPosition < vVector.getPositionCount(); valuesPosition++) { + int vValue = vVector.getInt(valuesPosition); + int extraValue = extraVector.getInt(valuesPosition); + TopIntIntAggregator.combine(state, vValue, extraValue); + } + } + + private void addRawVector(IntVector vVector, IntVector extraVector, BooleanVector mask) { + for (int valuesPosition = 0; valuesPosition < vVector.getPositionCount(); valuesPosition++) { + if (mask.getBoolean(valuesPosition) == false) { + continue; + } + int vValue = vVector.getInt(valuesPosition); + int extraValue = extraVector.getInt(valuesPosition); + TopIntIntAggregator.combine(state, vValue, extraValue); + } + } + + private void addRawBlock(IntBlock vBlock, IntBlock extraBlock) { + for (int p = 0; p < vBlock.getPositionCount(); p++) { + if (vBlock.isNull(p)) { + continue; + } + if (extraBlock.isNull(p)) { + continue; + } + int vStart = vBlock.getFirstValueIndex(p); + int vEnd = vStart + vBlock.getValueCount(p); + for (int vOffset = vStart; vOffset < vEnd; vOffset++) { + int vValue = vBlock.getInt(vOffset); + int extraStart = extraBlock.getFirstValueIndex(p); + int extraEnd = extraStart + extraBlock.getValueCount(p); + for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { + int extraValue = extraBlock.getInt(extraOffset); + TopIntIntAggregator.combine(state, vValue, extraValue); + } + } + } + } + + private void addRawBlock(IntBlock vBlock, IntBlock extraBlock, BooleanVector mask) { + for (int p = 0; p < vBlock.getPositionCount(); p++) { + if (mask.getBoolean(p) == false) { + continue; + } + if (vBlock.isNull(p)) { + continue; + } + if (extraBlock.isNull(p)) { + continue; + } + int vStart = vBlock.getFirstValueIndex(p); + int vEnd = vStart + vBlock.getValueCount(p); + for (int vOffset = vStart; vOffset < vEnd; vOffset++) { + int vValue = vBlock.getInt(vOffset); + int extraStart = extraBlock.getFirstValueIndex(p); + int extraEnd = extraStart + extraBlock.getValueCount(p); + for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { + int extraValue = extraBlock.getInt(extraOffset); + TopIntIntAggregator.combine(state, vValue, extraValue); + } + } + } + } + + @Override + public void addIntermediateInput(Page page) { + assert channels.size() == intermediateBlockCount(); + assert page.getBlockCount() >= channels.get(0) + intermediateStateDesc().size(); + Block topUncast = page.getBlock(channels.get(0)); + if (topUncast.areAllValuesNull()) { + return; + } + IntBlock top = (IntBlock) topUncast; + assert top.getPositionCount() == 1; + Block extraUncast = page.getBlock(channels.get(1)); + if (extraUncast.areAllValuesNull()) { + return; + } + IntBlock extra = (IntBlock) extraUncast; + assert extra.getPositionCount() == 1; + TopIntIntAggregator.combineIntermediate(state, top, extra); + } + + @Override + public void evaluateIntermediate(Block[] blocks, int offset, DriverContext driverContext) { + state.toIntermediate(blocks, offset, driverContext); + } + + @Override + public void evaluateFinal(Block[] blocks, int offset, DriverContext driverContext) { + blocks[offset] = TopIntIntAggregator.evaluateFinal(state, driverContext); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append(getClass().getSimpleName()).append("["); + sb.append("channels=").append(channels); + sb.append("]"); + return sb.toString(); + } + + @Override + public void close() { + state.close(); + } +} diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntIntAggregatorFunctionSupplier.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntIntAggregatorFunctionSupplier.java new file mode 100644 index 0000000000000..98483a1480f3a --- /dev/null +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntIntAggregatorFunctionSupplier.java @@ -0,0 +1,53 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License +// 2.0; you may not use this file except in compliance with the Elastic License +// 2.0. +package org.elasticsearch.compute.aggregation; + +import java.lang.Integer; +import java.lang.Override; +import java.lang.String; +import java.util.List; +import org.elasticsearch.compute.operator.DriverContext; + +/** + * {@link AggregatorFunctionSupplier} implementation for {@link TopIntIntAggregator}. + * This class is generated. Edit {@code AggregatorFunctionSupplierImplementer} instead. + */ +public final class TopIntIntAggregatorFunctionSupplier implements AggregatorFunctionSupplier { + private final int limit; + + private final boolean ascending; + + public TopIntIntAggregatorFunctionSupplier(int limit, boolean ascending) { + this.limit = limit; + this.ascending = ascending; + } + + @Override + public List nonGroupingIntermediateStateDesc() { + return TopIntIntAggregatorFunction.intermediateStateDesc(); + } + + @Override + public List groupingIntermediateStateDesc() { + return TopIntIntGroupingAggregatorFunction.intermediateStateDesc(); + } + + @Override + public TopIntIntAggregatorFunction aggregator(DriverContext driverContext, + List channels) { + return TopIntIntAggregatorFunction.create(driverContext, channels, limit, ascending); + } + + @Override + public TopIntIntGroupingAggregatorFunction groupingAggregator(DriverContext driverContext, + List channels) { + return TopIntIntGroupingAggregatorFunction.create(channels, driverContext, limit, ascending); + } + + @Override + public String describe() { + return "top_int of ints"; + } +} diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntIntGroupingAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntIntGroupingAggregatorFunction.java new file mode 100644 index 0000000000000..d9a797edce245 --- /dev/null +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntIntGroupingAggregatorFunction.java @@ -0,0 +1,394 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License +// 2.0; you may not use this file except in compliance with the Elastic License +// 2.0. +package org.elasticsearch.compute.aggregation; + +import java.lang.Integer; +import java.lang.Override; +import java.lang.String; +import java.lang.StringBuilder; +import java.util.List; +import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.ElementType; +import org.elasticsearch.compute.data.IntArrayBlock; +import org.elasticsearch.compute.data.IntBigArrayBlock; +import org.elasticsearch.compute.data.IntBlock; +import org.elasticsearch.compute.data.IntVector; +import org.elasticsearch.compute.data.Page; +import org.elasticsearch.compute.operator.DriverContext; + +/** + * {@link GroupingAggregatorFunction} implementation for {@link TopIntIntAggregator}. + * This class is generated. Edit {@code GroupingAggregatorImplementer} instead. + */ +public final class TopIntIntGroupingAggregatorFunction implements GroupingAggregatorFunction { + private static final List INTERMEDIATE_STATE_DESC = List.of( + new IntermediateStateDesc("top", ElementType.INT), + new IntermediateStateDesc("extra", ElementType.INT) ); + + private final TopIntIntAggregator.GroupingState state; + + private final List channels; + + private final DriverContext driverContext; + + private final int limit; + + private final boolean ascending; + + public TopIntIntGroupingAggregatorFunction(List channels, + TopIntIntAggregator.GroupingState state, DriverContext driverContext, int limit, + boolean ascending) { + this.channels = channels; + this.state = state; + this.driverContext = driverContext; + this.limit = limit; + this.ascending = ascending; + } + + public static TopIntIntGroupingAggregatorFunction create(List channels, + DriverContext driverContext, int limit, boolean ascending) { + return new TopIntIntGroupingAggregatorFunction(channels, TopIntIntAggregator.initGrouping(driverContext.bigArrays(), limit, ascending), driverContext, limit, ascending); + } + + public static List intermediateStateDesc() { + return INTERMEDIATE_STATE_DESC; + } + + @Override + public int intermediateBlockCount() { + return INTERMEDIATE_STATE_DESC.size(); + } + + @Override + public GroupingAggregatorFunction.AddInput prepareProcessRawInputPage(SeenGroupIds seenGroupIds, + Page page) { + IntBlock vBlock = page.getBlock(channels.get(0)); + IntBlock extraBlock = page.getBlock(channels.get(1)); + IntVector vVector = vBlock.asVector(); + if (vVector == null) { + maybeEnableGroupIdTracking(seenGroupIds, vBlock, extraBlock); + return new GroupingAggregatorFunction.AddInput() { + @Override + public void add(int positionOffset, IntArrayBlock groupIds) { + addRawInput(positionOffset, groupIds, vBlock, extraBlock); + } + + @Override + public void add(int positionOffset, IntBigArrayBlock groupIds) { + addRawInput(positionOffset, groupIds, vBlock, extraBlock); + } + + @Override + public void add(int positionOffset, IntVector groupIds) { + addRawInput(positionOffset, groupIds, vBlock, extraBlock); + } + + @Override + public void close() { + } + }; + } + IntVector extraVector = extraBlock.asVector(); + if (extraVector == null) { + maybeEnableGroupIdTracking(seenGroupIds, vBlock, extraBlock); + return new GroupingAggregatorFunction.AddInput() { + @Override + public void add(int positionOffset, IntArrayBlock groupIds) { + addRawInput(positionOffset, groupIds, vBlock, extraBlock); + } + + @Override + public void add(int positionOffset, IntBigArrayBlock groupIds) { + addRawInput(positionOffset, groupIds, vBlock, extraBlock); + } + + @Override + public void add(int positionOffset, IntVector groupIds) { + addRawInput(positionOffset, groupIds, vBlock, extraBlock); + } + + @Override + public void close() { + } + }; + } + return new GroupingAggregatorFunction.AddInput() { + @Override + public void add(int positionOffset, IntArrayBlock groupIds) { + addRawInput(positionOffset, groupIds, vVector, extraVector); + } + + @Override + public void add(int positionOffset, IntBigArrayBlock groupIds) { + addRawInput(positionOffset, groupIds, vVector, extraVector); + } + + @Override + public void add(int positionOffset, IntVector groupIds) { + addRawInput(positionOffset, groupIds, vVector, extraVector); + } + + @Override + public void close() { + } + }; + } + + private void addRawInput(int positionOffset, IntArrayBlock groups, IntBlock vBlock, + IntBlock extraBlock) { + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + if (groups.isNull(groupPosition)) { + continue; + } + int valuesPosition = groupPosition + positionOffset; + if (vBlock.isNull(valuesPosition)) { + continue; + } + if (extraBlock.isNull(valuesPosition)) { + continue; + } + int groupStart = groups.getFirstValueIndex(groupPosition); + int groupEnd = groupStart + groups.getValueCount(groupPosition); + for (int g = groupStart; g < groupEnd; g++) { + int groupId = groups.getInt(g); + int vStart = vBlock.getFirstValueIndex(valuesPosition); + int vEnd = vStart + vBlock.getValueCount(valuesPosition); + for (int vOffset = vStart; vOffset < vEnd; vOffset++) { + int vValue = vBlock.getInt(vOffset); + int extraStart = extraBlock.getFirstValueIndex(valuesPosition); + int extraEnd = extraStart + extraBlock.getValueCount(valuesPosition); + for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { + int extraValue = extraBlock.getInt(extraOffset); + TopIntIntAggregator.combine(state, groupId, vValue, extraValue); + } + } + } + } + } + + private void addRawInput(int positionOffset, IntArrayBlock groups, IntVector vVector, + IntVector extraVector) { + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + if (groups.isNull(groupPosition)) { + continue; + } + int valuesPosition = groupPosition + positionOffset; + int groupStart = groups.getFirstValueIndex(groupPosition); + int groupEnd = groupStart + groups.getValueCount(groupPosition); + for (int g = groupStart; g < groupEnd; g++) { + int groupId = groups.getInt(g); + int vValue = vVector.getInt(valuesPosition); + int extraValue = extraVector.getInt(valuesPosition); + TopIntIntAggregator.combine(state, groupId, vValue, extraValue); + } + } + } + + @Override + public void addIntermediateInput(int positionOffset, IntArrayBlock groups, Page page) { + state.enableGroupIdTracking(new SeenGroupIds.Empty()); + assert channels.size() == intermediateBlockCount(); + Block topUncast = page.getBlock(channels.get(0)); + if (topUncast.areAllValuesNull()) { + return; + } + IntBlock top = (IntBlock) topUncast; + Block extraUncast = page.getBlock(channels.get(1)); + if (extraUncast.areAllValuesNull()) { + return; + } + IntBlock extra = (IntBlock) extraUncast; + assert top.getPositionCount() == extra.getPositionCount(); + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + if (groups.isNull(groupPosition)) { + continue; + } + int groupStart = groups.getFirstValueIndex(groupPosition); + int groupEnd = groupStart + groups.getValueCount(groupPosition); + for (int g = groupStart; g < groupEnd; g++) { + int groupId = groups.getInt(g); + int valuesPosition = groupPosition + positionOffset; + TopIntIntAggregator.combineIntermediate(state, groupId, top, extra, valuesPosition); + } + } + } + + private void addRawInput(int positionOffset, IntBigArrayBlock groups, IntBlock vBlock, + IntBlock extraBlock) { + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + if (groups.isNull(groupPosition)) { + continue; + } + int valuesPosition = groupPosition + positionOffset; + if (vBlock.isNull(valuesPosition)) { + continue; + } + if (extraBlock.isNull(valuesPosition)) { + continue; + } + int groupStart = groups.getFirstValueIndex(groupPosition); + int groupEnd = groupStart + groups.getValueCount(groupPosition); + for (int g = groupStart; g < groupEnd; g++) { + int groupId = groups.getInt(g); + int vStart = vBlock.getFirstValueIndex(valuesPosition); + int vEnd = vStart + vBlock.getValueCount(valuesPosition); + for (int vOffset = vStart; vOffset < vEnd; vOffset++) { + int vValue = vBlock.getInt(vOffset); + int extraStart = extraBlock.getFirstValueIndex(valuesPosition); + int extraEnd = extraStart + extraBlock.getValueCount(valuesPosition); + for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { + int extraValue = extraBlock.getInt(extraOffset); + TopIntIntAggregator.combine(state, groupId, vValue, extraValue); + } + } + } + } + } + + private void addRawInput(int positionOffset, IntBigArrayBlock groups, IntVector vVector, + IntVector extraVector) { + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + if (groups.isNull(groupPosition)) { + continue; + } + int valuesPosition = groupPosition + positionOffset; + int groupStart = groups.getFirstValueIndex(groupPosition); + int groupEnd = groupStart + groups.getValueCount(groupPosition); + for (int g = groupStart; g < groupEnd; g++) { + int groupId = groups.getInt(g); + int vValue = vVector.getInt(valuesPosition); + int extraValue = extraVector.getInt(valuesPosition); + TopIntIntAggregator.combine(state, groupId, vValue, extraValue); + } + } + } + + @Override + public void addIntermediateInput(int positionOffset, IntBigArrayBlock groups, Page page) { + state.enableGroupIdTracking(new SeenGroupIds.Empty()); + assert channels.size() == intermediateBlockCount(); + Block topUncast = page.getBlock(channels.get(0)); + if (topUncast.areAllValuesNull()) { + return; + } + IntBlock top = (IntBlock) topUncast; + Block extraUncast = page.getBlock(channels.get(1)); + if (extraUncast.areAllValuesNull()) { + return; + } + IntBlock extra = (IntBlock) extraUncast; + assert top.getPositionCount() == extra.getPositionCount(); + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + if (groups.isNull(groupPosition)) { + continue; + } + int groupStart = groups.getFirstValueIndex(groupPosition); + int groupEnd = groupStart + groups.getValueCount(groupPosition); + for (int g = groupStart; g < groupEnd; g++) { + int groupId = groups.getInt(g); + int valuesPosition = groupPosition + positionOffset; + TopIntIntAggregator.combineIntermediate(state, groupId, top, extra, valuesPosition); + } + } + } + + private void addRawInput(int positionOffset, IntVector groups, IntBlock vBlock, + IntBlock extraBlock) { + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + int valuesPosition = groupPosition + positionOffset; + if (vBlock.isNull(valuesPosition)) { + continue; + } + if (extraBlock.isNull(valuesPosition)) { + continue; + } + int groupId = groups.getInt(groupPosition); + int vStart = vBlock.getFirstValueIndex(valuesPosition); + int vEnd = vStart + vBlock.getValueCount(valuesPosition); + for (int vOffset = vStart; vOffset < vEnd; vOffset++) { + int vValue = vBlock.getInt(vOffset); + int extraStart = extraBlock.getFirstValueIndex(valuesPosition); + int extraEnd = extraStart + extraBlock.getValueCount(valuesPosition); + for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { + int extraValue = extraBlock.getInt(extraOffset); + TopIntIntAggregator.combine(state, groupId, vValue, extraValue); + } + } + } + } + + private void addRawInput(int positionOffset, IntVector groups, IntVector vVector, + IntVector extraVector) { + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + int valuesPosition = groupPosition + positionOffset; + int groupId = groups.getInt(groupPosition); + int vValue = vVector.getInt(valuesPosition); + int extraValue = extraVector.getInt(valuesPosition); + TopIntIntAggregator.combine(state, groupId, vValue, extraValue); + } + } + + @Override + public void addIntermediateInput(int positionOffset, IntVector groups, Page page) { + state.enableGroupIdTracking(new SeenGroupIds.Empty()); + assert channels.size() == intermediateBlockCount(); + Block topUncast = page.getBlock(channels.get(0)); + if (topUncast.areAllValuesNull()) { + return; + } + IntBlock top = (IntBlock) topUncast; + Block extraUncast = page.getBlock(channels.get(1)); + if (extraUncast.areAllValuesNull()) { + return; + } + IntBlock extra = (IntBlock) extraUncast; + assert top.getPositionCount() == extra.getPositionCount(); + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + int groupId = groups.getInt(groupPosition); + int valuesPosition = groupPosition + positionOffset; + TopIntIntAggregator.combineIntermediate(state, groupId, top, extra, valuesPosition); + } + } + + private void maybeEnableGroupIdTracking(SeenGroupIds seenGroupIds, IntBlock vBlock, + IntBlock extraBlock) { + if (vBlock.mayHaveNulls()) { + state.enableGroupIdTracking(seenGroupIds); + } + if (extraBlock.mayHaveNulls()) { + state.enableGroupIdTracking(seenGroupIds); + } + } + + @Override + public void selectedMayContainUnseenGroups(SeenGroupIds seenGroupIds) { + state.enableGroupIdTracking(seenGroupIds); + } + + @Override + public void evaluateIntermediate(Block[] blocks, int offset, IntVector selected) { + state.toIntermediate(blocks, offset, selected, driverContext); + } + + @Override + public void evaluateFinal(Block[] blocks, int offset, IntVector selected, + GroupingAggregatorEvaluationContext ctx) { + blocks[offset] = TopIntIntAggregator.evaluateFinal(state, selected, ctx); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append(getClass().getSimpleName()).append("["); + sb.append("channels=").append(channels); + sb.append("]"); + return sb.toString(); + } + + @Override + public void close() { + state.close(); + } +} diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntLongAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntLongAggregatorFunction.java new file mode 100644 index 0000000000000..5e613d1a12aef --- /dev/null +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntLongAggregatorFunction.java @@ -0,0 +1,215 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License +// 2.0; you may not use this file except in compliance with the Elastic License +// 2.0. +package org.elasticsearch.compute.aggregation; + +import java.lang.Integer; +import java.lang.Override; +import java.lang.String; +import java.lang.StringBuilder; +import java.util.List; +import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.BooleanVector; +import org.elasticsearch.compute.data.ElementType; +import org.elasticsearch.compute.data.IntBlock; +import org.elasticsearch.compute.data.IntVector; +import org.elasticsearch.compute.data.LongBlock; +import org.elasticsearch.compute.data.LongVector; +import org.elasticsearch.compute.data.Page; +import org.elasticsearch.compute.operator.DriverContext; + +/** + * {@link AggregatorFunction} implementation for {@link TopIntLongAggregator}. + * This class is generated. Edit {@code AggregatorImplementer} instead. + */ +public final class TopIntLongAggregatorFunction implements AggregatorFunction { + private static final List INTERMEDIATE_STATE_DESC = List.of( + new IntermediateStateDesc("top", ElementType.INT), + new IntermediateStateDesc("extra", ElementType.LONG) ); + + private final DriverContext driverContext; + + private final TopIntLongAggregator.SingleState state; + + private final List channels; + + private final int limit; + + private final boolean ascending; + + public TopIntLongAggregatorFunction(DriverContext driverContext, List channels, + TopIntLongAggregator.SingleState state, int limit, boolean ascending) { + this.driverContext = driverContext; + this.channels = channels; + this.state = state; + this.limit = limit; + this.ascending = ascending; + } + + public static TopIntLongAggregatorFunction create(DriverContext driverContext, + List channels, int limit, boolean ascending) { + return new TopIntLongAggregatorFunction(driverContext, channels, TopIntLongAggregator.initSingle(driverContext.bigArrays(), limit, ascending), limit, ascending); + } + + public static List intermediateStateDesc() { + return INTERMEDIATE_STATE_DESC; + } + + @Override + public int intermediateBlockCount() { + return INTERMEDIATE_STATE_DESC.size(); + } + + @Override + public void addRawInput(Page page, BooleanVector mask) { + if (mask.allFalse()) { + // Entire page masked away + } else if (mask.allTrue()) { + addRawInputNotMasked(page); + } else { + addRawInputMasked(page, mask); + } + } + + private void addRawInputMasked(Page page, BooleanVector mask) { + IntBlock vBlock = page.getBlock(channels.get(0)); + LongBlock extraBlock = page.getBlock(channels.get(1)); + IntVector vVector = vBlock.asVector(); + if (vVector == null) { + addRawBlock(vBlock, extraBlock, mask); + return; + } + LongVector extraVector = extraBlock.asVector(); + if (extraVector == null) { + addRawBlock(vBlock, extraBlock, mask); + return; + } + addRawVector(vVector, extraVector, mask); + } + + private void addRawInputNotMasked(Page page) { + IntBlock vBlock = page.getBlock(channels.get(0)); + LongBlock extraBlock = page.getBlock(channels.get(1)); + IntVector vVector = vBlock.asVector(); + if (vVector == null) { + addRawBlock(vBlock, extraBlock); + return; + } + LongVector extraVector = extraBlock.asVector(); + if (extraVector == null) { + addRawBlock(vBlock, extraBlock); + return; + } + addRawVector(vVector, extraVector); + } + + private void addRawVector(IntVector vVector, LongVector extraVector) { + for (int valuesPosition = 0; valuesPosition < vVector.getPositionCount(); valuesPosition++) { + int vValue = vVector.getInt(valuesPosition); + long extraValue = extraVector.getLong(valuesPosition); + TopIntLongAggregator.combine(state, vValue, extraValue); + } + } + + private void addRawVector(IntVector vVector, LongVector extraVector, BooleanVector mask) { + for (int valuesPosition = 0; valuesPosition < vVector.getPositionCount(); valuesPosition++) { + if (mask.getBoolean(valuesPosition) == false) { + continue; + } + int vValue = vVector.getInt(valuesPosition); + long extraValue = extraVector.getLong(valuesPosition); + TopIntLongAggregator.combine(state, vValue, extraValue); + } + } + + private void addRawBlock(IntBlock vBlock, LongBlock extraBlock) { + for (int p = 0; p < vBlock.getPositionCount(); p++) { + if (vBlock.isNull(p)) { + continue; + } + if (extraBlock.isNull(p)) { + continue; + } + int vStart = vBlock.getFirstValueIndex(p); + int vEnd = vStart + vBlock.getValueCount(p); + for (int vOffset = vStart; vOffset < vEnd; vOffset++) { + int vValue = vBlock.getInt(vOffset); + int extraStart = extraBlock.getFirstValueIndex(p); + int extraEnd = extraStart + extraBlock.getValueCount(p); + for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { + long extraValue = extraBlock.getLong(extraOffset); + TopIntLongAggregator.combine(state, vValue, extraValue); + } + } + } + } + + private void addRawBlock(IntBlock vBlock, LongBlock extraBlock, BooleanVector mask) { + for (int p = 0; p < vBlock.getPositionCount(); p++) { + if (mask.getBoolean(p) == false) { + continue; + } + if (vBlock.isNull(p)) { + continue; + } + if (extraBlock.isNull(p)) { + continue; + } + int vStart = vBlock.getFirstValueIndex(p); + int vEnd = vStart + vBlock.getValueCount(p); + for (int vOffset = vStart; vOffset < vEnd; vOffset++) { + int vValue = vBlock.getInt(vOffset); + int extraStart = extraBlock.getFirstValueIndex(p); + int extraEnd = extraStart + extraBlock.getValueCount(p); + for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { + long extraValue = extraBlock.getLong(extraOffset); + TopIntLongAggregator.combine(state, vValue, extraValue); + } + } + } + } + + @Override + public void addIntermediateInput(Page page) { + assert channels.size() == intermediateBlockCount(); + assert page.getBlockCount() >= channels.get(0) + intermediateStateDesc().size(); + Block topUncast = page.getBlock(channels.get(0)); + if (topUncast.areAllValuesNull()) { + return; + } + IntBlock top = (IntBlock) topUncast; + assert top.getPositionCount() == 1; + Block extraUncast = page.getBlock(channels.get(1)); + if (extraUncast.areAllValuesNull()) { + return; + } + LongBlock extra = (LongBlock) extraUncast; + assert extra.getPositionCount() == 1; + TopIntLongAggregator.combineIntermediate(state, top, extra); + } + + @Override + public void evaluateIntermediate(Block[] blocks, int offset, DriverContext driverContext) { + state.toIntermediate(blocks, offset, driverContext); + } + + @Override + public void evaluateFinal(Block[] blocks, int offset, DriverContext driverContext) { + blocks[offset] = TopIntLongAggregator.evaluateFinal(state, driverContext); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append(getClass().getSimpleName()).append("["); + sb.append("channels=").append(channels); + sb.append("]"); + return sb.toString(); + } + + @Override + public void close() { + state.close(); + } +} diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntLongAggregatorFunctionSupplier.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntLongAggregatorFunctionSupplier.java new file mode 100644 index 0000000000000..720cf8fd05269 --- /dev/null +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntLongAggregatorFunctionSupplier.java @@ -0,0 +1,53 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License +// 2.0; you may not use this file except in compliance with the Elastic License +// 2.0. +package org.elasticsearch.compute.aggregation; + +import java.lang.Integer; +import java.lang.Override; +import java.lang.String; +import java.util.List; +import org.elasticsearch.compute.operator.DriverContext; + +/** + * {@link AggregatorFunctionSupplier} implementation for {@link TopIntLongAggregator}. + * This class is generated. Edit {@code AggregatorFunctionSupplierImplementer} instead. + */ +public final class TopIntLongAggregatorFunctionSupplier implements AggregatorFunctionSupplier { + private final int limit; + + private final boolean ascending; + + public TopIntLongAggregatorFunctionSupplier(int limit, boolean ascending) { + this.limit = limit; + this.ascending = ascending; + } + + @Override + public List nonGroupingIntermediateStateDesc() { + return TopIntLongAggregatorFunction.intermediateStateDesc(); + } + + @Override + public List groupingIntermediateStateDesc() { + return TopIntLongGroupingAggregatorFunction.intermediateStateDesc(); + } + + @Override + public TopIntLongAggregatorFunction aggregator(DriverContext driverContext, + List channels) { + return TopIntLongAggregatorFunction.create(driverContext, channels, limit, ascending); + } + + @Override + public TopIntLongGroupingAggregatorFunction groupingAggregator(DriverContext driverContext, + List channels) { + return TopIntLongGroupingAggregatorFunction.create(channels, driverContext, limit, ascending); + } + + @Override + public String describe() { + return "top_int of longs"; + } +} diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntLongGroupingAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntLongGroupingAggregatorFunction.java new file mode 100644 index 0000000000000..be98483bde6df --- /dev/null +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntLongGroupingAggregatorFunction.java @@ -0,0 +1,396 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License +// 2.0; you may not use this file except in compliance with the Elastic License +// 2.0. +package org.elasticsearch.compute.aggregation; + +import java.lang.Integer; +import java.lang.Override; +import java.lang.String; +import java.lang.StringBuilder; +import java.util.List; +import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.ElementType; +import org.elasticsearch.compute.data.IntArrayBlock; +import org.elasticsearch.compute.data.IntBigArrayBlock; +import org.elasticsearch.compute.data.IntBlock; +import org.elasticsearch.compute.data.IntVector; +import org.elasticsearch.compute.data.LongBlock; +import org.elasticsearch.compute.data.LongVector; +import org.elasticsearch.compute.data.Page; +import org.elasticsearch.compute.operator.DriverContext; + +/** + * {@link GroupingAggregatorFunction} implementation for {@link TopIntLongAggregator}. + * This class is generated. Edit {@code GroupingAggregatorImplementer} instead. + */ +public final class TopIntLongGroupingAggregatorFunction implements GroupingAggregatorFunction { + private static final List INTERMEDIATE_STATE_DESC = List.of( + new IntermediateStateDesc("top", ElementType.INT), + new IntermediateStateDesc("extra", ElementType.LONG) ); + + private final TopIntLongAggregator.GroupingState state; + + private final List channels; + + private final DriverContext driverContext; + + private final int limit; + + private final boolean ascending; + + public TopIntLongGroupingAggregatorFunction(List channels, + TopIntLongAggregator.GroupingState state, DriverContext driverContext, int limit, + boolean ascending) { + this.channels = channels; + this.state = state; + this.driverContext = driverContext; + this.limit = limit; + this.ascending = ascending; + } + + public static TopIntLongGroupingAggregatorFunction create(List channels, + DriverContext driverContext, int limit, boolean ascending) { + return new TopIntLongGroupingAggregatorFunction(channels, TopIntLongAggregator.initGrouping(driverContext.bigArrays(), limit, ascending), driverContext, limit, ascending); + } + + public static List intermediateStateDesc() { + return INTERMEDIATE_STATE_DESC; + } + + @Override + public int intermediateBlockCount() { + return INTERMEDIATE_STATE_DESC.size(); + } + + @Override + public GroupingAggregatorFunction.AddInput prepareProcessRawInputPage(SeenGroupIds seenGroupIds, + Page page) { + IntBlock vBlock = page.getBlock(channels.get(0)); + LongBlock extraBlock = page.getBlock(channels.get(1)); + IntVector vVector = vBlock.asVector(); + if (vVector == null) { + maybeEnableGroupIdTracking(seenGroupIds, vBlock, extraBlock); + return new GroupingAggregatorFunction.AddInput() { + @Override + public void add(int positionOffset, IntArrayBlock groupIds) { + addRawInput(positionOffset, groupIds, vBlock, extraBlock); + } + + @Override + public void add(int positionOffset, IntBigArrayBlock groupIds) { + addRawInput(positionOffset, groupIds, vBlock, extraBlock); + } + + @Override + public void add(int positionOffset, IntVector groupIds) { + addRawInput(positionOffset, groupIds, vBlock, extraBlock); + } + + @Override + public void close() { + } + }; + } + LongVector extraVector = extraBlock.asVector(); + if (extraVector == null) { + maybeEnableGroupIdTracking(seenGroupIds, vBlock, extraBlock); + return new GroupingAggregatorFunction.AddInput() { + @Override + public void add(int positionOffset, IntArrayBlock groupIds) { + addRawInput(positionOffset, groupIds, vBlock, extraBlock); + } + + @Override + public void add(int positionOffset, IntBigArrayBlock groupIds) { + addRawInput(positionOffset, groupIds, vBlock, extraBlock); + } + + @Override + public void add(int positionOffset, IntVector groupIds) { + addRawInput(positionOffset, groupIds, vBlock, extraBlock); + } + + @Override + public void close() { + } + }; + } + return new GroupingAggregatorFunction.AddInput() { + @Override + public void add(int positionOffset, IntArrayBlock groupIds) { + addRawInput(positionOffset, groupIds, vVector, extraVector); + } + + @Override + public void add(int positionOffset, IntBigArrayBlock groupIds) { + addRawInput(positionOffset, groupIds, vVector, extraVector); + } + + @Override + public void add(int positionOffset, IntVector groupIds) { + addRawInput(positionOffset, groupIds, vVector, extraVector); + } + + @Override + public void close() { + } + }; + } + + private void addRawInput(int positionOffset, IntArrayBlock groups, IntBlock vBlock, + LongBlock extraBlock) { + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + if (groups.isNull(groupPosition)) { + continue; + } + int valuesPosition = groupPosition + positionOffset; + if (vBlock.isNull(valuesPosition)) { + continue; + } + if (extraBlock.isNull(valuesPosition)) { + continue; + } + int groupStart = groups.getFirstValueIndex(groupPosition); + int groupEnd = groupStart + groups.getValueCount(groupPosition); + for (int g = groupStart; g < groupEnd; g++) { + int groupId = groups.getInt(g); + int vStart = vBlock.getFirstValueIndex(valuesPosition); + int vEnd = vStart + vBlock.getValueCount(valuesPosition); + for (int vOffset = vStart; vOffset < vEnd; vOffset++) { + int vValue = vBlock.getInt(vOffset); + int extraStart = extraBlock.getFirstValueIndex(valuesPosition); + int extraEnd = extraStart + extraBlock.getValueCount(valuesPosition); + for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { + long extraValue = extraBlock.getLong(extraOffset); + TopIntLongAggregator.combine(state, groupId, vValue, extraValue); + } + } + } + } + } + + private void addRawInput(int positionOffset, IntArrayBlock groups, IntVector vVector, + LongVector extraVector) { + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + if (groups.isNull(groupPosition)) { + continue; + } + int valuesPosition = groupPosition + positionOffset; + int groupStart = groups.getFirstValueIndex(groupPosition); + int groupEnd = groupStart + groups.getValueCount(groupPosition); + for (int g = groupStart; g < groupEnd; g++) { + int groupId = groups.getInt(g); + int vValue = vVector.getInt(valuesPosition); + long extraValue = extraVector.getLong(valuesPosition); + TopIntLongAggregator.combine(state, groupId, vValue, extraValue); + } + } + } + + @Override + public void addIntermediateInput(int positionOffset, IntArrayBlock groups, Page page) { + state.enableGroupIdTracking(new SeenGroupIds.Empty()); + assert channels.size() == intermediateBlockCount(); + Block topUncast = page.getBlock(channels.get(0)); + if (topUncast.areAllValuesNull()) { + return; + } + IntBlock top = (IntBlock) topUncast; + Block extraUncast = page.getBlock(channels.get(1)); + if (extraUncast.areAllValuesNull()) { + return; + } + LongBlock extra = (LongBlock) extraUncast; + assert top.getPositionCount() == extra.getPositionCount(); + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + if (groups.isNull(groupPosition)) { + continue; + } + int groupStart = groups.getFirstValueIndex(groupPosition); + int groupEnd = groupStart + groups.getValueCount(groupPosition); + for (int g = groupStart; g < groupEnd; g++) { + int groupId = groups.getInt(g); + int valuesPosition = groupPosition + positionOffset; + TopIntLongAggregator.combineIntermediate(state, groupId, top, extra, valuesPosition); + } + } + } + + private void addRawInput(int positionOffset, IntBigArrayBlock groups, IntBlock vBlock, + LongBlock extraBlock) { + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + if (groups.isNull(groupPosition)) { + continue; + } + int valuesPosition = groupPosition + positionOffset; + if (vBlock.isNull(valuesPosition)) { + continue; + } + if (extraBlock.isNull(valuesPosition)) { + continue; + } + int groupStart = groups.getFirstValueIndex(groupPosition); + int groupEnd = groupStart + groups.getValueCount(groupPosition); + for (int g = groupStart; g < groupEnd; g++) { + int groupId = groups.getInt(g); + int vStart = vBlock.getFirstValueIndex(valuesPosition); + int vEnd = vStart + vBlock.getValueCount(valuesPosition); + for (int vOffset = vStart; vOffset < vEnd; vOffset++) { + int vValue = vBlock.getInt(vOffset); + int extraStart = extraBlock.getFirstValueIndex(valuesPosition); + int extraEnd = extraStart + extraBlock.getValueCount(valuesPosition); + for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { + long extraValue = extraBlock.getLong(extraOffset); + TopIntLongAggregator.combine(state, groupId, vValue, extraValue); + } + } + } + } + } + + private void addRawInput(int positionOffset, IntBigArrayBlock groups, IntVector vVector, + LongVector extraVector) { + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + if (groups.isNull(groupPosition)) { + continue; + } + int valuesPosition = groupPosition + positionOffset; + int groupStart = groups.getFirstValueIndex(groupPosition); + int groupEnd = groupStart + groups.getValueCount(groupPosition); + for (int g = groupStart; g < groupEnd; g++) { + int groupId = groups.getInt(g); + int vValue = vVector.getInt(valuesPosition); + long extraValue = extraVector.getLong(valuesPosition); + TopIntLongAggregator.combine(state, groupId, vValue, extraValue); + } + } + } + + @Override + public void addIntermediateInput(int positionOffset, IntBigArrayBlock groups, Page page) { + state.enableGroupIdTracking(new SeenGroupIds.Empty()); + assert channels.size() == intermediateBlockCount(); + Block topUncast = page.getBlock(channels.get(0)); + if (topUncast.areAllValuesNull()) { + return; + } + IntBlock top = (IntBlock) topUncast; + Block extraUncast = page.getBlock(channels.get(1)); + if (extraUncast.areAllValuesNull()) { + return; + } + LongBlock extra = (LongBlock) extraUncast; + assert top.getPositionCount() == extra.getPositionCount(); + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + if (groups.isNull(groupPosition)) { + continue; + } + int groupStart = groups.getFirstValueIndex(groupPosition); + int groupEnd = groupStart + groups.getValueCount(groupPosition); + for (int g = groupStart; g < groupEnd; g++) { + int groupId = groups.getInt(g); + int valuesPosition = groupPosition + positionOffset; + TopIntLongAggregator.combineIntermediate(state, groupId, top, extra, valuesPosition); + } + } + } + + private void addRawInput(int positionOffset, IntVector groups, IntBlock vBlock, + LongBlock extraBlock) { + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + int valuesPosition = groupPosition + positionOffset; + if (vBlock.isNull(valuesPosition)) { + continue; + } + if (extraBlock.isNull(valuesPosition)) { + continue; + } + int groupId = groups.getInt(groupPosition); + int vStart = vBlock.getFirstValueIndex(valuesPosition); + int vEnd = vStart + vBlock.getValueCount(valuesPosition); + for (int vOffset = vStart; vOffset < vEnd; vOffset++) { + int vValue = vBlock.getInt(vOffset); + int extraStart = extraBlock.getFirstValueIndex(valuesPosition); + int extraEnd = extraStart + extraBlock.getValueCount(valuesPosition); + for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { + long extraValue = extraBlock.getLong(extraOffset); + TopIntLongAggregator.combine(state, groupId, vValue, extraValue); + } + } + } + } + + private void addRawInput(int positionOffset, IntVector groups, IntVector vVector, + LongVector extraVector) { + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + int valuesPosition = groupPosition + positionOffset; + int groupId = groups.getInt(groupPosition); + int vValue = vVector.getInt(valuesPosition); + long extraValue = extraVector.getLong(valuesPosition); + TopIntLongAggregator.combine(state, groupId, vValue, extraValue); + } + } + + @Override + public void addIntermediateInput(int positionOffset, IntVector groups, Page page) { + state.enableGroupIdTracking(new SeenGroupIds.Empty()); + assert channels.size() == intermediateBlockCount(); + Block topUncast = page.getBlock(channels.get(0)); + if (topUncast.areAllValuesNull()) { + return; + } + IntBlock top = (IntBlock) topUncast; + Block extraUncast = page.getBlock(channels.get(1)); + if (extraUncast.areAllValuesNull()) { + return; + } + LongBlock extra = (LongBlock) extraUncast; + assert top.getPositionCount() == extra.getPositionCount(); + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + int groupId = groups.getInt(groupPosition); + int valuesPosition = groupPosition + positionOffset; + TopIntLongAggregator.combineIntermediate(state, groupId, top, extra, valuesPosition); + } + } + + private void maybeEnableGroupIdTracking(SeenGroupIds seenGroupIds, IntBlock vBlock, + LongBlock extraBlock) { + if (vBlock.mayHaveNulls()) { + state.enableGroupIdTracking(seenGroupIds); + } + if (extraBlock.mayHaveNulls()) { + state.enableGroupIdTracking(seenGroupIds); + } + } + + @Override + public void selectedMayContainUnseenGroups(SeenGroupIds seenGroupIds) { + state.enableGroupIdTracking(seenGroupIds); + } + + @Override + public void evaluateIntermediate(Block[] blocks, int offset, IntVector selected) { + state.toIntermediate(blocks, offset, selected, driverContext); + } + + @Override + public void evaluateFinal(Block[] blocks, int offset, IntVector selected, + GroupingAggregatorEvaluationContext ctx) { + blocks[offset] = TopIntLongAggregator.evaluateFinal(state, selected, ctx); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append(getClass().getSimpleName()).append("["); + sb.append("channels=").append(channels); + sb.append("]"); + return sb.toString(); + } + + @Override + public void close() { + state.close(); + } +} diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongDoubleAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongDoubleAggregatorFunction.java new file mode 100644 index 0000000000000..d965ffe6ab80e --- /dev/null +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongDoubleAggregatorFunction.java @@ -0,0 +1,215 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License +// 2.0; you may not use this file except in compliance with the Elastic License +// 2.0. +package org.elasticsearch.compute.aggregation; + +import java.lang.Integer; +import java.lang.Override; +import java.lang.String; +import java.lang.StringBuilder; +import java.util.List; +import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.BooleanVector; +import org.elasticsearch.compute.data.DoubleBlock; +import org.elasticsearch.compute.data.DoubleVector; +import org.elasticsearch.compute.data.ElementType; +import org.elasticsearch.compute.data.LongBlock; +import org.elasticsearch.compute.data.LongVector; +import org.elasticsearch.compute.data.Page; +import org.elasticsearch.compute.operator.DriverContext; + +/** + * {@link AggregatorFunction} implementation for {@link TopLongDoubleAggregator}. + * This class is generated. Edit {@code AggregatorImplementer} instead. + */ +public final class TopLongDoubleAggregatorFunction implements AggregatorFunction { + private static final List INTERMEDIATE_STATE_DESC = List.of( + new IntermediateStateDesc("top", ElementType.LONG), + new IntermediateStateDesc("extra", ElementType.DOUBLE) ); + + private final DriverContext driverContext; + + private final TopLongDoubleAggregator.SingleState state; + + private final List channels; + + private final int limit; + + private final boolean ascending; + + public TopLongDoubleAggregatorFunction(DriverContext driverContext, List channels, + TopLongDoubleAggregator.SingleState state, int limit, boolean ascending) { + this.driverContext = driverContext; + this.channels = channels; + this.state = state; + this.limit = limit; + this.ascending = ascending; + } + + public static TopLongDoubleAggregatorFunction create(DriverContext driverContext, + List channels, int limit, boolean ascending) { + return new TopLongDoubleAggregatorFunction(driverContext, channels, TopLongDoubleAggregator.initSingle(driverContext.bigArrays(), limit, ascending), limit, ascending); + } + + public static List intermediateStateDesc() { + return INTERMEDIATE_STATE_DESC; + } + + @Override + public int intermediateBlockCount() { + return INTERMEDIATE_STATE_DESC.size(); + } + + @Override + public void addRawInput(Page page, BooleanVector mask) { + if (mask.allFalse()) { + // Entire page masked away + } else if (mask.allTrue()) { + addRawInputNotMasked(page); + } else { + addRawInputMasked(page, mask); + } + } + + private void addRawInputMasked(Page page, BooleanVector mask) { + LongBlock vBlock = page.getBlock(channels.get(0)); + DoubleBlock extraBlock = page.getBlock(channels.get(1)); + LongVector vVector = vBlock.asVector(); + if (vVector == null) { + addRawBlock(vBlock, extraBlock, mask); + return; + } + DoubleVector extraVector = extraBlock.asVector(); + if (extraVector == null) { + addRawBlock(vBlock, extraBlock, mask); + return; + } + addRawVector(vVector, extraVector, mask); + } + + private void addRawInputNotMasked(Page page) { + LongBlock vBlock = page.getBlock(channels.get(0)); + DoubleBlock extraBlock = page.getBlock(channels.get(1)); + LongVector vVector = vBlock.asVector(); + if (vVector == null) { + addRawBlock(vBlock, extraBlock); + return; + } + DoubleVector extraVector = extraBlock.asVector(); + if (extraVector == null) { + addRawBlock(vBlock, extraBlock); + return; + } + addRawVector(vVector, extraVector); + } + + private void addRawVector(LongVector vVector, DoubleVector extraVector) { + for (int valuesPosition = 0; valuesPosition < vVector.getPositionCount(); valuesPosition++) { + long vValue = vVector.getLong(valuesPosition); + double extraValue = extraVector.getDouble(valuesPosition); + TopLongDoubleAggregator.combine(state, vValue, extraValue); + } + } + + private void addRawVector(LongVector vVector, DoubleVector extraVector, BooleanVector mask) { + for (int valuesPosition = 0; valuesPosition < vVector.getPositionCount(); valuesPosition++) { + if (mask.getBoolean(valuesPosition) == false) { + continue; + } + long vValue = vVector.getLong(valuesPosition); + double extraValue = extraVector.getDouble(valuesPosition); + TopLongDoubleAggregator.combine(state, vValue, extraValue); + } + } + + private void addRawBlock(LongBlock vBlock, DoubleBlock extraBlock) { + for (int p = 0; p < vBlock.getPositionCount(); p++) { + if (vBlock.isNull(p)) { + continue; + } + if (extraBlock.isNull(p)) { + continue; + } + int vStart = vBlock.getFirstValueIndex(p); + int vEnd = vStart + vBlock.getValueCount(p); + for (int vOffset = vStart; vOffset < vEnd; vOffset++) { + long vValue = vBlock.getLong(vOffset); + int extraStart = extraBlock.getFirstValueIndex(p); + int extraEnd = extraStart + extraBlock.getValueCount(p); + for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { + double extraValue = extraBlock.getDouble(extraOffset); + TopLongDoubleAggregator.combine(state, vValue, extraValue); + } + } + } + } + + private void addRawBlock(LongBlock vBlock, DoubleBlock extraBlock, BooleanVector mask) { + for (int p = 0; p < vBlock.getPositionCount(); p++) { + if (mask.getBoolean(p) == false) { + continue; + } + if (vBlock.isNull(p)) { + continue; + } + if (extraBlock.isNull(p)) { + continue; + } + int vStart = vBlock.getFirstValueIndex(p); + int vEnd = vStart + vBlock.getValueCount(p); + for (int vOffset = vStart; vOffset < vEnd; vOffset++) { + long vValue = vBlock.getLong(vOffset); + int extraStart = extraBlock.getFirstValueIndex(p); + int extraEnd = extraStart + extraBlock.getValueCount(p); + for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { + double extraValue = extraBlock.getDouble(extraOffset); + TopLongDoubleAggregator.combine(state, vValue, extraValue); + } + } + } + } + + @Override + public void addIntermediateInput(Page page) { + assert channels.size() == intermediateBlockCount(); + assert page.getBlockCount() >= channels.get(0) + intermediateStateDesc().size(); + Block topUncast = page.getBlock(channels.get(0)); + if (topUncast.areAllValuesNull()) { + return; + } + LongBlock top = (LongBlock) topUncast; + assert top.getPositionCount() == 1; + Block extraUncast = page.getBlock(channels.get(1)); + if (extraUncast.areAllValuesNull()) { + return; + } + DoubleBlock extra = (DoubleBlock) extraUncast; + assert extra.getPositionCount() == 1; + TopLongDoubleAggregator.combineIntermediate(state, top, extra); + } + + @Override + public void evaluateIntermediate(Block[] blocks, int offset, DriverContext driverContext) { + state.toIntermediate(blocks, offset, driverContext); + } + + @Override + public void evaluateFinal(Block[] blocks, int offset, DriverContext driverContext) { + blocks[offset] = TopLongDoubleAggregator.evaluateFinal(state, driverContext); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append(getClass().getSimpleName()).append("["); + sb.append("channels=").append(channels); + sb.append("]"); + return sb.toString(); + } + + @Override + public void close() { + state.close(); + } +} diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongDoubleAggregatorFunctionSupplier.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongDoubleAggregatorFunctionSupplier.java new file mode 100644 index 0000000000000..d57f610de8a50 --- /dev/null +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongDoubleAggregatorFunctionSupplier.java @@ -0,0 +1,53 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License +// 2.0; you may not use this file except in compliance with the Elastic License +// 2.0. +package org.elasticsearch.compute.aggregation; + +import java.lang.Integer; +import java.lang.Override; +import java.lang.String; +import java.util.List; +import org.elasticsearch.compute.operator.DriverContext; + +/** + * {@link AggregatorFunctionSupplier} implementation for {@link TopLongDoubleAggregator}. + * This class is generated. Edit {@code AggregatorFunctionSupplierImplementer} instead. + */ +public final class TopLongDoubleAggregatorFunctionSupplier implements AggregatorFunctionSupplier { + private final int limit; + + private final boolean ascending; + + public TopLongDoubleAggregatorFunctionSupplier(int limit, boolean ascending) { + this.limit = limit; + this.ascending = ascending; + } + + @Override + public List nonGroupingIntermediateStateDesc() { + return TopLongDoubleAggregatorFunction.intermediateStateDesc(); + } + + @Override + public List groupingIntermediateStateDesc() { + return TopLongDoubleGroupingAggregatorFunction.intermediateStateDesc(); + } + + @Override + public TopLongDoubleAggregatorFunction aggregator(DriverContext driverContext, + List channels) { + return TopLongDoubleAggregatorFunction.create(driverContext, channels, limit, ascending); + } + + @Override + public TopLongDoubleGroupingAggregatorFunction groupingAggregator(DriverContext driverContext, + List channels) { + return TopLongDoubleGroupingAggregatorFunction.create(channels, driverContext, limit, ascending); + } + + @Override + public String describe() { + return "top_long of doubles"; + } +} diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongDoubleGroupingAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongDoubleGroupingAggregatorFunction.java new file mode 100644 index 0000000000000..9e4a5bcbf6020 --- /dev/null +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongDoubleGroupingAggregatorFunction.java @@ -0,0 +1,397 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License +// 2.0; you may not use this file except in compliance with the Elastic License +// 2.0. +package org.elasticsearch.compute.aggregation; + +import java.lang.Integer; +import java.lang.Override; +import java.lang.String; +import java.lang.StringBuilder; +import java.util.List; +import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.DoubleBlock; +import org.elasticsearch.compute.data.DoubleVector; +import org.elasticsearch.compute.data.ElementType; +import org.elasticsearch.compute.data.IntArrayBlock; +import org.elasticsearch.compute.data.IntBigArrayBlock; +import org.elasticsearch.compute.data.IntVector; +import org.elasticsearch.compute.data.LongBlock; +import org.elasticsearch.compute.data.LongVector; +import org.elasticsearch.compute.data.Page; +import org.elasticsearch.compute.operator.DriverContext; + +/** + * {@link GroupingAggregatorFunction} implementation for {@link TopLongDoubleAggregator}. + * This class is generated. Edit {@code GroupingAggregatorImplementer} instead. + */ +public final class TopLongDoubleGroupingAggregatorFunction implements GroupingAggregatorFunction { + private static final List INTERMEDIATE_STATE_DESC = List.of( + new IntermediateStateDesc("top", ElementType.LONG), + new IntermediateStateDesc("extra", ElementType.DOUBLE) ); + + private final TopLongDoubleAggregator.GroupingState state; + + private final List channels; + + private final DriverContext driverContext; + + private final int limit; + + private final boolean ascending; + + public TopLongDoubleGroupingAggregatorFunction(List channels, + TopLongDoubleAggregator.GroupingState state, DriverContext driverContext, int limit, + boolean ascending) { + this.channels = channels; + this.state = state; + this.driverContext = driverContext; + this.limit = limit; + this.ascending = ascending; + } + + public static TopLongDoubleGroupingAggregatorFunction create(List channels, + DriverContext driverContext, int limit, boolean ascending) { + return new TopLongDoubleGroupingAggregatorFunction(channels, TopLongDoubleAggregator.initGrouping(driverContext.bigArrays(), limit, ascending), driverContext, limit, ascending); + } + + public static List intermediateStateDesc() { + return INTERMEDIATE_STATE_DESC; + } + + @Override + public int intermediateBlockCount() { + return INTERMEDIATE_STATE_DESC.size(); + } + + @Override + public GroupingAggregatorFunction.AddInput prepareProcessRawInputPage(SeenGroupIds seenGroupIds, + Page page) { + LongBlock vBlock = page.getBlock(channels.get(0)); + DoubleBlock extraBlock = page.getBlock(channels.get(1)); + LongVector vVector = vBlock.asVector(); + if (vVector == null) { + maybeEnableGroupIdTracking(seenGroupIds, vBlock, extraBlock); + return new GroupingAggregatorFunction.AddInput() { + @Override + public void add(int positionOffset, IntArrayBlock groupIds) { + addRawInput(positionOffset, groupIds, vBlock, extraBlock); + } + + @Override + public void add(int positionOffset, IntBigArrayBlock groupIds) { + addRawInput(positionOffset, groupIds, vBlock, extraBlock); + } + + @Override + public void add(int positionOffset, IntVector groupIds) { + addRawInput(positionOffset, groupIds, vBlock, extraBlock); + } + + @Override + public void close() { + } + }; + } + DoubleVector extraVector = extraBlock.asVector(); + if (extraVector == null) { + maybeEnableGroupIdTracking(seenGroupIds, vBlock, extraBlock); + return new GroupingAggregatorFunction.AddInput() { + @Override + public void add(int positionOffset, IntArrayBlock groupIds) { + addRawInput(positionOffset, groupIds, vBlock, extraBlock); + } + + @Override + public void add(int positionOffset, IntBigArrayBlock groupIds) { + addRawInput(positionOffset, groupIds, vBlock, extraBlock); + } + + @Override + public void add(int positionOffset, IntVector groupIds) { + addRawInput(positionOffset, groupIds, vBlock, extraBlock); + } + + @Override + public void close() { + } + }; + } + return new GroupingAggregatorFunction.AddInput() { + @Override + public void add(int positionOffset, IntArrayBlock groupIds) { + addRawInput(positionOffset, groupIds, vVector, extraVector); + } + + @Override + public void add(int positionOffset, IntBigArrayBlock groupIds) { + addRawInput(positionOffset, groupIds, vVector, extraVector); + } + + @Override + public void add(int positionOffset, IntVector groupIds) { + addRawInput(positionOffset, groupIds, vVector, extraVector); + } + + @Override + public void close() { + } + }; + } + + private void addRawInput(int positionOffset, IntArrayBlock groups, LongBlock vBlock, + DoubleBlock extraBlock) { + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + if (groups.isNull(groupPosition)) { + continue; + } + int valuesPosition = groupPosition + positionOffset; + if (vBlock.isNull(valuesPosition)) { + continue; + } + if (extraBlock.isNull(valuesPosition)) { + continue; + } + int groupStart = groups.getFirstValueIndex(groupPosition); + int groupEnd = groupStart + groups.getValueCount(groupPosition); + for (int g = groupStart; g < groupEnd; g++) { + int groupId = groups.getInt(g); + int vStart = vBlock.getFirstValueIndex(valuesPosition); + int vEnd = vStart + vBlock.getValueCount(valuesPosition); + for (int vOffset = vStart; vOffset < vEnd; vOffset++) { + long vValue = vBlock.getLong(vOffset); + int extraStart = extraBlock.getFirstValueIndex(valuesPosition); + int extraEnd = extraStart + extraBlock.getValueCount(valuesPosition); + for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { + double extraValue = extraBlock.getDouble(extraOffset); + TopLongDoubleAggregator.combine(state, groupId, vValue, extraValue); + } + } + } + } + } + + private void addRawInput(int positionOffset, IntArrayBlock groups, LongVector vVector, + DoubleVector extraVector) { + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + if (groups.isNull(groupPosition)) { + continue; + } + int valuesPosition = groupPosition + positionOffset; + int groupStart = groups.getFirstValueIndex(groupPosition); + int groupEnd = groupStart + groups.getValueCount(groupPosition); + for (int g = groupStart; g < groupEnd; g++) { + int groupId = groups.getInt(g); + long vValue = vVector.getLong(valuesPosition); + double extraValue = extraVector.getDouble(valuesPosition); + TopLongDoubleAggregator.combine(state, groupId, vValue, extraValue); + } + } + } + + @Override + public void addIntermediateInput(int positionOffset, IntArrayBlock groups, Page page) { + state.enableGroupIdTracking(new SeenGroupIds.Empty()); + assert channels.size() == intermediateBlockCount(); + Block topUncast = page.getBlock(channels.get(0)); + if (topUncast.areAllValuesNull()) { + return; + } + LongBlock top = (LongBlock) topUncast; + Block extraUncast = page.getBlock(channels.get(1)); + if (extraUncast.areAllValuesNull()) { + return; + } + DoubleBlock extra = (DoubleBlock) extraUncast; + assert top.getPositionCount() == extra.getPositionCount(); + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + if (groups.isNull(groupPosition)) { + continue; + } + int groupStart = groups.getFirstValueIndex(groupPosition); + int groupEnd = groupStart + groups.getValueCount(groupPosition); + for (int g = groupStart; g < groupEnd; g++) { + int groupId = groups.getInt(g); + int valuesPosition = groupPosition + positionOffset; + TopLongDoubleAggregator.combineIntermediate(state, groupId, top, extra, valuesPosition); + } + } + } + + private void addRawInput(int positionOffset, IntBigArrayBlock groups, LongBlock vBlock, + DoubleBlock extraBlock) { + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + if (groups.isNull(groupPosition)) { + continue; + } + int valuesPosition = groupPosition + positionOffset; + if (vBlock.isNull(valuesPosition)) { + continue; + } + if (extraBlock.isNull(valuesPosition)) { + continue; + } + int groupStart = groups.getFirstValueIndex(groupPosition); + int groupEnd = groupStart + groups.getValueCount(groupPosition); + for (int g = groupStart; g < groupEnd; g++) { + int groupId = groups.getInt(g); + int vStart = vBlock.getFirstValueIndex(valuesPosition); + int vEnd = vStart + vBlock.getValueCount(valuesPosition); + for (int vOffset = vStart; vOffset < vEnd; vOffset++) { + long vValue = vBlock.getLong(vOffset); + int extraStart = extraBlock.getFirstValueIndex(valuesPosition); + int extraEnd = extraStart + extraBlock.getValueCount(valuesPosition); + for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { + double extraValue = extraBlock.getDouble(extraOffset); + TopLongDoubleAggregator.combine(state, groupId, vValue, extraValue); + } + } + } + } + } + + private void addRawInput(int positionOffset, IntBigArrayBlock groups, LongVector vVector, + DoubleVector extraVector) { + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + if (groups.isNull(groupPosition)) { + continue; + } + int valuesPosition = groupPosition + positionOffset; + int groupStart = groups.getFirstValueIndex(groupPosition); + int groupEnd = groupStart + groups.getValueCount(groupPosition); + for (int g = groupStart; g < groupEnd; g++) { + int groupId = groups.getInt(g); + long vValue = vVector.getLong(valuesPosition); + double extraValue = extraVector.getDouble(valuesPosition); + TopLongDoubleAggregator.combine(state, groupId, vValue, extraValue); + } + } + } + + @Override + public void addIntermediateInput(int positionOffset, IntBigArrayBlock groups, Page page) { + state.enableGroupIdTracking(new SeenGroupIds.Empty()); + assert channels.size() == intermediateBlockCount(); + Block topUncast = page.getBlock(channels.get(0)); + if (topUncast.areAllValuesNull()) { + return; + } + LongBlock top = (LongBlock) topUncast; + Block extraUncast = page.getBlock(channels.get(1)); + if (extraUncast.areAllValuesNull()) { + return; + } + DoubleBlock extra = (DoubleBlock) extraUncast; + assert top.getPositionCount() == extra.getPositionCount(); + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + if (groups.isNull(groupPosition)) { + continue; + } + int groupStart = groups.getFirstValueIndex(groupPosition); + int groupEnd = groupStart + groups.getValueCount(groupPosition); + for (int g = groupStart; g < groupEnd; g++) { + int groupId = groups.getInt(g); + int valuesPosition = groupPosition + positionOffset; + TopLongDoubleAggregator.combineIntermediate(state, groupId, top, extra, valuesPosition); + } + } + } + + private void addRawInput(int positionOffset, IntVector groups, LongBlock vBlock, + DoubleBlock extraBlock) { + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + int valuesPosition = groupPosition + positionOffset; + if (vBlock.isNull(valuesPosition)) { + continue; + } + if (extraBlock.isNull(valuesPosition)) { + continue; + } + int groupId = groups.getInt(groupPosition); + int vStart = vBlock.getFirstValueIndex(valuesPosition); + int vEnd = vStart + vBlock.getValueCount(valuesPosition); + for (int vOffset = vStart; vOffset < vEnd; vOffset++) { + long vValue = vBlock.getLong(vOffset); + int extraStart = extraBlock.getFirstValueIndex(valuesPosition); + int extraEnd = extraStart + extraBlock.getValueCount(valuesPosition); + for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { + double extraValue = extraBlock.getDouble(extraOffset); + TopLongDoubleAggregator.combine(state, groupId, vValue, extraValue); + } + } + } + } + + private void addRawInput(int positionOffset, IntVector groups, LongVector vVector, + DoubleVector extraVector) { + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + int valuesPosition = groupPosition + positionOffset; + int groupId = groups.getInt(groupPosition); + long vValue = vVector.getLong(valuesPosition); + double extraValue = extraVector.getDouble(valuesPosition); + TopLongDoubleAggregator.combine(state, groupId, vValue, extraValue); + } + } + + @Override + public void addIntermediateInput(int positionOffset, IntVector groups, Page page) { + state.enableGroupIdTracking(new SeenGroupIds.Empty()); + assert channels.size() == intermediateBlockCount(); + Block topUncast = page.getBlock(channels.get(0)); + if (topUncast.areAllValuesNull()) { + return; + } + LongBlock top = (LongBlock) topUncast; + Block extraUncast = page.getBlock(channels.get(1)); + if (extraUncast.areAllValuesNull()) { + return; + } + DoubleBlock extra = (DoubleBlock) extraUncast; + assert top.getPositionCount() == extra.getPositionCount(); + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + int groupId = groups.getInt(groupPosition); + int valuesPosition = groupPosition + positionOffset; + TopLongDoubleAggregator.combineIntermediate(state, groupId, top, extra, valuesPosition); + } + } + + private void maybeEnableGroupIdTracking(SeenGroupIds seenGroupIds, LongBlock vBlock, + DoubleBlock extraBlock) { + if (vBlock.mayHaveNulls()) { + state.enableGroupIdTracking(seenGroupIds); + } + if (extraBlock.mayHaveNulls()) { + state.enableGroupIdTracking(seenGroupIds); + } + } + + @Override + public void selectedMayContainUnseenGroups(SeenGroupIds seenGroupIds) { + state.enableGroupIdTracking(seenGroupIds); + } + + @Override + public void evaluateIntermediate(Block[] blocks, int offset, IntVector selected) { + state.toIntermediate(blocks, offset, selected, driverContext); + } + + @Override + public void evaluateFinal(Block[] blocks, int offset, IntVector selected, + GroupingAggregatorEvaluationContext ctx) { + blocks[offset] = TopLongDoubleAggregator.evaluateFinal(state, selected, ctx); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append(getClass().getSimpleName()).append("["); + sb.append("channels=").append(channels); + sb.append("]"); + return sb.toString(); + } + + @Override + public void close() { + state.close(); + } +} diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongFloatAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongFloatAggregatorFunction.java new file mode 100644 index 0000000000000..cb6b9cc988a27 --- /dev/null +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongFloatAggregatorFunction.java @@ -0,0 +1,215 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License +// 2.0; you may not use this file except in compliance with the Elastic License +// 2.0. +package org.elasticsearch.compute.aggregation; + +import java.lang.Integer; +import java.lang.Override; +import java.lang.String; +import java.lang.StringBuilder; +import java.util.List; +import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.BooleanVector; +import org.elasticsearch.compute.data.ElementType; +import org.elasticsearch.compute.data.FloatBlock; +import org.elasticsearch.compute.data.FloatVector; +import org.elasticsearch.compute.data.LongBlock; +import org.elasticsearch.compute.data.LongVector; +import org.elasticsearch.compute.data.Page; +import org.elasticsearch.compute.operator.DriverContext; + +/** + * {@link AggregatorFunction} implementation for {@link TopLongFloatAggregator}. + * This class is generated. Edit {@code AggregatorImplementer} instead. + */ +public final class TopLongFloatAggregatorFunction implements AggregatorFunction { + private static final List INTERMEDIATE_STATE_DESC = List.of( + new IntermediateStateDesc("top", ElementType.LONG), + new IntermediateStateDesc("extra", ElementType.FLOAT) ); + + private final DriverContext driverContext; + + private final TopLongFloatAggregator.SingleState state; + + private final List channels; + + private final int limit; + + private final boolean ascending; + + public TopLongFloatAggregatorFunction(DriverContext driverContext, List channels, + TopLongFloatAggregator.SingleState state, int limit, boolean ascending) { + this.driverContext = driverContext; + this.channels = channels; + this.state = state; + this.limit = limit; + this.ascending = ascending; + } + + public static TopLongFloatAggregatorFunction create(DriverContext driverContext, + List channels, int limit, boolean ascending) { + return new TopLongFloatAggregatorFunction(driverContext, channels, TopLongFloatAggregator.initSingle(driverContext.bigArrays(), limit, ascending), limit, ascending); + } + + public static List intermediateStateDesc() { + return INTERMEDIATE_STATE_DESC; + } + + @Override + public int intermediateBlockCount() { + return INTERMEDIATE_STATE_DESC.size(); + } + + @Override + public void addRawInput(Page page, BooleanVector mask) { + if (mask.allFalse()) { + // Entire page masked away + } else if (mask.allTrue()) { + addRawInputNotMasked(page); + } else { + addRawInputMasked(page, mask); + } + } + + private void addRawInputMasked(Page page, BooleanVector mask) { + LongBlock vBlock = page.getBlock(channels.get(0)); + FloatBlock extraBlock = page.getBlock(channels.get(1)); + LongVector vVector = vBlock.asVector(); + if (vVector == null) { + addRawBlock(vBlock, extraBlock, mask); + return; + } + FloatVector extraVector = extraBlock.asVector(); + if (extraVector == null) { + addRawBlock(vBlock, extraBlock, mask); + return; + } + addRawVector(vVector, extraVector, mask); + } + + private void addRawInputNotMasked(Page page) { + LongBlock vBlock = page.getBlock(channels.get(0)); + FloatBlock extraBlock = page.getBlock(channels.get(1)); + LongVector vVector = vBlock.asVector(); + if (vVector == null) { + addRawBlock(vBlock, extraBlock); + return; + } + FloatVector extraVector = extraBlock.asVector(); + if (extraVector == null) { + addRawBlock(vBlock, extraBlock); + return; + } + addRawVector(vVector, extraVector); + } + + private void addRawVector(LongVector vVector, FloatVector extraVector) { + for (int valuesPosition = 0; valuesPosition < vVector.getPositionCount(); valuesPosition++) { + long vValue = vVector.getLong(valuesPosition); + float extraValue = extraVector.getFloat(valuesPosition); + TopLongFloatAggregator.combine(state, vValue, extraValue); + } + } + + private void addRawVector(LongVector vVector, FloatVector extraVector, BooleanVector mask) { + for (int valuesPosition = 0; valuesPosition < vVector.getPositionCount(); valuesPosition++) { + if (mask.getBoolean(valuesPosition) == false) { + continue; + } + long vValue = vVector.getLong(valuesPosition); + float extraValue = extraVector.getFloat(valuesPosition); + TopLongFloatAggregator.combine(state, vValue, extraValue); + } + } + + private void addRawBlock(LongBlock vBlock, FloatBlock extraBlock) { + for (int p = 0; p < vBlock.getPositionCount(); p++) { + if (vBlock.isNull(p)) { + continue; + } + if (extraBlock.isNull(p)) { + continue; + } + int vStart = vBlock.getFirstValueIndex(p); + int vEnd = vStart + vBlock.getValueCount(p); + for (int vOffset = vStart; vOffset < vEnd; vOffset++) { + long vValue = vBlock.getLong(vOffset); + int extraStart = extraBlock.getFirstValueIndex(p); + int extraEnd = extraStart + extraBlock.getValueCount(p); + for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { + float extraValue = extraBlock.getFloat(extraOffset); + TopLongFloatAggregator.combine(state, vValue, extraValue); + } + } + } + } + + private void addRawBlock(LongBlock vBlock, FloatBlock extraBlock, BooleanVector mask) { + for (int p = 0; p < vBlock.getPositionCount(); p++) { + if (mask.getBoolean(p) == false) { + continue; + } + if (vBlock.isNull(p)) { + continue; + } + if (extraBlock.isNull(p)) { + continue; + } + int vStart = vBlock.getFirstValueIndex(p); + int vEnd = vStart + vBlock.getValueCount(p); + for (int vOffset = vStart; vOffset < vEnd; vOffset++) { + long vValue = vBlock.getLong(vOffset); + int extraStart = extraBlock.getFirstValueIndex(p); + int extraEnd = extraStart + extraBlock.getValueCount(p); + for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { + float extraValue = extraBlock.getFloat(extraOffset); + TopLongFloatAggregator.combine(state, vValue, extraValue); + } + } + } + } + + @Override + public void addIntermediateInput(Page page) { + assert channels.size() == intermediateBlockCount(); + assert page.getBlockCount() >= channels.get(0) + intermediateStateDesc().size(); + Block topUncast = page.getBlock(channels.get(0)); + if (topUncast.areAllValuesNull()) { + return; + } + LongBlock top = (LongBlock) topUncast; + assert top.getPositionCount() == 1; + Block extraUncast = page.getBlock(channels.get(1)); + if (extraUncast.areAllValuesNull()) { + return; + } + FloatBlock extra = (FloatBlock) extraUncast; + assert extra.getPositionCount() == 1; + TopLongFloatAggregator.combineIntermediate(state, top, extra); + } + + @Override + public void evaluateIntermediate(Block[] blocks, int offset, DriverContext driverContext) { + state.toIntermediate(blocks, offset, driverContext); + } + + @Override + public void evaluateFinal(Block[] blocks, int offset, DriverContext driverContext) { + blocks[offset] = TopLongFloatAggregator.evaluateFinal(state, driverContext); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append(getClass().getSimpleName()).append("["); + sb.append("channels=").append(channels); + sb.append("]"); + return sb.toString(); + } + + @Override + public void close() { + state.close(); + } +} diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongFloatAggregatorFunctionSupplier.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongFloatAggregatorFunctionSupplier.java new file mode 100644 index 0000000000000..57104208a686a --- /dev/null +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongFloatAggregatorFunctionSupplier.java @@ -0,0 +1,53 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License +// 2.0; you may not use this file except in compliance with the Elastic License +// 2.0. +package org.elasticsearch.compute.aggregation; + +import java.lang.Integer; +import java.lang.Override; +import java.lang.String; +import java.util.List; +import org.elasticsearch.compute.operator.DriverContext; + +/** + * {@link AggregatorFunctionSupplier} implementation for {@link TopLongFloatAggregator}. + * This class is generated. Edit {@code AggregatorFunctionSupplierImplementer} instead. + */ +public final class TopLongFloatAggregatorFunctionSupplier implements AggregatorFunctionSupplier { + private final int limit; + + private final boolean ascending; + + public TopLongFloatAggregatorFunctionSupplier(int limit, boolean ascending) { + this.limit = limit; + this.ascending = ascending; + } + + @Override + public List nonGroupingIntermediateStateDesc() { + return TopLongFloatAggregatorFunction.intermediateStateDesc(); + } + + @Override + public List groupingIntermediateStateDesc() { + return TopLongFloatGroupingAggregatorFunction.intermediateStateDesc(); + } + + @Override + public TopLongFloatAggregatorFunction aggregator(DriverContext driverContext, + List channels) { + return TopLongFloatAggregatorFunction.create(driverContext, channels, limit, ascending); + } + + @Override + public TopLongFloatGroupingAggregatorFunction groupingAggregator(DriverContext driverContext, + List channels) { + return TopLongFloatGroupingAggregatorFunction.create(channels, driverContext, limit, ascending); + } + + @Override + public String describe() { + return "top_long of floats"; + } +} diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongFloatGroupingAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongFloatGroupingAggregatorFunction.java new file mode 100644 index 0000000000000..060c41f9d4216 --- /dev/null +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongFloatGroupingAggregatorFunction.java @@ -0,0 +1,397 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License +// 2.0; you may not use this file except in compliance with the Elastic License +// 2.0. +package org.elasticsearch.compute.aggregation; + +import java.lang.Integer; +import java.lang.Override; +import java.lang.String; +import java.lang.StringBuilder; +import java.util.List; +import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.ElementType; +import org.elasticsearch.compute.data.FloatBlock; +import org.elasticsearch.compute.data.FloatVector; +import org.elasticsearch.compute.data.IntArrayBlock; +import org.elasticsearch.compute.data.IntBigArrayBlock; +import org.elasticsearch.compute.data.IntVector; +import org.elasticsearch.compute.data.LongBlock; +import org.elasticsearch.compute.data.LongVector; +import org.elasticsearch.compute.data.Page; +import org.elasticsearch.compute.operator.DriverContext; + +/** + * {@link GroupingAggregatorFunction} implementation for {@link TopLongFloatAggregator}. + * This class is generated. Edit {@code GroupingAggregatorImplementer} instead. + */ +public final class TopLongFloatGroupingAggregatorFunction implements GroupingAggregatorFunction { + private static final List INTERMEDIATE_STATE_DESC = List.of( + new IntermediateStateDesc("top", ElementType.LONG), + new IntermediateStateDesc("extra", ElementType.FLOAT) ); + + private final TopLongFloatAggregator.GroupingState state; + + private final List channels; + + private final DriverContext driverContext; + + private final int limit; + + private final boolean ascending; + + public TopLongFloatGroupingAggregatorFunction(List channels, + TopLongFloatAggregator.GroupingState state, DriverContext driverContext, int limit, + boolean ascending) { + this.channels = channels; + this.state = state; + this.driverContext = driverContext; + this.limit = limit; + this.ascending = ascending; + } + + public static TopLongFloatGroupingAggregatorFunction create(List channels, + DriverContext driverContext, int limit, boolean ascending) { + return new TopLongFloatGroupingAggregatorFunction(channels, TopLongFloatAggregator.initGrouping(driverContext.bigArrays(), limit, ascending), driverContext, limit, ascending); + } + + public static List intermediateStateDesc() { + return INTERMEDIATE_STATE_DESC; + } + + @Override + public int intermediateBlockCount() { + return INTERMEDIATE_STATE_DESC.size(); + } + + @Override + public GroupingAggregatorFunction.AddInput prepareProcessRawInputPage(SeenGroupIds seenGroupIds, + Page page) { + LongBlock vBlock = page.getBlock(channels.get(0)); + FloatBlock extraBlock = page.getBlock(channels.get(1)); + LongVector vVector = vBlock.asVector(); + if (vVector == null) { + maybeEnableGroupIdTracking(seenGroupIds, vBlock, extraBlock); + return new GroupingAggregatorFunction.AddInput() { + @Override + public void add(int positionOffset, IntArrayBlock groupIds) { + addRawInput(positionOffset, groupIds, vBlock, extraBlock); + } + + @Override + public void add(int positionOffset, IntBigArrayBlock groupIds) { + addRawInput(positionOffset, groupIds, vBlock, extraBlock); + } + + @Override + public void add(int positionOffset, IntVector groupIds) { + addRawInput(positionOffset, groupIds, vBlock, extraBlock); + } + + @Override + public void close() { + } + }; + } + FloatVector extraVector = extraBlock.asVector(); + if (extraVector == null) { + maybeEnableGroupIdTracking(seenGroupIds, vBlock, extraBlock); + return new GroupingAggregatorFunction.AddInput() { + @Override + public void add(int positionOffset, IntArrayBlock groupIds) { + addRawInput(positionOffset, groupIds, vBlock, extraBlock); + } + + @Override + public void add(int positionOffset, IntBigArrayBlock groupIds) { + addRawInput(positionOffset, groupIds, vBlock, extraBlock); + } + + @Override + public void add(int positionOffset, IntVector groupIds) { + addRawInput(positionOffset, groupIds, vBlock, extraBlock); + } + + @Override + public void close() { + } + }; + } + return new GroupingAggregatorFunction.AddInput() { + @Override + public void add(int positionOffset, IntArrayBlock groupIds) { + addRawInput(positionOffset, groupIds, vVector, extraVector); + } + + @Override + public void add(int positionOffset, IntBigArrayBlock groupIds) { + addRawInput(positionOffset, groupIds, vVector, extraVector); + } + + @Override + public void add(int positionOffset, IntVector groupIds) { + addRawInput(positionOffset, groupIds, vVector, extraVector); + } + + @Override + public void close() { + } + }; + } + + private void addRawInput(int positionOffset, IntArrayBlock groups, LongBlock vBlock, + FloatBlock extraBlock) { + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + if (groups.isNull(groupPosition)) { + continue; + } + int valuesPosition = groupPosition + positionOffset; + if (vBlock.isNull(valuesPosition)) { + continue; + } + if (extraBlock.isNull(valuesPosition)) { + continue; + } + int groupStart = groups.getFirstValueIndex(groupPosition); + int groupEnd = groupStart + groups.getValueCount(groupPosition); + for (int g = groupStart; g < groupEnd; g++) { + int groupId = groups.getInt(g); + int vStart = vBlock.getFirstValueIndex(valuesPosition); + int vEnd = vStart + vBlock.getValueCount(valuesPosition); + for (int vOffset = vStart; vOffset < vEnd; vOffset++) { + long vValue = vBlock.getLong(vOffset); + int extraStart = extraBlock.getFirstValueIndex(valuesPosition); + int extraEnd = extraStart + extraBlock.getValueCount(valuesPosition); + for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { + float extraValue = extraBlock.getFloat(extraOffset); + TopLongFloatAggregator.combine(state, groupId, vValue, extraValue); + } + } + } + } + } + + private void addRawInput(int positionOffset, IntArrayBlock groups, LongVector vVector, + FloatVector extraVector) { + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + if (groups.isNull(groupPosition)) { + continue; + } + int valuesPosition = groupPosition + positionOffset; + int groupStart = groups.getFirstValueIndex(groupPosition); + int groupEnd = groupStart + groups.getValueCount(groupPosition); + for (int g = groupStart; g < groupEnd; g++) { + int groupId = groups.getInt(g); + long vValue = vVector.getLong(valuesPosition); + float extraValue = extraVector.getFloat(valuesPosition); + TopLongFloatAggregator.combine(state, groupId, vValue, extraValue); + } + } + } + + @Override + public void addIntermediateInput(int positionOffset, IntArrayBlock groups, Page page) { + state.enableGroupIdTracking(new SeenGroupIds.Empty()); + assert channels.size() == intermediateBlockCount(); + Block topUncast = page.getBlock(channels.get(0)); + if (topUncast.areAllValuesNull()) { + return; + } + LongBlock top = (LongBlock) topUncast; + Block extraUncast = page.getBlock(channels.get(1)); + if (extraUncast.areAllValuesNull()) { + return; + } + FloatBlock extra = (FloatBlock) extraUncast; + assert top.getPositionCount() == extra.getPositionCount(); + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + if (groups.isNull(groupPosition)) { + continue; + } + int groupStart = groups.getFirstValueIndex(groupPosition); + int groupEnd = groupStart + groups.getValueCount(groupPosition); + for (int g = groupStart; g < groupEnd; g++) { + int groupId = groups.getInt(g); + int valuesPosition = groupPosition + positionOffset; + TopLongFloatAggregator.combineIntermediate(state, groupId, top, extra, valuesPosition); + } + } + } + + private void addRawInput(int positionOffset, IntBigArrayBlock groups, LongBlock vBlock, + FloatBlock extraBlock) { + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + if (groups.isNull(groupPosition)) { + continue; + } + int valuesPosition = groupPosition + positionOffset; + if (vBlock.isNull(valuesPosition)) { + continue; + } + if (extraBlock.isNull(valuesPosition)) { + continue; + } + int groupStart = groups.getFirstValueIndex(groupPosition); + int groupEnd = groupStart + groups.getValueCount(groupPosition); + for (int g = groupStart; g < groupEnd; g++) { + int groupId = groups.getInt(g); + int vStart = vBlock.getFirstValueIndex(valuesPosition); + int vEnd = vStart + vBlock.getValueCount(valuesPosition); + for (int vOffset = vStart; vOffset < vEnd; vOffset++) { + long vValue = vBlock.getLong(vOffset); + int extraStart = extraBlock.getFirstValueIndex(valuesPosition); + int extraEnd = extraStart + extraBlock.getValueCount(valuesPosition); + for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { + float extraValue = extraBlock.getFloat(extraOffset); + TopLongFloatAggregator.combine(state, groupId, vValue, extraValue); + } + } + } + } + } + + private void addRawInput(int positionOffset, IntBigArrayBlock groups, LongVector vVector, + FloatVector extraVector) { + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + if (groups.isNull(groupPosition)) { + continue; + } + int valuesPosition = groupPosition + positionOffset; + int groupStart = groups.getFirstValueIndex(groupPosition); + int groupEnd = groupStart + groups.getValueCount(groupPosition); + for (int g = groupStart; g < groupEnd; g++) { + int groupId = groups.getInt(g); + long vValue = vVector.getLong(valuesPosition); + float extraValue = extraVector.getFloat(valuesPosition); + TopLongFloatAggregator.combine(state, groupId, vValue, extraValue); + } + } + } + + @Override + public void addIntermediateInput(int positionOffset, IntBigArrayBlock groups, Page page) { + state.enableGroupIdTracking(new SeenGroupIds.Empty()); + assert channels.size() == intermediateBlockCount(); + Block topUncast = page.getBlock(channels.get(0)); + if (topUncast.areAllValuesNull()) { + return; + } + LongBlock top = (LongBlock) topUncast; + Block extraUncast = page.getBlock(channels.get(1)); + if (extraUncast.areAllValuesNull()) { + return; + } + FloatBlock extra = (FloatBlock) extraUncast; + assert top.getPositionCount() == extra.getPositionCount(); + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + if (groups.isNull(groupPosition)) { + continue; + } + int groupStart = groups.getFirstValueIndex(groupPosition); + int groupEnd = groupStart + groups.getValueCount(groupPosition); + for (int g = groupStart; g < groupEnd; g++) { + int groupId = groups.getInt(g); + int valuesPosition = groupPosition + positionOffset; + TopLongFloatAggregator.combineIntermediate(state, groupId, top, extra, valuesPosition); + } + } + } + + private void addRawInput(int positionOffset, IntVector groups, LongBlock vBlock, + FloatBlock extraBlock) { + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + int valuesPosition = groupPosition + positionOffset; + if (vBlock.isNull(valuesPosition)) { + continue; + } + if (extraBlock.isNull(valuesPosition)) { + continue; + } + int groupId = groups.getInt(groupPosition); + int vStart = vBlock.getFirstValueIndex(valuesPosition); + int vEnd = vStart + vBlock.getValueCount(valuesPosition); + for (int vOffset = vStart; vOffset < vEnd; vOffset++) { + long vValue = vBlock.getLong(vOffset); + int extraStart = extraBlock.getFirstValueIndex(valuesPosition); + int extraEnd = extraStart + extraBlock.getValueCount(valuesPosition); + for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { + float extraValue = extraBlock.getFloat(extraOffset); + TopLongFloatAggregator.combine(state, groupId, vValue, extraValue); + } + } + } + } + + private void addRawInput(int positionOffset, IntVector groups, LongVector vVector, + FloatVector extraVector) { + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + int valuesPosition = groupPosition + positionOffset; + int groupId = groups.getInt(groupPosition); + long vValue = vVector.getLong(valuesPosition); + float extraValue = extraVector.getFloat(valuesPosition); + TopLongFloatAggregator.combine(state, groupId, vValue, extraValue); + } + } + + @Override + public void addIntermediateInput(int positionOffset, IntVector groups, Page page) { + state.enableGroupIdTracking(new SeenGroupIds.Empty()); + assert channels.size() == intermediateBlockCount(); + Block topUncast = page.getBlock(channels.get(0)); + if (topUncast.areAllValuesNull()) { + return; + } + LongBlock top = (LongBlock) topUncast; + Block extraUncast = page.getBlock(channels.get(1)); + if (extraUncast.areAllValuesNull()) { + return; + } + FloatBlock extra = (FloatBlock) extraUncast; + assert top.getPositionCount() == extra.getPositionCount(); + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + int groupId = groups.getInt(groupPosition); + int valuesPosition = groupPosition + positionOffset; + TopLongFloatAggregator.combineIntermediate(state, groupId, top, extra, valuesPosition); + } + } + + private void maybeEnableGroupIdTracking(SeenGroupIds seenGroupIds, LongBlock vBlock, + FloatBlock extraBlock) { + if (vBlock.mayHaveNulls()) { + state.enableGroupIdTracking(seenGroupIds); + } + if (extraBlock.mayHaveNulls()) { + state.enableGroupIdTracking(seenGroupIds); + } + } + + @Override + public void selectedMayContainUnseenGroups(SeenGroupIds seenGroupIds) { + state.enableGroupIdTracking(seenGroupIds); + } + + @Override + public void evaluateIntermediate(Block[] blocks, int offset, IntVector selected) { + state.toIntermediate(blocks, offset, selected, driverContext); + } + + @Override + public void evaluateFinal(Block[] blocks, int offset, IntVector selected, + GroupingAggregatorEvaluationContext ctx) { + blocks[offset] = TopLongFloatAggregator.evaluateFinal(state, selected, ctx); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append(getClass().getSimpleName()).append("["); + sb.append("channels=").append(channels); + sb.append("]"); + return sb.toString(); + } + + @Override + public void close() { + state.close(); + } +} diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongIntAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongIntAggregatorFunction.java new file mode 100644 index 0000000000000..799439e9c0876 --- /dev/null +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongIntAggregatorFunction.java @@ -0,0 +1,215 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License +// 2.0; you may not use this file except in compliance with the Elastic License +// 2.0. +package org.elasticsearch.compute.aggregation; + +import java.lang.Integer; +import java.lang.Override; +import java.lang.String; +import java.lang.StringBuilder; +import java.util.List; +import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.BooleanVector; +import org.elasticsearch.compute.data.ElementType; +import org.elasticsearch.compute.data.IntBlock; +import org.elasticsearch.compute.data.IntVector; +import org.elasticsearch.compute.data.LongBlock; +import org.elasticsearch.compute.data.LongVector; +import org.elasticsearch.compute.data.Page; +import org.elasticsearch.compute.operator.DriverContext; + +/** + * {@link AggregatorFunction} implementation for {@link TopLongIntAggregator}. + * This class is generated. Edit {@code AggregatorImplementer} instead. + */ +public final class TopLongIntAggregatorFunction implements AggregatorFunction { + private static final List INTERMEDIATE_STATE_DESC = List.of( + new IntermediateStateDesc("top", ElementType.LONG), + new IntermediateStateDesc("extra", ElementType.INT) ); + + private final DriverContext driverContext; + + private final TopLongIntAggregator.SingleState state; + + private final List channels; + + private final int limit; + + private final boolean ascending; + + public TopLongIntAggregatorFunction(DriverContext driverContext, List channels, + TopLongIntAggregator.SingleState state, int limit, boolean ascending) { + this.driverContext = driverContext; + this.channels = channels; + this.state = state; + this.limit = limit; + this.ascending = ascending; + } + + public static TopLongIntAggregatorFunction create(DriverContext driverContext, + List channels, int limit, boolean ascending) { + return new TopLongIntAggregatorFunction(driverContext, channels, TopLongIntAggregator.initSingle(driverContext.bigArrays(), limit, ascending), limit, ascending); + } + + public static List intermediateStateDesc() { + return INTERMEDIATE_STATE_DESC; + } + + @Override + public int intermediateBlockCount() { + return INTERMEDIATE_STATE_DESC.size(); + } + + @Override + public void addRawInput(Page page, BooleanVector mask) { + if (mask.allFalse()) { + // Entire page masked away + } else if (mask.allTrue()) { + addRawInputNotMasked(page); + } else { + addRawInputMasked(page, mask); + } + } + + private void addRawInputMasked(Page page, BooleanVector mask) { + LongBlock vBlock = page.getBlock(channels.get(0)); + IntBlock extraBlock = page.getBlock(channels.get(1)); + LongVector vVector = vBlock.asVector(); + if (vVector == null) { + addRawBlock(vBlock, extraBlock, mask); + return; + } + IntVector extraVector = extraBlock.asVector(); + if (extraVector == null) { + addRawBlock(vBlock, extraBlock, mask); + return; + } + addRawVector(vVector, extraVector, mask); + } + + private void addRawInputNotMasked(Page page) { + LongBlock vBlock = page.getBlock(channels.get(0)); + IntBlock extraBlock = page.getBlock(channels.get(1)); + LongVector vVector = vBlock.asVector(); + if (vVector == null) { + addRawBlock(vBlock, extraBlock); + return; + } + IntVector extraVector = extraBlock.asVector(); + if (extraVector == null) { + addRawBlock(vBlock, extraBlock); + return; + } + addRawVector(vVector, extraVector); + } + + private void addRawVector(LongVector vVector, IntVector extraVector) { + for (int valuesPosition = 0; valuesPosition < vVector.getPositionCount(); valuesPosition++) { + long vValue = vVector.getLong(valuesPosition); + int extraValue = extraVector.getInt(valuesPosition); + TopLongIntAggregator.combine(state, vValue, extraValue); + } + } + + private void addRawVector(LongVector vVector, IntVector extraVector, BooleanVector mask) { + for (int valuesPosition = 0; valuesPosition < vVector.getPositionCount(); valuesPosition++) { + if (mask.getBoolean(valuesPosition) == false) { + continue; + } + long vValue = vVector.getLong(valuesPosition); + int extraValue = extraVector.getInt(valuesPosition); + TopLongIntAggregator.combine(state, vValue, extraValue); + } + } + + private void addRawBlock(LongBlock vBlock, IntBlock extraBlock) { + for (int p = 0; p < vBlock.getPositionCount(); p++) { + if (vBlock.isNull(p)) { + continue; + } + if (extraBlock.isNull(p)) { + continue; + } + int vStart = vBlock.getFirstValueIndex(p); + int vEnd = vStart + vBlock.getValueCount(p); + for (int vOffset = vStart; vOffset < vEnd; vOffset++) { + long vValue = vBlock.getLong(vOffset); + int extraStart = extraBlock.getFirstValueIndex(p); + int extraEnd = extraStart + extraBlock.getValueCount(p); + for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { + int extraValue = extraBlock.getInt(extraOffset); + TopLongIntAggregator.combine(state, vValue, extraValue); + } + } + } + } + + private void addRawBlock(LongBlock vBlock, IntBlock extraBlock, BooleanVector mask) { + for (int p = 0; p < vBlock.getPositionCount(); p++) { + if (mask.getBoolean(p) == false) { + continue; + } + if (vBlock.isNull(p)) { + continue; + } + if (extraBlock.isNull(p)) { + continue; + } + int vStart = vBlock.getFirstValueIndex(p); + int vEnd = vStart + vBlock.getValueCount(p); + for (int vOffset = vStart; vOffset < vEnd; vOffset++) { + long vValue = vBlock.getLong(vOffset); + int extraStart = extraBlock.getFirstValueIndex(p); + int extraEnd = extraStart + extraBlock.getValueCount(p); + for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { + int extraValue = extraBlock.getInt(extraOffset); + TopLongIntAggregator.combine(state, vValue, extraValue); + } + } + } + } + + @Override + public void addIntermediateInput(Page page) { + assert channels.size() == intermediateBlockCount(); + assert page.getBlockCount() >= channels.get(0) + intermediateStateDesc().size(); + Block topUncast = page.getBlock(channels.get(0)); + if (topUncast.areAllValuesNull()) { + return; + } + LongBlock top = (LongBlock) topUncast; + assert top.getPositionCount() == 1; + Block extraUncast = page.getBlock(channels.get(1)); + if (extraUncast.areAllValuesNull()) { + return; + } + IntBlock extra = (IntBlock) extraUncast; + assert extra.getPositionCount() == 1; + TopLongIntAggregator.combineIntermediate(state, top, extra); + } + + @Override + public void evaluateIntermediate(Block[] blocks, int offset, DriverContext driverContext) { + state.toIntermediate(blocks, offset, driverContext); + } + + @Override + public void evaluateFinal(Block[] blocks, int offset, DriverContext driverContext) { + blocks[offset] = TopLongIntAggregator.evaluateFinal(state, driverContext); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append(getClass().getSimpleName()).append("["); + sb.append("channels=").append(channels); + sb.append("]"); + return sb.toString(); + } + + @Override + public void close() { + state.close(); + } +} diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongIntAggregatorFunctionSupplier.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongIntAggregatorFunctionSupplier.java new file mode 100644 index 0000000000000..a4d67d1b63a73 --- /dev/null +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongIntAggregatorFunctionSupplier.java @@ -0,0 +1,53 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License +// 2.0; you may not use this file except in compliance with the Elastic License +// 2.0. +package org.elasticsearch.compute.aggregation; + +import java.lang.Integer; +import java.lang.Override; +import java.lang.String; +import java.util.List; +import org.elasticsearch.compute.operator.DriverContext; + +/** + * {@link AggregatorFunctionSupplier} implementation for {@link TopLongIntAggregator}. + * This class is generated. Edit {@code AggregatorFunctionSupplierImplementer} instead. + */ +public final class TopLongIntAggregatorFunctionSupplier implements AggregatorFunctionSupplier { + private final int limit; + + private final boolean ascending; + + public TopLongIntAggregatorFunctionSupplier(int limit, boolean ascending) { + this.limit = limit; + this.ascending = ascending; + } + + @Override + public List nonGroupingIntermediateStateDesc() { + return TopLongIntAggregatorFunction.intermediateStateDesc(); + } + + @Override + public List groupingIntermediateStateDesc() { + return TopLongIntGroupingAggregatorFunction.intermediateStateDesc(); + } + + @Override + public TopLongIntAggregatorFunction aggregator(DriverContext driverContext, + List channels) { + return TopLongIntAggregatorFunction.create(driverContext, channels, limit, ascending); + } + + @Override + public TopLongIntGroupingAggregatorFunction groupingAggregator(DriverContext driverContext, + List channels) { + return TopLongIntGroupingAggregatorFunction.create(channels, driverContext, limit, ascending); + } + + @Override + public String describe() { + return "top_long of ints"; + } +} diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongIntGroupingAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongIntGroupingAggregatorFunction.java new file mode 100644 index 0000000000000..dffa501f4c939 --- /dev/null +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongIntGroupingAggregatorFunction.java @@ -0,0 +1,396 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License +// 2.0; you may not use this file except in compliance with the Elastic License +// 2.0. +package org.elasticsearch.compute.aggregation; + +import java.lang.Integer; +import java.lang.Override; +import java.lang.String; +import java.lang.StringBuilder; +import java.util.List; +import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.ElementType; +import org.elasticsearch.compute.data.IntArrayBlock; +import org.elasticsearch.compute.data.IntBigArrayBlock; +import org.elasticsearch.compute.data.IntBlock; +import org.elasticsearch.compute.data.IntVector; +import org.elasticsearch.compute.data.LongBlock; +import org.elasticsearch.compute.data.LongVector; +import org.elasticsearch.compute.data.Page; +import org.elasticsearch.compute.operator.DriverContext; + +/** + * {@link GroupingAggregatorFunction} implementation for {@link TopLongIntAggregator}. + * This class is generated. Edit {@code GroupingAggregatorImplementer} instead. + */ +public final class TopLongIntGroupingAggregatorFunction implements GroupingAggregatorFunction { + private static final List INTERMEDIATE_STATE_DESC = List.of( + new IntermediateStateDesc("top", ElementType.LONG), + new IntermediateStateDesc("extra", ElementType.INT) ); + + private final TopLongIntAggregator.GroupingState state; + + private final List channels; + + private final DriverContext driverContext; + + private final int limit; + + private final boolean ascending; + + public TopLongIntGroupingAggregatorFunction(List channels, + TopLongIntAggregator.GroupingState state, DriverContext driverContext, int limit, + boolean ascending) { + this.channels = channels; + this.state = state; + this.driverContext = driverContext; + this.limit = limit; + this.ascending = ascending; + } + + public static TopLongIntGroupingAggregatorFunction create(List channels, + DriverContext driverContext, int limit, boolean ascending) { + return new TopLongIntGroupingAggregatorFunction(channels, TopLongIntAggregator.initGrouping(driverContext.bigArrays(), limit, ascending), driverContext, limit, ascending); + } + + public static List intermediateStateDesc() { + return INTERMEDIATE_STATE_DESC; + } + + @Override + public int intermediateBlockCount() { + return INTERMEDIATE_STATE_DESC.size(); + } + + @Override + public GroupingAggregatorFunction.AddInput prepareProcessRawInputPage(SeenGroupIds seenGroupIds, + Page page) { + LongBlock vBlock = page.getBlock(channels.get(0)); + IntBlock extraBlock = page.getBlock(channels.get(1)); + LongVector vVector = vBlock.asVector(); + if (vVector == null) { + maybeEnableGroupIdTracking(seenGroupIds, vBlock, extraBlock); + return new GroupingAggregatorFunction.AddInput() { + @Override + public void add(int positionOffset, IntArrayBlock groupIds) { + addRawInput(positionOffset, groupIds, vBlock, extraBlock); + } + + @Override + public void add(int positionOffset, IntBigArrayBlock groupIds) { + addRawInput(positionOffset, groupIds, vBlock, extraBlock); + } + + @Override + public void add(int positionOffset, IntVector groupIds) { + addRawInput(positionOffset, groupIds, vBlock, extraBlock); + } + + @Override + public void close() { + } + }; + } + IntVector extraVector = extraBlock.asVector(); + if (extraVector == null) { + maybeEnableGroupIdTracking(seenGroupIds, vBlock, extraBlock); + return new GroupingAggregatorFunction.AddInput() { + @Override + public void add(int positionOffset, IntArrayBlock groupIds) { + addRawInput(positionOffset, groupIds, vBlock, extraBlock); + } + + @Override + public void add(int positionOffset, IntBigArrayBlock groupIds) { + addRawInput(positionOffset, groupIds, vBlock, extraBlock); + } + + @Override + public void add(int positionOffset, IntVector groupIds) { + addRawInput(positionOffset, groupIds, vBlock, extraBlock); + } + + @Override + public void close() { + } + }; + } + return new GroupingAggregatorFunction.AddInput() { + @Override + public void add(int positionOffset, IntArrayBlock groupIds) { + addRawInput(positionOffset, groupIds, vVector, extraVector); + } + + @Override + public void add(int positionOffset, IntBigArrayBlock groupIds) { + addRawInput(positionOffset, groupIds, vVector, extraVector); + } + + @Override + public void add(int positionOffset, IntVector groupIds) { + addRawInput(positionOffset, groupIds, vVector, extraVector); + } + + @Override + public void close() { + } + }; + } + + private void addRawInput(int positionOffset, IntArrayBlock groups, LongBlock vBlock, + IntBlock extraBlock) { + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + if (groups.isNull(groupPosition)) { + continue; + } + int valuesPosition = groupPosition + positionOffset; + if (vBlock.isNull(valuesPosition)) { + continue; + } + if (extraBlock.isNull(valuesPosition)) { + continue; + } + int groupStart = groups.getFirstValueIndex(groupPosition); + int groupEnd = groupStart + groups.getValueCount(groupPosition); + for (int g = groupStart; g < groupEnd; g++) { + int groupId = groups.getInt(g); + int vStart = vBlock.getFirstValueIndex(valuesPosition); + int vEnd = vStart + vBlock.getValueCount(valuesPosition); + for (int vOffset = vStart; vOffset < vEnd; vOffset++) { + long vValue = vBlock.getLong(vOffset); + int extraStart = extraBlock.getFirstValueIndex(valuesPosition); + int extraEnd = extraStart + extraBlock.getValueCount(valuesPosition); + for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { + int extraValue = extraBlock.getInt(extraOffset); + TopLongIntAggregator.combine(state, groupId, vValue, extraValue); + } + } + } + } + } + + private void addRawInput(int positionOffset, IntArrayBlock groups, LongVector vVector, + IntVector extraVector) { + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + if (groups.isNull(groupPosition)) { + continue; + } + int valuesPosition = groupPosition + positionOffset; + int groupStart = groups.getFirstValueIndex(groupPosition); + int groupEnd = groupStart + groups.getValueCount(groupPosition); + for (int g = groupStart; g < groupEnd; g++) { + int groupId = groups.getInt(g); + long vValue = vVector.getLong(valuesPosition); + int extraValue = extraVector.getInt(valuesPosition); + TopLongIntAggregator.combine(state, groupId, vValue, extraValue); + } + } + } + + @Override + public void addIntermediateInput(int positionOffset, IntArrayBlock groups, Page page) { + state.enableGroupIdTracking(new SeenGroupIds.Empty()); + assert channels.size() == intermediateBlockCount(); + Block topUncast = page.getBlock(channels.get(0)); + if (topUncast.areAllValuesNull()) { + return; + } + LongBlock top = (LongBlock) topUncast; + Block extraUncast = page.getBlock(channels.get(1)); + if (extraUncast.areAllValuesNull()) { + return; + } + IntBlock extra = (IntBlock) extraUncast; + assert top.getPositionCount() == extra.getPositionCount(); + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + if (groups.isNull(groupPosition)) { + continue; + } + int groupStart = groups.getFirstValueIndex(groupPosition); + int groupEnd = groupStart + groups.getValueCount(groupPosition); + for (int g = groupStart; g < groupEnd; g++) { + int groupId = groups.getInt(g); + int valuesPosition = groupPosition + positionOffset; + TopLongIntAggregator.combineIntermediate(state, groupId, top, extra, valuesPosition); + } + } + } + + private void addRawInput(int positionOffset, IntBigArrayBlock groups, LongBlock vBlock, + IntBlock extraBlock) { + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + if (groups.isNull(groupPosition)) { + continue; + } + int valuesPosition = groupPosition + positionOffset; + if (vBlock.isNull(valuesPosition)) { + continue; + } + if (extraBlock.isNull(valuesPosition)) { + continue; + } + int groupStart = groups.getFirstValueIndex(groupPosition); + int groupEnd = groupStart + groups.getValueCount(groupPosition); + for (int g = groupStart; g < groupEnd; g++) { + int groupId = groups.getInt(g); + int vStart = vBlock.getFirstValueIndex(valuesPosition); + int vEnd = vStart + vBlock.getValueCount(valuesPosition); + for (int vOffset = vStart; vOffset < vEnd; vOffset++) { + long vValue = vBlock.getLong(vOffset); + int extraStart = extraBlock.getFirstValueIndex(valuesPosition); + int extraEnd = extraStart + extraBlock.getValueCount(valuesPosition); + for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { + int extraValue = extraBlock.getInt(extraOffset); + TopLongIntAggregator.combine(state, groupId, vValue, extraValue); + } + } + } + } + } + + private void addRawInput(int positionOffset, IntBigArrayBlock groups, LongVector vVector, + IntVector extraVector) { + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + if (groups.isNull(groupPosition)) { + continue; + } + int valuesPosition = groupPosition + positionOffset; + int groupStart = groups.getFirstValueIndex(groupPosition); + int groupEnd = groupStart + groups.getValueCount(groupPosition); + for (int g = groupStart; g < groupEnd; g++) { + int groupId = groups.getInt(g); + long vValue = vVector.getLong(valuesPosition); + int extraValue = extraVector.getInt(valuesPosition); + TopLongIntAggregator.combine(state, groupId, vValue, extraValue); + } + } + } + + @Override + public void addIntermediateInput(int positionOffset, IntBigArrayBlock groups, Page page) { + state.enableGroupIdTracking(new SeenGroupIds.Empty()); + assert channels.size() == intermediateBlockCount(); + Block topUncast = page.getBlock(channels.get(0)); + if (topUncast.areAllValuesNull()) { + return; + } + LongBlock top = (LongBlock) topUncast; + Block extraUncast = page.getBlock(channels.get(1)); + if (extraUncast.areAllValuesNull()) { + return; + } + IntBlock extra = (IntBlock) extraUncast; + assert top.getPositionCount() == extra.getPositionCount(); + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + if (groups.isNull(groupPosition)) { + continue; + } + int groupStart = groups.getFirstValueIndex(groupPosition); + int groupEnd = groupStart + groups.getValueCount(groupPosition); + for (int g = groupStart; g < groupEnd; g++) { + int groupId = groups.getInt(g); + int valuesPosition = groupPosition + positionOffset; + TopLongIntAggregator.combineIntermediate(state, groupId, top, extra, valuesPosition); + } + } + } + + private void addRawInput(int positionOffset, IntVector groups, LongBlock vBlock, + IntBlock extraBlock) { + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + int valuesPosition = groupPosition + positionOffset; + if (vBlock.isNull(valuesPosition)) { + continue; + } + if (extraBlock.isNull(valuesPosition)) { + continue; + } + int groupId = groups.getInt(groupPosition); + int vStart = vBlock.getFirstValueIndex(valuesPosition); + int vEnd = vStart + vBlock.getValueCount(valuesPosition); + for (int vOffset = vStart; vOffset < vEnd; vOffset++) { + long vValue = vBlock.getLong(vOffset); + int extraStart = extraBlock.getFirstValueIndex(valuesPosition); + int extraEnd = extraStart + extraBlock.getValueCount(valuesPosition); + for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { + int extraValue = extraBlock.getInt(extraOffset); + TopLongIntAggregator.combine(state, groupId, vValue, extraValue); + } + } + } + } + + private void addRawInput(int positionOffset, IntVector groups, LongVector vVector, + IntVector extraVector) { + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + int valuesPosition = groupPosition + positionOffset; + int groupId = groups.getInt(groupPosition); + long vValue = vVector.getLong(valuesPosition); + int extraValue = extraVector.getInt(valuesPosition); + TopLongIntAggregator.combine(state, groupId, vValue, extraValue); + } + } + + @Override + public void addIntermediateInput(int positionOffset, IntVector groups, Page page) { + state.enableGroupIdTracking(new SeenGroupIds.Empty()); + assert channels.size() == intermediateBlockCount(); + Block topUncast = page.getBlock(channels.get(0)); + if (topUncast.areAllValuesNull()) { + return; + } + LongBlock top = (LongBlock) topUncast; + Block extraUncast = page.getBlock(channels.get(1)); + if (extraUncast.areAllValuesNull()) { + return; + } + IntBlock extra = (IntBlock) extraUncast; + assert top.getPositionCount() == extra.getPositionCount(); + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + int groupId = groups.getInt(groupPosition); + int valuesPosition = groupPosition + positionOffset; + TopLongIntAggregator.combineIntermediate(state, groupId, top, extra, valuesPosition); + } + } + + private void maybeEnableGroupIdTracking(SeenGroupIds seenGroupIds, LongBlock vBlock, + IntBlock extraBlock) { + if (vBlock.mayHaveNulls()) { + state.enableGroupIdTracking(seenGroupIds); + } + if (extraBlock.mayHaveNulls()) { + state.enableGroupIdTracking(seenGroupIds); + } + } + + @Override + public void selectedMayContainUnseenGroups(SeenGroupIds seenGroupIds) { + state.enableGroupIdTracking(seenGroupIds); + } + + @Override + public void evaluateIntermediate(Block[] blocks, int offset, IntVector selected) { + state.toIntermediate(blocks, offset, selected, driverContext); + } + + @Override + public void evaluateFinal(Block[] blocks, int offset, IntVector selected, + GroupingAggregatorEvaluationContext ctx) { + blocks[offset] = TopLongIntAggregator.evaluateFinal(state, selected, ctx); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append(getClass().getSimpleName()).append("["); + sb.append("channels=").append(channels); + sb.append("]"); + return sb.toString(); + } + + @Override + public void close() { + state.close(); + } +} diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongLongAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongLongAggregatorFunction.java new file mode 100644 index 0000000000000..fe8cc4c940c24 --- /dev/null +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongLongAggregatorFunction.java @@ -0,0 +1,213 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License +// 2.0; you may not use this file except in compliance with the Elastic License +// 2.0. +package org.elasticsearch.compute.aggregation; + +import java.lang.Integer; +import java.lang.Override; +import java.lang.String; +import java.lang.StringBuilder; +import java.util.List; +import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.BooleanVector; +import org.elasticsearch.compute.data.ElementType; +import org.elasticsearch.compute.data.LongBlock; +import org.elasticsearch.compute.data.LongVector; +import org.elasticsearch.compute.data.Page; +import org.elasticsearch.compute.operator.DriverContext; + +/** + * {@link AggregatorFunction} implementation for {@link TopLongLongAggregator}. + * This class is generated. Edit {@code AggregatorImplementer} instead. + */ +public final class TopLongLongAggregatorFunction implements AggregatorFunction { + private static final List INTERMEDIATE_STATE_DESC = List.of( + new IntermediateStateDesc("top", ElementType.LONG), + new IntermediateStateDesc("extra", ElementType.LONG) ); + + private final DriverContext driverContext; + + private final TopLongLongAggregator.SingleState state; + + private final List channels; + + private final int limit; + + private final boolean ascending; + + public TopLongLongAggregatorFunction(DriverContext driverContext, List channels, + TopLongLongAggregator.SingleState state, int limit, boolean ascending) { + this.driverContext = driverContext; + this.channels = channels; + this.state = state; + this.limit = limit; + this.ascending = ascending; + } + + public static TopLongLongAggregatorFunction create(DriverContext driverContext, + List channels, int limit, boolean ascending) { + return new TopLongLongAggregatorFunction(driverContext, channels, TopLongLongAggregator.initSingle(driverContext.bigArrays(), limit, ascending), limit, ascending); + } + + public static List intermediateStateDesc() { + return INTERMEDIATE_STATE_DESC; + } + + @Override + public int intermediateBlockCount() { + return INTERMEDIATE_STATE_DESC.size(); + } + + @Override + public void addRawInput(Page page, BooleanVector mask) { + if (mask.allFalse()) { + // Entire page masked away + } else if (mask.allTrue()) { + addRawInputNotMasked(page); + } else { + addRawInputMasked(page, mask); + } + } + + private void addRawInputMasked(Page page, BooleanVector mask) { + LongBlock vBlock = page.getBlock(channels.get(0)); + LongBlock extraBlock = page.getBlock(channels.get(1)); + LongVector vVector = vBlock.asVector(); + if (vVector == null) { + addRawBlock(vBlock, extraBlock, mask); + return; + } + LongVector extraVector = extraBlock.asVector(); + if (extraVector == null) { + addRawBlock(vBlock, extraBlock, mask); + return; + } + addRawVector(vVector, extraVector, mask); + } + + private void addRawInputNotMasked(Page page) { + LongBlock vBlock = page.getBlock(channels.get(0)); + LongBlock extraBlock = page.getBlock(channels.get(1)); + LongVector vVector = vBlock.asVector(); + if (vVector == null) { + addRawBlock(vBlock, extraBlock); + return; + } + LongVector extraVector = extraBlock.asVector(); + if (extraVector == null) { + addRawBlock(vBlock, extraBlock); + return; + } + addRawVector(vVector, extraVector); + } + + private void addRawVector(LongVector vVector, LongVector extraVector) { + for (int valuesPosition = 0; valuesPosition < vVector.getPositionCount(); valuesPosition++) { + long vValue = vVector.getLong(valuesPosition); + long extraValue = extraVector.getLong(valuesPosition); + TopLongLongAggregator.combine(state, vValue, extraValue); + } + } + + private void addRawVector(LongVector vVector, LongVector extraVector, BooleanVector mask) { + for (int valuesPosition = 0; valuesPosition < vVector.getPositionCount(); valuesPosition++) { + if (mask.getBoolean(valuesPosition) == false) { + continue; + } + long vValue = vVector.getLong(valuesPosition); + long extraValue = extraVector.getLong(valuesPosition); + TopLongLongAggregator.combine(state, vValue, extraValue); + } + } + + private void addRawBlock(LongBlock vBlock, LongBlock extraBlock) { + for (int p = 0; p < vBlock.getPositionCount(); p++) { + if (vBlock.isNull(p)) { + continue; + } + if (extraBlock.isNull(p)) { + continue; + } + int vStart = vBlock.getFirstValueIndex(p); + int vEnd = vStart + vBlock.getValueCount(p); + for (int vOffset = vStart; vOffset < vEnd; vOffset++) { + long vValue = vBlock.getLong(vOffset); + int extraStart = extraBlock.getFirstValueIndex(p); + int extraEnd = extraStart + extraBlock.getValueCount(p); + for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { + long extraValue = extraBlock.getLong(extraOffset); + TopLongLongAggregator.combine(state, vValue, extraValue); + } + } + } + } + + private void addRawBlock(LongBlock vBlock, LongBlock extraBlock, BooleanVector mask) { + for (int p = 0; p < vBlock.getPositionCount(); p++) { + if (mask.getBoolean(p) == false) { + continue; + } + if (vBlock.isNull(p)) { + continue; + } + if (extraBlock.isNull(p)) { + continue; + } + int vStart = vBlock.getFirstValueIndex(p); + int vEnd = vStart + vBlock.getValueCount(p); + for (int vOffset = vStart; vOffset < vEnd; vOffset++) { + long vValue = vBlock.getLong(vOffset); + int extraStart = extraBlock.getFirstValueIndex(p); + int extraEnd = extraStart + extraBlock.getValueCount(p); + for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { + long extraValue = extraBlock.getLong(extraOffset); + TopLongLongAggregator.combine(state, vValue, extraValue); + } + } + } + } + + @Override + public void addIntermediateInput(Page page) { + assert channels.size() == intermediateBlockCount(); + assert page.getBlockCount() >= channels.get(0) + intermediateStateDesc().size(); + Block topUncast = page.getBlock(channels.get(0)); + if (topUncast.areAllValuesNull()) { + return; + } + LongBlock top = (LongBlock) topUncast; + assert top.getPositionCount() == 1; + Block extraUncast = page.getBlock(channels.get(1)); + if (extraUncast.areAllValuesNull()) { + return; + } + LongBlock extra = (LongBlock) extraUncast; + assert extra.getPositionCount() == 1; + TopLongLongAggregator.combineIntermediate(state, top, extra); + } + + @Override + public void evaluateIntermediate(Block[] blocks, int offset, DriverContext driverContext) { + state.toIntermediate(blocks, offset, driverContext); + } + + @Override + public void evaluateFinal(Block[] blocks, int offset, DriverContext driverContext) { + blocks[offset] = TopLongLongAggregator.evaluateFinal(state, driverContext); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append(getClass().getSimpleName()).append("["); + sb.append("channels=").append(channels); + sb.append("]"); + return sb.toString(); + } + + @Override + public void close() { + state.close(); + } +} diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongLongAggregatorFunctionSupplier.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongLongAggregatorFunctionSupplier.java new file mode 100644 index 0000000000000..ad17808763bed --- /dev/null +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongLongAggregatorFunctionSupplier.java @@ -0,0 +1,53 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License +// 2.0; you may not use this file except in compliance with the Elastic License +// 2.0. +package org.elasticsearch.compute.aggregation; + +import java.lang.Integer; +import java.lang.Override; +import java.lang.String; +import java.util.List; +import org.elasticsearch.compute.operator.DriverContext; + +/** + * {@link AggregatorFunctionSupplier} implementation for {@link TopLongLongAggregator}. + * This class is generated. Edit {@code AggregatorFunctionSupplierImplementer} instead. + */ +public final class TopLongLongAggregatorFunctionSupplier implements AggregatorFunctionSupplier { + private final int limit; + + private final boolean ascending; + + public TopLongLongAggregatorFunctionSupplier(int limit, boolean ascending) { + this.limit = limit; + this.ascending = ascending; + } + + @Override + public List nonGroupingIntermediateStateDesc() { + return TopLongLongAggregatorFunction.intermediateStateDesc(); + } + + @Override + public List groupingIntermediateStateDesc() { + return TopLongLongGroupingAggregatorFunction.intermediateStateDesc(); + } + + @Override + public TopLongLongAggregatorFunction aggregator(DriverContext driverContext, + List channels) { + return TopLongLongAggregatorFunction.create(driverContext, channels, limit, ascending); + } + + @Override + public TopLongLongGroupingAggregatorFunction groupingAggregator(DriverContext driverContext, + List channels) { + return TopLongLongGroupingAggregatorFunction.create(channels, driverContext, limit, ascending); + } + + @Override + public String describe() { + return "top_long of longs"; + } +} diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongLongGroupingAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongLongGroupingAggregatorFunction.java new file mode 100644 index 0000000000000..aaf8496e61d5d --- /dev/null +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongLongGroupingAggregatorFunction.java @@ -0,0 +1,395 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License +// 2.0; you may not use this file except in compliance with the Elastic License +// 2.0. +package org.elasticsearch.compute.aggregation; + +import java.lang.Integer; +import java.lang.Override; +import java.lang.String; +import java.lang.StringBuilder; +import java.util.List; +import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.ElementType; +import org.elasticsearch.compute.data.IntArrayBlock; +import org.elasticsearch.compute.data.IntBigArrayBlock; +import org.elasticsearch.compute.data.IntVector; +import org.elasticsearch.compute.data.LongBlock; +import org.elasticsearch.compute.data.LongVector; +import org.elasticsearch.compute.data.Page; +import org.elasticsearch.compute.operator.DriverContext; + +/** + * {@link GroupingAggregatorFunction} implementation for {@link TopLongLongAggregator}. + * This class is generated. Edit {@code GroupingAggregatorImplementer} instead. + */ +public final class TopLongLongGroupingAggregatorFunction implements GroupingAggregatorFunction { + private static final List INTERMEDIATE_STATE_DESC = List.of( + new IntermediateStateDesc("top", ElementType.LONG), + new IntermediateStateDesc("extra", ElementType.LONG) ); + + private final TopLongLongAggregator.GroupingState state; + + private final List channels; + + private final DriverContext driverContext; + + private final int limit; + + private final boolean ascending; + + public TopLongLongGroupingAggregatorFunction(List channels, + TopLongLongAggregator.GroupingState state, DriverContext driverContext, int limit, + boolean ascending) { + this.channels = channels; + this.state = state; + this.driverContext = driverContext; + this.limit = limit; + this.ascending = ascending; + } + + public static TopLongLongGroupingAggregatorFunction create(List channels, + DriverContext driverContext, int limit, boolean ascending) { + return new TopLongLongGroupingAggregatorFunction(channels, TopLongLongAggregator.initGrouping(driverContext.bigArrays(), limit, ascending), driverContext, limit, ascending); + } + + public static List intermediateStateDesc() { + return INTERMEDIATE_STATE_DESC; + } + + @Override + public int intermediateBlockCount() { + return INTERMEDIATE_STATE_DESC.size(); + } + + @Override + public GroupingAggregatorFunction.AddInput prepareProcessRawInputPage(SeenGroupIds seenGroupIds, + Page page) { + LongBlock vBlock = page.getBlock(channels.get(0)); + LongBlock extraBlock = page.getBlock(channels.get(1)); + LongVector vVector = vBlock.asVector(); + if (vVector == null) { + maybeEnableGroupIdTracking(seenGroupIds, vBlock, extraBlock); + return new GroupingAggregatorFunction.AddInput() { + @Override + public void add(int positionOffset, IntArrayBlock groupIds) { + addRawInput(positionOffset, groupIds, vBlock, extraBlock); + } + + @Override + public void add(int positionOffset, IntBigArrayBlock groupIds) { + addRawInput(positionOffset, groupIds, vBlock, extraBlock); + } + + @Override + public void add(int positionOffset, IntVector groupIds) { + addRawInput(positionOffset, groupIds, vBlock, extraBlock); + } + + @Override + public void close() { + } + }; + } + LongVector extraVector = extraBlock.asVector(); + if (extraVector == null) { + maybeEnableGroupIdTracking(seenGroupIds, vBlock, extraBlock); + return new GroupingAggregatorFunction.AddInput() { + @Override + public void add(int positionOffset, IntArrayBlock groupIds) { + addRawInput(positionOffset, groupIds, vBlock, extraBlock); + } + + @Override + public void add(int positionOffset, IntBigArrayBlock groupIds) { + addRawInput(positionOffset, groupIds, vBlock, extraBlock); + } + + @Override + public void add(int positionOffset, IntVector groupIds) { + addRawInput(positionOffset, groupIds, vBlock, extraBlock); + } + + @Override + public void close() { + } + }; + } + return new GroupingAggregatorFunction.AddInput() { + @Override + public void add(int positionOffset, IntArrayBlock groupIds) { + addRawInput(positionOffset, groupIds, vVector, extraVector); + } + + @Override + public void add(int positionOffset, IntBigArrayBlock groupIds) { + addRawInput(positionOffset, groupIds, vVector, extraVector); + } + + @Override + public void add(int positionOffset, IntVector groupIds) { + addRawInput(positionOffset, groupIds, vVector, extraVector); + } + + @Override + public void close() { + } + }; + } + + private void addRawInput(int positionOffset, IntArrayBlock groups, LongBlock vBlock, + LongBlock extraBlock) { + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + if (groups.isNull(groupPosition)) { + continue; + } + int valuesPosition = groupPosition + positionOffset; + if (vBlock.isNull(valuesPosition)) { + continue; + } + if (extraBlock.isNull(valuesPosition)) { + continue; + } + int groupStart = groups.getFirstValueIndex(groupPosition); + int groupEnd = groupStart + groups.getValueCount(groupPosition); + for (int g = groupStart; g < groupEnd; g++) { + int groupId = groups.getInt(g); + int vStart = vBlock.getFirstValueIndex(valuesPosition); + int vEnd = vStart + vBlock.getValueCount(valuesPosition); + for (int vOffset = vStart; vOffset < vEnd; vOffset++) { + long vValue = vBlock.getLong(vOffset); + int extraStart = extraBlock.getFirstValueIndex(valuesPosition); + int extraEnd = extraStart + extraBlock.getValueCount(valuesPosition); + for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { + long extraValue = extraBlock.getLong(extraOffset); + TopLongLongAggregator.combine(state, groupId, vValue, extraValue); + } + } + } + } + } + + private void addRawInput(int positionOffset, IntArrayBlock groups, LongVector vVector, + LongVector extraVector) { + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + if (groups.isNull(groupPosition)) { + continue; + } + int valuesPosition = groupPosition + positionOffset; + int groupStart = groups.getFirstValueIndex(groupPosition); + int groupEnd = groupStart + groups.getValueCount(groupPosition); + for (int g = groupStart; g < groupEnd; g++) { + int groupId = groups.getInt(g); + long vValue = vVector.getLong(valuesPosition); + long extraValue = extraVector.getLong(valuesPosition); + TopLongLongAggregator.combine(state, groupId, vValue, extraValue); + } + } + } + + @Override + public void addIntermediateInput(int positionOffset, IntArrayBlock groups, Page page) { + state.enableGroupIdTracking(new SeenGroupIds.Empty()); + assert channels.size() == intermediateBlockCount(); + Block topUncast = page.getBlock(channels.get(0)); + if (topUncast.areAllValuesNull()) { + return; + } + LongBlock top = (LongBlock) topUncast; + Block extraUncast = page.getBlock(channels.get(1)); + if (extraUncast.areAllValuesNull()) { + return; + } + LongBlock extra = (LongBlock) extraUncast; + assert top.getPositionCount() == extra.getPositionCount(); + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + if (groups.isNull(groupPosition)) { + continue; + } + int groupStart = groups.getFirstValueIndex(groupPosition); + int groupEnd = groupStart + groups.getValueCount(groupPosition); + for (int g = groupStart; g < groupEnd; g++) { + int groupId = groups.getInt(g); + int valuesPosition = groupPosition + positionOffset; + TopLongLongAggregator.combineIntermediate(state, groupId, top, extra, valuesPosition); + } + } + } + + private void addRawInput(int positionOffset, IntBigArrayBlock groups, LongBlock vBlock, + LongBlock extraBlock) { + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + if (groups.isNull(groupPosition)) { + continue; + } + int valuesPosition = groupPosition + positionOffset; + if (vBlock.isNull(valuesPosition)) { + continue; + } + if (extraBlock.isNull(valuesPosition)) { + continue; + } + int groupStart = groups.getFirstValueIndex(groupPosition); + int groupEnd = groupStart + groups.getValueCount(groupPosition); + for (int g = groupStart; g < groupEnd; g++) { + int groupId = groups.getInt(g); + int vStart = vBlock.getFirstValueIndex(valuesPosition); + int vEnd = vStart + vBlock.getValueCount(valuesPosition); + for (int vOffset = vStart; vOffset < vEnd; vOffset++) { + long vValue = vBlock.getLong(vOffset); + int extraStart = extraBlock.getFirstValueIndex(valuesPosition); + int extraEnd = extraStart + extraBlock.getValueCount(valuesPosition); + for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { + long extraValue = extraBlock.getLong(extraOffset); + TopLongLongAggregator.combine(state, groupId, vValue, extraValue); + } + } + } + } + } + + private void addRawInput(int positionOffset, IntBigArrayBlock groups, LongVector vVector, + LongVector extraVector) { + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + if (groups.isNull(groupPosition)) { + continue; + } + int valuesPosition = groupPosition + positionOffset; + int groupStart = groups.getFirstValueIndex(groupPosition); + int groupEnd = groupStart + groups.getValueCount(groupPosition); + for (int g = groupStart; g < groupEnd; g++) { + int groupId = groups.getInt(g); + long vValue = vVector.getLong(valuesPosition); + long extraValue = extraVector.getLong(valuesPosition); + TopLongLongAggregator.combine(state, groupId, vValue, extraValue); + } + } + } + + @Override + public void addIntermediateInput(int positionOffset, IntBigArrayBlock groups, Page page) { + state.enableGroupIdTracking(new SeenGroupIds.Empty()); + assert channels.size() == intermediateBlockCount(); + Block topUncast = page.getBlock(channels.get(0)); + if (topUncast.areAllValuesNull()) { + return; + } + LongBlock top = (LongBlock) topUncast; + Block extraUncast = page.getBlock(channels.get(1)); + if (extraUncast.areAllValuesNull()) { + return; + } + LongBlock extra = (LongBlock) extraUncast; + assert top.getPositionCount() == extra.getPositionCount(); + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + if (groups.isNull(groupPosition)) { + continue; + } + int groupStart = groups.getFirstValueIndex(groupPosition); + int groupEnd = groupStart + groups.getValueCount(groupPosition); + for (int g = groupStart; g < groupEnd; g++) { + int groupId = groups.getInt(g); + int valuesPosition = groupPosition + positionOffset; + TopLongLongAggregator.combineIntermediate(state, groupId, top, extra, valuesPosition); + } + } + } + + private void addRawInput(int positionOffset, IntVector groups, LongBlock vBlock, + LongBlock extraBlock) { + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + int valuesPosition = groupPosition + positionOffset; + if (vBlock.isNull(valuesPosition)) { + continue; + } + if (extraBlock.isNull(valuesPosition)) { + continue; + } + int groupId = groups.getInt(groupPosition); + int vStart = vBlock.getFirstValueIndex(valuesPosition); + int vEnd = vStart + vBlock.getValueCount(valuesPosition); + for (int vOffset = vStart; vOffset < vEnd; vOffset++) { + long vValue = vBlock.getLong(vOffset); + int extraStart = extraBlock.getFirstValueIndex(valuesPosition); + int extraEnd = extraStart + extraBlock.getValueCount(valuesPosition); + for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { + long extraValue = extraBlock.getLong(extraOffset); + TopLongLongAggregator.combine(state, groupId, vValue, extraValue); + } + } + } + } + + private void addRawInput(int positionOffset, IntVector groups, LongVector vVector, + LongVector extraVector) { + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + int valuesPosition = groupPosition + positionOffset; + int groupId = groups.getInt(groupPosition); + long vValue = vVector.getLong(valuesPosition); + long extraValue = extraVector.getLong(valuesPosition); + TopLongLongAggregator.combine(state, groupId, vValue, extraValue); + } + } + + @Override + public void addIntermediateInput(int positionOffset, IntVector groups, Page page) { + state.enableGroupIdTracking(new SeenGroupIds.Empty()); + assert channels.size() == intermediateBlockCount(); + Block topUncast = page.getBlock(channels.get(0)); + if (topUncast.areAllValuesNull()) { + return; + } + LongBlock top = (LongBlock) topUncast; + Block extraUncast = page.getBlock(channels.get(1)); + if (extraUncast.areAllValuesNull()) { + return; + } + LongBlock extra = (LongBlock) extraUncast; + assert top.getPositionCount() == extra.getPositionCount(); + for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { + int groupId = groups.getInt(groupPosition); + int valuesPosition = groupPosition + positionOffset; + TopLongLongAggregator.combineIntermediate(state, groupId, top, extra, valuesPosition); + } + } + + private void maybeEnableGroupIdTracking(SeenGroupIds seenGroupIds, LongBlock vBlock, + LongBlock extraBlock) { + if (vBlock.mayHaveNulls()) { + state.enableGroupIdTracking(seenGroupIds); + } + if (extraBlock.mayHaveNulls()) { + state.enableGroupIdTracking(seenGroupIds); + } + } + + @Override + public void selectedMayContainUnseenGroups(SeenGroupIds seenGroupIds) { + state.enableGroupIdTracking(seenGroupIds); + } + + @Override + public void evaluateIntermediate(Block[] blocks, int offset, IntVector selected) { + state.toIntermediate(blocks, offset, selected, driverContext); + } + + @Override + public void evaluateFinal(Block[] blocks, int offset, IntVector selected, + GroupingAggregatorEvaluationContext ctx) { + blocks[offset] = TopLongLongAggregator.evaluateFinal(state, selected, ctx); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append(getClass().getSimpleName()).append("["); + sb.append("channels=").append(channels); + sb.append("]"); + return sb.toString(); + } + + @Override + public void close() { + state.close(); + } +} diff --git a/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/X-TopAggregator.java.st b/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/X-TopAggregator.java.st index f2ad759a6d57f..5028564213939 100644 --- a/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/X-TopAggregator.java.st +++ b/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/X-TopAggregator.java.st @@ -17,9 +17,11 @@ import org.elasticsearch.compute.ann.IntermediateState; import org.elasticsearch.compute.data.Block; import org.elasticsearch.compute.data.BlockFactory; import org.elasticsearch.compute.data.$Type$Block; +$if(hasExtra)$ +import org.elasticsearch.compute.data.$ExtraType$Block; +$endif$ import org.elasticsearch.compute.data.IntVector; -import org.elasticsearch.compute.data.$Type$Block; -import org.elasticsearch.compute.data.sort.$Name$BucketedSort; +import org.elasticsearch.compute.data.sort.$Name$$ExtraName$BucketedSort; import org.elasticsearch.compute.operator.DriverContext; import org.elasticsearch.core.Releasables; import org.elasticsearch.search.sort.SortOrder; @@ -31,28 +33,32 @@ import org.elasticsearch.search.sort.SortOrder; * This class is generated. Edit `X-TopAggregator.java.st` to edit this file. *

*/ +$if(hasExtra)$ +@Aggregator({ @IntermediateState(name = "top", type = "$TYPE$_BLOCK"), @IntermediateState(name = "extra", type = "$ExtraTYPE$_BLOCK") }) +$else$ @Aggregator({ @IntermediateState(name = "top", type = "$TYPE$_BLOCK") }) +$endif$ @GroupingAggregator -class Top$Name$Aggregator { +class Top$Name$$ExtraName$Aggregator { public static SingleState initSingle(BigArrays bigArrays, int limit, boolean ascending) { return new SingleState(bigArrays, limit, ascending); } - public static void combine(SingleState state, $type$ v) { - state.add(v); + public static void combine(SingleState state, $type$ v$if(hasExtra)$, $Extratype$ extra$endif$) { + state.add(v$if(hasExtra)$, extra$endif$); } - public static void combineIntermediate(SingleState state, $Type$Block values) { + public static void combineIntermediate(SingleState state, $Type$Block values$if(hasExtra)$, $ExtraType$Block extras$endif$) { int start = values.getFirstValueIndex(0); int end = start + values.getValueCount(0); $if(BytesRef || Ip)$ var scratch = new BytesRef(); for (int i = start; i < end; i++) { - combine(state, values.get$Type$(i, scratch)); + combine(state, values.get$Type$(i, scratch)$if(hasExtra)$, extras.get$ExtraType$(i)$endif$); } $else$ for (int i = start; i < end; i++) { - combine(state, values.get$Type$(i)); + combine(state, values.get$Type$(i)$if(hasExtra)$, extras.get$ExtraType$(i)$endif$); } $endif$ } @@ -65,21 +71,21 @@ $endif$ return new GroupingState(bigArrays, limit, ascending); } - public static void combine(GroupingState state, int groupId, $type$ v) { - state.add(groupId, v); + public static void combine(GroupingState state, int groupId, $type$ v$if(hasExtra)$, $Extratype$ extra$endif$) { + state.add(groupId, v$if(hasExtra)$, extra$endif$); } - public static void combineIntermediate(GroupingState state, int groupId, $Type$Block values, int valuesPosition) { + public static void combineIntermediate(GroupingState state, int groupId, $Type$Block values, $if(hasExtra)$$ExtraType$Block extras, $endif$int valuesPosition) { int start = values.getFirstValueIndex(valuesPosition); int end = start + values.getValueCount(valuesPosition); $if(BytesRef || Ip)$ var scratch = new BytesRef(); for (int i = start; i < end; i++) { - combine(state, groupId, values.get$Type$(i, scratch)); + combine(state, groupId, values.get$Type$(i, scratch)$if(hasExtra)$, extras.get$ExtraType$(i)$endif$); } $else$ for (int i = start; i < end; i++) { - combine(state, groupId, values.get$Type$(i)); + combine(state, groupId, values.get$Type$(i)$if(hasExtra)$, extras.get$ExtraType$(i)$endif$); } $endif$ } @@ -89,7 +95,7 @@ $endif$ } public static class GroupingState implements GroupingAggregatorState { - private final $Name$BucketedSort sort; + private final $Name$$ExtraName$BucketedSort sort; private GroupingState(BigArrays bigArrays, int limit, boolean ascending) { $if(BytesRef)$ @@ -97,22 +103,36 @@ $if(BytesRef)$ CircuitBreaker breaker = bigArrays.breakerService().getBreaker(CircuitBreaker.REQUEST); this.sort = new BytesRefBucketedSort(breaker, "top", bigArrays, ascending ? SortOrder.ASC : SortOrder.DESC, limit); $else$ - this.sort = new $Name$BucketedSort(bigArrays, ascending ? SortOrder.ASC : SortOrder.DESC, limit); + this.sort = new $Name$$ExtraName$BucketedSort(bigArrays, ascending ? SortOrder.ASC : SortOrder.DESC, limit); $endif$ } - public void add(int groupId, $type$ value) { - sort.collect(value, groupId); + public void add(int groupId, $type$ value$if(hasExtra)$, $Extratype$ extra$endif$) { + sort.collect(value, $if(hasExtra)$extra, $endif$groupId); } @Override public void toIntermediate(Block[] blocks, int offset, IntVector selected, DriverContext driverContext) { +$if(hasExtra)$ + sort.toBlocks(driverContext.blockFactory(), blocks, offset, selected); +$else$ blocks[offset] = toBlock(driverContext.blockFactory(), selected); +$endif$ } +$if(hasExtra)$ + Block toBlock(BlockFactory blockFactory, IntVector selected) { + Block[] blocks = new Block[2]; + sort.toBlocks(blockFactory, blocks, 0, selected); + Releasables.close(blocks[0]); + return blocks[1]; + } + +$else$ Block toBlock(BlockFactory blockFactory, IntVector selected) { return sort.toBlock(blockFactory, selected); } +$endif$ @Override public void enableGroupIdTracking(SeenGroupIds seen) { @@ -132,13 +152,15 @@ $endif$ this.internalState = new GroupingState(bigArrays, limit, ascending); } - public void add($type$ value) { - internalState.add(0, value); + public void add($type$ value$if(hasExtra)$, $Extratype$ extra$endif$) { + internalState.add(0, value$if(hasExtra)$, extra$endif$); } @Override public void toIntermediate(Block[] blocks, int offset, DriverContext driverContext) { - blocks[offset] = toBlock(driverContext.blockFactory()); + try (var intValues = driverContext.blockFactory().newConstantIntVector(0, 1)) { + internalState.toIntermediate(blocks, offset, intValues, driverContext); + } } Block toBlock(BlockFactory blockFactory) { diff --git a/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/data/sort/X-BucketedSort.java.st b/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/data/sort/X-BucketedSort.java.st index 39eead2ed3044..6efe35406c4b2 100644 --- a/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/data/sort/X-BucketedSort.java.st +++ b/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/data/sort/X-BucketedSort.java.st @@ -9,6 +9,9 @@ package org.elasticsearch.compute.data.sort; import org.elasticsearch.common.util.BigArrays; import org.elasticsearch.common.util.BitArray; +$if(hasExtra && !(long && Extralong))$ +import org.elasticsearch.common.util.$ExtraType$Array; +$endif$ import org.elasticsearch.common.util.$Type$Array; import org.elasticsearch.common.util.PageCacheRecycler; import org.elasticsearch.compute.data.Block; @@ -23,11 +26,11 @@ import org.elasticsearch.search.sort.SortOrder; import java.util.stream.IntStream; /** - * Aggregates the top N $type$ values per bucket. + * Aggregates the top N {@code $type$} values per bucket. * See {@link BucketedSort} for more information. * This class is generated. Edit @{code X-BucketedSort.java.st} instead of this file. */ -public class $Type$BucketedSort implements Releasable { +public class $Name$$ExtraName$BucketedSort implements Releasable { private final BigArrays bigArrays; private final SortOrder order; @@ -64,9 +67,15 @@ public class $Type$BucketedSort implements Releasable { * * */ - private $Type$Array values; +$if(hasExtra)$ + private $Array$ values; + private $ExtraArray$ extraValues; + +$else$ + private $Array$ values; +$endif$ - public $Type$BucketedSort(BigArrays bigArrays, SortOrder order, int bucketSize) { + public $Name$$ExtraName$BucketedSort(BigArrays bigArrays, SortOrder order, int bucketSize) { this.bigArrays = bigArrays; this.order = order; this.bucketSize = bucketSize; @@ -75,6 +84,9 @@ public class $Type$BucketedSort implements Releasable { boolean success = false; try { values = bigArrays.new$Type$Array(0, false); +$if(hasExtra)$ + extraValues = bigArrays.new$ExtraType$Array(0, false); +$endif$ success = true; } finally { if (success == false) { @@ -89,11 +101,14 @@ public class $Type$BucketedSort implements Releasable { * It may or may not be inserted in the heap, depending on if it is better than the current root. *

*/ - public void collect($type$ value, int bucket) { + public void collect($type$ value, $if(hasExtra)$$Extratype$ extraValue, $endif$int bucket) { long rootIndex = (long) bucket * bucketSize; if (inHeapMode(bucket)) { - if (betterThan(value, values.get(rootIndex))) { + if (betterThan(value, values.get(rootIndex)$if(hasExtra)$, extraValue, extraValues.get(rootIndex)$endif$)) { values.set(rootIndex, value); +$if(hasExtra)$ + extraValues.set(rootIndex, extraValue); +$endif$ downHeap(rootIndex, 0, bucketSize); } return; @@ -108,6 +123,9 @@ public class $Type$BucketedSort implements Releasable { : "Expected next to be in the range of valid buckets [0 <= " + next + " < " + bucketSize + "]"; long index = next + rootIndex; values.set(index, value); +$if(hasExtra)$ + extraValues.set(index, extraValue); +$endif$ if (next == 0) { heapMode.set(bucket); heapify(rootIndex, bucketSize); @@ -148,26 +166,77 @@ public class $Type$BucketedSort implements Releasable { /** * Merge the values from {@code other}'s {@code otherGroupId} into {@code groupId}. */ - public void merge(int groupId, $Type$BucketedSort other, int otherGroupId) { + public void merge(int groupId, $Name$$ExtraName$BucketedSort other, int otherGroupId) { var otherBounds = other.getBucketValuesIndexes(otherGroupId); // TODO: This can be improved for heapified buckets by making use of the heap structures for (long i = otherBounds.v1(); i < otherBounds.v2(); i++) { - collect(other.values.get(i), groupId); + collect(other.values.get(i), $if(hasExtra)$other.extraValues.get(i), $endif$groupId); } } +$if(hasExtra)$ /** * Creates a block with the values from the {@code selected} groups. */ - public Block toBlock(BlockFactory blockFactory, IntVector selected) { + public void toBlocks(BlockFactory blockFactory, Block[] blocks, int offset, IntVector selected) { // Check if the selected groups are all empty, to avoid allocating extra memory - if (IntStream.range(0, selected.getPositionCount()).map(selected::getInt).noneMatch(bucket -> { - var bounds = this.getBucketValuesIndexes(bucket); - var size = bounds.v2() - bounds.v1(); + if (allSelectedGroupsAreEmpty(selected)) { + blocks[offset] = blockFactory.newConstantNullBlock(selected.getPositionCount()); + blocks[offset + 1] = blockFactory.newConstantNullBlock(selected.getPositionCount()); + return; + } - return size > 0; - })) { + try ( + var builder = blockFactory.new$Type$BlockBuilder(selected.getPositionCount()); + var extraBuilder = blockFactory.new$ExtraType$BlockBuilder(selected.getPositionCount()) + ) { + for (int s = 0; s < selected.getPositionCount(); s++) { + int bucket = selected.getInt(s); + + var bounds = getBucketValuesIndexes(bucket); + var rootIndex = bounds.v1(); + var size = bounds.v2() - bounds.v1(); + + if (size == 0) { + builder.appendNull(); + extraBuilder.appendNull(); + continue; + } + + if (size == 1) { + builder.append$Type$(values.get(rootIndex)); + extraBuilder.append$ExtraType$(extraValues.get(rootIndex)); + continue; + } + + // If we are in the gathering mode, we need to heapify before sorting. + if (inHeapMode(bucket) == false) { + heapify(rootIndex, (int) size); + } + heapSort(rootIndex, (int) size); + + builder.beginPositionEntry(); + extraBuilder.beginPositionEntry(); + for (int i = 0; i < size; i++) { + builder.append$Type$(values.get(rootIndex + i)); + extraBuilder.append$ExtraType$(extraValues.get(rootIndex + i)); + } + builder.endPositionEntry(); + extraBuilder.endPositionEntry(); + } + blocks[offset] = builder.build(); + blocks[offset + 1] = extraBuilder.build(); + } + } + +$else$ + /** + * Creates a block with the values from the {@code selected} groups. + */ + public Block toBlock(BlockFactory blockFactory, IntVector selected) { + // Check if the selected groups are all empty, to avoid allocating extra memory + if (allSelectedGroupsAreEmpty(selected)) { return blockFactory.newConstantNullBlock(selected.getPositionCount()); } @@ -185,7 +254,7 @@ public class $Type$BucketedSort implements Releasable { } if (size == 1) { - builder.append$Type$(values.get(bounds.v1())); + builder.append$Type$(values.get(rootIndex)); continue; } @@ -197,13 +266,25 @@ public class $Type$BucketedSort implements Releasable { builder.beginPositionEntry(); for (int i = 0; i < size; i++) { - builder.append$Type$(values.get(bounds.v1() + i)); + builder.append$Type$(values.get(rootIndex + i)); } builder.endPositionEntry(); } return builder.build(); } } +$endif$ + + /** + * Checks if the selected groups are all empty. + */ + private boolean allSelectedGroupsAreEmpty(IntVector selected) { + return IntStream.range(0, selected.getPositionCount()).map(selected::getInt).noneMatch(bucket -> { + var bounds = this.getBucketValuesIndexes(bucket); + var size = bounds.v2() - bounds.v1(); + return size > 0; + }); + } /** * Is this bucket a min heap {@code true} or in gathering mode {@code false}? @@ -237,8 +318,15 @@ $endif$ * the entry at {@code rhs}. "Better" in this means "lower" for * {@link SortOrder#ASC} and "higher" for {@link SortOrder#DESC}. */ - private boolean betterThan($type$ lhs, $type$ rhs) { - return getOrder().reverseMul() * $Wrapper$.compare(lhs, rhs) < 0; + private boolean betterThan($type$ lhs, $type$ rhs$if(hasExtra)$, $Extratype$ lhsExtra, $Extratype$ rhsExtra$endif$) { + int res = $Wrapper$.compare(lhs, rhs); +$if(hasExtra)$ + if (res != 0) { + return getOrder().reverseMul() * res < 0; + } + res = $ExtraWrapper$.compare(lhsExtra, rhsExtra); +$endif$ + return getOrder().reverseMul() * res < 0; } /** @@ -248,6 +336,11 @@ $endif$ var tmp = values.get(lhs); values.set(lhs, values.get(rhs)); values.set(rhs, tmp); +$if(hasExtra)$ + var tmpExtra = extraValues.get(lhs); + extraValues.set(lhs, extraValues.get(rhs)); + extraValues.set(rhs, tmpExtra); +$endif$ } /** @@ -263,6 +356,12 @@ $endif$ // Round up to the next full bucket. newSize = (newSize + bucketSize - 1) / bucketSize; values = bigArrays.resize(values, newSize * bucketSize); +$if(hasExtra)$ + long newExtraSize = BigArrays.overSize(((long) bucket + 1) * bucketSize, PageCacheRecycler.$ExtraTYPE$_PAGE_SIZE, $ExtraBYTES$); + // Round up to the next full bucket. + newExtraSize = (newExtraSize + bucketSize - 1) / bucketSize; + extraValues = bigArrays.resize(extraValues, newExtraSize * bucketSize); +$endif$ // Set the next gather offsets for all newly allocated buckets. fillGatherOffsets(oldMax); } @@ -344,13 +443,23 @@ $endif$ int leftChild = parent * 2 + 1; long leftIndex = rootIndex + leftChild; if (leftChild < heapSize) { - if (betterThan(values.get(worstIndex), values.get(leftIndex))) { + if (betterThan(values.get(worstIndex), values.get(leftIndex)$if(hasExtra)$, extraValues.get(worstIndex), extraValues.get(leftIndex)$endif$)) { worst = leftChild; worstIndex = leftIndex; } int rightChild = leftChild + 1; long rightIndex = rootIndex + rightChild; +$if(hasExtra)$ + if (rightChild < heapSize + && betterThan( + values.get(worstIndex), + values.get(rightIndex), + extraValues.get(worstIndex), + extraValues.get(rightIndex) + )) { +$else$ if (rightChild < heapSize && betterThan(values.get(worstIndex), values.get(rightIndex))) { +$endif$ worst = rightChild; worstIndex = rightIndex; } @@ -365,6 +474,6 @@ $endif$ @Override public final void close() { - Releasables.close(values, heapMode); + Releasables.close(values, $if(hasExtra)$extraValues, $endif$heapMode); } } diff --git a/x-pack/plugin/esql/qa/testFixtures/src/main/resources/stats_top_map.csv-spec b/x-pack/plugin/esql/qa/testFixtures/src/main/resources/stats_top_map.csv-spec new file mode 100644 index 0000000000000..9df9f3b66e218 --- /dev/null +++ b/x-pack/plugin/esql/qa/testFixtures/src/main/resources/stats_top_map.csv-spec @@ -0,0 +1,53 @@ +youngestEmployees +required_capability: agg_top_map_support +FROM employees +| STATS youngest_employees = TOP(birth_date, 3, "desc"), + youngest_employees_salaries = TOP(birth_date, 3, "desc", salary) +; + +youngest_employees:date | youngest_employees_salaries:integer +[1965-01-03T00:00:00.000Z, 1964-10-18T00:00:00.000Z, 1964-06-11T00:00:00.000Z] | [37702, 25976, 45656] +; + +youngestEmployeesByGender +required_capability: agg_top_map_support +FROM employees +| STATS youngest_employees = TOP(birth_date, 3, "desc"), + youngest_employees_salaries = TOP(birth_date, 3, "desc", salary) + BY gender +| SORT gender +| KEEP gender, youngest_employees, youngest_employees_salaries +; + +gender:keyword | youngest_employees:datetime | youngest_employees_salaries:integer +F | [1964-10-18T00:00:00.000Z, 1964-06-02T00:00:00.000Z, 1963-03-21T00:00:00.000Z] | [25976, 56371, 43602] +M | [1965-01-03T00:00:00.000Z, 1964-06-11T00:00:00.000Z, 1964-04-18T00:00:00.000Z] | [37702, 45656, 46595] +null | [1963-06-07T00:00:00.000Z, 1963-06-01T00:00:00.000Z, 1961-05-02T00:00:00.000Z] | [48735, 45797, 61358] +; + +oldestEmployees +required_capability: agg_top_map_support +FROM employees +| STATS oldest_employees = TOP(birth_date, 3, "asc"), + oldest_employees_salaries = TOP(birth_date, 3, "asc", salary) +; + +oldest_employees:date | oldest_employees_salaries:integer +[1952-02-27T00:00:00.000Z, 1952-04-19T00:00:00.000Z, 1952-05-15T00:00:00.000Z] | [71165, 66174, 54518] +; + +oldestEmployeesByGender +required_capability: agg_top_map_support +FROM employees +| STATS oldest_employees = TOP(birth_date, 3, "asc"), + oldest_employees_salaries = TOP(birth_date, 3, "asc", salary) + BY gender +| SORT gender +| KEEP gender, oldest_employees, oldest_employees_salaries +; + +gender:keyword | oldest_employees:datetime | oldest_employees_salaries:integer +F | [1952-04-19T00:00:00.000Z, 1952-05-15T00:00:00.000Z, 1952-06-13T00:00:00.000Z] | [66174, 54518, 62405] +M | [1952-02-27T00:00:00.000Z, 1952-07-08T00:00:00.000Z, 1952-11-13T00:00:00.000Z] | [71165, 48233, 31897] +null | [1953-01-23T00:00:00.000Z, 1953-11-07T00:00:00.000Z, 1954-06-19T00:00:00.000Z] | [73717, 31120, 56760] +; diff --git a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/EsqlIllegalArgumentException.java b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/EsqlIllegalArgumentException.java index d9a0694e98d2c..b615e7dfcbf49 100644 --- a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/EsqlIllegalArgumentException.java +++ b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/EsqlIllegalArgumentException.java @@ -42,4 +42,8 @@ public static EsqlIllegalArgumentException illegalDataType(DataType dataType) { public static EsqlIllegalArgumentException illegalDataType(String dataTypeName) { return new EsqlIllegalArgumentException("illegal data type [" + dataTypeName + "]"); } + + public static EsqlIllegalArgumentException illegalDataTypeCombination(DataType dataType1, DataType dataType2) { + return new EsqlIllegalArgumentException("illegal data type combination [" + dataType1 + ", " + dataType2 + "]"); + } } diff --git a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/action/EsqlCapabilities.java b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/action/EsqlCapabilities.java index 45763093c1532..dc61a2cfa595a 100644 --- a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/action/EsqlCapabilities.java +++ b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/action/EsqlCapabilities.java @@ -312,6 +312,11 @@ public enum Cap { */ AGG_TOP_WITH_OPTIONAL_ORDER_FIELD, + /** + * Support for the extra "map" field in {@code TOP} aggregation. + */ + AGG_TOP_MAP_SUPPORT, + /** * {@code CASE} properly handling multivalue conditions. */ diff --git a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/EsqlFunctionRegistry.java b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/EsqlFunctionRegistry.java index e46fd8b6068ff..fb25777460fe0 100644 --- a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/EsqlFunctionRegistry.java +++ b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/EsqlFunctionRegistry.java @@ -364,7 +364,7 @@ private static FunctionDefinition[][] functions() { def(StdDev.class, uni(StdDev::new), "std_dev"), def(Variance.class, uni(Variance::new), "variance", "std_var"), def(Sum.class, uni(Sum::new), "sum"), - def(Top.class, tri(Top::new), "top"), + def(Top.class, quad(Top::new), "top"), def(Values.class, uni(Values::new), "values"), def(WeightedAvg.class, bi(WeightedAvg::new), "weighted_avg"), def(Present.class, uni(Present::new), "present"), diff --git a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/aggregate/Top.java b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/aggregate/Top.java index 6a12f63ada117..777024bc6291e 100644 --- a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/aggregate/Top.java +++ b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/aggregate/Top.java @@ -14,9 +14,27 @@ import org.elasticsearch.compute.aggregation.TopBooleanAggregatorFunctionSupplier; import org.elasticsearch.compute.aggregation.TopBytesRefAggregatorFunctionSupplier; import org.elasticsearch.compute.aggregation.TopDoubleAggregatorFunctionSupplier; +import org.elasticsearch.compute.aggregation.TopDoubleDoubleAggregatorFunctionSupplier; +import org.elasticsearch.compute.aggregation.TopDoubleFloatAggregatorFunctionSupplier; +import org.elasticsearch.compute.aggregation.TopDoubleIntAggregatorFunctionSupplier; +import org.elasticsearch.compute.aggregation.TopDoubleLongAggregatorFunctionSupplier; +import org.elasticsearch.compute.aggregation.TopFloatDoubleAggregatorFunctionSupplier; +import org.elasticsearch.compute.aggregation.TopFloatFloatAggregatorFunctionSupplier; +import org.elasticsearch.compute.aggregation.TopFloatIntAggregatorFunctionSupplier; +import org.elasticsearch.compute.aggregation.TopFloatLongAggregatorFunctionSupplier; import org.elasticsearch.compute.aggregation.TopIntAggregatorFunctionSupplier; +import org.elasticsearch.compute.aggregation.TopIntDoubleAggregatorFunctionSupplier; +import org.elasticsearch.compute.aggregation.TopIntFloatAggregatorFunctionSupplier; +import org.elasticsearch.compute.aggregation.TopIntIntAggregatorFunctionSupplier; +import org.elasticsearch.compute.aggregation.TopIntLongAggregatorFunctionSupplier; import org.elasticsearch.compute.aggregation.TopIpAggregatorFunctionSupplier; import org.elasticsearch.compute.aggregation.TopLongAggregatorFunctionSupplier; +import org.elasticsearch.compute.aggregation.TopLongDoubleAggregatorFunctionSupplier; +import org.elasticsearch.compute.aggregation.TopLongFloatAggregatorFunctionSupplier; +import org.elasticsearch.compute.aggregation.TopLongIntAggregatorFunctionSupplier; +import org.elasticsearch.compute.aggregation.TopLongLongAggregatorFunctionSupplier; +import org.elasticsearch.core.Nullable; +import org.elasticsearch.core.Tuple; import org.elasticsearch.xpack.esql.EsqlIllegalArgumentException; import org.elasticsearch.xpack.esql.capabilities.PostOptimizationVerificationAware; import org.elasticsearch.xpack.esql.common.Failures; @@ -31,13 +49,14 @@ import org.elasticsearch.xpack.esql.expression.function.Example; import org.elasticsearch.xpack.esql.expression.function.FunctionInfo; import org.elasticsearch.xpack.esql.expression.function.FunctionType; -import org.elasticsearch.xpack.esql.expression.function.OptionalArgument; +import org.elasticsearch.xpack.esql.expression.function.TwoOptionalArguments; import org.elasticsearch.xpack.esql.expression.function.Param; -import org.elasticsearch.xpack.esql.io.stream.PlanStreamInput; import org.elasticsearch.xpack.esql.planner.ToAggregator; import java.io.IOException; import java.util.List; +import java.util.Map; +import java.util.function.BiFunction; import static java.util.Arrays.asList; import static org.elasticsearch.common.logging.LoggerMessageFormat.format; @@ -53,7 +72,7 @@ public class Top extends AggregateFunction implements - OptionalArgument, + TwoOptionalArguments, ToAggregator, SurrogateExpression, PostOptimizationVerificationAware { @@ -81,27 +100,28 @@ public Top( name = "order", type = { "keyword" }, description = "The order to calculate the top values. Either `asc` or `desc`, and defaults to `asc` if omitted." - ) Expression order + ) Expression order, + @Param( + optional = true, + name = "mapToField", + type = { "double", "integer", "long" }, + description = "The extra field that the result of the TOP call is mapped to." + ) Expression mapToField ) { - this(source, field, Literal.TRUE, limit, order == null ? Literal.keyword(source, ORDER_ASC) : order); + this(source, field, Literal.TRUE, limit, order == null ? Literal.keyword(source, ORDER_ASC) : order, mapToField); } - public Top(Source source, Expression field, Expression filter, Expression limit, Expression order) { - super(source, field, filter, asList(limit, order)); + public Top(Source source, Expression field, Expression filter, Expression limit, Expression order, @Nullable Expression mapToField) { + super(source, field, filter, mapToField != null ? asList(limit, order, mapToField) : asList(limit, order)); } private Top(StreamInput in) throws IOException { - super( - Source.readFrom((PlanStreamInput) in), - in.readNamedWriteable(Expression.class), - in.readNamedWriteable(Expression.class), - in.readNamedWriteableCollectionAsList(Expression.class) - ); + super(in); } @Override public Top withFilter(Expression filter) { - return new Top(source(), field(), filter, limitField(), orderField()); + return new Top(source(), field(), filter, limitField(), orderField(), mapToField()); } @Override @@ -117,6 +137,11 @@ Expression orderField() { return parameters().get(1); } + @Nullable + Expression mapToField() { + return parameters().size() > 2 ? parameters().get(2) : null; + } + private Integer limitValue() { return Foldables.limitValue(limitField(), sourceText()); } @@ -155,6 +180,16 @@ protected TypeResolution resolveType() { .and(isType(limitField(), dt -> dt == DataType.INTEGER, sourceText(), SECOND, "integer")) .and(isNotNull(orderField(), sourceText(), THIRD)) .and(isString(orderField(), sourceText(), THIRD)); + if (mapToField() != null) { + typeResolution.and(isType( + mapToField(), + dt -> dt == DataType.DATETIME || (dt.isNumeric() && dt != DataType.UNSIGNED_LONG), + sourceText(), + FIRST, + "date", + "numeric except unsigned_long or counter types" + )); + } if (typeResolution.unresolved()) { return typeResolution; @@ -242,41 +277,79 @@ private void postOptimizationVerificationOrder(Failures failures) { @Override public DataType dataType() { - return field().dataType().noText(); + return mapToField() == null ? field().dataType().noText() : mapToField().dataType().noText(); } @Override protected NodeInfo info() { - return NodeInfo.create(this, Top::new, field(), filter(), limitField(), orderField()); + return NodeInfo.create(this, Top::new, field(), filter(), limitField(), orderField(), mapToField()); } @Override public Top replaceChildren(List newChildren) { - return new Top(source(), newChildren.get(0), newChildren.get(1), newChildren.get(2), newChildren.get(3)); + return new Top( + source(), + newChildren.get(0), + newChildren.get(1), + newChildren.get(2), + newChildren.get(3), + newChildren.size() > 4 ? newChildren.get(4) : null + ); } + private static final Map> SUPPLIERS = Map + .ofEntries( + Map.entry(DataType.LONG, TopLongAggregatorFunctionSupplier::new), + Map.entry(DataType.DATETIME, TopLongAggregatorFunctionSupplier::new), + Map.entry(DataType.INTEGER, TopIntAggregatorFunctionSupplier::new), + Map.entry(DataType.DOUBLE, TopDoubleAggregatorFunctionSupplier::new), + Map.entry(DataType.BOOLEAN, TopBooleanAggregatorFunctionSupplier::new), + Map.entry(DataType.IP, TopIpAggregatorFunctionSupplier::new), + Map.entry(DataType.KEYWORD, TopBytesRefAggregatorFunctionSupplier::new), + Map.entry(DataType.TEXT, TopBytesRefAggregatorFunctionSupplier::new) + ); + + private static final Map, BiFunction> SUPPLIERS_WITH_EXTRA = Map + .ofEntries( + Map.entry(Tuple.tuple(DataType.LONG, DataType.INTEGER), TopLongIntAggregatorFunctionSupplier::new), + Map.entry(Tuple.tuple(DataType.LONG, DataType.LONG), TopLongLongAggregatorFunctionSupplier::new), + Map.entry(Tuple.tuple(DataType.LONG, DataType.FLOAT), TopLongFloatAggregatorFunctionSupplier::new), + Map.entry(Tuple.tuple(DataType.LONG, DataType.DOUBLE), TopLongDoubleAggregatorFunctionSupplier::new), + Map.entry(Tuple.tuple(DataType.DATETIME, DataType.INTEGER), TopLongIntAggregatorFunctionSupplier::new), + Map.entry(Tuple.tuple(DataType.DATETIME, DataType.LONG), TopLongLongAggregatorFunctionSupplier::new), + Map.entry(Tuple.tuple(DataType.DATETIME, DataType.FLOAT), TopLongFloatAggregatorFunctionSupplier::new), + Map.entry(Tuple.tuple(DataType.DATETIME, DataType.DOUBLE), TopLongDoubleAggregatorFunctionSupplier::new), + Map.entry(Tuple.tuple(DataType.INTEGER, DataType.INTEGER), TopIntIntAggregatorFunctionSupplier::new), + Map.entry(Tuple.tuple(DataType.INTEGER, DataType.LONG), TopIntLongAggregatorFunctionSupplier::new), + Map.entry(Tuple.tuple(DataType.INTEGER, DataType.FLOAT), TopIntFloatAggregatorFunctionSupplier::new), + Map.entry(Tuple.tuple(DataType.INTEGER, DataType.DOUBLE), TopIntDoubleAggregatorFunctionSupplier::new), + Map.entry(Tuple.tuple(DataType.FLOAT, DataType.INTEGER), TopFloatIntAggregatorFunctionSupplier::new), + Map.entry(Tuple.tuple(DataType.FLOAT, DataType.LONG), TopFloatLongAggregatorFunctionSupplier::new), + Map.entry(Tuple.tuple(DataType.FLOAT, DataType.FLOAT), TopFloatFloatAggregatorFunctionSupplier::new), + Map.entry(Tuple.tuple(DataType.FLOAT, DataType.DOUBLE), TopFloatDoubleAggregatorFunctionSupplier::new), + Map.entry(Tuple.tuple(DataType.DOUBLE, DataType.INTEGER), TopDoubleIntAggregatorFunctionSupplier::new), + Map.entry(Tuple.tuple(DataType.DOUBLE, DataType.LONG), TopDoubleLongAggregatorFunctionSupplier::new), + Map.entry(Tuple.tuple(DataType.DOUBLE, DataType.FLOAT), TopDoubleFloatAggregatorFunctionSupplier::new), + Map.entry(Tuple.tuple(DataType.DOUBLE, DataType.DOUBLE), TopDoubleDoubleAggregatorFunctionSupplier::new) + ); + @Override public AggregatorFunctionSupplier supplier() { DataType type = field().dataType(); - if (type == DataType.LONG || type == DataType.DATETIME) { - return new TopLongAggregatorFunctionSupplier(limitValue(), orderValue()); - } - if (type == DataType.INTEGER) { - return new TopIntAggregatorFunctionSupplier(limitValue(), orderValue()); - } - if (type == DataType.DOUBLE) { - return new TopDoubleAggregatorFunctionSupplier(limitValue(), orderValue()); - } - if (type == DataType.BOOLEAN) { - return new TopBooleanAggregatorFunctionSupplier(limitValue(), orderValue()); - } - if (type == DataType.IP) { - return new TopIpAggregatorFunctionSupplier(limitValue(), orderValue()); - } - if (DataType.isString(type)) { - return new TopBytesRefAggregatorFunctionSupplier(limitValue(), orderValue()); + BiFunction supplierCtor; + if (mapToField() == null) { + supplierCtor = SUPPLIERS.get(type); + if (supplierCtor == null) { + throw EsqlIllegalArgumentException.illegalDataType(type); + } + } else { + DataType mapToFieldType = mapToField().dataType(); + supplierCtor = SUPPLIERS_WITH_EXTRA.get(Tuple.tuple(type, mapToFieldType)); + if (supplierCtor == null) { + throw EsqlIllegalArgumentException.illegalDataTypeCombination(type, mapToFieldType); + } } - throw EsqlIllegalArgumentException.illegalDataType(type); + return supplierCtor.apply(limitValue(), orderValue()); } @Override diff --git a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/TopSerializationTests.java b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/TopSerializationTests.java index 82bf57d1a194e..6c681e2b81fae 100644 --- a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/TopSerializationTests.java +++ b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/TopSerializationTests.java @@ -20,7 +20,8 @@ protected Top createTestInstance() { Expression field = randomChild(); Expression limit = randomChild(); Expression order = randomChild(); - return new Top(source, field, limit, order); + Expression mapToField = randomChild(); + return new Top(source, field, limit, order, mapToField); } @Override @@ -29,11 +30,13 @@ protected Top mutateInstance(Top instance) throws IOException { Expression field = instance.field(); Expression limit = instance.limitField(); Expression order = instance.orderField(); - switch (between(0, 2)) { + Expression mapToField = instance.mapToField(); + switch (between(0, 3)) { case 0 -> field = randomValueOtherThan(field, AbstractExpressionSerializationTests::randomChild); case 1 -> limit = randomValueOtherThan(limit, AbstractExpressionSerializationTests::randomChild); case 2 -> order = randomValueOtherThan(order, AbstractExpressionSerializationTests::randomChild); + case 3 -> mapToField = randomValueOtherThan(mapToField, AbstractExpressionSerializationTests::randomChild); } - return new Top(source, field, limit, order); + return new Top(source, field, limit, order, mapToField); } } diff --git a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/TopTests.java b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/TopTests.java index 0d7733a6bcb98..93a346f819d8d 100644 --- a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/TopTests.java +++ b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/TopTests.java @@ -285,7 +285,7 @@ public static Iterable parameters() { @Override protected Expression build(Source source, List args) { - return new Top(source, args.get(0), args.get(1), args.size() == 3 ? args.get(2) : null); + return new Top(source, args.get(0), args.get(1), args.size() > 2 ? args.get(2) : null, args.size() > 3 ? args.get(3) : null); } @SuppressWarnings("unchecked") diff --git a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/plan/logical/AggregateSerializationTests.java b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/plan/logical/AggregateSerializationTests.java index c50c998674704..80ed49da8a8f6 100644 --- a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/plan/logical/AggregateSerializationTests.java +++ b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/plan/logical/AggregateSerializationTests.java @@ -39,7 +39,7 @@ public static List randomAggregates() { int size = between(1, 5); List result = new ArrayList<>(size); for (int i = 0; i < size; i++) { - Expression agg = switch (between(0, 5)) { + Expression agg = switch (between(0, 6)) { case 0 -> new Max(randomSource(), FieldAttributeTests.createFieldAttribute(1, true)); case 1 -> new Min(randomSource(), FieldAttributeTests.createFieldAttribute(1, true)); case 2 -> new Count(randomSource(), FieldAttributeTests.createFieldAttribute(1, true)); @@ -47,10 +47,18 @@ public static List randomAggregates() { randomSource(), FieldAttributeTests.createFieldAttribute(1, true), new Literal(randomSource(), between(1, 5), DataType.INTEGER), - Literal.keyword(randomSource(), randomFrom("ASC", "DESC")) + Literal.keyword(randomSource(), randomFrom("ASC", "DESC")), + null ); - case 4 -> new Values(randomSource(), FieldAttributeTests.createFieldAttribute(1, true)); - case 5 -> new Sum(randomSource(), FieldAttributeTests.createFieldAttribute(1, true)); + case 4 -> new Top( + randomSource(), + FieldAttributeTests.createFieldAttribute(1, true), + new Literal(randomSource(), between(1, 5), DataType.INTEGER), + Literal.keyword(randomSource(), randomFrom("ASC", "DESC")), + FieldAttributeTests.createFieldAttribute(1, true) + ); + case 5 -> new Values(randomSource(), FieldAttributeTests.createFieldAttribute(1, true)); + case 6 -> new Sum(randomSource(), FieldAttributeTests.createFieldAttribute(1, true)); default -> throw new IllegalArgumentException(); }; result.add(new Alias(randomSource(), randomAlphaOfLength(5), agg)); diff --git a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/tree/EsqlNodeSubclassTests.java b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/tree/EsqlNodeSubclassTests.java index 912c90b2abae6..8b1d6b655e911 100644 --- a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/tree/EsqlNodeSubclassTests.java +++ b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/tree/EsqlNodeSubclassTests.java @@ -182,7 +182,7 @@ public void testInfoParameters() throws Exception { */ expectedCount -= 1; - assertEquals(expectedCount, info(node).properties().size()); + assertEquals("Wrong number of info parameters for " + subclass.getSimpleName(), expectedCount, info(node).properties().size()); } /** From a045e391dd553559374b9b47ced1e55fc3f6c0a3 Mon Sep 17 00:00:00 2001 From: elasticsearchmachine Date: Wed, 8 Oct 2025 13:02:02 +0000 Subject: [PATCH 02/16] [CI] Auto commit changes from spotless --- .../expression/function/aggregate/Top.java | 41 ++++++++++--------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/aggregate/Top.java b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/aggregate/Top.java index 777024bc6291e..3a812bc5a43ac 100644 --- a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/aggregate/Top.java +++ b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/aggregate/Top.java @@ -49,8 +49,8 @@ import org.elasticsearch.xpack.esql.expression.function.Example; import org.elasticsearch.xpack.esql.expression.function.FunctionInfo; import org.elasticsearch.xpack.esql.expression.function.FunctionType; -import org.elasticsearch.xpack.esql.expression.function.TwoOptionalArguments; import org.elasticsearch.xpack.esql.expression.function.Param; +import org.elasticsearch.xpack.esql.expression.function.TwoOptionalArguments; import org.elasticsearch.xpack.esql.planner.ToAggregator; import java.io.IOException; @@ -181,14 +181,16 @@ protected TypeResolution resolveType() { .and(isNotNull(orderField(), sourceText(), THIRD)) .and(isString(orderField(), sourceText(), THIRD)); if (mapToField() != null) { - typeResolution.and(isType( - mapToField(), - dt -> dt == DataType.DATETIME || (dt.isNumeric() && dt != DataType.UNSIGNED_LONG), - sourceText(), - FIRST, - "date", - "numeric except unsigned_long or counter types" - )); + typeResolution.and( + isType( + mapToField(), + dt -> dt == DataType.DATETIME || (dt.isNumeric() && dt != DataType.UNSIGNED_LONG), + sourceText(), + FIRST, + "date", + "numeric except unsigned_long or counter types" + ) + ); } if (typeResolution.unresolved()) { @@ -297,17 +299,16 @@ public Top replaceChildren(List newChildren) { ); } - private static final Map> SUPPLIERS = Map - .ofEntries( - Map.entry(DataType.LONG, TopLongAggregatorFunctionSupplier::new), - Map.entry(DataType.DATETIME, TopLongAggregatorFunctionSupplier::new), - Map.entry(DataType.INTEGER, TopIntAggregatorFunctionSupplier::new), - Map.entry(DataType.DOUBLE, TopDoubleAggregatorFunctionSupplier::new), - Map.entry(DataType.BOOLEAN, TopBooleanAggregatorFunctionSupplier::new), - Map.entry(DataType.IP, TopIpAggregatorFunctionSupplier::new), - Map.entry(DataType.KEYWORD, TopBytesRefAggregatorFunctionSupplier::new), - Map.entry(DataType.TEXT, TopBytesRefAggregatorFunctionSupplier::new) - ); + private static final Map> SUPPLIERS = Map.ofEntries( + Map.entry(DataType.LONG, TopLongAggregatorFunctionSupplier::new), + Map.entry(DataType.DATETIME, TopLongAggregatorFunctionSupplier::new), + Map.entry(DataType.INTEGER, TopIntAggregatorFunctionSupplier::new), + Map.entry(DataType.DOUBLE, TopDoubleAggregatorFunctionSupplier::new), + Map.entry(DataType.BOOLEAN, TopBooleanAggregatorFunctionSupplier::new), + Map.entry(DataType.IP, TopIpAggregatorFunctionSupplier::new), + Map.entry(DataType.KEYWORD, TopBytesRefAggregatorFunctionSupplier::new), + Map.entry(DataType.TEXT, TopBytesRefAggregatorFunctionSupplier::new) + ); private static final Map, BiFunction> SUPPLIERS_WITH_EXTRA = Map .ofEntries( From 24ff3c79df6562717d3e317026cb554702f22efa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20Witek?= Date: Wed, 8 Oct 2025 16:28:28 +0200 Subject: [PATCH 03/16] Update docs/changelog/135434.yaml --- docs/changelog/135434.yaml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 docs/changelog/135434.yaml diff --git a/docs/changelog/135434.yaml b/docs/changelog/135434.yaml new file mode 100644 index 0000000000000..0a1506087a427 --- /dev/null +++ b/docs/changelog/135434.yaml @@ -0,0 +1,6 @@ +pr: 135434 +summary: Support extra field in TOP function +area: ES|QL +type: enhancement +issues: + - 128630 From d4bffea60523ac8a7a45846b0e51affcd99b136d Mon Sep 17 00:00:00 2001 From: Przemyslaw Witek Date: Tue, 14 Oct 2025 16:02:50 +0200 Subject: [PATCH 04/16] Apply review comments --- .../_snippets/functions/parameters/top.md | 4 +- .../esql/_snippets/functions/types/top.md | 2 +- .../esql/images/functions/top.svg | 2 +- x-pack/plugin/esql/compute/build.gradle | 270 ++++-------------- .../TopDoubleDoubleAggregator.java | 26 +- .../aggregation/TopDoubleFloatAggregator.java | 26 +- .../aggregation/TopDoubleIntAggregator.java | 26 +- .../aggregation/TopDoubleLongAggregator.java | 26 +- .../aggregation/TopFloatDoubleAggregator.java | 26 +- .../aggregation/TopFloatFloatAggregator.java | 26 +- .../aggregation/TopFloatIntAggregator.java | 26 +- .../aggregation/TopFloatLongAggregator.java | 26 +- .../aggregation/TopIntDoubleAggregator.java | 26 +- .../aggregation/TopIntFloatAggregator.java | 26 +- .../aggregation/TopIntIntAggregator.java | 26 +- .../aggregation/TopIntLongAggregator.java | 26 +- .../aggregation/TopLongDoubleAggregator.java | 26 +- .../aggregation/TopLongFloatAggregator.java | 26 +- .../aggregation/TopLongIntAggregator.java | 26 +- .../aggregation/TopLongLongAggregator.java | 26 +- .../compute/data/sort/DoubleBucketedSort.java | 3 +- .../data/sort/DoubleDoubleBucketedSort.java | 27 +- .../data/sort/DoubleFloatBucketedSort.java | 27 +- .../data/sort/DoubleIntBucketedSort.java | 27 +- .../data/sort/DoubleLongBucketedSort.java | 27 +- .../compute/data/sort/FloatBucketedSort.java | 3 +- .../data/sort/FloatDoubleBucketedSort.java | 27 +- .../data/sort/FloatFloatBucketedSort.java | 27 +- .../data/sort/FloatIntBucketedSort.java | 27 +- .../data/sort/FloatLongBucketedSort.java | 27 +- .../compute/data/sort/IntBucketedSort.java | 3 +- .../data/sort/IntDoubleBucketedSort.java | 27 +- .../data/sort/IntFloatBucketedSort.java | 27 +- .../compute/data/sort/IntIntBucketedSort.java | 27 +- .../data/sort/IntLongBucketedSort.java | 27 +- .../compute/data/sort/LongBucketedSort.java | 3 +- .../data/sort/LongDoubleBucketedSort.java | 27 +- .../data/sort/LongFloatBucketedSort.java | 27 +- .../data/sort/LongIntBucketedSort.java | 27 +- .../data/sort/LongLongBucketedSort.java | 27 +- .../TopDoubleDoubleAggregatorFunction.java | 77 ++--- ...oubleDoubleGroupingAggregatorFunction.java | 124 ++++---- .../TopDoubleFloatAggregatorFunction.java | 77 ++--- ...DoubleFloatGroupingAggregatorFunction.java | 124 ++++---- .../TopDoubleIntAggregatorFunction.java | 76 ++--- ...opDoubleIntGroupingAggregatorFunction.java | 124 ++++---- .../TopDoubleLongAggregatorFunction.java | 77 ++--- ...pDoubleLongGroupingAggregatorFunction.java | 124 ++++---- .../TopFloatDoubleAggregatorFunction.java | 77 ++--- ...FloatDoubleGroupingAggregatorFunction.java | 124 ++++---- .../TopFloatFloatAggregatorFunction.java | 77 ++--- ...pFloatFloatGroupingAggregatorFunction.java | 124 ++++---- .../TopFloatIntAggregatorFunction.java | 76 ++--- ...TopFloatIntGroupingAggregatorFunction.java | 124 ++++---- .../TopFloatLongAggregatorFunction.java | 76 ++--- ...opFloatLongGroupingAggregatorFunction.java | 124 ++++---- .../TopIntDoubleAggregatorFunction.java | 76 ++--- ...opIntDoubleGroupingAggregatorFunction.java | 124 ++++---- .../TopIntFloatAggregatorFunction.java | 76 ++--- ...TopIntFloatGroupingAggregatorFunction.java | 124 ++++---- .../TopIntIntAggregatorFunction.java | 76 ++--- .../TopIntIntGroupingAggregatorFunction.java | 124 ++++---- .../TopIntLongAggregatorFunction.java | 76 ++--- .../TopIntLongGroupingAggregatorFunction.java | 124 ++++---- .../TopLongDoubleAggregatorFunction.java | 77 ++--- ...pLongDoubleGroupingAggregatorFunction.java | 124 ++++---- .../TopLongFloatAggregatorFunction.java | 76 ++--- ...opLongFloatGroupingAggregatorFunction.java | 124 ++++---- .../TopLongIntAggregatorFunction.java | 76 ++--- .../TopLongIntGroupingAggregatorFunction.java | 124 ++++---- .../TopLongLongAggregatorFunction.java | 76 ++--- ...TopLongLongGroupingAggregatorFunction.java | 124 ++++---- .../aggregation/X-TopAggregator.java.st | 48 ++-- .../compute/data/sort/X-BucketedSort.java.st | 31 +- .../src/main/resources/stats_top.csv-spec | 92 ++++++ .../src/main/resources/stats_top_map.csv-spec | 53 ---- .../xpack/esql/action/EsqlCapabilities.java | 2 +- .../expression/function/aggregate/Top.java | 43 +-- .../aggregate/TopSerializationTests.java | 10 +- .../logical/AggregateSerializationTests.java | 15 +- 80 files changed, 2172 insertions(+), 2466 deletions(-) delete mode 100644 x-pack/plugin/esql/qa/testFixtures/src/main/resources/stats_top_map.csv-spec diff --git a/docs/reference/query-languages/esql/_snippets/functions/parameters/top.md b/docs/reference/query-languages/esql/_snippets/functions/parameters/top.md index 86eb630c410b4..6419af82362c1 100644 --- a/docs/reference/query-languages/esql/_snippets/functions/parameters/top.md +++ b/docs/reference/query-languages/esql/_snippets/functions/parameters/top.md @@ -11,6 +11,6 @@ `order` : The order to calculate the top values. Either `asc` or `desc`, and defaults to `asc` if omitted. -`mapToField` -: The extra field that the result of the TOP call is mapped to. +`outputField` +: The extra field that, if present, will be the output of the TOP call instead of `field`. diff --git a/docs/reference/query-languages/esql/_snippets/functions/types/top.md b/docs/reference/query-languages/esql/_snippets/functions/types/top.md index 15e7642227cb9..4f197b7e70874 100644 --- a/docs/reference/query-languages/esql/_snippets/functions/types/top.md +++ b/docs/reference/query-languages/esql/_snippets/functions/types/top.md @@ -2,7 +2,7 @@ **Supported types** -| field | limit | order | mapToField | result | +| field | limit | order | outputField | result | | --- | --- | --- | --- | --- | | boolean | integer | keyword | | boolean | | boolean | integer | | | boolean | diff --git a/docs/reference/query-languages/esql/images/functions/top.svg b/docs/reference/query-languages/esql/images/functions/top.svg index da1fb07dbc3ab..1987d050f981a 100644 --- a/docs/reference/query-languages/esql/images/functions/top.svg +++ b/docs/reference/query-languages/esql/images/functions/top.svg @@ -1 +1 @@ -TOP(field,limit,order,mapToField) \ No newline at end of file +TOP(field,limit,order,outputField) \ No newline at end of file diff --git a/x-pack/plugin/esql/compute/build.gradle b/x-pack/plugin/esql/compute/build.gradle index 5d2fd550b2a70..44f9bdd331238 100644 --- a/x-pack/plugin/esql/compute/build.gradle +++ b/x-pack/plugin/esql/compute/build.gradle @@ -81,22 +81,22 @@ def prop(Name, Type, type, Wrapper, TYPE, BYTES, Array, Hash) { ] } -def propWithoutExtra(prop1) { - def res = [ "hasExtra": "" ] +def propWithoutExtra(prop1, extraPrefix) { + def res = [ ("has" + extraPrefix): "" ] for ( e in prop1 ) { res.put(e.key, e.value) - res.put("Extra" + e.key, "") + res.put(extraPrefix + e.key, "") } return res } -def propWithExtra(prop1, prop2) { - def res = [ "hasExtra": "true" ] +def propWithExtra(prop1, prop2, extraPrefix) { + def res = [ ("has" + extraPrefix): "true" ] for ( e in prop1 ) { res.put(e.key, e.value) } for ( e in prop2 ) { - res.put("Extra" + e.key, e.value) + res.put(extraPrefix + e.key, e.value) } return res } @@ -744,125 +744,28 @@ tasks.named('stringTemplates').configure { File topAggregatorInputFile = new File("${projectDir}/src/main/java/org/elasticsearch/compute/aggregation/X-TopAggregator.java.st") // Simple TOP when the sort field and the output field are the same field - template { - it.properties = propWithoutExtra(intProperties) - it.inputFile = topAggregatorInputFile - it.outputFile = "org/elasticsearch/compute/aggregation/TopIntAggregator.java" - } - template { - it.properties = propWithoutExtra(longProperties) - it.inputFile = topAggregatorInputFile - it.outputFile = "org/elasticsearch/compute/aggregation/TopLongAggregator.java" - } - template { - it.properties = propWithoutExtra(floatProperties) - it.inputFile = topAggregatorInputFile - it.outputFile = "org/elasticsearch/compute/aggregation/TopFloatAggregator.java" - } - template { - it.properties = propWithoutExtra(doubleProperties) - it.inputFile = topAggregatorInputFile - it.outputFile = "org/elasticsearch/compute/aggregation/TopDoubleAggregator.java" - } - template { - it.properties = propWithoutExtra(booleanProperties) - it.inputFile = topAggregatorInputFile - it.outputFile = "org/elasticsearch/compute/aggregation/TopBooleanAggregator.java" - } - template { - it.properties = propWithoutExtra(bytesRefProperties) - it.inputFile = topAggregatorInputFile - it.outputFile = "org/elasticsearch/compute/aggregation/TopBytesRefAggregator.java" - } - template { - it.properties = propWithoutExtra(ipProperties) - it.inputFile = topAggregatorInputFile - it.outputFile = "org/elasticsearch/compute/aggregation/TopIpAggregator.java" - } - // TOP when the sort field and the output (extra) field are *different* fields - // 16 (4x4) combinations are listed here - template { - it.properties = propWithExtra(intProperties, intProperties) - it.inputFile = topAggregatorInputFile - it.outputFile = "org/elasticsearch/compute/aggregation/TopIntIntAggregator.java" - } - template { - it.properties = propWithExtra(intProperties, longProperties) - it.inputFile = topAggregatorInputFile - it.outputFile = "org/elasticsearch/compute/aggregation/TopIntLongAggregator.java" - } - template { - it.properties = propWithExtra(intProperties, floatProperties) - it.inputFile = topAggregatorInputFile - it.outputFile = "org/elasticsearch/compute/aggregation/TopIntFloatAggregator.java" - } - template { - it.properties = propWithExtra(intProperties, doubleProperties) - it.inputFile = topAggregatorInputFile - it.outputFile = "org/elasticsearch/compute/aggregation/TopIntDoubleAggregator.java" - } - - template { - it.properties = propWithExtra(longProperties, intProperties) - it.inputFile = topAggregatorInputFile - it.outputFile = "org/elasticsearch/compute/aggregation/TopLongIntAggregator.java" - } - template { - it.properties = propWithExtra(longProperties, longProperties) - it.inputFile = topAggregatorInputFile - it.outputFile = "org/elasticsearch/compute/aggregation/TopLongLongAggregator.java" - } - template { - it.properties = propWithExtra(longProperties, floatProperties) - it.inputFile = topAggregatorInputFile - it.outputFile = "org/elasticsearch/compute/aggregation/TopLongFloatAggregator.java" - } - template { - it.properties = propWithExtra(longProperties, doubleProperties) - it.inputFile = topAggregatorInputFile - it.outputFile = "org/elasticsearch/compute/aggregation/TopLongDoubleAggregator.java" - } - - template { - it.properties = propWithExtra(floatProperties, intProperties) - it.inputFile = topAggregatorInputFile - it.outputFile = "org/elasticsearch/compute/aggregation/TopFloatIntAggregator.java" - } - template { - it.properties = propWithExtra(floatProperties, longProperties) - it.inputFile = topAggregatorInputFile - it.outputFile = "org/elasticsearch/compute/aggregation/TopFloatLongAggregator.java" - } - template { - it.properties = propWithExtra(floatProperties, floatProperties) - it.inputFile = topAggregatorInputFile - it.outputFile = "org/elasticsearch/compute/aggregation/TopFloatFloatAggregator.java" - } - template { - it.properties = propWithExtra(floatProperties, doubleProperties) - it.inputFile = topAggregatorInputFile - it.outputFile = "org/elasticsearch/compute/aggregation/TopFloatDoubleAggregator.java" - } - - template { - it.properties = propWithExtra(doubleProperties, intProperties) - it.inputFile = topAggregatorInputFile - it.outputFile = "org/elasticsearch/compute/aggregation/TopDoubleIntAggregator.java" - } - template { - it.properties = propWithExtra(doubleProperties, longProperties) - it.inputFile = topAggregatorInputFile - it.outputFile = "org/elasticsearch/compute/aggregation/TopDoubleLongAggregator.java" - } - template { - it.properties = propWithExtra(doubleProperties, floatProperties) - it.inputFile = topAggregatorInputFile - it.outputFile = "org/elasticsearch/compute/aggregation/TopDoubleFloatAggregator.java" + [intProperties, longProperties, floatProperties, doubleProperties, booleanProperties, bytesRefProperties, ipProperties].forEach { props -> + { + template { + it.properties = propWithoutExtra(props, "OutputField") + it.inputFile = topAggregatorInputFile + it.outputFile = "org/elasticsearch/compute/aggregation/Top${props.Name}Aggregator.java" + } + } } - template { - it.properties = propWithExtra(doubleProperties, doubleProperties) - it.inputFile = topAggregatorInputFile - it.outputFile = "org/elasticsearch/compute/aggregation/TopDoubleDoubleAggregator.java" + // TOP when the sort field and the output field can be *different* fields + [intProperties, longProperties, floatProperties, doubleProperties].forEach { props1 -> + { + [intProperties, longProperties, floatProperties, doubleProperties].forEach { props2 -> + { + template { + it.properties = propWithExtra(props1, props2, "OutputField") + it.inputFile = topAggregatorInputFile + it.outputFile = "org/elasticsearch/compute/aggregation/Top${props1.Name}${props2.Name}Aggregator.java" + } + } + } + } } File multivalueDedupeInputFile = file("src/main/java/org/elasticsearch/compute/operator/mvdedupe/X-MultivalueDedupe.java.st") @@ -1002,105 +905,28 @@ tasks.named('stringTemplates').configure { } File bucketedSortInputFile = new File("${projectDir}/src/main/java/org/elasticsearch/compute/data/sort/X-BucketedSort.java.st") - template { - it.properties = propWithoutExtra(intProperties) - it.inputFile = bucketedSortInputFile - it.outputFile = "org/elasticsearch/compute/data/sort/IntBucketedSort.java" - } - template { - it.properties = propWithoutExtra(longProperties) - it.inputFile = bucketedSortInputFile - it.outputFile = "org/elasticsearch/compute/data/sort/LongBucketedSort.java" - } - template { - it.properties = propWithoutExtra(floatProperties) - it.inputFile = bucketedSortInputFile - it.outputFile = "org/elasticsearch/compute/data/sort/FloatBucketedSort.java" - } - template { - it.properties = propWithoutExtra(doubleProperties) - it.inputFile = bucketedSortInputFile - it.outputFile = "org/elasticsearch/compute/data/sort/DoubleBucketedSort.java" - } - template { - it.properties = propWithExtra(intProperties, intProperties) - it.inputFile = bucketedSortInputFile - it.outputFile = "org/elasticsearch/compute/data/sort/IntIntBucketedSort.java" - } - template { - it.properties = propWithExtra(intProperties, longProperties) - it.inputFile = bucketedSortInputFile - it.outputFile = "org/elasticsearch/compute/data/sort/IntLongBucketedSort.java" - } - template { - it.properties = propWithExtra(intProperties, floatProperties) - it.inputFile = bucketedSortInputFile - it.outputFile = "org/elasticsearch/compute/data/sort/IntFloatBucketedSort.java" - } - template { - it.properties = propWithExtra(intProperties, doubleProperties) - it.inputFile = bucketedSortInputFile - it.outputFile = "org/elasticsearch/compute/data/sort/IntDoubleBucketedSort.java" - } - template { - it.properties = propWithExtra(longProperties, intProperties) - it.inputFile = bucketedSortInputFile - it.outputFile = "org/elasticsearch/compute/data/sort/LongIntBucketedSort.java" - } - template { - it.properties = propWithExtra(longProperties, longProperties) - it.inputFile = bucketedSortInputFile - it.outputFile = "org/elasticsearch/compute/data/sort/LongLongBucketedSort.java" - } - template { - it.properties = propWithExtra(longProperties, floatProperties) - it.inputFile = bucketedSortInputFile - it.outputFile = "org/elasticsearch/compute/data/sort/LongFloatBucketedSort.java" - } - template { - it.properties = propWithExtra(longProperties, doubleProperties) - it.inputFile = bucketedSortInputFile - it.outputFile = "org/elasticsearch/compute/data/sort/LongDoubleBucketedSort.java" - } - template { - it.properties = propWithExtra(floatProperties, intProperties) - it.inputFile = bucketedSortInputFile - it.outputFile = "org/elasticsearch/compute/data/sort/FloatIntBucketedSort.java" - } - template { - it.properties = propWithExtra(floatProperties, longProperties) - it.inputFile = bucketedSortInputFile - it.outputFile = "org/elasticsearch/compute/data/sort/FloatLongBucketedSort.java" - } - template { - it.properties = propWithExtra(floatProperties, floatProperties) - it.inputFile = bucketedSortInputFile - it.outputFile = "org/elasticsearch/compute/data/sort/FloatFloatBucketedSort.java" - } - template { - it.properties = propWithExtra(floatProperties, doubleProperties) - it.inputFile = bucketedSortInputFile - it.outputFile = "org/elasticsearch/compute/data/sort/FloatDoubleBucketedSort.java" - } - template { - it.properties = propWithExtra(doubleProperties, intProperties) - it.inputFile = bucketedSortInputFile - it.outputFile = "org/elasticsearch/compute/data/sort/DoubleIntBucketedSort.java" - } - template { - it.properties = propWithExtra(doubleProperties, longProperties) - it.inputFile = bucketedSortInputFile - it.outputFile = "org/elasticsearch/compute/data/sort/DoubleLongBucketedSort.java" - } - template { - it.properties = propWithExtra(doubleProperties, floatProperties) - it.inputFile = bucketedSortInputFile - it.outputFile = "org/elasticsearch/compute/data/sort/DoubleFloatBucketedSort.java" + [intProperties, longProperties, floatProperties, doubleProperties].forEach { props -> + { + template { + it.properties = propWithoutExtra(props, "Extra") + it.inputFile = bucketedSortInputFile + it.outputFile = "org/elasticsearch/compute/data/sort/${props.Name}BucketedSort.java" + } + } } - template { - it.properties = propWithExtra(doubleProperties, doubleProperties) - it.inputFile = bucketedSortInputFile - it.outputFile = "org/elasticsearch/compute/data/sort/DoubleDoubleBucketedSort.java" + // TOP when the sort field and the output field can be *different* fields + [intProperties, longProperties, floatProperties, doubleProperties].forEach { props1 -> + { + [intProperties, longProperties, floatProperties, doubleProperties].forEach { props2 -> + { + template { + it.properties = propWithExtra(props1, props2, "Extra") + it.inputFile = bucketedSortInputFile + it.outputFile = "org/elasticsearch/compute/data/sort/${props1.Name}${props2.Name}BucketedSort.java" + } + } + } + } } File enrichResultBuilderInput = file("src/main/java/org/elasticsearch/compute/operator/lookup/X-EnrichResultBuilder.java.st") diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopDoubleDoubleAggregator.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopDoubleDoubleAggregator.java index 15fbe5345df09..45cd12e43c182 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopDoubleDoubleAggregator.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopDoubleDoubleAggregator.java @@ -31,22 +31,22 @@ * This class is generated. Edit `X-TopAggregator.java.st` to edit this file. *

*/ -@Aggregator({ @IntermediateState(name = "top", type = "DOUBLE_BLOCK"), @IntermediateState(name = "extra", type = "DOUBLE_BLOCK") }) +@Aggregator({ @IntermediateState(name = "top", type = "DOUBLE_BLOCK"), @IntermediateState(name = "output", type = "DOUBLE_BLOCK") }) @GroupingAggregator class TopDoubleDoubleAggregator { public static SingleState initSingle(BigArrays bigArrays, int limit, boolean ascending) { return new SingleState(bigArrays, limit, ascending); } - public static void combine(SingleState state, double v, double extra) { - state.add(v, extra); + public static void combine(SingleState state, double v, double outputValue) { + state.add(v, outputValue); } - public static void combineIntermediate(SingleState state, DoubleBlock values, DoubleBlock extras) { + public static void combineIntermediate(SingleState state, DoubleBlock values, DoubleBlock outputValues) { int start = values.getFirstValueIndex(0); int end = start + values.getValueCount(0); for (int i = start; i < end; i++) { - combine(state, values.getDouble(i), extras.getDouble(i)); + combine(state, values.getDouble(i), outputValues.getDouble(i)); } } @@ -58,15 +58,15 @@ public static GroupingState initGrouping(BigArrays bigArrays, int limit, boolean return new GroupingState(bigArrays, limit, ascending); } - public static void combine(GroupingState state, int groupId, double v, double extra) { - state.add(groupId, v, extra); + public static void combine(GroupingState state, int groupId, double v, double outputValue) { + state.add(groupId, v, outputValue); } - public static void combineIntermediate(GroupingState state, int groupId, DoubleBlock values, DoubleBlock extras, int valuesPosition) { + public static void combineIntermediate(GroupingState state, int groupId, DoubleBlock values, DoubleBlock outputValues, int valuesPosition) { int start = values.getFirstValueIndex(valuesPosition); int end = start + values.getValueCount(valuesPosition); for (int i = start; i < end; i++) { - combine(state, groupId, values.getDouble(i), extras.getDouble(i)); + combine(state, groupId, values.getDouble(i), outputValues.getDouble(i)); } } @@ -81,8 +81,8 @@ private GroupingState(BigArrays bigArrays, int limit, boolean ascending) { this.sort = new DoubleDoubleBucketedSort(bigArrays, ascending ? SortOrder.ASC : SortOrder.DESC, limit); } - public void add(int groupId, double value, double extra) { - sort.collect(value, extra, groupId); + public void add(int groupId, double value, double outputValue) { + sort.collect(value, outputValue, groupId); } @Override @@ -115,8 +115,8 @@ private SingleState(BigArrays bigArrays, int limit, boolean ascending) { this.internalState = new GroupingState(bigArrays, limit, ascending); } - public void add(double value, double extra) { - internalState.add(0, value, extra); + public void add(double value, double outputValue) { + internalState.add(0, value, outputValue); } @Override diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopDoubleFloatAggregator.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopDoubleFloatAggregator.java index 9cd0f08747930..da103d70c0a54 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopDoubleFloatAggregator.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopDoubleFloatAggregator.java @@ -31,22 +31,22 @@ * This class is generated. Edit `X-TopAggregator.java.st` to edit this file. *

*/ -@Aggregator({ @IntermediateState(name = "top", type = "DOUBLE_BLOCK"), @IntermediateState(name = "extra", type = "FLOAT_BLOCK") }) +@Aggregator({ @IntermediateState(name = "top", type = "DOUBLE_BLOCK"), @IntermediateState(name = "output", type = "FLOAT_BLOCK") }) @GroupingAggregator class TopDoubleFloatAggregator { public static SingleState initSingle(BigArrays bigArrays, int limit, boolean ascending) { return new SingleState(bigArrays, limit, ascending); } - public static void combine(SingleState state, double v, float extra) { - state.add(v, extra); + public static void combine(SingleState state, double v, float outputValue) { + state.add(v, outputValue); } - public static void combineIntermediate(SingleState state, DoubleBlock values, FloatBlock extras) { + public static void combineIntermediate(SingleState state, DoubleBlock values, FloatBlock outputValues) { int start = values.getFirstValueIndex(0); int end = start + values.getValueCount(0); for (int i = start; i < end; i++) { - combine(state, values.getDouble(i), extras.getFloat(i)); + combine(state, values.getDouble(i), outputValues.getFloat(i)); } } @@ -58,15 +58,15 @@ public static GroupingState initGrouping(BigArrays bigArrays, int limit, boolean return new GroupingState(bigArrays, limit, ascending); } - public static void combine(GroupingState state, int groupId, double v, float extra) { - state.add(groupId, v, extra); + public static void combine(GroupingState state, int groupId, double v, float outputValue) { + state.add(groupId, v, outputValue); } - public static void combineIntermediate(GroupingState state, int groupId, DoubleBlock values, FloatBlock extras, int valuesPosition) { + public static void combineIntermediate(GroupingState state, int groupId, DoubleBlock values, FloatBlock outputValues, int valuesPosition) { int start = values.getFirstValueIndex(valuesPosition); int end = start + values.getValueCount(valuesPosition); for (int i = start; i < end; i++) { - combine(state, groupId, values.getDouble(i), extras.getFloat(i)); + combine(state, groupId, values.getDouble(i), outputValues.getFloat(i)); } } @@ -81,8 +81,8 @@ private GroupingState(BigArrays bigArrays, int limit, boolean ascending) { this.sort = new DoubleFloatBucketedSort(bigArrays, ascending ? SortOrder.ASC : SortOrder.DESC, limit); } - public void add(int groupId, double value, float extra) { - sort.collect(value, extra, groupId); + public void add(int groupId, double value, float outputValue) { + sort.collect(value, outputValue, groupId); } @Override @@ -115,8 +115,8 @@ private SingleState(BigArrays bigArrays, int limit, boolean ascending) { this.internalState = new GroupingState(bigArrays, limit, ascending); } - public void add(double value, float extra) { - internalState.add(0, value, extra); + public void add(double value, float outputValue) { + internalState.add(0, value, outputValue); } @Override diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopDoubleIntAggregator.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopDoubleIntAggregator.java index fe1ce903b2d6c..2b0790c303e59 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopDoubleIntAggregator.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopDoubleIntAggregator.java @@ -31,22 +31,22 @@ * This class is generated. Edit `X-TopAggregator.java.st` to edit this file. *

*/ -@Aggregator({ @IntermediateState(name = "top", type = "DOUBLE_BLOCK"), @IntermediateState(name = "extra", type = "INT_BLOCK") }) +@Aggregator({ @IntermediateState(name = "top", type = "DOUBLE_BLOCK"), @IntermediateState(name = "output", type = "INT_BLOCK") }) @GroupingAggregator class TopDoubleIntAggregator { public static SingleState initSingle(BigArrays bigArrays, int limit, boolean ascending) { return new SingleState(bigArrays, limit, ascending); } - public static void combine(SingleState state, double v, int extra) { - state.add(v, extra); + public static void combine(SingleState state, double v, int outputValue) { + state.add(v, outputValue); } - public static void combineIntermediate(SingleState state, DoubleBlock values, IntBlock extras) { + public static void combineIntermediate(SingleState state, DoubleBlock values, IntBlock outputValues) { int start = values.getFirstValueIndex(0); int end = start + values.getValueCount(0); for (int i = start; i < end; i++) { - combine(state, values.getDouble(i), extras.getInt(i)); + combine(state, values.getDouble(i), outputValues.getInt(i)); } } @@ -58,15 +58,15 @@ public static GroupingState initGrouping(BigArrays bigArrays, int limit, boolean return new GroupingState(bigArrays, limit, ascending); } - public static void combine(GroupingState state, int groupId, double v, int extra) { - state.add(groupId, v, extra); + public static void combine(GroupingState state, int groupId, double v, int outputValue) { + state.add(groupId, v, outputValue); } - public static void combineIntermediate(GroupingState state, int groupId, DoubleBlock values, IntBlock extras, int valuesPosition) { + public static void combineIntermediate(GroupingState state, int groupId, DoubleBlock values, IntBlock outputValues, int valuesPosition) { int start = values.getFirstValueIndex(valuesPosition); int end = start + values.getValueCount(valuesPosition); for (int i = start; i < end; i++) { - combine(state, groupId, values.getDouble(i), extras.getInt(i)); + combine(state, groupId, values.getDouble(i), outputValues.getInt(i)); } } @@ -81,8 +81,8 @@ private GroupingState(BigArrays bigArrays, int limit, boolean ascending) { this.sort = new DoubleIntBucketedSort(bigArrays, ascending ? SortOrder.ASC : SortOrder.DESC, limit); } - public void add(int groupId, double value, int extra) { - sort.collect(value, extra, groupId); + public void add(int groupId, double value, int outputValue) { + sort.collect(value, outputValue, groupId); } @Override @@ -115,8 +115,8 @@ private SingleState(BigArrays bigArrays, int limit, boolean ascending) { this.internalState = new GroupingState(bigArrays, limit, ascending); } - public void add(double value, int extra) { - internalState.add(0, value, extra); + public void add(double value, int outputValue) { + internalState.add(0, value, outputValue); } @Override diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopDoubleLongAggregator.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopDoubleLongAggregator.java index 4546acdd1dd6f..57dd898fce1e4 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopDoubleLongAggregator.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopDoubleLongAggregator.java @@ -31,22 +31,22 @@ * This class is generated. Edit `X-TopAggregator.java.st` to edit this file. *

*/ -@Aggregator({ @IntermediateState(name = "top", type = "DOUBLE_BLOCK"), @IntermediateState(name = "extra", type = "LONG_BLOCK") }) +@Aggregator({ @IntermediateState(name = "top", type = "DOUBLE_BLOCK"), @IntermediateState(name = "output", type = "LONG_BLOCK") }) @GroupingAggregator class TopDoubleLongAggregator { public static SingleState initSingle(BigArrays bigArrays, int limit, boolean ascending) { return new SingleState(bigArrays, limit, ascending); } - public static void combine(SingleState state, double v, long extra) { - state.add(v, extra); + public static void combine(SingleState state, double v, long outputValue) { + state.add(v, outputValue); } - public static void combineIntermediate(SingleState state, DoubleBlock values, LongBlock extras) { + public static void combineIntermediate(SingleState state, DoubleBlock values, LongBlock outputValues) { int start = values.getFirstValueIndex(0); int end = start + values.getValueCount(0); for (int i = start; i < end; i++) { - combine(state, values.getDouble(i), extras.getLong(i)); + combine(state, values.getDouble(i), outputValues.getLong(i)); } } @@ -58,15 +58,15 @@ public static GroupingState initGrouping(BigArrays bigArrays, int limit, boolean return new GroupingState(bigArrays, limit, ascending); } - public static void combine(GroupingState state, int groupId, double v, long extra) { - state.add(groupId, v, extra); + public static void combine(GroupingState state, int groupId, double v, long outputValue) { + state.add(groupId, v, outputValue); } - public static void combineIntermediate(GroupingState state, int groupId, DoubleBlock values, LongBlock extras, int valuesPosition) { + public static void combineIntermediate(GroupingState state, int groupId, DoubleBlock values, LongBlock outputValues, int valuesPosition) { int start = values.getFirstValueIndex(valuesPosition); int end = start + values.getValueCount(valuesPosition); for (int i = start; i < end; i++) { - combine(state, groupId, values.getDouble(i), extras.getLong(i)); + combine(state, groupId, values.getDouble(i), outputValues.getLong(i)); } } @@ -81,8 +81,8 @@ private GroupingState(BigArrays bigArrays, int limit, boolean ascending) { this.sort = new DoubleLongBucketedSort(bigArrays, ascending ? SortOrder.ASC : SortOrder.DESC, limit); } - public void add(int groupId, double value, long extra) { - sort.collect(value, extra, groupId); + public void add(int groupId, double value, long outputValue) { + sort.collect(value, outputValue, groupId); } @Override @@ -115,8 +115,8 @@ private SingleState(BigArrays bigArrays, int limit, boolean ascending) { this.internalState = new GroupingState(bigArrays, limit, ascending); } - public void add(double value, long extra) { - internalState.add(0, value, extra); + public void add(double value, long outputValue) { + internalState.add(0, value, outputValue); } @Override diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopFloatDoubleAggregator.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopFloatDoubleAggregator.java index 7d085fc37cf02..ae4ba17da2529 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopFloatDoubleAggregator.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopFloatDoubleAggregator.java @@ -31,22 +31,22 @@ * This class is generated. Edit `X-TopAggregator.java.st` to edit this file. *

*/ -@Aggregator({ @IntermediateState(name = "top", type = "FLOAT_BLOCK"), @IntermediateState(name = "extra", type = "DOUBLE_BLOCK") }) +@Aggregator({ @IntermediateState(name = "top", type = "FLOAT_BLOCK"), @IntermediateState(name = "output", type = "DOUBLE_BLOCK") }) @GroupingAggregator class TopFloatDoubleAggregator { public static SingleState initSingle(BigArrays bigArrays, int limit, boolean ascending) { return new SingleState(bigArrays, limit, ascending); } - public static void combine(SingleState state, float v, double extra) { - state.add(v, extra); + public static void combine(SingleState state, float v, double outputValue) { + state.add(v, outputValue); } - public static void combineIntermediate(SingleState state, FloatBlock values, DoubleBlock extras) { + public static void combineIntermediate(SingleState state, FloatBlock values, DoubleBlock outputValues) { int start = values.getFirstValueIndex(0); int end = start + values.getValueCount(0); for (int i = start; i < end; i++) { - combine(state, values.getFloat(i), extras.getDouble(i)); + combine(state, values.getFloat(i), outputValues.getDouble(i)); } } @@ -58,15 +58,15 @@ public static GroupingState initGrouping(BigArrays bigArrays, int limit, boolean return new GroupingState(bigArrays, limit, ascending); } - public static void combine(GroupingState state, int groupId, float v, double extra) { - state.add(groupId, v, extra); + public static void combine(GroupingState state, int groupId, float v, double outputValue) { + state.add(groupId, v, outputValue); } - public static void combineIntermediate(GroupingState state, int groupId, FloatBlock values, DoubleBlock extras, int valuesPosition) { + public static void combineIntermediate(GroupingState state, int groupId, FloatBlock values, DoubleBlock outputValues, int valuesPosition) { int start = values.getFirstValueIndex(valuesPosition); int end = start + values.getValueCount(valuesPosition); for (int i = start; i < end; i++) { - combine(state, groupId, values.getFloat(i), extras.getDouble(i)); + combine(state, groupId, values.getFloat(i), outputValues.getDouble(i)); } } @@ -81,8 +81,8 @@ private GroupingState(BigArrays bigArrays, int limit, boolean ascending) { this.sort = new FloatDoubleBucketedSort(bigArrays, ascending ? SortOrder.ASC : SortOrder.DESC, limit); } - public void add(int groupId, float value, double extra) { - sort.collect(value, extra, groupId); + public void add(int groupId, float value, double outputValue) { + sort.collect(value, outputValue, groupId); } @Override @@ -115,8 +115,8 @@ private SingleState(BigArrays bigArrays, int limit, boolean ascending) { this.internalState = new GroupingState(bigArrays, limit, ascending); } - public void add(float value, double extra) { - internalState.add(0, value, extra); + public void add(float value, double outputValue) { + internalState.add(0, value, outputValue); } @Override diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopFloatFloatAggregator.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopFloatFloatAggregator.java index cdc0014b14edf..e2876b5cddffa 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopFloatFloatAggregator.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopFloatFloatAggregator.java @@ -31,22 +31,22 @@ * This class is generated. Edit `X-TopAggregator.java.st` to edit this file. *

*/ -@Aggregator({ @IntermediateState(name = "top", type = "FLOAT_BLOCK"), @IntermediateState(name = "extra", type = "FLOAT_BLOCK") }) +@Aggregator({ @IntermediateState(name = "top", type = "FLOAT_BLOCK"), @IntermediateState(name = "output", type = "FLOAT_BLOCK") }) @GroupingAggregator class TopFloatFloatAggregator { public static SingleState initSingle(BigArrays bigArrays, int limit, boolean ascending) { return new SingleState(bigArrays, limit, ascending); } - public static void combine(SingleState state, float v, float extra) { - state.add(v, extra); + public static void combine(SingleState state, float v, float outputValue) { + state.add(v, outputValue); } - public static void combineIntermediate(SingleState state, FloatBlock values, FloatBlock extras) { + public static void combineIntermediate(SingleState state, FloatBlock values, FloatBlock outputValues) { int start = values.getFirstValueIndex(0); int end = start + values.getValueCount(0); for (int i = start; i < end; i++) { - combine(state, values.getFloat(i), extras.getFloat(i)); + combine(state, values.getFloat(i), outputValues.getFloat(i)); } } @@ -58,15 +58,15 @@ public static GroupingState initGrouping(BigArrays bigArrays, int limit, boolean return new GroupingState(bigArrays, limit, ascending); } - public static void combine(GroupingState state, int groupId, float v, float extra) { - state.add(groupId, v, extra); + public static void combine(GroupingState state, int groupId, float v, float outputValue) { + state.add(groupId, v, outputValue); } - public static void combineIntermediate(GroupingState state, int groupId, FloatBlock values, FloatBlock extras, int valuesPosition) { + public static void combineIntermediate(GroupingState state, int groupId, FloatBlock values, FloatBlock outputValues, int valuesPosition) { int start = values.getFirstValueIndex(valuesPosition); int end = start + values.getValueCount(valuesPosition); for (int i = start; i < end; i++) { - combine(state, groupId, values.getFloat(i), extras.getFloat(i)); + combine(state, groupId, values.getFloat(i), outputValues.getFloat(i)); } } @@ -81,8 +81,8 @@ private GroupingState(BigArrays bigArrays, int limit, boolean ascending) { this.sort = new FloatFloatBucketedSort(bigArrays, ascending ? SortOrder.ASC : SortOrder.DESC, limit); } - public void add(int groupId, float value, float extra) { - sort.collect(value, extra, groupId); + public void add(int groupId, float value, float outputValue) { + sort.collect(value, outputValue, groupId); } @Override @@ -115,8 +115,8 @@ private SingleState(BigArrays bigArrays, int limit, boolean ascending) { this.internalState = new GroupingState(bigArrays, limit, ascending); } - public void add(float value, float extra) { - internalState.add(0, value, extra); + public void add(float value, float outputValue) { + internalState.add(0, value, outputValue); } @Override diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopFloatIntAggregator.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopFloatIntAggregator.java index ff443fd451503..0de205c508713 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopFloatIntAggregator.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopFloatIntAggregator.java @@ -31,22 +31,22 @@ * This class is generated. Edit `X-TopAggregator.java.st` to edit this file. *

*/ -@Aggregator({ @IntermediateState(name = "top", type = "FLOAT_BLOCK"), @IntermediateState(name = "extra", type = "INT_BLOCK") }) +@Aggregator({ @IntermediateState(name = "top", type = "FLOAT_BLOCK"), @IntermediateState(name = "output", type = "INT_BLOCK") }) @GroupingAggregator class TopFloatIntAggregator { public static SingleState initSingle(BigArrays bigArrays, int limit, boolean ascending) { return new SingleState(bigArrays, limit, ascending); } - public static void combine(SingleState state, float v, int extra) { - state.add(v, extra); + public static void combine(SingleState state, float v, int outputValue) { + state.add(v, outputValue); } - public static void combineIntermediate(SingleState state, FloatBlock values, IntBlock extras) { + public static void combineIntermediate(SingleState state, FloatBlock values, IntBlock outputValues) { int start = values.getFirstValueIndex(0); int end = start + values.getValueCount(0); for (int i = start; i < end; i++) { - combine(state, values.getFloat(i), extras.getInt(i)); + combine(state, values.getFloat(i), outputValues.getInt(i)); } } @@ -58,15 +58,15 @@ public static GroupingState initGrouping(BigArrays bigArrays, int limit, boolean return new GroupingState(bigArrays, limit, ascending); } - public static void combine(GroupingState state, int groupId, float v, int extra) { - state.add(groupId, v, extra); + public static void combine(GroupingState state, int groupId, float v, int outputValue) { + state.add(groupId, v, outputValue); } - public static void combineIntermediate(GroupingState state, int groupId, FloatBlock values, IntBlock extras, int valuesPosition) { + public static void combineIntermediate(GroupingState state, int groupId, FloatBlock values, IntBlock outputValues, int valuesPosition) { int start = values.getFirstValueIndex(valuesPosition); int end = start + values.getValueCount(valuesPosition); for (int i = start; i < end; i++) { - combine(state, groupId, values.getFloat(i), extras.getInt(i)); + combine(state, groupId, values.getFloat(i), outputValues.getInt(i)); } } @@ -81,8 +81,8 @@ private GroupingState(BigArrays bigArrays, int limit, boolean ascending) { this.sort = new FloatIntBucketedSort(bigArrays, ascending ? SortOrder.ASC : SortOrder.DESC, limit); } - public void add(int groupId, float value, int extra) { - sort.collect(value, extra, groupId); + public void add(int groupId, float value, int outputValue) { + sort.collect(value, outputValue, groupId); } @Override @@ -115,8 +115,8 @@ private SingleState(BigArrays bigArrays, int limit, boolean ascending) { this.internalState = new GroupingState(bigArrays, limit, ascending); } - public void add(float value, int extra) { - internalState.add(0, value, extra); + public void add(float value, int outputValue) { + internalState.add(0, value, outputValue); } @Override diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopFloatLongAggregator.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopFloatLongAggregator.java index 896ef0caf115f..580d649abae42 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopFloatLongAggregator.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopFloatLongAggregator.java @@ -31,22 +31,22 @@ * This class is generated. Edit `X-TopAggregator.java.st` to edit this file. *

*/ -@Aggregator({ @IntermediateState(name = "top", type = "FLOAT_BLOCK"), @IntermediateState(name = "extra", type = "LONG_BLOCK") }) +@Aggregator({ @IntermediateState(name = "top", type = "FLOAT_BLOCK"), @IntermediateState(name = "output", type = "LONG_BLOCK") }) @GroupingAggregator class TopFloatLongAggregator { public static SingleState initSingle(BigArrays bigArrays, int limit, boolean ascending) { return new SingleState(bigArrays, limit, ascending); } - public static void combine(SingleState state, float v, long extra) { - state.add(v, extra); + public static void combine(SingleState state, float v, long outputValue) { + state.add(v, outputValue); } - public static void combineIntermediate(SingleState state, FloatBlock values, LongBlock extras) { + public static void combineIntermediate(SingleState state, FloatBlock values, LongBlock outputValues) { int start = values.getFirstValueIndex(0); int end = start + values.getValueCount(0); for (int i = start; i < end; i++) { - combine(state, values.getFloat(i), extras.getLong(i)); + combine(state, values.getFloat(i), outputValues.getLong(i)); } } @@ -58,15 +58,15 @@ public static GroupingState initGrouping(BigArrays bigArrays, int limit, boolean return new GroupingState(bigArrays, limit, ascending); } - public static void combine(GroupingState state, int groupId, float v, long extra) { - state.add(groupId, v, extra); + public static void combine(GroupingState state, int groupId, float v, long outputValue) { + state.add(groupId, v, outputValue); } - public static void combineIntermediate(GroupingState state, int groupId, FloatBlock values, LongBlock extras, int valuesPosition) { + public static void combineIntermediate(GroupingState state, int groupId, FloatBlock values, LongBlock outputValues, int valuesPosition) { int start = values.getFirstValueIndex(valuesPosition); int end = start + values.getValueCount(valuesPosition); for (int i = start; i < end; i++) { - combine(state, groupId, values.getFloat(i), extras.getLong(i)); + combine(state, groupId, values.getFloat(i), outputValues.getLong(i)); } } @@ -81,8 +81,8 @@ private GroupingState(BigArrays bigArrays, int limit, boolean ascending) { this.sort = new FloatLongBucketedSort(bigArrays, ascending ? SortOrder.ASC : SortOrder.DESC, limit); } - public void add(int groupId, float value, long extra) { - sort.collect(value, extra, groupId); + public void add(int groupId, float value, long outputValue) { + sort.collect(value, outputValue, groupId); } @Override @@ -115,8 +115,8 @@ private SingleState(BigArrays bigArrays, int limit, boolean ascending) { this.internalState = new GroupingState(bigArrays, limit, ascending); } - public void add(float value, long extra) { - internalState.add(0, value, extra); + public void add(float value, long outputValue) { + internalState.add(0, value, outputValue); } @Override diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopIntDoubleAggregator.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopIntDoubleAggregator.java index d099c29c55a13..10090a179b5bb 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopIntDoubleAggregator.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopIntDoubleAggregator.java @@ -31,22 +31,22 @@ * This class is generated. Edit `X-TopAggregator.java.st` to edit this file. *

*/ -@Aggregator({ @IntermediateState(name = "top", type = "INT_BLOCK"), @IntermediateState(name = "extra", type = "DOUBLE_BLOCK") }) +@Aggregator({ @IntermediateState(name = "top", type = "INT_BLOCK"), @IntermediateState(name = "output", type = "DOUBLE_BLOCK") }) @GroupingAggregator class TopIntDoubleAggregator { public static SingleState initSingle(BigArrays bigArrays, int limit, boolean ascending) { return new SingleState(bigArrays, limit, ascending); } - public static void combine(SingleState state, int v, double extra) { - state.add(v, extra); + public static void combine(SingleState state, int v, double outputValue) { + state.add(v, outputValue); } - public static void combineIntermediate(SingleState state, IntBlock values, DoubleBlock extras) { + public static void combineIntermediate(SingleState state, IntBlock values, DoubleBlock outputValues) { int start = values.getFirstValueIndex(0); int end = start + values.getValueCount(0); for (int i = start; i < end; i++) { - combine(state, values.getInt(i), extras.getDouble(i)); + combine(state, values.getInt(i), outputValues.getDouble(i)); } } @@ -58,15 +58,15 @@ public static GroupingState initGrouping(BigArrays bigArrays, int limit, boolean return new GroupingState(bigArrays, limit, ascending); } - public static void combine(GroupingState state, int groupId, int v, double extra) { - state.add(groupId, v, extra); + public static void combine(GroupingState state, int groupId, int v, double outputValue) { + state.add(groupId, v, outputValue); } - public static void combineIntermediate(GroupingState state, int groupId, IntBlock values, DoubleBlock extras, int valuesPosition) { + public static void combineIntermediate(GroupingState state, int groupId, IntBlock values, DoubleBlock outputValues, int valuesPosition) { int start = values.getFirstValueIndex(valuesPosition); int end = start + values.getValueCount(valuesPosition); for (int i = start; i < end; i++) { - combine(state, groupId, values.getInt(i), extras.getDouble(i)); + combine(state, groupId, values.getInt(i), outputValues.getDouble(i)); } } @@ -81,8 +81,8 @@ private GroupingState(BigArrays bigArrays, int limit, boolean ascending) { this.sort = new IntDoubleBucketedSort(bigArrays, ascending ? SortOrder.ASC : SortOrder.DESC, limit); } - public void add(int groupId, int value, double extra) { - sort.collect(value, extra, groupId); + public void add(int groupId, int value, double outputValue) { + sort.collect(value, outputValue, groupId); } @Override @@ -115,8 +115,8 @@ private SingleState(BigArrays bigArrays, int limit, boolean ascending) { this.internalState = new GroupingState(bigArrays, limit, ascending); } - public void add(int value, double extra) { - internalState.add(0, value, extra); + public void add(int value, double outputValue) { + internalState.add(0, value, outputValue); } @Override diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopIntFloatAggregator.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopIntFloatAggregator.java index 8332fdb7042cb..e007e66e8b526 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopIntFloatAggregator.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopIntFloatAggregator.java @@ -31,22 +31,22 @@ * This class is generated. Edit `X-TopAggregator.java.st` to edit this file. *

*/ -@Aggregator({ @IntermediateState(name = "top", type = "INT_BLOCK"), @IntermediateState(name = "extra", type = "FLOAT_BLOCK") }) +@Aggregator({ @IntermediateState(name = "top", type = "INT_BLOCK"), @IntermediateState(name = "output", type = "FLOAT_BLOCK") }) @GroupingAggregator class TopIntFloatAggregator { public static SingleState initSingle(BigArrays bigArrays, int limit, boolean ascending) { return new SingleState(bigArrays, limit, ascending); } - public static void combine(SingleState state, int v, float extra) { - state.add(v, extra); + public static void combine(SingleState state, int v, float outputValue) { + state.add(v, outputValue); } - public static void combineIntermediate(SingleState state, IntBlock values, FloatBlock extras) { + public static void combineIntermediate(SingleState state, IntBlock values, FloatBlock outputValues) { int start = values.getFirstValueIndex(0); int end = start + values.getValueCount(0); for (int i = start; i < end; i++) { - combine(state, values.getInt(i), extras.getFloat(i)); + combine(state, values.getInt(i), outputValues.getFloat(i)); } } @@ -58,15 +58,15 @@ public static GroupingState initGrouping(BigArrays bigArrays, int limit, boolean return new GroupingState(bigArrays, limit, ascending); } - public static void combine(GroupingState state, int groupId, int v, float extra) { - state.add(groupId, v, extra); + public static void combine(GroupingState state, int groupId, int v, float outputValue) { + state.add(groupId, v, outputValue); } - public static void combineIntermediate(GroupingState state, int groupId, IntBlock values, FloatBlock extras, int valuesPosition) { + public static void combineIntermediate(GroupingState state, int groupId, IntBlock values, FloatBlock outputValues, int valuesPosition) { int start = values.getFirstValueIndex(valuesPosition); int end = start + values.getValueCount(valuesPosition); for (int i = start; i < end; i++) { - combine(state, groupId, values.getInt(i), extras.getFloat(i)); + combine(state, groupId, values.getInt(i), outputValues.getFloat(i)); } } @@ -81,8 +81,8 @@ private GroupingState(BigArrays bigArrays, int limit, boolean ascending) { this.sort = new IntFloatBucketedSort(bigArrays, ascending ? SortOrder.ASC : SortOrder.DESC, limit); } - public void add(int groupId, int value, float extra) { - sort.collect(value, extra, groupId); + public void add(int groupId, int value, float outputValue) { + sort.collect(value, outputValue, groupId); } @Override @@ -115,8 +115,8 @@ private SingleState(BigArrays bigArrays, int limit, boolean ascending) { this.internalState = new GroupingState(bigArrays, limit, ascending); } - public void add(int value, float extra) { - internalState.add(0, value, extra); + public void add(int value, float outputValue) { + internalState.add(0, value, outputValue); } @Override diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopIntIntAggregator.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopIntIntAggregator.java index 98577abc4a094..72b2065e1fe77 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopIntIntAggregator.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopIntIntAggregator.java @@ -31,22 +31,22 @@ * This class is generated. Edit `X-TopAggregator.java.st` to edit this file. *

*/ -@Aggregator({ @IntermediateState(name = "top", type = "INT_BLOCK"), @IntermediateState(name = "extra", type = "INT_BLOCK") }) +@Aggregator({ @IntermediateState(name = "top", type = "INT_BLOCK"), @IntermediateState(name = "output", type = "INT_BLOCK") }) @GroupingAggregator class TopIntIntAggregator { public static SingleState initSingle(BigArrays bigArrays, int limit, boolean ascending) { return new SingleState(bigArrays, limit, ascending); } - public static void combine(SingleState state, int v, int extra) { - state.add(v, extra); + public static void combine(SingleState state, int v, int outputValue) { + state.add(v, outputValue); } - public static void combineIntermediate(SingleState state, IntBlock values, IntBlock extras) { + public static void combineIntermediate(SingleState state, IntBlock values, IntBlock outputValues) { int start = values.getFirstValueIndex(0); int end = start + values.getValueCount(0); for (int i = start; i < end; i++) { - combine(state, values.getInt(i), extras.getInt(i)); + combine(state, values.getInt(i), outputValues.getInt(i)); } } @@ -58,15 +58,15 @@ public static GroupingState initGrouping(BigArrays bigArrays, int limit, boolean return new GroupingState(bigArrays, limit, ascending); } - public static void combine(GroupingState state, int groupId, int v, int extra) { - state.add(groupId, v, extra); + public static void combine(GroupingState state, int groupId, int v, int outputValue) { + state.add(groupId, v, outputValue); } - public static void combineIntermediate(GroupingState state, int groupId, IntBlock values, IntBlock extras, int valuesPosition) { + public static void combineIntermediate(GroupingState state, int groupId, IntBlock values, IntBlock outputValues, int valuesPosition) { int start = values.getFirstValueIndex(valuesPosition); int end = start + values.getValueCount(valuesPosition); for (int i = start; i < end; i++) { - combine(state, groupId, values.getInt(i), extras.getInt(i)); + combine(state, groupId, values.getInt(i), outputValues.getInt(i)); } } @@ -81,8 +81,8 @@ private GroupingState(BigArrays bigArrays, int limit, boolean ascending) { this.sort = new IntIntBucketedSort(bigArrays, ascending ? SortOrder.ASC : SortOrder.DESC, limit); } - public void add(int groupId, int value, int extra) { - sort.collect(value, extra, groupId); + public void add(int groupId, int value, int outputValue) { + sort.collect(value, outputValue, groupId); } @Override @@ -115,8 +115,8 @@ private SingleState(BigArrays bigArrays, int limit, boolean ascending) { this.internalState = new GroupingState(bigArrays, limit, ascending); } - public void add(int value, int extra) { - internalState.add(0, value, extra); + public void add(int value, int outputValue) { + internalState.add(0, value, outputValue); } @Override diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopIntLongAggregator.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopIntLongAggregator.java index 823928bcf09bf..a3eba01bd34cf 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopIntLongAggregator.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopIntLongAggregator.java @@ -31,22 +31,22 @@ * This class is generated. Edit `X-TopAggregator.java.st` to edit this file. *

*/ -@Aggregator({ @IntermediateState(name = "top", type = "INT_BLOCK"), @IntermediateState(name = "extra", type = "LONG_BLOCK") }) +@Aggregator({ @IntermediateState(name = "top", type = "INT_BLOCK"), @IntermediateState(name = "output", type = "LONG_BLOCK") }) @GroupingAggregator class TopIntLongAggregator { public static SingleState initSingle(BigArrays bigArrays, int limit, boolean ascending) { return new SingleState(bigArrays, limit, ascending); } - public static void combine(SingleState state, int v, long extra) { - state.add(v, extra); + public static void combine(SingleState state, int v, long outputValue) { + state.add(v, outputValue); } - public static void combineIntermediate(SingleState state, IntBlock values, LongBlock extras) { + public static void combineIntermediate(SingleState state, IntBlock values, LongBlock outputValues) { int start = values.getFirstValueIndex(0); int end = start + values.getValueCount(0); for (int i = start; i < end; i++) { - combine(state, values.getInt(i), extras.getLong(i)); + combine(state, values.getInt(i), outputValues.getLong(i)); } } @@ -58,15 +58,15 @@ public static GroupingState initGrouping(BigArrays bigArrays, int limit, boolean return new GroupingState(bigArrays, limit, ascending); } - public static void combine(GroupingState state, int groupId, int v, long extra) { - state.add(groupId, v, extra); + public static void combine(GroupingState state, int groupId, int v, long outputValue) { + state.add(groupId, v, outputValue); } - public static void combineIntermediate(GroupingState state, int groupId, IntBlock values, LongBlock extras, int valuesPosition) { + public static void combineIntermediate(GroupingState state, int groupId, IntBlock values, LongBlock outputValues, int valuesPosition) { int start = values.getFirstValueIndex(valuesPosition); int end = start + values.getValueCount(valuesPosition); for (int i = start; i < end; i++) { - combine(state, groupId, values.getInt(i), extras.getLong(i)); + combine(state, groupId, values.getInt(i), outputValues.getLong(i)); } } @@ -81,8 +81,8 @@ private GroupingState(BigArrays bigArrays, int limit, boolean ascending) { this.sort = new IntLongBucketedSort(bigArrays, ascending ? SortOrder.ASC : SortOrder.DESC, limit); } - public void add(int groupId, int value, long extra) { - sort.collect(value, extra, groupId); + public void add(int groupId, int value, long outputValue) { + sort.collect(value, outputValue, groupId); } @Override @@ -115,8 +115,8 @@ private SingleState(BigArrays bigArrays, int limit, boolean ascending) { this.internalState = new GroupingState(bigArrays, limit, ascending); } - public void add(int value, long extra) { - internalState.add(0, value, extra); + public void add(int value, long outputValue) { + internalState.add(0, value, outputValue); } @Override diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopLongDoubleAggregator.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopLongDoubleAggregator.java index a8c1c56adb95b..31c4f9096ca0e 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopLongDoubleAggregator.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopLongDoubleAggregator.java @@ -31,22 +31,22 @@ * This class is generated. Edit `X-TopAggregator.java.st` to edit this file. *

*/ -@Aggregator({ @IntermediateState(name = "top", type = "LONG_BLOCK"), @IntermediateState(name = "extra", type = "DOUBLE_BLOCK") }) +@Aggregator({ @IntermediateState(name = "top", type = "LONG_BLOCK"), @IntermediateState(name = "output", type = "DOUBLE_BLOCK") }) @GroupingAggregator class TopLongDoubleAggregator { public static SingleState initSingle(BigArrays bigArrays, int limit, boolean ascending) { return new SingleState(bigArrays, limit, ascending); } - public static void combine(SingleState state, long v, double extra) { - state.add(v, extra); + public static void combine(SingleState state, long v, double outputValue) { + state.add(v, outputValue); } - public static void combineIntermediate(SingleState state, LongBlock values, DoubleBlock extras) { + public static void combineIntermediate(SingleState state, LongBlock values, DoubleBlock outputValues) { int start = values.getFirstValueIndex(0); int end = start + values.getValueCount(0); for (int i = start; i < end; i++) { - combine(state, values.getLong(i), extras.getDouble(i)); + combine(state, values.getLong(i), outputValues.getDouble(i)); } } @@ -58,15 +58,15 @@ public static GroupingState initGrouping(BigArrays bigArrays, int limit, boolean return new GroupingState(bigArrays, limit, ascending); } - public static void combine(GroupingState state, int groupId, long v, double extra) { - state.add(groupId, v, extra); + public static void combine(GroupingState state, int groupId, long v, double outputValue) { + state.add(groupId, v, outputValue); } - public static void combineIntermediate(GroupingState state, int groupId, LongBlock values, DoubleBlock extras, int valuesPosition) { + public static void combineIntermediate(GroupingState state, int groupId, LongBlock values, DoubleBlock outputValues, int valuesPosition) { int start = values.getFirstValueIndex(valuesPosition); int end = start + values.getValueCount(valuesPosition); for (int i = start; i < end; i++) { - combine(state, groupId, values.getLong(i), extras.getDouble(i)); + combine(state, groupId, values.getLong(i), outputValues.getDouble(i)); } } @@ -81,8 +81,8 @@ private GroupingState(BigArrays bigArrays, int limit, boolean ascending) { this.sort = new LongDoubleBucketedSort(bigArrays, ascending ? SortOrder.ASC : SortOrder.DESC, limit); } - public void add(int groupId, long value, double extra) { - sort.collect(value, extra, groupId); + public void add(int groupId, long value, double outputValue) { + sort.collect(value, outputValue, groupId); } @Override @@ -115,8 +115,8 @@ private SingleState(BigArrays bigArrays, int limit, boolean ascending) { this.internalState = new GroupingState(bigArrays, limit, ascending); } - public void add(long value, double extra) { - internalState.add(0, value, extra); + public void add(long value, double outputValue) { + internalState.add(0, value, outputValue); } @Override diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopLongFloatAggregator.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopLongFloatAggregator.java index dce908d0adc28..66d699cfd3d32 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopLongFloatAggregator.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopLongFloatAggregator.java @@ -31,22 +31,22 @@ * This class is generated. Edit `X-TopAggregator.java.st` to edit this file. *

*/ -@Aggregator({ @IntermediateState(name = "top", type = "LONG_BLOCK"), @IntermediateState(name = "extra", type = "FLOAT_BLOCK") }) +@Aggregator({ @IntermediateState(name = "top", type = "LONG_BLOCK"), @IntermediateState(name = "output", type = "FLOAT_BLOCK") }) @GroupingAggregator class TopLongFloatAggregator { public static SingleState initSingle(BigArrays bigArrays, int limit, boolean ascending) { return new SingleState(bigArrays, limit, ascending); } - public static void combine(SingleState state, long v, float extra) { - state.add(v, extra); + public static void combine(SingleState state, long v, float outputValue) { + state.add(v, outputValue); } - public static void combineIntermediate(SingleState state, LongBlock values, FloatBlock extras) { + public static void combineIntermediate(SingleState state, LongBlock values, FloatBlock outputValues) { int start = values.getFirstValueIndex(0); int end = start + values.getValueCount(0); for (int i = start; i < end; i++) { - combine(state, values.getLong(i), extras.getFloat(i)); + combine(state, values.getLong(i), outputValues.getFloat(i)); } } @@ -58,15 +58,15 @@ public static GroupingState initGrouping(BigArrays bigArrays, int limit, boolean return new GroupingState(bigArrays, limit, ascending); } - public static void combine(GroupingState state, int groupId, long v, float extra) { - state.add(groupId, v, extra); + public static void combine(GroupingState state, int groupId, long v, float outputValue) { + state.add(groupId, v, outputValue); } - public static void combineIntermediate(GroupingState state, int groupId, LongBlock values, FloatBlock extras, int valuesPosition) { + public static void combineIntermediate(GroupingState state, int groupId, LongBlock values, FloatBlock outputValues, int valuesPosition) { int start = values.getFirstValueIndex(valuesPosition); int end = start + values.getValueCount(valuesPosition); for (int i = start; i < end; i++) { - combine(state, groupId, values.getLong(i), extras.getFloat(i)); + combine(state, groupId, values.getLong(i), outputValues.getFloat(i)); } } @@ -81,8 +81,8 @@ private GroupingState(BigArrays bigArrays, int limit, boolean ascending) { this.sort = new LongFloatBucketedSort(bigArrays, ascending ? SortOrder.ASC : SortOrder.DESC, limit); } - public void add(int groupId, long value, float extra) { - sort.collect(value, extra, groupId); + public void add(int groupId, long value, float outputValue) { + sort.collect(value, outputValue, groupId); } @Override @@ -115,8 +115,8 @@ private SingleState(BigArrays bigArrays, int limit, boolean ascending) { this.internalState = new GroupingState(bigArrays, limit, ascending); } - public void add(long value, float extra) { - internalState.add(0, value, extra); + public void add(long value, float outputValue) { + internalState.add(0, value, outputValue); } @Override diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopLongIntAggregator.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopLongIntAggregator.java index 495dea450d119..d2f661348a146 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopLongIntAggregator.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopLongIntAggregator.java @@ -31,22 +31,22 @@ * This class is generated. Edit `X-TopAggregator.java.st` to edit this file. *

*/ -@Aggregator({ @IntermediateState(name = "top", type = "LONG_BLOCK"), @IntermediateState(name = "extra", type = "INT_BLOCK") }) +@Aggregator({ @IntermediateState(name = "top", type = "LONG_BLOCK"), @IntermediateState(name = "output", type = "INT_BLOCK") }) @GroupingAggregator class TopLongIntAggregator { public static SingleState initSingle(BigArrays bigArrays, int limit, boolean ascending) { return new SingleState(bigArrays, limit, ascending); } - public static void combine(SingleState state, long v, int extra) { - state.add(v, extra); + public static void combine(SingleState state, long v, int outputValue) { + state.add(v, outputValue); } - public static void combineIntermediate(SingleState state, LongBlock values, IntBlock extras) { + public static void combineIntermediate(SingleState state, LongBlock values, IntBlock outputValues) { int start = values.getFirstValueIndex(0); int end = start + values.getValueCount(0); for (int i = start; i < end; i++) { - combine(state, values.getLong(i), extras.getInt(i)); + combine(state, values.getLong(i), outputValues.getInt(i)); } } @@ -58,15 +58,15 @@ public static GroupingState initGrouping(BigArrays bigArrays, int limit, boolean return new GroupingState(bigArrays, limit, ascending); } - public static void combine(GroupingState state, int groupId, long v, int extra) { - state.add(groupId, v, extra); + public static void combine(GroupingState state, int groupId, long v, int outputValue) { + state.add(groupId, v, outputValue); } - public static void combineIntermediate(GroupingState state, int groupId, LongBlock values, IntBlock extras, int valuesPosition) { + public static void combineIntermediate(GroupingState state, int groupId, LongBlock values, IntBlock outputValues, int valuesPosition) { int start = values.getFirstValueIndex(valuesPosition); int end = start + values.getValueCount(valuesPosition); for (int i = start; i < end; i++) { - combine(state, groupId, values.getLong(i), extras.getInt(i)); + combine(state, groupId, values.getLong(i), outputValues.getInt(i)); } } @@ -81,8 +81,8 @@ private GroupingState(BigArrays bigArrays, int limit, boolean ascending) { this.sort = new LongIntBucketedSort(bigArrays, ascending ? SortOrder.ASC : SortOrder.DESC, limit); } - public void add(int groupId, long value, int extra) { - sort.collect(value, extra, groupId); + public void add(int groupId, long value, int outputValue) { + sort.collect(value, outputValue, groupId); } @Override @@ -115,8 +115,8 @@ private SingleState(BigArrays bigArrays, int limit, boolean ascending) { this.internalState = new GroupingState(bigArrays, limit, ascending); } - public void add(long value, int extra) { - internalState.add(0, value, extra); + public void add(long value, int outputValue) { + internalState.add(0, value, outputValue); } @Override diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopLongLongAggregator.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopLongLongAggregator.java index e47e478ac0dac..3db32f71905c0 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopLongLongAggregator.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopLongLongAggregator.java @@ -31,22 +31,22 @@ * This class is generated. Edit `X-TopAggregator.java.st` to edit this file. *

*/ -@Aggregator({ @IntermediateState(name = "top", type = "LONG_BLOCK"), @IntermediateState(name = "extra", type = "LONG_BLOCK") }) +@Aggregator({ @IntermediateState(name = "top", type = "LONG_BLOCK"), @IntermediateState(name = "output", type = "LONG_BLOCK") }) @GroupingAggregator class TopLongLongAggregator { public static SingleState initSingle(BigArrays bigArrays, int limit, boolean ascending) { return new SingleState(bigArrays, limit, ascending); } - public static void combine(SingleState state, long v, long extra) { - state.add(v, extra); + public static void combine(SingleState state, long v, long outputValue) { + state.add(v, outputValue); } - public static void combineIntermediate(SingleState state, LongBlock values, LongBlock extras) { + public static void combineIntermediate(SingleState state, LongBlock values, LongBlock outputValues) { int start = values.getFirstValueIndex(0); int end = start + values.getValueCount(0); for (int i = start; i < end; i++) { - combine(state, values.getLong(i), extras.getLong(i)); + combine(state, values.getLong(i), outputValues.getLong(i)); } } @@ -58,15 +58,15 @@ public static GroupingState initGrouping(BigArrays bigArrays, int limit, boolean return new GroupingState(bigArrays, limit, ascending); } - public static void combine(GroupingState state, int groupId, long v, long extra) { - state.add(groupId, v, extra); + public static void combine(GroupingState state, int groupId, long v, long outputValue) { + state.add(groupId, v, outputValue); } - public static void combineIntermediate(GroupingState state, int groupId, LongBlock values, LongBlock extras, int valuesPosition) { + public static void combineIntermediate(GroupingState state, int groupId, LongBlock values, LongBlock outputValues, int valuesPosition) { int start = values.getFirstValueIndex(valuesPosition); int end = start + values.getValueCount(valuesPosition); for (int i = start; i < end; i++) { - combine(state, groupId, values.getLong(i), extras.getLong(i)); + combine(state, groupId, values.getLong(i), outputValues.getLong(i)); } } @@ -81,8 +81,8 @@ private GroupingState(BigArrays bigArrays, int limit, boolean ascending) { this.sort = new LongLongBucketedSort(bigArrays, ascending ? SortOrder.ASC : SortOrder.DESC, limit); } - public void add(int groupId, long value, long extra) { - sort.collect(value, extra, groupId); + public void add(int groupId, long value, long outputValue) { + sort.collect(value, outputValue, groupId); } @Override @@ -115,8 +115,8 @@ private SingleState(BigArrays bigArrays, int limit, boolean ascending) { this.internalState = new GroupingState(bigArrays, limit, ascending); } - public void add(long value, long extra) { - internalState.add(0, value, extra); + public void add(long value, long outputValue) { + internalState.add(0, value, outputValue); } @Override diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleBucketedSort.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleBucketedSort.java index 995cf68cd6a50..859dd564d2a72 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleBucketedSort.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleBucketedSort.java @@ -240,8 +240,7 @@ private void setNextGatherOffset(long rootIndex, int offset) { * {@link SortOrder#ASC} and "higher" for {@link SortOrder#DESC}. */ private boolean betterThan(double lhs, double rhs) { - int res = Double.compare(lhs, rhs); - return getOrder().reverseMul() * res < 0; + return getOrder().reverseMul() * Double.compare(lhs, rhs) < 0; } /** diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleDoubleBucketedSort.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleDoubleBucketedSort.java index 0794a3712ee1d..7b6ec62c9d6e9 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleDoubleBucketedSort.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleDoubleBucketedSort.java @@ -95,7 +95,7 @@ public DoubleDoubleBucketedSort(BigArrays bigArrays, SortOrder order, int bucket public void collect(double value, double extraValue, int bucket) { long rootIndex = (long) bucket * bucketSize; if (inHeapMode(bucket)) { - if (betterThan(value, values.get(rootIndex), extraValue, extraValues.get(rootIndex))) { + if (betterThan(value, values.get(rootIndex))) { values.set(rootIndex, value); extraValues.set(rootIndex, extraValue); downHeap(rootIndex, 0, bucketSize); @@ -168,8 +168,10 @@ public void merge(int groupId, DoubleDoubleBucketedSort other, int otherGroupId) public void toBlocks(BlockFactory blockFactory, Block[] blocks, int offset, IntVector selected) { // Check if the selected groups are all empty, to avoid allocating extra memory if (allSelectedGroupsAreEmpty(selected)) { - blocks[offset] = blockFactory.newConstantNullBlock(selected.getPositionCount()); - blocks[offset + 1] = blockFactory.newConstantNullBlock(selected.getPositionCount()); + Block constantNullBlock = blockFactory.newConstantNullBlock(selected.getPositionCount()); + constantNullBlock.incRef(); + blocks[offset] = constantNullBlock; + blocks[offset + 1] = constantNullBlock; return; } @@ -255,13 +257,8 @@ private void setNextGatherOffset(long rootIndex, int offset) { * the entry at {@code rhs}. "Better" in this means "lower" for * {@link SortOrder#ASC} and "higher" for {@link SortOrder#DESC}. */ - private boolean betterThan(double lhs, double rhs, double lhsExtra, double rhsExtra) { - int res = Double.compare(lhs, rhs); - if (res != 0) { - return getOrder().reverseMul() * res < 0; - } - res = Double.compare(lhsExtra, rhsExtra); - return getOrder().reverseMul() * res < 0; + private boolean betterThan(double lhs, double rhs) { + return getOrder().reverseMul() * Double.compare(lhs, rhs) < 0; } /** @@ -374,19 +371,13 @@ private void downHeap(long rootIndex, int parent, int heapSize) { int leftChild = parent * 2 + 1; long leftIndex = rootIndex + leftChild; if (leftChild < heapSize) { - if (betterThan(values.get(worstIndex), values.get(leftIndex), extraValues.get(worstIndex), extraValues.get(leftIndex))) { + if (betterThan(values.get(worstIndex), values.get(leftIndex))) { worst = leftChild; worstIndex = leftIndex; } int rightChild = leftChild + 1; long rightIndex = rootIndex + rightChild; - if (rightChild < heapSize - && betterThan( - values.get(worstIndex), - values.get(rightIndex), - extraValues.get(worstIndex), - extraValues.get(rightIndex) - )) { + if (rightChild < heapSize && betterThan(values.get(worstIndex), values.get(rightIndex))) { worst = rightChild; worstIndex = rightIndex; } diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleFloatBucketedSort.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleFloatBucketedSort.java index f86b3dfefa08f..4e21ca916726e 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleFloatBucketedSort.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleFloatBucketedSort.java @@ -95,7 +95,7 @@ public DoubleFloatBucketedSort(BigArrays bigArrays, SortOrder order, int bucketS public void collect(double value, float extraValue, int bucket) { long rootIndex = (long) bucket * bucketSize; if (inHeapMode(bucket)) { - if (betterThan(value, values.get(rootIndex), extraValue, extraValues.get(rootIndex))) { + if (betterThan(value, values.get(rootIndex))) { values.set(rootIndex, value); extraValues.set(rootIndex, extraValue); downHeap(rootIndex, 0, bucketSize); @@ -168,8 +168,10 @@ public void merge(int groupId, DoubleFloatBucketedSort other, int otherGroupId) public void toBlocks(BlockFactory blockFactory, Block[] blocks, int offset, IntVector selected) { // Check if the selected groups are all empty, to avoid allocating extra memory if (allSelectedGroupsAreEmpty(selected)) { - blocks[offset] = blockFactory.newConstantNullBlock(selected.getPositionCount()); - blocks[offset + 1] = blockFactory.newConstantNullBlock(selected.getPositionCount()); + Block constantNullBlock = blockFactory.newConstantNullBlock(selected.getPositionCount()); + constantNullBlock.incRef(); + blocks[offset] = constantNullBlock; + blocks[offset + 1] = constantNullBlock; return; } @@ -255,13 +257,8 @@ private void setNextGatherOffset(long rootIndex, int offset) { * the entry at {@code rhs}. "Better" in this means "lower" for * {@link SortOrder#ASC} and "higher" for {@link SortOrder#DESC}. */ - private boolean betterThan(double lhs, double rhs, float lhsExtra, float rhsExtra) { - int res = Double.compare(lhs, rhs); - if (res != 0) { - return getOrder().reverseMul() * res < 0; - } - res = Float.compare(lhsExtra, rhsExtra); - return getOrder().reverseMul() * res < 0; + private boolean betterThan(double lhs, double rhs) { + return getOrder().reverseMul() * Double.compare(lhs, rhs) < 0; } /** @@ -374,19 +371,13 @@ private void downHeap(long rootIndex, int parent, int heapSize) { int leftChild = parent * 2 + 1; long leftIndex = rootIndex + leftChild; if (leftChild < heapSize) { - if (betterThan(values.get(worstIndex), values.get(leftIndex), extraValues.get(worstIndex), extraValues.get(leftIndex))) { + if (betterThan(values.get(worstIndex), values.get(leftIndex))) { worst = leftChild; worstIndex = leftIndex; } int rightChild = leftChild + 1; long rightIndex = rootIndex + rightChild; - if (rightChild < heapSize - && betterThan( - values.get(worstIndex), - values.get(rightIndex), - extraValues.get(worstIndex), - extraValues.get(rightIndex) - )) { + if (rightChild < heapSize && betterThan(values.get(worstIndex), values.get(rightIndex))) { worst = rightChild; worstIndex = rightIndex; } diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleIntBucketedSort.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleIntBucketedSort.java index 44c51b34c0d39..5d2206ac49b2f 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleIntBucketedSort.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleIntBucketedSort.java @@ -95,7 +95,7 @@ public DoubleIntBucketedSort(BigArrays bigArrays, SortOrder order, int bucketSiz public void collect(double value, int extraValue, int bucket) { long rootIndex = (long) bucket * bucketSize; if (inHeapMode(bucket)) { - if (betterThan(value, values.get(rootIndex), extraValue, extraValues.get(rootIndex))) { + if (betterThan(value, values.get(rootIndex))) { values.set(rootIndex, value); extraValues.set(rootIndex, extraValue); downHeap(rootIndex, 0, bucketSize); @@ -168,8 +168,10 @@ public void merge(int groupId, DoubleIntBucketedSort other, int otherGroupId) { public void toBlocks(BlockFactory blockFactory, Block[] blocks, int offset, IntVector selected) { // Check if the selected groups are all empty, to avoid allocating extra memory if (allSelectedGroupsAreEmpty(selected)) { - blocks[offset] = blockFactory.newConstantNullBlock(selected.getPositionCount()); - blocks[offset + 1] = blockFactory.newConstantNullBlock(selected.getPositionCount()); + Block constantNullBlock = blockFactory.newConstantNullBlock(selected.getPositionCount()); + constantNullBlock.incRef(); + blocks[offset] = constantNullBlock; + blocks[offset + 1] = constantNullBlock; return; } @@ -255,13 +257,8 @@ private void setNextGatherOffset(long rootIndex, int offset) { * the entry at {@code rhs}. "Better" in this means "lower" for * {@link SortOrder#ASC} and "higher" for {@link SortOrder#DESC}. */ - private boolean betterThan(double lhs, double rhs, int lhsExtra, int rhsExtra) { - int res = Double.compare(lhs, rhs); - if (res != 0) { - return getOrder().reverseMul() * res < 0; - } - res = Integer.compare(lhsExtra, rhsExtra); - return getOrder().reverseMul() * res < 0; + private boolean betterThan(double lhs, double rhs) { + return getOrder().reverseMul() * Double.compare(lhs, rhs) < 0; } /** @@ -374,19 +371,13 @@ private void downHeap(long rootIndex, int parent, int heapSize) { int leftChild = parent * 2 + 1; long leftIndex = rootIndex + leftChild; if (leftChild < heapSize) { - if (betterThan(values.get(worstIndex), values.get(leftIndex), extraValues.get(worstIndex), extraValues.get(leftIndex))) { + if (betterThan(values.get(worstIndex), values.get(leftIndex))) { worst = leftChild; worstIndex = leftIndex; } int rightChild = leftChild + 1; long rightIndex = rootIndex + rightChild; - if (rightChild < heapSize - && betterThan( - values.get(worstIndex), - values.get(rightIndex), - extraValues.get(worstIndex), - extraValues.get(rightIndex) - )) { + if (rightChild < heapSize && betterThan(values.get(worstIndex), values.get(rightIndex))) { worst = rightChild; worstIndex = rightIndex; } diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleLongBucketedSort.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleLongBucketedSort.java index 519c03f59f5be..490636a5ee400 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleLongBucketedSort.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleLongBucketedSort.java @@ -95,7 +95,7 @@ public DoubleLongBucketedSort(BigArrays bigArrays, SortOrder order, int bucketSi public void collect(double value, long extraValue, int bucket) { long rootIndex = (long) bucket * bucketSize; if (inHeapMode(bucket)) { - if (betterThan(value, values.get(rootIndex), extraValue, extraValues.get(rootIndex))) { + if (betterThan(value, values.get(rootIndex))) { values.set(rootIndex, value); extraValues.set(rootIndex, extraValue); downHeap(rootIndex, 0, bucketSize); @@ -168,8 +168,10 @@ public void merge(int groupId, DoubleLongBucketedSort other, int otherGroupId) { public void toBlocks(BlockFactory blockFactory, Block[] blocks, int offset, IntVector selected) { // Check if the selected groups are all empty, to avoid allocating extra memory if (allSelectedGroupsAreEmpty(selected)) { - blocks[offset] = blockFactory.newConstantNullBlock(selected.getPositionCount()); - blocks[offset + 1] = blockFactory.newConstantNullBlock(selected.getPositionCount()); + Block constantNullBlock = blockFactory.newConstantNullBlock(selected.getPositionCount()); + constantNullBlock.incRef(); + blocks[offset] = constantNullBlock; + blocks[offset + 1] = constantNullBlock; return; } @@ -255,13 +257,8 @@ private void setNextGatherOffset(long rootIndex, int offset) { * the entry at {@code rhs}. "Better" in this means "lower" for * {@link SortOrder#ASC} and "higher" for {@link SortOrder#DESC}. */ - private boolean betterThan(double lhs, double rhs, long lhsExtra, long rhsExtra) { - int res = Double.compare(lhs, rhs); - if (res != 0) { - return getOrder().reverseMul() * res < 0; - } - res = Long.compare(lhsExtra, rhsExtra); - return getOrder().reverseMul() * res < 0; + private boolean betterThan(double lhs, double rhs) { + return getOrder().reverseMul() * Double.compare(lhs, rhs) < 0; } /** @@ -374,19 +371,13 @@ private void downHeap(long rootIndex, int parent, int heapSize) { int leftChild = parent * 2 + 1; long leftIndex = rootIndex + leftChild; if (leftChild < heapSize) { - if (betterThan(values.get(worstIndex), values.get(leftIndex), extraValues.get(worstIndex), extraValues.get(leftIndex))) { + if (betterThan(values.get(worstIndex), values.get(leftIndex))) { worst = leftChild; worstIndex = leftIndex; } int rightChild = leftChild + 1; long rightIndex = rootIndex + rightChild; - if (rightChild < heapSize - && betterThan( - values.get(worstIndex), - values.get(rightIndex), - extraValues.get(worstIndex), - extraValues.get(rightIndex) - )) { + if (rightChild < heapSize && betterThan(values.get(worstIndex), values.get(rightIndex))) { worst = rightChild; worstIndex = rightIndex; } diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/FloatBucketedSort.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/FloatBucketedSort.java index 5dee9e1555526..44a1938aa8d6b 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/FloatBucketedSort.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/FloatBucketedSort.java @@ -240,8 +240,7 @@ private void setNextGatherOffset(long rootIndex, int offset) { * {@link SortOrder#ASC} and "higher" for {@link SortOrder#DESC}. */ private boolean betterThan(float lhs, float rhs) { - int res = Float.compare(lhs, rhs); - return getOrder().reverseMul() * res < 0; + return getOrder().reverseMul() * Float.compare(lhs, rhs) < 0; } /** diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/FloatDoubleBucketedSort.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/FloatDoubleBucketedSort.java index a09d1e5220046..7bf97f44685ab 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/FloatDoubleBucketedSort.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/FloatDoubleBucketedSort.java @@ -95,7 +95,7 @@ public FloatDoubleBucketedSort(BigArrays bigArrays, SortOrder order, int bucketS public void collect(float value, double extraValue, int bucket) { long rootIndex = (long) bucket * bucketSize; if (inHeapMode(bucket)) { - if (betterThan(value, values.get(rootIndex), extraValue, extraValues.get(rootIndex))) { + if (betterThan(value, values.get(rootIndex))) { values.set(rootIndex, value); extraValues.set(rootIndex, extraValue); downHeap(rootIndex, 0, bucketSize); @@ -168,8 +168,10 @@ public void merge(int groupId, FloatDoubleBucketedSort other, int otherGroupId) public void toBlocks(BlockFactory blockFactory, Block[] blocks, int offset, IntVector selected) { // Check if the selected groups are all empty, to avoid allocating extra memory if (allSelectedGroupsAreEmpty(selected)) { - blocks[offset] = blockFactory.newConstantNullBlock(selected.getPositionCount()); - blocks[offset + 1] = blockFactory.newConstantNullBlock(selected.getPositionCount()); + Block constantNullBlock = blockFactory.newConstantNullBlock(selected.getPositionCount()); + constantNullBlock.incRef(); + blocks[offset] = constantNullBlock; + blocks[offset + 1] = constantNullBlock; return; } @@ -255,13 +257,8 @@ private void setNextGatherOffset(long rootIndex, int offset) { * the entry at {@code rhs}. "Better" in this means "lower" for * {@link SortOrder#ASC} and "higher" for {@link SortOrder#DESC}. */ - private boolean betterThan(float lhs, float rhs, double lhsExtra, double rhsExtra) { - int res = Float.compare(lhs, rhs); - if (res != 0) { - return getOrder().reverseMul() * res < 0; - } - res = Double.compare(lhsExtra, rhsExtra); - return getOrder().reverseMul() * res < 0; + private boolean betterThan(float lhs, float rhs) { + return getOrder().reverseMul() * Float.compare(lhs, rhs) < 0; } /** @@ -374,19 +371,13 @@ private void downHeap(long rootIndex, int parent, int heapSize) { int leftChild = parent * 2 + 1; long leftIndex = rootIndex + leftChild; if (leftChild < heapSize) { - if (betterThan(values.get(worstIndex), values.get(leftIndex), extraValues.get(worstIndex), extraValues.get(leftIndex))) { + if (betterThan(values.get(worstIndex), values.get(leftIndex))) { worst = leftChild; worstIndex = leftIndex; } int rightChild = leftChild + 1; long rightIndex = rootIndex + rightChild; - if (rightChild < heapSize - && betterThan( - values.get(worstIndex), - values.get(rightIndex), - extraValues.get(worstIndex), - extraValues.get(rightIndex) - )) { + if (rightChild < heapSize && betterThan(values.get(worstIndex), values.get(rightIndex))) { worst = rightChild; worstIndex = rightIndex; } diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/FloatFloatBucketedSort.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/FloatFloatBucketedSort.java index f5057a1ec57e5..2701659eac695 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/FloatFloatBucketedSort.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/FloatFloatBucketedSort.java @@ -95,7 +95,7 @@ public FloatFloatBucketedSort(BigArrays bigArrays, SortOrder order, int bucketSi public void collect(float value, float extraValue, int bucket) { long rootIndex = (long) bucket * bucketSize; if (inHeapMode(bucket)) { - if (betterThan(value, values.get(rootIndex), extraValue, extraValues.get(rootIndex))) { + if (betterThan(value, values.get(rootIndex))) { values.set(rootIndex, value); extraValues.set(rootIndex, extraValue); downHeap(rootIndex, 0, bucketSize); @@ -168,8 +168,10 @@ public void merge(int groupId, FloatFloatBucketedSort other, int otherGroupId) { public void toBlocks(BlockFactory blockFactory, Block[] blocks, int offset, IntVector selected) { // Check if the selected groups are all empty, to avoid allocating extra memory if (allSelectedGroupsAreEmpty(selected)) { - blocks[offset] = blockFactory.newConstantNullBlock(selected.getPositionCount()); - blocks[offset + 1] = blockFactory.newConstantNullBlock(selected.getPositionCount()); + Block constantNullBlock = blockFactory.newConstantNullBlock(selected.getPositionCount()); + constantNullBlock.incRef(); + blocks[offset] = constantNullBlock; + blocks[offset + 1] = constantNullBlock; return; } @@ -255,13 +257,8 @@ private void setNextGatherOffset(long rootIndex, int offset) { * the entry at {@code rhs}. "Better" in this means "lower" for * {@link SortOrder#ASC} and "higher" for {@link SortOrder#DESC}. */ - private boolean betterThan(float lhs, float rhs, float lhsExtra, float rhsExtra) { - int res = Float.compare(lhs, rhs); - if (res != 0) { - return getOrder().reverseMul() * res < 0; - } - res = Float.compare(lhsExtra, rhsExtra); - return getOrder().reverseMul() * res < 0; + private boolean betterThan(float lhs, float rhs) { + return getOrder().reverseMul() * Float.compare(lhs, rhs) < 0; } /** @@ -374,19 +371,13 @@ private void downHeap(long rootIndex, int parent, int heapSize) { int leftChild = parent * 2 + 1; long leftIndex = rootIndex + leftChild; if (leftChild < heapSize) { - if (betterThan(values.get(worstIndex), values.get(leftIndex), extraValues.get(worstIndex), extraValues.get(leftIndex))) { + if (betterThan(values.get(worstIndex), values.get(leftIndex))) { worst = leftChild; worstIndex = leftIndex; } int rightChild = leftChild + 1; long rightIndex = rootIndex + rightChild; - if (rightChild < heapSize - && betterThan( - values.get(worstIndex), - values.get(rightIndex), - extraValues.get(worstIndex), - extraValues.get(rightIndex) - )) { + if (rightChild < heapSize && betterThan(values.get(worstIndex), values.get(rightIndex))) { worst = rightChild; worstIndex = rightIndex; } diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/FloatIntBucketedSort.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/FloatIntBucketedSort.java index e8e5b8cc7bf8e..9d8f953143b47 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/FloatIntBucketedSort.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/FloatIntBucketedSort.java @@ -95,7 +95,7 @@ public FloatIntBucketedSort(BigArrays bigArrays, SortOrder order, int bucketSize public void collect(float value, int extraValue, int bucket) { long rootIndex = (long) bucket * bucketSize; if (inHeapMode(bucket)) { - if (betterThan(value, values.get(rootIndex), extraValue, extraValues.get(rootIndex))) { + if (betterThan(value, values.get(rootIndex))) { values.set(rootIndex, value); extraValues.set(rootIndex, extraValue); downHeap(rootIndex, 0, bucketSize); @@ -168,8 +168,10 @@ public void merge(int groupId, FloatIntBucketedSort other, int otherGroupId) { public void toBlocks(BlockFactory blockFactory, Block[] blocks, int offset, IntVector selected) { // Check if the selected groups are all empty, to avoid allocating extra memory if (allSelectedGroupsAreEmpty(selected)) { - blocks[offset] = blockFactory.newConstantNullBlock(selected.getPositionCount()); - blocks[offset + 1] = blockFactory.newConstantNullBlock(selected.getPositionCount()); + Block constantNullBlock = blockFactory.newConstantNullBlock(selected.getPositionCount()); + constantNullBlock.incRef(); + blocks[offset] = constantNullBlock; + blocks[offset + 1] = constantNullBlock; return; } @@ -255,13 +257,8 @@ private void setNextGatherOffset(long rootIndex, int offset) { * the entry at {@code rhs}. "Better" in this means "lower" for * {@link SortOrder#ASC} and "higher" for {@link SortOrder#DESC}. */ - private boolean betterThan(float lhs, float rhs, int lhsExtra, int rhsExtra) { - int res = Float.compare(lhs, rhs); - if (res != 0) { - return getOrder().reverseMul() * res < 0; - } - res = Integer.compare(lhsExtra, rhsExtra); - return getOrder().reverseMul() * res < 0; + private boolean betterThan(float lhs, float rhs) { + return getOrder().reverseMul() * Float.compare(lhs, rhs) < 0; } /** @@ -374,19 +371,13 @@ private void downHeap(long rootIndex, int parent, int heapSize) { int leftChild = parent * 2 + 1; long leftIndex = rootIndex + leftChild; if (leftChild < heapSize) { - if (betterThan(values.get(worstIndex), values.get(leftIndex), extraValues.get(worstIndex), extraValues.get(leftIndex))) { + if (betterThan(values.get(worstIndex), values.get(leftIndex))) { worst = leftChild; worstIndex = leftIndex; } int rightChild = leftChild + 1; long rightIndex = rootIndex + rightChild; - if (rightChild < heapSize - && betterThan( - values.get(worstIndex), - values.get(rightIndex), - extraValues.get(worstIndex), - extraValues.get(rightIndex) - )) { + if (rightChild < heapSize && betterThan(values.get(worstIndex), values.get(rightIndex))) { worst = rightChild; worstIndex = rightIndex; } diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/FloatLongBucketedSort.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/FloatLongBucketedSort.java index dc5813fbd4e35..458d03eedf5ae 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/FloatLongBucketedSort.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/FloatLongBucketedSort.java @@ -95,7 +95,7 @@ public FloatLongBucketedSort(BigArrays bigArrays, SortOrder order, int bucketSiz public void collect(float value, long extraValue, int bucket) { long rootIndex = (long) bucket * bucketSize; if (inHeapMode(bucket)) { - if (betterThan(value, values.get(rootIndex), extraValue, extraValues.get(rootIndex))) { + if (betterThan(value, values.get(rootIndex))) { values.set(rootIndex, value); extraValues.set(rootIndex, extraValue); downHeap(rootIndex, 0, bucketSize); @@ -168,8 +168,10 @@ public void merge(int groupId, FloatLongBucketedSort other, int otherGroupId) { public void toBlocks(BlockFactory blockFactory, Block[] blocks, int offset, IntVector selected) { // Check if the selected groups are all empty, to avoid allocating extra memory if (allSelectedGroupsAreEmpty(selected)) { - blocks[offset] = blockFactory.newConstantNullBlock(selected.getPositionCount()); - blocks[offset + 1] = blockFactory.newConstantNullBlock(selected.getPositionCount()); + Block constantNullBlock = blockFactory.newConstantNullBlock(selected.getPositionCount()); + constantNullBlock.incRef(); + blocks[offset] = constantNullBlock; + blocks[offset + 1] = constantNullBlock; return; } @@ -255,13 +257,8 @@ private void setNextGatherOffset(long rootIndex, int offset) { * the entry at {@code rhs}. "Better" in this means "lower" for * {@link SortOrder#ASC} and "higher" for {@link SortOrder#DESC}. */ - private boolean betterThan(float lhs, float rhs, long lhsExtra, long rhsExtra) { - int res = Float.compare(lhs, rhs); - if (res != 0) { - return getOrder().reverseMul() * res < 0; - } - res = Long.compare(lhsExtra, rhsExtra); - return getOrder().reverseMul() * res < 0; + private boolean betterThan(float lhs, float rhs) { + return getOrder().reverseMul() * Float.compare(lhs, rhs) < 0; } /** @@ -374,19 +371,13 @@ private void downHeap(long rootIndex, int parent, int heapSize) { int leftChild = parent * 2 + 1; long leftIndex = rootIndex + leftChild; if (leftChild < heapSize) { - if (betterThan(values.get(worstIndex), values.get(leftIndex), extraValues.get(worstIndex), extraValues.get(leftIndex))) { + if (betterThan(values.get(worstIndex), values.get(leftIndex))) { worst = leftChild; worstIndex = leftIndex; } int rightChild = leftChild + 1; long rightIndex = rootIndex + rightChild; - if (rightChild < heapSize - && betterThan( - values.get(worstIndex), - values.get(rightIndex), - extraValues.get(worstIndex), - extraValues.get(rightIndex) - )) { + if (rightChild < heapSize && betterThan(values.get(worstIndex), values.get(rightIndex))) { worst = rightChild; worstIndex = rightIndex; } diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/IntBucketedSort.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/IntBucketedSort.java index 7dcec4461f0a5..cca03a0d0e9bc 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/IntBucketedSort.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/IntBucketedSort.java @@ -240,8 +240,7 @@ private void setNextGatherOffset(long rootIndex, int offset) { * {@link SortOrder#ASC} and "higher" for {@link SortOrder#DESC}. */ private boolean betterThan(int lhs, int rhs) { - int res = Integer.compare(lhs, rhs); - return getOrder().reverseMul() * res < 0; + return getOrder().reverseMul() * Integer.compare(lhs, rhs) < 0; } /** diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/IntDoubleBucketedSort.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/IntDoubleBucketedSort.java index 5adbea93cc978..096563f7e5392 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/IntDoubleBucketedSort.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/IntDoubleBucketedSort.java @@ -95,7 +95,7 @@ public IntDoubleBucketedSort(BigArrays bigArrays, SortOrder order, int bucketSiz public void collect(int value, double extraValue, int bucket) { long rootIndex = (long) bucket * bucketSize; if (inHeapMode(bucket)) { - if (betterThan(value, values.get(rootIndex), extraValue, extraValues.get(rootIndex))) { + if (betterThan(value, values.get(rootIndex))) { values.set(rootIndex, value); extraValues.set(rootIndex, extraValue); downHeap(rootIndex, 0, bucketSize); @@ -168,8 +168,10 @@ public void merge(int groupId, IntDoubleBucketedSort other, int otherGroupId) { public void toBlocks(BlockFactory blockFactory, Block[] blocks, int offset, IntVector selected) { // Check if the selected groups are all empty, to avoid allocating extra memory if (allSelectedGroupsAreEmpty(selected)) { - blocks[offset] = blockFactory.newConstantNullBlock(selected.getPositionCount()); - blocks[offset + 1] = blockFactory.newConstantNullBlock(selected.getPositionCount()); + Block constantNullBlock = blockFactory.newConstantNullBlock(selected.getPositionCount()); + constantNullBlock.incRef(); + blocks[offset] = constantNullBlock; + blocks[offset + 1] = constantNullBlock; return; } @@ -255,13 +257,8 @@ private void setNextGatherOffset(long rootIndex, int offset) { * the entry at {@code rhs}. "Better" in this means "lower" for * {@link SortOrder#ASC} and "higher" for {@link SortOrder#DESC}. */ - private boolean betterThan(int lhs, int rhs, double lhsExtra, double rhsExtra) { - int res = Integer.compare(lhs, rhs); - if (res != 0) { - return getOrder().reverseMul() * res < 0; - } - res = Double.compare(lhsExtra, rhsExtra); - return getOrder().reverseMul() * res < 0; + private boolean betterThan(int lhs, int rhs) { + return getOrder().reverseMul() * Integer.compare(lhs, rhs) < 0; } /** @@ -374,19 +371,13 @@ private void downHeap(long rootIndex, int parent, int heapSize) { int leftChild = parent * 2 + 1; long leftIndex = rootIndex + leftChild; if (leftChild < heapSize) { - if (betterThan(values.get(worstIndex), values.get(leftIndex), extraValues.get(worstIndex), extraValues.get(leftIndex))) { + if (betterThan(values.get(worstIndex), values.get(leftIndex))) { worst = leftChild; worstIndex = leftIndex; } int rightChild = leftChild + 1; long rightIndex = rootIndex + rightChild; - if (rightChild < heapSize - && betterThan( - values.get(worstIndex), - values.get(rightIndex), - extraValues.get(worstIndex), - extraValues.get(rightIndex) - )) { + if (rightChild < heapSize && betterThan(values.get(worstIndex), values.get(rightIndex))) { worst = rightChild; worstIndex = rightIndex; } diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/IntFloatBucketedSort.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/IntFloatBucketedSort.java index 5e4d278fa27fc..b7bf1750e28ff 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/IntFloatBucketedSort.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/IntFloatBucketedSort.java @@ -95,7 +95,7 @@ public IntFloatBucketedSort(BigArrays bigArrays, SortOrder order, int bucketSize public void collect(int value, float extraValue, int bucket) { long rootIndex = (long) bucket * bucketSize; if (inHeapMode(bucket)) { - if (betterThan(value, values.get(rootIndex), extraValue, extraValues.get(rootIndex))) { + if (betterThan(value, values.get(rootIndex))) { values.set(rootIndex, value); extraValues.set(rootIndex, extraValue); downHeap(rootIndex, 0, bucketSize); @@ -168,8 +168,10 @@ public void merge(int groupId, IntFloatBucketedSort other, int otherGroupId) { public void toBlocks(BlockFactory blockFactory, Block[] blocks, int offset, IntVector selected) { // Check if the selected groups are all empty, to avoid allocating extra memory if (allSelectedGroupsAreEmpty(selected)) { - blocks[offset] = blockFactory.newConstantNullBlock(selected.getPositionCount()); - blocks[offset + 1] = blockFactory.newConstantNullBlock(selected.getPositionCount()); + Block constantNullBlock = blockFactory.newConstantNullBlock(selected.getPositionCount()); + constantNullBlock.incRef(); + blocks[offset] = constantNullBlock; + blocks[offset + 1] = constantNullBlock; return; } @@ -255,13 +257,8 @@ private void setNextGatherOffset(long rootIndex, int offset) { * the entry at {@code rhs}. "Better" in this means "lower" for * {@link SortOrder#ASC} and "higher" for {@link SortOrder#DESC}. */ - private boolean betterThan(int lhs, int rhs, float lhsExtra, float rhsExtra) { - int res = Integer.compare(lhs, rhs); - if (res != 0) { - return getOrder().reverseMul() * res < 0; - } - res = Float.compare(lhsExtra, rhsExtra); - return getOrder().reverseMul() * res < 0; + private boolean betterThan(int lhs, int rhs) { + return getOrder().reverseMul() * Integer.compare(lhs, rhs) < 0; } /** @@ -374,19 +371,13 @@ private void downHeap(long rootIndex, int parent, int heapSize) { int leftChild = parent * 2 + 1; long leftIndex = rootIndex + leftChild; if (leftChild < heapSize) { - if (betterThan(values.get(worstIndex), values.get(leftIndex), extraValues.get(worstIndex), extraValues.get(leftIndex))) { + if (betterThan(values.get(worstIndex), values.get(leftIndex))) { worst = leftChild; worstIndex = leftIndex; } int rightChild = leftChild + 1; long rightIndex = rootIndex + rightChild; - if (rightChild < heapSize - && betterThan( - values.get(worstIndex), - values.get(rightIndex), - extraValues.get(worstIndex), - extraValues.get(rightIndex) - )) { + if (rightChild < heapSize && betterThan(values.get(worstIndex), values.get(rightIndex))) { worst = rightChild; worstIndex = rightIndex; } diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/IntIntBucketedSort.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/IntIntBucketedSort.java index 0ed8bb94a8022..b561ea656a4cf 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/IntIntBucketedSort.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/IntIntBucketedSort.java @@ -95,7 +95,7 @@ public IntIntBucketedSort(BigArrays bigArrays, SortOrder order, int bucketSize) public void collect(int value, int extraValue, int bucket) { long rootIndex = (long) bucket * bucketSize; if (inHeapMode(bucket)) { - if (betterThan(value, values.get(rootIndex), extraValue, extraValues.get(rootIndex))) { + if (betterThan(value, values.get(rootIndex))) { values.set(rootIndex, value); extraValues.set(rootIndex, extraValue); downHeap(rootIndex, 0, bucketSize); @@ -168,8 +168,10 @@ public void merge(int groupId, IntIntBucketedSort other, int otherGroupId) { public void toBlocks(BlockFactory blockFactory, Block[] blocks, int offset, IntVector selected) { // Check if the selected groups are all empty, to avoid allocating extra memory if (allSelectedGroupsAreEmpty(selected)) { - blocks[offset] = blockFactory.newConstantNullBlock(selected.getPositionCount()); - blocks[offset + 1] = blockFactory.newConstantNullBlock(selected.getPositionCount()); + Block constantNullBlock = blockFactory.newConstantNullBlock(selected.getPositionCount()); + constantNullBlock.incRef(); + blocks[offset] = constantNullBlock; + blocks[offset + 1] = constantNullBlock; return; } @@ -255,13 +257,8 @@ private void setNextGatherOffset(long rootIndex, int offset) { * the entry at {@code rhs}. "Better" in this means "lower" for * {@link SortOrder#ASC} and "higher" for {@link SortOrder#DESC}. */ - private boolean betterThan(int lhs, int rhs, int lhsExtra, int rhsExtra) { - int res = Integer.compare(lhs, rhs); - if (res != 0) { - return getOrder().reverseMul() * res < 0; - } - res = Integer.compare(lhsExtra, rhsExtra); - return getOrder().reverseMul() * res < 0; + private boolean betterThan(int lhs, int rhs) { + return getOrder().reverseMul() * Integer.compare(lhs, rhs) < 0; } /** @@ -374,19 +371,13 @@ private void downHeap(long rootIndex, int parent, int heapSize) { int leftChild = parent * 2 + 1; long leftIndex = rootIndex + leftChild; if (leftChild < heapSize) { - if (betterThan(values.get(worstIndex), values.get(leftIndex), extraValues.get(worstIndex), extraValues.get(leftIndex))) { + if (betterThan(values.get(worstIndex), values.get(leftIndex))) { worst = leftChild; worstIndex = leftIndex; } int rightChild = leftChild + 1; long rightIndex = rootIndex + rightChild; - if (rightChild < heapSize - && betterThan( - values.get(worstIndex), - values.get(rightIndex), - extraValues.get(worstIndex), - extraValues.get(rightIndex) - )) { + if (rightChild < heapSize && betterThan(values.get(worstIndex), values.get(rightIndex))) { worst = rightChild; worstIndex = rightIndex; } diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/IntLongBucketedSort.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/IntLongBucketedSort.java index 7b7d3d3d76be2..7273660887b42 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/IntLongBucketedSort.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/IntLongBucketedSort.java @@ -95,7 +95,7 @@ public IntLongBucketedSort(BigArrays bigArrays, SortOrder order, int bucketSize) public void collect(int value, long extraValue, int bucket) { long rootIndex = (long) bucket * bucketSize; if (inHeapMode(bucket)) { - if (betterThan(value, values.get(rootIndex), extraValue, extraValues.get(rootIndex))) { + if (betterThan(value, values.get(rootIndex))) { values.set(rootIndex, value); extraValues.set(rootIndex, extraValue); downHeap(rootIndex, 0, bucketSize); @@ -168,8 +168,10 @@ public void merge(int groupId, IntLongBucketedSort other, int otherGroupId) { public void toBlocks(BlockFactory blockFactory, Block[] blocks, int offset, IntVector selected) { // Check if the selected groups are all empty, to avoid allocating extra memory if (allSelectedGroupsAreEmpty(selected)) { - blocks[offset] = blockFactory.newConstantNullBlock(selected.getPositionCount()); - blocks[offset + 1] = blockFactory.newConstantNullBlock(selected.getPositionCount()); + Block constantNullBlock = blockFactory.newConstantNullBlock(selected.getPositionCount()); + constantNullBlock.incRef(); + blocks[offset] = constantNullBlock; + blocks[offset + 1] = constantNullBlock; return; } @@ -255,13 +257,8 @@ private void setNextGatherOffset(long rootIndex, int offset) { * the entry at {@code rhs}. "Better" in this means "lower" for * {@link SortOrder#ASC} and "higher" for {@link SortOrder#DESC}. */ - private boolean betterThan(int lhs, int rhs, long lhsExtra, long rhsExtra) { - int res = Integer.compare(lhs, rhs); - if (res != 0) { - return getOrder().reverseMul() * res < 0; - } - res = Long.compare(lhsExtra, rhsExtra); - return getOrder().reverseMul() * res < 0; + private boolean betterThan(int lhs, int rhs) { + return getOrder().reverseMul() * Integer.compare(lhs, rhs) < 0; } /** @@ -374,19 +371,13 @@ private void downHeap(long rootIndex, int parent, int heapSize) { int leftChild = parent * 2 + 1; long leftIndex = rootIndex + leftChild; if (leftChild < heapSize) { - if (betterThan(values.get(worstIndex), values.get(leftIndex), extraValues.get(worstIndex), extraValues.get(leftIndex))) { + if (betterThan(values.get(worstIndex), values.get(leftIndex))) { worst = leftChild; worstIndex = leftIndex; } int rightChild = leftChild + 1; long rightIndex = rootIndex + rightChild; - if (rightChild < heapSize - && betterThan( - values.get(worstIndex), - values.get(rightIndex), - extraValues.get(worstIndex), - extraValues.get(rightIndex) - )) { + if (rightChild < heapSize && betterThan(values.get(worstIndex), values.get(rightIndex))) { worst = rightChild; worstIndex = rightIndex; } diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/LongBucketedSort.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/LongBucketedSort.java index e10ce05017d23..4975d7983bbbe 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/LongBucketedSort.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/LongBucketedSort.java @@ -240,8 +240,7 @@ private void setNextGatherOffset(long rootIndex, int offset) { * {@link SortOrder#ASC} and "higher" for {@link SortOrder#DESC}. */ private boolean betterThan(long lhs, long rhs) { - int res = Long.compare(lhs, rhs); - return getOrder().reverseMul() * res < 0; + return getOrder().reverseMul() * Long.compare(lhs, rhs) < 0; } /** diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/LongDoubleBucketedSort.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/LongDoubleBucketedSort.java index 41f644affe51b..c43444f3c01d3 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/LongDoubleBucketedSort.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/LongDoubleBucketedSort.java @@ -95,7 +95,7 @@ public LongDoubleBucketedSort(BigArrays bigArrays, SortOrder order, int bucketSi public void collect(long value, double extraValue, int bucket) { long rootIndex = (long) bucket * bucketSize; if (inHeapMode(bucket)) { - if (betterThan(value, values.get(rootIndex), extraValue, extraValues.get(rootIndex))) { + if (betterThan(value, values.get(rootIndex))) { values.set(rootIndex, value); extraValues.set(rootIndex, extraValue); downHeap(rootIndex, 0, bucketSize); @@ -168,8 +168,10 @@ public void merge(int groupId, LongDoubleBucketedSort other, int otherGroupId) { public void toBlocks(BlockFactory blockFactory, Block[] blocks, int offset, IntVector selected) { // Check if the selected groups are all empty, to avoid allocating extra memory if (allSelectedGroupsAreEmpty(selected)) { - blocks[offset] = blockFactory.newConstantNullBlock(selected.getPositionCount()); - blocks[offset + 1] = blockFactory.newConstantNullBlock(selected.getPositionCount()); + Block constantNullBlock = blockFactory.newConstantNullBlock(selected.getPositionCount()); + constantNullBlock.incRef(); + blocks[offset] = constantNullBlock; + blocks[offset + 1] = constantNullBlock; return; } @@ -255,13 +257,8 @@ private void setNextGatherOffset(long rootIndex, int offset) { * the entry at {@code rhs}. "Better" in this means "lower" for * {@link SortOrder#ASC} and "higher" for {@link SortOrder#DESC}. */ - private boolean betterThan(long lhs, long rhs, double lhsExtra, double rhsExtra) { - int res = Long.compare(lhs, rhs); - if (res != 0) { - return getOrder().reverseMul() * res < 0; - } - res = Double.compare(lhsExtra, rhsExtra); - return getOrder().reverseMul() * res < 0; + private boolean betterThan(long lhs, long rhs) { + return getOrder().reverseMul() * Long.compare(lhs, rhs) < 0; } /** @@ -374,19 +371,13 @@ private void downHeap(long rootIndex, int parent, int heapSize) { int leftChild = parent * 2 + 1; long leftIndex = rootIndex + leftChild; if (leftChild < heapSize) { - if (betterThan(values.get(worstIndex), values.get(leftIndex), extraValues.get(worstIndex), extraValues.get(leftIndex))) { + if (betterThan(values.get(worstIndex), values.get(leftIndex))) { worst = leftChild; worstIndex = leftIndex; } int rightChild = leftChild + 1; long rightIndex = rootIndex + rightChild; - if (rightChild < heapSize - && betterThan( - values.get(worstIndex), - values.get(rightIndex), - extraValues.get(worstIndex), - extraValues.get(rightIndex) - )) { + if (rightChild < heapSize && betterThan(values.get(worstIndex), values.get(rightIndex))) { worst = rightChild; worstIndex = rightIndex; } diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/LongFloatBucketedSort.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/LongFloatBucketedSort.java index 21428226458ac..a77e6f653a9a4 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/LongFloatBucketedSort.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/LongFloatBucketedSort.java @@ -95,7 +95,7 @@ public LongFloatBucketedSort(BigArrays bigArrays, SortOrder order, int bucketSiz public void collect(long value, float extraValue, int bucket) { long rootIndex = (long) bucket * bucketSize; if (inHeapMode(bucket)) { - if (betterThan(value, values.get(rootIndex), extraValue, extraValues.get(rootIndex))) { + if (betterThan(value, values.get(rootIndex))) { values.set(rootIndex, value); extraValues.set(rootIndex, extraValue); downHeap(rootIndex, 0, bucketSize); @@ -168,8 +168,10 @@ public void merge(int groupId, LongFloatBucketedSort other, int otherGroupId) { public void toBlocks(BlockFactory blockFactory, Block[] blocks, int offset, IntVector selected) { // Check if the selected groups are all empty, to avoid allocating extra memory if (allSelectedGroupsAreEmpty(selected)) { - blocks[offset] = blockFactory.newConstantNullBlock(selected.getPositionCount()); - blocks[offset + 1] = blockFactory.newConstantNullBlock(selected.getPositionCount()); + Block constantNullBlock = blockFactory.newConstantNullBlock(selected.getPositionCount()); + constantNullBlock.incRef(); + blocks[offset] = constantNullBlock; + blocks[offset + 1] = constantNullBlock; return; } @@ -255,13 +257,8 @@ private void setNextGatherOffset(long rootIndex, int offset) { * the entry at {@code rhs}. "Better" in this means "lower" for * {@link SortOrder#ASC} and "higher" for {@link SortOrder#DESC}. */ - private boolean betterThan(long lhs, long rhs, float lhsExtra, float rhsExtra) { - int res = Long.compare(lhs, rhs); - if (res != 0) { - return getOrder().reverseMul() * res < 0; - } - res = Float.compare(lhsExtra, rhsExtra); - return getOrder().reverseMul() * res < 0; + private boolean betterThan(long lhs, long rhs) { + return getOrder().reverseMul() * Long.compare(lhs, rhs) < 0; } /** @@ -374,19 +371,13 @@ private void downHeap(long rootIndex, int parent, int heapSize) { int leftChild = parent * 2 + 1; long leftIndex = rootIndex + leftChild; if (leftChild < heapSize) { - if (betterThan(values.get(worstIndex), values.get(leftIndex), extraValues.get(worstIndex), extraValues.get(leftIndex))) { + if (betterThan(values.get(worstIndex), values.get(leftIndex))) { worst = leftChild; worstIndex = leftIndex; } int rightChild = leftChild + 1; long rightIndex = rootIndex + rightChild; - if (rightChild < heapSize - && betterThan( - values.get(worstIndex), - values.get(rightIndex), - extraValues.get(worstIndex), - extraValues.get(rightIndex) - )) { + if (rightChild < heapSize && betterThan(values.get(worstIndex), values.get(rightIndex))) { worst = rightChild; worstIndex = rightIndex; } diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/LongIntBucketedSort.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/LongIntBucketedSort.java index cfec149bc558f..d3bfbbbcf78df 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/LongIntBucketedSort.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/LongIntBucketedSort.java @@ -95,7 +95,7 @@ public LongIntBucketedSort(BigArrays bigArrays, SortOrder order, int bucketSize) public void collect(long value, int extraValue, int bucket) { long rootIndex = (long) bucket * bucketSize; if (inHeapMode(bucket)) { - if (betterThan(value, values.get(rootIndex), extraValue, extraValues.get(rootIndex))) { + if (betterThan(value, values.get(rootIndex))) { values.set(rootIndex, value); extraValues.set(rootIndex, extraValue); downHeap(rootIndex, 0, bucketSize); @@ -168,8 +168,10 @@ public void merge(int groupId, LongIntBucketedSort other, int otherGroupId) { public void toBlocks(BlockFactory blockFactory, Block[] blocks, int offset, IntVector selected) { // Check if the selected groups are all empty, to avoid allocating extra memory if (allSelectedGroupsAreEmpty(selected)) { - blocks[offset] = blockFactory.newConstantNullBlock(selected.getPositionCount()); - blocks[offset + 1] = blockFactory.newConstantNullBlock(selected.getPositionCount()); + Block constantNullBlock = blockFactory.newConstantNullBlock(selected.getPositionCount()); + constantNullBlock.incRef(); + blocks[offset] = constantNullBlock; + blocks[offset + 1] = constantNullBlock; return; } @@ -255,13 +257,8 @@ private void setNextGatherOffset(long rootIndex, int offset) { * the entry at {@code rhs}. "Better" in this means "lower" for * {@link SortOrder#ASC} and "higher" for {@link SortOrder#DESC}. */ - private boolean betterThan(long lhs, long rhs, int lhsExtra, int rhsExtra) { - int res = Long.compare(lhs, rhs); - if (res != 0) { - return getOrder().reverseMul() * res < 0; - } - res = Integer.compare(lhsExtra, rhsExtra); - return getOrder().reverseMul() * res < 0; + private boolean betterThan(long lhs, long rhs) { + return getOrder().reverseMul() * Long.compare(lhs, rhs) < 0; } /** @@ -374,19 +371,13 @@ private void downHeap(long rootIndex, int parent, int heapSize) { int leftChild = parent * 2 + 1; long leftIndex = rootIndex + leftChild; if (leftChild < heapSize) { - if (betterThan(values.get(worstIndex), values.get(leftIndex), extraValues.get(worstIndex), extraValues.get(leftIndex))) { + if (betterThan(values.get(worstIndex), values.get(leftIndex))) { worst = leftChild; worstIndex = leftIndex; } int rightChild = leftChild + 1; long rightIndex = rootIndex + rightChild; - if (rightChild < heapSize - && betterThan( - values.get(worstIndex), - values.get(rightIndex), - extraValues.get(worstIndex), - extraValues.get(rightIndex) - )) { + if (rightChild < heapSize && betterThan(values.get(worstIndex), values.get(rightIndex))) { worst = rightChild; worstIndex = rightIndex; } diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/LongLongBucketedSort.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/LongLongBucketedSort.java index adef179bd9de6..378ef7785cf9a 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/LongLongBucketedSort.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/LongLongBucketedSort.java @@ -94,7 +94,7 @@ public LongLongBucketedSort(BigArrays bigArrays, SortOrder order, int bucketSize public void collect(long value, long extraValue, int bucket) { long rootIndex = (long) bucket * bucketSize; if (inHeapMode(bucket)) { - if (betterThan(value, values.get(rootIndex), extraValue, extraValues.get(rootIndex))) { + if (betterThan(value, values.get(rootIndex))) { values.set(rootIndex, value); extraValues.set(rootIndex, extraValue); downHeap(rootIndex, 0, bucketSize); @@ -167,8 +167,10 @@ public void merge(int groupId, LongLongBucketedSort other, int otherGroupId) { public void toBlocks(BlockFactory blockFactory, Block[] blocks, int offset, IntVector selected) { // Check if the selected groups are all empty, to avoid allocating extra memory if (allSelectedGroupsAreEmpty(selected)) { - blocks[offset] = blockFactory.newConstantNullBlock(selected.getPositionCount()); - blocks[offset + 1] = blockFactory.newConstantNullBlock(selected.getPositionCount()); + Block constantNullBlock = blockFactory.newConstantNullBlock(selected.getPositionCount()); + constantNullBlock.incRef(); + blocks[offset] = constantNullBlock; + blocks[offset + 1] = constantNullBlock; return; } @@ -254,13 +256,8 @@ private void setNextGatherOffset(long rootIndex, int offset) { * the entry at {@code rhs}. "Better" in this means "lower" for * {@link SortOrder#ASC} and "higher" for {@link SortOrder#DESC}. */ - private boolean betterThan(long lhs, long rhs, long lhsExtra, long rhsExtra) { - int res = Long.compare(lhs, rhs); - if (res != 0) { - return getOrder().reverseMul() * res < 0; - } - res = Long.compare(lhsExtra, rhsExtra); - return getOrder().reverseMul() * res < 0; + private boolean betterThan(long lhs, long rhs) { + return getOrder().reverseMul() * Long.compare(lhs, rhs) < 0; } /** @@ -373,19 +370,13 @@ private void downHeap(long rootIndex, int parent, int heapSize) { int leftChild = parent * 2 + 1; long leftIndex = rootIndex + leftChild; if (leftChild < heapSize) { - if (betterThan(values.get(worstIndex), values.get(leftIndex), extraValues.get(worstIndex), extraValues.get(leftIndex))) { + if (betterThan(values.get(worstIndex), values.get(leftIndex))) { worst = leftChild; worstIndex = leftIndex; } int rightChild = leftChild + 1; long rightIndex = rootIndex + rightChild; - if (rightChild < heapSize - && betterThan( - values.get(worstIndex), - values.get(rightIndex), - extraValues.get(worstIndex), - extraValues.get(rightIndex) - )) { + if (rightChild < heapSize && betterThan(values.get(worstIndex), values.get(rightIndex))) { worst = rightChild; worstIndex = rightIndex; } diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleDoubleAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleDoubleAggregatorFunction.java index f6716250a5d5a..b48d510380f19 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleDoubleAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleDoubleAggregatorFunction.java @@ -24,7 +24,7 @@ public final class TopDoubleDoubleAggregatorFunction implements AggregatorFunction { private static final List INTERMEDIATE_STATE_DESC = List.of( new IntermediateStateDesc("top", ElementType.DOUBLE), - new IntermediateStateDesc("extra", ElementType.DOUBLE) ); + new IntermediateStateDesc("output", ElementType.DOUBLE) ); private final DriverContext driverContext; @@ -72,78 +72,79 @@ public void addRawInput(Page page, BooleanVector mask) { private void addRawInputMasked(Page page, BooleanVector mask) { DoubleBlock vBlock = page.getBlock(channels.get(0)); - DoubleBlock extraBlock = page.getBlock(channels.get(1)); + DoubleBlock outputValueBlock = page.getBlock(channels.get(1)); DoubleVector vVector = vBlock.asVector(); if (vVector == null) { - addRawBlock(vBlock, extraBlock, mask); + addRawBlock(vBlock, outputValueBlock, mask); return; } - DoubleVector extraVector = extraBlock.asVector(); - if (extraVector == null) { - addRawBlock(vBlock, extraBlock, mask); + DoubleVector outputValueVector = outputValueBlock.asVector(); + if (outputValueVector == null) { + addRawBlock(vBlock, outputValueBlock, mask); return; } - addRawVector(vVector, extraVector, mask); + addRawVector(vVector, outputValueVector, mask); } private void addRawInputNotMasked(Page page) { DoubleBlock vBlock = page.getBlock(channels.get(0)); - DoubleBlock extraBlock = page.getBlock(channels.get(1)); + DoubleBlock outputValueBlock = page.getBlock(channels.get(1)); DoubleVector vVector = vBlock.asVector(); if (vVector == null) { - addRawBlock(vBlock, extraBlock); + addRawBlock(vBlock, outputValueBlock); return; } - DoubleVector extraVector = extraBlock.asVector(); - if (extraVector == null) { - addRawBlock(vBlock, extraBlock); + DoubleVector outputValueVector = outputValueBlock.asVector(); + if (outputValueVector == null) { + addRawBlock(vBlock, outputValueBlock); return; } - addRawVector(vVector, extraVector); + addRawVector(vVector, outputValueVector); } - private void addRawVector(DoubleVector vVector, DoubleVector extraVector) { + private void addRawVector(DoubleVector vVector, DoubleVector outputValueVector) { for (int valuesPosition = 0; valuesPosition < vVector.getPositionCount(); valuesPosition++) { double vValue = vVector.getDouble(valuesPosition); - double extraValue = extraVector.getDouble(valuesPosition); - TopDoubleDoubleAggregator.combine(state, vValue, extraValue); + double outputValueValue = outputValueVector.getDouble(valuesPosition); + TopDoubleDoubleAggregator.combine(state, vValue, outputValueValue); } } - private void addRawVector(DoubleVector vVector, DoubleVector extraVector, BooleanVector mask) { + private void addRawVector(DoubleVector vVector, DoubleVector outputValueVector, + BooleanVector mask) { for (int valuesPosition = 0; valuesPosition < vVector.getPositionCount(); valuesPosition++) { if (mask.getBoolean(valuesPosition) == false) { continue; } double vValue = vVector.getDouble(valuesPosition); - double extraValue = extraVector.getDouble(valuesPosition); - TopDoubleDoubleAggregator.combine(state, vValue, extraValue); + double outputValueValue = outputValueVector.getDouble(valuesPosition); + TopDoubleDoubleAggregator.combine(state, vValue, outputValueValue); } } - private void addRawBlock(DoubleBlock vBlock, DoubleBlock extraBlock) { + private void addRawBlock(DoubleBlock vBlock, DoubleBlock outputValueBlock) { for (int p = 0; p < vBlock.getPositionCount(); p++) { if (vBlock.isNull(p)) { continue; } - if (extraBlock.isNull(p)) { + if (outputValueBlock.isNull(p)) { continue; } int vStart = vBlock.getFirstValueIndex(p); int vEnd = vStart + vBlock.getValueCount(p); for (int vOffset = vStart; vOffset < vEnd; vOffset++) { double vValue = vBlock.getDouble(vOffset); - int extraStart = extraBlock.getFirstValueIndex(p); - int extraEnd = extraStart + extraBlock.getValueCount(p); - for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { - double extraValue = extraBlock.getDouble(extraOffset); - TopDoubleDoubleAggregator.combine(state, vValue, extraValue); + int outputValueStart = outputValueBlock.getFirstValueIndex(p); + int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(p); + for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { + double outputValueValue = outputValueBlock.getDouble(outputValueOffset); + TopDoubleDoubleAggregator.combine(state, vValue, outputValueValue); } } } } - private void addRawBlock(DoubleBlock vBlock, DoubleBlock extraBlock, BooleanVector mask) { + private void addRawBlock(DoubleBlock vBlock, DoubleBlock outputValueBlock, BooleanVector mask) { for (int p = 0; p < vBlock.getPositionCount(); p++) { if (mask.getBoolean(p) == false) { continue; @@ -151,18 +152,18 @@ private void addRawBlock(DoubleBlock vBlock, DoubleBlock extraBlock, BooleanVect if (vBlock.isNull(p)) { continue; } - if (extraBlock.isNull(p)) { + if (outputValueBlock.isNull(p)) { continue; } int vStart = vBlock.getFirstValueIndex(p); int vEnd = vStart + vBlock.getValueCount(p); for (int vOffset = vStart; vOffset < vEnd; vOffset++) { double vValue = vBlock.getDouble(vOffset); - int extraStart = extraBlock.getFirstValueIndex(p); - int extraEnd = extraStart + extraBlock.getValueCount(p); - for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { - double extraValue = extraBlock.getDouble(extraOffset); - TopDoubleDoubleAggregator.combine(state, vValue, extraValue); + int outputValueStart = outputValueBlock.getFirstValueIndex(p); + int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(p); + for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { + double outputValueValue = outputValueBlock.getDouble(outputValueOffset); + TopDoubleDoubleAggregator.combine(state, vValue, outputValueValue); } } } @@ -178,13 +179,13 @@ public void addIntermediateInput(Page page) { } DoubleBlock top = (DoubleBlock) topUncast; assert top.getPositionCount() == 1; - Block extraUncast = page.getBlock(channels.get(1)); - if (extraUncast.areAllValuesNull()) { + Block outputUncast = page.getBlock(channels.get(1)); + if (outputUncast.areAllValuesNull()) { return; } - DoubleBlock extra = (DoubleBlock) extraUncast; - assert extra.getPositionCount() == 1; - TopDoubleDoubleAggregator.combineIntermediate(state, top, extra); + DoubleBlock output = (DoubleBlock) outputUncast; + assert output.getPositionCount() == 1; + TopDoubleDoubleAggregator.combineIntermediate(state, top, output); } @Override diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleDoubleGroupingAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleDoubleGroupingAggregatorFunction.java index 42bd15d5a2f69..210ad4e23a6e1 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleDoubleGroupingAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleDoubleGroupingAggregatorFunction.java @@ -26,7 +26,7 @@ public final class TopDoubleDoubleGroupingAggregatorFunction implements GroupingAggregatorFunction { private static final List INTERMEDIATE_STATE_DESC = List.of( new IntermediateStateDesc("top", ElementType.DOUBLE), - new IntermediateStateDesc("extra", ElementType.DOUBLE) ); + new IntermediateStateDesc("output", ElementType.DOUBLE) ); private final TopDoubleDoubleAggregator.GroupingState state; @@ -66,24 +66,24 @@ public int intermediateBlockCount() { public GroupingAggregatorFunction.AddInput prepareProcessRawInputPage(SeenGroupIds seenGroupIds, Page page) { DoubleBlock vBlock = page.getBlock(channels.get(0)); - DoubleBlock extraBlock = page.getBlock(channels.get(1)); + DoubleBlock outputValueBlock = page.getBlock(channels.get(1)); DoubleVector vVector = vBlock.asVector(); if (vVector == null) { - maybeEnableGroupIdTracking(seenGroupIds, vBlock, extraBlock); + maybeEnableGroupIdTracking(seenGroupIds, vBlock, outputValueBlock); return new GroupingAggregatorFunction.AddInput() { @Override public void add(int positionOffset, IntArrayBlock groupIds) { - addRawInput(positionOffset, groupIds, vBlock, extraBlock); + addRawInput(positionOffset, groupIds, vBlock, outputValueBlock); } @Override public void add(int positionOffset, IntBigArrayBlock groupIds) { - addRawInput(positionOffset, groupIds, vBlock, extraBlock); + addRawInput(positionOffset, groupIds, vBlock, outputValueBlock); } @Override public void add(int positionOffset, IntVector groupIds) { - addRawInput(positionOffset, groupIds, vBlock, extraBlock); + addRawInput(positionOffset, groupIds, vBlock, outputValueBlock); } @Override @@ -91,23 +91,23 @@ public void close() { } }; } - DoubleVector extraVector = extraBlock.asVector(); - if (extraVector == null) { - maybeEnableGroupIdTracking(seenGroupIds, vBlock, extraBlock); + DoubleVector outputValueVector = outputValueBlock.asVector(); + if (outputValueVector == null) { + maybeEnableGroupIdTracking(seenGroupIds, vBlock, outputValueBlock); return new GroupingAggregatorFunction.AddInput() { @Override public void add(int positionOffset, IntArrayBlock groupIds) { - addRawInput(positionOffset, groupIds, vBlock, extraBlock); + addRawInput(positionOffset, groupIds, vBlock, outputValueBlock); } @Override public void add(int positionOffset, IntBigArrayBlock groupIds) { - addRawInput(positionOffset, groupIds, vBlock, extraBlock); + addRawInput(positionOffset, groupIds, vBlock, outputValueBlock); } @Override public void add(int positionOffset, IntVector groupIds) { - addRawInput(positionOffset, groupIds, vBlock, extraBlock); + addRawInput(positionOffset, groupIds, vBlock, outputValueBlock); } @Override @@ -118,17 +118,17 @@ public void close() { return new GroupingAggregatorFunction.AddInput() { @Override public void add(int positionOffset, IntArrayBlock groupIds) { - addRawInput(positionOffset, groupIds, vVector, extraVector); + addRawInput(positionOffset, groupIds, vVector, outputValueVector); } @Override public void add(int positionOffset, IntBigArrayBlock groupIds) { - addRawInput(positionOffset, groupIds, vVector, extraVector); + addRawInput(positionOffset, groupIds, vVector, outputValueVector); } @Override public void add(int positionOffset, IntVector groupIds) { - addRawInput(positionOffset, groupIds, vVector, extraVector); + addRawInput(positionOffset, groupIds, vVector, outputValueVector); } @Override @@ -138,7 +138,7 @@ public void close() { } private void addRawInput(int positionOffset, IntArrayBlock groups, DoubleBlock vBlock, - DoubleBlock extraBlock) { + DoubleBlock outputValueBlock) { for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { if (groups.isNull(groupPosition)) { continue; @@ -147,7 +147,7 @@ private void addRawInput(int positionOffset, IntArrayBlock groups, DoubleBlock v if (vBlock.isNull(valuesPosition)) { continue; } - if (extraBlock.isNull(valuesPosition)) { + if (outputValueBlock.isNull(valuesPosition)) { continue; } int groupStart = groups.getFirstValueIndex(groupPosition); @@ -158,11 +158,11 @@ private void addRawInput(int positionOffset, IntArrayBlock groups, DoubleBlock v int vEnd = vStart + vBlock.getValueCount(valuesPosition); for (int vOffset = vStart; vOffset < vEnd; vOffset++) { double vValue = vBlock.getDouble(vOffset); - int extraStart = extraBlock.getFirstValueIndex(valuesPosition); - int extraEnd = extraStart + extraBlock.getValueCount(valuesPosition); - for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { - double extraValue = extraBlock.getDouble(extraOffset); - TopDoubleDoubleAggregator.combine(state, groupId, vValue, extraValue); + int outputValueStart = outputValueBlock.getFirstValueIndex(valuesPosition); + int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(valuesPosition); + for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { + double outputValueValue = outputValueBlock.getDouble(outputValueOffset); + TopDoubleDoubleAggregator.combine(state, groupId, vValue, outputValueValue); } } } @@ -170,7 +170,7 @@ private void addRawInput(int positionOffset, IntArrayBlock groups, DoubleBlock v } private void addRawInput(int positionOffset, IntArrayBlock groups, DoubleVector vVector, - DoubleVector extraVector) { + DoubleVector outputValueVector) { for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { if (groups.isNull(groupPosition)) { continue; @@ -181,8 +181,8 @@ private void addRawInput(int positionOffset, IntArrayBlock groups, DoubleVector for (int g = groupStart; g < groupEnd; g++) { int groupId = groups.getInt(g); double vValue = vVector.getDouble(valuesPosition); - double extraValue = extraVector.getDouble(valuesPosition); - TopDoubleDoubleAggregator.combine(state, groupId, vValue, extraValue); + double outputValueValue = outputValueVector.getDouble(valuesPosition); + TopDoubleDoubleAggregator.combine(state, groupId, vValue, outputValueValue); } } } @@ -196,12 +196,12 @@ public void addIntermediateInput(int positionOffset, IntArrayBlock groups, Page return; } DoubleBlock top = (DoubleBlock) topUncast; - Block extraUncast = page.getBlock(channels.get(1)); - if (extraUncast.areAllValuesNull()) { + Block outputUncast = page.getBlock(channels.get(1)); + if (outputUncast.areAllValuesNull()) { return; } - DoubleBlock extra = (DoubleBlock) extraUncast; - assert top.getPositionCount() == extra.getPositionCount(); + DoubleBlock output = (DoubleBlock) outputUncast; + assert top.getPositionCount() == output.getPositionCount(); for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { if (groups.isNull(groupPosition)) { continue; @@ -211,13 +211,13 @@ public void addIntermediateInput(int positionOffset, IntArrayBlock groups, Page for (int g = groupStart; g < groupEnd; g++) { int groupId = groups.getInt(g); int valuesPosition = groupPosition + positionOffset; - TopDoubleDoubleAggregator.combineIntermediate(state, groupId, top, extra, valuesPosition); + TopDoubleDoubleAggregator.combineIntermediate(state, groupId, top, output, valuesPosition); } } } private void addRawInput(int positionOffset, IntBigArrayBlock groups, DoubleBlock vBlock, - DoubleBlock extraBlock) { + DoubleBlock outputValueBlock) { for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { if (groups.isNull(groupPosition)) { continue; @@ -226,7 +226,7 @@ private void addRawInput(int positionOffset, IntBigArrayBlock groups, DoubleBloc if (vBlock.isNull(valuesPosition)) { continue; } - if (extraBlock.isNull(valuesPosition)) { + if (outputValueBlock.isNull(valuesPosition)) { continue; } int groupStart = groups.getFirstValueIndex(groupPosition); @@ -237,11 +237,11 @@ private void addRawInput(int positionOffset, IntBigArrayBlock groups, DoubleBloc int vEnd = vStart + vBlock.getValueCount(valuesPosition); for (int vOffset = vStart; vOffset < vEnd; vOffset++) { double vValue = vBlock.getDouble(vOffset); - int extraStart = extraBlock.getFirstValueIndex(valuesPosition); - int extraEnd = extraStart + extraBlock.getValueCount(valuesPosition); - for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { - double extraValue = extraBlock.getDouble(extraOffset); - TopDoubleDoubleAggregator.combine(state, groupId, vValue, extraValue); + int outputValueStart = outputValueBlock.getFirstValueIndex(valuesPosition); + int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(valuesPosition); + for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { + double outputValueValue = outputValueBlock.getDouble(outputValueOffset); + TopDoubleDoubleAggregator.combine(state, groupId, vValue, outputValueValue); } } } @@ -249,7 +249,7 @@ private void addRawInput(int positionOffset, IntBigArrayBlock groups, DoubleBloc } private void addRawInput(int positionOffset, IntBigArrayBlock groups, DoubleVector vVector, - DoubleVector extraVector) { + DoubleVector outputValueVector) { for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { if (groups.isNull(groupPosition)) { continue; @@ -260,8 +260,8 @@ private void addRawInput(int positionOffset, IntBigArrayBlock groups, DoubleVect for (int g = groupStart; g < groupEnd; g++) { int groupId = groups.getInt(g); double vValue = vVector.getDouble(valuesPosition); - double extraValue = extraVector.getDouble(valuesPosition); - TopDoubleDoubleAggregator.combine(state, groupId, vValue, extraValue); + double outputValueValue = outputValueVector.getDouble(valuesPosition); + TopDoubleDoubleAggregator.combine(state, groupId, vValue, outputValueValue); } } } @@ -275,12 +275,12 @@ public void addIntermediateInput(int positionOffset, IntBigArrayBlock groups, Pa return; } DoubleBlock top = (DoubleBlock) topUncast; - Block extraUncast = page.getBlock(channels.get(1)); - if (extraUncast.areAllValuesNull()) { + Block outputUncast = page.getBlock(channels.get(1)); + if (outputUncast.areAllValuesNull()) { return; } - DoubleBlock extra = (DoubleBlock) extraUncast; - assert top.getPositionCount() == extra.getPositionCount(); + DoubleBlock output = (DoubleBlock) outputUncast; + assert top.getPositionCount() == output.getPositionCount(); for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { if (groups.isNull(groupPosition)) { continue; @@ -290,19 +290,19 @@ public void addIntermediateInput(int positionOffset, IntBigArrayBlock groups, Pa for (int g = groupStart; g < groupEnd; g++) { int groupId = groups.getInt(g); int valuesPosition = groupPosition + positionOffset; - TopDoubleDoubleAggregator.combineIntermediate(state, groupId, top, extra, valuesPosition); + TopDoubleDoubleAggregator.combineIntermediate(state, groupId, top, output, valuesPosition); } } } private void addRawInput(int positionOffset, IntVector groups, DoubleBlock vBlock, - DoubleBlock extraBlock) { + DoubleBlock outputValueBlock) { for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { int valuesPosition = groupPosition + positionOffset; if (vBlock.isNull(valuesPosition)) { continue; } - if (extraBlock.isNull(valuesPosition)) { + if (outputValueBlock.isNull(valuesPosition)) { continue; } int groupId = groups.getInt(groupPosition); @@ -310,24 +310,24 @@ private void addRawInput(int positionOffset, IntVector groups, DoubleBlock vBloc int vEnd = vStart + vBlock.getValueCount(valuesPosition); for (int vOffset = vStart; vOffset < vEnd; vOffset++) { double vValue = vBlock.getDouble(vOffset); - int extraStart = extraBlock.getFirstValueIndex(valuesPosition); - int extraEnd = extraStart + extraBlock.getValueCount(valuesPosition); - for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { - double extraValue = extraBlock.getDouble(extraOffset); - TopDoubleDoubleAggregator.combine(state, groupId, vValue, extraValue); + int outputValueStart = outputValueBlock.getFirstValueIndex(valuesPosition); + int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(valuesPosition); + for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { + double outputValueValue = outputValueBlock.getDouble(outputValueOffset); + TopDoubleDoubleAggregator.combine(state, groupId, vValue, outputValueValue); } } } } private void addRawInput(int positionOffset, IntVector groups, DoubleVector vVector, - DoubleVector extraVector) { + DoubleVector outputValueVector) { for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { int valuesPosition = groupPosition + positionOffset; int groupId = groups.getInt(groupPosition); double vValue = vVector.getDouble(valuesPosition); - double extraValue = extraVector.getDouble(valuesPosition); - TopDoubleDoubleAggregator.combine(state, groupId, vValue, extraValue); + double outputValueValue = outputValueVector.getDouble(valuesPosition); + TopDoubleDoubleAggregator.combine(state, groupId, vValue, outputValueValue); } } @@ -340,25 +340,25 @@ public void addIntermediateInput(int positionOffset, IntVector groups, Page page return; } DoubleBlock top = (DoubleBlock) topUncast; - Block extraUncast = page.getBlock(channels.get(1)); - if (extraUncast.areAllValuesNull()) { + Block outputUncast = page.getBlock(channels.get(1)); + if (outputUncast.areAllValuesNull()) { return; } - DoubleBlock extra = (DoubleBlock) extraUncast; - assert top.getPositionCount() == extra.getPositionCount(); + DoubleBlock output = (DoubleBlock) outputUncast; + assert top.getPositionCount() == output.getPositionCount(); for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { int groupId = groups.getInt(groupPosition); int valuesPosition = groupPosition + positionOffset; - TopDoubleDoubleAggregator.combineIntermediate(state, groupId, top, extra, valuesPosition); + TopDoubleDoubleAggregator.combineIntermediate(state, groupId, top, output, valuesPosition); } } private void maybeEnableGroupIdTracking(SeenGroupIds seenGroupIds, DoubleBlock vBlock, - DoubleBlock extraBlock) { + DoubleBlock outputValueBlock) { if (vBlock.mayHaveNulls()) { state.enableGroupIdTracking(seenGroupIds); } - if (extraBlock.mayHaveNulls()) { + if (outputValueBlock.mayHaveNulls()) { state.enableGroupIdTracking(seenGroupIds); } } diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleFloatAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleFloatAggregatorFunction.java index d68e1929a906b..40d426edd77c3 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleFloatAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleFloatAggregatorFunction.java @@ -26,7 +26,7 @@ public final class TopDoubleFloatAggregatorFunction implements AggregatorFunction { private static final List INTERMEDIATE_STATE_DESC = List.of( new IntermediateStateDesc("top", ElementType.DOUBLE), - new IntermediateStateDesc("extra", ElementType.FLOAT) ); + new IntermediateStateDesc("output", ElementType.FLOAT) ); private final DriverContext driverContext; @@ -74,78 +74,79 @@ public void addRawInput(Page page, BooleanVector mask) { private void addRawInputMasked(Page page, BooleanVector mask) { DoubleBlock vBlock = page.getBlock(channels.get(0)); - FloatBlock extraBlock = page.getBlock(channels.get(1)); + FloatBlock outputValueBlock = page.getBlock(channels.get(1)); DoubleVector vVector = vBlock.asVector(); if (vVector == null) { - addRawBlock(vBlock, extraBlock, mask); + addRawBlock(vBlock, outputValueBlock, mask); return; } - FloatVector extraVector = extraBlock.asVector(); - if (extraVector == null) { - addRawBlock(vBlock, extraBlock, mask); + FloatVector outputValueVector = outputValueBlock.asVector(); + if (outputValueVector == null) { + addRawBlock(vBlock, outputValueBlock, mask); return; } - addRawVector(vVector, extraVector, mask); + addRawVector(vVector, outputValueVector, mask); } private void addRawInputNotMasked(Page page) { DoubleBlock vBlock = page.getBlock(channels.get(0)); - FloatBlock extraBlock = page.getBlock(channels.get(1)); + FloatBlock outputValueBlock = page.getBlock(channels.get(1)); DoubleVector vVector = vBlock.asVector(); if (vVector == null) { - addRawBlock(vBlock, extraBlock); + addRawBlock(vBlock, outputValueBlock); return; } - FloatVector extraVector = extraBlock.asVector(); - if (extraVector == null) { - addRawBlock(vBlock, extraBlock); + FloatVector outputValueVector = outputValueBlock.asVector(); + if (outputValueVector == null) { + addRawBlock(vBlock, outputValueBlock); return; } - addRawVector(vVector, extraVector); + addRawVector(vVector, outputValueVector); } - private void addRawVector(DoubleVector vVector, FloatVector extraVector) { + private void addRawVector(DoubleVector vVector, FloatVector outputValueVector) { for (int valuesPosition = 0; valuesPosition < vVector.getPositionCount(); valuesPosition++) { double vValue = vVector.getDouble(valuesPosition); - float extraValue = extraVector.getFloat(valuesPosition); - TopDoubleFloatAggregator.combine(state, vValue, extraValue); + float outputValueValue = outputValueVector.getFloat(valuesPosition); + TopDoubleFloatAggregator.combine(state, vValue, outputValueValue); } } - private void addRawVector(DoubleVector vVector, FloatVector extraVector, BooleanVector mask) { + private void addRawVector(DoubleVector vVector, FloatVector outputValueVector, + BooleanVector mask) { for (int valuesPosition = 0; valuesPosition < vVector.getPositionCount(); valuesPosition++) { if (mask.getBoolean(valuesPosition) == false) { continue; } double vValue = vVector.getDouble(valuesPosition); - float extraValue = extraVector.getFloat(valuesPosition); - TopDoubleFloatAggregator.combine(state, vValue, extraValue); + float outputValueValue = outputValueVector.getFloat(valuesPosition); + TopDoubleFloatAggregator.combine(state, vValue, outputValueValue); } } - private void addRawBlock(DoubleBlock vBlock, FloatBlock extraBlock) { + private void addRawBlock(DoubleBlock vBlock, FloatBlock outputValueBlock) { for (int p = 0; p < vBlock.getPositionCount(); p++) { if (vBlock.isNull(p)) { continue; } - if (extraBlock.isNull(p)) { + if (outputValueBlock.isNull(p)) { continue; } int vStart = vBlock.getFirstValueIndex(p); int vEnd = vStart + vBlock.getValueCount(p); for (int vOffset = vStart; vOffset < vEnd; vOffset++) { double vValue = vBlock.getDouble(vOffset); - int extraStart = extraBlock.getFirstValueIndex(p); - int extraEnd = extraStart + extraBlock.getValueCount(p); - for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { - float extraValue = extraBlock.getFloat(extraOffset); - TopDoubleFloatAggregator.combine(state, vValue, extraValue); + int outputValueStart = outputValueBlock.getFirstValueIndex(p); + int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(p); + for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { + float outputValueValue = outputValueBlock.getFloat(outputValueOffset); + TopDoubleFloatAggregator.combine(state, vValue, outputValueValue); } } } } - private void addRawBlock(DoubleBlock vBlock, FloatBlock extraBlock, BooleanVector mask) { + private void addRawBlock(DoubleBlock vBlock, FloatBlock outputValueBlock, BooleanVector mask) { for (int p = 0; p < vBlock.getPositionCount(); p++) { if (mask.getBoolean(p) == false) { continue; @@ -153,18 +154,18 @@ private void addRawBlock(DoubleBlock vBlock, FloatBlock extraBlock, BooleanVecto if (vBlock.isNull(p)) { continue; } - if (extraBlock.isNull(p)) { + if (outputValueBlock.isNull(p)) { continue; } int vStart = vBlock.getFirstValueIndex(p); int vEnd = vStart + vBlock.getValueCount(p); for (int vOffset = vStart; vOffset < vEnd; vOffset++) { double vValue = vBlock.getDouble(vOffset); - int extraStart = extraBlock.getFirstValueIndex(p); - int extraEnd = extraStart + extraBlock.getValueCount(p); - for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { - float extraValue = extraBlock.getFloat(extraOffset); - TopDoubleFloatAggregator.combine(state, vValue, extraValue); + int outputValueStart = outputValueBlock.getFirstValueIndex(p); + int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(p); + for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { + float outputValueValue = outputValueBlock.getFloat(outputValueOffset); + TopDoubleFloatAggregator.combine(state, vValue, outputValueValue); } } } @@ -180,13 +181,13 @@ public void addIntermediateInput(Page page) { } DoubleBlock top = (DoubleBlock) topUncast; assert top.getPositionCount() == 1; - Block extraUncast = page.getBlock(channels.get(1)); - if (extraUncast.areAllValuesNull()) { + Block outputUncast = page.getBlock(channels.get(1)); + if (outputUncast.areAllValuesNull()) { return; } - FloatBlock extra = (FloatBlock) extraUncast; - assert extra.getPositionCount() == 1; - TopDoubleFloatAggregator.combineIntermediate(state, top, extra); + FloatBlock output = (FloatBlock) outputUncast; + assert output.getPositionCount() == 1; + TopDoubleFloatAggregator.combineIntermediate(state, top, output); } @Override diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleFloatGroupingAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleFloatGroupingAggregatorFunction.java index 7eb2ece1b1406..e3bb5b23405d6 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleFloatGroupingAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleFloatGroupingAggregatorFunction.java @@ -28,7 +28,7 @@ public final class TopDoubleFloatGroupingAggregatorFunction implements GroupingAggregatorFunction { private static final List INTERMEDIATE_STATE_DESC = List.of( new IntermediateStateDesc("top", ElementType.DOUBLE), - new IntermediateStateDesc("extra", ElementType.FLOAT) ); + new IntermediateStateDesc("output", ElementType.FLOAT) ); private final TopDoubleFloatAggregator.GroupingState state; @@ -68,24 +68,24 @@ public int intermediateBlockCount() { public GroupingAggregatorFunction.AddInput prepareProcessRawInputPage(SeenGroupIds seenGroupIds, Page page) { DoubleBlock vBlock = page.getBlock(channels.get(0)); - FloatBlock extraBlock = page.getBlock(channels.get(1)); + FloatBlock outputValueBlock = page.getBlock(channels.get(1)); DoubleVector vVector = vBlock.asVector(); if (vVector == null) { - maybeEnableGroupIdTracking(seenGroupIds, vBlock, extraBlock); + maybeEnableGroupIdTracking(seenGroupIds, vBlock, outputValueBlock); return new GroupingAggregatorFunction.AddInput() { @Override public void add(int positionOffset, IntArrayBlock groupIds) { - addRawInput(positionOffset, groupIds, vBlock, extraBlock); + addRawInput(positionOffset, groupIds, vBlock, outputValueBlock); } @Override public void add(int positionOffset, IntBigArrayBlock groupIds) { - addRawInput(positionOffset, groupIds, vBlock, extraBlock); + addRawInput(positionOffset, groupIds, vBlock, outputValueBlock); } @Override public void add(int positionOffset, IntVector groupIds) { - addRawInput(positionOffset, groupIds, vBlock, extraBlock); + addRawInput(positionOffset, groupIds, vBlock, outputValueBlock); } @Override @@ -93,23 +93,23 @@ public void close() { } }; } - FloatVector extraVector = extraBlock.asVector(); - if (extraVector == null) { - maybeEnableGroupIdTracking(seenGroupIds, vBlock, extraBlock); + FloatVector outputValueVector = outputValueBlock.asVector(); + if (outputValueVector == null) { + maybeEnableGroupIdTracking(seenGroupIds, vBlock, outputValueBlock); return new GroupingAggregatorFunction.AddInput() { @Override public void add(int positionOffset, IntArrayBlock groupIds) { - addRawInput(positionOffset, groupIds, vBlock, extraBlock); + addRawInput(positionOffset, groupIds, vBlock, outputValueBlock); } @Override public void add(int positionOffset, IntBigArrayBlock groupIds) { - addRawInput(positionOffset, groupIds, vBlock, extraBlock); + addRawInput(positionOffset, groupIds, vBlock, outputValueBlock); } @Override public void add(int positionOffset, IntVector groupIds) { - addRawInput(positionOffset, groupIds, vBlock, extraBlock); + addRawInput(positionOffset, groupIds, vBlock, outputValueBlock); } @Override @@ -120,17 +120,17 @@ public void close() { return new GroupingAggregatorFunction.AddInput() { @Override public void add(int positionOffset, IntArrayBlock groupIds) { - addRawInput(positionOffset, groupIds, vVector, extraVector); + addRawInput(positionOffset, groupIds, vVector, outputValueVector); } @Override public void add(int positionOffset, IntBigArrayBlock groupIds) { - addRawInput(positionOffset, groupIds, vVector, extraVector); + addRawInput(positionOffset, groupIds, vVector, outputValueVector); } @Override public void add(int positionOffset, IntVector groupIds) { - addRawInput(positionOffset, groupIds, vVector, extraVector); + addRawInput(positionOffset, groupIds, vVector, outputValueVector); } @Override @@ -140,7 +140,7 @@ public void close() { } private void addRawInput(int positionOffset, IntArrayBlock groups, DoubleBlock vBlock, - FloatBlock extraBlock) { + FloatBlock outputValueBlock) { for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { if (groups.isNull(groupPosition)) { continue; @@ -149,7 +149,7 @@ private void addRawInput(int positionOffset, IntArrayBlock groups, DoubleBlock v if (vBlock.isNull(valuesPosition)) { continue; } - if (extraBlock.isNull(valuesPosition)) { + if (outputValueBlock.isNull(valuesPosition)) { continue; } int groupStart = groups.getFirstValueIndex(groupPosition); @@ -160,11 +160,11 @@ private void addRawInput(int positionOffset, IntArrayBlock groups, DoubleBlock v int vEnd = vStart + vBlock.getValueCount(valuesPosition); for (int vOffset = vStart; vOffset < vEnd; vOffset++) { double vValue = vBlock.getDouble(vOffset); - int extraStart = extraBlock.getFirstValueIndex(valuesPosition); - int extraEnd = extraStart + extraBlock.getValueCount(valuesPosition); - for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { - float extraValue = extraBlock.getFloat(extraOffset); - TopDoubleFloatAggregator.combine(state, groupId, vValue, extraValue); + int outputValueStart = outputValueBlock.getFirstValueIndex(valuesPosition); + int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(valuesPosition); + for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { + float outputValueValue = outputValueBlock.getFloat(outputValueOffset); + TopDoubleFloatAggregator.combine(state, groupId, vValue, outputValueValue); } } } @@ -172,7 +172,7 @@ private void addRawInput(int positionOffset, IntArrayBlock groups, DoubleBlock v } private void addRawInput(int positionOffset, IntArrayBlock groups, DoubleVector vVector, - FloatVector extraVector) { + FloatVector outputValueVector) { for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { if (groups.isNull(groupPosition)) { continue; @@ -183,8 +183,8 @@ private void addRawInput(int positionOffset, IntArrayBlock groups, DoubleVector for (int g = groupStart; g < groupEnd; g++) { int groupId = groups.getInt(g); double vValue = vVector.getDouble(valuesPosition); - float extraValue = extraVector.getFloat(valuesPosition); - TopDoubleFloatAggregator.combine(state, groupId, vValue, extraValue); + float outputValueValue = outputValueVector.getFloat(valuesPosition); + TopDoubleFloatAggregator.combine(state, groupId, vValue, outputValueValue); } } } @@ -198,12 +198,12 @@ public void addIntermediateInput(int positionOffset, IntArrayBlock groups, Page return; } DoubleBlock top = (DoubleBlock) topUncast; - Block extraUncast = page.getBlock(channels.get(1)); - if (extraUncast.areAllValuesNull()) { + Block outputUncast = page.getBlock(channels.get(1)); + if (outputUncast.areAllValuesNull()) { return; } - FloatBlock extra = (FloatBlock) extraUncast; - assert top.getPositionCount() == extra.getPositionCount(); + FloatBlock output = (FloatBlock) outputUncast; + assert top.getPositionCount() == output.getPositionCount(); for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { if (groups.isNull(groupPosition)) { continue; @@ -213,13 +213,13 @@ public void addIntermediateInput(int positionOffset, IntArrayBlock groups, Page for (int g = groupStart; g < groupEnd; g++) { int groupId = groups.getInt(g); int valuesPosition = groupPosition + positionOffset; - TopDoubleFloatAggregator.combineIntermediate(state, groupId, top, extra, valuesPosition); + TopDoubleFloatAggregator.combineIntermediate(state, groupId, top, output, valuesPosition); } } } private void addRawInput(int positionOffset, IntBigArrayBlock groups, DoubleBlock vBlock, - FloatBlock extraBlock) { + FloatBlock outputValueBlock) { for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { if (groups.isNull(groupPosition)) { continue; @@ -228,7 +228,7 @@ private void addRawInput(int positionOffset, IntBigArrayBlock groups, DoubleBloc if (vBlock.isNull(valuesPosition)) { continue; } - if (extraBlock.isNull(valuesPosition)) { + if (outputValueBlock.isNull(valuesPosition)) { continue; } int groupStart = groups.getFirstValueIndex(groupPosition); @@ -239,11 +239,11 @@ private void addRawInput(int positionOffset, IntBigArrayBlock groups, DoubleBloc int vEnd = vStart + vBlock.getValueCount(valuesPosition); for (int vOffset = vStart; vOffset < vEnd; vOffset++) { double vValue = vBlock.getDouble(vOffset); - int extraStart = extraBlock.getFirstValueIndex(valuesPosition); - int extraEnd = extraStart + extraBlock.getValueCount(valuesPosition); - for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { - float extraValue = extraBlock.getFloat(extraOffset); - TopDoubleFloatAggregator.combine(state, groupId, vValue, extraValue); + int outputValueStart = outputValueBlock.getFirstValueIndex(valuesPosition); + int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(valuesPosition); + for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { + float outputValueValue = outputValueBlock.getFloat(outputValueOffset); + TopDoubleFloatAggregator.combine(state, groupId, vValue, outputValueValue); } } } @@ -251,7 +251,7 @@ private void addRawInput(int positionOffset, IntBigArrayBlock groups, DoubleBloc } private void addRawInput(int positionOffset, IntBigArrayBlock groups, DoubleVector vVector, - FloatVector extraVector) { + FloatVector outputValueVector) { for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { if (groups.isNull(groupPosition)) { continue; @@ -262,8 +262,8 @@ private void addRawInput(int positionOffset, IntBigArrayBlock groups, DoubleVect for (int g = groupStart; g < groupEnd; g++) { int groupId = groups.getInt(g); double vValue = vVector.getDouble(valuesPosition); - float extraValue = extraVector.getFloat(valuesPosition); - TopDoubleFloatAggregator.combine(state, groupId, vValue, extraValue); + float outputValueValue = outputValueVector.getFloat(valuesPosition); + TopDoubleFloatAggregator.combine(state, groupId, vValue, outputValueValue); } } } @@ -277,12 +277,12 @@ public void addIntermediateInput(int positionOffset, IntBigArrayBlock groups, Pa return; } DoubleBlock top = (DoubleBlock) topUncast; - Block extraUncast = page.getBlock(channels.get(1)); - if (extraUncast.areAllValuesNull()) { + Block outputUncast = page.getBlock(channels.get(1)); + if (outputUncast.areAllValuesNull()) { return; } - FloatBlock extra = (FloatBlock) extraUncast; - assert top.getPositionCount() == extra.getPositionCount(); + FloatBlock output = (FloatBlock) outputUncast; + assert top.getPositionCount() == output.getPositionCount(); for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { if (groups.isNull(groupPosition)) { continue; @@ -292,19 +292,19 @@ public void addIntermediateInput(int positionOffset, IntBigArrayBlock groups, Pa for (int g = groupStart; g < groupEnd; g++) { int groupId = groups.getInt(g); int valuesPosition = groupPosition + positionOffset; - TopDoubleFloatAggregator.combineIntermediate(state, groupId, top, extra, valuesPosition); + TopDoubleFloatAggregator.combineIntermediate(state, groupId, top, output, valuesPosition); } } } private void addRawInput(int positionOffset, IntVector groups, DoubleBlock vBlock, - FloatBlock extraBlock) { + FloatBlock outputValueBlock) { for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { int valuesPosition = groupPosition + positionOffset; if (vBlock.isNull(valuesPosition)) { continue; } - if (extraBlock.isNull(valuesPosition)) { + if (outputValueBlock.isNull(valuesPosition)) { continue; } int groupId = groups.getInt(groupPosition); @@ -312,24 +312,24 @@ private void addRawInput(int positionOffset, IntVector groups, DoubleBlock vBloc int vEnd = vStart + vBlock.getValueCount(valuesPosition); for (int vOffset = vStart; vOffset < vEnd; vOffset++) { double vValue = vBlock.getDouble(vOffset); - int extraStart = extraBlock.getFirstValueIndex(valuesPosition); - int extraEnd = extraStart + extraBlock.getValueCount(valuesPosition); - for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { - float extraValue = extraBlock.getFloat(extraOffset); - TopDoubleFloatAggregator.combine(state, groupId, vValue, extraValue); + int outputValueStart = outputValueBlock.getFirstValueIndex(valuesPosition); + int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(valuesPosition); + for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { + float outputValueValue = outputValueBlock.getFloat(outputValueOffset); + TopDoubleFloatAggregator.combine(state, groupId, vValue, outputValueValue); } } } } private void addRawInput(int positionOffset, IntVector groups, DoubleVector vVector, - FloatVector extraVector) { + FloatVector outputValueVector) { for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { int valuesPosition = groupPosition + positionOffset; int groupId = groups.getInt(groupPosition); double vValue = vVector.getDouble(valuesPosition); - float extraValue = extraVector.getFloat(valuesPosition); - TopDoubleFloatAggregator.combine(state, groupId, vValue, extraValue); + float outputValueValue = outputValueVector.getFloat(valuesPosition); + TopDoubleFloatAggregator.combine(state, groupId, vValue, outputValueValue); } } @@ -342,25 +342,25 @@ public void addIntermediateInput(int positionOffset, IntVector groups, Page page return; } DoubleBlock top = (DoubleBlock) topUncast; - Block extraUncast = page.getBlock(channels.get(1)); - if (extraUncast.areAllValuesNull()) { + Block outputUncast = page.getBlock(channels.get(1)); + if (outputUncast.areAllValuesNull()) { return; } - FloatBlock extra = (FloatBlock) extraUncast; - assert top.getPositionCount() == extra.getPositionCount(); + FloatBlock output = (FloatBlock) outputUncast; + assert top.getPositionCount() == output.getPositionCount(); for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { int groupId = groups.getInt(groupPosition); int valuesPosition = groupPosition + positionOffset; - TopDoubleFloatAggregator.combineIntermediate(state, groupId, top, extra, valuesPosition); + TopDoubleFloatAggregator.combineIntermediate(state, groupId, top, output, valuesPosition); } } private void maybeEnableGroupIdTracking(SeenGroupIds seenGroupIds, DoubleBlock vBlock, - FloatBlock extraBlock) { + FloatBlock outputValueBlock) { if (vBlock.mayHaveNulls()) { state.enableGroupIdTracking(seenGroupIds); } - if (extraBlock.mayHaveNulls()) { + if (outputValueBlock.mayHaveNulls()) { state.enableGroupIdTracking(seenGroupIds); } } diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleIntAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleIntAggregatorFunction.java index c3b2bfee37db9..c71351faea869 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleIntAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleIntAggregatorFunction.java @@ -26,7 +26,7 @@ public final class TopDoubleIntAggregatorFunction implements AggregatorFunction { private static final List INTERMEDIATE_STATE_DESC = List.of( new IntermediateStateDesc("top", ElementType.DOUBLE), - new IntermediateStateDesc("extra", ElementType.INT) ); + new IntermediateStateDesc("output", ElementType.INT) ); private final DriverContext driverContext; @@ -74,78 +74,78 @@ public void addRawInput(Page page, BooleanVector mask) { private void addRawInputMasked(Page page, BooleanVector mask) { DoubleBlock vBlock = page.getBlock(channels.get(0)); - IntBlock extraBlock = page.getBlock(channels.get(1)); + IntBlock outputValueBlock = page.getBlock(channels.get(1)); DoubleVector vVector = vBlock.asVector(); if (vVector == null) { - addRawBlock(vBlock, extraBlock, mask); + addRawBlock(vBlock, outputValueBlock, mask); return; } - IntVector extraVector = extraBlock.asVector(); - if (extraVector == null) { - addRawBlock(vBlock, extraBlock, mask); + IntVector outputValueVector = outputValueBlock.asVector(); + if (outputValueVector == null) { + addRawBlock(vBlock, outputValueBlock, mask); return; } - addRawVector(vVector, extraVector, mask); + addRawVector(vVector, outputValueVector, mask); } private void addRawInputNotMasked(Page page) { DoubleBlock vBlock = page.getBlock(channels.get(0)); - IntBlock extraBlock = page.getBlock(channels.get(1)); + IntBlock outputValueBlock = page.getBlock(channels.get(1)); DoubleVector vVector = vBlock.asVector(); if (vVector == null) { - addRawBlock(vBlock, extraBlock); + addRawBlock(vBlock, outputValueBlock); return; } - IntVector extraVector = extraBlock.asVector(); - if (extraVector == null) { - addRawBlock(vBlock, extraBlock); + IntVector outputValueVector = outputValueBlock.asVector(); + if (outputValueVector == null) { + addRawBlock(vBlock, outputValueBlock); return; } - addRawVector(vVector, extraVector); + addRawVector(vVector, outputValueVector); } - private void addRawVector(DoubleVector vVector, IntVector extraVector) { + private void addRawVector(DoubleVector vVector, IntVector outputValueVector) { for (int valuesPosition = 0; valuesPosition < vVector.getPositionCount(); valuesPosition++) { double vValue = vVector.getDouble(valuesPosition); - int extraValue = extraVector.getInt(valuesPosition); - TopDoubleIntAggregator.combine(state, vValue, extraValue); + int outputValueValue = outputValueVector.getInt(valuesPosition); + TopDoubleIntAggregator.combine(state, vValue, outputValueValue); } } - private void addRawVector(DoubleVector vVector, IntVector extraVector, BooleanVector mask) { + private void addRawVector(DoubleVector vVector, IntVector outputValueVector, BooleanVector mask) { for (int valuesPosition = 0; valuesPosition < vVector.getPositionCount(); valuesPosition++) { if (mask.getBoolean(valuesPosition) == false) { continue; } double vValue = vVector.getDouble(valuesPosition); - int extraValue = extraVector.getInt(valuesPosition); - TopDoubleIntAggregator.combine(state, vValue, extraValue); + int outputValueValue = outputValueVector.getInt(valuesPosition); + TopDoubleIntAggregator.combine(state, vValue, outputValueValue); } } - private void addRawBlock(DoubleBlock vBlock, IntBlock extraBlock) { + private void addRawBlock(DoubleBlock vBlock, IntBlock outputValueBlock) { for (int p = 0; p < vBlock.getPositionCount(); p++) { if (vBlock.isNull(p)) { continue; } - if (extraBlock.isNull(p)) { + if (outputValueBlock.isNull(p)) { continue; } int vStart = vBlock.getFirstValueIndex(p); int vEnd = vStart + vBlock.getValueCount(p); for (int vOffset = vStart; vOffset < vEnd; vOffset++) { double vValue = vBlock.getDouble(vOffset); - int extraStart = extraBlock.getFirstValueIndex(p); - int extraEnd = extraStart + extraBlock.getValueCount(p); - for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { - int extraValue = extraBlock.getInt(extraOffset); - TopDoubleIntAggregator.combine(state, vValue, extraValue); + int outputValueStart = outputValueBlock.getFirstValueIndex(p); + int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(p); + for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { + int outputValueValue = outputValueBlock.getInt(outputValueOffset); + TopDoubleIntAggregator.combine(state, vValue, outputValueValue); } } } } - private void addRawBlock(DoubleBlock vBlock, IntBlock extraBlock, BooleanVector mask) { + private void addRawBlock(DoubleBlock vBlock, IntBlock outputValueBlock, BooleanVector mask) { for (int p = 0; p < vBlock.getPositionCount(); p++) { if (mask.getBoolean(p) == false) { continue; @@ -153,18 +153,18 @@ private void addRawBlock(DoubleBlock vBlock, IntBlock extraBlock, BooleanVector if (vBlock.isNull(p)) { continue; } - if (extraBlock.isNull(p)) { + if (outputValueBlock.isNull(p)) { continue; } int vStart = vBlock.getFirstValueIndex(p); int vEnd = vStart + vBlock.getValueCount(p); for (int vOffset = vStart; vOffset < vEnd; vOffset++) { double vValue = vBlock.getDouble(vOffset); - int extraStart = extraBlock.getFirstValueIndex(p); - int extraEnd = extraStart + extraBlock.getValueCount(p); - for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { - int extraValue = extraBlock.getInt(extraOffset); - TopDoubleIntAggregator.combine(state, vValue, extraValue); + int outputValueStart = outputValueBlock.getFirstValueIndex(p); + int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(p); + for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { + int outputValueValue = outputValueBlock.getInt(outputValueOffset); + TopDoubleIntAggregator.combine(state, vValue, outputValueValue); } } } @@ -180,13 +180,13 @@ public void addIntermediateInput(Page page) { } DoubleBlock top = (DoubleBlock) topUncast; assert top.getPositionCount() == 1; - Block extraUncast = page.getBlock(channels.get(1)); - if (extraUncast.areAllValuesNull()) { + Block outputUncast = page.getBlock(channels.get(1)); + if (outputUncast.areAllValuesNull()) { return; } - IntBlock extra = (IntBlock) extraUncast; - assert extra.getPositionCount() == 1; - TopDoubleIntAggregator.combineIntermediate(state, top, extra); + IntBlock output = (IntBlock) outputUncast; + assert output.getPositionCount() == 1; + TopDoubleIntAggregator.combineIntermediate(state, top, output); } @Override diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleIntGroupingAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleIntGroupingAggregatorFunction.java index 0ef06a2136d4b..817ac9746c37b 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleIntGroupingAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleIntGroupingAggregatorFunction.java @@ -27,7 +27,7 @@ public final class TopDoubleIntGroupingAggregatorFunction implements GroupingAggregatorFunction { private static final List INTERMEDIATE_STATE_DESC = List.of( new IntermediateStateDesc("top", ElementType.DOUBLE), - new IntermediateStateDesc("extra", ElementType.INT) ); + new IntermediateStateDesc("output", ElementType.INT) ); private final TopDoubleIntAggregator.GroupingState state; @@ -67,24 +67,24 @@ public int intermediateBlockCount() { public GroupingAggregatorFunction.AddInput prepareProcessRawInputPage(SeenGroupIds seenGroupIds, Page page) { DoubleBlock vBlock = page.getBlock(channels.get(0)); - IntBlock extraBlock = page.getBlock(channels.get(1)); + IntBlock outputValueBlock = page.getBlock(channels.get(1)); DoubleVector vVector = vBlock.asVector(); if (vVector == null) { - maybeEnableGroupIdTracking(seenGroupIds, vBlock, extraBlock); + maybeEnableGroupIdTracking(seenGroupIds, vBlock, outputValueBlock); return new GroupingAggregatorFunction.AddInput() { @Override public void add(int positionOffset, IntArrayBlock groupIds) { - addRawInput(positionOffset, groupIds, vBlock, extraBlock); + addRawInput(positionOffset, groupIds, vBlock, outputValueBlock); } @Override public void add(int positionOffset, IntBigArrayBlock groupIds) { - addRawInput(positionOffset, groupIds, vBlock, extraBlock); + addRawInput(positionOffset, groupIds, vBlock, outputValueBlock); } @Override public void add(int positionOffset, IntVector groupIds) { - addRawInput(positionOffset, groupIds, vBlock, extraBlock); + addRawInput(positionOffset, groupIds, vBlock, outputValueBlock); } @Override @@ -92,23 +92,23 @@ public void close() { } }; } - IntVector extraVector = extraBlock.asVector(); - if (extraVector == null) { - maybeEnableGroupIdTracking(seenGroupIds, vBlock, extraBlock); + IntVector outputValueVector = outputValueBlock.asVector(); + if (outputValueVector == null) { + maybeEnableGroupIdTracking(seenGroupIds, vBlock, outputValueBlock); return new GroupingAggregatorFunction.AddInput() { @Override public void add(int positionOffset, IntArrayBlock groupIds) { - addRawInput(positionOffset, groupIds, vBlock, extraBlock); + addRawInput(positionOffset, groupIds, vBlock, outputValueBlock); } @Override public void add(int positionOffset, IntBigArrayBlock groupIds) { - addRawInput(positionOffset, groupIds, vBlock, extraBlock); + addRawInput(positionOffset, groupIds, vBlock, outputValueBlock); } @Override public void add(int positionOffset, IntVector groupIds) { - addRawInput(positionOffset, groupIds, vBlock, extraBlock); + addRawInput(positionOffset, groupIds, vBlock, outputValueBlock); } @Override @@ -119,17 +119,17 @@ public void close() { return new GroupingAggregatorFunction.AddInput() { @Override public void add(int positionOffset, IntArrayBlock groupIds) { - addRawInput(positionOffset, groupIds, vVector, extraVector); + addRawInput(positionOffset, groupIds, vVector, outputValueVector); } @Override public void add(int positionOffset, IntBigArrayBlock groupIds) { - addRawInput(positionOffset, groupIds, vVector, extraVector); + addRawInput(positionOffset, groupIds, vVector, outputValueVector); } @Override public void add(int positionOffset, IntVector groupIds) { - addRawInput(positionOffset, groupIds, vVector, extraVector); + addRawInput(positionOffset, groupIds, vVector, outputValueVector); } @Override @@ -139,7 +139,7 @@ public void close() { } private void addRawInput(int positionOffset, IntArrayBlock groups, DoubleBlock vBlock, - IntBlock extraBlock) { + IntBlock outputValueBlock) { for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { if (groups.isNull(groupPosition)) { continue; @@ -148,7 +148,7 @@ private void addRawInput(int positionOffset, IntArrayBlock groups, DoubleBlock v if (vBlock.isNull(valuesPosition)) { continue; } - if (extraBlock.isNull(valuesPosition)) { + if (outputValueBlock.isNull(valuesPosition)) { continue; } int groupStart = groups.getFirstValueIndex(groupPosition); @@ -159,11 +159,11 @@ private void addRawInput(int positionOffset, IntArrayBlock groups, DoubleBlock v int vEnd = vStart + vBlock.getValueCount(valuesPosition); for (int vOffset = vStart; vOffset < vEnd; vOffset++) { double vValue = vBlock.getDouble(vOffset); - int extraStart = extraBlock.getFirstValueIndex(valuesPosition); - int extraEnd = extraStart + extraBlock.getValueCount(valuesPosition); - for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { - int extraValue = extraBlock.getInt(extraOffset); - TopDoubleIntAggregator.combine(state, groupId, vValue, extraValue); + int outputValueStart = outputValueBlock.getFirstValueIndex(valuesPosition); + int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(valuesPosition); + for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { + int outputValueValue = outputValueBlock.getInt(outputValueOffset); + TopDoubleIntAggregator.combine(state, groupId, vValue, outputValueValue); } } } @@ -171,7 +171,7 @@ private void addRawInput(int positionOffset, IntArrayBlock groups, DoubleBlock v } private void addRawInput(int positionOffset, IntArrayBlock groups, DoubleVector vVector, - IntVector extraVector) { + IntVector outputValueVector) { for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { if (groups.isNull(groupPosition)) { continue; @@ -182,8 +182,8 @@ private void addRawInput(int positionOffset, IntArrayBlock groups, DoubleVector for (int g = groupStart; g < groupEnd; g++) { int groupId = groups.getInt(g); double vValue = vVector.getDouble(valuesPosition); - int extraValue = extraVector.getInt(valuesPosition); - TopDoubleIntAggregator.combine(state, groupId, vValue, extraValue); + int outputValueValue = outputValueVector.getInt(valuesPosition); + TopDoubleIntAggregator.combine(state, groupId, vValue, outputValueValue); } } } @@ -197,12 +197,12 @@ public void addIntermediateInput(int positionOffset, IntArrayBlock groups, Page return; } DoubleBlock top = (DoubleBlock) topUncast; - Block extraUncast = page.getBlock(channels.get(1)); - if (extraUncast.areAllValuesNull()) { + Block outputUncast = page.getBlock(channels.get(1)); + if (outputUncast.areAllValuesNull()) { return; } - IntBlock extra = (IntBlock) extraUncast; - assert top.getPositionCount() == extra.getPositionCount(); + IntBlock output = (IntBlock) outputUncast; + assert top.getPositionCount() == output.getPositionCount(); for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { if (groups.isNull(groupPosition)) { continue; @@ -212,13 +212,13 @@ public void addIntermediateInput(int positionOffset, IntArrayBlock groups, Page for (int g = groupStart; g < groupEnd; g++) { int groupId = groups.getInt(g); int valuesPosition = groupPosition + positionOffset; - TopDoubleIntAggregator.combineIntermediate(state, groupId, top, extra, valuesPosition); + TopDoubleIntAggregator.combineIntermediate(state, groupId, top, output, valuesPosition); } } } private void addRawInput(int positionOffset, IntBigArrayBlock groups, DoubleBlock vBlock, - IntBlock extraBlock) { + IntBlock outputValueBlock) { for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { if (groups.isNull(groupPosition)) { continue; @@ -227,7 +227,7 @@ private void addRawInput(int positionOffset, IntBigArrayBlock groups, DoubleBloc if (vBlock.isNull(valuesPosition)) { continue; } - if (extraBlock.isNull(valuesPosition)) { + if (outputValueBlock.isNull(valuesPosition)) { continue; } int groupStart = groups.getFirstValueIndex(groupPosition); @@ -238,11 +238,11 @@ private void addRawInput(int positionOffset, IntBigArrayBlock groups, DoubleBloc int vEnd = vStart + vBlock.getValueCount(valuesPosition); for (int vOffset = vStart; vOffset < vEnd; vOffset++) { double vValue = vBlock.getDouble(vOffset); - int extraStart = extraBlock.getFirstValueIndex(valuesPosition); - int extraEnd = extraStart + extraBlock.getValueCount(valuesPosition); - for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { - int extraValue = extraBlock.getInt(extraOffset); - TopDoubleIntAggregator.combine(state, groupId, vValue, extraValue); + int outputValueStart = outputValueBlock.getFirstValueIndex(valuesPosition); + int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(valuesPosition); + for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { + int outputValueValue = outputValueBlock.getInt(outputValueOffset); + TopDoubleIntAggregator.combine(state, groupId, vValue, outputValueValue); } } } @@ -250,7 +250,7 @@ private void addRawInput(int positionOffset, IntBigArrayBlock groups, DoubleBloc } private void addRawInput(int positionOffset, IntBigArrayBlock groups, DoubleVector vVector, - IntVector extraVector) { + IntVector outputValueVector) { for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { if (groups.isNull(groupPosition)) { continue; @@ -261,8 +261,8 @@ private void addRawInput(int positionOffset, IntBigArrayBlock groups, DoubleVect for (int g = groupStart; g < groupEnd; g++) { int groupId = groups.getInt(g); double vValue = vVector.getDouble(valuesPosition); - int extraValue = extraVector.getInt(valuesPosition); - TopDoubleIntAggregator.combine(state, groupId, vValue, extraValue); + int outputValueValue = outputValueVector.getInt(valuesPosition); + TopDoubleIntAggregator.combine(state, groupId, vValue, outputValueValue); } } } @@ -276,12 +276,12 @@ public void addIntermediateInput(int positionOffset, IntBigArrayBlock groups, Pa return; } DoubleBlock top = (DoubleBlock) topUncast; - Block extraUncast = page.getBlock(channels.get(1)); - if (extraUncast.areAllValuesNull()) { + Block outputUncast = page.getBlock(channels.get(1)); + if (outputUncast.areAllValuesNull()) { return; } - IntBlock extra = (IntBlock) extraUncast; - assert top.getPositionCount() == extra.getPositionCount(); + IntBlock output = (IntBlock) outputUncast; + assert top.getPositionCount() == output.getPositionCount(); for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { if (groups.isNull(groupPosition)) { continue; @@ -291,19 +291,19 @@ public void addIntermediateInput(int positionOffset, IntBigArrayBlock groups, Pa for (int g = groupStart; g < groupEnd; g++) { int groupId = groups.getInt(g); int valuesPosition = groupPosition + positionOffset; - TopDoubleIntAggregator.combineIntermediate(state, groupId, top, extra, valuesPosition); + TopDoubleIntAggregator.combineIntermediate(state, groupId, top, output, valuesPosition); } } } private void addRawInput(int positionOffset, IntVector groups, DoubleBlock vBlock, - IntBlock extraBlock) { + IntBlock outputValueBlock) { for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { int valuesPosition = groupPosition + positionOffset; if (vBlock.isNull(valuesPosition)) { continue; } - if (extraBlock.isNull(valuesPosition)) { + if (outputValueBlock.isNull(valuesPosition)) { continue; } int groupId = groups.getInt(groupPosition); @@ -311,24 +311,24 @@ private void addRawInput(int positionOffset, IntVector groups, DoubleBlock vBloc int vEnd = vStart + vBlock.getValueCount(valuesPosition); for (int vOffset = vStart; vOffset < vEnd; vOffset++) { double vValue = vBlock.getDouble(vOffset); - int extraStart = extraBlock.getFirstValueIndex(valuesPosition); - int extraEnd = extraStart + extraBlock.getValueCount(valuesPosition); - for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { - int extraValue = extraBlock.getInt(extraOffset); - TopDoubleIntAggregator.combine(state, groupId, vValue, extraValue); + int outputValueStart = outputValueBlock.getFirstValueIndex(valuesPosition); + int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(valuesPosition); + for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { + int outputValueValue = outputValueBlock.getInt(outputValueOffset); + TopDoubleIntAggregator.combine(state, groupId, vValue, outputValueValue); } } } } private void addRawInput(int positionOffset, IntVector groups, DoubleVector vVector, - IntVector extraVector) { + IntVector outputValueVector) { for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { int valuesPosition = groupPosition + positionOffset; int groupId = groups.getInt(groupPosition); double vValue = vVector.getDouble(valuesPosition); - int extraValue = extraVector.getInt(valuesPosition); - TopDoubleIntAggregator.combine(state, groupId, vValue, extraValue); + int outputValueValue = outputValueVector.getInt(valuesPosition); + TopDoubleIntAggregator.combine(state, groupId, vValue, outputValueValue); } } @@ -341,25 +341,25 @@ public void addIntermediateInput(int positionOffset, IntVector groups, Page page return; } DoubleBlock top = (DoubleBlock) topUncast; - Block extraUncast = page.getBlock(channels.get(1)); - if (extraUncast.areAllValuesNull()) { + Block outputUncast = page.getBlock(channels.get(1)); + if (outputUncast.areAllValuesNull()) { return; } - IntBlock extra = (IntBlock) extraUncast; - assert top.getPositionCount() == extra.getPositionCount(); + IntBlock output = (IntBlock) outputUncast; + assert top.getPositionCount() == output.getPositionCount(); for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { int groupId = groups.getInt(groupPosition); int valuesPosition = groupPosition + positionOffset; - TopDoubleIntAggregator.combineIntermediate(state, groupId, top, extra, valuesPosition); + TopDoubleIntAggregator.combineIntermediate(state, groupId, top, output, valuesPosition); } } private void maybeEnableGroupIdTracking(SeenGroupIds seenGroupIds, DoubleBlock vBlock, - IntBlock extraBlock) { + IntBlock outputValueBlock) { if (vBlock.mayHaveNulls()) { state.enableGroupIdTracking(seenGroupIds); } - if (extraBlock.mayHaveNulls()) { + if (outputValueBlock.mayHaveNulls()) { state.enableGroupIdTracking(seenGroupIds); } } diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleLongAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleLongAggregatorFunction.java index 00ee94bfb7d4a..3505e75ce3663 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleLongAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleLongAggregatorFunction.java @@ -26,7 +26,7 @@ public final class TopDoubleLongAggregatorFunction implements AggregatorFunction { private static final List INTERMEDIATE_STATE_DESC = List.of( new IntermediateStateDesc("top", ElementType.DOUBLE), - new IntermediateStateDesc("extra", ElementType.LONG) ); + new IntermediateStateDesc("output", ElementType.LONG) ); private final DriverContext driverContext; @@ -74,78 +74,79 @@ public void addRawInput(Page page, BooleanVector mask) { private void addRawInputMasked(Page page, BooleanVector mask) { DoubleBlock vBlock = page.getBlock(channels.get(0)); - LongBlock extraBlock = page.getBlock(channels.get(1)); + LongBlock outputValueBlock = page.getBlock(channels.get(1)); DoubleVector vVector = vBlock.asVector(); if (vVector == null) { - addRawBlock(vBlock, extraBlock, mask); + addRawBlock(vBlock, outputValueBlock, mask); return; } - LongVector extraVector = extraBlock.asVector(); - if (extraVector == null) { - addRawBlock(vBlock, extraBlock, mask); + LongVector outputValueVector = outputValueBlock.asVector(); + if (outputValueVector == null) { + addRawBlock(vBlock, outputValueBlock, mask); return; } - addRawVector(vVector, extraVector, mask); + addRawVector(vVector, outputValueVector, mask); } private void addRawInputNotMasked(Page page) { DoubleBlock vBlock = page.getBlock(channels.get(0)); - LongBlock extraBlock = page.getBlock(channels.get(1)); + LongBlock outputValueBlock = page.getBlock(channels.get(1)); DoubleVector vVector = vBlock.asVector(); if (vVector == null) { - addRawBlock(vBlock, extraBlock); + addRawBlock(vBlock, outputValueBlock); return; } - LongVector extraVector = extraBlock.asVector(); - if (extraVector == null) { - addRawBlock(vBlock, extraBlock); + LongVector outputValueVector = outputValueBlock.asVector(); + if (outputValueVector == null) { + addRawBlock(vBlock, outputValueBlock); return; } - addRawVector(vVector, extraVector); + addRawVector(vVector, outputValueVector); } - private void addRawVector(DoubleVector vVector, LongVector extraVector) { + private void addRawVector(DoubleVector vVector, LongVector outputValueVector) { for (int valuesPosition = 0; valuesPosition < vVector.getPositionCount(); valuesPosition++) { double vValue = vVector.getDouble(valuesPosition); - long extraValue = extraVector.getLong(valuesPosition); - TopDoubleLongAggregator.combine(state, vValue, extraValue); + long outputValueValue = outputValueVector.getLong(valuesPosition); + TopDoubleLongAggregator.combine(state, vValue, outputValueValue); } } - private void addRawVector(DoubleVector vVector, LongVector extraVector, BooleanVector mask) { + private void addRawVector(DoubleVector vVector, LongVector outputValueVector, + BooleanVector mask) { for (int valuesPosition = 0; valuesPosition < vVector.getPositionCount(); valuesPosition++) { if (mask.getBoolean(valuesPosition) == false) { continue; } double vValue = vVector.getDouble(valuesPosition); - long extraValue = extraVector.getLong(valuesPosition); - TopDoubleLongAggregator.combine(state, vValue, extraValue); + long outputValueValue = outputValueVector.getLong(valuesPosition); + TopDoubleLongAggregator.combine(state, vValue, outputValueValue); } } - private void addRawBlock(DoubleBlock vBlock, LongBlock extraBlock) { + private void addRawBlock(DoubleBlock vBlock, LongBlock outputValueBlock) { for (int p = 0; p < vBlock.getPositionCount(); p++) { if (vBlock.isNull(p)) { continue; } - if (extraBlock.isNull(p)) { + if (outputValueBlock.isNull(p)) { continue; } int vStart = vBlock.getFirstValueIndex(p); int vEnd = vStart + vBlock.getValueCount(p); for (int vOffset = vStart; vOffset < vEnd; vOffset++) { double vValue = vBlock.getDouble(vOffset); - int extraStart = extraBlock.getFirstValueIndex(p); - int extraEnd = extraStart + extraBlock.getValueCount(p); - for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { - long extraValue = extraBlock.getLong(extraOffset); - TopDoubleLongAggregator.combine(state, vValue, extraValue); + int outputValueStart = outputValueBlock.getFirstValueIndex(p); + int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(p); + for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { + long outputValueValue = outputValueBlock.getLong(outputValueOffset); + TopDoubleLongAggregator.combine(state, vValue, outputValueValue); } } } } - private void addRawBlock(DoubleBlock vBlock, LongBlock extraBlock, BooleanVector mask) { + private void addRawBlock(DoubleBlock vBlock, LongBlock outputValueBlock, BooleanVector mask) { for (int p = 0; p < vBlock.getPositionCount(); p++) { if (mask.getBoolean(p) == false) { continue; @@ -153,18 +154,18 @@ private void addRawBlock(DoubleBlock vBlock, LongBlock extraBlock, BooleanVector if (vBlock.isNull(p)) { continue; } - if (extraBlock.isNull(p)) { + if (outputValueBlock.isNull(p)) { continue; } int vStart = vBlock.getFirstValueIndex(p); int vEnd = vStart + vBlock.getValueCount(p); for (int vOffset = vStart; vOffset < vEnd; vOffset++) { double vValue = vBlock.getDouble(vOffset); - int extraStart = extraBlock.getFirstValueIndex(p); - int extraEnd = extraStart + extraBlock.getValueCount(p); - for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { - long extraValue = extraBlock.getLong(extraOffset); - TopDoubleLongAggregator.combine(state, vValue, extraValue); + int outputValueStart = outputValueBlock.getFirstValueIndex(p); + int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(p); + for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { + long outputValueValue = outputValueBlock.getLong(outputValueOffset); + TopDoubleLongAggregator.combine(state, vValue, outputValueValue); } } } @@ -180,13 +181,13 @@ public void addIntermediateInput(Page page) { } DoubleBlock top = (DoubleBlock) topUncast; assert top.getPositionCount() == 1; - Block extraUncast = page.getBlock(channels.get(1)); - if (extraUncast.areAllValuesNull()) { + Block outputUncast = page.getBlock(channels.get(1)); + if (outputUncast.areAllValuesNull()) { return; } - LongBlock extra = (LongBlock) extraUncast; - assert extra.getPositionCount() == 1; - TopDoubleLongAggregator.combineIntermediate(state, top, extra); + LongBlock output = (LongBlock) outputUncast; + assert output.getPositionCount() == 1; + TopDoubleLongAggregator.combineIntermediate(state, top, output); } @Override diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleLongGroupingAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleLongGroupingAggregatorFunction.java index 685c5172d0788..04cd530e8dd41 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleLongGroupingAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleLongGroupingAggregatorFunction.java @@ -28,7 +28,7 @@ public final class TopDoubleLongGroupingAggregatorFunction implements GroupingAggregatorFunction { private static final List INTERMEDIATE_STATE_DESC = List.of( new IntermediateStateDesc("top", ElementType.DOUBLE), - new IntermediateStateDesc("extra", ElementType.LONG) ); + new IntermediateStateDesc("output", ElementType.LONG) ); private final TopDoubleLongAggregator.GroupingState state; @@ -68,24 +68,24 @@ public int intermediateBlockCount() { public GroupingAggregatorFunction.AddInput prepareProcessRawInputPage(SeenGroupIds seenGroupIds, Page page) { DoubleBlock vBlock = page.getBlock(channels.get(0)); - LongBlock extraBlock = page.getBlock(channels.get(1)); + LongBlock outputValueBlock = page.getBlock(channels.get(1)); DoubleVector vVector = vBlock.asVector(); if (vVector == null) { - maybeEnableGroupIdTracking(seenGroupIds, vBlock, extraBlock); + maybeEnableGroupIdTracking(seenGroupIds, vBlock, outputValueBlock); return new GroupingAggregatorFunction.AddInput() { @Override public void add(int positionOffset, IntArrayBlock groupIds) { - addRawInput(positionOffset, groupIds, vBlock, extraBlock); + addRawInput(positionOffset, groupIds, vBlock, outputValueBlock); } @Override public void add(int positionOffset, IntBigArrayBlock groupIds) { - addRawInput(positionOffset, groupIds, vBlock, extraBlock); + addRawInput(positionOffset, groupIds, vBlock, outputValueBlock); } @Override public void add(int positionOffset, IntVector groupIds) { - addRawInput(positionOffset, groupIds, vBlock, extraBlock); + addRawInput(positionOffset, groupIds, vBlock, outputValueBlock); } @Override @@ -93,23 +93,23 @@ public void close() { } }; } - LongVector extraVector = extraBlock.asVector(); - if (extraVector == null) { - maybeEnableGroupIdTracking(seenGroupIds, vBlock, extraBlock); + LongVector outputValueVector = outputValueBlock.asVector(); + if (outputValueVector == null) { + maybeEnableGroupIdTracking(seenGroupIds, vBlock, outputValueBlock); return new GroupingAggregatorFunction.AddInput() { @Override public void add(int positionOffset, IntArrayBlock groupIds) { - addRawInput(positionOffset, groupIds, vBlock, extraBlock); + addRawInput(positionOffset, groupIds, vBlock, outputValueBlock); } @Override public void add(int positionOffset, IntBigArrayBlock groupIds) { - addRawInput(positionOffset, groupIds, vBlock, extraBlock); + addRawInput(positionOffset, groupIds, vBlock, outputValueBlock); } @Override public void add(int positionOffset, IntVector groupIds) { - addRawInput(positionOffset, groupIds, vBlock, extraBlock); + addRawInput(positionOffset, groupIds, vBlock, outputValueBlock); } @Override @@ -120,17 +120,17 @@ public void close() { return new GroupingAggregatorFunction.AddInput() { @Override public void add(int positionOffset, IntArrayBlock groupIds) { - addRawInput(positionOffset, groupIds, vVector, extraVector); + addRawInput(positionOffset, groupIds, vVector, outputValueVector); } @Override public void add(int positionOffset, IntBigArrayBlock groupIds) { - addRawInput(positionOffset, groupIds, vVector, extraVector); + addRawInput(positionOffset, groupIds, vVector, outputValueVector); } @Override public void add(int positionOffset, IntVector groupIds) { - addRawInput(positionOffset, groupIds, vVector, extraVector); + addRawInput(positionOffset, groupIds, vVector, outputValueVector); } @Override @@ -140,7 +140,7 @@ public void close() { } private void addRawInput(int positionOffset, IntArrayBlock groups, DoubleBlock vBlock, - LongBlock extraBlock) { + LongBlock outputValueBlock) { for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { if (groups.isNull(groupPosition)) { continue; @@ -149,7 +149,7 @@ private void addRawInput(int positionOffset, IntArrayBlock groups, DoubleBlock v if (vBlock.isNull(valuesPosition)) { continue; } - if (extraBlock.isNull(valuesPosition)) { + if (outputValueBlock.isNull(valuesPosition)) { continue; } int groupStart = groups.getFirstValueIndex(groupPosition); @@ -160,11 +160,11 @@ private void addRawInput(int positionOffset, IntArrayBlock groups, DoubleBlock v int vEnd = vStart + vBlock.getValueCount(valuesPosition); for (int vOffset = vStart; vOffset < vEnd; vOffset++) { double vValue = vBlock.getDouble(vOffset); - int extraStart = extraBlock.getFirstValueIndex(valuesPosition); - int extraEnd = extraStart + extraBlock.getValueCount(valuesPosition); - for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { - long extraValue = extraBlock.getLong(extraOffset); - TopDoubleLongAggregator.combine(state, groupId, vValue, extraValue); + int outputValueStart = outputValueBlock.getFirstValueIndex(valuesPosition); + int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(valuesPosition); + for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { + long outputValueValue = outputValueBlock.getLong(outputValueOffset); + TopDoubleLongAggregator.combine(state, groupId, vValue, outputValueValue); } } } @@ -172,7 +172,7 @@ private void addRawInput(int positionOffset, IntArrayBlock groups, DoubleBlock v } private void addRawInput(int positionOffset, IntArrayBlock groups, DoubleVector vVector, - LongVector extraVector) { + LongVector outputValueVector) { for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { if (groups.isNull(groupPosition)) { continue; @@ -183,8 +183,8 @@ private void addRawInput(int positionOffset, IntArrayBlock groups, DoubleVector for (int g = groupStart; g < groupEnd; g++) { int groupId = groups.getInt(g); double vValue = vVector.getDouble(valuesPosition); - long extraValue = extraVector.getLong(valuesPosition); - TopDoubleLongAggregator.combine(state, groupId, vValue, extraValue); + long outputValueValue = outputValueVector.getLong(valuesPosition); + TopDoubleLongAggregator.combine(state, groupId, vValue, outputValueValue); } } } @@ -198,12 +198,12 @@ public void addIntermediateInput(int positionOffset, IntArrayBlock groups, Page return; } DoubleBlock top = (DoubleBlock) topUncast; - Block extraUncast = page.getBlock(channels.get(1)); - if (extraUncast.areAllValuesNull()) { + Block outputUncast = page.getBlock(channels.get(1)); + if (outputUncast.areAllValuesNull()) { return; } - LongBlock extra = (LongBlock) extraUncast; - assert top.getPositionCount() == extra.getPositionCount(); + LongBlock output = (LongBlock) outputUncast; + assert top.getPositionCount() == output.getPositionCount(); for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { if (groups.isNull(groupPosition)) { continue; @@ -213,13 +213,13 @@ public void addIntermediateInput(int positionOffset, IntArrayBlock groups, Page for (int g = groupStart; g < groupEnd; g++) { int groupId = groups.getInt(g); int valuesPosition = groupPosition + positionOffset; - TopDoubleLongAggregator.combineIntermediate(state, groupId, top, extra, valuesPosition); + TopDoubleLongAggregator.combineIntermediate(state, groupId, top, output, valuesPosition); } } } private void addRawInput(int positionOffset, IntBigArrayBlock groups, DoubleBlock vBlock, - LongBlock extraBlock) { + LongBlock outputValueBlock) { for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { if (groups.isNull(groupPosition)) { continue; @@ -228,7 +228,7 @@ private void addRawInput(int positionOffset, IntBigArrayBlock groups, DoubleBloc if (vBlock.isNull(valuesPosition)) { continue; } - if (extraBlock.isNull(valuesPosition)) { + if (outputValueBlock.isNull(valuesPosition)) { continue; } int groupStart = groups.getFirstValueIndex(groupPosition); @@ -239,11 +239,11 @@ private void addRawInput(int positionOffset, IntBigArrayBlock groups, DoubleBloc int vEnd = vStart + vBlock.getValueCount(valuesPosition); for (int vOffset = vStart; vOffset < vEnd; vOffset++) { double vValue = vBlock.getDouble(vOffset); - int extraStart = extraBlock.getFirstValueIndex(valuesPosition); - int extraEnd = extraStart + extraBlock.getValueCount(valuesPosition); - for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { - long extraValue = extraBlock.getLong(extraOffset); - TopDoubleLongAggregator.combine(state, groupId, vValue, extraValue); + int outputValueStart = outputValueBlock.getFirstValueIndex(valuesPosition); + int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(valuesPosition); + for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { + long outputValueValue = outputValueBlock.getLong(outputValueOffset); + TopDoubleLongAggregator.combine(state, groupId, vValue, outputValueValue); } } } @@ -251,7 +251,7 @@ private void addRawInput(int positionOffset, IntBigArrayBlock groups, DoubleBloc } private void addRawInput(int positionOffset, IntBigArrayBlock groups, DoubleVector vVector, - LongVector extraVector) { + LongVector outputValueVector) { for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { if (groups.isNull(groupPosition)) { continue; @@ -262,8 +262,8 @@ private void addRawInput(int positionOffset, IntBigArrayBlock groups, DoubleVect for (int g = groupStart; g < groupEnd; g++) { int groupId = groups.getInt(g); double vValue = vVector.getDouble(valuesPosition); - long extraValue = extraVector.getLong(valuesPosition); - TopDoubleLongAggregator.combine(state, groupId, vValue, extraValue); + long outputValueValue = outputValueVector.getLong(valuesPosition); + TopDoubleLongAggregator.combine(state, groupId, vValue, outputValueValue); } } } @@ -277,12 +277,12 @@ public void addIntermediateInput(int positionOffset, IntBigArrayBlock groups, Pa return; } DoubleBlock top = (DoubleBlock) topUncast; - Block extraUncast = page.getBlock(channels.get(1)); - if (extraUncast.areAllValuesNull()) { + Block outputUncast = page.getBlock(channels.get(1)); + if (outputUncast.areAllValuesNull()) { return; } - LongBlock extra = (LongBlock) extraUncast; - assert top.getPositionCount() == extra.getPositionCount(); + LongBlock output = (LongBlock) outputUncast; + assert top.getPositionCount() == output.getPositionCount(); for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { if (groups.isNull(groupPosition)) { continue; @@ -292,19 +292,19 @@ public void addIntermediateInput(int positionOffset, IntBigArrayBlock groups, Pa for (int g = groupStart; g < groupEnd; g++) { int groupId = groups.getInt(g); int valuesPosition = groupPosition + positionOffset; - TopDoubleLongAggregator.combineIntermediate(state, groupId, top, extra, valuesPosition); + TopDoubleLongAggregator.combineIntermediate(state, groupId, top, output, valuesPosition); } } } private void addRawInput(int positionOffset, IntVector groups, DoubleBlock vBlock, - LongBlock extraBlock) { + LongBlock outputValueBlock) { for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { int valuesPosition = groupPosition + positionOffset; if (vBlock.isNull(valuesPosition)) { continue; } - if (extraBlock.isNull(valuesPosition)) { + if (outputValueBlock.isNull(valuesPosition)) { continue; } int groupId = groups.getInt(groupPosition); @@ -312,24 +312,24 @@ private void addRawInput(int positionOffset, IntVector groups, DoubleBlock vBloc int vEnd = vStart + vBlock.getValueCount(valuesPosition); for (int vOffset = vStart; vOffset < vEnd; vOffset++) { double vValue = vBlock.getDouble(vOffset); - int extraStart = extraBlock.getFirstValueIndex(valuesPosition); - int extraEnd = extraStart + extraBlock.getValueCount(valuesPosition); - for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { - long extraValue = extraBlock.getLong(extraOffset); - TopDoubleLongAggregator.combine(state, groupId, vValue, extraValue); + int outputValueStart = outputValueBlock.getFirstValueIndex(valuesPosition); + int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(valuesPosition); + for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { + long outputValueValue = outputValueBlock.getLong(outputValueOffset); + TopDoubleLongAggregator.combine(state, groupId, vValue, outputValueValue); } } } } private void addRawInput(int positionOffset, IntVector groups, DoubleVector vVector, - LongVector extraVector) { + LongVector outputValueVector) { for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { int valuesPosition = groupPosition + positionOffset; int groupId = groups.getInt(groupPosition); double vValue = vVector.getDouble(valuesPosition); - long extraValue = extraVector.getLong(valuesPosition); - TopDoubleLongAggregator.combine(state, groupId, vValue, extraValue); + long outputValueValue = outputValueVector.getLong(valuesPosition); + TopDoubleLongAggregator.combine(state, groupId, vValue, outputValueValue); } } @@ -342,25 +342,25 @@ public void addIntermediateInput(int positionOffset, IntVector groups, Page page return; } DoubleBlock top = (DoubleBlock) topUncast; - Block extraUncast = page.getBlock(channels.get(1)); - if (extraUncast.areAllValuesNull()) { + Block outputUncast = page.getBlock(channels.get(1)); + if (outputUncast.areAllValuesNull()) { return; } - LongBlock extra = (LongBlock) extraUncast; - assert top.getPositionCount() == extra.getPositionCount(); + LongBlock output = (LongBlock) outputUncast; + assert top.getPositionCount() == output.getPositionCount(); for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { int groupId = groups.getInt(groupPosition); int valuesPosition = groupPosition + positionOffset; - TopDoubleLongAggregator.combineIntermediate(state, groupId, top, extra, valuesPosition); + TopDoubleLongAggregator.combineIntermediate(state, groupId, top, output, valuesPosition); } } private void maybeEnableGroupIdTracking(SeenGroupIds seenGroupIds, DoubleBlock vBlock, - LongBlock extraBlock) { + LongBlock outputValueBlock) { if (vBlock.mayHaveNulls()) { state.enableGroupIdTracking(seenGroupIds); } - if (extraBlock.mayHaveNulls()) { + if (outputValueBlock.mayHaveNulls()) { state.enableGroupIdTracking(seenGroupIds); } } diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatDoubleAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatDoubleAggregatorFunction.java index 7de2b10e4938e..4f918eb079b72 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatDoubleAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatDoubleAggregatorFunction.java @@ -26,7 +26,7 @@ public final class TopFloatDoubleAggregatorFunction implements AggregatorFunction { private static final List INTERMEDIATE_STATE_DESC = List.of( new IntermediateStateDesc("top", ElementType.FLOAT), - new IntermediateStateDesc("extra", ElementType.DOUBLE) ); + new IntermediateStateDesc("output", ElementType.DOUBLE) ); private final DriverContext driverContext; @@ -74,78 +74,79 @@ public void addRawInput(Page page, BooleanVector mask) { private void addRawInputMasked(Page page, BooleanVector mask) { FloatBlock vBlock = page.getBlock(channels.get(0)); - DoubleBlock extraBlock = page.getBlock(channels.get(1)); + DoubleBlock outputValueBlock = page.getBlock(channels.get(1)); FloatVector vVector = vBlock.asVector(); if (vVector == null) { - addRawBlock(vBlock, extraBlock, mask); + addRawBlock(vBlock, outputValueBlock, mask); return; } - DoubleVector extraVector = extraBlock.asVector(); - if (extraVector == null) { - addRawBlock(vBlock, extraBlock, mask); + DoubleVector outputValueVector = outputValueBlock.asVector(); + if (outputValueVector == null) { + addRawBlock(vBlock, outputValueBlock, mask); return; } - addRawVector(vVector, extraVector, mask); + addRawVector(vVector, outputValueVector, mask); } private void addRawInputNotMasked(Page page) { FloatBlock vBlock = page.getBlock(channels.get(0)); - DoubleBlock extraBlock = page.getBlock(channels.get(1)); + DoubleBlock outputValueBlock = page.getBlock(channels.get(1)); FloatVector vVector = vBlock.asVector(); if (vVector == null) { - addRawBlock(vBlock, extraBlock); + addRawBlock(vBlock, outputValueBlock); return; } - DoubleVector extraVector = extraBlock.asVector(); - if (extraVector == null) { - addRawBlock(vBlock, extraBlock); + DoubleVector outputValueVector = outputValueBlock.asVector(); + if (outputValueVector == null) { + addRawBlock(vBlock, outputValueBlock); return; } - addRawVector(vVector, extraVector); + addRawVector(vVector, outputValueVector); } - private void addRawVector(FloatVector vVector, DoubleVector extraVector) { + private void addRawVector(FloatVector vVector, DoubleVector outputValueVector) { for (int valuesPosition = 0; valuesPosition < vVector.getPositionCount(); valuesPosition++) { float vValue = vVector.getFloat(valuesPosition); - double extraValue = extraVector.getDouble(valuesPosition); - TopFloatDoubleAggregator.combine(state, vValue, extraValue); + double outputValueValue = outputValueVector.getDouble(valuesPosition); + TopFloatDoubleAggregator.combine(state, vValue, outputValueValue); } } - private void addRawVector(FloatVector vVector, DoubleVector extraVector, BooleanVector mask) { + private void addRawVector(FloatVector vVector, DoubleVector outputValueVector, + BooleanVector mask) { for (int valuesPosition = 0; valuesPosition < vVector.getPositionCount(); valuesPosition++) { if (mask.getBoolean(valuesPosition) == false) { continue; } float vValue = vVector.getFloat(valuesPosition); - double extraValue = extraVector.getDouble(valuesPosition); - TopFloatDoubleAggregator.combine(state, vValue, extraValue); + double outputValueValue = outputValueVector.getDouble(valuesPosition); + TopFloatDoubleAggregator.combine(state, vValue, outputValueValue); } } - private void addRawBlock(FloatBlock vBlock, DoubleBlock extraBlock) { + private void addRawBlock(FloatBlock vBlock, DoubleBlock outputValueBlock) { for (int p = 0; p < vBlock.getPositionCount(); p++) { if (vBlock.isNull(p)) { continue; } - if (extraBlock.isNull(p)) { + if (outputValueBlock.isNull(p)) { continue; } int vStart = vBlock.getFirstValueIndex(p); int vEnd = vStart + vBlock.getValueCount(p); for (int vOffset = vStart; vOffset < vEnd; vOffset++) { float vValue = vBlock.getFloat(vOffset); - int extraStart = extraBlock.getFirstValueIndex(p); - int extraEnd = extraStart + extraBlock.getValueCount(p); - for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { - double extraValue = extraBlock.getDouble(extraOffset); - TopFloatDoubleAggregator.combine(state, vValue, extraValue); + int outputValueStart = outputValueBlock.getFirstValueIndex(p); + int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(p); + for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { + double outputValueValue = outputValueBlock.getDouble(outputValueOffset); + TopFloatDoubleAggregator.combine(state, vValue, outputValueValue); } } } } - private void addRawBlock(FloatBlock vBlock, DoubleBlock extraBlock, BooleanVector mask) { + private void addRawBlock(FloatBlock vBlock, DoubleBlock outputValueBlock, BooleanVector mask) { for (int p = 0; p < vBlock.getPositionCount(); p++) { if (mask.getBoolean(p) == false) { continue; @@ -153,18 +154,18 @@ private void addRawBlock(FloatBlock vBlock, DoubleBlock extraBlock, BooleanVecto if (vBlock.isNull(p)) { continue; } - if (extraBlock.isNull(p)) { + if (outputValueBlock.isNull(p)) { continue; } int vStart = vBlock.getFirstValueIndex(p); int vEnd = vStart + vBlock.getValueCount(p); for (int vOffset = vStart; vOffset < vEnd; vOffset++) { float vValue = vBlock.getFloat(vOffset); - int extraStart = extraBlock.getFirstValueIndex(p); - int extraEnd = extraStart + extraBlock.getValueCount(p); - for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { - double extraValue = extraBlock.getDouble(extraOffset); - TopFloatDoubleAggregator.combine(state, vValue, extraValue); + int outputValueStart = outputValueBlock.getFirstValueIndex(p); + int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(p); + for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { + double outputValueValue = outputValueBlock.getDouble(outputValueOffset); + TopFloatDoubleAggregator.combine(state, vValue, outputValueValue); } } } @@ -180,13 +181,13 @@ public void addIntermediateInput(Page page) { } FloatBlock top = (FloatBlock) topUncast; assert top.getPositionCount() == 1; - Block extraUncast = page.getBlock(channels.get(1)); - if (extraUncast.areAllValuesNull()) { + Block outputUncast = page.getBlock(channels.get(1)); + if (outputUncast.areAllValuesNull()) { return; } - DoubleBlock extra = (DoubleBlock) extraUncast; - assert extra.getPositionCount() == 1; - TopFloatDoubleAggregator.combineIntermediate(state, top, extra); + DoubleBlock output = (DoubleBlock) outputUncast; + assert output.getPositionCount() == 1; + TopFloatDoubleAggregator.combineIntermediate(state, top, output); } @Override diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatDoubleGroupingAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatDoubleGroupingAggregatorFunction.java index 11d8bbe9c6ff2..a4fe8f7a107e9 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatDoubleGroupingAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatDoubleGroupingAggregatorFunction.java @@ -28,7 +28,7 @@ public final class TopFloatDoubleGroupingAggregatorFunction implements GroupingAggregatorFunction { private static final List INTERMEDIATE_STATE_DESC = List.of( new IntermediateStateDesc("top", ElementType.FLOAT), - new IntermediateStateDesc("extra", ElementType.DOUBLE) ); + new IntermediateStateDesc("output", ElementType.DOUBLE) ); private final TopFloatDoubleAggregator.GroupingState state; @@ -68,24 +68,24 @@ public int intermediateBlockCount() { public GroupingAggregatorFunction.AddInput prepareProcessRawInputPage(SeenGroupIds seenGroupIds, Page page) { FloatBlock vBlock = page.getBlock(channels.get(0)); - DoubleBlock extraBlock = page.getBlock(channels.get(1)); + DoubleBlock outputValueBlock = page.getBlock(channels.get(1)); FloatVector vVector = vBlock.asVector(); if (vVector == null) { - maybeEnableGroupIdTracking(seenGroupIds, vBlock, extraBlock); + maybeEnableGroupIdTracking(seenGroupIds, vBlock, outputValueBlock); return new GroupingAggregatorFunction.AddInput() { @Override public void add(int positionOffset, IntArrayBlock groupIds) { - addRawInput(positionOffset, groupIds, vBlock, extraBlock); + addRawInput(positionOffset, groupIds, vBlock, outputValueBlock); } @Override public void add(int positionOffset, IntBigArrayBlock groupIds) { - addRawInput(positionOffset, groupIds, vBlock, extraBlock); + addRawInput(positionOffset, groupIds, vBlock, outputValueBlock); } @Override public void add(int positionOffset, IntVector groupIds) { - addRawInput(positionOffset, groupIds, vBlock, extraBlock); + addRawInput(positionOffset, groupIds, vBlock, outputValueBlock); } @Override @@ -93,23 +93,23 @@ public void close() { } }; } - DoubleVector extraVector = extraBlock.asVector(); - if (extraVector == null) { - maybeEnableGroupIdTracking(seenGroupIds, vBlock, extraBlock); + DoubleVector outputValueVector = outputValueBlock.asVector(); + if (outputValueVector == null) { + maybeEnableGroupIdTracking(seenGroupIds, vBlock, outputValueBlock); return new GroupingAggregatorFunction.AddInput() { @Override public void add(int positionOffset, IntArrayBlock groupIds) { - addRawInput(positionOffset, groupIds, vBlock, extraBlock); + addRawInput(positionOffset, groupIds, vBlock, outputValueBlock); } @Override public void add(int positionOffset, IntBigArrayBlock groupIds) { - addRawInput(positionOffset, groupIds, vBlock, extraBlock); + addRawInput(positionOffset, groupIds, vBlock, outputValueBlock); } @Override public void add(int positionOffset, IntVector groupIds) { - addRawInput(positionOffset, groupIds, vBlock, extraBlock); + addRawInput(positionOffset, groupIds, vBlock, outputValueBlock); } @Override @@ -120,17 +120,17 @@ public void close() { return new GroupingAggregatorFunction.AddInput() { @Override public void add(int positionOffset, IntArrayBlock groupIds) { - addRawInput(positionOffset, groupIds, vVector, extraVector); + addRawInput(positionOffset, groupIds, vVector, outputValueVector); } @Override public void add(int positionOffset, IntBigArrayBlock groupIds) { - addRawInput(positionOffset, groupIds, vVector, extraVector); + addRawInput(positionOffset, groupIds, vVector, outputValueVector); } @Override public void add(int positionOffset, IntVector groupIds) { - addRawInput(positionOffset, groupIds, vVector, extraVector); + addRawInput(positionOffset, groupIds, vVector, outputValueVector); } @Override @@ -140,7 +140,7 @@ public void close() { } private void addRawInput(int positionOffset, IntArrayBlock groups, FloatBlock vBlock, - DoubleBlock extraBlock) { + DoubleBlock outputValueBlock) { for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { if (groups.isNull(groupPosition)) { continue; @@ -149,7 +149,7 @@ private void addRawInput(int positionOffset, IntArrayBlock groups, FloatBlock vB if (vBlock.isNull(valuesPosition)) { continue; } - if (extraBlock.isNull(valuesPosition)) { + if (outputValueBlock.isNull(valuesPosition)) { continue; } int groupStart = groups.getFirstValueIndex(groupPosition); @@ -160,11 +160,11 @@ private void addRawInput(int positionOffset, IntArrayBlock groups, FloatBlock vB int vEnd = vStart + vBlock.getValueCount(valuesPosition); for (int vOffset = vStart; vOffset < vEnd; vOffset++) { float vValue = vBlock.getFloat(vOffset); - int extraStart = extraBlock.getFirstValueIndex(valuesPosition); - int extraEnd = extraStart + extraBlock.getValueCount(valuesPosition); - for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { - double extraValue = extraBlock.getDouble(extraOffset); - TopFloatDoubleAggregator.combine(state, groupId, vValue, extraValue); + int outputValueStart = outputValueBlock.getFirstValueIndex(valuesPosition); + int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(valuesPosition); + for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { + double outputValueValue = outputValueBlock.getDouble(outputValueOffset); + TopFloatDoubleAggregator.combine(state, groupId, vValue, outputValueValue); } } } @@ -172,7 +172,7 @@ private void addRawInput(int positionOffset, IntArrayBlock groups, FloatBlock vB } private void addRawInput(int positionOffset, IntArrayBlock groups, FloatVector vVector, - DoubleVector extraVector) { + DoubleVector outputValueVector) { for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { if (groups.isNull(groupPosition)) { continue; @@ -183,8 +183,8 @@ private void addRawInput(int positionOffset, IntArrayBlock groups, FloatVector v for (int g = groupStart; g < groupEnd; g++) { int groupId = groups.getInt(g); float vValue = vVector.getFloat(valuesPosition); - double extraValue = extraVector.getDouble(valuesPosition); - TopFloatDoubleAggregator.combine(state, groupId, vValue, extraValue); + double outputValueValue = outputValueVector.getDouble(valuesPosition); + TopFloatDoubleAggregator.combine(state, groupId, vValue, outputValueValue); } } } @@ -198,12 +198,12 @@ public void addIntermediateInput(int positionOffset, IntArrayBlock groups, Page return; } FloatBlock top = (FloatBlock) topUncast; - Block extraUncast = page.getBlock(channels.get(1)); - if (extraUncast.areAllValuesNull()) { + Block outputUncast = page.getBlock(channels.get(1)); + if (outputUncast.areAllValuesNull()) { return; } - DoubleBlock extra = (DoubleBlock) extraUncast; - assert top.getPositionCount() == extra.getPositionCount(); + DoubleBlock output = (DoubleBlock) outputUncast; + assert top.getPositionCount() == output.getPositionCount(); for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { if (groups.isNull(groupPosition)) { continue; @@ -213,13 +213,13 @@ public void addIntermediateInput(int positionOffset, IntArrayBlock groups, Page for (int g = groupStart; g < groupEnd; g++) { int groupId = groups.getInt(g); int valuesPosition = groupPosition + positionOffset; - TopFloatDoubleAggregator.combineIntermediate(state, groupId, top, extra, valuesPosition); + TopFloatDoubleAggregator.combineIntermediate(state, groupId, top, output, valuesPosition); } } } private void addRawInput(int positionOffset, IntBigArrayBlock groups, FloatBlock vBlock, - DoubleBlock extraBlock) { + DoubleBlock outputValueBlock) { for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { if (groups.isNull(groupPosition)) { continue; @@ -228,7 +228,7 @@ private void addRawInput(int positionOffset, IntBigArrayBlock groups, FloatBlock if (vBlock.isNull(valuesPosition)) { continue; } - if (extraBlock.isNull(valuesPosition)) { + if (outputValueBlock.isNull(valuesPosition)) { continue; } int groupStart = groups.getFirstValueIndex(groupPosition); @@ -239,11 +239,11 @@ private void addRawInput(int positionOffset, IntBigArrayBlock groups, FloatBlock int vEnd = vStart + vBlock.getValueCount(valuesPosition); for (int vOffset = vStart; vOffset < vEnd; vOffset++) { float vValue = vBlock.getFloat(vOffset); - int extraStart = extraBlock.getFirstValueIndex(valuesPosition); - int extraEnd = extraStart + extraBlock.getValueCount(valuesPosition); - for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { - double extraValue = extraBlock.getDouble(extraOffset); - TopFloatDoubleAggregator.combine(state, groupId, vValue, extraValue); + int outputValueStart = outputValueBlock.getFirstValueIndex(valuesPosition); + int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(valuesPosition); + for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { + double outputValueValue = outputValueBlock.getDouble(outputValueOffset); + TopFloatDoubleAggregator.combine(state, groupId, vValue, outputValueValue); } } } @@ -251,7 +251,7 @@ private void addRawInput(int positionOffset, IntBigArrayBlock groups, FloatBlock } private void addRawInput(int positionOffset, IntBigArrayBlock groups, FloatVector vVector, - DoubleVector extraVector) { + DoubleVector outputValueVector) { for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { if (groups.isNull(groupPosition)) { continue; @@ -262,8 +262,8 @@ private void addRawInput(int positionOffset, IntBigArrayBlock groups, FloatVecto for (int g = groupStart; g < groupEnd; g++) { int groupId = groups.getInt(g); float vValue = vVector.getFloat(valuesPosition); - double extraValue = extraVector.getDouble(valuesPosition); - TopFloatDoubleAggregator.combine(state, groupId, vValue, extraValue); + double outputValueValue = outputValueVector.getDouble(valuesPosition); + TopFloatDoubleAggregator.combine(state, groupId, vValue, outputValueValue); } } } @@ -277,12 +277,12 @@ public void addIntermediateInput(int positionOffset, IntBigArrayBlock groups, Pa return; } FloatBlock top = (FloatBlock) topUncast; - Block extraUncast = page.getBlock(channels.get(1)); - if (extraUncast.areAllValuesNull()) { + Block outputUncast = page.getBlock(channels.get(1)); + if (outputUncast.areAllValuesNull()) { return; } - DoubleBlock extra = (DoubleBlock) extraUncast; - assert top.getPositionCount() == extra.getPositionCount(); + DoubleBlock output = (DoubleBlock) outputUncast; + assert top.getPositionCount() == output.getPositionCount(); for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { if (groups.isNull(groupPosition)) { continue; @@ -292,19 +292,19 @@ public void addIntermediateInput(int positionOffset, IntBigArrayBlock groups, Pa for (int g = groupStart; g < groupEnd; g++) { int groupId = groups.getInt(g); int valuesPosition = groupPosition + positionOffset; - TopFloatDoubleAggregator.combineIntermediate(state, groupId, top, extra, valuesPosition); + TopFloatDoubleAggregator.combineIntermediate(state, groupId, top, output, valuesPosition); } } } private void addRawInput(int positionOffset, IntVector groups, FloatBlock vBlock, - DoubleBlock extraBlock) { + DoubleBlock outputValueBlock) { for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { int valuesPosition = groupPosition + positionOffset; if (vBlock.isNull(valuesPosition)) { continue; } - if (extraBlock.isNull(valuesPosition)) { + if (outputValueBlock.isNull(valuesPosition)) { continue; } int groupId = groups.getInt(groupPosition); @@ -312,24 +312,24 @@ private void addRawInput(int positionOffset, IntVector groups, FloatBlock vBlock int vEnd = vStart + vBlock.getValueCount(valuesPosition); for (int vOffset = vStart; vOffset < vEnd; vOffset++) { float vValue = vBlock.getFloat(vOffset); - int extraStart = extraBlock.getFirstValueIndex(valuesPosition); - int extraEnd = extraStart + extraBlock.getValueCount(valuesPosition); - for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { - double extraValue = extraBlock.getDouble(extraOffset); - TopFloatDoubleAggregator.combine(state, groupId, vValue, extraValue); + int outputValueStart = outputValueBlock.getFirstValueIndex(valuesPosition); + int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(valuesPosition); + for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { + double outputValueValue = outputValueBlock.getDouble(outputValueOffset); + TopFloatDoubleAggregator.combine(state, groupId, vValue, outputValueValue); } } } } private void addRawInput(int positionOffset, IntVector groups, FloatVector vVector, - DoubleVector extraVector) { + DoubleVector outputValueVector) { for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { int valuesPosition = groupPosition + positionOffset; int groupId = groups.getInt(groupPosition); float vValue = vVector.getFloat(valuesPosition); - double extraValue = extraVector.getDouble(valuesPosition); - TopFloatDoubleAggregator.combine(state, groupId, vValue, extraValue); + double outputValueValue = outputValueVector.getDouble(valuesPosition); + TopFloatDoubleAggregator.combine(state, groupId, vValue, outputValueValue); } } @@ -342,25 +342,25 @@ public void addIntermediateInput(int positionOffset, IntVector groups, Page page return; } FloatBlock top = (FloatBlock) topUncast; - Block extraUncast = page.getBlock(channels.get(1)); - if (extraUncast.areAllValuesNull()) { + Block outputUncast = page.getBlock(channels.get(1)); + if (outputUncast.areAllValuesNull()) { return; } - DoubleBlock extra = (DoubleBlock) extraUncast; - assert top.getPositionCount() == extra.getPositionCount(); + DoubleBlock output = (DoubleBlock) outputUncast; + assert top.getPositionCount() == output.getPositionCount(); for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { int groupId = groups.getInt(groupPosition); int valuesPosition = groupPosition + positionOffset; - TopFloatDoubleAggregator.combineIntermediate(state, groupId, top, extra, valuesPosition); + TopFloatDoubleAggregator.combineIntermediate(state, groupId, top, output, valuesPosition); } } private void maybeEnableGroupIdTracking(SeenGroupIds seenGroupIds, FloatBlock vBlock, - DoubleBlock extraBlock) { + DoubleBlock outputValueBlock) { if (vBlock.mayHaveNulls()) { state.enableGroupIdTracking(seenGroupIds); } - if (extraBlock.mayHaveNulls()) { + if (outputValueBlock.mayHaveNulls()) { state.enableGroupIdTracking(seenGroupIds); } } diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatFloatAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatFloatAggregatorFunction.java index 0d5d4cf441d14..7f314a111a055 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatFloatAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatFloatAggregatorFunction.java @@ -24,7 +24,7 @@ public final class TopFloatFloatAggregatorFunction implements AggregatorFunction { private static final List INTERMEDIATE_STATE_DESC = List.of( new IntermediateStateDesc("top", ElementType.FLOAT), - new IntermediateStateDesc("extra", ElementType.FLOAT) ); + new IntermediateStateDesc("output", ElementType.FLOAT) ); private final DriverContext driverContext; @@ -72,78 +72,79 @@ public void addRawInput(Page page, BooleanVector mask) { private void addRawInputMasked(Page page, BooleanVector mask) { FloatBlock vBlock = page.getBlock(channels.get(0)); - FloatBlock extraBlock = page.getBlock(channels.get(1)); + FloatBlock outputValueBlock = page.getBlock(channels.get(1)); FloatVector vVector = vBlock.asVector(); if (vVector == null) { - addRawBlock(vBlock, extraBlock, mask); + addRawBlock(vBlock, outputValueBlock, mask); return; } - FloatVector extraVector = extraBlock.asVector(); - if (extraVector == null) { - addRawBlock(vBlock, extraBlock, mask); + FloatVector outputValueVector = outputValueBlock.asVector(); + if (outputValueVector == null) { + addRawBlock(vBlock, outputValueBlock, mask); return; } - addRawVector(vVector, extraVector, mask); + addRawVector(vVector, outputValueVector, mask); } private void addRawInputNotMasked(Page page) { FloatBlock vBlock = page.getBlock(channels.get(0)); - FloatBlock extraBlock = page.getBlock(channels.get(1)); + FloatBlock outputValueBlock = page.getBlock(channels.get(1)); FloatVector vVector = vBlock.asVector(); if (vVector == null) { - addRawBlock(vBlock, extraBlock); + addRawBlock(vBlock, outputValueBlock); return; } - FloatVector extraVector = extraBlock.asVector(); - if (extraVector == null) { - addRawBlock(vBlock, extraBlock); + FloatVector outputValueVector = outputValueBlock.asVector(); + if (outputValueVector == null) { + addRawBlock(vBlock, outputValueBlock); return; } - addRawVector(vVector, extraVector); + addRawVector(vVector, outputValueVector); } - private void addRawVector(FloatVector vVector, FloatVector extraVector) { + private void addRawVector(FloatVector vVector, FloatVector outputValueVector) { for (int valuesPosition = 0; valuesPosition < vVector.getPositionCount(); valuesPosition++) { float vValue = vVector.getFloat(valuesPosition); - float extraValue = extraVector.getFloat(valuesPosition); - TopFloatFloatAggregator.combine(state, vValue, extraValue); + float outputValueValue = outputValueVector.getFloat(valuesPosition); + TopFloatFloatAggregator.combine(state, vValue, outputValueValue); } } - private void addRawVector(FloatVector vVector, FloatVector extraVector, BooleanVector mask) { + private void addRawVector(FloatVector vVector, FloatVector outputValueVector, + BooleanVector mask) { for (int valuesPosition = 0; valuesPosition < vVector.getPositionCount(); valuesPosition++) { if (mask.getBoolean(valuesPosition) == false) { continue; } float vValue = vVector.getFloat(valuesPosition); - float extraValue = extraVector.getFloat(valuesPosition); - TopFloatFloatAggregator.combine(state, vValue, extraValue); + float outputValueValue = outputValueVector.getFloat(valuesPosition); + TopFloatFloatAggregator.combine(state, vValue, outputValueValue); } } - private void addRawBlock(FloatBlock vBlock, FloatBlock extraBlock) { + private void addRawBlock(FloatBlock vBlock, FloatBlock outputValueBlock) { for (int p = 0; p < vBlock.getPositionCount(); p++) { if (vBlock.isNull(p)) { continue; } - if (extraBlock.isNull(p)) { + if (outputValueBlock.isNull(p)) { continue; } int vStart = vBlock.getFirstValueIndex(p); int vEnd = vStart + vBlock.getValueCount(p); for (int vOffset = vStart; vOffset < vEnd; vOffset++) { float vValue = vBlock.getFloat(vOffset); - int extraStart = extraBlock.getFirstValueIndex(p); - int extraEnd = extraStart + extraBlock.getValueCount(p); - for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { - float extraValue = extraBlock.getFloat(extraOffset); - TopFloatFloatAggregator.combine(state, vValue, extraValue); + int outputValueStart = outputValueBlock.getFirstValueIndex(p); + int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(p); + for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { + float outputValueValue = outputValueBlock.getFloat(outputValueOffset); + TopFloatFloatAggregator.combine(state, vValue, outputValueValue); } } } } - private void addRawBlock(FloatBlock vBlock, FloatBlock extraBlock, BooleanVector mask) { + private void addRawBlock(FloatBlock vBlock, FloatBlock outputValueBlock, BooleanVector mask) { for (int p = 0; p < vBlock.getPositionCount(); p++) { if (mask.getBoolean(p) == false) { continue; @@ -151,18 +152,18 @@ private void addRawBlock(FloatBlock vBlock, FloatBlock extraBlock, BooleanVector if (vBlock.isNull(p)) { continue; } - if (extraBlock.isNull(p)) { + if (outputValueBlock.isNull(p)) { continue; } int vStart = vBlock.getFirstValueIndex(p); int vEnd = vStart + vBlock.getValueCount(p); for (int vOffset = vStart; vOffset < vEnd; vOffset++) { float vValue = vBlock.getFloat(vOffset); - int extraStart = extraBlock.getFirstValueIndex(p); - int extraEnd = extraStart + extraBlock.getValueCount(p); - for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { - float extraValue = extraBlock.getFloat(extraOffset); - TopFloatFloatAggregator.combine(state, vValue, extraValue); + int outputValueStart = outputValueBlock.getFirstValueIndex(p); + int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(p); + for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { + float outputValueValue = outputValueBlock.getFloat(outputValueOffset); + TopFloatFloatAggregator.combine(state, vValue, outputValueValue); } } } @@ -178,13 +179,13 @@ public void addIntermediateInput(Page page) { } FloatBlock top = (FloatBlock) topUncast; assert top.getPositionCount() == 1; - Block extraUncast = page.getBlock(channels.get(1)); - if (extraUncast.areAllValuesNull()) { + Block outputUncast = page.getBlock(channels.get(1)); + if (outputUncast.areAllValuesNull()) { return; } - FloatBlock extra = (FloatBlock) extraUncast; - assert extra.getPositionCount() == 1; - TopFloatFloatAggregator.combineIntermediate(state, top, extra); + FloatBlock output = (FloatBlock) outputUncast; + assert output.getPositionCount() == 1; + TopFloatFloatAggregator.combineIntermediate(state, top, output); } @Override diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatFloatGroupingAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatFloatGroupingAggregatorFunction.java index 25b900fe6b047..6d955b01f352c 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatFloatGroupingAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatFloatGroupingAggregatorFunction.java @@ -26,7 +26,7 @@ public final class TopFloatFloatGroupingAggregatorFunction implements GroupingAggregatorFunction { private static final List INTERMEDIATE_STATE_DESC = List.of( new IntermediateStateDesc("top", ElementType.FLOAT), - new IntermediateStateDesc("extra", ElementType.FLOAT) ); + new IntermediateStateDesc("output", ElementType.FLOAT) ); private final TopFloatFloatAggregator.GroupingState state; @@ -66,24 +66,24 @@ public int intermediateBlockCount() { public GroupingAggregatorFunction.AddInput prepareProcessRawInputPage(SeenGroupIds seenGroupIds, Page page) { FloatBlock vBlock = page.getBlock(channels.get(0)); - FloatBlock extraBlock = page.getBlock(channels.get(1)); + FloatBlock outputValueBlock = page.getBlock(channels.get(1)); FloatVector vVector = vBlock.asVector(); if (vVector == null) { - maybeEnableGroupIdTracking(seenGroupIds, vBlock, extraBlock); + maybeEnableGroupIdTracking(seenGroupIds, vBlock, outputValueBlock); return new GroupingAggregatorFunction.AddInput() { @Override public void add(int positionOffset, IntArrayBlock groupIds) { - addRawInput(positionOffset, groupIds, vBlock, extraBlock); + addRawInput(positionOffset, groupIds, vBlock, outputValueBlock); } @Override public void add(int positionOffset, IntBigArrayBlock groupIds) { - addRawInput(positionOffset, groupIds, vBlock, extraBlock); + addRawInput(positionOffset, groupIds, vBlock, outputValueBlock); } @Override public void add(int positionOffset, IntVector groupIds) { - addRawInput(positionOffset, groupIds, vBlock, extraBlock); + addRawInput(positionOffset, groupIds, vBlock, outputValueBlock); } @Override @@ -91,23 +91,23 @@ public void close() { } }; } - FloatVector extraVector = extraBlock.asVector(); - if (extraVector == null) { - maybeEnableGroupIdTracking(seenGroupIds, vBlock, extraBlock); + FloatVector outputValueVector = outputValueBlock.asVector(); + if (outputValueVector == null) { + maybeEnableGroupIdTracking(seenGroupIds, vBlock, outputValueBlock); return new GroupingAggregatorFunction.AddInput() { @Override public void add(int positionOffset, IntArrayBlock groupIds) { - addRawInput(positionOffset, groupIds, vBlock, extraBlock); + addRawInput(positionOffset, groupIds, vBlock, outputValueBlock); } @Override public void add(int positionOffset, IntBigArrayBlock groupIds) { - addRawInput(positionOffset, groupIds, vBlock, extraBlock); + addRawInput(positionOffset, groupIds, vBlock, outputValueBlock); } @Override public void add(int positionOffset, IntVector groupIds) { - addRawInput(positionOffset, groupIds, vBlock, extraBlock); + addRawInput(positionOffset, groupIds, vBlock, outputValueBlock); } @Override @@ -118,17 +118,17 @@ public void close() { return new GroupingAggregatorFunction.AddInput() { @Override public void add(int positionOffset, IntArrayBlock groupIds) { - addRawInput(positionOffset, groupIds, vVector, extraVector); + addRawInput(positionOffset, groupIds, vVector, outputValueVector); } @Override public void add(int positionOffset, IntBigArrayBlock groupIds) { - addRawInput(positionOffset, groupIds, vVector, extraVector); + addRawInput(positionOffset, groupIds, vVector, outputValueVector); } @Override public void add(int positionOffset, IntVector groupIds) { - addRawInput(positionOffset, groupIds, vVector, extraVector); + addRawInput(positionOffset, groupIds, vVector, outputValueVector); } @Override @@ -138,7 +138,7 @@ public void close() { } private void addRawInput(int positionOffset, IntArrayBlock groups, FloatBlock vBlock, - FloatBlock extraBlock) { + FloatBlock outputValueBlock) { for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { if (groups.isNull(groupPosition)) { continue; @@ -147,7 +147,7 @@ private void addRawInput(int positionOffset, IntArrayBlock groups, FloatBlock vB if (vBlock.isNull(valuesPosition)) { continue; } - if (extraBlock.isNull(valuesPosition)) { + if (outputValueBlock.isNull(valuesPosition)) { continue; } int groupStart = groups.getFirstValueIndex(groupPosition); @@ -158,11 +158,11 @@ private void addRawInput(int positionOffset, IntArrayBlock groups, FloatBlock vB int vEnd = vStart + vBlock.getValueCount(valuesPosition); for (int vOffset = vStart; vOffset < vEnd; vOffset++) { float vValue = vBlock.getFloat(vOffset); - int extraStart = extraBlock.getFirstValueIndex(valuesPosition); - int extraEnd = extraStart + extraBlock.getValueCount(valuesPosition); - for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { - float extraValue = extraBlock.getFloat(extraOffset); - TopFloatFloatAggregator.combine(state, groupId, vValue, extraValue); + int outputValueStart = outputValueBlock.getFirstValueIndex(valuesPosition); + int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(valuesPosition); + for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { + float outputValueValue = outputValueBlock.getFloat(outputValueOffset); + TopFloatFloatAggregator.combine(state, groupId, vValue, outputValueValue); } } } @@ -170,7 +170,7 @@ private void addRawInput(int positionOffset, IntArrayBlock groups, FloatBlock vB } private void addRawInput(int positionOffset, IntArrayBlock groups, FloatVector vVector, - FloatVector extraVector) { + FloatVector outputValueVector) { for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { if (groups.isNull(groupPosition)) { continue; @@ -181,8 +181,8 @@ private void addRawInput(int positionOffset, IntArrayBlock groups, FloatVector v for (int g = groupStart; g < groupEnd; g++) { int groupId = groups.getInt(g); float vValue = vVector.getFloat(valuesPosition); - float extraValue = extraVector.getFloat(valuesPosition); - TopFloatFloatAggregator.combine(state, groupId, vValue, extraValue); + float outputValueValue = outputValueVector.getFloat(valuesPosition); + TopFloatFloatAggregator.combine(state, groupId, vValue, outputValueValue); } } } @@ -196,12 +196,12 @@ public void addIntermediateInput(int positionOffset, IntArrayBlock groups, Page return; } FloatBlock top = (FloatBlock) topUncast; - Block extraUncast = page.getBlock(channels.get(1)); - if (extraUncast.areAllValuesNull()) { + Block outputUncast = page.getBlock(channels.get(1)); + if (outputUncast.areAllValuesNull()) { return; } - FloatBlock extra = (FloatBlock) extraUncast; - assert top.getPositionCount() == extra.getPositionCount(); + FloatBlock output = (FloatBlock) outputUncast; + assert top.getPositionCount() == output.getPositionCount(); for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { if (groups.isNull(groupPosition)) { continue; @@ -211,13 +211,13 @@ public void addIntermediateInput(int positionOffset, IntArrayBlock groups, Page for (int g = groupStart; g < groupEnd; g++) { int groupId = groups.getInt(g); int valuesPosition = groupPosition + positionOffset; - TopFloatFloatAggregator.combineIntermediate(state, groupId, top, extra, valuesPosition); + TopFloatFloatAggregator.combineIntermediate(state, groupId, top, output, valuesPosition); } } } private void addRawInput(int positionOffset, IntBigArrayBlock groups, FloatBlock vBlock, - FloatBlock extraBlock) { + FloatBlock outputValueBlock) { for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { if (groups.isNull(groupPosition)) { continue; @@ -226,7 +226,7 @@ private void addRawInput(int positionOffset, IntBigArrayBlock groups, FloatBlock if (vBlock.isNull(valuesPosition)) { continue; } - if (extraBlock.isNull(valuesPosition)) { + if (outputValueBlock.isNull(valuesPosition)) { continue; } int groupStart = groups.getFirstValueIndex(groupPosition); @@ -237,11 +237,11 @@ private void addRawInput(int positionOffset, IntBigArrayBlock groups, FloatBlock int vEnd = vStart + vBlock.getValueCount(valuesPosition); for (int vOffset = vStart; vOffset < vEnd; vOffset++) { float vValue = vBlock.getFloat(vOffset); - int extraStart = extraBlock.getFirstValueIndex(valuesPosition); - int extraEnd = extraStart + extraBlock.getValueCount(valuesPosition); - for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { - float extraValue = extraBlock.getFloat(extraOffset); - TopFloatFloatAggregator.combine(state, groupId, vValue, extraValue); + int outputValueStart = outputValueBlock.getFirstValueIndex(valuesPosition); + int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(valuesPosition); + for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { + float outputValueValue = outputValueBlock.getFloat(outputValueOffset); + TopFloatFloatAggregator.combine(state, groupId, vValue, outputValueValue); } } } @@ -249,7 +249,7 @@ private void addRawInput(int positionOffset, IntBigArrayBlock groups, FloatBlock } private void addRawInput(int positionOffset, IntBigArrayBlock groups, FloatVector vVector, - FloatVector extraVector) { + FloatVector outputValueVector) { for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { if (groups.isNull(groupPosition)) { continue; @@ -260,8 +260,8 @@ private void addRawInput(int positionOffset, IntBigArrayBlock groups, FloatVecto for (int g = groupStart; g < groupEnd; g++) { int groupId = groups.getInt(g); float vValue = vVector.getFloat(valuesPosition); - float extraValue = extraVector.getFloat(valuesPosition); - TopFloatFloatAggregator.combine(state, groupId, vValue, extraValue); + float outputValueValue = outputValueVector.getFloat(valuesPosition); + TopFloatFloatAggregator.combine(state, groupId, vValue, outputValueValue); } } } @@ -275,12 +275,12 @@ public void addIntermediateInput(int positionOffset, IntBigArrayBlock groups, Pa return; } FloatBlock top = (FloatBlock) topUncast; - Block extraUncast = page.getBlock(channels.get(1)); - if (extraUncast.areAllValuesNull()) { + Block outputUncast = page.getBlock(channels.get(1)); + if (outputUncast.areAllValuesNull()) { return; } - FloatBlock extra = (FloatBlock) extraUncast; - assert top.getPositionCount() == extra.getPositionCount(); + FloatBlock output = (FloatBlock) outputUncast; + assert top.getPositionCount() == output.getPositionCount(); for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { if (groups.isNull(groupPosition)) { continue; @@ -290,19 +290,19 @@ public void addIntermediateInput(int positionOffset, IntBigArrayBlock groups, Pa for (int g = groupStart; g < groupEnd; g++) { int groupId = groups.getInt(g); int valuesPosition = groupPosition + positionOffset; - TopFloatFloatAggregator.combineIntermediate(state, groupId, top, extra, valuesPosition); + TopFloatFloatAggregator.combineIntermediate(state, groupId, top, output, valuesPosition); } } } private void addRawInput(int positionOffset, IntVector groups, FloatBlock vBlock, - FloatBlock extraBlock) { + FloatBlock outputValueBlock) { for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { int valuesPosition = groupPosition + positionOffset; if (vBlock.isNull(valuesPosition)) { continue; } - if (extraBlock.isNull(valuesPosition)) { + if (outputValueBlock.isNull(valuesPosition)) { continue; } int groupId = groups.getInt(groupPosition); @@ -310,24 +310,24 @@ private void addRawInput(int positionOffset, IntVector groups, FloatBlock vBlock int vEnd = vStart + vBlock.getValueCount(valuesPosition); for (int vOffset = vStart; vOffset < vEnd; vOffset++) { float vValue = vBlock.getFloat(vOffset); - int extraStart = extraBlock.getFirstValueIndex(valuesPosition); - int extraEnd = extraStart + extraBlock.getValueCount(valuesPosition); - for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { - float extraValue = extraBlock.getFloat(extraOffset); - TopFloatFloatAggregator.combine(state, groupId, vValue, extraValue); + int outputValueStart = outputValueBlock.getFirstValueIndex(valuesPosition); + int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(valuesPosition); + for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { + float outputValueValue = outputValueBlock.getFloat(outputValueOffset); + TopFloatFloatAggregator.combine(state, groupId, vValue, outputValueValue); } } } } private void addRawInput(int positionOffset, IntVector groups, FloatVector vVector, - FloatVector extraVector) { + FloatVector outputValueVector) { for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { int valuesPosition = groupPosition + positionOffset; int groupId = groups.getInt(groupPosition); float vValue = vVector.getFloat(valuesPosition); - float extraValue = extraVector.getFloat(valuesPosition); - TopFloatFloatAggregator.combine(state, groupId, vValue, extraValue); + float outputValueValue = outputValueVector.getFloat(valuesPosition); + TopFloatFloatAggregator.combine(state, groupId, vValue, outputValueValue); } } @@ -340,25 +340,25 @@ public void addIntermediateInput(int positionOffset, IntVector groups, Page page return; } FloatBlock top = (FloatBlock) topUncast; - Block extraUncast = page.getBlock(channels.get(1)); - if (extraUncast.areAllValuesNull()) { + Block outputUncast = page.getBlock(channels.get(1)); + if (outputUncast.areAllValuesNull()) { return; } - FloatBlock extra = (FloatBlock) extraUncast; - assert top.getPositionCount() == extra.getPositionCount(); + FloatBlock output = (FloatBlock) outputUncast; + assert top.getPositionCount() == output.getPositionCount(); for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { int groupId = groups.getInt(groupPosition); int valuesPosition = groupPosition + positionOffset; - TopFloatFloatAggregator.combineIntermediate(state, groupId, top, extra, valuesPosition); + TopFloatFloatAggregator.combineIntermediate(state, groupId, top, output, valuesPosition); } } private void maybeEnableGroupIdTracking(SeenGroupIds seenGroupIds, FloatBlock vBlock, - FloatBlock extraBlock) { + FloatBlock outputValueBlock) { if (vBlock.mayHaveNulls()) { state.enableGroupIdTracking(seenGroupIds); } - if (extraBlock.mayHaveNulls()) { + if (outputValueBlock.mayHaveNulls()) { state.enableGroupIdTracking(seenGroupIds); } } diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatIntAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatIntAggregatorFunction.java index fef58724f4b9e..b3a4cee6d2b1c 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatIntAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatIntAggregatorFunction.java @@ -26,7 +26,7 @@ public final class TopFloatIntAggregatorFunction implements AggregatorFunction { private static final List INTERMEDIATE_STATE_DESC = List.of( new IntermediateStateDesc("top", ElementType.FLOAT), - new IntermediateStateDesc("extra", ElementType.INT) ); + new IntermediateStateDesc("output", ElementType.INT) ); private final DriverContext driverContext; @@ -74,78 +74,78 @@ public void addRawInput(Page page, BooleanVector mask) { private void addRawInputMasked(Page page, BooleanVector mask) { FloatBlock vBlock = page.getBlock(channels.get(0)); - IntBlock extraBlock = page.getBlock(channels.get(1)); + IntBlock outputValueBlock = page.getBlock(channels.get(1)); FloatVector vVector = vBlock.asVector(); if (vVector == null) { - addRawBlock(vBlock, extraBlock, mask); + addRawBlock(vBlock, outputValueBlock, mask); return; } - IntVector extraVector = extraBlock.asVector(); - if (extraVector == null) { - addRawBlock(vBlock, extraBlock, mask); + IntVector outputValueVector = outputValueBlock.asVector(); + if (outputValueVector == null) { + addRawBlock(vBlock, outputValueBlock, mask); return; } - addRawVector(vVector, extraVector, mask); + addRawVector(vVector, outputValueVector, mask); } private void addRawInputNotMasked(Page page) { FloatBlock vBlock = page.getBlock(channels.get(0)); - IntBlock extraBlock = page.getBlock(channels.get(1)); + IntBlock outputValueBlock = page.getBlock(channels.get(1)); FloatVector vVector = vBlock.asVector(); if (vVector == null) { - addRawBlock(vBlock, extraBlock); + addRawBlock(vBlock, outputValueBlock); return; } - IntVector extraVector = extraBlock.asVector(); - if (extraVector == null) { - addRawBlock(vBlock, extraBlock); + IntVector outputValueVector = outputValueBlock.asVector(); + if (outputValueVector == null) { + addRawBlock(vBlock, outputValueBlock); return; } - addRawVector(vVector, extraVector); + addRawVector(vVector, outputValueVector); } - private void addRawVector(FloatVector vVector, IntVector extraVector) { + private void addRawVector(FloatVector vVector, IntVector outputValueVector) { for (int valuesPosition = 0; valuesPosition < vVector.getPositionCount(); valuesPosition++) { float vValue = vVector.getFloat(valuesPosition); - int extraValue = extraVector.getInt(valuesPosition); - TopFloatIntAggregator.combine(state, vValue, extraValue); + int outputValueValue = outputValueVector.getInt(valuesPosition); + TopFloatIntAggregator.combine(state, vValue, outputValueValue); } } - private void addRawVector(FloatVector vVector, IntVector extraVector, BooleanVector mask) { + private void addRawVector(FloatVector vVector, IntVector outputValueVector, BooleanVector mask) { for (int valuesPosition = 0; valuesPosition < vVector.getPositionCount(); valuesPosition++) { if (mask.getBoolean(valuesPosition) == false) { continue; } float vValue = vVector.getFloat(valuesPosition); - int extraValue = extraVector.getInt(valuesPosition); - TopFloatIntAggregator.combine(state, vValue, extraValue); + int outputValueValue = outputValueVector.getInt(valuesPosition); + TopFloatIntAggregator.combine(state, vValue, outputValueValue); } } - private void addRawBlock(FloatBlock vBlock, IntBlock extraBlock) { + private void addRawBlock(FloatBlock vBlock, IntBlock outputValueBlock) { for (int p = 0; p < vBlock.getPositionCount(); p++) { if (vBlock.isNull(p)) { continue; } - if (extraBlock.isNull(p)) { + if (outputValueBlock.isNull(p)) { continue; } int vStart = vBlock.getFirstValueIndex(p); int vEnd = vStart + vBlock.getValueCount(p); for (int vOffset = vStart; vOffset < vEnd; vOffset++) { float vValue = vBlock.getFloat(vOffset); - int extraStart = extraBlock.getFirstValueIndex(p); - int extraEnd = extraStart + extraBlock.getValueCount(p); - for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { - int extraValue = extraBlock.getInt(extraOffset); - TopFloatIntAggregator.combine(state, vValue, extraValue); + int outputValueStart = outputValueBlock.getFirstValueIndex(p); + int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(p); + for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { + int outputValueValue = outputValueBlock.getInt(outputValueOffset); + TopFloatIntAggregator.combine(state, vValue, outputValueValue); } } } } - private void addRawBlock(FloatBlock vBlock, IntBlock extraBlock, BooleanVector mask) { + private void addRawBlock(FloatBlock vBlock, IntBlock outputValueBlock, BooleanVector mask) { for (int p = 0; p < vBlock.getPositionCount(); p++) { if (mask.getBoolean(p) == false) { continue; @@ -153,18 +153,18 @@ private void addRawBlock(FloatBlock vBlock, IntBlock extraBlock, BooleanVector m if (vBlock.isNull(p)) { continue; } - if (extraBlock.isNull(p)) { + if (outputValueBlock.isNull(p)) { continue; } int vStart = vBlock.getFirstValueIndex(p); int vEnd = vStart + vBlock.getValueCount(p); for (int vOffset = vStart; vOffset < vEnd; vOffset++) { float vValue = vBlock.getFloat(vOffset); - int extraStart = extraBlock.getFirstValueIndex(p); - int extraEnd = extraStart + extraBlock.getValueCount(p); - for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { - int extraValue = extraBlock.getInt(extraOffset); - TopFloatIntAggregator.combine(state, vValue, extraValue); + int outputValueStart = outputValueBlock.getFirstValueIndex(p); + int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(p); + for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { + int outputValueValue = outputValueBlock.getInt(outputValueOffset); + TopFloatIntAggregator.combine(state, vValue, outputValueValue); } } } @@ -180,13 +180,13 @@ public void addIntermediateInput(Page page) { } FloatBlock top = (FloatBlock) topUncast; assert top.getPositionCount() == 1; - Block extraUncast = page.getBlock(channels.get(1)); - if (extraUncast.areAllValuesNull()) { + Block outputUncast = page.getBlock(channels.get(1)); + if (outputUncast.areAllValuesNull()) { return; } - IntBlock extra = (IntBlock) extraUncast; - assert extra.getPositionCount() == 1; - TopFloatIntAggregator.combineIntermediate(state, top, extra); + IntBlock output = (IntBlock) outputUncast; + assert output.getPositionCount() == 1; + TopFloatIntAggregator.combineIntermediate(state, top, output); } @Override diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatIntGroupingAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatIntGroupingAggregatorFunction.java index 3f9485ce7c3b8..af35589123794 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatIntGroupingAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatIntGroupingAggregatorFunction.java @@ -27,7 +27,7 @@ public final class TopFloatIntGroupingAggregatorFunction implements GroupingAggregatorFunction { private static final List INTERMEDIATE_STATE_DESC = List.of( new IntermediateStateDesc("top", ElementType.FLOAT), - new IntermediateStateDesc("extra", ElementType.INT) ); + new IntermediateStateDesc("output", ElementType.INT) ); private final TopFloatIntAggregator.GroupingState state; @@ -67,24 +67,24 @@ public int intermediateBlockCount() { public GroupingAggregatorFunction.AddInput prepareProcessRawInputPage(SeenGroupIds seenGroupIds, Page page) { FloatBlock vBlock = page.getBlock(channels.get(0)); - IntBlock extraBlock = page.getBlock(channels.get(1)); + IntBlock outputValueBlock = page.getBlock(channels.get(1)); FloatVector vVector = vBlock.asVector(); if (vVector == null) { - maybeEnableGroupIdTracking(seenGroupIds, vBlock, extraBlock); + maybeEnableGroupIdTracking(seenGroupIds, vBlock, outputValueBlock); return new GroupingAggregatorFunction.AddInput() { @Override public void add(int positionOffset, IntArrayBlock groupIds) { - addRawInput(positionOffset, groupIds, vBlock, extraBlock); + addRawInput(positionOffset, groupIds, vBlock, outputValueBlock); } @Override public void add(int positionOffset, IntBigArrayBlock groupIds) { - addRawInput(positionOffset, groupIds, vBlock, extraBlock); + addRawInput(positionOffset, groupIds, vBlock, outputValueBlock); } @Override public void add(int positionOffset, IntVector groupIds) { - addRawInput(positionOffset, groupIds, vBlock, extraBlock); + addRawInput(positionOffset, groupIds, vBlock, outputValueBlock); } @Override @@ -92,23 +92,23 @@ public void close() { } }; } - IntVector extraVector = extraBlock.asVector(); - if (extraVector == null) { - maybeEnableGroupIdTracking(seenGroupIds, vBlock, extraBlock); + IntVector outputValueVector = outputValueBlock.asVector(); + if (outputValueVector == null) { + maybeEnableGroupIdTracking(seenGroupIds, vBlock, outputValueBlock); return new GroupingAggregatorFunction.AddInput() { @Override public void add(int positionOffset, IntArrayBlock groupIds) { - addRawInput(positionOffset, groupIds, vBlock, extraBlock); + addRawInput(positionOffset, groupIds, vBlock, outputValueBlock); } @Override public void add(int positionOffset, IntBigArrayBlock groupIds) { - addRawInput(positionOffset, groupIds, vBlock, extraBlock); + addRawInput(positionOffset, groupIds, vBlock, outputValueBlock); } @Override public void add(int positionOffset, IntVector groupIds) { - addRawInput(positionOffset, groupIds, vBlock, extraBlock); + addRawInput(positionOffset, groupIds, vBlock, outputValueBlock); } @Override @@ -119,17 +119,17 @@ public void close() { return new GroupingAggregatorFunction.AddInput() { @Override public void add(int positionOffset, IntArrayBlock groupIds) { - addRawInput(positionOffset, groupIds, vVector, extraVector); + addRawInput(positionOffset, groupIds, vVector, outputValueVector); } @Override public void add(int positionOffset, IntBigArrayBlock groupIds) { - addRawInput(positionOffset, groupIds, vVector, extraVector); + addRawInput(positionOffset, groupIds, vVector, outputValueVector); } @Override public void add(int positionOffset, IntVector groupIds) { - addRawInput(positionOffset, groupIds, vVector, extraVector); + addRawInput(positionOffset, groupIds, vVector, outputValueVector); } @Override @@ -139,7 +139,7 @@ public void close() { } private void addRawInput(int positionOffset, IntArrayBlock groups, FloatBlock vBlock, - IntBlock extraBlock) { + IntBlock outputValueBlock) { for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { if (groups.isNull(groupPosition)) { continue; @@ -148,7 +148,7 @@ private void addRawInput(int positionOffset, IntArrayBlock groups, FloatBlock vB if (vBlock.isNull(valuesPosition)) { continue; } - if (extraBlock.isNull(valuesPosition)) { + if (outputValueBlock.isNull(valuesPosition)) { continue; } int groupStart = groups.getFirstValueIndex(groupPosition); @@ -159,11 +159,11 @@ private void addRawInput(int positionOffset, IntArrayBlock groups, FloatBlock vB int vEnd = vStart + vBlock.getValueCount(valuesPosition); for (int vOffset = vStart; vOffset < vEnd; vOffset++) { float vValue = vBlock.getFloat(vOffset); - int extraStart = extraBlock.getFirstValueIndex(valuesPosition); - int extraEnd = extraStart + extraBlock.getValueCount(valuesPosition); - for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { - int extraValue = extraBlock.getInt(extraOffset); - TopFloatIntAggregator.combine(state, groupId, vValue, extraValue); + int outputValueStart = outputValueBlock.getFirstValueIndex(valuesPosition); + int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(valuesPosition); + for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { + int outputValueValue = outputValueBlock.getInt(outputValueOffset); + TopFloatIntAggregator.combine(state, groupId, vValue, outputValueValue); } } } @@ -171,7 +171,7 @@ private void addRawInput(int positionOffset, IntArrayBlock groups, FloatBlock vB } private void addRawInput(int positionOffset, IntArrayBlock groups, FloatVector vVector, - IntVector extraVector) { + IntVector outputValueVector) { for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { if (groups.isNull(groupPosition)) { continue; @@ -182,8 +182,8 @@ private void addRawInput(int positionOffset, IntArrayBlock groups, FloatVector v for (int g = groupStart; g < groupEnd; g++) { int groupId = groups.getInt(g); float vValue = vVector.getFloat(valuesPosition); - int extraValue = extraVector.getInt(valuesPosition); - TopFloatIntAggregator.combine(state, groupId, vValue, extraValue); + int outputValueValue = outputValueVector.getInt(valuesPosition); + TopFloatIntAggregator.combine(state, groupId, vValue, outputValueValue); } } } @@ -197,12 +197,12 @@ public void addIntermediateInput(int positionOffset, IntArrayBlock groups, Page return; } FloatBlock top = (FloatBlock) topUncast; - Block extraUncast = page.getBlock(channels.get(1)); - if (extraUncast.areAllValuesNull()) { + Block outputUncast = page.getBlock(channels.get(1)); + if (outputUncast.areAllValuesNull()) { return; } - IntBlock extra = (IntBlock) extraUncast; - assert top.getPositionCount() == extra.getPositionCount(); + IntBlock output = (IntBlock) outputUncast; + assert top.getPositionCount() == output.getPositionCount(); for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { if (groups.isNull(groupPosition)) { continue; @@ -212,13 +212,13 @@ public void addIntermediateInput(int positionOffset, IntArrayBlock groups, Page for (int g = groupStart; g < groupEnd; g++) { int groupId = groups.getInt(g); int valuesPosition = groupPosition + positionOffset; - TopFloatIntAggregator.combineIntermediate(state, groupId, top, extra, valuesPosition); + TopFloatIntAggregator.combineIntermediate(state, groupId, top, output, valuesPosition); } } } private void addRawInput(int positionOffset, IntBigArrayBlock groups, FloatBlock vBlock, - IntBlock extraBlock) { + IntBlock outputValueBlock) { for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { if (groups.isNull(groupPosition)) { continue; @@ -227,7 +227,7 @@ private void addRawInput(int positionOffset, IntBigArrayBlock groups, FloatBlock if (vBlock.isNull(valuesPosition)) { continue; } - if (extraBlock.isNull(valuesPosition)) { + if (outputValueBlock.isNull(valuesPosition)) { continue; } int groupStart = groups.getFirstValueIndex(groupPosition); @@ -238,11 +238,11 @@ private void addRawInput(int positionOffset, IntBigArrayBlock groups, FloatBlock int vEnd = vStart + vBlock.getValueCount(valuesPosition); for (int vOffset = vStart; vOffset < vEnd; vOffset++) { float vValue = vBlock.getFloat(vOffset); - int extraStart = extraBlock.getFirstValueIndex(valuesPosition); - int extraEnd = extraStart + extraBlock.getValueCount(valuesPosition); - for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { - int extraValue = extraBlock.getInt(extraOffset); - TopFloatIntAggregator.combine(state, groupId, vValue, extraValue); + int outputValueStart = outputValueBlock.getFirstValueIndex(valuesPosition); + int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(valuesPosition); + for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { + int outputValueValue = outputValueBlock.getInt(outputValueOffset); + TopFloatIntAggregator.combine(state, groupId, vValue, outputValueValue); } } } @@ -250,7 +250,7 @@ private void addRawInput(int positionOffset, IntBigArrayBlock groups, FloatBlock } private void addRawInput(int positionOffset, IntBigArrayBlock groups, FloatVector vVector, - IntVector extraVector) { + IntVector outputValueVector) { for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { if (groups.isNull(groupPosition)) { continue; @@ -261,8 +261,8 @@ private void addRawInput(int positionOffset, IntBigArrayBlock groups, FloatVecto for (int g = groupStart; g < groupEnd; g++) { int groupId = groups.getInt(g); float vValue = vVector.getFloat(valuesPosition); - int extraValue = extraVector.getInt(valuesPosition); - TopFloatIntAggregator.combine(state, groupId, vValue, extraValue); + int outputValueValue = outputValueVector.getInt(valuesPosition); + TopFloatIntAggregator.combine(state, groupId, vValue, outputValueValue); } } } @@ -276,12 +276,12 @@ public void addIntermediateInput(int positionOffset, IntBigArrayBlock groups, Pa return; } FloatBlock top = (FloatBlock) topUncast; - Block extraUncast = page.getBlock(channels.get(1)); - if (extraUncast.areAllValuesNull()) { + Block outputUncast = page.getBlock(channels.get(1)); + if (outputUncast.areAllValuesNull()) { return; } - IntBlock extra = (IntBlock) extraUncast; - assert top.getPositionCount() == extra.getPositionCount(); + IntBlock output = (IntBlock) outputUncast; + assert top.getPositionCount() == output.getPositionCount(); for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { if (groups.isNull(groupPosition)) { continue; @@ -291,19 +291,19 @@ public void addIntermediateInput(int positionOffset, IntBigArrayBlock groups, Pa for (int g = groupStart; g < groupEnd; g++) { int groupId = groups.getInt(g); int valuesPosition = groupPosition + positionOffset; - TopFloatIntAggregator.combineIntermediate(state, groupId, top, extra, valuesPosition); + TopFloatIntAggregator.combineIntermediate(state, groupId, top, output, valuesPosition); } } } private void addRawInput(int positionOffset, IntVector groups, FloatBlock vBlock, - IntBlock extraBlock) { + IntBlock outputValueBlock) { for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { int valuesPosition = groupPosition + positionOffset; if (vBlock.isNull(valuesPosition)) { continue; } - if (extraBlock.isNull(valuesPosition)) { + if (outputValueBlock.isNull(valuesPosition)) { continue; } int groupId = groups.getInt(groupPosition); @@ -311,24 +311,24 @@ private void addRawInput(int positionOffset, IntVector groups, FloatBlock vBlock int vEnd = vStart + vBlock.getValueCount(valuesPosition); for (int vOffset = vStart; vOffset < vEnd; vOffset++) { float vValue = vBlock.getFloat(vOffset); - int extraStart = extraBlock.getFirstValueIndex(valuesPosition); - int extraEnd = extraStart + extraBlock.getValueCount(valuesPosition); - for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { - int extraValue = extraBlock.getInt(extraOffset); - TopFloatIntAggregator.combine(state, groupId, vValue, extraValue); + int outputValueStart = outputValueBlock.getFirstValueIndex(valuesPosition); + int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(valuesPosition); + for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { + int outputValueValue = outputValueBlock.getInt(outputValueOffset); + TopFloatIntAggregator.combine(state, groupId, vValue, outputValueValue); } } } } private void addRawInput(int positionOffset, IntVector groups, FloatVector vVector, - IntVector extraVector) { + IntVector outputValueVector) { for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { int valuesPosition = groupPosition + positionOffset; int groupId = groups.getInt(groupPosition); float vValue = vVector.getFloat(valuesPosition); - int extraValue = extraVector.getInt(valuesPosition); - TopFloatIntAggregator.combine(state, groupId, vValue, extraValue); + int outputValueValue = outputValueVector.getInt(valuesPosition); + TopFloatIntAggregator.combine(state, groupId, vValue, outputValueValue); } } @@ -341,25 +341,25 @@ public void addIntermediateInput(int positionOffset, IntVector groups, Page page return; } FloatBlock top = (FloatBlock) topUncast; - Block extraUncast = page.getBlock(channels.get(1)); - if (extraUncast.areAllValuesNull()) { + Block outputUncast = page.getBlock(channels.get(1)); + if (outputUncast.areAllValuesNull()) { return; } - IntBlock extra = (IntBlock) extraUncast; - assert top.getPositionCount() == extra.getPositionCount(); + IntBlock output = (IntBlock) outputUncast; + assert top.getPositionCount() == output.getPositionCount(); for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { int groupId = groups.getInt(groupPosition); int valuesPosition = groupPosition + positionOffset; - TopFloatIntAggregator.combineIntermediate(state, groupId, top, extra, valuesPosition); + TopFloatIntAggregator.combineIntermediate(state, groupId, top, output, valuesPosition); } } private void maybeEnableGroupIdTracking(SeenGroupIds seenGroupIds, FloatBlock vBlock, - IntBlock extraBlock) { + IntBlock outputValueBlock) { if (vBlock.mayHaveNulls()) { state.enableGroupIdTracking(seenGroupIds); } - if (extraBlock.mayHaveNulls()) { + if (outputValueBlock.mayHaveNulls()) { state.enableGroupIdTracking(seenGroupIds); } } diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatLongAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatLongAggregatorFunction.java index 81d52c5bd0a94..e06e81b086bca 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatLongAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatLongAggregatorFunction.java @@ -26,7 +26,7 @@ public final class TopFloatLongAggregatorFunction implements AggregatorFunction { private static final List INTERMEDIATE_STATE_DESC = List.of( new IntermediateStateDesc("top", ElementType.FLOAT), - new IntermediateStateDesc("extra", ElementType.LONG) ); + new IntermediateStateDesc("output", ElementType.LONG) ); private final DriverContext driverContext; @@ -74,78 +74,78 @@ public void addRawInput(Page page, BooleanVector mask) { private void addRawInputMasked(Page page, BooleanVector mask) { FloatBlock vBlock = page.getBlock(channels.get(0)); - LongBlock extraBlock = page.getBlock(channels.get(1)); + LongBlock outputValueBlock = page.getBlock(channels.get(1)); FloatVector vVector = vBlock.asVector(); if (vVector == null) { - addRawBlock(vBlock, extraBlock, mask); + addRawBlock(vBlock, outputValueBlock, mask); return; } - LongVector extraVector = extraBlock.asVector(); - if (extraVector == null) { - addRawBlock(vBlock, extraBlock, mask); + LongVector outputValueVector = outputValueBlock.asVector(); + if (outputValueVector == null) { + addRawBlock(vBlock, outputValueBlock, mask); return; } - addRawVector(vVector, extraVector, mask); + addRawVector(vVector, outputValueVector, mask); } private void addRawInputNotMasked(Page page) { FloatBlock vBlock = page.getBlock(channels.get(0)); - LongBlock extraBlock = page.getBlock(channels.get(1)); + LongBlock outputValueBlock = page.getBlock(channels.get(1)); FloatVector vVector = vBlock.asVector(); if (vVector == null) { - addRawBlock(vBlock, extraBlock); + addRawBlock(vBlock, outputValueBlock); return; } - LongVector extraVector = extraBlock.asVector(); - if (extraVector == null) { - addRawBlock(vBlock, extraBlock); + LongVector outputValueVector = outputValueBlock.asVector(); + if (outputValueVector == null) { + addRawBlock(vBlock, outputValueBlock); return; } - addRawVector(vVector, extraVector); + addRawVector(vVector, outputValueVector); } - private void addRawVector(FloatVector vVector, LongVector extraVector) { + private void addRawVector(FloatVector vVector, LongVector outputValueVector) { for (int valuesPosition = 0; valuesPosition < vVector.getPositionCount(); valuesPosition++) { float vValue = vVector.getFloat(valuesPosition); - long extraValue = extraVector.getLong(valuesPosition); - TopFloatLongAggregator.combine(state, vValue, extraValue); + long outputValueValue = outputValueVector.getLong(valuesPosition); + TopFloatLongAggregator.combine(state, vValue, outputValueValue); } } - private void addRawVector(FloatVector vVector, LongVector extraVector, BooleanVector mask) { + private void addRawVector(FloatVector vVector, LongVector outputValueVector, BooleanVector mask) { for (int valuesPosition = 0; valuesPosition < vVector.getPositionCount(); valuesPosition++) { if (mask.getBoolean(valuesPosition) == false) { continue; } float vValue = vVector.getFloat(valuesPosition); - long extraValue = extraVector.getLong(valuesPosition); - TopFloatLongAggregator.combine(state, vValue, extraValue); + long outputValueValue = outputValueVector.getLong(valuesPosition); + TopFloatLongAggregator.combine(state, vValue, outputValueValue); } } - private void addRawBlock(FloatBlock vBlock, LongBlock extraBlock) { + private void addRawBlock(FloatBlock vBlock, LongBlock outputValueBlock) { for (int p = 0; p < vBlock.getPositionCount(); p++) { if (vBlock.isNull(p)) { continue; } - if (extraBlock.isNull(p)) { + if (outputValueBlock.isNull(p)) { continue; } int vStart = vBlock.getFirstValueIndex(p); int vEnd = vStart + vBlock.getValueCount(p); for (int vOffset = vStart; vOffset < vEnd; vOffset++) { float vValue = vBlock.getFloat(vOffset); - int extraStart = extraBlock.getFirstValueIndex(p); - int extraEnd = extraStart + extraBlock.getValueCount(p); - for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { - long extraValue = extraBlock.getLong(extraOffset); - TopFloatLongAggregator.combine(state, vValue, extraValue); + int outputValueStart = outputValueBlock.getFirstValueIndex(p); + int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(p); + for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { + long outputValueValue = outputValueBlock.getLong(outputValueOffset); + TopFloatLongAggregator.combine(state, vValue, outputValueValue); } } } } - private void addRawBlock(FloatBlock vBlock, LongBlock extraBlock, BooleanVector mask) { + private void addRawBlock(FloatBlock vBlock, LongBlock outputValueBlock, BooleanVector mask) { for (int p = 0; p < vBlock.getPositionCount(); p++) { if (mask.getBoolean(p) == false) { continue; @@ -153,18 +153,18 @@ private void addRawBlock(FloatBlock vBlock, LongBlock extraBlock, BooleanVector if (vBlock.isNull(p)) { continue; } - if (extraBlock.isNull(p)) { + if (outputValueBlock.isNull(p)) { continue; } int vStart = vBlock.getFirstValueIndex(p); int vEnd = vStart + vBlock.getValueCount(p); for (int vOffset = vStart; vOffset < vEnd; vOffset++) { float vValue = vBlock.getFloat(vOffset); - int extraStart = extraBlock.getFirstValueIndex(p); - int extraEnd = extraStart + extraBlock.getValueCount(p); - for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { - long extraValue = extraBlock.getLong(extraOffset); - TopFloatLongAggregator.combine(state, vValue, extraValue); + int outputValueStart = outputValueBlock.getFirstValueIndex(p); + int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(p); + for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { + long outputValueValue = outputValueBlock.getLong(outputValueOffset); + TopFloatLongAggregator.combine(state, vValue, outputValueValue); } } } @@ -180,13 +180,13 @@ public void addIntermediateInput(Page page) { } FloatBlock top = (FloatBlock) topUncast; assert top.getPositionCount() == 1; - Block extraUncast = page.getBlock(channels.get(1)); - if (extraUncast.areAllValuesNull()) { + Block outputUncast = page.getBlock(channels.get(1)); + if (outputUncast.areAllValuesNull()) { return; } - LongBlock extra = (LongBlock) extraUncast; - assert extra.getPositionCount() == 1; - TopFloatLongAggregator.combineIntermediate(state, top, extra); + LongBlock output = (LongBlock) outputUncast; + assert output.getPositionCount() == 1; + TopFloatLongAggregator.combineIntermediate(state, top, output); } @Override diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatLongGroupingAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatLongGroupingAggregatorFunction.java index 844a07a80b60f..6c04a6df03f2e 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatLongGroupingAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatLongGroupingAggregatorFunction.java @@ -28,7 +28,7 @@ public final class TopFloatLongGroupingAggregatorFunction implements GroupingAggregatorFunction { private static final List INTERMEDIATE_STATE_DESC = List.of( new IntermediateStateDesc("top", ElementType.FLOAT), - new IntermediateStateDesc("extra", ElementType.LONG) ); + new IntermediateStateDesc("output", ElementType.LONG) ); private final TopFloatLongAggregator.GroupingState state; @@ -68,24 +68,24 @@ public int intermediateBlockCount() { public GroupingAggregatorFunction.AddInput prepareProcessRawInputPage(SeenGroupIds seenGroupIds, Page page) { FloatBlock vBlock = page.getBlock(channels.get(0)); - LongBlock extraBlock = page.getBlock(channels.get(1)); + LongBlock outputValueBlock = page.getBlock(channels.get(1)); FloatVector vVector = vBlock.asVector(); if (vVector == null) { - maybeEnableGroupIdTracking(seenGroupIds, vBlock, extraBlock); + maybeEnableGroupIdTracking(seenGroupIds, vBlock, outputValueBlock); return new GroupingAggregatorFunction.AddInput() { @Override public void add(int positionOffset, IntArrayBlock groupIds) { - addRawInput(positionOffset, groupIds, vBlock, extraBlock); + addRawInput(positionOffset, groupIds, vBlock, outputValueBlock); } @Override public void add(int positionOffset, IntBigArrayBlock groupIds) { - addRawInput(positionOffset, groupIds, vBlock, extraBlock); + addRawInput(positionOffset, groupIds, vBlock, outputValueBlock); } @Override public void add(int positionOffset, IntVector groupIds) { - addRawInput(positionOffset, groupIds, vBlock, extraBlock); + addRawInput(positionOffset, groupIds, vBlock, outputValueBlock); } @Override @@ -93,23 +93,23 @@ public void close() { } }; } - LongVector extraVector = extraBlock.asVector(); - if (extraVector == null) { - maybeEnableGroupIdTracking(seenGroupIds, vBlock, extraBlock); + LongVector outputValueVector = outputValueBlock.asVector(); + if (outputValueVector == null) { + maybeEnableGroupIdTracking(seenGroupIds, vBlock, outputValueBlock); return new GroupingAggregatorFunction.AddInput() { @Override public void add(int positionOffset, IntArrayBlock groupIds) { - addRawInput(positionOffset, groupIds, vBlock, extraBlock); + addRawInput(positionOffset, groupIds, vBlock, outputValueBlock); } @Override public void add(int positionOffset, IntBigArrayBlock groupIds) { - addRawInput(positionOffset, groupIds, vBlock, extraBlock); + addRawInput(positionOffset, groupIds, vBlock, outputValueBlock); } @Override public void add(int positionOffset, IntVector groupIds) { - addRawInput(positionOffset, groupIds, vBlock, extraBlock); + addRawInput(positionOffset, groupIds, vBlock, outputValueBlock); } @Override @@ -120,17 +120,17 @@ public void close() { return new GroupingAggregatorFunction.AddInput() { @Override public void add(int positionOffset, IntArrayBlock groupIds) { - addRawInput(positionOffset, groupIds, vVector, extraVector); + addRawInput(positionOffset, groupIds, vVector, outputValueVector); } @Override public void add(int positionOffset, IntBigArrayBlock groupIds) { - addRawInput(positionOffset, groupIds, vVector, extraVector); + addRawInput(positionOffset, groupIds, vVector, outputValueVector); } @Override public void add(int positionOffset, IntVector groupIds) { - addRawInput(positionOffset, groupIds, vVector, extraVector); + addRawInput(positionOffset, groupIds, vVector, outputValueVector); } @Override @@ -140,7 +140,7 @@ public void close() { } private void addRawInput(int positionOffset, IntArrayBlock groups, FloatBlock vBlock, - LongBlock extraBlock) { + LongBlock outputValueBlock) { for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { if (groups.isNull(groupPosition)) { continue; @@ -149,7 +149,7 @@ private void addRawInput(int positionOffset, IntArrayBlock groups, FloatBlock vB if (vBlock.isNull(valuesPosition)) { continue; } - if (extraBlock.isNull(valuesPosition)) { + if (outputValueBlock.isNull(valuesPosition)) { continue; } int groupStart = groups.getFirstValueIndex(groupPosition); @@ -160,11 +160,11 @@ private void addRawInput(int positionOffset, IntArrayBlock groups, FloatBlock vB int vEnd = vStart + vBlock.getValueCount(valuesPosition); for (int vOffset = vStart; vOffset < vEnd; vOffset++) { float vValue = vBlock.getFloat(vOffset); - int extraStart = extraBlock.getFirstValueIndex(valuesPosition); - int extraEnd = extraStart + extraBlock.getValueCount(valuesPosition); - for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { - long extraValue = extraBlock.getLong(extraOffset); - TopFloatLongAggregator.combine(state, groupId, vValue, extraValue); + int outputValueStart = outputValueBlock.getFirstValueIndex(valuesPosition); + int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(valuesPosition); + for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { + long outputValueValue = outputValueBlock.getLong(outputValueOffset); + TopFloatLongAggregator.combine(state, groupId, vValue, outputValueValue); } } } @@ -172,7 +172,7 @@ private void addRawInput(int positionOffset, IntArrayBlock groups, FloatBlock vB } private void addRawInput(int positionOffset, IntArrayBlock groups, FloatVector vVector, - LongVector extraVector) { + LongVector outputValueVector) { for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { if (groups.isNull(groupPosition)) { continue; @@ -183,8 +183,8 @@ private void addRawInput(int positionOffset, IntArrayBlock groups, FloatVector v for (int g = groupStart; g < groupEnd; g++) { int groupId = groups.getInt(g); float vValue = vVector.getFloat(valuesPosition); - long extraValue = extraVector.getLong(valuesPosition); - TopFloatLongAggregator.combine(state, groupId, vValue, extraValue); + long outputValueValue = outputValueVector.getLong(valuesPosition); + TopFloatLongAggregator.combine(state, groupId, vValue, outputValueValue); } } } @@ -198,12 +198,12 @@ public void addIntermediateInput(int positionOffset, IntArrayBlock groups, Page return; } FloatBlock top = (FloatBlock) topUncast; - Block extraUncast = page.getBlock(channels.get(1)); - if (extraUncast.areAllValuesNull()) { + Block outputUncast = page.getBlock(channels.get(1)); + if (outputUncast.areAllValuesNull()) { return; } - LongBlock extra = (LongBlock) extraUncast; - assert top.getPositionCount() == extra.getPositionCount(); + LongBlock output = (LongBlock) outputUncast; + assert top.getPositionCount() == output.getPositionCount(); for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { if (groups.isNull(groupPosition)) { continue; @@ -213,13 +213,13 @@ public void addIntermediateInput(int positionOffset, IntArrayBlock groups, Page for (int g = groupStart; g < groupEnd; g++) { int groupId = groups.getInt(g); int valuesPosition = groupPosition + positionOffset; - TopFloatLongAggregator.combineIntermediate(state, groupId, top, extra, valuesPosition); + TopFloatLongAggregator.combineIntermediate(state, groupId, top, output, valuesPosition); } } } private void addRawInput(int positionOffset, IntBigArrayBlock groups, FloatBlock vBlock, - LongBlock extraBlock) { + LongBlock outputValueBlock) { for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { if (groups.isNull(groupPosition)) { continue; @@ -228,7 +228,7 @@ private void addRawInput(int positionOffset, IntBigArrayBlock groups, FloatBlock if (vBlock.isNull(valuesPosition)) { continue; } - if (extraBlock.isNull(valuesPosition)) { + if (outputValueBlock.isNull(valuesPosition)) { continue; } int groupStart = groups.getFirstValueIndex(groupPosition); @@ -239,11 +239,11 @@ private void addRawInput(int positionOffset, IntBigArrayBlock groups, FloatBlock int vEnd = vStart + vBlock.getValueCount(valuesPosition); for (int vOffset = vStart; vOffset < vEnd; vOffset++) { float vValue = vBlock.getFloat(vOffset); - int extraStart = extraBlock.getFirstValueIndex(valuesPosition); - int extraEnd = extraStart + extraBlock.getValueCount(valuesPosition); - for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { - long extraValue = extraBlock.getLong(extraOffset); - TopFloatLongAggregator.combine(state, groupId, vValue, extraValue); + int outputValueStart = outputValueBlock.getFirstValueIndex(valuesPosition); + int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(valuesPosition); + for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { + long outputValueValue = outputValueBlock.getLong(outputValueOffset); + TopFloatLongAggregator.combine(state, groupId, vValue, outputValueValue); } } } @@ -251,7 +251,7 @@ private void addRawInput(int positionOffset, IntBigArrayBlock groups, FloatBlock } private void addRawInput(int positionOffset, IntBigArrayBlock groups, FloatVector vVector, - LongVector extraVector) { + LongVector outputValueVector) { for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { if (groups.isNull(groupPosition)) { continue; @@ -262,8 +262,8 @@ private void addRawInput(int positionOffset, IntBigArrayBlock groups, FloatVecto for (int g = groupStart; g < groupEnd; g++) { int groupId = groups.getInt(g); float vValue = vVector.getFloat(valuesPosition); - long extraValue = extraVector.getLong(valuesPosition); - TopFloatLongAggregator.combine(state, groupId, vValue, extraValue); + long outputValueValue = outputValueVector.getLong(valuesPosition); + TopFloatLongAggregator.combine(state, groupId, vValue, outputValueValue); } } } @@ -277,12 +277,12 @@ public void addIntermediateInput(int positionOffset, IntBigArrayBlock groups, Pa return; } FloatBlock top = (FloatBlock) topUncast; - Block extraUncast = page.getBlock(channels.get(1)); - if (extraUncast.areAllValuesNull()) { + Block outputUncast = page.getBlock(channels.get(1)); + if (outputUncast.areAllValuesNull()) { return; } - LongBlock extra = (LongBlock) extraUncast; - assert top.getPositionCount() == extra.getPositionCount(); + LongBlock output = (LongBlock) outputUncast; + assert top.getPositionCount() == output.getPositionCount(); for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { if (groups.isNull(groupPosition)) { continue; @@ -292,19 +292,19 @@ public void addIntermediateInput(int positionOffset, IntBigArrayBlock groups, Pa for (int g = groupStart; g < groupEnd; g++) { int groupId = groups.getInt(g); int valuesPosition = groupPosition + positionOffset; - TopFloatLongAggregator.combineIntermediate(state, groupId, top, extra, valuesPosition); + TopFloatLongAggregator.combineIntermediate(state, groupId, top, output, valuesPosition); } } } private void addRawInput(int positionOffset, IntVector groups, FloatBlock vBlock, - LongBlock extraBlock) { + LongBlock outputValueBlock) { for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { int valuesPosition = groupPosition + positionOffset; if (vBlock.isNull(valuesPosition)) { continue; } - if (extraBlock.isNull(valuesPosition)) { + if (outputValueBlock.isNull(valuesPosition)) { continue; } int groupId = groups.getInt(groupPosition); @@ -312,24 +312,24 @@ private void addRawInput(int positionOffset, IntVector groups, FloatBlock vBlock int vEnd = vStart + vBlock.getValueCount(valuesPosition); for (int vOffset = vStart; vOffset < vEnd; vOffset++) { float vValue = vBlock.getFloat(vOffset); - int extraStart = extraBlock.getFirstValueIndex(valuesPosition); - int extraEnd = extraStart + extraBlock.getValueCount(valuesPosition); - for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { - long extraValue = extraBlock.getLong(extraOffset); - TopFloatLongAggregator.combine(state, groupId, vValue, extraValue); + int outputValueStart = outputValueBlock.getFirstValueIndex(valuesPosition); + int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(valuesPosition); + for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { + long outputValueValue = outputValueBlock.getLong(outputValueOffset); + TopFloatLongAggregator.combine(state, groupId, vValue, outputValueValue); } } } } private void addRawInput(int positionOffset, IntVector groups, FloatVector vVector, - LongVector extraVector) { + LongVector outputValueVector) { for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { int valuesPosition = groupPosition + positionOffset; int groupId = groups.getInt(groupPosition); float vValue = vVector.getFloat(valuesPosition); - long extraValue = extraVector.getLong(valuesPosition); - TopFloatLongAggregator.combine(state, groupId, vValue, extraValue); + long outputValueValue = outputValueVector.getLong(valuesPosition); + TopFloatLongAggregator.combine(state, groupId, vValue, outputValueValue); } } @@ -342,25 +342,25 @@ public void addIntermediateInput(int positionOffset, IntVector groups, Page page return; } FloatBlock top = (FloatBlock) topUncast; - Block extraUncast = page.getBlock(channels.get(1)); - if (extraUncast.areAllValuesNull()) { + Block outputUncast = page.getBlock(channels.get(1)); + if (outputUncast.areAllValuesNull()) { return; } - LongBlock extra = (LongBlock) extraUncast; - assert top.getPositionCount() == extra.getPositionCount(); + LongBlock output = (LongBlock) outputUncast; + assert top.getPositionCount() == output.getPositionCount(); for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { int groupId = groups.getInt(groupPosition); int valuesPosition = groupPosition + positionOffset; - TopFloatLongAggregator.combineIntermediate(state, groupId, top, extra, valuesPosition); + TopFloatLongAggregator.combineIntermediate(state, groupId, top, output, valuesPosition); } } private void maybeEnableGroupIdTracking(SeenGroupIds seenGroupIds, FloatBlock vBlock, - LongBlock extraBlock) { + LongBlock outputValueBlock) { if (vBlock.mayHaveNulls()) { state.enableGroupIdTracking(seenGroupIds); } - if (extraBlock.mayHaveNulls()) { + if (outputValueBlock.mayHaveNulls()) { state.enableGroupIdTracking(seenGroupIds); } } diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntDoubleAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntDoubleAggregatorFunction.java index 47923fda31567..34d497c44dbb1 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntDoubleAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntDoubleAggregatorFunction.java @@ -26,7 +26,7 @@ public final class TopIntDoubleAggregatorFunction implements AggregatorFunction { private static final List INTERMEDIATE_STATE_DESC = List.of( new IntermediateStateDesc("top", ElementType.INT), - new IntermediateStateDesc("extra", ElementType.DOUBLE) ); + new IntermediateStateDesc("output", ElementType.DOUBLE) ); private final DriverContext driverContext; @@ -74,78 +74,78 @@ public void addRawInput(Page page, BooleanVector mask) { private void addRawInputMasked(Page page, BooleanVector mask) { IntBlock vBlock = page.getBlock(channels.get(0)); - DoubleBlock extraBlock = page.getBlock(channels.get(1)); + DoubleBlock outputValueBlock = page.getBlock(channels.get(1)); IntVector vVector = vBlock.asVector(); if (vVector == null) { - addRawBlock(vBlock, extraBlock, mask); + addRawBlock(vBlock, outputValueBlock, mask); return; } - DoubleVector extraVector = extraBlock.asVector(); - if (extraVector == null) { - addRawBlock(vBlock, extraBlock, mask); + DoubleVector outputValueVector = outputValueBlock.asVector(); + if (outputValueVector == null) { + addRawBlock(vBlock, outputValueBlock, mask); return; } - addRawVector(vVector, extraVector, mask); + addRawVector(vVector, outputValueVector, mask); } private void addRawInputNotMasked(Page page) { IntBlock vBlock = page.getBlock(channels.get(0)); - DoubleBlock extraBlock = page.getBlock(channels.get(1)); + DoubleBlock outputValueBlock = page.getBlock(channels.get(1)); IntVector vVector = vBlock.asVector(); if (vVector == null) { - addRawBlock(vBlock, extraBlock); + addRawBlock(vBlock, outputValueBlock); return; } - DoubleVector extraVector = extraBlock.asVector(); - if (extraVector == null) { - addRawBlock(vBlock, extraBlock); + DoubleVector outputValueVector = outputValueBlock.asVector(); + if (outputValueVector == null) { + addRawBlock(vBlock, outputValueBlock); return; } - addRawVector(vVector, extraVector); + addRawVector(vVector, outputValueVector); } - private void addRawVector(IntVector vVector, DoubleVector extraVector) { + private void addRawVector(IntVector vVector, DoubleVector outputValueVector) { for (int valuesPosition = 0; valuesPosition < vVector.getPositionCount(); valuesPosition++) { int vValue = vVector.getInt(valuesPosition); - double extraValue = extraVector.getDouble(valuesPosition); - TopIntDoubleAggregator.combine(state, vValue, extraValue); + double outputValueValue = outputValueVector.getDouble(valuesPosition); + TopIntDoubleAggregator.combine(state, vValue, outputValueValue); } } - private void addRawVector(IntVector vVector, DoubleVector extraVector, BooleanVector mask) { + private void addRawVector(IntVector vVector, DoubleVector outputValueVector, BooleanVector mask) { for (int valuesPosition = 0; valuesPosition < vVector.getPositionCount(); valuesPosition++) { if (mask.getBoolean(valuesPosition) == false) { continue; } int vValue = vVector.getInt(valuesPosition); - double extraValue = extraVector.getDouble(valuesPosition); - TopIntDoubleAggregator.combine(state, vValue, extraValue); + double outputValueValue = outputValueVector.getDouble(valuesPosition); + TopIntDoubleAggregator.combine(state, vValue, outputValueValue); } } - private void addRawBlock(IntBlock vBlock, DoubleBlock extraBlock) { + private void addRawBlock(IntBlock vBlock, DoubleBlock outputValueBlock) { for (int p = 0; p < vBlock.getPositionCount(); p++) { if (vBlock.isNull(p)) { continue; } - if (extraBlock.isNull(p)) { + if (outputValueBlock.isNull(p)) { continue; } int vStart = vBlock.getFirstValueIndex(p); int vEnd = vStart + vBlock.getValueCount(p); for (int vOffset = vStart; vOffset < vEnd; vOffset++) { int vValue = vBlock.getInt(vOffset); - int extraStart = extraBlock.getFirstValueIndex(p); - int extraEnd = extraStart + extraBlock.getValueCount(p); - for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { - double extraValue = extraBlock.getDouble(extraOffset); - TopIntDoubleAggregator.combine(state, vValue, extraValue); + int outputValueStart = outputValueBlock.getFirstValueIndex(p); + int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(p); + for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { + double outputValueValue = outputValueBlock.getDouble(outputValueOffset); + TopIntDoubleAggregator.combine(state, vValue, outputValueValue); } } } } - private void addRawBlock(IntBlock vBlock, DoubleBlock extraBlock, BooleanVector mask) { + private void addRawBlock(IntBlock vBlock, DoubleBlock outputValueBlock, BooleanVector mask) { for (int p = 0; p < vBlock.getPositionCount(); p++) { if (mask.getBoolean(p) == false) { continue; @@ -153,18 +153,18 @@ private void addRawBlock(IntBlock vBlock, DoubleBlock extraBlock, BooleanVector if (vBlock.isNull(p)) { continue; } - if (extraBlock.isNull(p)) { + if (outputValueBlock.isNull(p)) { continue; } int vStart = vBlock.getFirstValueIndex(p); int vEnd = vStart + vBlock.getValueCount(p); for (int vOffset = vStart; vOffset < vEnd; vOffset++) { int vValue = vBlock.getInt(vOffset); - int extraStart = extraBlock.getFirstValueIndex(p); - int extraEnd = extraStart + extraBlock.getValueCount(p); - for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { - double extraValue = extraBlock.getDouble(extraOffset); - TopIntDoubleAggregator.combine(state, vValue, extraValue); + int outputValueStart = outputValueBlock.getFirstValueIndex(p); + int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(p); + for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { + double outputValueValue = outputValueBlock.getDouble(outputValueOffset); + TopIntDoubleAggregator.combine(state, vValue, outputValueValue); } } } @@ -180,13 +180,13 @@ public void addIntermediateInput(Page page) { } IntBlock top = (IntBlock) topUncast; assert top.getPositionCount() == 1; - Block extraUncast = page.getBlock(channels.get(1)); - if (extraUncast.areAllValuesNull()) { + Block outputUncast = page.getBlock(channels.get(1)); + if (outputUncast.areAllValuesNull()) { return; } - DoubleBlock extra = (DoubleBlock) extraUncast; - assert extra.getPositionCount() == 1; - TopIntDoubleAggregator.combineIntermediate(state, top, extra); + DoubleBlock output = (DoubleBlock) outputUncast; + assert output.getPositionCount() == 1; + TopIntDoubleAggregator.combineIntermediate(state, top, output); } @Override diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntDoubleGroupingAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntDoubleGroupingAggregatorFunction.java index b7ecbb9588f79..d75f26dfb2338 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntDoubleGroupingAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntDoubleGroupingAggregatorFunction.java @@ -27,7 +27,7 @@ public final class TopIntDoubleGroupingAggregatorFunction implements GroupingAggregatorFunction { private static final List INTERMEDIATE_STATE_DESC = List.of( new IntermediateStateDesc("top", ElementType.INT), - new IntermediateStateDesc("extra", ElementType.DOUBLE) ); + new IntermediateStateDesc("output", ElementType.DOUBLE) ); private final TopIntDoubleAggregator.GroupingState state; @@ -67,24 +67,24 @@ public int intermediateBlockCount() { public GroupingAggregatorFunction.AddInput prepareProcessRawInputPage(SeenGroupIds seenGroupIds, Page page) { IntBlock vBlock = page.getBlock(channels.get(0)); - DoubleBlock extraBlock = page.getBlock(channels.get(1)); + DoubleBlock outputValueBlock = page.getBlock(channels.get(1)); IntVector vVector = vBlock.asVector(); if (vVector == null) { - maybeEnableGroupIdTracking(seenGroupIds, vBlock, extraBlock); + maybeEnableGroupIdTracking(seenGroupIds, vBlock, outputValueBlock); return new GroupingAggregatorFunction.AddInput() { @Override public void add(int positionOffset, IntArrayBlock groupIds) { - addRawInput(positionOffset, groupIds, vBlock, extraBlock); + addRawInput(positionOffset, groupIds, vBlock, outputValueBlock); } @Override public void add(int positionOffset, IntBigArrayBlock groupIds) { - addRawInput(positionOffset, groupIds, vBlock, extraBlock); + addRawInput(positionOffset, groupIds, vBlock, outputValueBlock); } @Override public void add(int positionOffset, IntVector groupIds) { - addRawInput(positionOffset, groupIds, vBlock, extraBlock); + addRawInput(positionOffset, groupIds, vBlock, outputValueBlock); } @Override @@ -92,23 +92,23 @@ public void close() { } }; } - DoubleVector extraVector = extraBlock.asVector(); - if (extraVector == null) { - maybeEnableGroupIdTracking(seenGroupIds, vBlock, extraBlock); + DoubleVector outputValueVector = outputValueBlock.asVector(); + if (outputValueVector == null) { + maybeEnableGroupIdTracking(seenGroupIds, vBlock, outputValueBlock); return new GroupingAggregatorFunction.AddInput() { @Override public void add(int positionOffset, IntArrayBlock groupIds) { - addRawInput(positionOffset, groupIds, vBlock, extraBlock); + addRawInput(positionOffset, groupIds, vBlock, outputValueBlock); } @Override public void add(int positionOffset, IntBigArrayBlock groupIds) { - addRawInput(positionOffset, groupIds, vBlock, extraBlock); + addRawInput(positionOffset, groupIds, vBlock, outputValueBlock); } @Override public void add(int positionOffset, IntVector groupIds) { - addRawInput(positionOffset, groupIds, vBlock, extraBlock); + addRawInput(positionOffset, groupIds, vBlock, outputValueBlock); } @Override @@ -119,17 +119,17 @@ public void close() { return new GroupingAggregatorFunction.AddInput() { @Override public void add(int positionOffset, IntArrayBlock groupIds) { - addRawInput(positionOffset, groupIds, vVector, extraVector); + addRawInput(positionOffset, groupIds, vVector, outputValueVector); } @Override public void add(int positionOffset, IntBigArrayBlock groupIds) { - addRawInput(positionOffset, groupIds, vVector, extraVector); + addRawInput(positionOffset, groupIds, vVector, outputValueVector); } @Override public void add(int positionOffset, IntVector groupIds) { - addRawInput(positionOffset, groupIds, vVector, extraVector); + addRawInput(positionOffset, groupIds, vVector, outputValueVector); } @Override @@ -139,7 +139,7 @@ public void close() { } private void addRawInput(int positionOffset, IntArrayBlock groups, IntBlock vBlock, - DoubleBlock extraBlock) { + DoubleBlock outputValueBlock) { for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { if (groups.isNull(groupPosition)) { continue; @@ -148,7 +148,7 @@ private void addRawInput(int positionOffset, IntArrayBlock groups, IntBlock vBlo if (vBlock.isNull(valuesPosition)) { continue; } - if (extraBlock.isNull(valuesPosition)) { + if (outputValueBlock.isNull(valuesPosition)) { continue; } int groupStart = groups.getFirstValueIndex(groupPosition); @@ -159,11 +159,11 @@ private void addRawInput(int positionOffset, IntArrayBlock groups, IntBlock vBlo int vEnd = vStart + vBlock.getValueCount(valuesPosition); for (int vOffset = vStart; vOffset < vEnd; vOffset++) { int vValue = vBlock.getInt(vOffset); - int extraStart = extraBlock.getFirstValueIndex(valuesPosition); - int extraEnd = extraStart + extraBlock.getValueCount(valuesPosition); - for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { - double extraValue = extraBlock.getDouble(extraOffset); - TopIntDoubleAggregator.combine(state, groupId, vValue, extraValue); + int outputValueStart = outputValueBlock.getFirstValueIndex(valuesPosition); + int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(valuesPosition); + for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { + double outputValueValue = outputValueBlock.getDouble(outputValueOffset); + TopIntDoubleAggregator.combine(state, groupId, vValue, outputValueValue); } } } @@ -171,7 +171,7 @@ private void addRawInput(int positionOffset, IntArrayBlock groups, IntBlock vBlo } private void addRawInput(int positionOffset, IntArrayBlock groups, IntVector vVector, - DoubleVector extraVector) { + DoubleVector outputValueVector) { for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { if (groups.isNull(groupPosition)) { continue; @@ -182,8 +182,8 @@ private void addRawInput(int positionOffset, IntArrayBlock groups, IntVector vVe for (int g = groupStart; g < groupEnd; g++) { int groupId = groups.getInt(g); int vValue = vVector.getInt(valuesPosition); - double extraValue = extraVector.getDouble(valuesPosition); - TopIntDoubleAggregator.combine(state, groupId, vValue, extraValue); + double outputValueValue = outputValueVector.getDouble(valuesPosition); + TopIntDoubleAggregator.combine(state, groupId, vValue, outputValueValue); } } } @@ -197,12 +197,12 @@ public void addIntermediateInput(int positionOffset, IntArrayBlock groups, Page return; } IntBlock top = (IntBlock) topUncast; - Block extraUncast = page.getBlock(channels.get(1)); - if (extraUncast.areAllValuesNull()) { + Block outputUncast = page.getBlock(channels.get(1)); + if (outputUncast.areAllValuesNull()) { return; } - DoubleBlock extra = (DoubleBlock) extraUncast; - assert top.getPositionCount() == extra.getPositionCount(); + DoubleBlock output = (DoubleBlock) outputUncast; + assert top.getPositionCount() == output.getPositionCount(); for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { if (groups.isNull(groupPosition)) { continue; @@ -212,13 +212,13 @@ public void addIntermediateInput(int positionOffset, IntArrayBlock groups, Page for (int g = groupStart; g < groupEnd; g++) { int groupId = groups.getInt(g); int valuesPosition = groupPosition + positionOffset; - TopIntDoubleAggregator.combineIntermediate(state, groupId, top, extra, valuesPosition); + TopIntDoubleAggregator.combineIntermediate(state, groupId, top, output, valuesPosition); } } } private void addRawInput(int positionOffset, IntBigArrayBlock groups, IntBlock vBlock, - DoubleBlock extraBlock) { + DoubleBlock outputValueBlock) { for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { if (groups.isNull(groupPosition)) { continue; @@ -227,7 +227,7 @@ private void addRawInput(int positionOffset, IntBigArrayBlock groups, IntBlock v if (vBlock.isNull(valuesPosition)) { continue; } - if (extraBlock.isNull(valuesPosition)) { + if (outputValueBlock.isNull(valuesPosition)) { continue; } int groupStart = groups.getFirstValueIndex(groupPosition); @@ -238,11 +238,11 @@ private void addRawInput(int positionOffset, IntBigArrayBlock groups, IntBlock v int vEnd = vStart + vBlock.getValueCount(valuesPosition); for (int vOffset = vStart; vOffset < vEnd; vOffset++) { int vValue = vBlock.getInt(vOffset); - int extraStart = extraBlock.getFirstValueIndex(valuesPosition); - int extraEnd = extraStart + extraBlock.getValueCount(valuesPosition); - for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { - double extraValue = extraBlock.getDouble(extraOffset); - TopIntDoubleAggregator.combine(state, groupId, vValue, extraValue); + int outputValueStart = outputValueBlock.getFirstValueIndex(valuesPosition); + int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(valuesPosition); + for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { + double outputValueValue = outputValueBlock.getDouble(outputValueOffset); + TopIntDoubleAggregator.combine(state, groupId, vValue, outputValueValue); } } } @@ -250,7 +250,7 @@ private void addRawInput(int positionOffset, IntBigArrayBlock groups, IntBlock v } private void addRawInput(int positionOffset, IntBigArrayBlock groups, IntVector vVector, - DoubleVector extraVector) { + DoubleVector outputValueVector) { for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { if (groups.isNull(groupPosition)) { continue; @@ -261,8 +261,8 @@ private void addRawInput(int positionOffset, IntBigArrayBlock groups, IntVector for (int g = groupStart; g < groupEnd; g++) { int groupId = groups.getInt(g); int vValue = vVector.getInt(valuesPosition); - double extraValue = extraVector.getDouble(valuesPosition); - TopIntDoubleAggregator.combine(state, groupId, vValue, extraValue); + double outputValueValue = outputValueVector.getDouble(valuesPosition); + TopIntDoubleAggregator.combine(state, groupId, vValue, outputValueValue); } } } @@ -276,12 +276,12 @@ public void addIntermediateInput(int positionOffset, IntBigArrayBlock groups, Pa return; } IntBlock top = (IntBlock) topUncast; - Block extraUncast = page.getBlock(channels.get(1)); - if (extraUncast.areAllValuesNull()) { + Block outputUncast = page.getBlock(channels.get(1)); + if (outputUncast.areAllValuesNull()) { return; } - DoubleBlock extra = (DoubleBlock) extraUncast; - assert top.getPositionCount() == extra.getPositionCount(); + DoubleBlock output = (DoubleBlock) outputUncast; + assert top.getPositionCount() == output.getPositionCount(); for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { if (groups.isNull(groupPosition)) { continue; @@ -291,19 +291,19 @@ public void addIntermediateInput(int positionOffset, IntBigArrayBlock groups, Pa for (int g = groupStart; g < groupEnd; g++) { int groupId = groups.getInt(g); int valuesPosition = groupPosition + positionOffset; - TopIntDoubleAggregator.combineIntermediate(state, groupId, top, extra, valuesPosition); + TopIntDoubleAggregator.combineIntermediate(state, groupId, top, output, valuesPosition); } } } private void addRawInput(int positionOffset, IntVector groups, IntBlock vBlock, - DoubleBlock extraBlock) { + DoubleBlock outputValueBlock) { for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { int valuesPosition = groupPosition + positionOffset; if (vBlock.isNull(valuesPosition)) { continue; } - if (extraBlock.isNull(valuesPosition)) { + if (outputValueBlock.isNull(valuesPosition)) { continue; } int groupId = groups.getInt(groupPosition); @@ -311,24 +311,24 @@ private void addRawInput(int positionOffset, IntVector groups, IntBlock vBlock, int vEnd = vStart + vBlock.getValueCount(valuesPosition); for (int vOffset = vStart; vOffset < vEnd; vOffset++) { int vValue = vBlock.getInt(vOffset); - int extraStart = extraBlock.getFirstValueIndex(valuesPosition); - int extraEnd = extraStart + extraBlock.getValueCount(valuesPosition); - for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { - double extraValue = extraBlock.getDouble(extraOffset); - TopIntDoubleAggregator.combine(state, groupId, vValue, extraValue); + int outputValueStart = outputValueBlock.getFirstValueIndex(valuesPosition); + int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(valuesPosition); + for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { + double outputValueValue = outputValueBlock.getDouble(outputValueOffset); + TopIntDoubleAggregator.combine(state, groupId, vValue, outputValueValue); } } } } private void addRawInput(int positionOffset, IntVector groups, IntVector vVector, - DoubleVector extraVector) { + DoubleVector outputValueVector) { for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { int valuesPosition = groupPosition + positionOffset; int groupId = groups.getInt(groupPosition); int vValue = vVector.getInt(valuesPosition); - double extraValue = extraVector.getDouble(valuesPosition); - TopIntDoubleAggregator.combine(state, groupId, vValue, extraValue); + double outputValueValue = outputValueVector.getDouble(valuesPosition); + TopIntDoubleAggregator.combine(state, groupId, vValue, outputValueValue); } } @@ -341,25 +341,25 @@ public void addIntermediateInput(int positionOffset, IntVector groups, Page page return; } IntBlock top = (IntBlock) topUncast; - Block extraUncast = page.getBlock(channels.get(1)); - if (extraUncast.areAllValuesNull()) { + Block outputUncast = page.getBlock(channels.get(1)); + if (outputUncast.areAllValuesNull()) { return; } - DoubleBlock extra = (DoubleBlock) extraUncast; - assert top.getPositionCount() == extra.getPositionCount(); + DoubleBlock output = (DoubleBlock) outputUncast; + assert top.getPositionCount() == output.getPositionCount(); for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { int groupId = groups.getInt(groupPosition); int valuesPosition = groupPosition + positionOffset; - TopIntDoubleAggregator.combineIntermediate(state, groupId, top, extra, valuesPosition); + TopIntDoubleAggregator.combineIntermediate(state, groupId, top, output, valuesPosition); } } private void maybeEnableGroupIdTracking(SeenGroupIds seenGroupIds, IntBlock vBlock, - DoubleBlock extraBlock) { + DoubleBlock outputValueBlock) { if (vBlock.mayHaveNulls()) { state.enableGroupIdTracking(seenGroupIds); } - if (extraBlock.mayHaveNulls()) { + if (outputValueBlock.mayHaveNulls()) { state.enableGroupIdTracking(seenGroupIds); } } diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntFloatAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntFloatAggregatorFunction.java index 45001027d9a2c..eaa73dcca6b18 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntFloatAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntFloatAggregatorFunction.java @@ -26,7 +26,7 @@ public final class TopIntFloatAggregatorFunction implements AggregatorFunction { private static final List INTERMEDIATE_STATE_DESC = List.of( new IntermediateStateDesc("top", ElementType.INT), - new IntermediateStateDesc("extra", ElementType.FLOAT) ); + new IntermediateStateDesc("output", ElementType.FLOAT) ); private final DriverContext driverContext; @@ -74,78 +74,78 @@ public void addRawInput(Page page, BooleanVector mask) { private void addRawInputMasked(Page page, BooleanVector mask) { IntBlock vBlock = page.getBlock(channels.get(0)); - FloatBlock extraBlock = page.getBlock(channels.get(1)); + FloatBlock outputValueBlock = page.getBlock(channels.get(1)); IntVector vVector = vBlock.asVector(); if (vVector == null) { - addRawBlock(vBlock, extraBlock, mask); + addRawBlock(vBlock, outputValueBlock, mask); return; } - FloatVector extraVector = extraBlock.asVector(); - if (extraVector == null) { - addRawBlock(vBlock, extraBlock, mask); + FloatVector outputValueVector = outputValueBlock.asVector(); + if (outputValueVector == null) { + addRawBlock(vBlock, outputValueBlock, mask); return; } - addRawVector(vVector, extraVector, mask); + addRawVector(vVector, outputValueVector, mask); } private void addRawInputNotMasked(Page page) { IntBlock vBlock = page.getBlock(channels.get(0)); - FloatBlock extraBlock = page.getBlock(channels.get(1)); + FloatBlock outputValueBlock = page.getBlock(channels.get(1)); IntVector vVector = vBlock.asVector(); if (vVector == null) { - addRawBlock(vBlock, extraBlock); + addRawBlock(vBlock, outputValueBlock); return; } - FloatVector extraVector = extraBlock.asVector(); - if (extraVector == null) { - addRawBlock(vBlock, extraBlock); + FloatVector outputValueVector = outputValueBlock.asVector(); + if (outputValueVector == null) { + addRawBlock(vBlock, outputValueBlock); return; } - addRawVector(vVector, extraVector); + addRawVector(vVector, outputValueVector); } - private void addRawVector(IntVector vVector, FloatVector extraVector) { + private void addRawVector(IntVector vVector, FloatVector outputValueVector) { for (int valuesPosition = 0; valuesPosition < vVector.getPositionCount(); valuesPosition++) { int vValue = vVector.getInt(valuesPosition); - float extraValue = extraVector.getFloat(valuesPosition); - TopIntFloatAggregator.combine(state, vValue, extraValue); + float outputValueValue = outputValueVector.getFloat(valuesPosition); + TopIntFloatAggregator.combine(state, vValue, outputValueValue); } } - private void addRawVector(IntVector vVector, FloatVector extraVector, BooleanVector mask) { + private void addRawVector(IntVector vVector, FloatVector outputValueVector, BooleanVector mask) { for (int valuesPosition = 0; valuesPosition < vVector.getPositionCount(); valuesPosition++) { if (mask.getBoolean(valuesPosition) == false) { continue; } int vValue = vVector.getInt(valuesPosition); - float extraValue = extraVector.getFloat(valuesPosition); - TopIntFloatAggregator.combine(state, vValue, extraValue); + float outputValueValue = outputValueVector.getFloat(valuesPosition); + TopIntFloatAggregator.combine(state, vValue, outputValueValue); } } - private void addRawBlock(IntBlock vBlock, FloatBlock extraBlock) { + private void addRawBlock(IntBlock vBlock, FloatBlock outputValueBlock) { for (int p = 0; p < vBlock.getPositionCount(); p++) { if (vBlock.isNull(p)) { continue; } - if (extraBlock.isNull(p)) { + if (outputValueBlock.isNull(p)) { continue; } int vStart = vBlock.getFirstValueIndex(p); int vEnd = vStart + vBlock.getValueCount(p); for (int vOffset = vStart; vOffset < vEnd; vOffset++) { int vValue = vBlock.getInt(vOffset); - int extraStart = extraBlock.getFirstValueIndex(p); - int extraEnd = extraStart + extraBlock.getValueCount(p); - for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { - float extraValue = extraBlock.getFloat(extraOffset); - TopIntFloatAggregator.combine(state, vValue, extraValue); + int outputValueStart = outputValueBlock.getFirstValueIndex(p); + int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(p); + for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { + float outputValueValue = outputValueBlock.getFloat(outputValueOffset); + TopIntFloatAggregator.combine(state, vValue, outputValueValue); } } } } - private void addRawBlock(IntBlock vBlock, FloatBlock extraBlock, BooleanVector mask) { + private void addRawBlock(IntBlock vBlock, FloatBlock outputValueBlock, BooleanVector mask) { for (int p = 0; p < vBlock.getPositionCount(); p++) { if (mask.getBoolean(p) == false) { continue; @@ -153,18 +153,18 @@ private void addRawBlock(IntBlock vBlock, FloatBlock extraBlock, BooleanVector m if (vBlock.isNull(p)) { continue; } - if (extraBlock.isNull(p)) { + if (outputValueBlock.isNull(p)) { continue; } int vStart = vBlock.getFirstValueIndex(p); int vEnd = vStart + vBlock.getValueCount(p); for (int vOffset = vStart; vOffset < vEnd; vOffset++) { int vValue = vBlock.getInt(vOffset); - int extraStart = extraBlock.getFirstValueIndex(p); - int extraEnd = extraStart + extraBlock.getValueCount(p); - for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { - float extraValue = extraBlock.getFloat(extraOffset); - TopIntFloatAggregator.combine(state, vValue, extraValue); + int outputValueStart = outputValueBlock.getFirstValueIndex(p); + int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(p); + for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { + float outputValueValue = outputValueBlock.getFloat(outputValueOffset); + TopIntFloatAggregator.combine(state, vValue, outputValueValue); } } } @@ -180,13 +180,13 @@ public void addIntermediateInput(Page page) { } IntBlock top = (IntBlock) topUncast; assert top.getPositionCount() == 1; - Block extraUncast = page.getBlock(channels.get(1)); - if (extraUncast.areAllValuesNull()) { + Block outputUncast = page.getBlock(channels.get(1)); + if (outputUncast.areAllValuesNull()) { return; } - FloatBlock extra = (FloatBlock) extraUncast; - assert extra.getPositionCount() == 1; - TopIntFloatAggregator.combineIntermediate(state, top, extra); + FloatBlock output = (FloatBlock) outputUncast; + assert output.getPositionCount() == 1; + TopIntFloatAggregator.combineIntermediate(state, top, output); } @Override diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntFloatGroupingAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntFloatGroupingAggregatorFunction.java index aa8b624a8d9c3..b9b7abd9ff435 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntFloatGroupingAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntFloatGroupingAggregatorFunction.java @@ -27,7 +27,7 @@ public final class TopIntFloatGroupingAggregatorFunction implements GroupingAggregatorFunction { private static final List INTERMEDIATE_STATE_DESC = List.of( new IntermediateStateDesc("top", ElementType.INT), - new IntermediateStateDesc("extra", ElementType.FLOAT) ); + new IntermediateStateDesc("output", ElementType.FLOAT) ); private final TopIntFloatAggregator.GroupingState state; @@ -67,24 +67,24 @@ public int intermediateBlockCount() { public GroupingAggregatorFunction.AddInput prepareProcessRawInputPage(SeenGroupIds seenGroupIds, Page page) { IntBlock vBlock = page.getBlock(channels.get(0)); - FloatBlock extraBlock = page.getBlock(channels.get(1)); + FloatBlock outputValueBlock = page.getBlock(channels.get(1)); IntVector vVector = vBlock.asVector(); if (vVector == null) { - maybeEnableGroupIdTracking(seenGroupIds, vBlock, extraBlock); + maybeEnableGroupIdTracking(seenGroupIds, vBlock, outputValueBlock); return new GroupingAggregatorFunction.AddInput() { @Override public void add(int positionOffset, IntArrayBlock groupIds) { - addRawInput(positionOffset, groupIds, vBlock, extraBlock); + addRawInput(positionOffset, groupIds, vBlock, outputValueBlock); } @Override public void add(int positionOffset, IntBigArrayBlock groupIds) { - addRawInput(positionOffset, groupIds, vBlock, extraBlock); + addRawInput(positionOffset, groupIds, vBlock, outputValueBlock); } @Override public void add(int positionOffset, IntVector groupIds) { - addRawInput(positionOffset, groupIds, vBlock, extraBlock); + addRawInput(positionOffset, groupIds, vBlock, outputValueBlock); } @Override @@ -92,23 +92,23 @@ public void close() { } }; } - FloatVector extraVector = extraBlock.asVector(); - if (extraVector == null) { - maybeEnableGroupIdTracking(seenGroupIds, vBlock, extraBlock); + FloatVector outputValueVector = outputValueBlock.asVector(); + if (outputValueVector == null) { + maybeEnableGroupIdTracking(seenGroupIds, vBlock, outputValueBlock); return new GroupingAggregatorFunction.AddInput() { @Override public void add(int positionOffset, IntArrayBlock groupIds) { - addRawInput(positionOffset, groupIds, vBlock, extraBlock); + addRawInput(positionOffset, groupIds, vBlock, outputValueBlock); } @Override public void add(int positionOffset, IntBigArrayBlock groupIds) { - addRawInput(positionOffset, groupIds, vBlock, extraBlock); + addRawInput(positionOffset, groupIds, vBlock, outputValueBlock); } @Override public void add(int positionOffset, IntVector groupIds) { - addRawInput(positionOffset, groupIds, vBlock, extraBlock); + addRawInput(positionOffset, groupIds, vBlock, outputValueBlock); } @Override @@ -119,17 +119,17 @@ public void close() { return new GroupingAggregatorFunction.AddInput() { @Override public void add(int positionOffset, IntArrayBlock groupIds) { - addRawInput(positionOffset, groupIds, vVector, extraVector); + addRawInput(positionOffset, groupIds, vVector, outputValueVector); } @Override public void add(int positionOffset, IntBigArrayBlock groupIds) { - addRawInput(positionOffset, groupIds, vVector, extraVector); + addRawInput(positionOffset, groupIds, vVector, outputValueVector); } @Override public void add(int positionOffset, IntVector groupIds) { - addRawInput(positionOffset, groupIds, vVector, extraVector); + addRawInput(positionOffset, groupIds, vVector, outputValueVector); } @Override @@ -139,7 +139,7 @@ public void close() { } private void addRawInput(int positionOffset, IntArrayBlock groups, IntBlock vBlock, - FloatBlock extraBlock) { + FloatBlock outputValueBlock) { for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { if (groups.isNull(groupPosition)) { continue; @@ -148,7 +148,7 @@ private void addRawInput(int positionOffset, IntArrayBlock groups, IntBlock vBlo if (vBlock.isNull(valuesPosition)) { continue; } - if (extraBlock.isNull(valuesPosition)) { + if (outputValueBlock.isNull(valuesPosition)) { continue; } int groupStart = groups.getFirstValueIndex(groupPosition); @@ -159,11 +159,11 @@ private void addRawInput(int positionOffset, IntArrayBlock groups, IntBlock vBlo int vEnd = vStart + vBlock.getValueCount(valuesPosition); for (int vOffset = vStart; vOffset < vEnd; vOffset++) { int vValue = vBlock.getInt(vOffset); - int extraStart = extraBlock.getFirstValueIndex(valuesPosition); - int extraEnd = extraStart + extraBlock.getValueCount(valuesPosition); - for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { - float extraValue = extraBlock.getFloat(extraOffset); - TopIntFloatAggregator.combine(state, groupId, vValue, extraValue); + int outputValueStart = outputValueBlock.getFirstValueIndex(valuesPosition); + int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(valuesPosition); + for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { + float outputValueValue = outputValueBlock.getFloat(outputValueOffset); + TopIntFloatAggregator.combine(state, groupId, vValue, outputValueValue); } } } @@ -171,7 +171,7 @@ private void addRawInput(int positionOffset, IntArrayBlock groups, IntBlock vBlo } private void addRawInput(int positionOffset, IntArrayBlock groups, IntVector vVector, - FloatVector extraVector) { + FloatVector outputValueVector) { for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { if (groups.isNull(groupPosition)) { continue; @@ -182,8 +182,8 @@ private void addRawInput(int positionOffset, IntArrayBlock groups, IntVector vVe for (int g = groupStart; g < groupEnd; g++) { int groupId = groups.getInt(g); int vValue = vVector.getInt(valuesPosition); - float extraValue = extraVector.getFloat(valuesPosition); - TopIntFloatAggregator.combine(state, groupId, vValue, extraValue); + float outputValueValue = outputValueVector.getFloat(valuesPosition); + TopIntFloatAggregator.combine(state, groupId, vValue, outputValueValue); } } } @@ -197,12 +197,12 @@ public void addIntermediateInput(int positionOffset, IntArrayBlock groups, Page return; } IntBlock top = (IntBlock) topUncast; - Block extraUncast = page.getBlock(channels.get(1)); - if (extraUncast.areAllValuesNull()) { + Block outputUncast = page.getBlock(channels.get(1)); + if (outputUncast.areAllValuesNull()) { return; } - FloatBlock extra = (FloatBlock) extraUncast; - assert top.getPositionCount() == extra.getPositionCount(); + FloatBlock output = (FloatBlock) outputUncast; + assert top.getPositionCount() == output.getPositionCount(); for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { if (groups.isNull(groupPosition)) { continue; @@ -212,13 +212,13 @@ public void addIntermediateInput(int positionOffset, IntArrayBlock groups, Page for (int g = groupStart; g < groupEnd; g++) { int groupId = groups.getInt(g); int valuesPosition = groupPosition + positionOffset; - TopIntFloatAggregator.combineIntermediate(state, groupId, top, extra, valuesPosition); + TopIntFloatAggregator.combineIntermediate(state, groupId, top, output, valuesPosition); } } } private void addRawInput(int positionOffset, IntBigArrayBlock groups, IntBlock vBlock, - FloatBlock extraBlock) { + FloatBlock outputValueBlock) { for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { if (groups.isNull(groupPosition)) { continue; @@ -227,7 +227,7 @@ private void addRawInput(int positionOffset, IntBigArrayBlock groups, IntBlock v if (vBlock.isNull(valuesPosition)) { continue; } - if (extraBlock.isNull(valuesPosition)) { + if (outputValueBlock.isNull(valuesPosition)) { continue; } int groupStart = groups.getFirstValueIndex(groupPosition); @@ -238,11 +238,11 @@ private void addRawInput(int positionOffset, IntBigArrayBlock groups, IntBlock v int vEnd = vStart + vBlock.getValueCount(valuesPosition); for (int vOffset = vStart; vOffset < vEnd; vOffset++) { int vValue = vBlock.getInt(vOffset); - int extraStart = extraBlock.getFirstValueIndex(valuesPosition); - int extraEnd = extraStart + extraBlock.getValueCount(valuesPosition); - for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { - float extraValue = extraBlock.getFloat(extraOffset); - TopIntFloatAggregator.combine(state, groupId, vValue, extraValue); + int outputValueStart = outputValueBlock.getFirstValueIndex(valuesPosition); + int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(valuesPosition); + for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { + float outputValueValue = outputValueBlock.getFloat(outputValueOffset); + TopIntFloatAggregator.combine(state, groupId, vValue, outputValueValue); } } } @@ -250,7 +250,7 @@ private void addRawInput(int positionOffset, IntBigArrayBlock groups, IntBlock v } private void addRawInput(int positionOffset, IntBigArrayBlock groups, IntVector vVector, - FloatVector extraVector) { + FloatVector outputValueVector) { for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { if (groups.isNull(groupPosition)) { continue; @@ -261,8 +261,8 @@ private void addRawInput(int positionOffset, IntBigArrayBlock groups, IntVector for (int g = groupStart; g < groupEnd; g++) { int groupId = groups.getInt(g); int vValue = vVector.getInt(valuesPosition); - float extraValue = extraVector.getFloat(valuesPosition); - TopIntFloatAggregator.combine(state, groupId, vValue, extraValue); + float outputValueValue = outputValueVector.getFloat(valuesPosition); + TopIntFloatAggregator.combine(state, groupId, vValue, outputValueValue); } } } @@ -276,12 +276,12 @@ public void addIntermediateInput(int positionOffset, IntBigArrayBlock groups, Pa return; } IntBlock top = (IntBlock) topUncast; - Block extraUncast = page.getBlock(channels.get(1)); - if (extraUncast.areAllValuesNull()) { + Block outputUncast = page.getBlock(channels.get(1)); + if (outputUncast.areAllValuesNull()) { return; } - FloatBlock extra = (FloatBlock) extraUncast; - assert top.getPositionCount() == extra.getPositionCount(); + FloatBlock output = (FloatBlock) outputUncast; + assert top.getPositionCount() == output.getPositionCount(); for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { if (groups.isNull(groupPosition)) { continue; @@ -291,19 +291,19 @@ public void addIntermediateInput(int positionOffset, IntBigArrayBlock groups, Pa for (int g = groupStart; g < groupEnd; g++) { int groupId = groups.getInt(g); int valuesPosition = groupPosition + positionOffset; - TopIntFloatAggregator.combineIntermediate(state, groupId, top, extra, valuesPosition); + TopIntFloatAggregator.combineIntermediate(state, groupId, top, output, valuesPosition); } } } private void addRawInput(int positionOffset, IntVector groups, IntBlock vBlock, - FloatBlock extraBlock) { + FloatBlock outputValueBlock) { for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { int valuesPosition = groupPosition + positionOffset; if (vBlock.isNull(valuesPosition)) { continue; } - if (extraBlock.isNull(valuesPosition)) { + if (outputValueBlock.isNull(valuesPosition)) { continue; } int groupId = groups.getInt(groupPosition); @@ -311,24 +311,24 @@ private void addRawInput(int positionOffset, IntVector groups, IntBlock vBlock, int vEnd = vStart + vBlock.getValueCount(valuesPosition); for (int vOffset = vStart; vOffset < vEnd; vOffset++) { int vValue = vBlock.getInt(vOffset); - int extraStart = extraBlock.getFirstValueIndex(valuesPosition); - int extraEnd = extraStart + extraBlock.getValueCount(valuesPosition); - for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { - float extraValue = extraBlock.getFloat(extraOffset); - TopIntFloatAggregator.combine(state, groupId, vValue, extraValue); + int outputValueStart = outputValueBlock.getFirstValueIndex(valuesPosition); + int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(valuesPosition); + for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { + float outputValueValue = outputValueBlock.getFloat(outputValueOffset); + TopIntFloatAggregator.combine(state, groupId, vValue, outputValueValue); } } } } private void addRawInput(int positionOffset, IntVector groups, IntVector vVector, - FloatVector extraVector) { + FloatVector outputValueVector) { for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { int valuesPosition = groupPosition + positionOffset; int groupId = groups.getInt(groupPosition); int vValue = vVector.getInt(valuesPosition); - float extraValue = extraVector.getFloat(valuesPosition); - TopIntFloatAggregator.combine(state, groupId, vValue, extraValue); + float outputValueValue = outputValueVector.getFloat(valuesPosition); + TopIntFloatAggregator.combine(state, groupId, vValue, outputValueValue); } } @@ -341,25 +341,25 @@ public void addIntermediateInput(int positionOffset, IntVector groups, Page page return; } IntBlock top = (IntBlock) topUncast; - Block extraUncast = page.getBlock(channels.get(1)); - if (extraUncast.areAllValuesNull()) { + Block outputUncast = page.getBlock(channels.get(1)); + if (outputUncast.areAllValuesNull()) { return; } - FloatBlock extra = (FloatBlock) extraUncast; - assert top.getPositionCount() == extra.getPositionCount(); + FloatBlock output = (FloatBlock) outputUncast; + assert top.getPositionCount() == output.getPositionCount(); for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { int groupId = groups.getInt(groupPosition); int valuesPosition = groupPosition + positionOffset; - TopIntFloatAggregator.combineIntermediate(state, groupId, top, extra, valuesPosition); + TopIntFloatAggregator.combineIntermediate(state, groupId, top, output, valuesPosition); } } private void maybeEnableGroupIdTracking(SeenGroupIds seenGroupIds, IntBlock vBlock, - FloatBlock extraBlock) { + FloatBlock outputValueBlock) { if (vBlock.mayHaveNulls()) { state.enableGroupIdTracking(seenGroupIds); } - if (extraBlock.mayHaveNulls()) { + if (outputValueBlock.mayHaveNulls()) { state.enableGroupIdTracking(seenGroupIds); } } diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntIntAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntIntAggregatorFunction.java index e7bb2efc74f07..e197c7952d783 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntIntAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntIntAggregatorFunction.java @@ -24,7 +24,7 @@ public final class TopIntIntAggregatorFunction implements AggregatorFunction { private static final List INTERMEDIATE_STATE_DESC = List.of( new IntermediateStateDesc("top", ElementType.INT), - new IntermediateStateDesc("extra", ElementType.INT) ); + new IntermediateStateDesc("output", ElementType.INT) ); private final DriverContext driverContext; @@ -72,78 +72,78 @@ public void addRawInput(Page page, BooleanVector mask) { private void addRawInputMasked(Page page, BooleanVector mask) { IntBlock vBlock = page.getBlock(channels.get(0)); - IntBlock extraBlock = page.getBlock(channels.get(1)); + IntBlock outputValueBlock = page.getBlock(channels.get(1)); IntVector vVector = vBlock.asVector(); if (vVector == null) { - addRawBlock(vBlock, extraBlock, mask); + addRawBlock(vBlock, outputValueBlock, mask); return; } - IntVector extraVector = extraBlock.asVector(); - if (extraVector == null) { - addRawBlock(vBlock, extraBlock, mask); + IntVector outputValueVector = outputValueBlock.asVector(); + if (outputValueVector == null) { + addRawBlock(vBlock, outputValueBlock, mask); return; } - addRawVector(vVector, extraVector, mask); + addRawVector(vVector, outputValueVector, mask); } private void addRawInputNotMasked(Page page) { IntBlock vBlock = page.getBlock(channels.get(0)); - IntBlock extraBlock = page.getBlock(channels.get(1)); + IntBlock outputValueBlock = page.getBlock(channels.get(1)); IntVector vVector = vBlock.asVector(); if (vVector == null) { - addRawBlock(vBlock, extraBlock); + addRawBlock(vBlock, outputValueBlock); return; } - IntVector extraVector = extraBlock.asVector(); - if (extraVector == null) { - addRawBlock(vBlock, extraBlock); + IntVector outputValueVector = outputValueBlock.asVector(); + if (outputValueVector == null) { + addRawBlock(vBlock, outputValueBlock); return; } - addRawVector(vVector, extraVector); + addRawVector(vVector, outputValueVector); } - private void addRawVector(IntVector vVector, IntVector extraVector) { + private void addRawVector(IntVector vVector, IntVector outputValueVector) { for (int valuesPosition = 0; valuesPosition < vVector.getPositionCount(); valuesPosition++) { int vValue = vVector.getInt(valuesPosition); - int extraValue = extraVector.getInt(valuesPosition); - TopIntIntAggregator.combine(state, vValue, extraValue); + int outputValueValue = outputValueVector.getInt(valuesPosition); + TopIntIntAggregator.combine(state, vValue, outputValueValue); } } - private void addRawVector(IntVector vVector, IntVector extraVector, BooleanVector mask) { + private void addRawVector(IntVector vVector, IntVector outputValueVector, BooleanVector mask) { for (int valuesPosition = 0; valuesPosition < vVector.getPositionCount(); valuesPosition++) { if (mask.getBoolean(valuesPosition) == false) { continue; } int vValue = vVector.getInt(valuesPosition); - int extraValue = extraVector.getInt(valuesPosition); - TopIntIntAggregator.combine(state, vValue, extraValue); + int outputValueValue = outputValueVector.getInt(valuesPosition); + TopIntIntAggregator.combine(state, vValue, outputValueValue); } } - private void addRawBlock(IntBlock vBlock, IntBlock extraBlock) { + private void addRawBlock(IntBlock vBlock, IntBlock outputValueBlock) { for (int p = 0; p < vBlock.getPositionCount(); p++) { if (vBlock.isNull(p)) { continue; } - if (extraBlock.isNull(p)) { + if (outputValueBlock.isNull(p)) { continue; } int vStart = vBlock.getFirstValueIndex(p); int vEnd = vStart + vBlock.getValueCount(p); for (int vOffset = vStart; vOffset < vEnd; vOffset++) { int vValue = vBlock.getInt(vOffset); - int extraStart = extraBlock.getFirstValueIndex(p); - int extraEnd = extraStart + extraBlock.getValueCount(p); - for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { - int extraValue = extraBlock.getInt(extraOffset); - TopIntIntAggregator.combine(state, vValue, extraValue); + int outputValueStart = outputValueBlock.getFirstValueIndex(p); + int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(p); + for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { + int outputValueValue = outputValueBlock.getInt(outputValueOffset); + TopIntIntAggregator.combine(state, vValue, outputValueValue); } } } } - private void addRawBlock(IntBlock vBlock, IntBlock extraBlock, BooleanVector mask) { + private void addRawBlock(IntBlock vBlock, IntBlock outputValueBlock, BooleanVector mask) { for (int p = 0; p < vBlock.getPositionCount(); p++) { if (mask.getBoolean(p) == false) { continue; @@ -151,18 +151,18 @@ private void addRawBlock(IntBlock vBlock, IntBlock extraBlock, BooleanVector mas if (vBlock.isNull(p)) { continue; } - if (extraBlock.isNull(p)) { + if (outputValueBlock.isNull(p)) { continue; } int vStart = vBlock.getFirstValueIndex(p); int vEnd = vStart + vBlock.getValueCount(p); for (int vOffset = vStart; vOffset < vEnd; vOffset++) { int vValue = vBlock.getInt(vOffset); - int extraStart = extraBlock.getFirstValueIndex(p); - int extraEnd = extraStart + extraBlock.getValueCount(p); - for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { - int extraValue = extraBlock.getInt(extraOffset); - TopIntIntAggregator.combine(state, vValue, extraValue); + int outputValueStart = outputValueBlock.getFirstValueIndex(p); + int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(p); + for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { + int outputValueValue = outputValueBlock.getInt(outputValueOffset); + TopIntIntAggregator.combine(state, vValue, outputValueValue); } } } @@ -178,13 +178,13 @@ public void addIntermediateInput(Page page) { } IntBlock top = (IntBlock) topUncast; assert top.getPositionCount() == 1; - Block extraUncast = page.getBlock(channels.get(1)); - if (extraUncast.areAllValuesNull()) { + Block outputUncast = page.getBlock(channels.get(1)); + if (outputUncast.areAllValuesNull()) { return; } - IntBlock extra = (IntBlock) extraUncast; - assert extra.getPositionCount() == 1; - TopIntIntAggregator.combineIntermediate(state, top, extra); + IntBlock output = (IntBlock) outputUncast; + assert output.getPositionCount() == 1; + TopIntIntAggregator.combineIntermediate(state, top, output); } @Override diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntIntGroupingAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntIntGroupingAggregatorFunction.java index d9a797edce245..c4966d76012e9 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntIntGroupingAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntIntGroupingAggregatorFunction.java @@ -25,7 +25,7 @@ public final class TopIntIntGroupingAggregatorFunction implements GroupingAggregatorFunction { private static final List INTERMEDIATE_STATE_DESC = List.of( new IntermediateStateDesc("top", ElementType.INT), - new IntermediateStateDesc("extra", ElementType.INT) ); + new IntermediateStateDesc("output", ElementType.INT) ); private final TopIntIntAggregator.GroupingState state; @@ -65,24 +65,24 @@ public int intermediateBlockCount() { public GroupingAggregatorFunction.AddInput prepareProcessRawInputPage(SeenGroupIds seenGroupIds, Page page) { IntBlock vBlock = page.getBlock(channels.get(0)); - IntBlock extraBlock = page.getBlock(channels.get(1)); + IntBlock outputValueBlock = page.getBlock(channels.get(1)); IntVector vVector = vBlock.asVector(); if (vVector == null) { - maybeEnableGroupIdTracking(seenGroupIds, vBlock, extraBlock); + maybeEnableGroupIdTracking(seenGroupIds, vBlock, outputValueBlock); return new GroupingAggregatorFunction.AddInput() { @Override public void add(int positionOffset, IntArrayBlock groupIds) { - addRawInput(positionOffset, groupIds, vBlock, extraBlock); + addRawInput(positionOffset, groupIds, vBlock, outputValueBlock); } @Override public void add(int positionOffset, IntBigArrayBlock groupIds) { - addRawInput(positionOffset, groupIds, vBlock, extraBlock); + addRawInput(positionOffset, groupIds, vBlock, outputValueBlock); } @Override public void add(int positionOffset, IntVector groupIds) { - addRawInput(positionOffset, groupIds, vBlock, extraBlock); + addRawInput(positionOffset, groupIds, vBlock, outputValueBlock); } @Override @@ -90,23 +90,23 @@ public void close() { } }; } - IntVector extraVector = extraBlock.asVector(); - if (extraVector == null) { - maybeEnableGroupIdTracking(seenGroupIds, vBlock, extraBlock); + IntVector outputValueVector = outputValueBlock.asVector(); + if (outputValueVector == null) { + maybeEnableGroupIdTracking(seenGroupIds, vBlock, outputValueBlock); return new GroupingAggregatorFunction.AddInput() { @Override public void add(int positionOffset, IntArrayBlock groupIds) { - addRawInput(positionOffset, groupIds, vBlock, extraBlock); + addRawInput(positionOffset, groupIds, vBlock, outputValueBlock); } @Override public void add(int positionOffset, IntBigArrayBlock groupIds) { - addRawInput(positionOffset, groupIds, vBlock, extraBlock); + addRawInput(positionOffset, groupIds, vBlock, outputValueBlock); } @Override public void add(int positionOffset, IntVector groupIds) { - addRawInput(positionOffset, groupIds, vBlock, extraBlock); + addRawInput(positionOffset, groupIds, vBlock, outputValueBlock); } @Override @@ -117,17 +117,17 @@ public void close() { return new GroupingAggregatorFunction.AddInput() { @Override public void add(int positionOffset, IntArrayBlock groupIds) { - addRawInput(positionOffset, groupIds, vVector, extraVector); + addRawInput(positionOffset, groupIds, vVector, outputValueVector); } @Override public void add(int positionOffset, IntBigArrayBlock groupIds) { - addRawInput(positionOffset, groupIds, vVector, extraVector); + addRawInput(positionOffset, groupIds, vVector, outputValueVector); } @Override public void add(int positionOffset, IntVector groupIds) { - addRawInput(positionOffset, groupIds, vVector, extraVector); + addRawInput(positionOffset, groupIds, vVector, outputValueVector); } @Override @@ -137,7 +137,7 @@ public void close() { } private void addRawInput(int positionOffset, IntArrayBlock groups, IntBlock vBlock, - IntBlock extraBlock) { + IntBlock outputValueBlock) { for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { if (groups.isNull(groupPosition)) { continue; @@ -146,7 +146,7 @@ private void addRawInput(int positionOffset, IntArrayBlock groups, IntBlock vBlo if (vBlock.isNull(valuesPosition)) { continue; } - if (extraBlock.isNull(valuesPosition)) { + if (outputValueBlock.isNull(valuesPosition)) { continue; } int groupStart = groups.getFirstValueIndex(groupPosition); @@ -157,11 +157,11 @@ private void addRawInput(int positionOffset, IntArrayBlock groups, IntBlock vBlo int vEnd = vStart + vBlock.getValueCount(valuesPosition); for (int vOffset = vStart; vOffset < vEnd; vOffset++) { int vValue = vBlock.getInt(vOffset); - int extraStart = extraBlock.getFirstValueIndex(valuesPosition); - int extraEnd = extraStart + extraBlock.getValueCount(valuesPosition); - for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { - int extraValue = extraBlock.getInt(extraOffset); - TopIntIntAggregator.combine(state, groupId, vValue, extraValue); + int outputValueStart = outputValueBlock.getFirstValueIndex(valuesPosition); + int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(valuesPosition); + for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { + int outputValueValue = outputValueBlock.getInt(outputValueOffset); + TopIntIntAggregator.combine(state, groupId, vValue, outputValueValue); } } } @@ -169,7 +169,7 @@ private void addRawInput(int positionOffset, IntArrayBlock groups, IntBlock vBlo } private void addRawInput(int positionOffset, IntArrayBlock groups, IntVector vVector, - IntVector extraVector) { + IntVector outputValueVector) { for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { if (groups.isNull(groupPosition)) { continue; @@ -180,8 +180,8 @@ private void addRawInput(int positionOffset, IntArrayBlock groups, IntVector vVe for (int g = groupStart; g < groupEnd; g++) { int groupId = groups.getInt(g); int vValue = vVector.getInt(valuesPosition); - int extraValue = extraVector.getInt(valuesPosition); - TopIntIntAggregator.combine(state, groupId, vValue, extraValue); + int outputValueValue = outputValueVector.getInt(valuesPosition); + TopIntIntAggregator.combine(state, groupId, vValue, outputValueValue); } } } @@ -195,12 +195,12 @@ public void addIntermediateInput(int positionOffset, IntArrayBlock groups, Page return; } IntBlock top = (IntBlock) topUncast; - Block extraUncast = page.getBlock(channels.get(1)); - if (extraUncast.areAllValuesNull()) { + Block outputUncast = page.getBlock(channels.get(1)); + if (outputUncast.areAllValuesNull()) { return; } - IntBlock extra = (IntBlock) extraUncast; - assert top.getPositionCount() == extra.getPositionCount(); + IntBlock output = (IntBlock) outputUncast; + assert top.getPositionCount() == output.getPositionCount(); for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { if (groups.isNull(groupPosition)) { continue; @@ -210,13 +210,13 @@ public void addIntermediateInput(int positionOffset, IntArrayBlock groups, Page for (int g = groupStart; g < groupEnd; g++) { int groupId = groups.getInt(g); int valuesPosition = groupPosition + positionOffset; - TopIntIntAggregator.combineIntermediate(state, groupId, top, extra, valuesPosition); + TopIntIntAggregator.combineIntermediate(state, groupId, top, output, valuesPosition); } } } private void addRawInput(int positionOffset, IntBigArrayBlock groups, IntBlock vBlock, - IntBlock extraBlock) { + IntBlock outputValueBlock) { for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { if (groups.isNull(groupPosition)) { continue; @@ -225,7 +225,7 @@ private void addRawInput(int positionOffset, IntBigArrayBlock groups, IntBlock v if (vBlock.isNull(valuesPosition)) { continue; } - if (extraBlock.isNull(valuesPosition)) { + if (outputValueBlock.isNull(valuesPosition)) { continue; } int groupStart = groups.getFirstValueIndex(groupPosition); @@ -236,11 +236,11 @@ private void addRawInput(int positionOffset, IntBigArrayBlock groups, IntBlock v int vEnd = vStart + vBlock.getValueCount(valuesPosition); for (int vOffset = vStart; vOffset < vEnd; vOffset++) { int vValue = vBlock.getInt(vOffset); - int extraStart = extraBlock.getFirstValueIndex(valuesPosition); - int extraEnd = extraStart + extraBlock.getValueCount(valuesPosition); - for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { - int extraValue = extraBlock.getInt(extraOffset); - TopIntIntAggregator.combine(state, groupId, vValue, extraValue); + int outputValueStart = outputValueBlock.getFirstValueIndex(valuesPosition); + int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(valuesPosition); + for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { + int outputValueValue = outputValueBlock.getInt(outputValueOffset); + TopIntIntAggregator.combine(state, groupId, vValue, outputValueValue); } } } @@ -248,7 +248,7 @@ private void addRawInput(int positionOffset, IntBigArrayBlock groups, IntBlock v } private void addRawInput(int positionOffset, IntBigArrayBlock groups, IntVector vVector, - IntVector extraVector) { + IntVector outputValueVector) { for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { if (groups.isNull(groupPosition)) { continue; @@ -259,8 +259,8 @@ private void addRawInput(int positionOffset, IntBigArrayBlock groups, IntVector for (int g = groupStart; g < groupEnd; g++) { int groupId = groups.getInt(g); int vValue = vVector.getInt(valuesPosition); - int extraValue = extraVector.getInt(valuesPosition); - TopIntIntAggregator.combine(state, groupId, vValue, extraValue); + int outputValueValue = outputValueVector.getInt(valuesPosition); + TopIntIntAggregator.combine(state, groupId, vValue, outputValueValue); } } } @@ -274,12 +274,12 @@ public void addIntermediateInput(int positionOffset, IntBigArrayBlock groups, Pa return; } IntBlock top = (IntBlock) topUncast; - Block extraUncast = page.getBlock(channels.get(1)); - if (extraUncast.areAllValuesNull()) { + Block outputUncast = page.getBlock(channels.get(1)); + if (outputUncast.areAllValuesNull()) { return; } - IntBlock extra = (IntBlock) extraUncast; - assert top.getPositionCount() == extra.getPositionCount(); + IntBlock output = (IntBlock) outputUncast; + assert top.getPositionCount() == output.getPositionCount(); for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { if (groups.isNull(groupPosition)) { continue; @@ -289,19 +289,19 @@ public void addIntermediateInput(int positionOffset, IntBigArrayBlock groups, Pa for (int g = groupStart; g < groupEnd; g++) { int groupId = groups.getInt(g); int valuesPosition = groupPosition + positionOffset; - TopIntIntAggregator.combineIntermediate(state, groupId, top, extra, valuesPosition); + TopIntIntAggregator.combineIntermediate(state, groupId, top, output, valuesPosition); } } } private void addRawInput(int positionOffset, IntVector groups, IntBlock vBlock, - IntBlock extraBlock) { + IntBlock outputValueBlock) { for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { int valuesPosition = groupPosition + positionOffset; if (vBlock.isNull(valuesPosition)) { continue; } - if (extraBlock.isNull(valuesPosition)) { + if (outputValueBlock.isNull(valuesPosition)) { continue; } int groupId = groups.getInt(groupPosition); @@ -309,24 +309,24 @@ private void addRawInput(int positionOffset, IntVector groups, IntBlock vBlock, int vEnd = vStart + vBlock.getValueCount(valuesPosition); for (int vOffset = vStart; vOffset < vEnd; vOffset++) { int vValue = vBlock.getInt(vOffset); - int extraStart = extraBlock.getFirstValueIndex(valuesPosition); - int extraEnd = extraStart + extraBlock.getValueCount(valuesPosition); - for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { - int extraValue = extraBlock.getInt(extraOffset); - TopIntIntAggregator.combine(state, groupId, vValue, extraValue); + int outputValueStart = outputValueBlock.getFirstValueIndex(valuesPosition); + int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(valuesPosition); + for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { + int outputValueValue = outputValueBlock.getInt(outputValueOffset); + TopIntIntAggregator.combine(state, groupId, vValue, outputValueValue); } } } } private void addRawInput(int positionOffset, IntVector groups, IntVector vVector, - IntVector extraVector) { + IntVector outputValueVector) { for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { int valuesPosition = groupPosition + positionOffset; int groupId = groups.getInt(groupPosition); int vValue = vVector.getInt(valuesPosition); - int extraValue = extraVector.getInt(valuesPosition); - TopIntIntAggregator.combine(state, groupId, vValue, extraValue); + int outputValueValue = outputValueVector.getInt(valuesPosition); + TopIntIntAggregator.combine(state, groupId, vValue, outputValueValue); } } @@ -339,25 +339,25 @@ public void addIntermediateInput(int positionOffset, IntVector groups, Page page return; } IntBlock top = (IntBlock) topUncast; - Block extraUncast = page.getBlock(channels.get(1)); - if (extraUncast.areAllValuesNull()) { + Block outputUncast = page.getBlock(channels.get(1)); + if (outputUncast.areAllValuesNull()) { return; } - IntBlock extra = (IntBlock) extraUncast; - assert top.getPositionCount() == extra.getPositionCount(); + IntBlock output = (IntBlock) outputUncast; + assert top.getPositionCount() == output.getPositionCount(); for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { int groupId = groups.getInt(groupPosition); int valuesPosition = groupPosition + positionOffset; - TopIntIntAggregator.combineIntermediate(state, groupId, top, extra, valuesPosition); + TopIntIntAggregator.combineIntermediate(state, groupId, top, output, valuesPosition); } } private void maybeEnableGroupIdTracking(SeenGroupIds seenGroupIds, IntBlock vBlock, - IntBlock extraBlock) { + IntBlock outputValueBlock) { if (vBlock.mayHaveNulls()) { state.enableGroupIdTracking(seenGroupIds); } - if (extraBlock.mayHaveNulls()) { + if (outputValueBlock.mayHaveNulls()) { state.enableGroupIdTracking(seenGroupIds); } } diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntLongAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntLongAggregatorFunction.java index 5e613d1a12aef..089c3f17f5571 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntLongAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntLongAggregatorFunction.java @@ -26,7 +26,7 @@ public final class TopIntLongAggregatorFunction implements AggregatorFunction { private static final List INTERMEDIATE_STATE_DESC = List.of( new IntermediateStateDesc("top", ElementType.INT), - new IntermediateStateDesc("extra", ElementType.LONG) ); + new IntermediateStateDesc("output", ElementType.LONG) ); private final DriverContext driverContext; @@ -74,78 +74,78 @@ public void addRawInput(Page page, BooleanVector mask) { private void addRawInputMasked(Page page, BooleanVector mask) { IntBlock vBlock = page.getBlock(channels.get(0)); - LongBlock extraBlock = page.getBlock(channels.get(1)); + LongBlock outputValueBlock = page.getBlock(channels.get(1)); IntVector vVector = vBlock.asVector(); if (vVector == null) { - addRawBlock(vBlock, extraBlock, mask); + addRawBlock(vBlock, outputValueBlock, mask); return; } - LongVector extraVector = extraBlock.asVector(); - if (extraVector == null) { - addRawBlock(vBlock, extraBlock, mask); + LongVector outputValueVector = outputValueBlock.asVector(); + if (outputValueVector == null) { + addRawBlock(vBlock, outputValueBlock, mask); return; } - addRawVector(vVector, extraVector, mask); + addRawVector(vVector, outputValueVector, mask); } private void addRawInputNotMasked(Page page) { IntBlock vBlock = page.getBlock(channels.get(0)); - LongBlock extraBlock = page.getBlock(channels.get(1)); + LongBlock outputValueBlock = page.getBlock(channels.get(1)); IntVector vVector = vBlock.asVector(); if (vVector == null) { - addRawBlock(vBlock, extraBlock); + addRawBlock(vBlock, outputValueBlock); return; } - LongVector extraVector = extraBlock.asVector(); - if (extraVector == null) { - addRawBlock(vBlock, extraBlock); + LongVector outputValueVector = outputValueBlock.asVector(); + if (outputValueVector == null) { + addRawBlock(vBlock, outputValueBlock); return; } - addRawVector(vVector, extraVector); + addRawVector(vVector, outputValueVector); } - private void addRawVector(IntVector vVector, LongVector extraVector) { + private void addRawVector(IntVector vVector, LongVector outputValueVector) { for (int valuesPosition = 0; valuesPosition < vVector.getPositionCount(); valuesPosition++) { int vValue = vVector.getInt(valuesPosition); - long extraValue = extraVector.getLong(valuesPosition); - TopIntLongAggregator.combine(state, vValue, extraValue); + long outputValueValue = outputValueVector.getLong(valuesPosition); + TopIntLongAggregator.combine(state, vValue, outputValueValue); } } - private void addRawVector(IntVector vVector, LongVector extraVector, BooleanVector mask) { + private void addRawVector(IntVector vVector, LongVector outputValueVector, BooleanVector mask) { for (int valuesPosition = 0; valuesPosition < vVector.getPositionCount(); valuesPosition++) { if (mask.getBoolean(valuesPosition) == false) { continue; } int vValue = vVector.getInt(valuesPosition); - long extraValue = extraVector.getLong(valuesPosition); - TopIntLongAggregator.combine(state, vValue, extraValue); + long outputValueValue = outputValueVector.getLong(valuesPosition); + TopIntLongAggregator.combine(state, vValue, outputValueValue); } } - private void addRawBlock(IntBlock vBlock, LongBlock extraBlock) { + private void addRawBlock(IntBlock vBlock, LongBlock outputValueBlock) { for (int p = 0; p < vBlock.getPositionCount(); p++) { if (vBlock.isNull(p)) { continue; } - if (extraBlock.isNull(p)) { + if (outputValueBlock.isNull(p)) { continue; } int vStart = vBlock.getFirstValueIndex(p); int vEnd = vStart + vBlock.getValueCount(p); for (int vOffset = vStart; vOffset < vEnd; vOffset++) { int vValue = vBlock.getInt(vOffset); - int extraStart = extraBlock.getFirstValueIndex(p); - int extraEnd = extraStart + extraBlock.getValueCount(p); - for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { - long extraValue = extraBlock.getLong(extraOffset); - TopIntLongAggregator.combine(state, vValue, extraValue); + int outputValueStart = outputValueBlock.getFirstValueIndex(p); + int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(p); + for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { + long outputValueValue = outputValueBlock.getLong(outputValueOffset); + TopIntLongAggregator.combine(state, vValue, outputValueValue); } } } } - private void addRawBlock(IntBlock vBlock, LongBlock extraBlock, BooleanVector mask) { + private void addRawBlock(IntBlock vBlock, LongBlock outputValueBlock, BooleanVector mask) { for (int p = 0; p < vBlock.getPositionCount(); p++) { if (mask.getBoolean(p) == false) { continue; @@ -153,18 +153,18 @@ private void addRawBlock(IntBlock vBlock, LongBlock extraBlock, BooleanVector ma if (vBlock.isNull(p)) { continue; } - if (extraBlock.isNull(p)) { + if (outputValueBlock.isNull(p)) { continue; } int vStart = vBlock.getFirstValueIndex(p); int vEnd = vStart + vBlock.getValueCount(p); for (int vOffset = vStart; vOffset < vEnd; vOffset++) { int vValue = vBlock.getInt(vOffset); - int extraStart = extraBlock.getFirstValueIndex(p); - int extraEnd = extraStart + extraBlock.getValueCount(p); - for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { - long extraValue = extraBlock.getLong(extraOffset); - TopIntLongAggregator.combine(state, vValue, extraValue); + int outputValueStart = outputValueBlock.getFirstValueIndex(p); + int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(p); + for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { + long outputValueValue = outputValueBlock.getLong(outputValueOffset); + TopIntLongAggregator.combine(state, vValue, outputValueValue); } } } @@ -180,13 +180,13 @@ public void addIntermediateInput(Page page) { } IntBlock top = (IntBlock) topUncast; assert top.getPositionCount() == 1; - Block extraUncast = page.getBlock(channels.get(1)); - if (extraUncast.areAllValuesNull()) { + Block outputUncast = page.getBlock(channels.get(1)); + if (outputUncast.areAllValuesNull()) { return; } - LongBlock extra = (LongBlock) extraUncast; - assert extra.getPositionCount() == 1; - TopIntLongAggregator.combineIntermediate(state, top, extra); + LongBlock output = (LongBlock) outputUncast; + assert output.getPositionCount() == 1; + TopIntLongAggregator.combineIntermediate(state, top, output); } @Override diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntLongGroupingAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntLongGroupingAggregatorFunction.java index be98483bde6df..113d80aa98bdb 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntLongGroupingAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntLongGroupingAggregatorFunction.java @@ -27,7 +27,7 @@ public final class TopIntLongGroupingAggregatorFunction implements GroupingAggregatorFunction { private static final List INTERMEDIATE_STATE_DESC = List.of( new IntermediateStateDesc("top", ElementType.INT), - new IntermediateStateDesc("extra", ElementType.LONG) ); + new IntermediateStateDesc("output", ElementType.LONG) ); private final TopIntLongAggregator.GroupingState state; @@ -67,24 +67,24 @@ public int intermediateBlockCount() { public GroupingAggregatorFunction.AddInput prepareProcessRawInputPage(SeenGroupIds seenGroupIds, Page page) { IntBlock vBlock = page.getBlock(channels.get(0)); - LongBlock extraBlock = page.getBlock(channels.get(1)); + LongBlock outputValueBlock = page.getBlock(channels.get(1)); IntVector vVector = vBlock.asVector(); if (vVector == null) { - maybeEnableGroupIdTracking(seenGroupIds, vBlock, extraBlock); + maybeEnableGroupIdTracking(seenGroupIds, vBlock, outputValueBlock); return new GroupingAggregatorFunction.AddInput() { @Override public void add(int positionOffset, IntArrayBlock groupIds) { - addRawInput(positionOffset, groupIds, vBlock, extraBlock); + addRawInput(positionOffset, groupIds, vBlock, outputValueBlock); } @Override public void add(int positionOffset, IntBigArrayBlock groupIds) { - addRawInput(positionOffset, groupIds, vBlock, extraBlock); + addRawInput(positionOffset, groupIds, vBlock, outputValueBlock); } @Override public void add(int positionOffset, IntVector groupIds) { - addRawInput(positionOffset, groupIds, vBlock, extraBlock); + addRawInput(positionOffset, groupIds, vBlock, outputValueBlock); } @Override @@ -92,23 +92,23 @@ public void close() { } }; } - LongVector extraVector = extraBlock.asVector(); - if (extraVector == null) { - maybeEnableGroupIdTracking(seenGroupIds, vBlock, extraBlock); + LongVector outputValueVector = outputValueBlock.asVector(); + if (outputValueVector == null) { + maybeEnableGroupIdTracking(seenGroupIds, vBlock, outputValueBlock); return new GroupingAggregatorFunction.AddInput() { @Override public void add(int positionOffset, IntArrayBlock groupIds) { - addRawInput(positionOffset, groupIds, vBlock, extraBlock); + addRawInput(positionOffset, groupIds, vBlock, outputValueBlock); } @Override public void add(int positionOffset, IntBigArrayBlock groupIds) { - addRawInput(positionOffset, groupIds, vBlock, extraBlock); + addRawInput(positionOffset, groupIds, vBlock, outputValueBlock); } @Override public void add(int positionOffset, IntVector groupIds) { - addRawInput(positionOffset, groupIds, vBlock, extraBlock); + addRawInput(positionOffset, groupIds, vBlock, outputValueBlock); } @Override @@ -119,17 +119,17 @@ public void close() { return new GroupingAggregatorFunction.AddInput() { @Override public void add(int positionOffset, IntArrayBlock groupIds) { - addRawInput(positionOffset, groupIds, vVector, extraVector); + addRawInput(positionOffset, groupIds, vVector, outputValueVector); } @Override public void add(int positionOffset, IntBigArrayBlock groupIds) { - addRawInput(positionOffset, groupIds, vVector, extraVector); + addRawInput(positionOffset, groupIds, vVector, outputValueVector); } @Override public void add(int positionOffset, IntVector groupIds) { - addRawInput(positionOffset, groupIds, vVector, extraVector); + addRawInput(positionOffset, groupIds, vVector, outputValueVector); } @Override @@ -139,7 +139,7 @@ public void close() { } private void addRawInput(int positionOffset, IntArrayBlock groups, IntBlock vBlock, - LongBlock extraBlock) { + LongBlock outputValueBlock) { for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { if (groups.isNull(groupPosition)) { continue; @@ -148,7 +148,7 @@ private void addRawInput(int positionOffset, IntArrayBlock groups, IntBlock vBlo if (vBlock.isNull(valuesPosition)) { continue; } - if (extraBlock.isNull(valuesPosition)) { + if (outputValueBlock.isNull(valuesPosition)) { continue; } int groupStart = groups.getFirstValueIndex(groupPosition); @@ -159,11 +159,11 @@ private void addRawInput(int positionOffset, IntArrayBlock groups, IntBlock vBlo int vEnd = vStart + vBlock.getValueCount(valuesPosition); for (int vOffset = vStart; vOffset < vEnd; vOffset++) { int vValue = vBlock.getInt(vOffset); - int extraStart = extraBlock.getFirstValueIndex(valuesPosition); - int extraEnd = extraStart + extraBlock.getValueCount(valuesPosition); - for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { - long extraValue = extraBlock.getLong(extraOffset); - TopIntLongAggregator.combine(state, groupId, vValue, extraValue); + int outputValueStart = outputValueBlock.getFirstValueIndex(valuesPosition); + int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(valuesPosition); + for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { + long outputValueValue = outputValueBlock.getLong(outputValueOffset); + TopIntLongAggregator.combine(state, groupId, vValue, outputValueValue); } } } @@ -171,7 +171,7 @@ private void addRawInput(int positionOffset, IntArrayBlock groups, IntBlock vBlo } private void addRawInput(int positionOffset, IntArrayBlock groups, IntVector vVector, - LongVector extraVector) { + LongVector outputValueVector) { for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { if (groups.isNull(groupPosition)) { continue; @@ -182,8 +182,8 @@ private void addRawInput(int positionOffset, IntArrayBlock groups, IntVector vVe for (int g = groupStart; g < groupEnd; g++) { int groupId = groups.getInt(g); int vValue = vVector.getInt(valuesPosition); - long extraValue = extraVector.getLong(valuesPosition); - TopIntLongAggregator.combine(state, groupId, vValue, extraValue); + long outputValueValue = outputValueVector.getLong(valuesPosition); + TopIntLongAggregator.combine(state, groupId, vValue, outputValueValue); } } } @@ -197,12 +197,12 @@ public void addIntermediateInput(int positionOffset, IntArrayBlock groups, Page return; } IntBlock top = (IntBlock) topUncast; - Block extraUncast = page.getBlock(channels.get(1)); - if (extraUncast.areAllValuesNull()) { + Block outputUncast = page.getBlock(channels.get(1)); + if (outputUncast.areAllValuesNull()) { return; } - LongBlock extra = (LongBlock) extraUncast; - assert top.getPositionCount() == extra.getPositionCount(); + LongBlock output = (LongBlock) outputUncast; + assert top.getPositionCount() == output.getPositionCount(); for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { if (groups.isNull(groupPosition)) { continue; @@ -212,13 +212,13 @@ public void addIntermediateInput(int positionOffset, IntArrayBlock groups, Page for (int g = groupStart; g < groupEnd; g++) { int groupId = groups.getInt(g); int valuesPosition = groupPosition + positionOffset; - TopIntLongAggregator.combineIntermediate(state, groupId, top, extra, valuesPosition); + TopIntLongAggregator.combineIntermediate(state, groupId, top, output, valuesPosition); } } } private void addRawInput(int positionOffset, IntBigArrayBlock groups, IntBlock vBlock, - LongBlock extraBlock) { + LongBlock outputValueBlock) { for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { if (groups.isNull(groupPosition)) { continue; @@ -227,7 +227,7 @@ private void addRawInput(int positionOffset, IntBigArrayBlock groups, IntBlock v if (vBlock.isNull(valuesPosition)) { continue; } - if (extraBlock.isNull(valuesPosition)) { + if (outputValueBlock.isNull(valuesPosition)) { continue; } int groupStart = groups.getFirstValueIndex(groupPosition); @@ -238,11 +238,11 @@ private void addRawInput(int positionOffset, IntBigArrayBlock groups, IntBlock v int vEnd = vStart + vBlock.getValueCount(valuesPosition); for (int vOffset = vStart; vOffset < vEnd; vOffset++) { int vValue = vBlock.getInt(vOffset); - int extraStart = extraBlock.getFirstValueIndex(valuesPosition); - int extraEnd = extraStart + extraBlock.getValueCount(valuesPosition); - for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { - long extraValue = extraBlock.getLong(extraOffset); - TopIntLongAggregator.combine(state, groupId, vValue, extraValue); + int outputValueStart = outputValueBlock.getFirstValueIndex(valuesPosition); + int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(valuesPosition); + for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { + long outputValueValue = outputValueBlock.getLong(outputValueOffset); + TopIntLongAggregator.combine(state, groupId, vValue, outputValueValue); } } } @@ -250,7 +250,7 @@ private void addRawInput(int positionOffset, IntBigArrayBlock groups, IntBlock v } private void addRawInput(int positionOffset, IntBigArrayBlock groups, IntVector vVector, - LongVector extraVector) { + LongVector outputValueVector) { for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { if (groups.isNull(groupPosition)) { continue; @@ -261,8 +261,8 @@ private void addRawInput(int positionOffset, IntBigArrayBlock groups, IntVector for (int g = groupStart; g < groupEnd; g++) { int groupId = groups.getInt(g); int vValue = vVector.getInt(valuesPosition); - long extraValue = extraVector.getLong(valuesPosition); - TopIntLongAggregator.combine(state, groupId, vValue, extraValue); + long outputValueValue = outputValueVector.getLong(valuesPosition); + TopIntLongAggregator.combine(state, groupId, vValue, outputValueValue); } } } @@ -276,12 +276,12 @@ public void addIntermediateInput(int positionOffset, IntBigArrayBlock groups, Pa return; } IntBlock top = (IntBlock) topUncast; - Block extraUncast = page.getBlock(channels.get(1)); - if (extraUncast.areAllValuesNull()) { + Block outputUncast = page.getBlock(channels.get(1)); + if (outputUncast.areAllValuesNull()) { return; } - LongBlock extra = (LongBlock) extraUncast; - assert top.getPositionCount() == extra.getPositionCount(); + LongBlock output = (LongBlock) outputUncast; + assert top.getPositionCount() == output.getPositionCount(); for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { if (groups.isNull(groupPosition)) { continue; @@ -291,19 +291,19 @@ public void addIntermediateInput(int positionOffset, IntBigArrayBlock groups, Pa for (int g = groupStart; g < groupEnd; g++) { int groupId = groups.getInt(g); int valuesPosition = groupPosition + positionOffset; - TopIntLongAggregator.combineIntermediate(state, groupId, top, extra, valuesPosition); + TopIntLongAggregator.combineIntermediate(state, groupId, top, output, valuesPosition); } } } private void addRawInput(int positionOffset, IntVector groups, IntBlock vBlock, - LongBlock extraBlock) { + LongBlock outputValueBlock) { for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { int valuesPosition = groupPosition + positionOffset; if (vBlock.isNull(valuesPosition)) { continue; } - if (extraBlock.isNull(valuesPosition)) { + if (outputValueBlock.isNull(valuesPosition)) { continue; } int groupId = groups.getInt(groupPosition); @@ -311,24 +311,24 @@ private void addRawInput(int positionOffset, IntVector groups, IntBlock vBlock, int vEnd = vStart + vBlock.getValueCount(valuesPosition); for (int vOffset = vStart; vOffset < vEnd; vOffset++) { int vValue = vBlock.getInt(vOffset); - int extraStart = extraBlock.getFirstValueIndex(valuesPosition); - int extraEnd = extraStart + extraBlock.getValueCount(valuesPosition); - for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { - long extraValue = extraBlock.getLong(extraOffset); - TopIntLongAggregator.combine(state, groupId, vValue, extraValue); + int outputValueStart = outputValueBlock.getFirstValueIndex(valuesPosition); + int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(valuesPosition); + for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { + long outputValueValue = outputValueBlock.getLong(outputValueOffset); + TopIntLongAggregator.combine(state, groupId, vValue, outputValueValue); } } } } private void addRawInput(int positionOffset, IntVector groups, IntVector vVector, - LongVector extraVector) { + LongVector outputValueVector) { for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { int valuesPosition = groupPosition + positionOffset; int groupId = groups.getInt(groupPosition); int vValue = vVector.getInt(valuesPosition); - long extraValue = extraVector.getLong(valuesPosition); - TopIntLongAggregator.combine(state, groupId, vValue, extraValue); + long outputValueValue = outputValueVector.getLong(valuesPosition); + TopIntLongAggregator.combine(state, groupId, vValue, outputValueValue); } } @@ -341,25 +341,25 @@ public void addIntermediateInput(int positionOffset, IntVector groups, Page page return; } IntBlock top = (IntBlock) topUncast; - Block extraUncast = page.getBlock(channels.get(1)); - if (extraUncast.areAllValuesNull()) { + Block outputUncast = page.getBlock(channels.get(1)); + if (outputUncast.areAllValuesNull()) { return; } - LongBlock extra = (LongBlock) extraUncast; - assert top.getPositionCount() == extra.getPositionCount(); + LongBlock output = (LongBlock) outputUncast; + assert top.getPositionCount() == output.getPositionCount(); for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { int groupId = groups.getInt(groupPosition); int valuesPosition = groupPosition + positionOffset; - TopIntLongAggregator.combineIntermediate(state, groupId, top, extra, valuesPosition); + TopIntLongAggregator.combineIntermediate(state, groupId, top, output, valuesPosition); } } private void maybeEnableGroupIdTracking(SeenGroupIds seenGroupIds, IntBlock vBlock, - LongBlock extraBlock) { + LongBlock outputValueBlock) { if (vBlock.mayHaveNulls()) { state.enableGroupIdTracking(seenGroupIds); } - if (extraBlock.mayHaveNulls()) { + if (outputValueBlock.mayHaveNulls()) { state.enableGroupIdTracking(seenGroupIds); } } diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongDoubleAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongDoubleAggregatorFunction.java index d965ffe6ab80e..a2dcfd06801c2 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongDoubleAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongDoubleAggregatorFunction.java @@ -26,7 +26,7 @@ public final class TopLongDoubleAggregatorFunction implements AggregatorFunction { private static final List INTERMEDIATE_STATE_DESC = List.of( new IntermediateStateDesc("top", ElementType.LONG), - new IntermediateStateDesc("extra", ElementType.DOUBLE) ); + new IntermediateStateDesc("output", ElementType.DOUBLE) ); private final DriverContext driverContext; @@ -74,78 +74,79 @@ public void addRawInput(Page page, BooleanVector mask) { private void addRawInputMasked(Page page, BooleanVector mask) { LongBlock vBlock = page.getBlock(channels.get(0)); - DoubleBlock extraBlock = page.getBlock(channels.get(1)); + DoubleBlock outputValueBlock = page.getBlock(channels.get(1)); LongVector vVector = vBlock.asVector(); if (vVector == null) { - addRawBlock(vBlock, extraBlock, mask); + addRawBlock(vBlock, outputValueBlock, mask); return; } - DoubleVector extraVector = extraBlock.asVector(); - if (extraVector == null) { - addRawBlock(vBlock, extraBlock, mask); + DoubleVector outputValueVector = outputValueBlock.asVector(); + if (outputValueVector == null) { + addRawBlock(vBlock, outputValueBlock, mask); return; } - addRawVector(vVector, extraVector, mask); + addRawVector(vVector, outputValueVector, mask); } private void addRawInputNotMasked(Page page) { LongBlock vBlock = page.getBlock(channels.get(0)); - DoubleBlock extraBlock = page.getBlock(channels.get(1)); + DoubleBlock outputValueBlock = page.getBlock(channels.get(1)); LongVector vVector = vBlock.asVector(); if (vVector == null) { - addRawBlock(vBlock, extraBlock); + addRawBlock(vBlock, outputValueBlock); return; } - DoubleVector extraVector = extraBlock.asVector(); - if (extraVector == null) { - addRawBlock(vBlock, extraBlock); + DoubleVector outputValueVector = outputValueBlock.asVector(); + if (outputValueVector == null) { + addRawBlock(vBlock, outputValueBlock); return; } - addRawVector(vVector, extraVector); + addRawVector(vVector, outputValueVector); } - private void addRawVector(LongVector vVector, DoubleVector extraVector) { + private void addRawVector(LongVector vVector, DoubleVector outputValueVector) { for (int valuesPosition = 0; valuesPosition < vVector.getPositionCount(); valuesPosition++) { long vValue = vVector.getLong(valuesPosition); - double extraValue = extraVector.getDouble(valuesPosition); - TopLongDoubleAggregator.combine(state, vValue, extraValue); + double outputValueValue = outputValueVector.getDouble(valuesPosition); + TopLongDoubleAggregator.combine(state, vValue, outputValueValue); } } - private void addRawVector(LongVector vVector, DoubleVector extraVector, BooleanVector mask) { + private void addRawVector(LongVector vVector, DoubleVector outputValueVector, + BooleanVector mask) { for (int valuesPosition = 0; valuesPosition < vVector.getPositionCount(); valuesPosition++) { if (mask.getBoolean(valuesPosition) == false) { continue; } long vValue = vVector.getLong(valuesPosition); - double extraValue = extraVector.getDouble(valuesPosition); - TopLongDoubleAggregator.combine(state, vValue, extraValue); + double outputValueValue = outputValueVector.getDouble(valuesPosition); + TopLongDoubleAggregator.combine(state, vValue, outputValueValue); } } - private void addRawBlock(LongBlock vBlock, DoubleBlock extraBlock) { + private void addRawBlock(LongBlock vBlock, DoubleBlock outputValueBlock) { for (int p = 0; p < vBlock.getPositionCount(); p++) { if (vBlock.isNull(p)) { continue; } - if (extraBlock.isNull(p)) { + if (outputValueBlock.isNull(p)) { continue; } int vStart = vBlock.getFirstValueIndex(p); int vEnd = vStart + vBlock.getValueCount(p); for (int vOffset = vStart; vOffset < vEnd; vOffset++) { long vValue = vBlock.getLong(vOffset); - int extraStart = extraBlock.getFirstValueIndex(p); - int extraEnd = extraStart + extraBlock.getValueCount(p); - for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { - double extraValue = extraBlock.getDouble(extraOffset); - TopLongDoubleAggregator.combine(state, vValue, extraValue); + int outputValueStart = outputValueBlock.getFirstValueIndex(p); + int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(p); + for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { + double outputValueValue = outputValueBlock.getDouble(outputValueOffset); + TopLongDoubleAggregator.combine(state, vValue, outputValueValue); } } } } - private void addRawBlock(LongBlock vBlock, DoubleBlock extraBlock, BooleanVector mask) { + private void addRawBlock(LongBlock vBlock, DoubleBlock outputValueBlock, BooleanVector mask) { for (int p = 0; p < vBlock.getPositionCount(); p++) { if (mask.getBoolean(p) == false) { continue; @@ -153,18 +154,18 @@ private void addRawBlock(LongBlock vBlock, DoubleBlock extraBlock, BooleanVector if (vBlock.isNull(p)) { continue; } - if (extraBlock.isNull(p)) { + if (outputValueBlock.isNull(p)) { continue; } int vStart = vBlock.getFirstValueIndex(p); int vEnd = vStart + vBlock.getValueCount(p); for (int vOffset = vStart; vOffset < vEnd; vOffset++) { long vValue = vBlock.getLong(vOffset); - int extraStart = extraBlock.getFirstValueIndex(p); - int extraEnd = extraStart + extraBlock.getValueCount(p); - for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { - double extraValue = extraBlock.getDouble(extraOffset); - TopLongDoubleAggregator.combine(state, vValue, extraValue); + int outputValueStart = outputValueBlock.getFirstValueIndex(p); + int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(p); + for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { + double outputValueValue = outputValueBlock.getDouble(outputValueOffset); + TopLongDoubleAggregator.combine(state, vValue, outputValueValue); } } } @@ -180,13 +181,13 @@ public void addIntermediateInput(Page page) { } LongBlock top = (LongBlock) topUncast; assert top.getPositionCount() == 1; - Block extraUncast = page.getBlock(channels.get(1)); - if (extraUncast.areAllValuesNull()) { + Block outputUncast = page.getBlock(channels.get(1)); + if (outputUncast.areAllValuesNull()) { return; } - DoubleBlock extra = (DoubleBlock) extraUncast; - assert extra.getPositionCount() == 1; - TopLongDoubleAggregator.combineIntermediate(state, top, extra); + DoubleBlock output = (DoubleBlock) outputUncast; + assert output.getPositionCount() == 1; + TopLongDoubleAggregator.combineIntermediate(state, top, output); } @Override diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongDoubleGroupingAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongDoubleGroupingAggregatorFunction.java index 9e4a5bcbf6020..ee6db0949b81e 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongDoubleGroupingAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongDoubleGroupingAggregatorFunction.java @@ -28,7 +28,7 @@ public final class TopLongDoubleGroupingAggregatorFunction implements GroupingAggregatorFunction { private static final List INTERMEDIATE_STATE_DESC = List.of( new IntermediateStateDesc("top", ElementType.LONG), - new IntermediateStateDesc("extra", ElementType.DOUBLE) ); + new IntermediateStateDesc("output", ElementType.DOUBLE) ); private final TopLongDoubleAggregator.GroupingState state; @@ -68,24 +68,24 @@ public int intermediateBlockCount() { public GroupingAggregatorFunction.AddInput prepareProcessRawInputPage(SeenGroupIds seenGroupIds, Page page) { LongBlock vBlock = page.getBlock(channels.get(0)); - DoubleBlock extraBlock = page.getBlock(channels.get(1)); + DoubleBlock outputValueBlock = page.getBlock(channels.get(1)); LongVector vVector = vBlock.asVector(); if (vVector == null) { - maybeEnableGroupIdTracking(seenGroupIds, vBlock, extraBlock); + maybeEnableGroupIdTracking(seenGroupIds, vBlock, outputValueBlock); return new GroupingAggregatorFunction.AddInput() { @Override public void add(int positionOffset, IntArrayBlock groupIds) { - addRawInput(positionOffset, groupIds, vBlock, extraBlock); + addRawInput(positionOffset, groupIds, vBlock, outputValueBlock); } @Override public void add(int positionOffset, IntBigArrayBlock groupIds) { - addRawInput(positionOffset, groupIds, vBlock, extraBlock); + addRawInput(positionOffset, groupIds, vBlock, outputValueBlock); } @Override public void add(int positionOffset, IntVector groupIds) { - addRawInput(positionOffset, groupIds, vBlock, extraBlock); + addRawInput(positionOffset, groupIds, vBlock, outputValueBlock); } @Override @@ -93,23 +93,23 @@ public void close() { } }; } - DoubleVector extraVector = extraBlock.asVector(); - if (extraVector == null) { - maybeEnableGroupIdTracking(seenGroupIds, vBlock, extraBlock); + DoubleVector outputValueVector = outputValueBlock.asVector(); + if (outputValueVector == null) { + maybeEnableGroupIdTracking(seenGroupIds, vBlock, outputValueBlock); return new GroupingAggregatorFunction.AddInput() { @Override public void add(int positionOffset, IntArrayBlock groupIds) { - addRawInput(positionOffset, groupIds, vBlock, extraBlock); + addRawInput(positionOffset, groupIds, vBlock, outputValueBlock); } @Override public void add(int positionOffset, IntBigArrayBlock groupIds) { - addRawInput(positionOffset, groupIds, vBlock, extraBlock); + addRawInput(positionOffset, groupIds, vBlock, outputValueBlock); } @Override public void add(int positionOffset, IntVector groupIds) { - addRawInput(positionOffset, groupIds, vBlock, extraBlock); + addRawInput(positionOffset, groupIds, vBlock, outputValueBlock); } @Override @@ -120,17 +120,17 @@ public void close() { return new GroupingAggregatorFunction.AddInput() { @Override public void add(int positionOffset, IntArrayBlock groupIds) { - addRawInput(positionOffset, groupIds, vVector, extraVector); + addRawInput(positionOffset, groupIds, vVector, outputValueVector); } @Override public void add(int positionOffset, IntBigArrayBlock groupIds) { - addRawInput(positionOffset, groupIds, vVector, extraVector); + addRawInput(positionOffset, groupIds, vVector, outputValueVector); } @Override public void add(int positionOffset, IntVector groupIds) { - addRawInput(positionOffset, groupIds, vVector, extraVector); + addRawInput(positionOffset, groupIds, vVector, outputValueVector); } @Override @@ -140,7 +140,7 @@ public void close() { } private void addRawInput(int positionOffset, IntArrayBlock groups, LongBlock vBlock, - DoubleBlock extraBlock) { + DoubleBlock outputValueBlock) { for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { if (groups.isNull(groupPosition)) { continue; @@ -149,7 +149,7 @@ private void addRawInput(int positionOffset, IntArrayBlock groups, LongBlock vBl if (vBlock.isNull(valuesPosition)) { continue; } - if (extraBlock.isNull(valuesPosition)) { + if (outputValueBlock.isNull(valuesPosition)) { continue; } int groupStart = groups.getFirstValueIndex(groupPosition); @@ -160,11 +160,11 @@ private void addRawInput(int positionOffset, IntArrayBlock groups, LongBlock vBl int vEnd = vStart + vBlock.getValueCount(valuesPosition); for (int vOffset = vStart; vOffset < vEnd; vOffset++) { long vValue = vBlock.getLong(vOffset); - int extraStart = extraBlock.getFirstValueIndex(valuesPosition); - int extraEnd = extraStart + extraBlock.getValueCount(valuesPosition); - for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { - double extraValue = extraBlock.getDouble(extraOffset); - TopLongDoubleAggregator.combine(state, groupId, vValue, extraValue); + int outputValueStart = outputValueBlock.getFirstValueIndex(valuesPosition); + int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(valuesPosition); + for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { + double outputValueValue = outputValueBlock.getDouble(outputValueOffset); + TopLongDoubleAggregator.combine(state, groupId, vValue, outputValueValue); } } } @@ -172,7 +172,7 @@ private void addRawInput(int positionOffset, IntArrayBlock groups, LongBlock vBl } private void addRawInput(int positionOffset, IntArrayBlock groups, LongVector vVector, - DoubleVector extraVector) { + DoubleVector outputValueVector) { for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { if (groups.isNull(groupPosition)) { continue; @@ -183,8 +183,8 @@ private void addRawInput(int positionOffset, IntArrayBlock groups, LongVector vV for (int g = groupStart; g < groupEnd; g++) { int groupId = groups.getInt(g); long vValue = vVector.getLong(valuesPosition); - double extraValue = extraVector.getDouble(valuesPosition); - TopLongDoubleAggregator.combine(state, groupId, vValue, extraValue); + double outputValueValue = outputValueVector.getDouble(valuesPosition); + TopLongDoubleAggregator.combine(state, groupId, vValue, outputValueValue); } } } @@ -198,12 +198,12 @@ public void addIntermediateInput(int positionOffset, IntArrayBlock groups, Page return; } LongBlock top = (LongBlock) topUncast; - Block extraUncast = page.getBlock(channels.get(1)); - if (extraUncast.areAllValuesNull()) { + Block outputUncast = page.getBlock(channels.get(1)); + if (outputUncast.areAllValuesNull()) { return; } - DoubleBlock extra = (DoubleBlock) extraUncast; - assert top.getPositionCount() == extra.getPositionCount(); + DoubleBlock output = (DoubleBlock) outputUncast; + assert top.getPositionCount() == output.getPositionCount(); for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { if (groups.isNull(groupPosition)) { continue; @@ -213,13 +213,13 @@ public void addIntermediateInput(int positionOffset, IntArrayBlock groups, Page for (int g = groupStart; g < groupEnd; g++) { int groupId = groups.getInt(g); int valuesPosition = groupPosition + positionOffset; - TopLongDoubleAggregator.combineIntermediate(state, groupId, top, extra, valuesPosition); + TopLongDoubleAggregator.combineIntermediate(state, groupId, top, output, valuesPosition); } } } private void addRawInput(int positionOffset, IntBigArrayBlock groups, LongBlock vBlock, - DoubleBlock extraBlock) { + DoubleBlock outputValueBlock) { for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { if (groups.isNull(groupPosition)) { continue; @@ -228,7 +228,7 @@ private void addRawInput(int positionOffset, IntBigArrayBlock groups, LongBlock if (vBlock.isNull(valuesPosition)) { continue; } - if (extraBlock.isNull(valuesPosition)) { + if (outputValueBlock.isNull(valuesPosition)) { continue; } int groupStart = groups.getFirstValueIndex(groupPosition); @@ -239,11 +239,11 @@ private void addRawInput(int positionOffset, IntBigArrayBlock groups, LongBlock int vEnd = vStart + vBlock.getValueCount(valuesPosition); for (int vOffset = vStart; vOffset < vEnd; vOffset++) { long vValue = vBlock.getLong(vOffset); - int extraStart = extraBlock.getFirstValueIndex(valuesPosition); - int extraEnd = extraStart + extraBlock.getValueCount(valuesPosition); - for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { - double extraValue = extraBlock.getDouble(extraOffset); - TopLongDoubleAggregator.combine(state, groupId, vValue, extraValue); + int outputValueStart = outputValueBlock.getFirstValueIndex(valuesPosition); + int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(valuesPosition); + for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { + double outputValueValue = outputValueBlock.getDouble(outputValueOffset); + TopLongDoubleAggregator.combine(state, groupId, vValue, outputValueValue); } } } @@ -251,7 +251,7 @@ private void addRawInput(int positionOffset, IntBigArrayBlock groups, LongBlock } private void addRawInput(int positionOffset, IntBigArrayBlock groups, LongVector vVector, - DoubleVector extraVector) { + DoubleVector outputValueVector) { for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { if (groups.isNull(groupPosition)) { continue; @@ -262,8 +262,8 @@ private void addRawInput(int positionOffset, IntBigArrayBlock groups, LongVector for (int g = groupStart; g < groupEnd; g++) { int groupId = groups.getInt(g); long vValue = vVector.getLong(valuesPosition); - double extraValue = extraVector.getDouble(valuesPosition); - TopLongDoubleAggregator.combine(state, groupId, vValue, extraValue); + double outputValueValue = outputValueVector.getDouble(valuesPosition); + TopLongDoubleAggregator.combine(state, groupId, vValue, outputValueValue); } } } @@ -277,12 +277,12 @@ public void addIntermediateInput(int positionOffset, IntBigArrayBlock groups, Pa return; } LongBlock top = (LongBlock) topUncast; - Block extraUncast = page.getBlock(channels.get(1)); - if (extraUncast.areAllValuesNull()) { + Block outputUncast = page.getBlock(channels.get(1)); + if (outputUncast.areAllValuesNull()) { return; } - DoubleBlock extra = (DoubleBlock) extraUncast; - assert top.getPositionCount() == extra.getPositionCount(); + DoubleBlock output = (DoubleBlock) outputUncast; + assert top.getPositionCount() == output.getPositionCount(); for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { if (groups.isNull(groupPosition)) { continue; @@ -292,19 +292,19 @@ public void addIntermediateInput(int positionOffset, IntBigArrayBlock groups, Pa for (int g = groupStart; g < groupEnd; g++) { int groupId = groups.getInt(g); int valuesPosition = groupPosition + positionOffset; - TopLongDoubleAggregator.combineIntermediate(state, groupId, top, extra, valuesPosition); + TopLongDoubleAggregator.combineIntermediate(state, groupId, top, output, valuesPosition); } } } private void addRawInput(int positionOffset, IntVector groups, LongBlock vBlock, - DoubleBlock extraBlock) { + DoubleBlock outputValueBlock) { for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { int valuesPosition = groupPosition + positionOffset; if (vBlock.isNull(valuesPosition)) { continue; } - if (extraBlock.isNull(valuesPosition)) { + if (outputValueBlock.isNull(valuesPosition)) { continue; } int groupId = groups.getInt(groupPosition); @@ -312,24 +312,24 @@ private void addRawInput(int positionOffset, IntVector groups, LongBlock vBlock, int vEnd = vStart + vBlock.getValueCount(valuesPosition); for (int vOffset = vStart; vOffset < vEnd; vOffset++) { long vValue = vBlock.getLong(vOffset); - int extraStart = extraBlock.getFirstValueIndex(valuesPosition); - int extraEnd = extraStart + extraBlock.getValueCount(valuesPosition); - for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { - double extraValue = extraBlock.getDouble(extraOffset); - TopLongDoubleAggregator.combine(state, groupId, vValue, extraValue); + int outputValueStart = outputValueBlock.getFirstValueIndex(valuesPosition); + int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(valuesPosition); + for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { + double outputValueValue = outputValueBlock.getDouble(outputValueOffset); + TopLongDoubleAggregator.combine(state, groupId, vValue, outputValueValue); } } } } private void addRawInput(int positionOffset, IntVector groups, LongVector vVector, - DoubleVector extraVector) { + DoubleVector outputValueVector) { for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { int valuesPosition = groupPosition + positionOffset; int groupId = groups.getInt(groupPosition); long vValue = vVector.getLong(valuesPosition); - double extraValue = extraVector.getDouble(valuesPosition); - TopLongDoubleAggregator.combine(state, groupId, vValue, extraValue); + double outputValueValue = outputValueVector.getDouble(valuesPosition); + TopLongDoubleAggregator.combine(state, groupId, vValue, outputValueValue); } } @@ -342,25 +342,25 @@ public void addIntermediateInput(int positionOffset, IntVector groups, Page page return; } LongBlock top = (LongBlock) topUncast; - Block extraUncast = page.getBlock(channels.get(1)); - if (extraUncast.areAllValuesNull()) { + Block outputUncast = page.getBlock(channels.get(1)); + if (outputUncast.areAllValuesNull()) { return; } - DoubleBlock extra = (DoubleBlock) extraUncast; - assert top.getPositionCount() == extra.getPositionCount(); + DoubleBlock output = (DoubleBlock) outputUncast; + assert top.getPositionCount() == output.getPositionCount(); for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { int groupId = groups.getInt(groupPosition); int valuesPosition = groupPosition + positionOffset; - TopLongDoubleAggregator.combineIntermediate(state, groupId, top, extra, valuesPosition); + TopLongDoubleAggregator.combineIntermediate(state, groupId, top, output, valuesPosition); } } private void maybeEnableGroupIdTracking(SeenGroupIds seenGroupIds, LongBlock vBlock, - DoubleBlock extraBlock) { + DoubleBlock outputValueBlock) { if (vBlock.mayHaveNulls()) { state.enableGroupIdTracking(seenGroupIds); } - if (extraBlock.mayHaveNulls()) { + if (outputValueBlock.mayHaveNulls()) { state.enableGroupIdTracking(seenGroupIds); } } diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongFloatAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongFloatAggregatorFunction.java index cb6b9cc988a27..d6661180b41da 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongFloatAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongFloatAggregatorFunction.java @@ -26,7 +26,7 @@ public final class TopLongFloatAggregatorFunction implements AggregatorFunction { private static final List INTERMEDIATE_STATE_DESC = List.of( new IntermediateStateDesc("top", ElementType.LONG), - new IntermediateStateDesc("extra", ElementType.FLOAT) ); + new IntermediateStateDesc("output", ElementType.FLOAT) ); private final DriverContext driverContext; @@ -74,78 +74,78 @@ public void addRawInput(Page page, BooleanVector mask) { private void addRawInputMasked(Page page, BooleanVector mask) { LongBlock vBlock = page.getBlock(channels.get(0)); - FloatBlock extraBlock = page.getBlock(channels.get(1)); + FloatBlock outputValueBlock = page.getBlock(channels.get(1)); LongVector vVector = vBlock.asVector(); if (vVector == null) { - addRawBlock(vBlock, extraBlock, mask); + addRawBlock(vBlock, outputValueBlock, mask); return; } - FloatVector extraVector = extraBlock.asVector(); - if (extraVector == null) { - addRawBlock(vBlock, extraBlock, mask); + FloatVector outputValueVector = outputValueBlock.asVector(); + if (outputValueVector == null) { + addRawBlock(vBlock, outputValueBlock, mask); return; } - addRawVector(vVector, extraVector, mask); + addRawVector(vVector, outputValueVector, mask); } private void addRawInputNotMasked(Page page) { LongBlock vBlock = page.getBlock(channels.get(0)); - FloatBlock extraBlock = page.getBlock(channels.get(1)); + FloatBlock outputValueBlock = page.getBlock(channels.get(1)); LongVector vVector = vBlock.asVector(); if (vVector == null) { - addRawBlock(vBlock, extraBlock); + addRawBlock(vBlock, outputValueBlock); return; } - FloatVector extraVector = extraBlock.asVector(); - if (extraVector == null) { - addRawBlock(vBlock, extraBlock); + FloatVector outputValueVector = outputValueBlock.asVector(); + if (outputValueVector == null) { + addRawBlock(vBlock, outputValueBlock); return; } - addRawVector(vVector, extraVector); + addRawVector(vVector, outputValueVector); } - private void addRawVector(LongVector vVector, FloatVector extraVector) { + private void addRawVector(LongVector vVector, FloatVector outputValueVector) { for (int valuesPosition = 0; valuesPosition < vVector.getPositionCount(); valuesPosition++) { long vValue = vVector.getLong(valuesPosition); - float extraValue = extraVector.getFloat(valuesPosition); - TopLongFloatAggregator.combine(state, vValue, extraValue); + float outputValueValue = outputValueVector.getFloat(valuesPosition); + TopLongFloatAggregator.combine(state, vValue, outputValueValue); } } - private void addRawVector(LongVector vVector, FloatVector extraVector, BooleanVector mask) { + private void addRawVector(LongVector vVector, FloatVector outputValueVector, BooleanVector mask) { for (int valuesPosition = 0; valuesPosition < vVector.getPositionCount(); valuesPosition++) { if (mask.getBoolean(valuesPosition) == false) { continue; } long vValue = vVector.getLong(valuesPosition); - float extraValue = extraVector.getFloat(valuesPosition); - TopLongFloatAggregator.combine(state, vValue, extraValue); + float outputValueValue = outputValueVector.getFloat(valuesPosition); + TopLongFloatAggregator.combine(state, vValue, outputValueValue); } } - private void addRawBlock(LongBlock vBlock, FloatBlock extraBlock) { + private void addRawBlock(LongBlock vBlock, FloatBlock outputValueBlock) { for (int p = 0; p < vBlock.getPositionCount(); p++) { if (vBlock.isNull(p)) { continue; } - if (extraBlock.isNull(p)) { + if (outputValueBlock.isNull(p)) { continue; } int vStart = vBlock.getFirstValueIndex(p); int vEnd = vStart + vBlock.getValueCount(p); for (int vOffset = vStart; vOffset < vEnd; vOffset++) { long vValue = vBlock.getLong(vOffset); - int extraStart = extraBlock.getFirstValueIndex(p); - int extraEnd = extraStart + extraBlock.getValueCount(p); - for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { - float extraValue = extraBlock.getFloat(extraOffset); - TopLongFloatAggregator.combine(state, vValue, extraValue); + int outputValueStart = outputValueBlock.getFirstValueIndex(p); + int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(p); + for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { + float outputValueValue = outputValueBlock.getFloat(outputValueOffset); + TopLongFloatAggregator.combine(state, vValue, outputValueValue); } } } } - private void addRawBlock(LongBlock vBlock, FloatBlock extraBlock, BooleanVector mask) { + private void addRawBlock(LongBlock vBlock, FloatBlock outputValueBlock, BooleanVector mask) { for (int p = 0; p < vBlock.getPositionCount(); p++) { if (mask.getBoolean(p) == false) { continue; @@ -153,18 +153,18 @@ private void addRawBlock(LongBlock vBlock, FloatBlock extraBlock, BooleanVector if (vBlock.isNull(p)) { continue; } - if (extraBlock.isNull(p)) { + if (outputValueBlock.isNull(p)) { continue; } int vStart = vBlock.getFirstValueIndex(p); int vEnd = vStart + vBlock.getValueCount(p); for (int vOffset = vStart; vOffset < vEnd; vOffset++) { long vValue = vBlock.getLong(vOffset); - int extraStart = extraBlock.getFirstValueIndex(p); - int extraEnd = extraStart + extraBlock.getValueCount(p); - for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { - float extraValue = extraBlock.getFloat(extraOffset); - TopLongFloatAggregator.combine(state, vValue, extraValue); + int outputValueStart = outputValueBlock.getFirstValueIndex(p); + int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(p); + for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { + float outputValueValue = outputValueBlock.getFloat(outputValueOffset); + TopLongFloatAggregator.combine(state, vValue, outputValueValue); } } } @@ -180,13 +180,13 @@ public void addIntermediateInput(Page page) { } LongBlock top = (LongBlock) topUncast; assert top.getPositionCount() == 1; - Block extraUncast = page.getBlock(channels.get(1)); - if (extraUncast.areAllValuesNull()) { + Block outputUncast = page.getBlock(channels.get(1)); + if (outputUncast.areAllValuesNull()) { return; } - FloatBlock extra = (FloatBlock) extraUncast; - assert extra.getPositionCount() == 1; - TopLongFloatAggregator.combineIntermediate(state, top, extra); + FloatBlock output = (FloatBlock) outputUncast; + assert output.getPositionCount() == 1; + TopLongFloatAggregator.combineIntermediate(state, top, output); } @Override diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongFloatGroupingAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongFloatGroupingAggregatorFunction.java index 060c41f9d4216..b91efe7571529 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongFloatGroupingAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongFloatGroupingAggregatorFunction.java @@ -28,7 +28,7 @@ public final class TopLongFloatGroupingAggregatorFunction implements GroupingAggregatorFunction { private static final List INTERMEDIATE_STATE_DESC = List.of( new IntermediateStateDesc("top", ElementType.LONG), - new IntermediateStateDesc("extra", ElementType.FLOAT) ); + new IntermediateStateDesc("output", ElementType.FLOAT) ); private final TopLongFloatAggregator.GroupingState state; @@ -68,24 +68,24 @@ public int intermediateBlockCount() { public GroupingAggregatorFunction.AddInput prepareProcessRawInputPage(SeenGroupIds seenGroupIds, Page page) { LongBlock vBlock = page.getBlock(channels.get(0)); - FloatBlock extraBlock = page.getBlock(channels.get(1)); + FloatBlock outputValueBlock = page.getBlock(channels.get(1)); LongVector vVector = vBlock.asVector(); if (vVector == null) { - maybeEnableGroupIdTracking(seenGroupIds, vBlock, extraBlock); + maybeEnableGroupIdTracking(seenGroupIds, vBlock, outputValueBlock); return new GroupingAggregatorFunction.AddInput() { @Override public void add(int positionOffset, IntArrayBlock groupIds) { - addRawInput(positionOffset, groupIds, vBlock, extraBlock); + addRawInput(positionOffset, groupIds, vBlock, outputValueBlock); } @Override public void add(int positionOffset, IntBigArrayBlock groupIds) { - addRawInput(positionOffset, groupIds, vBlock, extraBlock); + addRawInput(positionOffset, groupIds, vBlock, outputValueBlock); } @Override public void add(int positionOffset, IntVector groupIds) { - addRawInput(positionOffset, groupIds, vBlock, extraBlock); + addRawInput(positionOffset, groupIds, vBlock, outputValueBlock); } @Override @@ -93,23 +93,23 @@ public void close() { } }; } - FloatVector extraVector = extraBlock.asVector(); - if (extraVector == null) { - maybeEnableGroupIdTracking(seenGroupIds, vBlock, extraBlock); + FloatVector outputValueVector = outputValueBlock.asVector(); + if (outputValueVector == null) { + maybeEnableGroupIdTracking(seenGroupIds, vBlock, outputValueBlock); return new GroupingAggregatorFunction.AddInput() { @Override public void add(int positionOffset, IntArrayBlock groupIds) { - addRawInput(positionOffset, groupIds, vBlock, extraBlock); + addRawInput(positionOffset, groupIds, vBlock, outputValueBlock); } @Override public void add(int positionOffset, IntBigArrayBlock groupIds) { - addRawInput(positionOffset, groupIds, vBlock, extraBlock); + addRawInput(positionOffset, groupIds, vBlock, outputValueBlock); } @Override public void add(int positionOffset, IntVector groupIds) { - addRawInput(positionOffset, groupIds, vBlock, extraBlock); + addRawInput(positionOffset, groupIds, vBlock, outputValueBlock); } @Override @@ -120,17 +120,17 @@ public void close() { return new GroupingAggregatorFunction.AddInput() { @Override public void add(int positionOffset, IntArrayBlock groupIds) { - addRawInput(positionOffset, groupIds, vVector, extraVector); + addRawInput(positionOffset, groupIds, vVector, outputValueVector); } @Override public void add(int positionOffset, IntBigArrayBlock groupIds) { - addRawInput(positionOffset, groupIds, vVector, extraVector); + addRawInput(positionOffset, groupIds, vVector, outputValueVector); } @Override public void add(int positionOffset, IntVector groupIds) { - addRawInput(positionOffset, groupIds, vVector, extraVector); + addRawInput(positionOffset, groupIds, vVector, outputValueVector); } @Override @@ -140,7 +140,7 @@ public void close() { } private void addRawInput(int positionOffset, IntArrayBlock groups, LongBlock vBlock, - FloatBlock extraBlock) { + FloatBlock outputValueBlock) { for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { if (groups.isNull(groupPosition)) { continue; @@ -149,7 +149,7 @@ private void addRawInput(int positionOffset, IntArrayBlock groups, LongBlock vBl if (vBlock.isNull(valuesPosition)) { continue; } - if (extraBlock.isNull(valuesPosition)) { + if (outputValueBlock.isNull(valuesPosition)) { continue; } int groupStart = groups.getFirstValueIndex(groupPosition); @@ -160,11 +160,11 @@ private void addRawInput(int positionOffset, IntArrayBlock groups, LongBlock vBl int vEnd = vStart + vBlock.getValueCount(valuesPosition); for (int vOffset = vStart; vOffset < vEnd; vOffset++) { long vValue = vBlock.getLong(vOffset); - int extraStart = extraBlock.getFirstValueIndex(valuesPosition); - int extraEnd = extraStart + extraBlock.getValueCount(valuesPosition); - for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { - float extraValue = extraBlock.getFloat(extraOffset); - TopLongFloatAggregator.combine(state, groupId, vValue, extraValue); + int outputValueStart = outputValueBlock.getFirstValueIndex(valuesPosition); + int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(valuesPosition); + for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { + float outputValueValue = outputValueBlock.getFloat(outputValueOffset); + TopLongFloatAggregator.combine(state, groupId, vValue, outputValueValue); } } } @@ -172,7 +172,7 @@ private void addRawInput(int positionOffset, IntArrayBlock groups, LongBlock vBl } private void addRawInput(int positionOffset, IntArrayBlock groups, LongVector vVector, - FloatVector extraVector) { + FloatVector outputValueVector) { for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { if (groups.isNull(groupPosition)) { continue; @@ -183,8 +183,8 @@ private void addRawInput(int positionOffset, IntArrayBlock groups, LongVector vV for (int g = groupStart; g < groupEnd; g++) { int groupId = groups.getInt(g); long vValue = vVector.getLong(valuesPosition); - float extraValue = extraVector.getFloat(valuesPosition); - TopLongFloatAggregator.combine(state, groupId, vValue, extraValue); + float outputValueValue = outputValueVector.getFloat(valuesPosition); + TopLongFloatAggregator.combine(state, groupId, vValue, outputValueValue); } } } @@ -198,12 +198,12 @@ public void addIntermediateInput(int positionOffset, IntArrayBlock groups, Page return; } LongBlock top = (LongBlock) topUncast; - Block extraUncast = page.getBlock(channels.get(1)); - if (extraUncast.areAllValuesNull()) { + Block outputUncast = page.getBlock(channels.get(1)); + if (outputUncast.areAllValuesNull()) { return; } - FloatBlock extra = (FloatBlock) extraUncast; - assert top.getPositionCount() == extra.getPositionCount(); + FloatBlock output = (FloatBlock) outputUncast; + assert top.getPositionCount() == output.getPositionCount(); for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { if (groups.isNull(groupPosition)) { continue; @@ -213,13 +213,13 @@ public void addIntermediateInput(int positionOffset, IntArrayBlock groups, Page for (int g = groupStart; g < groupEnd; g++) { int groupId = groups.getInt(g); int valuesPosition = groupPosition + positionOffset; - TopLongFloatAggregator.combineIntermediate(state, groupId, top, extra, valuesPosition); + TopLongFloatAggregator.combineIntermediate(state, groupId, top, output, valuesPosition); } } } private void addRawInput(int positionOffset, IntBigArrayBlock groups, LongBlock vBlock, - FloatBlock extraBlock) { + FloatBlock outputValueBlock) { for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { if (groups.isNull(groupPosition)) { continue; @@ -228,7 +228,7 @@ private void addRawInput(int positionOffset, IntBigArrayBlock groups, LongBlock if (vBlock.isNull(valuesPosition)) { continue; } - if (extraBlock.isNull(valuesPosition)) { + if (outputValueBlock.isNull(valuesPosition)) { continue; } int groupStart = groups.getFirstValueIndex(groupPosition); @@ -239,11 +239,11 @@ private void addRawInput(int positionOffset, IntBigArrayBlock groups, LongBlock int vEnd = vStart + vBlock.getValueCount(valuesPosition); for (int vOffset = vStart; vOffset < vEnd; vOffset++) { long vValue = vBlock.getLong(vOffset); - int extraStart = extraBlock.getFirstValueIndex(valuesPosition); - int extraEnd = extraStart + extraBlock.getValueCount(valuesPosition); - for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { - float extraValue = extraBlock.getFloat(extraOffset); - TopLongFloatAggregator.combine(state, groupId, vValue, extraValue); + int outputValueStart = outputValueBlock.getFirstValueIndex(valuesPosition); + int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(valuesPosition); + for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { + float outputValueValue = outputValueBlock.getFloat(outputValueOffset); + TopLongFloatAggregator.combine(state, groupId, vValue, outputValueValue); } } } @@ -251,7 +251,7 @@ private void addRawInput(int positionOffset, IntBigArrayBlock groups, LongBlock } private void addRawInput(int positionOffset, IntBigArrayBlock groups, LongVector vVector, - FloatVector extraVector) { + FloatVector outputValueVector) { for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { if (groups.isNull(groupPosition)) { continue; @@ -262,8 +262,8 @@ private void addRawInput(int positionOffset, IntBigArrayBlock groups, LongVector for (int g = groupStart; g < groupEnd; g++) { int groupId = groups.getInt(g); long vValue = vVector.getLong(valuesPosition); - float extraValue = extraVector.getFloat(valuesPosition); - TopLongFloatAggregator.combine(state, groupId, vValue, extraValue); + float outputValueValue = outputValueVector.getFloat(valuesPosition); + TopLongFloatAggregator.combine(state, groupId, vValue, outputValueValue); } } } @@ -277,12 +277,12 @@ public void addIntermediateInput(int positionOffset, IntBigArrayBlock groups, Pa return; } LongBlock top = (LongBlock) topUncast; - Block extraUncast = page.getBlock(channels.get(1)); - if (extraUncast.areAllValuesNull()) { + Block outputUncast = page.getBlock(channels.get(1)); + if (outputUncast.areAllValuesNull()) { return; } - FloatBlock extra = (FloatBlock) extraUncast; - assert top.getPositionCount() == extra.getPositionCount(); + FloatBlock output = (FloatBlock) outputUncast; + assert top.getPositionCount() == output.getPositionCount(); for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { if (groups.isNull(groupPosition)) { continue; @@ -292,19 +292,19 @@ public void addIntermediateInput(int positionOffset, IntBigArrayBlock groups, Pa for (int g = groupStart; g < groupEnd; g++) { int groupId = groups.getInt(g); int valuesPosition = groupPosition + positionOffset; - TopLongFloatAggregator.combineIntermediate(state, groupId, top, extra, valuesPosition); + TopLongFloatAggregator.combineIntermediate(state, groupId, top, output, valuesPosition); } } } private void addRawInput(int positionOffset, IntVector groups, LongBlock vBlock, - FloatBlock extraBlock) { + FloatBlock outputValueBlock) { for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { int valuesPosition = groupPosition + positionOffset; if (vBlock.isNull(valuesPosition)) { continue; } - if (extraBlock.isNull(valuesPosition)) { + if (outputValueBlock.isNull(valuesPosition)) { continue; } int groupId = groups.getInt(groupPosition); @@ -312,24 +312,24 @@ private void addRawInput(int positionOffset, IntVector groups, LongBlock vBlock, int vEnd = vStart + vBlock.getValueCount(valuesPosition); for (int vOffset = vStart; vOffset < vEnd; vOffset++) { long vValue = vBlock.getLong(vOffset); - int extraStart = extraBlock.getFirstValueIndex(valuesPosition); - int extraEnd = extraStart + extraBlock.getValueCount(valuesPosition); - for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { - float extraValue = extraBlock.getFloat(extraOffset); - TopLongFloatAggregator.combine(state, groupId, vValue, extraValue); + int outputValueStart = outputValueBlock.getFirstValueIndex(valuesPosition); + int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(valuesPosition); + for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { + float outputValueValue = outputValueBlock.getFloat(outputValueOffset); + TopLongFloatAggregator.combine(state, groupId, vValue, outputValueValue); } } } } private void addRawInput(int positionOffset, IntVector groups, LongVector vVector, - FloatVector extraVector) { + FloatVector outputValueVector) { for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { int valuesPosition = groupPosition + positionOffset; int groupId = groups.getInt(groupPosition); long vValue = vVector.getLong(valuesPosition); - float extraValue = extraVector.getFloat(valuesPosition); - TopLongFloatAggregator.combine(state, groupId, vValue, extraValue); + float outputValueValue = outputValueVector.getFloat(valuesPosition); + TopLongFloatAggregator.combine(state, groupId, vValue, outputValueValue); } } @@ -342,25 +342,25 @@ public void addIntermediateInput(int positionOffset, IntVector groups, Page page return; } LongBlock top = (LongBlock) topUncast; - Block extraUncast = page.getBlock(channels.get(1)); - if (extraUncast.areAllValuesNull()) { + Block outputUncast = page.getBlock(channels.get(1)); + if (outputUncast.areAllValuesNull()) { return; } - FloatBlock extra = (FloatBlock) extraUncast; - assert top.getPositionCount() == extra.getPositionCount(); + FloatBlock output = (FloatBlock) outputUncast; + assert top.getPositionCount() == output.getPositionCount(); for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { int groupId = groups.getInt(groupPosition); int valuesPosition = groupPosition + positionOffset; - TopLongFloatAggregator.combineIntermediate(state, groupId, top, extra, valuesPosition); + TopLongFloatAggregator.combineIntermediate(state, groupId, top, output, valuesPosition); } } private void maybeEnableGroupIdTracking(SeenGroupIds seenGroupIds, LongBlock vBlock, - FloatBlock extraBlock) { + FloatBlock outputValueBlock) { if (vBlock.mayHaveNulls()) { state.enableGroupIdTracking(seenGroupIds); } - if (extraBlock.mayHaveNulls()) { + if (outputValueBlock.mayHaveNulls()) { state.enableGroupIdTracking(seenGroupIds); } } diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongIntAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongIntAggregatorFunction.java index 799439e9c0876..61abc3a436a1d 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongIntAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongIntAggregatorFunction.java @@ -26,7 +26,7 @@ public final class TopLongIntAggregatorFunction implements AggregatorFunction { private static final List INTERMEDIATE_STATE_DESC = List.of( new IntermediateStateDesc("top", ElementType.LONG), - new IntermediateStateDesc("extra", ElementType.INT) ); + new IntermediateStateDesc("output", ElementType.INT) ); private final DriverContext driverContext; @@ -74,78 +74,78 @@ public void addRawInput(Page page, BooleanVector mask) { private void addRawInputMasked(Page page, BooleanVector mask) { LongBlock vBlock = page.getBlock(channels.get(0)); - IntBlock extraBlock = page.getBlock(channels.get(1)); + IntBlock outputValueBlock = page.getBlock(channels.get(1)); LongVector vVector = vBlock.asVector(); if (vVector == null) { - addRawBlock(vBlock, extraBlock, mask); + addRawBlock(vBlock, outputValueBlock, mask); return; } - IntVector extraVector = extraBlock.asVector(); - if (extraVector == null) { - addRawBlock(vBlock, extraBlock, mask); + IntVector outputValueVector = outputValueBlock.asVector(); + if (outputValueVector == null) { + addRawBlock(vBlock, outputValueBlock, mask); return; } - addRawVector(vVector, extraVector, mask); + addRawVector(vVector, outputValueVector, mask); } private void addRawInputNotMasked(Page page) { LongBlock vBlock = page.getBlock(channels.get(0)); - IntBlock extraBlock = page.getBlock(channels.get(1)); + IntBlock outputValueBlock = page.getBlock(channels.get(1)); LongVector vVector = vBlock.asVector(); if (vVector == null) { - addRawBlock(vBlock, extraBlock); + addRawBlock(vBlock, outputValueBlock); return; } - IntVector extraVector = extraBlock.asVector(); - if (extraVector == null) { - addRawBlock(vBlock, extraBlock); + IntVector outputValueVector = outputValueBlock.asVector(); + if (outputValueVector == null) { + addRawBlock(vBlock, outputValueBlock); return; } - addRawVector(vVector, extraVector); + addRawVector(vVector, outputValueVector); } - private void addRawVector(LongVector vVector, IntVector extraVector) { + private void addRawVector(LongVector vVector, IntVector outputValueVector) { for (int valuesPosition = 0; valuesPosition < vVector.getPositionCount(); valuesPosition++) { long vValue = vVector.getLong(valuesPosition); - int extraValue = extraVector.getInt(valuesPosition); - TopLongIntAggregator.combine(state, vValue, extraValue); + int outputValueValue = outputValueVector.getInt(valuesPosition); + TopLongIntAggregator.combine(state, vValue, outputValueValue); } } - private void addRawVector(LongVector vVector, IntVector extraVector, BooleanVector mask) { + private void addRawVector(LongVector vVector, IntVector outputValueVector, BooleanVector mask) { for (int valuesPosition = 0; valuesPosition < vVector.getPositionCount(); valuesPosition++) { if (mask.getBoolean(valuesPosition) == false) { continue; } long vValue = vVector.getLong(valuesPosition); - int extraValue = extraVector.getInt(valuesPosition); - TopLongIntAggregator.combine(state, vValue, extraValue); + int outputValueValue = outputValueVector.getInt(valuesPosition); + TopLongIntAggregator.combine(state, vValue, outputValueValue); } } - private void addRawBlock(LongBlock vBlock, IntBlock extraBlock) { + private void addRawBlock(LongBlock vBlock, IntBlock outputValueBlock) { for (int p = 0; p < vBlock.getPositionCount(); p++) { if (vBlock.isNull(p)) { continue; } - if (extraBlock.isNull(p)) { + if (outputValueBlock.isNull(p)) { continue; } int vStart = vBlock.getFirstValueIndex(p); int vEnd = vStart + vBlock.getValueCount(p); for (int vOffset = vStart; vOffset < vEnd; vOffset++) { long vValue = vBlock.getLong(vOffset); - int extraStart = extraBlock.getFirstValueIndex(p); - int extraEnd = extraStart + extraBlock.getValueCount(p); - for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { - int extraValue = extraBlock.getInt(extraOffset); - TopLongIntAggregator.combine(state, vValue, extraValue); + int outputValueStart = outputValueBlock.getFirstValueIndex(p); + int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(p); + for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { + int outputValueValue = outputValueBlock.getInt(outputValueOffset); + TopLongIntAggregator.combine(state, vValue, outputValueValue); } } } } - private void addRawBlock(LongBlock vBlock, IntBlock extraBlock, BooleanVector mask) { + private void addRawBlock(LongBlock vBlock, IntBlock outputValueBlock, BooleanVector mask) { for (int p = 0; p < vBlock.getPositionCount(); p++) { if (mask.getBoolean(p) == false) { continue; @@ -153,18 +153,18 @@ private void addRawBlock(LongBlock vBlock, IntBlock extraBlock, BooleanVector ma if (vBlock.isNull(p)) { continue; } - if (extraBlock.isNull(p)) { + if (outputValueBlock.isNull(p)) { continue; } int vStart = vBlock.getFirstValueIndex(p); int vEnd = vStart + vBlock.getValueCount(p); for (int vOffset = vStart; vOffset < vEnd; vOffset++) { long vValue = vBlock.getLong(vOffset); - int extraStart = extraBlock.getFirstValueIndex(p); - int extraEnd = extraStart + extraBlock.getValueCount(p); - for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { - int extraValue = extraBlock.getInt(extraOffset); - TopLongIntAggregator.combine(state, vValue, extraValue); + int outputValueStart = outputValueBlock.getFirstValueIndex(p); + int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(p); + for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { + int outputValueValue = outputValueBlock.getInt(outputValueOffset); + TopLongIntAggregator.combine(state, vValue, outputValueValue); } } } @@ -180,13 +180,13 @@ public void addIntermediateInput(Page page) { } LongBlock top = (LongBlock) topUncast; assert top.getPositionCount() == 1; - Block extraUncast = page.getBlock(channels.get(1)); - if (extraUncast.areAllValuesNull()) { + Block outputUncast = page.getBlock(channels.get(1)); + if (outputUncast.areAllValuesNull()) { return; } - IntBlock extra = (IntBlock) extraUncast; - assert extra.getPositionCount() == 1; - TopLongIntAggregator.combineIntermediate(state, top, extra); + IntBlock output = (IntBlock) outputUncast; + assert output.getPositionCount() == 1; + TopLongIntAggregator.combineIntermediate(state, top, output); } @Override diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongIntGroupingAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongIntGroupingAggregatorFunction.java index dffa501f4c939..3a78089397a4c 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongIntGroupingAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongIntGroupingAggregatorFunction.java @@ -27,7 +27,7 @@ public final class TopLongIntGroupingAggregatorFunction implements GroupingAggregatorFunction { private static final List INTERMEDIATE_STATE_DESC = List.of( new IntermediateStateDesc("top", ElementType.LONG), - new IntermediateStateDesc("extra", ElementType.INT) ); + new IntermediateStateDesc("output", ElementType.INT) ); private final TopLongIntAggregator.GroupingState state; @@ -67,24 +67,24 @@ public int intermediateBlockCount() { public GroupingAggregatorFunction.AddInput prepareProcessRawInputPage(SeenGroupIds seenGroupIds, Page page) { LongBlock vBlock = page.getBlock(channels.get(0)); - IntBlock extraBlock = page.getBlock(channels.get(1)); + IntBlock outputValueBlock = page.getBlock(channels.get(1)); LongVector vVector = vBlock.asVector(); if (vVector == null) { - maybeEnableGroupIdTracking(seenGroupIds, vBlock, extraBlock); + maybeEnableGroupIdTracking(seenGroupIds, vBlock, outputValueBlock); return new GroupingAggregatorFunction.AddInput() { @Override public void add(int positionOffset, IntArrayBlock groupIds) { - addRawInput(positionOffset, groupIds, vBlock, extraBlock); + addRawInput(positionOffset, groupIds, vBlock, outputValueBlock); } @Override public void add(int positionOffset, IntBigArrayBlock groupIds) { - addRawInput(positionOffset, groupIds, vBlock, extraBlock); + addRawInput(positionOffset, groupIds, vBlock, outputValueBlock); } @Override public void add(int positionOffset, IntVector groupIds) { - addRawInput(positionOffset, groupIds, vBlock, extraBlock); + addRawInput(positionOffset, groupIds, vBlock, outputValueBlock); } @Override @@ -92,23 +92,23 @@ public void close() { } }; } - IntVector extraVector = extraBlock.asVector(); - if (extraVector == null) { - maybeEnableGroupIdTracking(seenGroupIds, vBlock, extraBlock); + IntVector outputValueVector = outputValueBlock.asVector(); + if (outputValueVector == null) { + maybeEnableGroupIdTracking(seenGroupIds, vBlock, outputValueBlock); return new GroupingAggregatorFunction.AddInput() { @Override public void add(int positionOffset, IntArrayBlock groupIds) { - addRawInput(positionOffset, groupIds, vBlock, extraBlock); + addRawInput(positionOffset, groupIds, vBlock, outputValueBlock); } @Override public void add(int positionOffset, IntBigArrayBlock groupIds) { - addRawInput(positionOffset, groupIds, vBlock, extraBlock); + addRawInput(positionOffset, groupIds, vBlock, outputValueBlock); } @Override public void add(int positionOffset, IntVector groupIds) { - addRawInput(positionOffset, groupIds, vBlock, extraBlock); + addRawInput(positionOffset, groupIds, vBlock, outputValueBlock); } @Override @@ -119,17 +119,17 @@ public void close() { return new GroupingAggregatorFunction.AddInput() { @Override public void add(int positionOffset, IntArrayBlock groupIds) { - addRawInput(positionOffset, groupIds, vVector, extraVector); + addRawInput(positionOffset, groupIds, vVector, outputValueVector); } @Override public void add(int positionOffset, IntBigArrayBlock groupIds) { - addRawInput(positionOffset, groupIds, vVector, extraVector); + addRawInput(positionOffset, groupIds, vVector, outputValueVector); } @Override public void add(int positionOffset, IntVector groupIds) { - addRawInput(positionOffset, groupIds, vVector, extraVector); + addRawInput(positionOffset, groupIds, vVector, outputValueVector); } @Override @@ -139,7 +139,7 @@ public void close() { } private void addRawInput(int positionOffset, IntArrayBlock groups, LongBlock vBlock, - IntBlock extraBlock) { + IntBlock outputValueBlock) { for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { if (groups.isNull(groupPosition)) { continue; @@ -148,7 +148,7 @@ private void addRawInput(int positionOffset, IntArrayBlock groups, LongBlock vBl if (vBlock.isNull(valuesPosition)) { continue; } - if (extraBlock.isNull(valuesPosition)) { + if (outputValueBlock.isNull(valuesPosition)) { continue; } int groupStart = groups.getFirstValueIndex(groupPosition); @@ -159,11 +159,11 @@ private void addRawInput(int positionOffset, IntArrayBlock groups, LongBlock vBl int vEnd = vStart + vBlock.getValueCount(valuesPosition); for (int vOffset = vStart; vOffset < vEnd; vOffset++) { long vValue = vBlock.getLong(vOffset); - int extraStart = extraBlock.getFirstValueIndex(valuesPosition); - int extraEnd = extraStart + extraBlock.getValueCount(valuesPosition); - for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { - int extraValue = extraBlock.getInt(extraOffset); - TopLongIntAggregator.combine(state, groupId, vValue, extraValue); + int outputValueStart = outputValueBlock.getFirstValueIndex(valuesPosition); + int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(valuesPosition); + for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { + int outputValueValue = outputValueBlock.getInt(outputValueOffset); + TopLongIntAggregator.combine(state, groupId, vValue, outputValueValue); } } } @@ -171,7 +171,7 @@ private void addRawInput(int positionOffset, IntArrayBlock groups, LongBlock vBl } private void addRawInput(int positionOffset, IntArrayBlock groups, LongVector vVector, - IntVector extraVector) { + IntVector outputValueVector) { for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { if (groups.isNull(groupPosition)) { continue; @@ -182,8 +182,8 @@ private void addRawInput(int positionOffset, IntArrayBlock groups, LongVector vV for (int g = groupStart; g < groupEnd; g++) { int groupId = groups.getInt(g); long vValue = vVector.getLong(valuesPosition); - int extraValue = extraVector.getInt(valuesPosition); - TopLongIntAggregator.combine(state, groupId, vValue, extraValue); + int outputValueValue = outputValueVector.getInt(valuesPosition); + TopLongIntAggregator.combine(state, groupId, vValue, outputValueValue); } } } @@ -197,12 +197,12 @@ public void addIntermediateInput(int positionOffset, IntArrayBlock groups, Page return; } LongBlock top = (LongBlock) topUncast; - Block extraUncast = page.getBlock(channels.get(1)); - if (extraUncast.areAllValuesNull()) { + Block outputUncast = page.getBlock(channels.get(1)); + if (outputUncast.areAllValuesNull()) { return; } - IntBlock extra = (IntBlock) extraUncast; - assert top.getPositionCount() == extra.getPositionCount(); + IntBlock output = (IntBlock) outputUncast; + assert top.getPositionCount() == output.getPositionCount(); for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { if (groups.isNull(groupPosition)) { continue; @@ -212,13 +212,13 @@ public void addIntermediateInput(int positionOffset, IntArrayBlock groups, Page for (int g = groupStart; g < groupEnd; g++) { int groupId = groups.getInt(g); int valuesPosition = groupPosition + positionOffset; - TopLongIntAggregator.combineIntermediate(state, groupId, top, extra, valuesPosition); + TopLongIntAggregator.combineIntermediate(state, groupId, top, output, valuesPosition); } } } private void addRawInput(int positionOffset, IntBigArrayBlock groups, LongBlock vBlock, - IntBlock extraBlock) { + IntBlock outputValueBlock) { for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { if (groups.isNull(groupPosition)) { continue; @@ -227,7 +227,7 @@ private void addRawInput(int positionOffset, IntBigArrayBlock groups, LongBlock if (vBlock.isNull(valuesPosition)) { continue; } - if (extraBlock.isNull(valuesPosition)) { + if (outputValueBlock.isNull(valuesPosition)) { continue; } int groupStart = groups.getFirstValueIndex(groupPosition); @@ -238,11 +238,11 @@ private void addRawInput(int positionOffset, IntBigArrayBlock groups, LongBlock int vEnd = vStart + vBlock.getValueCount(valuesPosition); for (int vOffset = vStart; vOffset < vEnd; vOffset++) { long vValue = vBlock.getLong(vOffset); - int extraStart = extraBlock.getFirstValueIndex(valuesPosition); - int extraEnd = extraStart + extraBlock.getValueCount(valuesPosition); - for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { - int extraValue = extraBlock.getInt(extraOffset); - TopLongIntAggregator.combine(state, groupId, vValue, extraValue); + int outputValueStart = outputValueBlock.getFirstValueIndex(valuesPosition); + int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(valuesPosition); + for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { + int outputValueValue = outputValueBlock.getInt(outputValueOffset); + TopLongIntAggregator.combine(state, groupId, vValue, outputValueValue); } } } @@ -250,7 +250,7 @@ private void addRawInput(int positionOffset, IntBigArrayBlock groups, LongBlock } private void addRawInput(int positionOffset, IntBigArrayBlock groups, LongVector vVector, - IntVector extraVector) { + IntVector outputValueVector) { for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { if (groups.isNull(groupPosition)) { continue; @@ -261,8 +261,8 @@ private void addRawInput(int positionOffset, IntBigArrayBlock groups, LongVector for (int g = groupStart; g < groupEnd; g++) { int groupId = groups.getInt(g); long vValue = vVector.getLong(valuesPosition); - int extraValue = extraVector.getInt(valuesPosition); - TopLongIntAggregator.combine(state, groupId, vValue, extraValue); + int outputValueValue = outputValueVector.getInt(valuesPosition); + TopLongIntAggregator.combine(state, groupId, vValue, outputValueValue); } } } @@ -276,12 +276,12 @@ public void addIntermediateInput(int positionOffset, IntBigArrayBlock groups, Pa return; } LongBlock top = (LongBlock) topUncast; - Block extraUncast = page.getBlock(channels.get(1)); - if (extraUncast.areAllValuesNull()) { + Block outputUncast = page.getBlock(channels.get(1)); + if (outputUncast.areAllValuesNull()) { return; } - IntBlock extra = (IntBlock) extraUncast; - assert top.getPositionCount() == extra.getPositionCount(); + IntBlock output = (IntBlock) outputUncast; + assert top.getPositionCount() == output.getPositionCount(); for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { if (groups.isNull(groupPosition)) { continue; @@ -291,19 +291,19 @@ public void addIntermediateInput(int positionOffset, IntBigArrayBlock groups, Pa for (int g = groupStart; g < groupEnd; g++) { int groupId = groups.getInt(g); int valuesPosition = groupPosition + positionOffset; - TopLongIntAggregator.combineIntermediate(state, groupId, top, extra, valuesPosition); + TopLongIntAggregator.combineIntermediate(state, groupId, top, output, valuesPosition); } } } private void addRawInput(int positionOffset, IntVector groups, LongBlock vBlock, - IntBlock extraBlock) { + IntBlock outputValueBlock) { for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { int valuesPosition = groupPosition + positionOffset; if (vBlock.isNull(valuesPosition)) { continue; } - if (extraBlock.isNull(valuesPosition)) { + if (outputValueBlock.isNull(valuesPosition)) { continue; } int groupId = groups.getInt(groupPosition); @@ -311,24 +311,24 @@ private void addRawInput(int positionOffset, IntVector groups, LongBlock vBlock, int vEnd = vStart + vBlock.getValueCount(valuesPosition); for (int vOffset = vStart; vOffset < vEnd; vOffset++) { long vValue = vBlock.getLong(vOffset); - int extraStart = extraBlock.getFirstValueIndex(valuesPosition); - int extraEnd = extraStart + extraBlock.getValueCount(valuesPosition); - for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { - int extraValue = extraBlock.getInt(extraOffset); - TopLongIntAggregator.combine(state, groupId, vValue, extraValue); + int outputValueStart = outputValueBlock.getFirstValueIndex(valuesPosition); + int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(valuesPosition); + for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { + int outputValueValue = outputValueBlock.getInt(outputValueOffset); + TopLongIntAggregator.combine(state, groupId, vValue, outputValueValue); } } } } private void addRawInput(int positionOffset, IntVector groups, LongVector vVector, - IntVector extraVector) { + IntVector outputValueVector) { for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { int valuesPosition = groupPosition + positionOffset; int groupId = groups.getInt(groupPosition); long vValue = vVector.getLong(valuesPosition); - int extraValue = extraVector.getInt(valuesPosition); - TopLongIntAggregator.combine(state, groupId, vValue, extraValue); + int outputValueValue = outputValueVector.getInt(valuesPosition); + TopLongIntAggregator.combine(state, groupId, vValue, outputValueValue); } } @@ -341,25 +341,25 @@ public void addIntermediateInput(int positionOffset, IntVector groups, Page page return; } LongBlock top = (LongBlock) topUncast; - Block extraUncast = page.getBlock(channels.get(1)); - if (extraUncast.areAllValuesNull()) { + Block outputUncast = page.getBlock(channels.get(1)); + if (outputUncast.areAllValuesNull()) { return; } - IntBlock extra = (IntBlock) extraUncast; - assert top.getPositionCount() == extra.getPositionCount(); + IntBlock output = (IntBlock) outputUncast; + assert top.getPositionCount() == output.getPositionCount(); for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { int groupId = groups.getInt(groupPosition); int valuesPosition = groupPosition + positionOffset; - TopLongIntAggregator.combineIntermediate(state, groupId, top, extra, valuesPosition); + TopLongIntAggregator.combineIntermediate(state, groupId, top, output, valuesPosition); } } private void maybeEnableGroupIdTracking(SeenGroupIds seenGroupIds, LongBlock vBlock, - IntBlock extraBlock) { + IntBlock outputValueBlock) { if (vBlock.mayHaveNulls()) { state.enableGroupIdTracking(seenGroupIds); } - if (extraBlock.mayHaveNulls()) { + if (outputValueBlock.mayHaveNulls()) { state.enableGroupIdTracking(seenGroupIds); } } diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongLongAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongLongAggregatorFunction.java index fe8cc4c940c24..bd64887b12f67 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongLongAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongLongAggregatorFunction.java @@ -24,7 +24,7 @@ public final class TopLongLongAggregatorFunction implements AggregatorFunction { private static final List INTERMEDIATE_STATE_DESC = List.of( new IntermediateStateDesc("top", ElementType.LONG), - new IntermediateStateDesc("extra", ElementType.LONG) ); + new IntermediateStateDesc("output", ElementType.LONG) ); private final DriverContext driverContext; @@ -72,78 +72,78 @@ public void addRawInput(Page page, BooleanVector mask) { private void addRawInputMasked(Page page, BooleanVector mask) { LongBlock vBlock = page.getBlock(channels.get(0)); - LongBlock extraBlock = page.getBlock(channels.get(1)); + LongBlock outputValueBlock = page.getBlock(channels.get(1)); LongVector vVector = vBlock.asVector(); if (vVector == null) { - addRawBlock(vBlock, extraBlock, mask); + addRawBlock(vBlock, outputValueBlock, mask); return; } - LongVector extraVector = extraBlock.asVector(); - if (extraVector == null) { - addRawBlock(vBlock, extraBlock, mask); + LongVector outputValueVector = outputValueBlock.asVector(); + if (outputValueVector == null) { + addRawBlock(vBlock, outputValueBlock, mask); return; } - addRawVector(vVector, extraVector, mask); + addRawVector(vVector, outputValueVector, mask); } private void addRawInputNotMasked(Page page) { LongBlock vBlock = page.getBlock(channels.get(0)); - LongBlock extraBlock = page.getBlock(channels.get(1)); + LongBlock outputValueBlock = page.getBlock(channels.get(1)); LongVector vVector = vBlock.asVector(); if (vVector == null) { - addRawBlock(vBlock, extraBlock); + addRawBlock(vBlock, outputValueBlock); return; } - LongVector extraVector = extraBlock.asVector(); - if (extraVector == null) { - addRawBlock(vBlock, extraBlock); + LongVector outputValueVector = outputValueBlock.asVector(); + if (outputValueVector == null) { + addRawBlock(vBlock, outputValueBlock); return; } - addRawVector(vVector, extraVector); + addRawVector(vVector, outputValueVector); } - private void addRawVector(LongVector vVector, LongVector extraVector) { + private void addRawVector(LongVector vVector, LongVector outputValueVector) { for (int valuesPosition = 0; valuesPosition < vVector.getPositionCount(); valuesPosition++) { long vValue = vVector.getLong(valuesPosition); - long extraValue = extraVector.getLong(valuesPosition); - TopLongLongAggregator.combine(state, vValue, extraValue); + long outputValueValue = outputValueVector.getLong(valuesPosition); + TopLongLongAggregator.combine(state, vValue, outputValueValue); } } - private void addRawVector(LongVector vVector, LongVector extraVector, BooleanVector mask) { + private void addRawVector(LongVector vVector, LongVector outputValueVector, BooleanVector mask) { for (int valuesPosition = 0; valuesPosition < vVector.getPositionCount(); valuesPosition++) { if (mask.getBoolean(valuesPosition) == false) { continue; } long vValue = vVector.getLong(valuesPosition); - long extraValue = extraVector.getLong(valuesPosition); - TopLongLongAggregator.combine(state, vValue, extraValue); + long outputValueValue = outputValueVector.getLong(valuesPosition); + TopLongLongAggregator.combine(state, vValue, outputValueValue); } } - private void addRawBlock(LongBlock vBlock, LongBlock extraBlock) { + private void addRawBlock(LongBlock vBlock, LongBlock outputValueBlock) { for (int p = 0; p < vBlock.getPositionCount(); p++) { if (vBlock.isNull(p)) { continue; } - if (extraBlock.isNull(p)) { + if (outputValueBlock.isNull(p)) { continue; } int vStart = vBlock.getFirstValueIndex(p); int vEnd = vStart + vBlock.getValueCount(p); for (int vOffset = vStart; vOffset < vEnd; vOffset++) { long vValue = vBlock.getLong(vOffset); - int extraStart = extraBlock.getFirstValueIndex(p); - int extraEnd = extraStart + extraBlock.getValueCount(p); - for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { - long extraValue = extraBlock.getLong(extraOffset); - TopLongLongAggregator.combine(state, vValue, extraValue); + int outputValueStart = outputValueBlock.getFirstValueIndex(p); + int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(p); + for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { + long outputValueValue = outputValueBlock.getLong(outputValueOffset); + TopLongLongAggregator.combine(state, vValue, outputValueValue); } } } } - private void addRawBlock(LongBlock vBlock, LongBlock extraBlock, BooleanVector mask) { + private void addRawBlock(LongBlock vBlock, LongBlock outputValueBlock, BooleanVector mask) { for (int p = 0; p < vBlock.getPositionCount(); p++) { if (mask.getBoolean(p) == false) { continue; @@ -151,18 +151,18 @@ private void addRawBlock(LongBlock vBlock, LongBlock extraBlock, BooleanVector m if (vBlock.isNull(p)) { continue; } - if (extraBlock.isNull(p)) { + if (outputValueBlock.isNull(p)) { continue; } int vStart = vBlock.getFirstValueIndex(p); int vEnd = vStart + vBlock.getValueCount(p); for (int vOffset = vStart; vOffset < vEnd; vOffset++) { long vValue = vBlock.getLong(vOffset); - int extraStart = extraBlock.getFirstValueIndex(p); - int extraEnd = extraStart + extraBlock.getValueCount(p); - for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { - long extraValue = extraBlock.getLong(extraOffset); - TopLongLongAggregator.combine(state, vValue, extraValue); + int outputValueStart = outputValueBlock.getFirstValueIndex(p); + int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(p); + for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { + long outputValueValue = outputValueBlock.getLong(outputValueOffset); + TopLongLongAggregator.combine(state, vValue, outputValueValue); } } } @@ -178,13 +178,13 @@ public void addIntermediateInput(Page page) { } LongBlock top = (LongBlock) topUncast; assert top.getPositionCount() == 1; - Block extraUncast = page.getBlock(channels.get(1)); - if (extraUncast.areAllValuesNull()) { + Block outputUncast = page.getBlock(channels.get(1)); + if (outputUncast.areAllValuesNull()) { return; } - LongBlock extra = (LongBlock) extraUncast; - assert extra.getPositionCount() == 1; - TopLongLongAggregator.combineIntermediate(state, top, extra); + LongBlock output = (LongBlock) outputUncast; + assert output.getPositionCount() == 1; + TopLongLongAggregator.combineIntermediate(state, top, output); } @Override diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongLongGroupingAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongLongGroupingAggregatorFunction.java index aaf8496e61d5d..4d8f016593497 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongLongGroupingAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongLongGroupingAggregatorFunction.java @@ -26,7 +26,7 @@ public final class TopLongLongGroupingAggregatorFunction implements GroupingAggregatorFunction { private static final List INTERMEDIATE_STATE_DESC = List.of( new IntermediateStateDesc("top", ElementType.LONG), - new IntermediateStateDesc("extra", ElementType.LONG) ); + new IntermediateStateDesc("output", ElementType.LONG) ); private final TopLongLongAggregator.GroupingState state; @@ -66,24 +66,24 @@ public int intermediateBlockCount() { public GroupingAggregatorFunction.AddInput prepareProcessRawInputPage(SeenGroupIds seenGroupIds, Page page) { LongBlock vBlock = page.getBlock(channels.get(0)); - LongBlock extraBlock = page.getBlock(channels.get(1)); + LongBlock outputValueBlock = page.getBlock(channels.get(1)); LongVector vVector = vBlock.asVector(); if (vVector == null) { - maybeEnableGroupIdTracking(seenGroupIds, vBlock, extraBlock); + maybeEnableGroupIdTracking(seenGroupIds, vBlock, outputValueBlock); return new GroupingAggregatorFunction.AddInput() { @Override public void add(int positionOffset, IntArrayBlock groupIds) { - addRawInput(positionOffset, groupIds, vBlock, extraBlock); + addRawInput(positionOffset, groupIds, vBlock, outputValueBlock); } @Override public void add(int positionOffset, IntBigArrayBlock groupIds) { - addRawInput(positionOffset, groupIds, vBlock, extraBlock); + addRawInput(positionOffset, groupIds, vBlock, outputValueBlock); } @Override public void add(int positionOffset, IntVector groupIds) { - addRawInput(positionOffset, groupIds, vBlock, extraBlock); + addRawInput(positionOffset, groupIds, vBlock, outputValueBlock); } @Override @@ -91,23 +91,23 @@ public void close() { } }; } - LongVector extraVector = extraBlock.asVector(); - if (extraVector == null) { - maybeEnableGroupIdTracking(seenGroupIds, vBlock, extraBlock); + LongVector outputValueVector = outputValueBlock.asVector(); + if (outputValueVector == null) { + maybeEnableGroupIdTracking(seenGroupIds, vBlock, outputValueBlock); return new GroupingAggregatorFunction.AddInput() { @Override public void add(int positionOffset, IntArrayBlock groupIds) { - addRawInput(positionOffset, groupIds, vBlock, extraBlock); + addRawInput(positionOffset, groupIds, vBlock, outputValueBlock); } @Override public void add(int positionOffset, IntBigArrayBlock groupIds) { - addRawInput(positionOffset, groupIds, vBlock, extraBlock); + addRawInput(positionOffset, groupIds, vBlock, outputValueBlock); } @Override public void add(int positionOffset, IntVector groupIds) { - addRawInput(positionOffset, groupIds, vBlock, extraBlock); + addRawInput(positionOffset, groupIds, vBlock, outputValueBlock); } @Override @@ -118,17 +118,17 @@ public void close() { return new GroupingAggregatorFunction.AddInput() { @Override public void add(int positionOffset, IntArrayBlock groupIds) { - addRawInput(positionOffset, groupIds, vVector, extraVector); + addRawInput(positionOffset, groupIds, vVector, outputValueVector); } @Override public void add(int positionOffset, IntBigArrayBlock groupIds) { - addRawInput(positionOffset, groupIds, vVector, extraVector); + addRawInput(positionOffset, groupIds, vVector, outputValueVector); } @Override public void add(int positionOffset, IntVector groupIds) { - addRawInput(positionOffset, groupIds, vVector, extraVector); + addRawInput(positionOffset, groupIds, vVector, outputValueVector); } @Override @@ -138,7 +138,7 @@ public void close() { } private void addRawInput(int positionOffset, IntArrayBlock groups, LongBlock vBlock, - LongBlock extraBlock) { + LongBlock outputValueBlock) { for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { if (groups.isNull(groupPosition)) { continue; @@ -147,7 +147,7 @@ private void addRawInput(int positionOffset, IntArrayBlock groups, LongBlock vBl if (vBlock.isNull(valuesPosition)) { continue; } - if (extraBlock.isNull(valuesPosition)) { + if (outputValueBlock.isNull(valuesPosition)) { continue; } int groupStart = groups.getFirstValueIndex(groupPosition); @@ -158,11 +158,11 @@ private void addRawInput(int positionOffset, IntArrayBlock groups, LongBlock vBl int vEnd = vStart + vBlock.getValueCount(valuesPosition); for (int vOffset = vStart; vOffset < vEnd; vOffset++) { long vValue = vBlock.getLong(vOffset); - int extraStart = extraBlock.getFirstValueIndex(valuesPosition); - int extraEnd = extraStart + extraBlock.getValueCount(valuesPosition); - for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { - long extraValue = extraBlock.getLong(extraOffset); - TopLongLongAggregator.combine(state, groupId, vValue, extraValue); + int outputValueStart = outputValueBlock.getFirstValueIndex(valuesPosition); + int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(valuesPosition); + for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { + long outputValueValue = outputValueBlock.getLong(outputValueOffset); + TopLongLongAggregator.combine(state, groupId, vValue, outputValueValue); } } } @@ -170,7 +170,7 @@ private void addRawInput(int positionOffset, IntArrayBlock groups, LongBlock vBl } private void addRawInput(int positionOffset, IntArrayBlock groups, LongVector vVector, - LongVector extraVector) { + LongVector outputValueVector) { for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { if (groups.isNull(groupPosition)) { continue; @@ -181,8 +181,8 @@ private void addRawInput(int positionOffset, IntArrayBlock groups, LongVector vV for (int g = groupStart; g < groupEnd; g++) { int groupId = groups.getInt(g); long vValue = vVector.getLong(valuesPosition); - long extraValue = extraVector.getLong(valuesPosition); - TopLongLongAggregator.combine(state, groupId, vValue, extraValue); + long outputValueValue = outputValueVector.getLong(valuesPosition); + TopLongLongAggregator.combine(state, groupId, vValue, outputValueValue); } } } @@ -196,12 +196,12 @@ public void addIntermediateInput(int positionOffset, IntArrayBlock groups, Page return; } LongBlock top = (LongBlock) topUncast; - Block extraUncast = page.getBlock(channels.get(1)); - if (extraUncast.areAllValuesNull()) { + Block outputUncast = page.getBlock(channels.get(1)); + if (outputUncast.areAllValuesNull()) { return; } - LongBlock extra = (LongBlock) extraUncast; - assert top.getPositionCount() == extra.getPositionCount(); + LongBlock output = (LongBlock) outputUncast; + assert top.getPositionCount() == output.getPositionCount(); for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { if (groups.isNull(groupPosition)) { continue; @@ -211,13 +211,13 @@ public void addIntermediateInput(int positionOffset, IntArrayBlock groups, Page for (int g = groupStart; g < groupEnd; g++) { int groupId = groups.getInt(g); int valuesPosition = groupPosition + positionOffset; - TopLongLongAggregator.combineIntermediate(state, groupId, top, extra, valuesPosition); + TopLongLongAggregator.combineIntermediate(state, groupId, top, output, valuesPosition); } } } private void addRawInput(int positionOffset, IntBigArrayBlock groups, LongBlock vBlock, - LongBlock extraBlock) { + LongBlock outputValueBlock) { for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { if (groups.isNull(groupPosition)) { continue; @@ -226,7 +226,7 @@ private void addRawInput(int positionOffset, IntBigArrayBlock groups, LongBlock if (vBlock.isNull(valuesPosition)) { continue; } - if (extraBlock.isNull(valuesPosition)) { + if (outputValueBlock.isNull(valuesPosition)) { continue; } int groupStart = groups.getFirstValueIndex(groupPosition); @@ -237,11 +237,11 @@ private void addRawInput(int positionOffset, IntBigArrayBlock groups, LongBlock int vEnd = vStart + vBlock.getValueCount(valuesPosition); for (int vOffset = vStart; vOffset < vEnd; vOffset++) { long vValue = vBlock.getLong(vOffset); - int extraStart = extraBlock.getFirstValueIndex(valuesPosition); - int extraEnd = extraStart + extraBlock.getValueCount(valuesPosition); - for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { - long extraValue = extraBlock.getLong(extraOffset); - TopLongLongAggregator.combine(state, groupId, vValue, extraValue); + int outputValueStart = outputValueBlock.getFirstValueIndex(valuesPosition); + int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(valuesPosition); + for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { + long outputValueValue = outputValueBlock.getLong(outputValueOffset); + TopLongLongAggregator.combine(state, groupId, vValue, outputValueValue); } } } @@ -249,7 +249,7 @@ private void addRawInput(int positionOffset, IntBigArrayBlock groups, LongBlock } private void addRawInput(int positionOffset, IntBigArrayBlock groups, LongVector vVector, - LongVector extraVector) { + LongVector outputValueVector) { for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { if (groups.isNull(groupPosition)) { continue; @@ -260,8 +260,8 @@ private void addRawInput(int positionOffset, IntBigArrayBlock groups, LongVector for (int g = groupStart; g < groupEnd; g++) { int groupId = groups.getInt(g); long vValue = vVector.getLong(valuesPosition); - long extraValue = extraVector.getLong(valuesPosition); - TopLongLongAggregator.combine(state, groupId, vValue, extraValue); + long outputValueValue = outputValueVector.getLong(valuesPosition); + TopLongLongAggregator.combine(state, groupId, vValue, outputValueValue); } } } @@ -275,12 +275,12 @@ public void addIntermediateInput(int positionOffset, IntBigArrayBlock groups, Pa return; } LongBlock top = (LongBlock) topUncast; - Block extraUncast = page.getBlock(channels.get(1)); - if (extraUncast.areAllValuesNull()) { + Block outputUncast = page.getBlock(channels.get(1)); + if (outputUncast.areAllValuesNull()) { return; } - LongBlock extra = (LongBlock) extraUncast; - assert top.getPositionCount() == extra.getPositionCount(); + LongBlock output = (LongBlock) outputUncast; + assert top.getPositionCount() == output.getPositionCount(); for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { if (groups.isNull(groupPosition)) { continue; @@ -290,19 +290,19 @@ public void addIntermediateInput(int positionOffset, IntBigArrayBlock groups, Pa for (int g = groupStart; g < groupEnd; g++) { int groupId = groups.getInt(g); int valuesPosition = groupPosition + positionOffset; - TopLongLongAggregator.combineIntermediate(state, groupId, top, extra, valuesPosition); + TopLongLongAggregator.combineIntermediate(state, groupId, top, output, valuesPosition); } } } private void addRawInput(int positionOffset, IntVector groups, LongBlock vBlock, - LongBlock extraBlock) { + LongBlock outputValueBlock) { for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { int valuesPosition = groupPosition + positionOffset; if (vBlock.isNull(valuesPosition)) { continue; } - if (extraBlock.isNull(valuesPosition)) { + if (outputValueBlock.isNull(valuesPosition)) { continue; } int groupId = groups.getInt(groupPosition); @@ -310,24 +310,24 @@ private void addRawInput(int positionOffset, IntVector groups, LongBlock vBlock, int vEnd = vStart + vBlock.getValueCount(valuesPosition); for (int vOffset = vStart; vOffset < vEnd; vOffset++) { long vValue = vBlock.getLong(vOffset); - int extraStart = extraBlock.getFirstValueIndex(valuesPosition); - int extraEnd = extraStart + extraBlock.getValueCount(valuesPosition); - for (int extraOffset = extraStart; extraOffset < extraEnd; extraOffset++) { - long extraValue = extraBlock.getLong(extraOffset); - TopLongLongAggregator.combine(state, groupId, vValue, extraValue); + int outputValueStart = outputValueBlock.getFirstValueIndex(valuesPosition); + int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(valuesPosition); + for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { + long outputValueValue = outputValueBlock.getLong(outputValueOffset); + TopLongLongAggregator.combine(state, groupId, vValue, outputValueValue); } } } } private void addRawInput(int positionOffset, IntVector groups, LongVector vVector, - LongVector extraVector) { + LongVector outputValueVector) { for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { int valuesPosition = groupPosition + positionOffset; int groupId = groups.getInt(groupPosition); long vValue = vVector.getLong(valuesPosition); - long extraValue = extraVector.getLong(valuesPosition); - TopLongLongAggregator.combine(state, groupId, vValue, extraValue); + long outputValueValue = outputValueVector.getLong(valuesPosition); + TopLongLongAggregator.combine(state, groupId, vValue, outputValueValue); } } @@ -340,25 +340,25 @@ public void addIntermediateInput(int positionOffset, IntVector groups, Page page return; } LongBlock top = (LongBlock) topUncast; - Block extraUncast = page.getBlock(channels.get(1)); - if (extraUncast.areAllValuesNull()) { + Block outputUncast = page.getBlock(channels.get(1)); + if (outputUncast.areAllValuesNull()) { return; } - LongBlock extra = (LongBlock) extraUncast; - assert top.getPositionCount() == extra.getPositionCount(); + LongBlock output = (LongBlock) outputUncast; + assert top.getPositionCount() == output.getPositionCount(); for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) { int groupId = groups.getInt(groupPosition); int valuesPosition = groupPosition + positionOffset; - TopLongLongAggregator.combineIntermediate(state, groupId, top, extra, valuesPosition); + TopLongLongAggregator.combineIntermediate(state, groupId, top, output, valuesPosition); } } private void maybeEnableGroupIdTracking(SeenGroupIds seenGroupIds, LongBlock vBlock, - LongBlock extraBlock) { + LongBlock outputValueBlock) { if (vBlock.mayHaveNulls()) { state.enableGroupIdTracking(seenGroupIds); } - if (extraBlock.mayHaveNulls()) { + if (outputValueBlock.mayHaveNulls()) { state.enableGroupIdTracking(seenGroupIds); } } diff --git a/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/X-TopAggregator.java.st b/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/X-TopAggregator.java.st index 5028564213939..da5499eeed082 100644 --- a/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/X-TopAggregator.java.st +++ b/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/X-TopAggregator.java.st @@ -17,11 +17,11 @@ import org.elasticsearch.compute.ann.IntermediateState; import org.elasticsearch.compute.data.Block; import org.elasticsearch.compute.data.BlockFactory; import org.elasticsearch.compute.data.$Type$Block; -$if(hasExtra)$ -import org.elasticsearch.compute.data.$ExtraType$Block; +$if(hasOutputField)$ +import org.elasticsearch.compute.data.$OutputFieldType$Block; $endif$ import org.elasticsearch.compute.data.IntVector; -import org.elasticsearch.compute.data.sort.$Name$$ExtraName$BucketedSort; +import org.elasticsearch.compute.data.sort.$Name$$OutputFieldName$BucketedSort; import org.elasticsearch.compute.operator.DriverContext; import org.elasticsearch.core.Releasables; import org.elasticsearch.search.sort.SortOrder; @@ -33,32 +33,32 @@ import org.elasticsearch.search.sort.SortOrder; * This class is generated. Edit `X-TopAggregator.java.st` to edit this file. *

*/ -$if(hasExtra)$ -@Aggregator({ @IntermediateState(name = "top", type = "$TYPE$_BLOCK"), @IntermediateState(name = "extra", type = "$ExtraTYPE$_BLOCK") }) +$if(hasOutputField)$ +@Aggregator({ @IntermediateState(name = "top", type = "$TYPE$_BLOCK"), @IntermediateState(name = "output", type = "$OutputFieldTYPE$_BLOCK") }) $else$ @Aggregator({ @IntermediateState(name = "top", type = "$TYPE$_BLOCK") }) $endif$ @GroupingAggregator -class Top$Name$$ExtraName$Aggregator { +class Top$Name$$OutputFieldName$Aggregator { public static SingleState initSingle(BigArrays bigArrays, int limit, boolean ascending) { return new SingleState(bigArrays, limit, ascending); } - public static void combine(SingleState state, $type$ v$if(hasExtra)$, $Extratype$ extra$endif$) { - state.add(v$if(hasExtra)$, extra$endif$); + public static void combine(SingleState state, $type$ v$if(hasOutputField)$, $OutputFieldtype$ outputValue$endif$) { + state.add(v$if(hasOutputField)$, outputValue$endif$); } - public static void combineIntermediate(SingleState state, $Type$Block values$if(hasExtra)$, $ExtraType$Block extras$endif$) { + public static void combineIntermediate(SingleState state, $Type$Block values$if(hasOutputField)$, $OutputFieldType$Block outputValues$endif$) { int start = values.getFirstValueIndex(0); int end = start + values.getValueCount(0); $if(BytesRef || Ip)$ var scratch = new BytesRef(); for (int i = start; i < end; i++) { - combine(state, values.get$Type$(i, scratch)$if(hasExtra)$, extras.get$ExtraType$(i)$endif$); + combine(state, values.get$Type$(i, scratch)$if(hasOutputField)$, outputValues.get$OutputFieldType$(i)$endif$); } $else$ for (int i = start; i < end; i++) { - combine(state, values.get$Type$(i)$if(hasExtra)$, extras.get$ExtraType$(i)$endif$); + combine(state, values.get$Type$(i)$if(hasOutputField)$, outputValues.get$OutputFieldType$(i)$endif$); } $endif$ } @@ -71,21 +71,21 @@ $endif$ return new GroupingState(bigArrays, limit, ascending); } - public static void combine(GroupingState state, int groupId, $type$ v$if(hasExtra)$, $Extratype$ extra$endif$) { - state.add(groupId, v$if(hasExtra)$, extra$endif$); + public static void combine(GroupingState state, int groupId, $type$ v$if(hasOutputField)$, $OutputFieldtype$ outputValue$endif$) { + state.add(groupId, v$if(hasOutputField)$, outputValue$endif$); } - public static void combineIntermediate(GroupingState state, int groupId, $Type$Block values, $if(hasExtra)$$ExtraType$Block extras, $endif$int valuesPosition) { + public static void combineIntermediate(GroupingState state, int groupId, $Type$Block values, $if(hasOutputField)$$OutputFieldType$Block outputValues, $endif$int valuesPosition) { int start = values.getFirstValueIndex(valuesPosition); int end = start + values.getValueCount(valuesPosition); $if(BytesRef || Ip)$ var scratch = new BytesRef(); for (int i = start; i < end; i++) { - combine(state, groupId, values.get$Type$(i, scratch)$if(hasExtra)$, extras.get$ExtraType$(i)$endif$); + combine(state, groupId, values.get$Type$(i, scratch)$if(hasOutputField)$, outputValues.get$OutputFieldType$(i)$endif$); } $else$ for (int i = start; i < end; i++) { - combine(state, groupId, values.get$Type$(i)$if(hasExtra)$, extras.get$ExtraType$(i)$endif$); + combine(state, groupId, values.get$Type$(i)$if(hasOutputField)$, outputValues.get$OutputFieldType$(i)$endif$); } $endif$ } @@ -95,7 +95,7 @@ $endif$ } public static class GroupingState implements GroupingAggregatorState { - private final $Name$$ExtraName$BucketedSort sort; + private final $Name$$OutputFieldName$BucketedSort sort; private GroupingState(BigArrays bigArrays, int limit, boolean ascending) { $if(BytesRef)$ @@ -103,24 +103,24 @@ $if(BytesRef)$ CircuitBreaker breaker = bigArrays.breakerService().getBreaker(CircuitBreaker.REQUEST); this.sort = new BytesRefBucketedSort(breaker, "top", bigArrays, ascending ? SortOrder.ASC : SortOrder.DESC, limit); $else$ - this.sort = new $Name$$ExtraName$BucketedSort(bigArrays, ascending ? SortOrder.ASC : SortOrder.DESC, limit); + this.sort = new $Name$$OutputFieldName$BucketedSort(bigArrays, ascending ? SortOrder.ASC : SortOrder.DESC, limit); $endif$ } - public void add(int groupId, $type$ value$if(hasExtra)$, $Extratype$ extra$endif$) { - sort.collect(value, $if(hasExtra)$extra, $endif$groupId); + public void add(int groupId, $type$ value$if(hasOutputField)$, $OutputFieldtype$ outputValue$endif$) { + sort.collect(value, $if(hasOutputField)$outputValue, $endif$groupId); } @Override public void toIntermediate(Block[] blocks, int offset, IntVector selected, DriverContext driverContext) { -$if(hasExtra)$ +$if(hasOutputField)$ sort.toBlocks(driverContext.blockFactory(), blocks, offset, selected); $else$ blocks[offset] = toBlock(driverContext.blockFactory(), selected); $endif$ } -$if(hasExtra)$ +$if(hasOutputField)$ Block toBlock(BlockFactory blockFactory, IntVector selected) { Block[] blocks = new Block[2]; sort.toBlocks(blockFactory, blocks, 0, selected); @@ -152,8 +152,8 @@ $endif$ this.internalState = new GroupingState(bigArrays, limit, ascending); } - public void add($type$ value$if(hasExtra)$, $Extratype$ extra$endif$) { - internalState.add(0, value$if(hasExtra)$, extra$endif$); + public void add($type$ value$if(hasOutputField)$, $OutputFieldtype$ outputValue$endif$) { + internalState.add(0, value$if(hasOutputField)$, outputValue$endif$); } @Override diff --git a/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/data/sort/X-BucketedSort.java.st b/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/data/sort/X-BucketedSort.java.st index 6efe35406c4b2..d0ff45a3eb76e 100644 --- a/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/data/sort/X-BucketedSort.java.st +++ b/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/data/sort/X-BucketedSort.java.st @@ -104,7 +104,7 @@ $endif$ public void collect($type$ value, $if(hasExtra)$$Extratype$ extraValue, $endif$int bucket) { long rootIndex = (long) bucket * bucketSize; if (inHeapMode(bucket)) { - if (betterThan(value, values.get(rootIndex)$if(hasExtra)$, extraValue, extraValues.get(rootIndex)$endif$)) { + if (betterThan(value, values.get(rootIndex))) { values.set(rootIndex, value); $if(hasExtra)$ extraValues.set(rootIndex, extraValue); @@ -182,8 +182,10 @@ $if(hasExtra)$ public void toBlocks(BlockFactory blockFactory, Block[] blocks, int offset, IntVector selected) { // Check if the selected groups are all empty, to avoid allocating extra memory if (allSelectedGroupsAreEmpty(selected)) { - blocks[offset] = blockFactory.newConstantNullBlock(selected.getPositionCount()); - blocks[offset + 1] = blockFactory.newConstantNullBlock(selected.getPositionCount()); + Block constantNullBlock = blockFactory.newConstantNullBlock(selected.getPositionCount()); + constantNullBlock.incRef(); + blocks[offset] = constantNullBlock; + blocks[offset + 1] = constantNullBlock; return; } @@ -318,15 +320,8 @@ $endif$ * the entry at {@code rhs}. "Better" in this means "lower" for * {@link SortOrder#ASC} and "higher" for {@link SortOrder#DESC}. */ - private boolean betterThan($type$ lhs, $type$ rhs$if(hasExtra)$, $Extratype$ lhsExtra, $Extratype$ rhsExtra$endif$) { - int res = $Wrapper$.compare(lhs, rhs); -$if(hasExtra)$ - if (res != 0) { - return getOrder().reverseMul() * res < 0; - } - res = $ExtraWrapper$.compare(lhsExtra, rhsExtra); -$endif$ - return getOrder().reverseMul() * res < 0; + private boolean betterThan($type$ lhs, $type$ rhs) { + return getOrder().reverseMul() * $Wrapper$.compare(lhs, rhs) < 0; } /** @@ -443,23 +438,13 @@ $endif$ int leftChild = parent * 2 + 1; long leftIndex = rootIndex + leftChild; if (leftChild < heapSize) { - if (betterThan(values.get(worstIndex), values.get(leftIndex)$if(hasExtra)$, extraValues.get(worstIndex), extraValues.get(leftIndex)$endif$)) { + if (betterThan(values.get(worstIndex), values.get(leftIndex))) { worst = leftChild; worstIndex = leftIndex; } int rightChild = leftChild + 1; long rightIndex = rootIndex + rightChild; -$if(hasExtra)$ - if (rightChild < heapSize - && betterThan( - values.get(worstIndex), - values.get(rightIndex), - extraValues.get(worstIndex), - extraValues.get(rightIndex) - )) { -$else$ if (rightChild < heapSize && betterThan(values.get(worstIndex), values.get(rightIndex))) { -$endif$ worst = rightChild; worstIndex = rightIndex; } diff --git a/x-pack/plugin/esql/qa/testFixtures/src/main/resources/stats_top.csv-spec b/x-pack/plugin/esql/qa/testFixtures/src/main/resources/stats_top.csv-spec index 8c6d157790d6f..ad5c2001c5d24 100644 --- a/x-pack/plugin/esql/qa/testFixtures/src/main/resources/stats_top.csv-spec +++ b/x-pack/plugin/esql/qa/testFixtures/src/main/resources/stats_top.csv-spec @@ -312,3 +312,95 @@ top_salaries:integer [25324, 25945, 25976] ; + +youngestEmployees +required_capability: agg_top_with_output_field +FROM employees +| STATS youngest_employees = TOP(birth_date, 3, "desc"), + youngest_employees_salaries = TOP(birth_date, 3, "desc", salary) +; + +youngest_employees:date | youngest_employees_salaries:integer +[1965-01-03T00:00:00.000Z, 1964-10-18T00:00:00.000Z, 1964-06-11T00:00:00.000Z] | [37702, 25976, 45656] +; + +youngestEmployeesByGender +required_capability: agg_top_with_output_field +FROM employees +| STATS youngest_employees = TOP(birth_date, 3, "desc"), + youngest_employees_salaries = TOP(birth_date, 3, "desc", salary) + BY gender +| SORT gender +| KEEP gender, youngest_employees, youngest_employees_salaries +; + +gender:keyword | youngest_employees:datetime | youngest_employees_salaries:integer +F | [1964-10-18T00:00:00.000Z, 1964-06-02T00:00:00.000Z, 1963-03-21T00:00:00.000Z] | [25976, 56371, 43602] +M | [1965-01-03T00:00:00.000Z, 1964-06-11T00:00:00.000Z, 1964-04-18T00:00:00.000Z] | [37702, 45656, 46595] +null | [1963-06-07T00:00:00.000Z, 1963-06-01T00:00:00.000Z, 1961-05-02T00:00:00.000Z] | [48735, 45797, 61358] +; + +oldestEmployees +required_capability: agg_top_with_output_field +FROM employees +| STATS oldest_employees = TOP(birth_date, 3, "asc"), + oldest_employees_salaries = TOP(birth_date, 3, "asc", salary) +; + +oldest_employees:date | oldest_employees_salaries:integer +[1952-02-27T00:00:00.000Z, 1952-04-19T00:00:00.000Z, 1952-05-15T00:00:00.000Z] | [71165, 66174, 54518] +; + +oldestEmployeesByGender +required_capability: agg_top_with_output_field +FROM employees +| STATS oldest_employees = TOP(birth_date, 3, "asc"), + oldest_employees_salaries = TOP(birth_date, 3, "asc", salary) + BY gender +| SORT gender +| KEEP gender, oldest_employees, oldest_employees_salaries +; + +gender:keyword | oldest_employees:datetime | oldest_employees_salaries:integer +F | [1952-04-19T00:00:00.000Z, 1952-05-15T00:00:00.000Z, 1952-06-13T00:00:00.000Z] | [66174, 54518, 62405] +M | [1952-02-27T00:00:00.000Z, 1952-07-08T00:00:00.000Z, 1952-11-13T00:00:00.000Z] | [71165, 48233, 31897] +null | [1953-01-23T00:00:00.000Z, 1953-11-07T00:00:00.000Z, 1954-06-19T00:00:00.000Z] | [73717, 31120, 56760] +; + +oldestEmployeesDuplicated +required_capability: agg_top_with_output_field +FROM employees +| STATS oldest_employees = TOP(birth_date, 3, "asc"), + oldest_employees_dup = TOP(birth_date, 3, "asc", birth_date) +; + +oldest_employees:date | oldest_employees_dup:date +[1952-02-27T00:00:00.000Z, 1952-04-19T00:00:00.000Z, 1952-05-15T00:00:00.000Z] | [1952-02-27T00:00:00.000Z, 1952-04-19T00:00:00.000Z, 1952-05-15T00:00:00.000Z] +; + +empNoByHireDateByBirthYear +required_capability: agg_top_with_output_field + +FROM employees +| EVAL birth_year = DATE_EXTRACT("year", birth_date) +| STATS v = TOP(birth_year, 20, "asc", emp_no) BY birth_year +| KEEP birth_year, v +; + +birth_year:long | v:integer +null | null +1953 | [10001, 10006, 10011, 10019, 10023, 10026, 10035, 10051, 10059, 10067, 10100] +1964 | [10002, 10077, 10092, 10093] +1959 | [10003, 10015, 10031, 10036, 10039, 10064, 10078, 10083, 10087] +1954 | [10004, 10018, 10053, 10057, 10058, 10073, 10088, 10096] +1955 | [10005, 10070, 10074, 10091] +1957 | [10007, 10054, 10080, 10094] +1958 | [10008, 10017, 10024, 10025, 10030, 10050, 10071] +1952 | [10009, 10020, 10022, 10063, 10066, 10072, 10076, 10097] +1963 | [10010, 10013, 10028, 10037, 10065, 10082, 10089] +1960 | [10012, 10021, 10032, 10038, 10069, 10075, 10081, 10084] +1956 | [10014, 10029, 10033, 10055, 10099] +1961 | [10016, 10052, 10056, 10060, 10062, 10079, 10090, 10098] +1962 | [10027, 10034, 10061, 10068, 10085, 10086] +1965 | 10095 +; diff --git a/x-pack/plugin/esql/qa/testFixtures/src/main/resources/stats_top_map.csv-spec b/x-pack/plugin/esql/qa/testFixtures/src/main/resources/stats_top_map.csv-spec deleted file mode 100644 index 9df9f3b66e218..0000000000000 --- a/x-pack/plugin/esql/qa/testFixtures/src/main/resources/stats_top_map.csv-spec +++ /dev/null @@ -1,53 +0,0 @@ -youngestEmployees -required_capability: agg_top_map_support -FROM employees -| STATS youngest_employees = TOP(birth_date, 3, "desc"), - youngest_employees_salaries = TOP(birth_date, 3, "desc", salary) -; - -youngest_employees:date | youngest_employees_salaries:integer -[1965-01-03T00:00:00.000Z, 1964-10-18T00:00:00.000Z, 1964-06-11T00:00:00.000Z] | [37702, 25976, 45656] -; - -youngestEmployeesByGender -required_capability: agg_top_map_support -FROM employees -| STATS youngest_employees = TOP(birth_date, 3, "desc"), - youngest_employees_salaries = TOP(birth_date, 3, "desc", salary) - BY gender -| SORT gender -| KEEP gender, youngest_employees, youngest_employees_salaries -; - -gender:keyword | youngest_employees:datetime | youngest_employees_salaries:integer -F | [1964-10-18T00:00:00.000Z, 1964-06-02T00:00:00.000Z, 1963-03-21T00:00:00.000Z] | [25976, 56371, 43602] -M | [1965-01-03T00:00:00.000Z, 1964-06-11T00:00:00.000Z, 1964-04-18T00:00:00.000Z] | [37702, 45656, 46595] -null | [1963-06-07T00:00:00.000Z, 1963-06-01T00:00:00.000Z, 1961-05-02T00:00:00.000Z] | [48735, 45797, 61358] -; - -oldestEmployees -required_capability: agg_top_map_support -FROM employees -| STATS oldest_employees = TOP(birth_date, 3, "asc"), - oldest_employees_salaries = TOP(birth_date, 3, "asc", salary) -; - -oldest_employees:date | oldest_employees_salaries:integer -[1952-02-27T00:00:00.000Z, 1952-04-19T00:00:00.000Z, 1952-05-15T00:00:00.000Z] | [71165, 66174, 54518] -; - -oldestEmployeesByGender -required_capability: agg_top_map_support -FROM employees -| STATS oldest_employees = TOP(birth_date, 3, "asc"), - oldest_employees_salaries = TOP(birth_date, 3, "asc", salary) - BY gender -| SORT gender -| KEEP gender, oldest_employees, oldest_employees_salaries -; - -gender:keyword | oldest_employees:datetime | oldest_employees_salaries:integer -F | [1952-04-19T00:00:00.000Z, 1952-05-15T00:00:00.000Z, 1952-06-13T00:00:00.000Z] | [66174, 54518, 62405] -M | [1952-02-27T00:00:00.000Z, 1952-07-08T00:00:00.000Z, 1952-11-13T00:00:00.000Z] | [71165, 48233, 31897] -null | [1953-01-23T00:00:00.000Z, 1953-11-07T00:00:00.000Z, 1954-06-19T00:00:00.000Z] | [73717, 31120, 56760] -; diff --git a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/action/EsqlCapabilities.java b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/action/EsqlCapabilities.java index dc61a2cfa595a..89f14c07dcd54 100644 --- a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/action/EsqlCapabilities.java +++ b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/action/EsqlCapabilities.java @@ -315,7 +315,7 @@ public enum Cap { /** * Support for the extra "map" field in {@code TOP} aggregation. */ - AGG_TOP_MAP_SUPPORT, + AGG_TOP_WITH_OUTPUT_FIELD, /** * {@code CASE} properly handling multivalue conditions. diff --git a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/aggregate/Top.java b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/aggregate/Top.java index 3a812bc5a43ac..d9812f9b96b11 100644 --- a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/aggregate/Top.java +++ b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/aggregate/Top.java @@ -103,16 +103,16 @@ public Top( ) Expression order, @Param( optional = true, - name = "mapToField", + name = "outputField", type = { "double", "integer", "long" }, - description = "The extra field that the result of the TOP call is mapped to." - ) Expression mapToField + description = "The extra field that, if present, will be the output of the TOP call instead of `field`." + ) Expression outputField ) { - this(source, field, Literal.TRUE, limit, order == null ? Literal.keyword(source, ORDER_ASC) : order, mapToField); + this(source, field, Literal.TRUE, limit, order == null ? Literal.keyword(source, ORDER_ASC) : order, outputField); } - public Top(Source source, Expression field, Expression filter, Expression limit, Expression order, @Nullable Expression mapToField) { - super(source, field, filter, mapToField != null ? asList(limit, order, mapToField) : asList(limit, order)); + public Top(Source source, Expression field, Expression filter, Expression limit, Expression order, @Nullable Expression outputField) { + super(source, field, filter, outputField != null ? asList(limit, order, outputField) : asList(limit, order)); } private Top(StreamInput in) throws IOException { @@ -121,7 +121,7 @@ private Top(StreamInput in) throws IOException { @Override public Top withFilter(Expression filter) { - return new Top(source(), field(), filter, limitField(), orderField(), mapToField()); + return new Top(source(), field(), filter, limitField(), orderField(), outputField()); } @Override @@ -138,7 +138,7 @@ Expression orderField() { } @Nullable - Expression mapToField() { + Expression outputField() { return parameters().size() > 2 ? parameters().get(2) : null; } @@ -180,10 +180,10 @@ protected TypeResolution resolveType() { .and(isType(limitField(), dt -> dt == DataType.INTEGER, sourceText(), SECOND, "integer")) .and(isNotNull(orderField(), sourceText(), THIRD)) .and(isString(orderField(), sourceText(), THIRD)); - if (mapToField() != null) { + if (outputField() != null) { typeResolution.and( isType( - mapToField(), + outputField(), dt -> dt == DataType.DATETIME || (dt.isNumeric() && dt != DataType.UNSIGNED_LONG), sourceText(), FIRST, @@ -279,12 +279,12 @@ private void postOptimizationVerificationOrder(Failures failures) { @Override public DataType dataType() { - return mapToField() == null ? field().dataType().noText() : mapToField().dataType().noText(); + return outputField() == null ? field().dataType().noText() : outputField().dataType().noText(); } @Override protected NodeInfo info() { - return NodeInfo.create(this, Top::new, field(), filter(), limitField(), orderField(), mapToField()); + return NodeInfo.create(this, Top::new, field(), filter(), limitField(), orderField(), outputField()); } @Override @@ -312,22 +312,27 @@ public Top replaceChildren(List newChildren) { private static final Map, BiFunction> SUPPLIERS_WITH_EXTRA = Map .ofEntries( + Map.entry(Tuple.tuple(DataType.LONG, DataType.DATETIME), TopLongLongAggregatorFunctionSupplier::new), Map.entry(Tuple.tuple(DataType.LONG, DataType.INTEGER), TopLongIntAggregatorFunctionSupplier::new), Map.entry(Tuple.tuple(DataType.LONG, DataType.LONG), TopLongLongAggregatorFunctionSupplier::new), Map.entry(Tuple.tuple(DataType.LONG, DataType.FLOAT), TopLongFloatAggregatorFunctionSupplier::new), Map.entry(Tuple.tuple(DataType.LONG, DataType.DOUBLE), TopLongDoubleAggregatorFunctionSupplier::new), + Map.entry(Tuple.tuple(DataType.DATETIME, DataType.DATETIME), TopLongLongAggregatorFunctionSupplier::new), Map.entry(Tuple.tuple(DataType.DATETIME, DataType.INTEGER), TopLongIntAggregatorFunctionSupplier::new), Map.entry(Tuple.tuple(DataType.DATETIME, DataType.LONG), TopLongLongAggregatorFunctionSupplier::new), Map.entry(Tuple.tuple(DataType.DATETIME, DataType.FLOAT), TopLongFloatAggregatorFunctionSupplier::new), Map.entry(Tuple.tuple(DataType.DATETIME, DataType.DOUBLE), TopLongDoubleAggregatorFunctionSupplier::new), + Map.entry(Tuple.tuple(DataType.INTEGER, DataType.DATETIME), TopIntLongAggregatorFunctionSupplier::new), Map.entry(Tuple.tuple(DataType.INTEGER, DataType.INTEGER), TopIntIntAggregatorFunctionSupplier::new), Map.entry(Tuple.tuple(DataType.INTEGER, DataType.LONG), TopIntLongAggregatorFunctionSupplier::new), Map.entry(Tuple.tuple(DataType.INTEGER, DataType.FLOAT), TopIntFloatAggregatorFunctionSupplier::new), Map.entry(Tuple.tuple(DataType.INTEGER, DataType.DOUBLE), TopIntDoubleAggregatorFunctionSupplier::new), + Map.entry(Tuple.tuple(DataType.FLOAT, DataType.DATETIME), TopFloatLongAggregatorFunctionSupplier::new), Map.entry(Tuple.tuple(DataType.FLOAT, DataType.INTEGER), TopFloatIntAggregatorFunctionSupplier::new), Map.entry(Tuple.tuple(DataType.FLOAT, DataType.LONG), TopFloatLongAggregatorFunctionSupplier::new), Map.entry(Tuple.tuple(DataType.FLOAT, DataType.FLOAT), TopFloatFloatAggregatorFunctionSupplier::new), Map.entry(Tuple.tuple(DataType.FLOAT, DataType.DOUBLE), TopFloatDoubleAggregatorFunctionSupplier::new), + Map.entry(Tuple.tuple(DataType.DOUBLE, DataType.DATETIME), TopDoubleLongAggregatorFunctionSupplier::new), Map.entry(Tuple.tuple(DataType.DOUBLE, DataType.INTEGER), TopDoubleIntAggregatorFunctionSupplier::new), Map.entry(Tuple.tuple(DataType.DOUBLE, DataType.LONG), TopDoubleLongAggregatorFunctionSupplier::new), Map.entry(Tuple.tuple(DataType.DOUBLE, DataType.FLOAT), TopDoubleFloatAggregatorFunctionSupplier::new), @@ -336,18 +341,18 @@ public Top replaceChildren(List newChildren) { @Override public AggregatorFunctionSupplier supplier() { - DataType type = field().dataType(); + DataType fieldType = field().dataType(); BiFunction supplierCtor; - if (mapToField() == null) { - supplierCtor = SUPPLIERS.get(type); + if (outputField() == null) { + supplierCtor = SUPPLIERS.get(fieldType); if (supplierCtor == null) { - throw EsqlIllegalArgumentException.illegalDataType(type); + throw EsqlIllegalArgumentException.illegalDataType(fieldType); } } else { - DataType mapToFieldType = mapToField().dataType(); - supplierCtor = SUPPLIERS_WITH_EXTRA.get(Tuple.tuple(type, mapToFieldType)); + DataType outputFieldType = outputField().dataType(); + supplierCtor = SUPPLIERS_WITH_EXTRA.get(Tuple.tuple(fieldType, outputFieldType)); if (supplierCtor == null) { - throw EsqlIllegalArgumentException.illegalDataTypeCombination(type, mapToFieldType); + throw EsqlIllegalArgumentException.illegalDataTypeCombination(fieldType, outputFieldType); } } return supplierCtor.apply(limitValue(), orderValue()); diff --git a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/TopSerializationTests.java b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/TopSerializationTests.java index 6c681e2b81fae..c9badc3d86993 100644 --- a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/TopSerializationTests.java +++ b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/TopSerializationTests.java @@ -20,8 +20,8 @@ protected Top createTestInstance() { Expression field = randomChild(); Expression limit = randomChild(); Expression order = randomChild(); - Expression mapToField = randomChild(); - return new Top(source, field, limit, order, mapToField); + Expression outputField = randomBoolean() ? null : randomChild(); + return new Top(source, field, limit, order, outputField); } @Override @@ -30,13 +30,13 @@ protected Top mutateInstance(Top instance) throws IOException { Expression field = instance.field(); Expression limit = instance.limitField(); Expression order = instance.orderField(); - Expression mapToField = instance.mapToField(); + Expression outputField = instance.outputField(); switch (between(0, 3)) { case 0 -> field = randomValueOtherThan(field, AbstractExpressionSerializationTests::randomChild); case 1 -> limit = randomValueOtherThan(limit, AbstractExpressionSerializationTests::randomChild); case 2 -> order = randomValueOtherThan(order, AbstractExpressionSerializationTests::randomChild); - case 3 -> mapToField = randomValueOtherThan(mapToField, AbstractExpressionSerializationTests::randomChild); + case 3 -> outputField = randomValueOtherThan(outputField, () -> randomBoolean() ? null : randomChild()); } - return new Top(source, field, limit, order, mapToField); + return new Top(source, field, limit, order, outputField); } } diff --git a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/plan/logical/AggregateSerializationTests.java b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/plan/logical/AggregateSerializationTests.java index 80ed49da8a8f6..c7404360c2017 100644 --- a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/plan/logical/AggregateSerializationTests.java +++ b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/plan/logical/AggregateSerializationTests.java @@ -39,7 +39,7 @@ public static List randomAggregates() { int size = between(1, 5); List result = new ArrayList<>(size); for (int i = 0; i < size; i++) { - Expression agg = switch (between(0, 6)) { + Expression agg = switch (between(0, 5)) { case 0 -> new Max(randomSource(), FieldAttributeTests.createFieldAttribute(1, true)); case 1 -> new Min(randomSource(), FieldAttributeTests.createFieldAttribute(1, true)); case 2 -> new Count(randomSource(), FieldAttributeTests.createFieldAttribute(1, true)); @@ -48,17 +48,10 @@ public static List randomAggregates() { FieldAttributeTests.createFieldAttribute(1, true), new Literal(randomSource(), between(1, 5), DataType.INTEGER), Literal.keyword(randomSource(), randomFrom("ASC", "DESC")), - null + randomBoolean() ? null : FieldAttributeTests.createFieldAttribute(1, true) ); - case 4 -> new Top( - randomSource(), - FieldAttributeTests.createFieldAttribute(1, true), - new Literal(randomSource(), between(1, 5), DataType.INTEGER), - Literal.keyword(randomSource(), randomFrom("ASC", "DESC")), - FieldAttributeTests.createFieldAttribute(1, true) - ); - case 5 -> new Values(randomSource(), FieldAttributeTests.createFieldAttribute(1, true)); - case 6 -> new Sum(randomSource(), FieldAttributeTests.createFieldAttribute(1, true)); + case 4 -> new Values(randomSource(), FieldAttributeTests.createFieldAttribute(1, true)); + case 5 -> new Sum(randomSource(), FieldAttributeTests.createFieldAttribute(1, true)); default -> throw new IllegalArgumentException(); }; result.add(new Alias(randomSource(), randomAlphaOfLength(5), agg)); From 42791c7868a43cd831f8fd30235c1e28f2008b6b Mon Sep 17 00:00:00 2001 From: Przemyslaw Witek Date: Wed, 15 Oct 2025 12:38:41 +0200 Subject: [PATCH 05/16] Simplify TOP(f, limit, order, f) to TOP(f, limit, order, null) --- .../xpack/esql/expression/function/aggregate/Top.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/aggregate/Top.java b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/aggregate/Top.java index d9812f9b96b11..1f6a785ac6a9f 100644 --- a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/aggregate/Top.java +++ b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/aggregate/Top.java @@ -361,6 +361,10 @@ public AggregatorFunctionSupplier supplier() { @Override public Expression surrogate() { var s = source(); + // If the `outputField` is specified but its value is the same as `field` then we do not need to handle `outputField` separately. + if (outputField() != null && field().semanticEquals(outputField())) { + return new Top(s, field(), limitField(), orderField(), null); + } if (orderField() instanceof Literal && limitField() instanceof Literal && limitValue() == 1) { if (orderValue()) { return new Min(s, field(), filter()); From fb61869afc318fc9a2e32d66d15728b22d1fc621 Mon Sep 17 00:00:00 2001 From: Przemyslaw Witek Date: Mon, 20 Oct 2025 14:31:55 +0200 Subject: [PATCH 06/16] - Add enhanced TOP tests to TopTests.java - Fix grow() method in X-BucketedSort - Add `date` type to supported types of `outputField` --- .../_snippets/functions/parameters/top.md | 2 +- .../esql/_snippets/functions/types/top.md | 16 + .../esql/kibana/definition/functions/top.json | 480 ++++++++++++++++++ .../compute/data/sort/DoubleBucketedSort.java | 3 +- .../data/sort/DoubleDoubleBucketedSort.java | 25 +- .../data/sort/DoubleFloatBucketedSort.java | 25 +- .../data/sort/DoubleIntBucketedSort.java | 25 +- .../data/sort/DoubleLongBucketedSort.java | 25 +- .../compute/data/sort/FloatBucketedSort.java | 3 +- .../data/sort/FloatDoubleBucketedSort.java | 25 +- .../data/sort/FloatFloatBucketedSort.java | 25 +- .../data/sort/FloatIntBucketedSort.java | 25 +- .../data/sort/FloatLongBucketedSort.java | 25 +- .../compute/data/sort/IntBucketedSort.java | 3 +- .../data/sort/IntDoubleBucketedSort.java | 25 +- .../data/sort/IntFloatBucketedSort.java | 25 +- .../compute/data/sort/IntIntBucketedSort.java | 25 +- .../data/sort/IntLongBucketedSort.java | 25 +- .../compute/data/sort/LongBucketedSort.java | 3 +- .../data/sort/LongDoubleBucketedSort.java | 25 +- .../data/sort/LongFloatBucketedSort.java | 25 +- .../data/sort/LongIntBucketedSort.java | 25 +- .../data/sort/LongLongBucketedSort.java | 25 +- .../compute/data/sort/X-BucketedSort.java.st | 29 +- .../expression/function/aggregate/Top.java | 2 +- .../function/aggregate/TopTests.java | 114 ++++- 26 files changed, 893 insertions(+), 162 deletions(-) diff --git a/docs/reference/query-languages/esql/_snippets/functions/parameters/top.md b/docs/reference/query-languages/esql/_snippets/functions/parameters/top.md index 6419af82362c1..c56bf558809d1 100644 --- a/docs/reference/query-languages/esql/_snippets/functions/parameters/top.md +++ b/docs/reference/query-languages/esql/_snippets/functions/parameters/top.md @@ -12,5 +12,5 @@ : The order to calculate the top values. Either `asc` or `desc`, and defaults to `asc` if omitted. `outputField` -: The extra field that, if present, will be the output of the TOP call instead of `field`. +: The extra field that, if present, will be the output of the TOP call instead of `field`. diff --git a/docs/reference/query-languages/esql/_snippets/functions/types/top.md b/docs/reference/query-languages/esql/_snippets/functions/types/top.md index 4f197b7e70874..063fb157980d0 100644 --- a/docs/reference/query-languages/esql/_snippets/functions/types/top.md +++ b/docs/reference/query-languages/esql/_snippets/functions/types/top.md @@ -6,16 +6,32 @@ | --- | --- | --- | --- | --- | | boolean | integer | keyword | | boolean | | boolean | integer | | | boolean | +| date | integer | keyword | date | date | +| date | integer | keyword | double | double | +| date | integer | keyword | integer | integer | +| date | integer | keyword | long | long | | date | integer | keyword | | date | | date | integer | | | date | +| double | integer | keyword | date | date | +| double | integer | keyword | double | double | +| double | integer | keyword | integer | integer | +| double | integer | keyword | long | long | | double | integer | keyword | | double | | double | integer | | | double | +| integer | integer | keyword | date | date | +| integer | integer | keyword | double | double | +| integer | integer | keyword | integer | integer | +| integer | integer | keyword | long | long | | integer | integer | keyword | | integer | | integer | integer | | | integer | | ip | integer | keyword | | ip | | ip | integer | | | ip | | keyword | integer | keyword | | keyword | | keyword | integer | | | keyword | +| long | integer | keyword | date | date | +| long | integer | keyword | double | double | +| long | integer | keyword | integer | integer | +| long | integer | keyword | long | long | | long | integer | keyword | | long | | long | integer | | | long | | text | integer | keyword | | keyword | diff --git a/docs/reference/query-languages/esql/kibana/definition/functions/top.json b/docs/reference/query-languages/esql/kibana/definition/functions/top.json index 8cef8d534764e..6308eed3bff61 100644 --- a/docs/reference/query-languages/esql/kibana/definition/functions/top.json +++ b/docs/reference/query-languages/esql/kibana/definition/functions/top.json @@ -88,6 +88,126 @@ "variadic" : false, "returnType" : "date" }, + { + "params" : [ + { + "name" : "field", + "type" : "date", + "optional" : false, + "description" : "The field to collect the top values for." + }, + { + "name" : "limit", + "type" : "integer", + "optional" : false, + "description" : "The maximum number of values to collect." + }, + { + "name" : "order", + "type" : "keyword", + "optional" : true, + "description" : "The order to calculate the top values. Either `asc` or `desc`, and defaults to `asc` if omitted." + }, + { + "name" : "outputField", + "type" : "date", + "optional" : true, + "description" : "The extra field that, if present, will be the output of the TOP call instead of `field`." + } + ], + "variadic" : false, + "returnType" : "date" + }, + { + "params" : [ + { + "name" : "field", + "type" : "date", + "optional" : false, + "description" : "The field to collect the top values for." + }, + { + "name" : "limit", + "type" : "integer", + "optional" : false, + "description" : "The maximum number of values to collect." + }, + { + "name" : "order", + "type" : "keyword", + "optional" : true, + "description" : "The order to calculate the top values. Either `asc` or `desc`, and defaults to `asc` if omitted." + }, + { + "name" : "outputField", + "type" : "double", + "optional" : true, + "description" : "The extra field that, if present, will be the output of the TOP call instead of `field`." + } + ], + "variadic" : false, + "returnType" : "double" + }, + { + "params" : [ + { + "name" : "field", + "type" : "date", + "optional" : false, + "description" : "The field to collect the top values for." + }, + { + "name" : "limit", + "type" : "integer", + "optional" : false, + "description" : "The maximum number of values to collect." + }, + { + "name" : "order", + "type" : "keyword", + "optional" : true, + "description" : "The order to calculate the top values. Either `asc` or `desc`, and defaults to `asc` if omitted." + }, + { + "name" : "outputField", + "type" : "integer", + "optional" : true, + "description" : "The extra field that, if present, will be the output of the TOP call instead of `field`." + } + ], + "variadic" : false, + "returnType" : "integer" + }, + { + "params" : [ + { + "name" : "field", + "type" : "date", + "optional" : false, + "description" : "The field to collect the top values for." + }, + { + "name" : "limit", + "type" : "integer", + "optional" : false, + "description" : "The maximum number of values to collect." + }, + { + "name" : "order", + "type" : "keyword", + "optional" : true, + "description" : "The order to calculate the top values. Either `asc` or `desc`, and defaults to `asc` if omitted." + }, + { + "name" : "outputField", + "type" : "long", + "optional" : true, + "description" : "The extra field that, if present, will be the output of the TOP call instead of `field`." + } + ], + "variadic" : false, + "returnType" : "long" + }, { "params" : [ { @@ -130,6 +250,126 @@ "variadic" : false, "returnType" : "double" }, + { + "params" : [ + { + "name" : "field", + "type" : "double", + "optional" : false, + "description" : "The field to collect the top values for." + }, + { + "name" : "limit", + "type" : "integer", + "optional" : false, + "description" : "The maximum number of values to collect." + }, + { + "name" : "order", + "type" : "keyword", + "optional" : true, + "description" : "The order to calculate the top values. Either `asc` or `desc`, and defaults to `asc` if omitted." + }, + { + "name" : "outputField", + "type" : "date", + "optional" : true, + "description" : "The extra field that, if present, will be the output of the TOP call instead of `field`." + } + ], + "variadic" : false, + "returnType" : "date" + }, + { + "params" : [ + { + "name" : "field", + "type" : "double", + "optional" : false, + "description" : "The field to collect the top values for." + }, + { + "name" : "limit", + "type" : "integer", + "optional" : false, + "description" : "The maximum number of values to collect." + }, + { + "name" : "order", + "type" : "keyword", + "optional" : true, + "description" : "The order to calculate the top values. Either `asc` or `desc`, and defaults to `asc` if omitted." + }, + { + "name" : "outputField", + "type" : "double", + "optional" : true, + "description" : "The extra field that, if present, will be the output of the TOP call instead of `field`." + } + ], + "variadic" : false, + "returnType" : "double" + }, + { + "params" : [ + { + "name" : "field", + "type" : "double", + "optional" : false, + "description" : "The field to collect the top values for." + }, + { + "name" : "limit", + "type" : "integer", + "optional" : false, + "description" : "The maximum number of values to collect." + }, + { + "name" : "order", + "type" : "keyword", + "optional" : true, + "description" : "The order to calculate the top values. Either `asc` or `desc`, and defaults to `asc` if omitted." + }, + { + "name" : "outputField", + "type" : "integer", + "optional" : true, + "description" : "The extra field that, if present, will be the output of the TOP call instead of `field`." + } + ], + "variadic" : false, + "returnType" : "integer" + }, + { + "params" : [ + { + "name" : "field", + "type" : "double", + "optional" : false, + "description" : "The field to collect the top values for." + }, + { + "name" : "limit", + "type" : "integer", + "optional" : false, + "description" : "The maximum number of values to collect." + }, + { + "name" : "order", + "type" : "keyword", + "optional" : true, + "description" : "The order to calculate the top values. Either `asc` or `desc`, and defaults to `asc` if omitted." + }, + { + "name" : "outputField", + "type" : "long", + "optional" : true, + "description" : "The extra field that, if present, will be the output of the TOP call instead of `field`." + } + ], + "variadic" : false, + "returnType" : "long" + }, { "params" : [ { @@ -172,6 +412,126 @@ "variadic" : false, "returnType" : "integer" }, + { + "params" : [ + { + "name" : "field", + "type" : "integer", + "optional" : false, + "description" : "The field to collect the top values for." + }, + { + "name" : "limit", + "type" : "integer", + "optional" : false, + "description" : "The maximum number of values to collect." + }, + { + "name" : "order", + "type" : "keyword", + "optional" : true, + "description" : "The order to calculate the top values. Either `asc` or `desc`, and defaults to `asc` if omitted." + }, + { + "name" : "outputField", + "type" : "date", + "optional" : true, + "description" : "The extra field that, if present, will be the output of the TOP call instead of `field`." + } + ], + "variadic" : false, + "returnType" : "date" + }, + { + "params" : [ + { + "name" : "field", + "type" : "integer", + "optional" : false, + "description" : "The field to collect the top values for." + }, + { + "name" : "limit", + "type" : "integer", + "optional" : false, + "description" : "The maximum number of values to collect." + }, + { + "name" : "order", + "type" : "keyword", + "optional" : true, + "description" : "The order to calculate the top values. Either `asc` or `desc`, and defaults to `asc` if omitted." + }, + { + "name" : "outputField", + "type" : "double", + "optional" : true, + "description" : "The extra field that, if present, will be the output of the TOP call instead of `field`." + } + ], + "variadic" : false, + "returnType" : "double" + }, + { + "params" : [ + { + "name" : "field", + "type" : "integer", + "optional" : false, + "description" : "The field to collect the top values for." + }, + { + "name" : "limit", + "type" : "integer", + "optional" : false, + "description" : "The maximum number of values to collect." + }, + { + "name" : "order", + "type" : "keyword", + "optional" : true, + "description" : "The order to calculate the top values. Either `asc` or `desc`, and defaults to `asc` if omitted." + }, + { + "name" : "outputField", + "type" : "integer", + "optional" : true, + "description" : "The extra field that, if present, will be the output of the TOP call instead of `field`." + } + ], + "variadic" : false, + "returnType" : "integer" + }, + { + "params" : [ + { + "name" : "field", + "type" : "integer", + "optional" : false, + "description" : "The field to collect the top values for." + }, + { + "name" : "limit", + "type" : "integer", + "optional" : false, + "description" : "The maximum number of values to collect." + }, + { + "name" : "order", + "type" : "keyword", + "optional" : true, + "description" : "The order to calculate the top values. Either `asc` or `desc`, and defaults to `asc` if omitted." + }, + { + "name" : "outputField", + "type" : "long", + "optional" : true, + "description" : "The extra field that, if present, will be the output of the TOP call instead of `field`." + } + ], + "variadic" : false, + "returnType" : "long" + }, { "params" : [ { @@ -298,6 +658,126 @@ "variadic" : false, "returnType" : "long" }, + { + "params" : [ + { + "name" : "field", + "type" : "long", + "optional" : false, + "description" : "The field to collect the top values for." + }, + { + "name" : "limit", + "type" : "integer", + "optional" : false, + "description" : "The maximum number of values to collect." + }, + { + "name" : "order", + "type" : "keyword", + "optional" : true, + "description" : "The order to calculate the top values. Either `asc` or `desc`, and defaults to `asc` if omitted." + }, + { + "name" : "outputField", + "type" : "date", + "optional" : true, + "description" : "The extra field that, if present, will be the output of the TOP call instead of `field`." + } + ], + "variadic" : false, + "returnType" : "date" + }, + { + "params" : [ + { + "name" : "field", + "type" : "long", + "optional" : false, + "description" : "The field to collect the top values for." + }, + { + "name" : "limit", + "type" : "integer", + "optional" : false, + "description" : "The maximum number of values to collect." + }, + { + "name" : "order", + "type" : "keyword", + "optional" : true, + "description" : "The order to calculate the top values. Either `asc` or `desc`, and defaults to `asc` if omitted." + }, + { + "name" : "outputField", + "type" : "double", + "optional" : true, + "description" : "The extra field that, if present, will be the output of the TOP call instead of `field`." + } + ], + "variadic" : false, + "returnType" : "double" + }, + { + "params" : [ + { + "name" : "field", + "type" : "long", + "optional" : false, + "description" : "The field to collect the top values for." + }, + { + "name" : "limit", + "type" : "integer", + "optional" : false, + "description" : "The maximum number of values to collect." + }, + { + "name" : "order", + "type" : "keyword", + "optional" : true, + "description" : "The order to calculate the top values. Either `asc` or `desc`, and defaults to `asc` if omitted." + }, + { + "name" : "outputField", + "type" : "integer", + "optional" : true, + "description" : "The extra field that, if present, will be the output of the TOP call instead of `field`." + } + ], + "variadic" : false, + "returnType" : "integer" + }, + { + "params" : [ + { + "name" : "field", + "type" : "long", + "optional" : false, + "description" : "The field to collect the top values for." + }, + { + "name" : "limit", + "type" : "integer", + "optional" : false, + "description" : "The maximum number of values to collect." + }, + { + "name" : "order", + "type" : "keyword", + "optional" : true, + "description" : "The order to calculate the top values. Either `asc` or `desc`, and defaults to `asc` if omitted." + }, + { + "name" : "outputField", + "type" : "long", + "optional" : true, + "description" : "The extra field that, if present, will be the output of the TOP call instead of `field`." + } + ], + "variadic" : false, + "returnType" : "long" + }, { "params" : [ { diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleBucketedSort.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleBucketedSort.java index 859dd564d2a72..995cf68cd6a50 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleBucketedSort.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleBucketedSort.java @@ -240,7 +240,8 @@ private void setNextGatherOffset(long rootIndex, int offset) { * {@link SortOrder#ASC} and "higher" for {@link SortOrder#DESC}. */ private boolean betterThan(double lhs, double rhs) { - return getOrder().reverseMul() * Double.compare(lhs, rhs) < 0; + int res = Double.compare(lhs, rhs); + return getOrder().reverseMul() * res < 0; } /** diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleDoubleBucketedSort.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleDoubleBucketedSort.java index 7b6ec62c9d6e9..6438cb1c99a62 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleDoubleBucketedSort.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleDoubleBucketedSort.java @@ -95,7 +95,7 @@ public DoubleDoubleBucketedSort(BigArrays bigArrays, SortOrder order, int bucket public void collect(double value, double extraValue, int bucket) { long rootIndex = (long) bucket * bucketSize; if (inHeapMode(bucket)) { - if (betterThan(value, values.get(rootIndex))) { + if (betterThan(value, values.get(rootIndex), extraValue, extraValues.get(rootIndex))) { values.set(rootIndex, value); extraValues.set(rootIndex, extraValue); downHeap(rootIndex, 0, bucketSize); @@ -257,8 +257,13 @@ private void setNextGatherOffset(long rootIndex, int offset) { * the entry at {@code rhs}. "Better" in this means "lower" for * {@link SortOrder#ASC} and "higher" for {@link SortOrder#DESC}. */ - private boolean betterThan(double lhs, double rhs) { - return getOrder().reverseMul() * Double.compare(lhs, rhs) < 0; + private boolean betterThan(double lhs, double rhs, double lhsExtra, double rhsExtra) { + int res = Double.compare(lhs, rhs); + if (res != 0) { + return getOrder().reverseMul() * res < 0; + } + res = Double.compare(lhsExtra, rhsExtra); + return getOrder().reverseMul() * res < 0; } /** @@ -286,10 +291,8 @@ private void grow(int bucket) { // Round up to the next full bucket. newSize = (newSize + bucketSize - 1) / bucketSize; values = bigArrays.resize(values, newSize * bucketSize); - long newExtraSize = BigArrays.overSize(((long) bucket + 1) * bucketSize, PageCacheRecycler.DOUBLE_PAGE_SIZE, Double.BYTES); // Round up to the next full bucket. - newExtraSize = (newExtraSize + bucketSize - 1) / bucketSize; - extraValues = bigArrays.resize(extraValues, newExtraSize * bucketSize); + extraValues = bigArrays.resize(extraValues, newSize * bucketSize); // Set the next gather offsets for all newly allocated buckets. fillGatherOffsets(oldMax); } @@ -371,13 +374,19 @@ private void downHeap(long rootIndex, int parent, int heapSize) { int leftChild = parent * 2 + 1; long leftIndex = rootIndex + leftChild; if (leftChild < heapSize) { - if (betterThan(values.get(worstIndex), values.get(leftIndex))) { + if (betterThan(values.get(worstIndex), values.get(leftIndex), extraValues.get(worstIndex), extraValues.get(leftIndex))) { worst = leftChild; worstIndex = leftIndex; } int rightChild = leftChild + 1; long rightIndex = rootIndex + rightChild; - if (rightChild < heapSize && betterThan(values.get(worstIndex), values.get(rightIndex))) { + if (rightChild < heapSize + && betterThan( + values.get(worstIndex), + values.get(rightIndex), + extraValues.get(worstIndex), + extraValues.get(rightIndex) + )) { worst = rightChild; worstIndex = rightIndex; } diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleFloatBucketedSort.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleFloatBucketedSort.java index 4e21ca916726e..f4bd6d9fdbf92 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleFloatBucketedSort.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleFloatBucketedSort.java @@ -95,7 +95,7 @@ public DoubleFloatBucketedSort(BigArrays bigArrays, SortOrder order, int bucketS public void collect(double value, float extraValue, int bucket) { long rootIndex = (long) bucket * bucketSize; if (inHeapMode(bucket)) { - if (betterThan(value, values.get(rootIndex))) { + if (betterThan(value, values.get(rootIndex), extraValue, extraValues.get(rootIndex))) { values.set(rootIndex, value); extraValues.set(rootIndex, extraValue); downHeap(rootIndex, 0, bucketSize); @@ -257,8 +257,13 @@ private void setNextGatherOffset(long rootIndex, int offset) { * the entry at {@code rhs}. "Better" in this means "lower" for * {@link SortOrder#ASC} and "higher" for {@link SortOrder#DESC}. */ - private boolean betterThan(double lhs, double rhs) { - return getOrder().reverseMul() * Double.compare(lhs, rhs) < 0; + private boolean betterThan(double lhs, double rhs, float lhsExtra, float rhsExtra) { + int res = Double.compare(lhs, rhs); + if (res != 0) { + return getOrder().reverseMul() * res < 0; + } + res = Float.compare(lhsExtra, rhsExtra); + return getOrder().reverseMul() * res < 0; } /** @@ -286,10 +291,8 @@ private void grow(int bucket) { // Round up to the next full bucket. newSize = (newSize + bucketSize - 1) / bucketSize; values = bigArrays.resize(values, newSize * bucketSize); - long newExtraSize = BigArrays.overSize(((long) bucket + 1) * bucketSize, PageCacheRecycler.FLOAT_PAGE_SIZE, Float.BYTES); // Round up to the next full bucket. - newExtraSize = (newExtraSize + bucketSize - 1) / bucketSize; - extraValues = bigArrays.resize(extraValues, newExtraSize * bucketSize); + extraValues = bigArrays.resize(extraValues, newSize * bucketSize); // Set the next gather offsets for all newly allocated buckets. fillGatherOffsets(oldMax); } @@ -371,13 +374,19 @@ private void downHeap(long rootIndex, int parent, int heapSize) { int leftChild = parent * 2 + 1; long leftIndex = rootIndex + leftChild; if (leftChild < heapSize) { - if (betterThan(values.get(worstIndex), values.get(leftIndex))) { + if (betterThan(values.get(worstIndex), values.get(leftIndex), extraValues.get(worstIndex), extraValues.get(leftIndex))) { worst = leftChild; worstIndex = leftIndex; } int rightChild = leftChild + 1; long rightIndex = rootIndex + rightChild; - if (rightChild < heapSize && betterThan(values.get(worstIndex), values.get(rightIndex))) { + if (rightChild < heapSize + && betterThan( + values.get(worstIndex), + values.get(rightIndex), + extraValues.get(worstIndex), + extraValues.get(rightIndex) + )) { worst = rightChild; worstIndex = rightIndex; } diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleIntBucketedSort.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleIntBucketedSort.java index 5d2206ac49b2f..c20fb8f9ce1a4 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleIntBucketedSort.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleIntBucketedSort.java @@ -95,7 +95,7 @@ public DoubleIntBucketedSort(BigArrays bigArrays, SortOrder order, int bucketSiz public void collect(double value, int extraValue, int bucket) { long rootIndex = (long) bucket * bucketSize; if (inHeapMode(bucket)) { - if (betterThan(value, values.get(rootIndex))) { + if (betterThan(value, values.get(rootIndex), extraValue, extraValues.get(rootIndex))) { values.set(rootIndex, value); extraValues.set(rootIndex, extraValue); downHeap(rootIndex, 0, bucketSize); @@ -257,8 +257,13 @@ private void setNextGatherOffset(long rootIndex, int offset) { * the entry at {@code rhs}. "Better" in this means "lower" for * {@link SortOrder#ASC} and "higher" for {@link SortOrder#DESC}. */ - private boolean betterThan(double lhs, double rhs) { - return getOrder().reverseMul() * Double.compare(lhs, rhs) < 0; + private boolean betterThan(double lhs, double rhs, int lhsExtra, int rhsExtra) { + int res = Double.compare(lhs, rhs); + if (res != 0) { + return getOrder().reverseMul() * res < 0; + } + res = Integer.compare(lhsExtra, rhsExtra); + return getOrder().reverseMul() * res < 0; } /** @@ -286,10 +291,8 @@ private void grow(int bucket) { // Round up to the next full bucket. newSize = (newSize + bucketSize - 1) / bucketSize; values = bigArrays.resize(values, newSize * bucketSize); - long newExtraSize = BigArrays.overSize(((long) bucket + 1) * bucketSize, PageCacheRecycler.INT_PAGE_SIZE, Integer.BYTES); // Round up to the next full bucket. - newExtraSize = (newExtraSize + bucketSize - 1) / bucketSize; - extraValues = bigArrays.resize(extraValues, newExtraSize * bucketSize); + extraValues = bigArrays.resize(extraValues, newSize * bucketSize); // Set the next gather offsets for all newly allocated buckets. fillGatherOffsets(oldMax); } @@ -371,13 +374,19 @@ private void downHeap(long rootIndex, int parent, int heapSize) { int leftChild = parent * 2 + 1; long leftIndex = rootIndex + leftChild; if (leftChild < heapSize) { - if (betterThan(values.get(worstIndex), values.get(leftIndex))) { + if (betterThan(values.get(worstIndex), values.get(leftIndex), extraValues.get(worstIndex), extraValues.get(leftIndex))) { worst = leftChild; worstIndex = leftIndex; } int rightChild = leftChild + 1; long rightIndex = rootIndex + rightChild; - if (rightChild < heapSize && betterThan(values.get(worstIndex), values.get(rightIndex))) { + if (rightChild < heapSize + && betterThan( + values.get(worstIndex), + values.get(rightIndex), + extraValues.get(worstIndex), + extraValues.get(rightIndex) + )) { worst = rightChild; worstIndex = rightIndex; } diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleLongBucketedSort.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleLongBucketedSort.java index 490636a5ee400..6f84c762c3258 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleLongBucketedSort.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleLongBucketedSort.java @@ -95,7 +95,7 @@ public DoubleLongBucketedSort(BigArrays bigArrays, SortOrder order, int bucketSi public void collect(double value, long extraValue, int bucket) { long rootIndex = (long) bucket * bucketSize; if (inHeapMode(bucket)) { - if (betterThan(value, values.get(rootIndex))) { + if (betterThan(value, values.get(rootIndex), extraValue, extraValues.get(rootIndex))) { values.set(rootIndex, value); extraValues.set(rootIndex, extraValue); downHeap(rootIndex, 0, bucketSize); @@ -257,8 +257,13 @@ private void setNextGatherOffset(long rootIndex, int offset) { * the entry at {@code rhs}. "Better" in this means "lower" for * {@link SortOrder#ASC} and "higher" for {@link SortOrder#DESC}. */ - private boolean betterThan(double lhs, double rhs) { - return getOrder().reverseMul() * Double.compare(lhs, rhs) < 0; + private boolean betterThan(double lhs, double rhs, long lhsExtra, long rhsExtra) { + int res = Double.compare(lhs, rhs); + if (res != 0) { + return getOrder().reverseMul() * res < 0; + } + res = Long.compare(lhsExtra, rhsExtra); + return getOrder().reverseMul() * res < 0; } /** @@ -286,10 +291,8 @@ private void grow(int bucket) { // Round up to the next full bucket. newSize = (newSize + bucketSize - 1) / bucketSize; values = bigArrays.resize(values, newSize * bucketSize); - long newExtraSize = BigArrays.overSize(((long) bucket + 1) * bucketSize, PageCacheRecycler.LONG_PAGE_SIZE, Long.BYTES); // Round up to the next full bucket. - newExtraSize = (newExtraSize + bucketSize - 1) / bucketSize; - extraValues = bigArrays.resize(extraValues, newExtraSize * bucketSize); + extraValues = bigArrays.resize(extraValues, newSize * bucketSize); // Set the next gather offsets for all newly allocated buckets. fillGatherOffsets(oldMax); } @@ -371,13 +374,19 @@ private void downHeap(long rootIndex, int parent, int heapSize) { int leftChild = parent * 2 + 1; long leftIndex = rootIndex + leftChild; if (leftChild < heapSize) { - if (betterThan(values.get(worstIndex), values.get(leftIndex))) { + if (betterThan(values.get(worstIndex), values.get(leftIndex), extraValues.get(worstIndex), extraValues.get(leftIndex))) { worst = leftChild; worstIndex = leftIndex; } int rightChild = leftChild + 1; long rightIndex = rootIndex + rightChild; - if (rightChild < heapSize && betterThan(values.get(worstIndex), values.get(rightIndex))) { + if (rightChild < heapSize + && betterThan( + values.get(worstIndex), + values.get(rightIndex), + extraValues.get(worstIndex), + extraValues.get(rightIndex) + )) { worst = rightChild; worstIndex = rightIndex; } diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/FloatBucketedSort.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/FloatBucketedSort.java index 44a1938aa8d6b..5dee9e1555526 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/FloatBucketedSort.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/FloatBucketedSort.java @@ -240,7 +240,8 @@ private void setNextGatherOffset(long rootIndex, int offset) { * {@link SortOrder#ASC} and "higher" for {@link SortOrder#DESC}. */ private boolean betterThan(float lhs, float rhs) { - return getOrder().reverseMul() * Float.compare(lhs, rhs) < 0; + int res = Float.compare(lhs, rhs); + return getOrder().reverseMul() * res < 0; } /** diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/FloatDoubleBucketedSort.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/FloatDoubleBucketedSort.java index 7bf97f44685ab..9e66583b2373e 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/FloatDoubleBucketedSort.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/FloatDoubleBucketedSort.java @@ -95,7 +95,7 @@ public FloatDoubleBucketedSort(BigArrays bigArrays, SortOrder order, int bucketS public void collect(float value, double extraValue, int bucket) { long rootIndex = (long) bucket * bucketSize; if (inHeapMode(bucket)) { - if (betterThan(value, values.get(rootIndex))) { + if (betterThan(value, values.get(rootIndex), extraValue, extraValues.get(rootIndex))) { values.set(rootIndex, value); extraValues.set(rootIndex, extraValue); downHeap(rootIndex, 0, bucketSize); @@ -257,8 +257,13 @@ private void setNextGatherOffset(long rootIndex, int offset) { * the entry at {@code rhs}. "Better" in this means "lower" for * {@link SortOrder#ASC} and "higher" for {@link SortOrder#DESC}. */ - private boolean betterThan(float lhs, float rhs) { - return getOrder().reverseMul() * Float.compare(lhs, rhs) < 0; + private boolean betterThan(float lhs, float rhs, double lhsExtra, double rhsExtra) { + int res = Float.compare(lhs, rhs); + if (res != 0) { + return getOrder().reverseMul() * res < 0; + } + res = Double.compare(lhsExtra, rhsExtra); + return getOrder().reverseMul() * res < 0; } /** @@ -286,10 +291,8 @@ private void grow(int bucket) { // Round up to the next full bucket. newSize = (newSize + bucketSize - 1) / bucketSize; values = bigArrays.resize(values, newSize * bucketSize); - long newExtraSize = BigArrays.overSize(((long) bucket + 1) * bucketSize, PageCacheRecycler.DOUBLE_PAGE_SIZE, Double.BYTES); // Round up to the next full bucket. - newExtraSize = (newExtraSize + bucketSize - 1) / bucketSize; - extraValues = bigArrays.resize(extraValues, newExtraSize * bucketSize); + extraValues = bigArrays.resize(extraValues, newSize * bucketSize); // Set the next gather offsets for all newly allocated buckets. fillGatherOffsets(oldMax); } @@ -371,13 +374,19 @@ private void downHeap(long rootIndex, int parent, int heapSize) { int leftChild = parent * 2 + 1; long leftIndex = rootIndex + leftChild; if (leftChild < heapSize) { - if (betterThan(values.get(worstIndex), values.get(leftIndex))) { + if (betterThan(values.get(worstIndex), values.get(leftIndex), extraValues.get(worstIndex), extraValues.get(leftIndex))) { worst = leftChild; worstIndex = leftIndex; } int rightChild = leftChild + 1; long rightIndex = rootIndex + rightChild; - if (rightChild < heapSize && betterThan(values.get(worstIndex), values.get(rightIndex))) { + if (rightChild < heapSize + && betterThan( + values.get(worstIndex), + values.get(rightIndex), + extraValues.get(worstIndex), + extraValues.get(rightIndex) + )) { worst = rightChild; worstIndex = rightIndex; } diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/FloatFloatBucketedSort.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/FloatFloatBucketedSort.java index 2701659eac695..c3ad1e47f1698 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/FloatFloatBucketedSort.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/FloatFloatBucketedSort.java @@ -95,7 +95,7 @@ public FloatFloatBucketedSort(BigArrays bigArrays, SortOrder order, int bucketSi public void collect(float value, float extraValue, int bucket) { long rootIndex = (long) bucket * bucketSize; if (inHeapMode(bucket)) { - if (betterThan(value, values.get(rootIndex))) { + if (betterThan(value, values.get(rootIndex), extraValue, extraValues.get(rootIndex))) { values.set(rootIndex, value); extraValues.set(rootIndex, extraValue); downHeap(rootIndex, 0, bucketSize); @@ -257,8 +257,13 @@ private void setNextGatherOffset(long rootIndex, int offset) { * the entry at {@code rhs}. "Better" in this means "lower" for * {@link SortOrder#ASC} and "higher" for {@link SortOrder#DESC}. */ - private boolean betterThan(float lhs, float rhs) { - return getOrder().reverseMul() * Float.compare(lhs, rhs) < 0; + private boolean betterThan(float lhs, float rhs, float lhsExtra, float rhsExtra) { + int res = Float.compare(lhs, rhs); + if (res != 0) { + return getOrder().reverseMul() * res < 0; + } + res = Float.compare(lhsExtra, rhsExtra); + return getOrder().reverseMul() * res < 0; } /** @@ -286,10 +291,8 @@ private void grow(int bucket) { // Round up to the next full bucket. newSize = (newSize + bucketSize - 1) / bucketSize; values = bigArrays.resize(values, newSize * bucketSize); - long newExtraSize = BigArrays.overSize(((long) bucket + 1) * bucketSize, PageCacheRecycler.FLOAT_PAGE_SIZE, Float.BYTES); // Round up to the next full bucket. - newExtraSize = (newExtraSize + bucketSize - 1) / bucketSize; - extraValues = bigArrays.resize(extraValues, newExtraSize * bucketSize); + extraValues = bigArrays.resize(extraValues, newSize * bucketSize); // Set the next gather offsets for all newly allocated buckets. fillGatherOffsets(oldMax); } @@ -371,13 +374,19 @@ private void downHeap(long rootIndex, int parent, int heapSize) { int leftChild = parent * 2 + 1; long leftIndex = rootIndex + leftChild; if (leftChild < heapSize) { - if (betterThan(values.get(worstIndex), values.get(leftIndex))) { + if (betterThan(values.get(worstIndex), values.get(leftIndex), extraValues.get(worstIndex), extraValues.get(leftIndex))) { worst = leftChild; worstIndex = leftIndex; } int rightChild = leftChild + 1; long rightIndex = rootIndex + rightChild; - if (rightChild < heapSize && betterThan(values.get(worstIndex), values.get(rightIndex))) { + if (rightChild < heapSize + && betterThan( + values.get(worstIndex), + values.get(rightIndex), + extraValues.get(worstIndex), + extraValues.get(rightIndex) + )) { worst = rightChild; worstIndex = rightIndex; } diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/FloatIntBucketedSort.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/FloatIntBucketedSort.java index 9d8f953143b47..fefe511a88586 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/FloatIntBucketedSort.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/FloatIntBucketedSort.java @@ -95,7 +95,7 @@ public FloatIntBucketedSort(BigArrays bigArrays, SortOrder order, int bucketSize public void collect(float value, int extraValue, int bucket) { long rootIndex = (long) bucket * bucketSize; if (inHeapMode(bucket)) { - if (betterThan(value, values.get(rootIndex))) { + if (betterThan(value, values.get(rootIndex), extraValue, extraValues.get(rootIndex))) { values.set(rootIndex, value); extraValues.set(rootIndex, extraValue); downHeap(rootIndex, 0, bucketSize); @@ -257,8 +257,13 @@ private void setNextGatherOffset(long rootIndex, int offset) { * the entry at {@code rhs}. "Better" in this means "lower" for * {@link SortOrder#ASC} and "higher" for {@link SortOrder#DESC}. */ - private boolean betterThan(float lhs, float rhs) { - return getOrder().reverseMul() * Float.compare(lhs, rhs) < 0; + private boolean betterThan(float lhs, float rhs, int lhsExtra, int rhsExtra) { + int res = Float.compare(lhs, rhs); + if (res != 0) { + return getOrder().reverseMul() * res < 0; + } + res = Integer.compare(lhsExtra, rhsExtra); + return getOrder().reverseMul() * res < 0; } /** @@ -286,10 +291,8 @@ private void grow(int bucket) { // Round up to the next full bucket. newSize = (newSize + bucketSize - 1) / bucketSize; values = bigArrays.resize(values, newSize * bucketSize); - long newExtraSize = BigArrays.overSize(((long) bucket + 1) * bucketSize, PageCacheRecycler.INT_PAGE_SIZE, Integer.BYTES); // Round up to the next full bucket. - newExtraSize = (newExtraSize + bucketSize - 1) / bucketSize; - extraValues = bigArrays.resize(extraValues, newExtraSize * bucketSize); + extraValues = bigArrays.resize(extraValues, newSize * bucketSize); // Set the next gather offsets for all newly allocated buckets. fillGatherOffsets(oldMax); } @@ -371,13 +374,19 @@ private void downHeap(long rootIndex, int parent, int heapSize) { int leftChild = parent * 2 + 1; long leftIndex = rootIndex + leftChild; if (leftChild < heapSize) { - if (betterThan(values.get(worstIndex), values.get(leftIndex))) { + if (betterThan(values.get(worstIndex), values.get(leftIndex), extraValues.get(worstIndex), extraValues.get(leftIndex))) { worst = leftChild; worstIndex = leftIndex; } int rightChild = leftChild + 1; long rightIndex = rootIndex + rightChild; - if (rightChild < heapSize && betterThan(values.get(worstIndex), values.get(rightIndex))) { + if (rightChild < heapSize + && betterThan( + values.get(worstIndex), + values.get(rightIndex), + extraValues.get(worstIndex), + extraValues.get(rightIndex) + )) { worst = rightChild; worstIndex = rightIndex; } diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/FloatLongBucketedSort.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/FloatLongBucketedSort.java index 458d03eedf5ae..32aa8e9fdb191 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/FloatLongBucketedSort.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/FloatLongBucketedSort.java @@ -95,7 +95,7 @@ public FloatLongBucketedSort(BigArrays bigArrays, SortOrder order, int bucketSiz public void collect(float value, long extraValue, int bucket) { long rootIndex = (long) bucket * bucketSize; if (inHeapMode(bucket)) { - if (betterThan(value, values.get(rootIndex))) { + if (betterThan(value, values.get(rootIndex), extraValue, extraValues.get(rootIndex))) { values.set(rootIndex, value); extraValues.set(rootIndex, extraValue); downHeap(rootIndex, 0, bucketSize); @@ -257,8 +257,13 @@ private void setNextGatherOffset(long rootIndex, int offset) { * the entry at {@code rhs}. "Better" in this means "lower" for * {@link SortOrder#ASC} and "higher" for {@link SortOrder#DESC}. */ - private boolean betterThan(float lhs, float rhs) { - return getOrder().reverseMul() * Float.compare(lhs, rhs) < 0; + private boolean betterThan(float lhs, float rhs, long lhsExtra, long rhsExtra) { + int res = Float.compare(lhs, rhs); + if (res != 0) { + return getOrder().reverseMul() * res < 0; + } + res = Long.compare(lhsExtra, rhsExtra); + return getOrder().reverseMul() * res < 0; } /** @@ -286,10 +291,8 @@ private void grow(int bucket) { // Round up to the next full bucket. newSize = (newSize + bucketSize - 1) / bucketSize; values = bigArrays.resize(values, newSize * bucketSize); - long newExtraSize = BigArrays.overSize(((long) bucket + 1) * bucketSize, PageCacheRecycler.LONG_PAGE_SIZE, Long.BYTES); // Round up to the next full bucket. - newExtraSize = (newExtraSize + bucketSize - 1) / bucketSize; - extraValues = bigArrays.resize(extraValues, newExtraSize * bucketSize); + extraValues = bigArrays.resize(extraValues, newSize * bucketSize); // Set the next gather offsets for all newly allocated buckets. fillGatherOffsets(oldMax); } @@ -371,13 +374,19 @@ private void downHeap(long rootIndex, int parent, int heapSize) { int leftChild = parent * 2 + 1; long leftIndex = rootIndex + leftChild; if (leftChild < heapSize) { - if (betterThan(values.get(worstIndex), values.get(leftIndex))) { + if (betterThan(values.get(worstIndex), values.get(leftIndex), extraValues.get(worstIndex), extraValues.get(leftIndex))) { worst = leftChild; worstIndex = leftIndex; } int rightChild = leftChild + 1; long rightIndex = rootIndex + rightChild; - if (rightChild < heapSize && betterThan(values.get(worstIndex), values.get(rightIndex))) { + if (rightChild < heapSize + && betterThan( + values.get(worstIndex), + values.get(rightIndex), + extraValues.get(worstIndex), + extraValues.get(rightIndex) + )) { worst = rightChild; worstIndex = rightIndex; } diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/IntBucketedSort.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/IntBucketedSort.java index cca03a0d0e9bc..7dcec4461f0a5 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/IntBucketedSort.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/IntBucketedSort.java @@ -240,7 +240,8 @@ private void setNextGatherOffset(long rootIndex, int offset) { * {@link SortOrder#ASC} and "higher" for {@link SortOrder#DESC}. */ private boolean betterThan(int lhs, int rhs) { - return getOrder().reverseMul() * Integer.compare(lhs, rhs) < 0; + int res = Integer.compare(lhs, rhs); + return getOrder().reverseMul() * res < 0; } /** diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/IntDoubleBucketedSort.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/IntDoubleBucketedSort.java index 096563f7e5392..9692a3490add6 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/IntDoubleBucketedSort.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/IntDoubleBucketedSort.java @@ -95,7 +95,7 @@ public IntDoubleBucketedSort(BigArrays bigArrays, SortOrder order, int bucketSiz public void collect(int value, double extraValue, int bucket) { long rootIndex = (long) bucket * bucketSize; if (inHeapMode(bucket)) { - if (betterThan(value, values.get(rootIndex))) { + if (betterThan(value, values.get(rootIndex), extraValue, extraValues.get(rootIndex))) { values.set(rootIndex, value); extraValues.set(rootIndex, extraValue); downHeap(rootIndex, 0, bucketSize); @@ -257,8 +257,13 @@ private void setNextGatherOffset(long rootIndex, int offset) { * the entry at {@code rhs}. "Better" in this means "lower" for * {@link SortOrder#ASC} and "higher" for {@link SortOrder#DESC}. */ - private boolean betterThan(int lhs, int rhs) { - return getOrder().reverseMul() * Integer.compare(lhs, rhs) < 0; + private boolean betterThan(int lhs, int rhs, double lhsExtra, double rhsExtra) { + int res = Integer.compare(lhs, rhs); + if (res != 0) { + return getOrder().reverseMul() * res < 0; + } + res = Double.compare(lhsExtra, rhsExtra); + return getOrder().reverseMul() * res < 0; } /** @@ -286,10 +291,8 @@ private void grow(int bucket) { // Round up to the next full bucket. newSize = (newSize + bucketSize - 1) / bucketSize; values = bigArrays.resize(values, newSize * bucketSize); - long newExtraSize = BigArrays.overSize(((long) bucket + 1) * bucketSize, PageCacheRecycler.DOUBLE_PAGE_SIZE, Double.BYTES); // Round up to the next full bucket. - newExtraSize = (newExtraSize + bucketSize - 1) / bucketSize; - extraValues = bigArrays.resize(extraValues, newExtraSize * bucketSize); + extraValues = bigArrays.resize(extraValues, newSize * bucketSize); // Set the next gather offsets for all newly allocated buckets. fillGatherOffsets(oldMax); } @@ -371,13 +374,19 @@ private void downHeap(long rootIndex, int parent, int heapSize) { int leftChild = parent * 2 + 1; long leftIndex = rootIndex + leftChild; if (leftChild < heapSize) { - if (betterThan(values.get(worstIndex), values.get(leftIndex))) { + if (betterThan(values.get(worstIndex), values.get(leftIndex), extraValues.get(worstIndex), extraValues.get(leftIndex))) { worst = leftChild; worstIndex = leftIndex; } int rightChild = leftChild + 1; long rightIndex = rootIndex + rightChild; - if (rightChild < heapSize && betterThan(values.get(worstIndex), values.get(rightIndex))) { + if (rightChild < heapSize + && betterThan( + values.get(worstIndex), + values.get(rightIndex), + extraValues.get(worstIndex), + extraValues.get(rightIndex) + )) { worst = rightChild; worstIndex = rightIndex; } diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/IntFloatBucketedSort.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/IntFloatBucketedSort.java index b7bf1750e28ff..756f9894d887a 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/IntFloatBucketedSort.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/IntFloatBucketedSort.java @@ -95,7 +95,7 @@ public IntFloatBucketedSort(BigArrays bigArrays, SortOrder order, int bucketSize public void collect(int value, float extraValue, int bucket) { long rootIndex = (long) bucket * bucketSize; if (inHeapMode(bucket)) { - if (betterThan(value, values.get(rootIndex))) { + if (betterThan(value, values.get(rootIndex), extraValue, extraValues.get(rootIndex))) { values.set(rootIndex, value); extraValues.set(rootIndex, extraValue); downHeap(rootIndex, 0, bucketSize); @@ -257,8 +257,13 @@ private void setNextGatherOffset(long rootIndex, int offset) { * the entry at {@code rhs}. "Better" in this means "lower" for * {@link SortOrder#ASC} and "higher" for {@link SortOrder#DESC}. */ - private boolean betterThan(int lhs, int rhs) { - return getOrder().reverseMul() * Integer.compare(lhs, rhs) < 0; + private boolean betterThan(int lhs, int rhs, float lhsExtra, float rhsExtra) { + int res = Integer.compare(lhs, rhs); + if (res != 0) { + return getOrder().reverseMul() * res < 0; + } + res = Float.compare(lhsExtra, rhsExtra); + return getOrder().reverseMul() * res < 0; } /** @@ -286,10 +291,8 @@ private void grow(int bucket) { // Round up to the next full bucket. newSize = (newSize + bucketSize - 1) / bucketSize; values = bigArrays.resize(values, newSize * bucketSize); - long newExtraSize = BigArrays.overSize(((long) bucket + 1) * bucketSize, PageCacheRecycler.FLOAT_PAGE_SIZE, Float.BYTES); // Round up to the next full bucket. - newExtraSize = (newExtraSize + bucketSize - 1) / bucketSize; - extraValues = bigArrays.resize(extraValues, newExtraSize * bucketSize); + extraValues = bigArrays.resize(extraValues, newSize * bucketSize); // Set the next gather offsets for all newly allocated buckets. fillGatherOffsets(oldMax); } @@ -371,13 +374,19 @@ private void downHeap(long rootIndex, int parent, int heapSize) { int leftChild = parent * 2 + 1; long leftIndex = rootIndex + leftChild; if (leftChild < heapSize) { - if (betterThan(values.get(worstIndex), values.get(leftIndex))) { + if (betterThan(values.get(worstIndex), values.get(leftIndex), extraValues.get(worstIndex), extraValues.get(leftIndex))) { worst = leftChild; worstIndex = leftIndex; } int rightChild = leftChild + 1; long rightIndex = rootIndex + rightChild; - if (rightChild < heapSize && betterThan(values.get(worstIndex), values.get(rightIndex))) { + if (rightChild < heapSize + && betterThan( + values.get(worstIndex), + values.get(rightIndex), + extraValues.get(worstIndex), + extraValues.get(rightIndex) + )) { worst = rightChild; worstIndex = rightIndex; } diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/IntIntBucketedSort.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/IntIntBucketedSort.java index b561ea656a4cf..13cb37e886ce6 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/IntIntBucketedSort.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/IntIntBucketedSort.java @@ -95,7 +95,7 @@ public IntIntBucketedSort(BigArrays bigArrays, SortOrder order, int bucketSize) public void collect(int value, int extraValue, int bucket) { long rootIndex = (long) bucket * bucketSize; if (inHeapMode(bucket)) { - if (betterThan(value, values.get(rootIndex))) { + if (betterThan(value, values.get(rootIndex), extraValue, extraValues.get(rootIndex))) { values.set(rootIndex, value); extraValues.set(rootIndex, extraValue); downHeap(rootIndex, 0, bucketSize); @@ -257,8 +257,13 @@ private void setNextGatherOffset(long rootIndex, int offset) { * the entry at {@code rhs}. "Better" in this means "lower" for * {@link SortOrder#ASC} and "higher" for {@link SortOrder#DESC}. */ - private boolean betterThan(int lhs, int rhs) { - return getOrder().reverseMul() * Integer.compare(lhs, rhs) < 0; + private boolean betterThan(int lhs, int rhs, int lhsExtra, int rhsExtra) { + int res = Integer.compare(lhs, rhs); + if (res != 0) { + return getOrder().reverseMul() * res < 0; + } + res = Integer.compare(lhsExtra, rhsExtra); + return getOrder().reverseMul() * res < 0; } /** @@ -286,10 +291,8 @@ private void grow(int bucket) { // Round up to the next full bucket. newSize = (newSize + bucketSize - 1) / bucketSize; values = bigArrays.resize(values, newSize * bucketSize); - long newExtraSize = BigArrays.overSize(((long) bucket + 1) * bucketSize, PageCacheRecycler.INT_PAGE_SIZE, Integer.BYTES); // Round up to the next full bucket. - newExtraSize = (newExtraSize + bucketSize - 1) / bucketSize; - extraValues = bigArrays.resize(extraValues, newExtraSize * bucketSize); + extraValues = bigArrays.resize(extraValues, newSize * bucketSize); // Set the next gather offsets for all newly allocated buckets. fillGatherOffsets(oldMax); } @@ -371,13 +374,19 @@ private void downHeap(long rootIndex, int parent, int heapSize) { int leftChild = parent * 2 + 1; long leftIndex = rootIndex + leftChild; if (leftChild < heapSize) { - if (betterThan(values.get(worstIndex), values.get(leftIndex))) { + if (betterThan(values.get(worstIndex), values.get(leftIndex), extraValues.get(worstIndex), extraValues.get(leftIndex))) { worst = leftChild; worstIndex = leftIndex; } int rightChild = leftChild + 1; long rightIndex = rootIndex + rightChild; - if (rightChild < heapSize && betterThan(values.get(worstIndex), values.get(rightIndex))) { + if (rightChild < heapSize + && betterThan( + values.get(worstIndex), + values.get(rightIndex), + extraValues.get(worstIndex), + extraValues.get(rightIndex) + )) { worst = rightChild; worstIndex = rightIndex; } diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/IntLongBucketedSort.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/IntLongBucketedSort.java index 7273660887b42..dae223f67dc8d 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/IntLongBucketedSort.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/IntLongBucketedSort.java @@ -95,7 +95,7 @@ public IntLongBucketedSort(BigArrays bigArrays, SortOrder order, int bucketSize) public void collect(int value, long extraValue, int bucket) { long rootIndex = (long) bucket * bucketSize; if (inHeapMode(bucket)) { - if (betterThan(value, values.get(rootIndex))) { + if (betterThan(value, values.get(rootIndex), extraValue, extraValues.get(rootIndex))) { values.set(rootIndex, value); extraValues.set(rootIndex, extraValue); downHeap(rootIndex, 0, bucketSize); @@ -257,8 +257,13 @@ private void setNextGatherOffset(long rootIndex, int offset) { * the entry at {@code rhs}. "Better" in this means "lower" for * {@link SortOrder#ASC} and "higher" for {@link SortOrder#DESC}. */ - private boolean betterThan(int lhs, int rhs) { - return getOrder().reverseMul() * Integer.compare(lhs, rhs) < 0; + private boolean betterThan(int lhs, int rhs, long lhsExtra, long rhsExtra) { + int res = Integer.compare(lhs, rhs); + if (res != 0) { + return getOrder().reverseMul() * res < 0; + } + res = Long.compare(lhsExtra, rhsExtra); + return getOrder().reverseMul() * res < 0; } /** @@ -286,10 +291,8 @@ private void grow(int bucket) { // Round up to the next full bucket. newSize = (newSize + bucketSize - 1) / bucketSize; values = bigArrays.resize(values, newSize * bucketSize); - long newExtraSize = BigArrays.overSize(((long) bucket + 1) * bucketSize, PageCacheRecycler.LONG_PAGE_SIZE, Long.BYTES); // Round up to the next full bucket. - newExtraSize = (newExtraSize + bucketSize - 1) / bucketSize; - extraValues = bigArrays.resize(extraValues, newExtraSize * bucketSize); + extraValues = bigArrays.resize(extraValues, newSize * bucketSize); // Set the next gather offsets for all newly allocated buckets. fillGatherOffsets(oldMax); } @@ -371,13 +374,19 @@ private void downHeap(long rootIndex, int parent, int heapSize) { int leftChild = parent * 2 + 1; long leftIndex = rootIndex + leftChild; if (leftChild < heapSize) { - if (betterThan(values.get(worstIndex), values.get(leftIndex))) { + if (betterThan(values.get(worstIndex), values.get(leftIndex), extraValues.get(worstIndex), extraValues.get(leftIndex))) { worst = leftChild; worstIndex = leftIndex; } int rightChild = leftChild + 1; long rightIndex = rootIndex + rightChild; - if (rightChild < heapSize && betterThan(values.get(worstIndex), values.get(rightIndex))) { + if (rightChild < heapSize + && betterThan( + values.get(worstIndex), + values.get(rightIndex), + extraValues.get(worstIndex), + extraValues.get(rightIndex) + )) { worst = rightChild; worstIndex = rightIndex; } diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/LongBucketedSort.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/LongBucketedSort.java index 4975d7983bbbe..e10ce05017d23 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/LongBucketedSort.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/LongBucketedSort.java @@ -240,7 +240,8 @@ private void setNextGatherOffset(long rootIndex, int offset) { * {@link SortOrder#ASC} and "higher" for {@link SortOrder#DESC}. */ private boolean betterThan(long lhs, long rhs) { - return getOrder().reverseMul() * Long.compare(lhs, rhs) < 0; + int res = Long.compare(lhs, rhs); + return getOrder().reverseMul() * res < 0; } /** diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/LongDoubleBucketedSort.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/LongDoubleBucketedSort.java index c43444f3c01d3..dd7bf77eaf6f6 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/LongDoubleBucketedSort.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/LongDoubleBucketedSort.java @@ -95,7 +95,7 @@ public LongDoubleBucketedSort(BigArrays bigArrays, SortOrder order, int bucketSi public void collect(long value, double extraValue, int bucket) { long rootIndex = (long) bucket * bucketSize; if (inHeapMode(bucket)) { - if (betterThan(value, values.get(rootIndex))) { + if (betterThan(value, values.get(rootIndex), extraValue, extraValues.get(rootIndex))) { values.set(rootIndex, value); extraValues.set(rootIndex, extraValue); downHeap(rootIndex, 0, bucketSize); @@ -257,8 +257,13 @@ private void setNextGatherOffset(long rootIndex, int offset) { * the entry at {@code rhs}. "Better" in this means "lower" for * {@link SortOrder#ASC} and "higher" for {@link SortOrder#DESC}. */ - private boolean betterThan(long lhs, long rhs) { - return getOrder().reverseMul() * Long.compare(lhs, rhs) < 0; + private boolean betterThan(long lhs, long rhs, double lhsExtra, double rhsExtra) { + int res = Long.compare(lhs, rhs); + if (res != 0) { + return getOrder().reverseMul() * res < 0; + } + res = Double.compare(lhsExtra, rhsExtra); + return getOrder().reverseMul() * res < 0; } /** @@ -286,10 +291,8 @@ private void grow(int bucket) { // Round up to the next full bucket. newSize = (newSize + bucketSize - 1) / bucketSize; values = bigArrays.resize(values, newSize * bucketSize); - long newExtraSize = BigArrays.overSize(((long) bucket + 1) * bucketSize, PageCacheRecycler.DOUBLE_PAGE_SIZE, Double.BYTES); // Round up to the next full bucket. - newExtraSize = (newExtraSize + bucketSize - 1) / bucketSize; - extraValues = bigArrays.resize(extraValues, newExtraSize * bucketSize); + extraValues = bigArrays.resize(extraValues, newSize * bucketSize); // Set the next gather offsets for all newly allocated buckets. fillGatherOffsets(oldMax); } @@ -371,13 +374,19 @@ private void downHeap(long rootIndex, int parent, int heapSize) { int leftChild = parent * 2 + 1; long leftIndex = rootIndex + leftChild; if (leftChild < heapSize) { - if (betterThan(values.get(worstIndex), values.get(leftIndex))) { + if (betterThan(values.get(worstIndex), values.get(leftIndex), extraValues.get(worstIndex), extraValues.get(leftIndex))) { worst = leftChild; worstIndex = leftIndex; } int rightChild = leftChild + 1; long rightIndex = rootIndex + rightChild; - if (rightChild < heapSize && betterThan(values.get(worstIndex), values.get(rightIndex))) { + if (rightChild < heapSize + && betterThan( + values.get(worstIndex), + values.get(rightIndex), + extraValues.get(worstIndex), + extraValues.get(rightIndex) + )) { worst = rightChild; worstIndex = rightIndex; } diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/LongFloatBucketedSort.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/LongFloatBucketedSort.java index a77e6f653a9a4..db4d25aecfa74 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/LongFloatBucketedSort.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/LongFloatBucketedSort.java @@ -95,7 +95,7 @@ public LongFloatBucketedSort(BigArrays bigArrays, SortOrder order, int bucketSiz public void collect(long value, float extraValue, int bucket) { long rootIndex = (long) bucket * bucketSize; if (inHeapMode(bucket)) { - if (betterThan(value, values.get(rootIndex))) { + if (betterThan(value, values.get(rootIndex), extraValue, extraValues.get(rootIndex))) { values.set(rootIndex, value); extraValues.set(rootIndex, extraValue); downHeap(rootIndex, 0, bucketSize); @@ -257,8 +257,13 @@ private void setNextGatherOffset(long rootIndex, int offset) { * the entry at {@code rhs}. "Better" in this means "lower" for * {@link SortOrder#ASC} and "higher" for {@link SortOrder#DESC}. */ - private boolean betterThan(long lhs, long rhs) { - return getOrder().reverseMul() * Long.compare(lhs, rhs) < 0; + private boolean betterThan(long lhs, long rhs, float lhsExtra, float rhsExtra) { + int res = Long.compare(lhs, rhs); + if (res != 0) { + return getOrder().reverseMul() * res < 0; + } + res = Float.compare(lhsExtra, rhsExtra); + return getOrder().reverseMul() * res < 0; } /** @@ -286,10 +291,8 @@ private void grow(int bucket) { // Round up to the next full bucket. newSize = (newSize + bucketSize - 1) / bucketSize; values = bigArrays.resize(values, newSize * bucketSize); - long newExtraSize = BigArrays.overSize(((long) bucket + 1) * bucketSize, PageCacheRecycler.FLOAT_PAGE_SIZE, Float.BYTES); // Round up to the next full bucket. - newExtraSize = (newExtraSize + bucketSize - 1) / bucketSize; - extraValues = bigArrays.resize(extraValues, newExtraSize * bucketSize); + extraValues = bigArrays.resize(extraValues, newSize * bucketSize); // Set the next gather offsets for all newly allocated buckets. fillGatherOffsets(oldMax); } @@ -371,13 +374,19 @@ private void downHeap(long rootIndex, int parent, int heapSize) { int leftChild = parent * 2 + 1; long leftIndex = rootIndex + leftChild; if (leftChild < heapSize) { - if (betterThan(values.get(worstIndex), values.get(leftIndex))) { + if (betterThan(values.get(worstIndex), values.get(leftIndex), extraValues.get(worstIndex), extraValues.get(leftIndex))) { worst = leftChild; worstIndex = leftIndex; } int rightChild = leftChild + 1; long rightIndex = rootIndex + rightChild; - if (rightChild < heapSize && betterThan(values.get(worstIndex), values.get(rightIndex))) { + if (rightChild < heapSize + && betterThan( + values.get(worstIndex), + values.get(rightIndex), + extraValues.get(worstIndex), + extraValues.get(rightIndex) + )) { worst = rightChild; worstIndex = rightIndex; } diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/LongIntBucketedSort.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/LongIntBucketedSort.java index d3bfbbbcf78df..8e22b27791a2c 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/LongIntBucketedSort.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/LongIntBucketedSort.java @@ -95,7 +95,7 @@ public LongIntBucketedSort(BigArrays bigArrays, SortOrder order, int bucketSize) public void collect(long value, int extraValue, int bucket) { long rootIndex = (long) bucket * bucketSize; if (inHeapMode(bucket)) { - if (betterThan(value, values.get(rootIndex))) { + if (betterThan(value, values.get(rootIndex), extraValue, extraValues.get(rootIndex))) { values.set(rootIndex, value); extraValues.set(rootIndex, extraValue); downHeap(rootIndex, 0, bucketSize); @@ -257,8 +257,13 @@ private void setNextGatherOffset(long rootIndex, int offset) { * the entry at {@code rhs}. "Better" in this means "lower" for * {@link SortOrder#ASC} and "higher" for {@link SortOrder#DESC}. */ - private boolean betterThan(long lhs, long rhs) { - return getOrder().reverseMul() * Long.compare(lhs, rhs) < 0; + private boolean betterThan(long lhs, long rhs, int lhsExtra, int rhsExtra) { + int res = Long.compare(lhs, rhs); + if (res != 0) { + return getOrder().reverseMul() * res < 0; + } + res = Integer.compare(lhsExtra, rhsExtra); + return getOrder().reverseMul() * res < 0; } /** @@ -286,10 +291,8 @@ private void grow(int bucket) { // Round up to the next full bucket. newSize = (newSize + bucketSize - 1) / bucketSize; values = bigArrays.resize(values, newSize * bucketSize); - long newExtraSize = BigArrays.overSize(((long) bucket + 1) * bucketSize, PageCacheRecycler.INT_PAGE_SIZE, Integer.BYTES); // Round up to the next full bucket. - newExtraSize = (newExtraSize + bucketSize - 1) / bucketSize; - extraValues = bigArrays.resize(extraValues, newExtraSize * bucketSize); + extraValues = bigArrays.resize(extraValues, newSize * bucketSize); // Set the next gather offsets for all newly allocated buckets. fillGatherOffsets(oldMax); } @@ -371,13 +374,19 @@ private void downHeap(long rootIndex, int parent, int heapSize) { int leftChild = parent * 2 + 1; long leftIndex = rootIndex + leftChild; if (leftChild < heapSize) { - if (betterThan(values.get(worstIndex), values.get(leftIndex))) { + if (betterThan(values.get(worstIndex), values.get(leftIndex), extraValues.get(worstIndex), extraValues.get(leftIndex))) { worst = leftChild; worstIndex = leftIndex; } int rightChild = leftChild + 1; long rightIndex = rootIndex + rightChild; - if (rightChild < heapSize && betterThan(values.get(worstIndex), values.get(rightIndex))) { + if (rightChild < heapSize + && betterThan( + values.get(worstIndex), + values.get(rightIndex), + extraValues.get(worstIndex), + extraValues.get(rightIndex) + )) { worst = rightChild; worstIndex = rightIndex; } diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/LongLongBucketedSort.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/LongLongBucketedSort.java index 378ef7785cf9a..49a824e0c88b0 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/LongLongBucketedSort.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/LongLongBucketedSort.java @@ -94,7 +94,7 @@ public LongLongBucketedSort(BigArrays bigArrays, SortOrder order, int bucketSize public void collect(long value, long extraValue, int bucket) { long rootIndex = (long) bucket * bucketSize; if (inHeapMode(bucket)) { - if (betterThan(value, values.get(rootIndex))) { + if (betterThan(value, values.get(rootIndex), extraValue, extraValues.get(rootIndex))) { values.set(rootIndex, value); extraValues.set(rootIndex, extraValue); downHeap(rootIndex, 0, bucketSize); @@ -256,8 +256,13 @@ private void setNextGatherOffset(long rootIndex, int offset) { * the entry at {@code rhs}. "Better" in this means "lower" for * {@link SortOrder#ASC} and "higher" for {@link SortOrder#DESC}. */ - private boolean betterThan(long lhs, long rhs) { - return getOrder().reverseMul() * Long.compare(lhs, rhs) < 0; + private boolean betterThan(long lhs, long rhs, long lhsExtra, long rhsExtra) { + int res = Long.compare(lhs, rhs); + if (res != 0) { + return getOrder().reverseMul() * res < 0; + } + res = Long.compare(lhsExtra, rhsExtra); + return getOrder().reverseMul() * res < 0; } /** @@ -285,10 +290,8 @@ private void grow(int bucket) { // Round up to the next full bucket. newSize = (newSize + bucketSize - 1) / bucketSize; values = bigArrays.resize(values, newSize * bucketSize); - long newExtraSize = BigArrays.overSize(((long) bucket + 1) * bucketSize, PageCacheRecycler.LONG_PAGE_SIZE, Long.BYTES); // Round up to the next full bucket. - newExtraSize = (newExtraSize + bucketSize - 1) / bucketSize; - extraValues = bigArrays.resize(extraValues, newExtraSize * bucketSize); + extraValues = bigArrays.resize(extraValues, newSize * bucketSize); // Set the next gather offsets for all newly allocated buckets. fillGatherOffsets(oldMax); } @@ -370,13 +373,19 @@ private void downHeap(long rootIndex, int parent, int heapSize) { int leftChild = parent * 2 + 1; long leftIndex = rootIndex + leftChild; if (leftChild < heapSize) { - if (betterThan(values.get(worstIndex), values.get(leftIndex))) { + if (betterThan(values.get(worstIndex), values.get(leftIndex), extraValues.get(worstIndex), extraValues.get(leftIndex))) { worst = leftChild; worstIndex = leftIndex; } int rightChild = leftChild + 1; long rightIndex = rootIndex + rightChild; - if (rightChild < heapSize && betterThan(values.get(worstIndex), values.get(rightIndex))) { + if (rightChild < heapSize + && betterThan( + values.get(worstIndex), + values.get(rightIndex), + extraValues.get(worstIndex), + extraValues.get(rightIndex) + )) { worst = rightChild; worstIndex = rightIndex; } diff --git a/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/data/sort/X-BucketedSort.java.st b/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/data/sort/X-BucketedSort.java.st index d0ff45a3eb76e..70d7c5fb3f5e7 100644 --- a/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/data/sort/X-BucketedSort.java.st +++ b/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/data/sort/X-BucketedSort.java.st @@ -104,7 +104,7 @@ $endif$ public void collect($type$ value, $if(hasExtra)$$Extratype$ extraValue, $endif$int bucket) { long rootIndex = (long) bucket * bucketSize; if (inHeapMode(bucket)) { - if (betterThan(value, values.get(rootIndex))) { + if (betterThan(value, values.get(rootIndex)$if(hasExtra)$, extraValue, extraValues.get(rootIndex)$endif$)) { values.set(rootIndex, value); $if(hasExtra)$ extraValues.set(rootIndex, extraValue); @@ -320,8 +320,15 @@ $endif$ * the entry at {@code rhs}. "Better" in this means "lower" for * {@link SortOrder#ASC} and "higher" for {@link SortOrder#DESC}. */ - private boolean betterThan($type$ lhs, $type$ rhs) { - return getOrder().reverseMul() * $Wrapper$.compare(lhs, rhs) < 0; + private boolean betterThan($type$ lhs, $type$ rhs$if(hasExtra)$, $Extratype$ lhsExtra, $Extratype$ rhsExtra$endif$) { + int res = $Wrapper$.compare(lhs, rhs); +$if(hasExtra)$ + if (res != 0) { + return getOrder().reverseMul() * res < 0; + } + res = $ExtraWrapper$.compare(lhsExtra, rhsExtra); +$endif$ + return getOrder().reverseMul() * res < 0; } /** @@ -352,10 +359,8 @@ $endif$ newSize = (newSize + bucketSize - 1) / bucketSize; values = bigArrays.resize(values, newSize * bucketSize); $if(hasExtra)$ - long newExtraSize = BigArrays.overSize(((long) bucket + 1) * bucketSize, PageCacheRecycler.$ExtraTYPE$_PAGE_SIZE, $ExtraBYTES$); // Round up to the next full bucket. - newExtraSize = (newExtraSize + bucketSize - 1) / bucketSize; - extraValues = bigArrays.resize(extraValues, newExtraSize * bucketSize); + extraValues = bigArrays.resize(extraValues, newSize * bucketSize); $endif$ // Set the next gather offsets for all newly allocated buckets. fillGatherOffsets(oldMax); @@ -438,13 +443,23 @@ $endif$ int leftChild = parent * 2 + 1; long leftIndex = rootIndex + leftChild; if (leftChild < heapSize) { - if (betterThan(values.get(worstIndex), values.get(leftIndex))) { + if (betterThan(values.get(worstIndex), values.get(leftIndex)$if(hasExtra)$, extraValues.get(worstIndex), extraValues.get(leftIndex)$endif$)) { worst = leftChild; worstIndex = leftIndex; } int rightChild = leftChild + 1; long rightIndex = rootIndex + rightChild; +$if(hasExtra)$ + if (rightChild < heapSize + && betterThan( + values.get(worstIndex), + values.get(rightIndex), + extraValues.get(worstIndex), + extraValues.get(rightIndex) + )) { +$else$ if (rightChild < heapSize && betterThan(values.get(worstIndex), values.get(rightIndex))) { +$endif$ worst = rightChild; worstIndex = rightIndex; } diff --git a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/aggregate/Top.java b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/aggregate/Top.java index 1f6a785ac6a9f..062a98aa17d64 100644 --- a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/aggregate/Top.java +++ b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/aggregate/Top.java @@ -104,7 +104,7 @@ public Top( @Param( optional = true, name = "outputField", - type = { "double", "integer", "long" }, + type = { "double", "integer", "long", "date" }, description = "The extra field that, if present, will be the output of the TOP call instead of `field`." ) Expression outputField ) { diff --git a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/TopTests.java b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/TopTests.java index 93a346f819d8d..a90d1198791e1 100644 --- a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/TopTests.java +++ b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/TopTests.java @@ -24,11 +24,15 @@ import java.util.Arrays; import java.util.Comparator; import java.util.List; +import java.util.Map; import java.util.function.Supplier; import java.util.stream.Collectors; +import java.util.stream.IntStream; import java.util.stream.Stream; import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.hasSize; +import static org.hamcrest.Matchers.isA; public class TopTests extends AbstractAggregationTestCase { public TopTests(@Name("TestCase") Supplier testCaseSupplier) { @@ -52,11 +56,41 @@ public static Iterable parameters() { MultiRowTestCaseSupplier.stringCases(1, 1000, DataType.TEXT) ) .flatMap(List::stream) - .map(fieldCaseSupplier -> TopTests.makeSupplier(fieldCaseSupplier, limitCaseSupplier, order)) + .map(fieldCaseSupplier -> TopTests.makeSupplier(fieldCaseSupplier, limitCaseSupplier, order, null)) .collect(Collectors.toCollection(() -> suppliers)); } } + for (var limitCaseSupplier : TestCaseSupplier.intCases(1, 1000, false)) { + for (String order : Arrays.asList("asc", "desc")) { + int rows = 100; + List fieldCaseSuppliers = Stream.of( + MultiRowTestCaseSupplier.intCases(rows, rows, Integer.MIN_VALUE, Integer.MAX_VALUE, true), + MultiRowTestCaseSupplier.longCases(rows, rows, Long.MIN_VALUE, Long.MAX_VALUE, true), + MultiRowTestCaseSupplier.doubleCases(rows, rows, -Double.MAX_VALUE, Double.MAX_VALUE, true), + MultiRowTestCaseSupplier.dateCases(rows, rows) + ) + .flatMap(List::stream) + .toList(); + for (var fieldCaseSupplier : fieldCaseSuppliers) { + List outputFieldCaseSuppliers = Stream.of( + MultiRowTestCaseSupplier.intCases(rows, rows, Integer.MIN_VALUE, Integer.MAX_VALUE, true), + MultiRowTestCaseSupplier.longCases(rows, rows, Long.MIN_VALUE, Long.MAX_VALUE, true), + MultiRowTestCaseSupplier.doubleCases(rows, rows, -Double.MAX_VALUE, Double.MAX_VALUE, true), + MultiRowTestCaseSupplier.dateCases(rows, rows) + ) + .flatMap(List::stream) + .toList(); + for (var outputFieldCaseSupplier : outputFieldCaseSuppliers) { + if (fieldCaseSupplier.name().equals(outputFieldCaseSupplier.name())) { + continue; + } + suppliers.add(TopTests.makeSupplier(fieldCaseSupplier, limitCaseSupplier, order, outputFieldCaseSupplier)); + } + } + } + } + suppliers.addAll( List.of( // Surrogates @@ -292,25 +326,59 @@ protected Expression build(Source source, List args) { private static TestCaseSupplier makeSupplier( TestCaseSupplier.TypedDataSupplier fieldSupplier, TestCaseSupplier.TypedDataSupplier limitCaseSupplier, - String order + String order, + TestCaseSupplier.TypedDataSupplier outputFieldSupplier ) { boolean isAscending = order == null || order.equalsIgnoreCase("asc"); - boolean noOrderSupplied = order == null; + boolean orderSupplied = order != null; + boolean outputFieldSupplied = outputFieldSupplier != null; - List dataTypes = noOrderSupplied - ? List.of(fieldSupplier.type(), DataType.INTEGER) - : List.of(fieldSupplier.type(), DataType.INTEGER, DataType.KEYWORD); + List dataTypes = new ArrayList<>(); + dataTypes.add(fieldSupplier.type()); + dataTypes.add(DataType.INTEGER); + if (orderSupplied) { + dataTypes.add(DataType.KEYWORD); + } + if (outputFieldSupplied) { + dataTypes.add(outputFieldSupplier.type()); + } + + DataType expectedType = outputFieldSupplied ? outputFieldSupplier.type() : fieldSupplier.type(); return new TestCaseSupplier(fieldSupplier.name(), dataTypes, () -> { var fieldTypedData = fieldSupplier.get(); var limitTypedData = limitCaseSupplier.get().forceLiteral(); var limit = (int) limitTypedData.getValue(); - var expected = fieldTypedData.multiRowData() - .stream() - .map(v -> (Comparable>) v) - .sorted(isAscending ? Comparator.naturalOrder() : Comparator.reverseOrder()) - .limit(limit) - .toList(); + TestCaseSupplier.TypedData outputFieldTypedData; + List expected; + if (outputFieldSupplied) { + outputFieldTypedData = outputFieldSupplier.get(); + assertThat(outputFieldTypedData.multiRowData(), hasSize(equalTo(fieldTypedData.multiRowData().size()))); + Comparator>, Comparable>>> comparator = + Map.Entry + .>, Comparable>>comparingByKey() + .thenComparing(Map.Entry::getValue); + if (isAscending == false) { + comparator = comparator.reversed(); + } + expected = IntStream.range(0, fieldTypedData.multiRowData().size()) + .mapToObj(i -> Map.>, Comparable>>entry( + (Comparable>) fieldTypedData.multiRowData().get(i), + (Comparable>) outputFieldTypedData.multiRowData().get(i)) + ) + .sorted(comparator) + .map(Map.Entry::getValue) + .limit(limit) + .toList(); + } else { + outputFieldTypedData = null; + expected = fieldTypedData.multiRowData() + .stream() + .map(v -> (Comparable>) v) + .sorted(isAscending ? Comparator.naturalOrder() : Comparator.reverseOrder()) + .limit(limit) + .toList(); + } String baseName; if (limit != 1) { @@ -324,18 +392,22 @@ private static TestCaseSupplier makeSupplier( } } - List typedData = noOrderSupplied - ? List.of(fieldTypedData, limitTypedData) - : List.of( - fieldTypedData, - limitTypedData, - new TestCaseSupplier.TypedData(new BytesRef(order), DataType.KEYWORD, order + " order").forceLiteral() - ); + List typedData = new ArrayList<>(); + typedData.add(fieldTypedData); + typedData.add(limitTypedData); + if (orderSupplied) { + typedData.add(new TestCaseSupplier.TypedData(new BytesRef(order), DataType.KEYWORD, order + " order").forceLiteral()); + } + if (outputFieldSupplied) { + typedData.add(outputFieldTypedData); + } return new TestCaseSupplier.TestCase( typedData, - standardAggregatorName(baseName, fieldTypedData.type()), - fieldSupplier.type(), + outputFieldSupplied && (fieldTypedData.name().equals(outputFieldTypedData.name()) == false) + ? standardAggregatorName(standardAggregatorName(baseName, fieldTypedData.type()), outputFieldTypedData.type()) + : standardAggregatorName(baseName, fieldTypedData.type()), + expectedType, equalTo(expected.size() == 1 ? expected.get(0) : expected) ); }); From 832852c2e4fb419ebcd8db3864e6b1db61526981 Mon Sep 17 00:00:00 2001 From: Przemyslaw Witek Date: Tue, 21 Oct 2025 09:03:07 +0200 Subject: [PATCH 07/16] Fix style with spotless --- .../function/aggregate/TopTests.java | 24 ++++++++----------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/TopTests.java b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/TopTests.java index a90d1198791e1..46538cdfe43b4 100644 --- a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/TopTests.java +++ b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/TopTests.java @@ -32,7 +32,6 @@ import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.hasSize; -import static org.hamcrest.Matchers.isA; public class TopTests extends AbstractAggregationTestCase { public TopTests(@Name("TestCase") Supplier testCaseSupplier) { @@ -69,18 +68,14 @@ public static Iterable parameters() { MultiRowTestCaseSupplier.longCases(rows, rows, Long.MIN_VALUE, Long.MAX_VALUE, true), MultiRowTestCaseSupplier.doubleCases(rows, rows, -Double.MAX_VALUE, Double.MAX_VALUE, true), MultiRowTestCaseSupplier.dateCases(rows, rows) - ) - .flatMap(List::stream) - .toList(); + ).flatMap(List::stream).toList(); for (var fieldCaseSupplier : fieldCaseSuppliers) { List outputFieldCaseSuppliers = Stream.of( MultiRowTestCaseSupplier.intCases(rows, rows, Integer.MIN_VALUE, Integer.MAX_VALUE, true), MultiRowTestCaseSupplier.longCases(rows, rows, Long.MIN_VALUE, Long.MAX_VALUE, true), MultiRowTestCaseSupplier.doubleCases(rows, rows, -Double.MAX_VALUE, Double.MAX_VALUE, true), MultiRowTestCaseSupplier.dateCases(rows, rows) - ) - .flatMap(List::stream) - .toList(); + ).flatMap(List::stream).toList(); for (var outputFieldCaseSupplier : outputFieldCaseSuppliers) { if (fieldCaseSupplier.name().equals(outputFieldCaseSupplier.name())) { continue; @@ -354,17 +349,18 @@ private static TestCaseSupplier makeSupplier( if (outputFieldSupplied) { outputFieldTypedData = outputFieldSupplier.get(); assertThat(outputFieldTypedData.multiRowData(), hasSize(equalTo(fieldTypedData.multiRowData().size()))); - Comparator>, Comparable>>> comparator = - Map.Entry - .>, Comparable>>comparingByKey() - .thenComparing(Map.Entry::getValue); + Comparator>, Comparable>>> comparator = Map.Entry.< + Comparable>, + Comparable>>comparingByKey().thenComparing(Map.Entry::getValue); if (isAscending == false) { comparator = comparator.reversed(); } expected = IntStream.range(0, fieldTypedData.multiRowData().size()) - .mapToObj(i -> Map.>, Comparable>>entry( - (Comparable>) fieldTypedData.multiRowData().get(i), - (Comparable>) outputFieldTypedData.multiRowData().get(i)) + .mapToObj( + i -> Map.>, Comparable>>entry( + (Comparable>) fieldTypedData.multiRowData().get(i), + (Comparable>) outputFieldTypedData.multiRowData().get(i) + ) ) .sorted(comparator) .map(Map.Entry::getValue) From a097f81ba769fbea638bbcfa42fe6aaab7799864 Mon Sep 17 00:00:00 2001 From: Przemyslaw Witek Date: Tue, 21 Oct 2025 10:12:21 +0200 Subject: [PATCH 08/16] Fix TOP's type resolution and add appropriate tests --- .../esql/core/expression/TypeResolutions.java | 17 +++- .../expression/function/aggregate/Top.java | 19 ++++- .../function/aggregate/TopTests.java | 78 +++++++++++++++++++ 3 files changed, 109 insertions(+), 5 deletions(-) diff --git a/x-pack/plugin/esql-core/src/main/java/org/elasticsearch/xpack/esql/core/expression/TypeResolutions.java b/x-pack/plugin/esql-core/src/main/java/org/elasticsearch/xpack/esql/core/expression/TypeResolutions.java index b5e630cefcfee..1b723e536602d 100644 --- a/x-pack/plugin/esql-core/src/main/java/org/elasticsearch/xpack/esql/core/expression/TypeResolutions.java +++ b/x-pack/plugin/esql-core/src/main/java/org/elasticsearch/xpack/esql/core/expression/TypeResolutions.java @@ -212,6 +212,18 @@ public static TypeResolution isType( ParamOrdinal paramOrd, boolean allowUnionTypes, String... acceptedTypes + ) { + return isType(e, predicate, null, operationName, paramOrd, allowUnionTypes, acceptedTypes); + } + + public static TypeResolution isType( + Expression e, + Predicate predicate, + String errorMessagePrefix, + String operationName, + ParamOrdinal paramOrd, + boolean allowUnionTypes, + String... acceptedTypes ) { if (predicate.test(e.dataType()) || e.dataType() == NULL) { return TypeResolution.TYPE_RESOLVED; @@ -226,11 +238,12 @@ public static TypeResolution isType( } return new TypeResolution( - errorStringIncompatibleTypes(operationName, paramOrd, name(e), e.dataType(), acceptedTypesForErrorMsg(acceptedTypes)) + errorStringIncompatibleTypes(errorMessagePrefix, operationName, paramOrd, name(e), e.dataType(), acceptedTypesForErrorMsg(acceptedTypes)) ); } private static String errorStringIncompatibleTypes( + String errorMessagePrefix, String operationName, ParamOrdinal paramOrd, String argumentName, @@ -238,7 +251,7 @@ private static String errorStringIncompatibleTypes( String... acceptedTypes ) { return format( - null, + errorMessagePrefix, "{}argument of [{}] must be [{}], found value [{}] type [{}]", paramOrd == null || paramOrd == DEFAULT ? "" : paramOrd.name().toLowerCase(Locale.ROOT) + " ", operationName, diff --git a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/aggregate/Top.java b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/aggregate/Top.java index 062a98aa17d64..aab0d4287d980 100644 --- a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/aggregate/Top.java +++ b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/aggregate/Top.java @@ -62,6 +62,7 @@ import static org.elasticsearch.common.logging.LoggerMessageFormat.format; import static org.elasticsearch.xpack.esql.common.Failure.fail; import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.ParamOrdinal.FIRST; +import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.ParamOrdinal.FOURTH; import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.ParamOrdinal.SECOND; import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.ParamOrdinal.THIRD; import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.isNotNull; @@ -181,16 +182,28 @@ protected TypeResolution resolveType() { .and(isNotNull(orderField(), sourceText(), THIRD)) .and(isString(orderField(), sourceText(), THIRD)); if (outputField() != null) { - typeResolution.and( + typeResolution = typeResolution.and( isType( outputField(), dt -> dt == DataType.DATETIME || (dt.isNumeric() && dt != DataType.UNSIGNED_LONG), sourceText(), - FIRST, + FOURTH, "date", "numeric except unsigned_long or counter types" ) - ); + ) + .and( + isType( + field(), + dt -> dt == DataType.DATETIME || (dt.isNumeric() && dt != DataType.UNSIGNED_LONG), + "when fourth argument is set, ", + sourceText(), + FIRST, + false, + "date", + "numeric except unsigned_long or counter types" + ) + ); } if (typeResolution.unresolved()) { diff --git a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/TopTests.java b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/TopTests.java index 46538cdfe43b4..d81987499536e 100644 --- a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/TopTests.java +++ b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/TopTests.java @@ -305,6 +305,84 @@ public static Iterable parameters() { ), "Invalid order value in [source], expected [ASC, DESC] but got [null]" ) + ), + new TestCaseSupplier( + List.of(DataType.LONG, DataType.INTEGER, DataType.KEYWORD, DataType.BOOLEAN), + () -> TestCaseSupplier.TestCase.typeError( + List.of( + TestCaseSupplier.TypedData.multiRow(List.of(1L, 2L), DataType.LONG, "field"), + new TestCaseSupplier.TypedData(1, DataType.INTEGER, "limit").forceLiteral(), + new TestCaseSupplier.TypedData("asc", DataType.KEYWORD, "order").forceLiteral(), + TestCaseSupplier.TypedData.multiRow(List.of(true, false), DataType.BOOLEAN, "outputField") + ), + "fourth argument of [source] must be [date or numeric except unsigned_long or counter types], " + + "found value [outputField] type [boolean]" + ) + ), + new TestCaseSupplier( + List.of(DataType.LONG, DataType.INTEGER, DataType.KEYWORD, DataType.KEYWORD), + () -> TestCaseSupplier.TestCase.typeError( + List.of( + TestCaseSupplier.TypedData.multiRow(List.of(1L, 2L), DataType.LONG, "field"), + new TestCaseSupplier.TypedData(1, DataType.INTEGER, "limit").forceLiteral(), + new TestCaseSupplier.TypedData("asc", DataType.KEYWORD, "order").forceLiteral(), + TestCaseSupplier.TypedData.multiRow(List.of("a", "b"), DataType.KEYWORD, "outputField") + ), + "fourth argument of [source] must be [date or numeric except unsigned_long or counter types], " + + "found value [outputField] type [keyword]" + ) + ), + new TestCaseSupplier( + List.of(DataType.LONG, DataType.INTEGER, DataType.KEYWORD, DataType.IP), + () -> TestCaseSupplier.TestCase.typeError( + List.of( + TestCaseSupplier.TypedData.multiRow(List.of(1L, 2L), DataType.LONG, "field"), + new TestCaseSupplier.TypedData(1, DataType.INTEGER, "limit").forceLiteral(), + new TestCaseSupplier.TypedData("asc", DataType.KEYWORD, "order").forceLiteral(), + TestCaseSupplier.TypedData.multiRow(List.of("192.168.0.1", "192.168.0.2"), DataType.IP, "outputField") + ), + "fourth argument of [source] must be [date or numeric except unsigned_long or counter types], " + + "found value [outputField] type [ip]" + ) + ), + new TestCaseSupplier( + List.of(DataType.BOOLEAN, DataType.INTEGER, DataType.KEYWORD, DataType.LONG), + () -> TestCaseSupplier.TestCase.typeError( + List.of( + TestCaseSupplier.TypedData.multiRow(List.of(true, false), DataType.BOOLEAN, "field"), + new TestCaseSupplier.TypedData(1, DataType.INTEGER, "limit").forceLiteral(), + new TestCaseSupplier.TypedData("asc", DataType.KEYWORD, "order").forceLiteral(), + TestCaseSupplier.TypedData.multiRow(List.of(1L, 2L), DataType.LONG, "outputField") + ), + "when fourth argument is set, first argument of [source] must be " + + "[date or numeric except unsigned_long or counter types], found value [field] type [boolean]" + ) + ), + new TestCaseSupplier( + List.of(DataType.KEYWORD, DataType.INTEGER, DataType.KEYWORD, DataType.LONG), + () -> TestCaseSupplier.TestCase.typeError( + List.of( + TestCaseSupplier.TypedData.multiRow(List.of("a", "b"), DataType.KEYWORD, "field"), + new TestCaseSupplier.TypedData(1, DataType.INTEGER, "limit").forceLiteral(), + new TestCaseSupplier.TypedData("asc", DataType.KEYWORD, "order").forceLiteral(), + TestCaseSupplier.TypedData.multiRow(List.of(1L, 2L), DataType.LONG, "outputField") + ), + "when fourth argument is set, first argument of [source] must be " + + "[date or numeric except unsigned_long or counter types], found value [field] type [keyword]" + ) + ), + new TestCaseSupplier( + List.of(DataType.IP, DataType.INTEGER, DataType.KEYWORD, DataType.LONG), + () -> TestCaseSupplier.TestCase.typeError( + List.of( + TestCaseSupplier.TypedData.multiRow(List.of("192.168.0.1", "192.168.0.2"), DataType.IP, "field"), + new TestCaseSupplier.TypedData(1, DataType.INTEGER, "limit").forceLiteral(), + new TestCaseSupplier.TypedData("asc", DataType.KEYWORD, "order").forceLiteral(), + TestCaseSupplier.TypedData.multiRow(List.of(1L, 2L), DataType.LONG, "outputField") + ), + "when fourth argument is set, first argument of [source] must be " + + "[date or numeric except unsigned_long or counter types], found value [field] type [ip]" + ) ) ) ); From 83ab3bb0414daaf3978ff37f92b1a5b6dd5ca489 Mon Sep 17 00:00:00 2001 From: Przemyslaw Witek Date: Tue, 21 Oct 2025 10:12:48 +0200 Subject: [PATCH 09/16] Regenerate TopXYAggregatorFunction classes. --- .../TopDoubleDoubleAggregatorFunction.java | 20 +++++++++++-------- .../TopDoubleFloatAggregatorFunction.java | 20 +++++++++++-------- .../TopDoubleIntAggregatorFunction.java | 20 +++++++++++-------- .../TopDoubleLongAggregatorFunction.java | 20 +++++++++++-------- .../TopFloatDoubleAggregatorFunction.java | 20 +++++++++++-------- .../TopFloatFloatAggregatorFunction.java | 20 +++++++++++-------- .../TopFloatIntAggregatorFunction.java | 20 +++++++++++-------- .../TopFloatLongAggregatorFunction.java | 20 +++++++++++-------- .../TopIntDoubleAggregatorFunction.java | 20 +++++++++++-------- .../TopIntFloatAggregatorFunction.java | 20 +++++++++++-------- .../TopIntIntAggregatorFunction.java | 20 +++++++++++-------- .../TopIntLongAggregatorFunction.java | 20 +++++++++++-------- .../TopLongDoubleAggregatorFunction.java | 20 +++++++++++-------- .../TopLongFloatAggregatorFunction.java | 20 +++++++++++-------- .../TopLongIntAggregatorFunction.java | 20 +++++++++++-------- .../TopLongLongAggregatorFunction.java | 20 +++++++++++-------- 16 files changed, 192 insertions(+), 128 deletions(-) diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleDoubleAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleDoubleAggregatorFunction.java index b48d510380f19..111f7ce2d3a6b 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleDoubleAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleDoubleAggregatorFunction.java @@ -124,18 +124,20 @@ private void addRawVector(DoubleVector vVector, DoubleVector outputValueVector, private void addRawBlock(DoubleBlock vBlock, DoubleBlock outputValueBlock) { for (int p = 0; p < vBlock.getPositionCount(); p++) { - if (vBlock.isNull(p)) { + int vValueCount = vBlock.getValueCount(p); + if (vValueCount == 0) { continue; } - if (outputValueBlock.isNull(p)) { + int outputValueValueCount = outputValueBlock.getValueCount(p); + if (outputValueValueCount == 0) { continue; } int vStart = vBlock.getFirstValueIndex(p); - int vEnd = vStart + vBlock.getValueCount(p); + int vEnd = vStart + vValueCount; for (int vOffset = vStart; vOffset < vEnd; vOffset++) { double vValue = vBlock.getDouble(vOffset); int outputValueStart = outputValueBlock.getFirstValueIndex(p); - int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(p); + int outputValueEnd = outputValueStart + outputValueValueCount; for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { double outputValueValue = outputValueBlock.getDouble(outputValueOffset); TopDoubleDoubleAggregator.combine(state, vValue, outputValueValue); @@ -149,18 +151,20 @@ private void addRawBlock(DoubleBlock vBlock, DoubleBlock outputValueBlock, Boole if (mask.getBoolean(p) == false) { continue; } - if (vBlock.isNull(p)) { + int vValueCount = vBlock.getValueCount(p); + if (vValueCount == 0) { continue; } - if (outputValueBlock.isNull(p)) { + int outputValueValueCount = outputValueBlock.getValueCount(p); + if (outputValueValueCount == 0) { continue; } int vStart = vBlock.getFirstValueIndex(p); - int vEnd = vStart + vBlock.getValueCount(p); + int vEnd = vStart + vValueCount; for (int vOffset = vStart; vOffset < vEnd; vOffset++) { double vValue = vBlock.getDouble(vOffset); int outputValueStart = outputValueBlock.getFirstValueIndex(p); - int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(p); + int outputValueEnd = outputValueStart + outputValueValueCount; for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { double outputValueValue = outputValueBlock.getDouble(outputValueOffset); TopDoubleDoubleAggregator.combine(state, vValue, outputValueValue); diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleFloatAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleFloatAggregatorFunction.java index 40d426edd77c3..a1c451e229c8c 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleFloatAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleFloatAggregatorFunction.java @@ -126,18 +126,20 @@ private void addRawVector(DoubleVector vVector, FloatVector outputValueVector, private void addRawBlock(DoubleBlock vBlock, FloatBlock outputValueBlock) { for (int p = 0; p < vBlock.getPositionCount(); p++) { - if (vBlock.isNull(p)) { + int vValueCount = vBlock.getValueCount(p); + if (vValueCount == 0) { continue; } - if (outputValueBlock.isNull(p)) { + int outputValueValueCount = outputValueBlock.getValueCount(p); + if (outputValueValueCount == 0) { continue; } int vStart = vBlock.getFirstValueIndex(p); - int vEnd = vStart + vBlock.getValueCount(p); + int vEnd = vStart + vValueCount; for (int vOffset = vStart; vOffset < vEnd; vOffset++) { double vValue = vBlock.getDouble(vOffset); int outputValueStart = outputValueBlock.getFirstValueIndex(p); - int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(p); + int outputValueEnd = outputValueStart + outputValueValueCount; for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { float outputValueValue = outputValueBlock.getFloat(outputValueOffset); TopDoubleFloatAggregator.combine(state, vValue, outputValueValue); @@ -151,18 +153,20 @@ private void addRawBlock(DoubleBlock vBlock, FloatBlock outputValueBlock, Boolea if (mask.getBoolean(p) == false) { continue; } - if (vBlock.isNull(p)) { + int vValueCount = vBlock.getValueCount(p); + if (vValueCount == 0) { continue; } - if (outputValueBlock.isNull(p)) { + int outputValueValueCount = outputValueBlock.getValueCount(p); + if (outputValueValueCount == 0) { continue; } int vStart = vBlock.getFirstValueIndex(p); - int vEnd = vStart + vBlock.getValueCount(p); + int vEnd = vStart + vValueCount; for (int vOffset = vStart; vOffset < vEnd; vOffset++) { double vValue = vBlock.getDouble(vOffset); int outputValueStart = outputValueBlock.getFirstValueIndex(p); - int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(p); + int outputValueEnd = outputValueStart + outputValueValueCount; for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { float outputValueValue = outputValueBlock.getFloat(outputValueOffset); TopDoubleFloatAggregator.combine(state, vValue, outputValueValue); diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleIntAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleIntAggregatorFunction.java index c71351faea869..bf2a4eb912b82 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleIntAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleIntAggregatorFunction.java @@ -125,18 +125,20 @@ private void addRawVector(DoubleVector vVector, IntVector outputValueVector, Boo private void addRawBlock(DoubleBlock vBlock, IntBlock outputValueBlock) { for (int p = 0; p < vBlock.getPositionCount(); p++) { - if (vBlock.isNull(p)) { + int vValueCount = vBlock.getValueCount(p); + if (vValueCount == 0) { continue; } - if (outputValueBlock.isNull(p)) { + int outputValueValueCount = outputValueBlock.getValueCount(p); + if (outputValueValueCount == 0) { continue; } int vStart = vBlock.getFirstValueIndex(p); - int vEnd = vStart + vBlock.getValueCount(p); + int vEnd = vStart + vValueCount; for (int vOffset = vStart; vOffset < vEnd; vOffset++) { double vValue = vBlock.getDouble(vOffset); int outputValueStart = outputValueBlock.getFirstValueIndex(p); - int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(p); + int outputValueEnd = outputValueStart + outputValueValueCount; for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { int outputValueValue = outputValueBlock.getInt(outputValueOffset); TopDoubleIntAggregator.combine(state, vValue, outputValueValue); @@ -150,18 +152,20 @@ private void addRawBlock(DoubleBlock vBlock, IntBlock outputValueBlock, BooleanV if (mask.getBoolean(p) == false) { continue; } - if (vBlock.isNull(p)) { + int vValueCount = vBlock.getValueCount(p); + if (vValueCount == 0) { continue; } - if (outputValueBlock.isNull(p)) { + int outputValueValueCount = outputValueBlock.getValueCount(p); + if (outputValueValueCount == 0) { continue; } int vStart = vBlock.getFirstValueIndex(p); - int vEnd = vStart + vBlock.getValueCount(p); + int vEnd = vStart + vValueCount; for (int vOffset = vStart; vOffset < vEnd; vOffset++) { double vValue = vBlock.getDouble(vOffset); int outputValueStart = outputValueBlock.getFirstValueIndex(p); - int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(p); + int outputValueEnd = outputValueStart + outputValueValueCount; for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { int outputValueValue = outputValueBlock.getInt(outputValueOffset); TopDoubleIntAggregator.combine(state, vValue, outputValueValue); diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleLongAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleLongAggregatorFunction.java index 3505e75ce3663..9951bd7dd5c2b 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleLongAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleLongAggregatorFunction.java @@ -126,18 +126,20 @@ private void addRawVector(DoubleVector vVector, LongVector outputValueVector, private void addRawBlock(DoubleBlock vBlock, LongBlock outputValueBlock) { for (int p = 0; p < vBlock.getPositionCount(); p++) { - if (vBlock.isNull(p)) { + int vValueCount = vBlock.getValueCount(p); + if (vValueCount == 0) { continue; } - if (outputValueBlock.isNull(p)) { + int outputValueValueCount = outputValueBlock.getValueCount(p); + if (outputValueValueCount == 0) { continue; } int vStart = vBlock.getFirstValueIndex(p); - int vEnd = vStart + vBlock.getValueCount(p); + int vEnd = vStart + vValueCount; for (int vOffset = vStart; vOffset < vEnd; vOffset++) { double vValue = vBlock.getDouble(vOffset); int outputValueStart = outputValueBlock.getFirstValueIndex(p); - int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(p); + int outputValueEnd = outputValueStart + outputValueValueCount; for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { long outputValueValue = outputValueBlock.getLong(outputValueOffset); TopDoubleLongAggregator.combine(state, vValue, outputValueValue); @@ -151,18 +153,20 @@ private void addRawBlock(DoubleBlock vBlock, LongBlock outputValueBlock, Boolean if (mask.getBoolean(p) == false) { continue; } - if (vBlock.isNull(p)) { + int vValueCount = vBlock.getValueCount(p); + if (vValueCount == 0) { continue; } - if (outputValueBlock.isNull(p)) { + int outputValueValueCount = outputValueBlock.getValueCount(p); + if (outputValueValueCount == 0) { continue; } int vStart = vBlock.getFirstValueIndex(p); - int vEnd = vStart + vBlock.getValueCount(p); + int vEnd = vStart + vValueCount; for (int vOffset = vStart; vOffset < vEnd; vOffset++) { double vValue = vBlock.getDouble(vOffset); int outputValueStart = outputValueBlock.getFirstValueIndex(p); - int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(p); + int outputValueEnd = outputValueStart + outputValueValueCount; for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { long outputValueValue = outputValueBlock.getLong(outputValueOffset); TopDoubleLongAggregator.combine(state, vValue, outputValueValue); diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatDoubleAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatDoubleAggregatorFunction.java index 4f918eb079b72..3fc172d2a2dfe 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatDoubleAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatDoubleAggregatorFunction.java @@ -126,18 +126,20 @@ private void addRawVector(FloatVector vVector, DoubleVector outputValueVector, private void addRawBlock(FloatBlock vBlock, DoubleBlock outputValueBlock) { for (int p = 0; p < vBlock.getPositionCount(); p++) { - if (vBlock.isNull(p)) { + int vValueCount = vBlock.getValueCount(p); + if (vValueCount == 0) { continue; } - if (outputValueBlock.isNull(p)) { + int outputValueValueCount = outputValueBlock.getValueCount(p); + if (outputValueValueCount == 0) { continue; } int vStart = vBlock.getFirstValueIndex(p); - int vEnd = vStart + vBlock.getValueCount(p); + int vEnd = vStart + vValueCount; for (int vOffset = vStart; vOffset < vEnd; vOffset++) { float vValue = vBlock.getFloat(vOffset); int outputValueStart = outputValueBlock.getFirstValueIndex(p); - int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(p); + int outputValueEnd = outputValueStart + outputValueValueCount; for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { double outputValueValue = outputValueBlock.getDouble(outputValueOffset); TopFloatDoubleAggregator.combine(state, vValue, outputValueValue); @@ -151,18 +153,20 @@ private void addRawBlock(FloatBlock vBlock, DoubleBlock outputValueBlock, Boolea if (mask.getBoolean(p) == false) { continue; } - if (vBlock.isNull(p)) { + int vValueCount = vBlock.getValueCount(p); + if (vValueCount == 0) { continue; } - if (outputValueBlock.isNull(p)) { + int outputValueValueCount = outputValueBlock.getValueCount(p); + if (outputValueValueCount == 0) { continue; } int vStart = vBlock.getFirstValueIndex(p); - int vEnd = vStart + vBlock.getValueCount(p); + int vEnd = vStart + vValueCount; for (int vOffset = vStart; vOffset < vEnd; vOffset++) { float vValue = vBlock.getFloat(vOffset); int outputValueStart = outputValueBlock.getFirstValueIndex(p); - int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(p); + int outputValueEnd = outputValueStart + outputValueValueCount; for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { double outputValueValue = outputValueBlock.getDouble(outputValueOffset); TopFloatDoubleAggregator.combine(state, vValue, outputValueValue); diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatFloatAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatFloatAggregatorFunction.java index 7f314a111a055..7a59c9060c727 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatFloatAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatFloatAggregatorFunction.java @@ -124,18 +124,20 @@ private void addRawVector(FloatVector vVector, FloatVector outputValueVector, private void addRawBlock(FloatBlock vBlock, FloatBlock outputValueBlock) { for (int p = 0; p < vBlock.getPositionCount(); p++) { - if (vBlock.isNull(p)) { + int vValueCount = vBlock.getValueCount(p); + if (vValueCount == 0) { continue; } - if (outputValueBlock.isNull(p)) { + int outputValueValueCount = outputValueBlock.getValueCount(p); + if (outputValueValueCount == 0) { continue; } int vStart = vBlock.getFirstValueIndex(p); - int vEnd = vStart + vBlock.getValueCount(p); + int vEnd = vStart + vValueCount; for (int vOffset = vStart; vOffset < vEnd; vOffset++) { float vValue = vBlock.getFloat(vOffset); int outputValueStart = outputValueBlock.getFirstValueIndex(p); - int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(p); + int outputValueEnd = outputValueStart + outputValueValueCount; for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { float outputValueValue = outputValueBlock.getFloat(outputValueOffset); TopFloatFloatAggregator.combine(state, vValue, outputValueValue); @@ -149,18 +151,20 @@ private void addRawBlock(FloatBlock vBlock, FloatBlock outputValueBlock, Boolean if (mask.getBoolean(p) == false) { continue; } - if (vBlock.isNull(p)) { + int vValueCount = vBlock.getValueCount(p); + if (vValueCount == 0) { continue; } - if (outputValueBlock.isNull(p)) { + int outputValueValueCount = outputValueBlock.getValueCount(p); + if (outputValueValueCount == 0) { continue; } int vStart = vBlock.getFirstValueIndex(p); - int vEnd = vStart + vBlock.getValueCount(p); + int vEnd = vStart + vValueCount; for (int vOffset = vStart; vOffset < vEnd; vOffset++) { float vValue = vBlock.getFloat(vOffset); int outputValueStart = outputValueBlock.getFirstValueIndex(p); - int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(p); + int outputValueEnd = outputValueStart + outputValueValueCount; for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { float outputValueValue = outputValueBlock.getFloat(outputValueOffset); TopFloatFloatAggregator.combine(state, vValue, outputValueValue); diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatIntAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatIntAggregatorFunction.java index b3a4cee6d2b1c..3b190c8a069ce 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatIntAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatIntAggregatorFunction.java @@ -125,18 +125,20 @@ private void addRawVector(FloatVector vVector, IntVector outputValueVector, Bool private void addRawBlock(FloatBlock vBlock, IntBlock outputValueBlock) { for (int p = 0; p < vBlock.getPositionCount(); p++) { - if (vBlock.isNull(p)) { + int vValueCount = vBlock.getValueCount(p); + if (vValueCount == 0) { continue; } - if (outputValueBlock.isNull(p)) { + int outputValueValueCount = outputValueBlock.getValueCount(p); + if (outputValueValueCount == 0) { continue; } int vStart = vBlock.getFirstValueIndex(p); - int vEnd = vStart + vBlock.getValueCount(p); + int vEnd = vStart + vValueCount; for (int vOffset = vStart; vOffset < vEnd; vOffset++) { float vValue = vBlock.getFloat(vOffset); int outputValueStart = outputValueBlock.getFirstValueIndex(p); - int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(p); + int outputValueEnd = outputValueStart + outputValueValueCount; for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { int outputValueValue = outputValueBlock.getInt(outputValueOffset); TopFloatIntAggregator.combine(state, vValue, outputValueValue); @@ -150,18 +152,20 @@ private void addRawBlock(FloatBlock vBlock, IntBlock outputValueBlock, BooleanVe if (mask.getBoolean(p) == false) { continue; } - if (vBlock.isNull(p)) { + int vValueCount = vBlock.getValueCount(p); + if (vValueCount == 0) { continue; } - if (outputValueBlock.isNull(p)) { + int outputValueValueCount = outputValueBlock.getValueCount(p); + if (outputValueValueCount == 0) { continue; } int vStart = vBlock.getFirstValueIndex(p); - int vEnd = vStart + vBlock.getValueCount(p); + int vEnd = vStart + vValueCount; for (int vOffset = vStart; vOffset < vEnd; vOffset++) { float vValue = vBlock.getFloat(vOffset); int outputValueStart = outputValueBlock.getFirstValueIndex(p); - int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(p); + int outputValueEnd = outputValueStart + outputValueValueCount; for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { int outputValueValue = outputValueBlock.getInt(outputValueOffset); TopFloatIntAggregator.combine(state, vValue, outputValueValue); diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatLongAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatLongAggregatorFunction.java index e06e81b086bca..39006ef2ad955 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatLongAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatLongAggregatorFunction.java @@ -125,18 +125,20 @@ private void addRawVector(FloatVector vVector, LongVector outputValueVector, Boo private void addRawBlock(FloatBlock vBlock, LongBlock outputValueBlock) { for (int p = 0; p < vBlock.getPositionCount(); p++) { - if (vBlock.isNull(p)) { + int vValueCount = vBlock.getValueCount(p); + if (vValueCount == 0) { continue; } - if (outputValueBlock.isNull(p)) { + int outputValueValueCount = outputValueBlock.getValueCount(p); + if (outputValueValueCount == 0) { continue; } int vStart = vBlock.getFirstValueIndex(p); - int vEnd = vStart + vBlock.getValueCount(p); + int vEnd = vStart + vValueCount; for (int vOffset = vStart; vOffset < vEnd; vOffset++) { float vValue = vBlock.getFloat(vOffset); int outputValueStart = outputValueBlock.getFirstValueIndex(p); - int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(p); + int outputValueEnd = outputValueStart + outputValueValueCount; for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { long outputValueValue = outputValueBlock.getLong(outputValueOffset); TopFloatLongAggregator.combine(state, vValue, outputValueValue); @@ -150,18 +152,20 @@ private void addRawBlock(FloatBlock vBlock, LongBlock outputValueBlock, BooleanV if (mask.getBoolean(p) == false) { continue; } - if (vBlock.isNull(p)) { + int vValueCount = vBlock.getValueCount(p); + if (vValueCount == 0) { continue; } - if (outputValueBlock.isNull(p)) { + int outputValueValueCount = outputValueBlock.getValueCount(p); + if (outputValueValueCount == 0) { continue; } int vStart = vBlock.getFirstValueIndex(p); - int vEnd = vStart + vBlock.getValueCount(p); + int vEnd = vStart + vValueCount; for (int vOffset = vStart; vOffset < vEnd; vOffset++) { float vValue = vBlock.getFloat(vOffset); int outputValueStart = outputValueBlock.getFirstValueIndex(p); - int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(p); + int outputValueEnd = outputValueStart + outputValueValueCount; for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { long outputValueValue = outputValueBlock.getLong(outputValueOffset); TopFloatLongAggregator.combine(state, vValue, outputValueValue); diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntDoubleAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntDoubleAggregatorFunction.java index 34d497c44dbb1..4f661b865cb9c 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntDoubleAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntDoubleAggregatorFunction.java @@ -125,18 +125,20 @@ private void addRawVector(IntVector vVector, DoubleVector outputValueVector, Boo private void addRawBlock(IntBlock vBlock, DoubleBlock outputValueBlock) { for (int p = 0; p < vBlock.getPositionCount(); p++) { - if (vBlock.isNull(p)) { + int vValueCount = vBlock.getValueCount(p); + if (vValueCount == 0) { continue; } - if (outputValueBlock.isNull(p)) { + int outputValueValueCount = outputValueBlock.getValueCount(p); + if (outputValueValueCount == 0) { continue; } int vStart = vBlock.getFirstValueIndex(p); - int vEnd = vStart + vBlock.getValueCount(p); + int vEnd = vStart + vValueCount; for (int vOffset = vStart; vOffset < vEnd; vOffset++) { int vValue = vBlock.getInt(vOffset); int outputValueStart = outputValueBlock.getFirstValueIndex(p); - int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(p); + int outputValueEnd = outputValueStart + outputValueValueCount; for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { double outputValueValue = outputValueBlock.getDouble(outputValueOffset); TopIntDoubleAggregator.combine(state, vValue, outputValueValue); @@ -150,18 +152,20 @@ private void addRawBlock(IntBlock vBlock, DoubleBlock outputValueBlock, BooleanV if (mask.getBoolean(p) == false) { continue; } - if (vBlock.isNull(p)) { + int vValueCount = vBlock.getValueCount(p); + if (vValueCount == 0) { continue; } - if (outputValueBlock.isNull(p)) { + int outputValueValueCount = outputValueBlock.getValueCount(p); + if (outputValueValueCount == 0) { continue; } int vStart = vBlock.getFirstValueIndex(p); - int vEnd = vStart + vBlock.getValueCount(p); + int vEnd = vStart + vValueCount; for (int vOffset = vStart; vOffset < vEnd; vOffset++) { int vValue = vBlock.getInt(vOffset); int outputValueStart = outputValueBlock.getFirstValueIndex(p); - int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(p); + int outputValueEnd = outputValueStart + outputValueValueCount; for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { double outputValueValue = outputValueBlock.getDouble(outputValueOffset); TopIntDoubleAggregator.combine(state, vValue, outputValueValue); diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntFloatAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntFloatAggregatorFunction.java index eaa73dcca6b18..8f39a47ed99a7 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntFloatAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntFloatAggregatorFunction.java @@ -125,18 +125,20 @@ private void addRawVector(IntVector vVector, FloatVector outputValueVector, Bool private void addRawBlock(IntBlock vBlock, FloatBlock outputValueBlock) { for (int p = 0; p < vBlock.getPositionCount(); p++) { - if (vBlock.isNull(p)) { + int vValueCount = vBlock.getValueCount(p); + if (vValueCount == 0) { continue; } - if (outputValueBlock.isNull(p)) { + int outputValueValueCount = outputValueBlock.getValueCount(p); + if (outputValueValueCount == 0) { continue; } int vStart = vBlock.getFirstValueIndex(p); - int vEnd = vStart + vBlock.getValueCount(p); + int vEnd = vStart + vValueCount; for (int vOffset = vStart; vOffset < vEnd; vOffset++) { int vValue = vBlock.getInt(vOffset); int outputValueStart = outputValueBlock.getFirstValueIndex(p); - int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(p); + int outputValueEnd = outputValueStart + outputValueValueCount; for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { float outputValueValue = outputValueBlock.getFloat(outputValueOffset); TopIntFloatAggregator.combine(state, vValue, outputValueValue); @@ -150,18 +152,20 @@ private void addRawBlock(IntBlock vBlock, FloatBlock outputValueBlock, BooleanVe if (mask.getBoolean(p) == false) { continue; } - if (vBlock.isNull(p)) { + int vValueCount = vBlock.getValueCount(p); + if (vValueCount == 0) { continue; } - if (outputValueBlock.isNull(p)) { + int outputValueValueCount = outputValueBlock.getValueCount(p); + if (outputValueValueCount == 0) { continue; } int vStart = vBlock.getFirstValueIndex(p); - int vEnd = vStart + vBlock.getValueCount(p); + int vEnd = vStart + vValueCount; for (int vOffset = vStart; vOffset < vEnd; vOffset++) { int vValue = vBlock.getInt(vOffset); int outputValueStart = outputValueBlock.getFirstValueIndex(p); - int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(p); + int outputValueEnd = outputValueStart + outputValueValueCount; for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { float outputValueValue = outputValueBlock.getFloat(outputValueOffset); TopIntFloatAggregator.combine(state, vValue, outputValueValue); diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntIntAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntIntAggregatorFunction.java index e197c7952d783..8c9f4ed629f0f 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntIntAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntIntAggregatorFunction.java @@ -123,18 +123,20 @@ private void addRawVector(IntVector vVector, IntVector outputValueVector, Boolea private void addRawBlock(IntBlock vBlock, IntBlock outputValueBlock) { for (int p = 0; p < vBlock.getPositionCount(); p++) { - if (vBlock.isNull(p)) { + int vValueCount = vBlock.getValueCount(p); + if (vValueCount == 0) { continue; } - if (outputValueBlock.isNull(p)) { + int outputValueValueCount = outputValueBlock.getValueCount(p); + if (outputValueValueCount == 0) { continue; } int vStart = vBlock.getFirstValueIndex(p); - int vEnd = vStart + vBlock.getValueCount(p); + int vEnd = vStart + vValueCount; for (int vOffset = vStart; vOffset < vEnd; vOffset++) { int vValue = vBlock.getInt(vOffset); int outputValueStart = outputValueBlock.getFirstValueIndex(p); - int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(p); + int outputValueEnd = outputValueStart + outputValueValueCount; for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { int outputValueValue = outputValueBlock.getInt(outputValueOffset); TopIntIntAggregator.combine(state, vValue, outputValueValue); @@ -148,18 +150,20 @@ private void addRawBlock(IntBlock vBlock, IntBlock outputValueBlock, BooleanVect if (mask.getBoolean(p) == false) { continue; } - if (vBlock.isNull(p)) { + int vValueCount = vBlock.getValueCount(p); + if (vValueCount == 0) { continue; } - if (outputValueBlock.isNull(p)) { + int outputValueValueCount = outputValueBlock.getValueCount(p); + if (outputValueValueCount == 0) { continue; } int vStart = vBlock.getFirstValueIndex(p); - int vEnd = vStart + vBlock.getValueCount(p); + int vEnd = vStart + vValueCount; for (int vOffset = vStart; vOffset < vEnd; vOffset++) { int vValue = vBlock.getInt(vOffset); int outputValueStart = outputValueBlock.getFirstValueIndex(p); - int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(p); + int outputValueEnd = outputValueStart + outputValueValueCount; for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { int outputValueValue = outputValueBlock.getInt(outputValueOffset); TopIntIntAggregator.combine(state, vValue, outputValueValue); diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntLongAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntLongAggregatorFunction.java index 089c3f17f5571..9b44f260e3517 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntLongAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntLongAggregatorFunction.java @@ -125,18 +125,20 @@ private void addRawVector(IntVector vVector, LongVector outputValueVector, Boole private void addRawBlock(IntBlock vBlock, LongBlock outputValueBlock) { for (int p = 0; p < vBlock.getPositionCount(); p++) { - if (vBlock.isNull(p)) { + int vValueCount = vBlock.getValueCount(p); + if (vValueCount == 0) { continue; } - if (outputValueBlock.isNull(p)) { + int outputValueValueCount = outputValueBlock.getValueCount(p); + if (outputValueValueCount == 0) { continue; } int vStart = vBlock.getFirstValueIndex(p); - int vEnd = vStart + vBlock.getValueCount(p); + int vEnd = vStart + vValueCount; for (int vOffset = vStart; vOffset < vEnd; vOffset++) { int vValue = vBlock.getInt(vOffset); int outputValueStart = outputValueBlock.getFirstValueIndex(p); - int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(p); + int outputValueEnd = outputValueStart + outputValueValueCount; for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { long outputValueValue = outputValueBlock.getLong(outputValueOffset); TopIntLongAggregator.combine(state, vValue, outputValueValue); @@ -150,18 +152,20 @@ private void addRawBlock(IntBlock vBlock, LongBlock outputValueBlock, BooleanVec if (mask.getBoolean(p) == false) { continue; } - if (vBlock.isNull(p)) { + int vValueCount = vBlock.getValueCount(p); + if (vValueCount == 0) { continue; } - if (outputValueBlock.isNull(p)) { + int outputValueValueCount = outputValueBlock.getValueCount(p); + if (outputValueValueCount == 0) { continue; } int vStart = vBlock.getFirstValueIndex(p); - int vEnd = vStart + vBlock.getValueCount(p); + int vEnd = vStart + vValueCount; for (int vOffset = vStart; vOffset < vEnd; vOffset++) { int vValue = vBlock.getInt(vOffset); int outputValueStart = outputValueBlock.getFirstValueIndex(p); - int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(p); + int outputValueEnd = outputValueStart + outputValueValueCount; for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { long outputValueValue = outputValueBlock.getLong(outputValueOffset); TopIntLongAggregator.combine(state, vValue, outputValueValue); diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongDoubleAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongDoubleAggregatorFunction.java index a2dcfd06801c2..3ce085f84251d 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongDoubleAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongDoubleAggregatorFunction.java @@ -126,18 +126,20 @@ private void addRawVector(LongVector vVector, DoubleVector outputValueVector, private void addRawBlock(LongBlock vBlock, DoubleBlock outputValueBlock) { for (int p = 0; p < vBlock.getPositionCount(); p++) { - if (vBlock.isNull(p)) { + int vValueCount = vBlock.getValueCount(p); + if (vValueCount == 0) { continue; } - if (outputValueBlock.isNull(p)) { + int outputValueValueCount = outputValueBlock.getValueCount(p); + if (outputValueValueCount == 0) { continue; } int vStart = vBlock.getFirstValueIndex(p); - int vEnd = vStart + vBlock.getValueCount(p); + int vEnd = vStart + vValueCount; for (int vOffset = vStart; vOffset < vEnd; vOffset++) { long vValue = vBlock.getLong(vOffset); int outputValueStart = outputValueBlock.getFirstValueIndex(p); - int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(p); + int outputValueEnd = outputValueStart + outputValueValueCount; for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { double outputValueValue = outputValueBlock.getDouble(outputValueOffset); TopLongDoubleAggregator.combine(state, vValue, outputValueValue); @@ -151,18 +153,20 @@ private void addRawBlock(LongBlock vBlock, DoubleBlock outputValueBlock, Boolean if (mask.getBoolean(p) == false) { continue; } - if (vBlock.isNull(p)) { + int vValueCount = vBlock.getValueCount(p); + if (vValueCount == 0) { continue; } - if (outputValueBlock.isNull(p)) { + int outputValueValueCount = outputValueBlock.getValueCount(p); + if (outputValueValueCount == 0) { continue; } int vStart = vBlock.getFirstValueIndex(p); - int vEnd = vStart + vBlock.getValueCount(p); + int vEnd = vStart + vValueCount; for (int vOffset = vStart; vOffset < vEnd; vOffset++) { long vValue = vBlock.getLong(vOffset); int outputValueStart = outputValueBlock.getFirstValueIndex(p); - int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(p); + int outputValueEnd = outputValueStart + outputValueValueCount; for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { double outputValueValue = outputValueBlock.getDouble(outputValueOffset); TopLongDoubleAggregator.combine(state, vValue, outputValueValue); diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongFloatAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongFloatAggregatorFunction.java index d6661180b41da..0de6c65d1e5e5 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongFloatAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongFloatAggregatorFunction.java @@ -125,18 +125,20 @@ private void addRawVector(LongVector vVector, FloatVector outputValueVector, Boo private void addRawBlock(LongBlock vBlock, FloatBlock outputValueBlock) { for (int p = 0; p < vBlock.getPositionCount(); p++) { - if (vBlock.isNull(p)) { + int vValueCount = vBlock.getValueCount(p); + if (vValueCount == 0) { continue; } - if (outputValueBlock.isNull(p)) { + int outputValueValueCount = outputValueBlock.getValueCount(p); + if (outputValueValueCount == 0) { continue; } int vStart = vBlock.getFirstValueIndex(p); - int vEnd = vStart + vBlock.getValueCount(p); + int vEnd = vStart + vValueCount; for (int vOffset = vStart; vOffset < vEnd; vOffset++) { long vValue = vBlock.getLong(vOffset); int outputValueStart = outputValueBlock.getFirstValueIndex(p); - int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(p); + int outputValueEnd = outputValueStart + outputValueValueCount; for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { float outputValueValue = outputValueBlock.getFloat(outputValueOffset); TopLongFloatAggregator.combine(state, vValue, outputValueValue); @@ -150,18 +152,20 @@ private void addRawBlock(LongBlock vBlock, FloatBlock outputValueBlock, BooleanV if (mask.getBoolean(p) == false) { continue; } - if (vBlock.isNull(p)) { + int vValueCount = vBlock.getValueCount(p); + if (vValueCount == 0) { continue; } - if (outputValueBlock.isNull(p)) { + int outputValueValueCount = outputValueBlock.getValueCount(p); + if (outputValueValueCount == 0) { continue; } int vStart = vBlock.getFirstValueIndex(p); - int vEnd = vStart + vBlock.getValueCount(p); + int vEnd = vStart + vValueCount; for (int vOffset = vStart; vOffset < vEnd; vOffset++) { long vValue = vBlock.getLong(vOffset); int outputValueStart = outputValueBlock.getFirstValueIndex(p); - int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(p); + int outputValueEnd = outputValueStart + outputValueValueCount; for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { float outputValueValue = outputValueBlock.getFloat(outputValueOffset); TopLongFloatAggregator.combine(state, vValue, outputValueValue); diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongIntAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongIntAggregatorFunction.java index 61abc3a436a1d..9186916c34e8d 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongIntAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongIntAggregatorFunction.java @@ -125,18 +125,20 @@ private void addRawVector(LongVector vVector, IntVector outputValueVector, Boole private void addRawBlock(LongBlock vBlock, IntBlock outputValueBlock) { for (int p = 0; p < vBlock.getPositionCount(); p++) { - if (vBlock.isNull(p)) { + int vValueCount = vBlock.getValueCount(p); + if (vValueCount == 0) { continue; } - if (outputValueBlock.isNull(p)) { + int outputValueValueCount = outputValueBlock.getValueCount(p); + if (outputValueValueCount == 0) { continue; } int vStart = vBlock.getFirstValueIndex(p); - int vEnd = vStart + vBlock.getValueCount(p); + int vEnd = vStart + vValueCount; for (int vOffset = vStart; vOffset < vEnd; vOffset++) { long vValue = vBlock.getLong(vOffset); int outputValueStart = outputValueBlock.getFirstValueIndex(p); - int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(p); + int outputValueEnd = outputValueStart + outputValueValueCount; for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { int outputValueValue = outputValueBlock.getInt(outputValueOffset); TopLongIntAggregator.combine(state, vValue, outputValueValue); @@ -150,18 +152,20 @@ private void addRawBlock(LongBlock vBlock, IntBlock outputValueBlock, BooleanVec if (mask.getBoolean(p) == false) { continue; } - if (vBlock.isNull(p)) { + int vValueCount = vBlock.getValueCount(p); + if (vValueCount == 0) { continue; } - if (outputValueBlock.isNull(p)) { + int outputValueValueCount = outputValueBlock.getValueCount(p); + if (outputValueValueCount == 0) { continue; } int vStart = vBlock.getFirstValueIndex(p); - int vEnd = vStart + vBlock.getValueCount(p); + int vEnd = vStart + vValueCount; for (int vOffset = vStart; vOffset < vEnd; vOffset++) { long vValue = vBlock.getLong(vOffset); int outputValueStart = outputValueBlock.getFirstValueIndex(p); - int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(p); + int outputValueEnd = outputValueStart + outputValueValueCount; for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { int outputValueValue = outputValueBlock.getInt(outputValueOffset); TopLongIntAggregator.combine(state, vValue, outputValueValue); diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongLongAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongLongAggregatorFunction.java index bd64887b12f67..fe9df560a0516 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongLongAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongLongAggregatorFunction.java @@ -123,18 +123,20 @@ private void addRawVector(LongVector vVector, LongVector outputValueVector, Bool private void addRawBlock(LongBlock vBlock, LongBlock outputValueBlock) { for (int p = 0; p < vBlock.getPositionCount(); p++) { - if (vBlock.isNull(p)) { + int vValueCount = vBlock.getValueCount(p); + if (vValueCount == 0) { continue; } - if (outputValueBlock.isNull(p)) { + int outputValueValueCount = outputValueBlock.getValueCount(p); + if (outputValueValueCount == 0) { continue; } int vStart = vBlock.getFirstValueIndex(p); - int vEnd = vStart + vBlock.getValueCount(p); + int vEnd = vStart + vValueCount; for (int vOffset = vStart; vOffset < vEnd; vOffset++) { long vValue = vBlock.getLong(vOffset); int outputValueStart = outputValueBlock.getFirstValueIndex(p); - int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(p); + int outputValueEnd = outputValueStart + outputValueValueCount; for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { long outputValueValue = outputValueBlock.getLong(outputValueOffset); TopLongLongAggregator.combine(state, vValue, outputValueValue); @@ -148,18 +150,20 @@ private void addRawBlock(LongBlock vBlock, LongBlock outputValueBlock, BooleanVe if (mask.getBoolean(p) == false) { continue; } - if (vBlock.isNull(p)) { + int vValueCount = vBlock.getValueCount(p); + if (vValueCount == 0) { continue; } - if (outputValueBlock.isNull(p)) { + int outputValueValueCount = outputValueBlock.getValueCount(p); + if (outputValueValueCount == 0) { continue; } int vStart = vBlock.getFirstValueIndex(p); - int vEnd = vStart + vBlock.getValueCount(p); + int vEnd = vStart + vValueCount; for (int vOffset = vStart; vOffset < vEnd; vOffset++) { long vValue = vBlock.getLong(vOffset); int outputValueStart = outputValueBlock.getFirstValueIndex(p); - int outputValueEnd = outputValueStart + outputValueBlock.getValueCount(p); + int outputValueEnd = outputValueStart + outputValueValueCount; for (int outputValueOffset = outputValueStart; outputValueOffset < outputValueEnd; outputValueOffset++) { long outputValueValue = outputValueBlock.getLong(outputValueOffset); TopLongLongAggregator.combine(state, vValue, outputValueValue); From 562c7cd92dab0eda81fea8f142dc2b063faed966 Mon Sep 17 00:00:00 2001 From: Przemyslaw Witek Date: Tue, 21 Oct 2025 14:25:13 +0200 Subject: [PATCH 10/16] Add tests for new surrogates --- .../function/aggregate/TopTests.java | 70 ++++++++++++++++++- 1 file changed, 68 insertions(+), 2 deletions(-) diff --git a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/TopTests.java b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/TopTests.java index d81987499536e..d1a10da22372e 100644 --- a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/TopTests.java +++ b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/TopTests.java @@ -14,6 +14,7 @@ import org.apache.lucene.util.BytesRef; import org.elasticsearch.common.network.InetAddresses; import org.elasticsearch.xpack.esql.core.expression.Expression; +import org.elasticsearch.xpack.esql.core.expression.FieldAttribute; import org.elasticsearch.xpack.esql.core.tree.Source; import org.elasticsearch.xpack.esql.core.type.DataType; import org.elasticsearch.xpack.esql.expression.function.AbstractAggregationTestCase; @@ -88,7 +89,64 @@ public static Iterable parameters() { suppliers.addAll( List.of( - // Surrogates + // Surrogates for cases where field and outputField are effectively the same field + new TestCaseSupplier( + List.of(DataType.INTEGER, DataType.INTEGER, DataType.KEYWORD, DataType.INTEGER), + () -> new TestCaseSupplier.TestCase( + List.of( + TestCaseSupplier.TypedData.multiRow(List.of(5, 8, -2, 0, 200), DataType.INTEGER, "field"), + new TestCaseSupplier.TypedData(3, DataType.INTEGER, "limit").forceLiteral(), + new TestCaseSupplier.TypedData(new BytesRef("desc"), DataType.KEYWORD, "order").forceLiteral(), + TestCaseSupplier.TypedData.multiRow(List.of(5, 8, -2, 0, 200), DataType.INTEGER, "field") + ), + "TopInt", + DataType.INTEGER, + equalTo(List.of(200, 8, 5)) + ) + ), + new TestCaseSupplier( + List.of(DataType.LONG, DataType.INTEGER, DataType.KEYWORD, DataType.LONG), + () -> new TestCaseSupplier.TestCase( + List.of( + TestCaseSupplier.TypedData.multiRow(List.of(5L, 8L, -2L, 0L, 200L), DataType.LONG, "field"), + new TestCaseSupplier.TypedData(3, DataType.INTEGER, "limit").forceLiteral(), + new TestCaseSupplier.TypedData(new BytesRef("desc"), DataType.KEYWORD, "order").forceLiteral(), + TestCaseSupplier.TypedData.multiRow(List.of(5L, 8L, -2L, 0L, 200L), DataType.LONG, "field") + ), + "TopLong", + DataType.LONG, + equalTo(List.of(200L, 8L, 5L)) + ) + ), + new TestCaseSupplier( + List.of(DataType.DOUBLE, DataType.INTEGER, DataType.KEYWORD, DataType.DOUBLE), + () -> new TestCaseSupplier.TestCase( + List.of( + TestCaseSupplier.TypedData.multiRow(List.of(5., 8., -2., 0., 200.), DataType.DOUBLE, "field"), + new TestCaseSupplier.TypedData(3, DataType.INTEGER, "limit").forceLiteral(), + new TestCaseSupplier.TypedData(new BytesRef("desc"), DataType.KEYWORD, "order").forceLiteral(), + TestCaseSupplier.TypedData.multiRow(List.of(5., 8., -2., 0., 200.), DataType.DOUBLE, "field") + ), + "TopDouble", + DataType.DOUBLE, + equalTo(List.of(200., 8., 5.)) + ) + ), + new TestCaseSupplier( + List.of(DataType.DATETIME, DataType.INTEGER, DataType.KEYWORD, DataType.DATETIME), + () -> new TestCaseSupplier.TestCase( + List.of( + TestCaseSupplier.TypedData.multiRow(List.of(5L, 8L, 2L, 0L, 200L), DataType.DATETIME, "field"), + new TestCaseSupplier.TypedData(3, DataType.INTEGER, "limit").forceLiteral(), + new TestCaseSupplier.TypedData(new BytesRef("desc"), DataType.KEYWORD, "order").forceLiteral(), + TestCaseSupplier.TypedData.multiRow(List.of(5L, 8L, 2L, 0L, 200L), DataType.DATETIME, "field") + ), + "TopLong", + DataType.DATETIME, + equalTo(List.of(200L, 8L, 5L)) + ) + ), + // Surrogates for cases where limit == 1 new TestCaseSupplier( List.of(DataType.BOOLEAN, DataType.INTEGER, DataType.KEYWORD), () -> new TestCaseSupplier.TestCase( @@ -392,7 +450,15 @@ public static Iterable parameters() { @Override protected Expression build(Source source, List args) { - return new Top(source, args.get(0), args.get(1), args.size() > 2 ? args.get(2) : null, args.size() > 3 ? args.get(3) : null); + Expression field = args.get(0); + Expression outputField = args.size() > 3 ? args.get(3) : null; + if (field instanceof FieldAttribute f && outputField instanceof FieldAttribute of && f.fieldName().equals(of.fieldName())) { + // In order to avoid passing the same field twice as two different FieldAttribute objects, we use `field` as the fourth argument + // if `field`'s and `outputField`'s `fieldName` match. In such case TOP will use surrogate. + return new Top(source, field, args.get(1), args.size() > 2 ? args.get(2) : null, field); + } else { + return new Top(source, field, args.get(1), args.size() > 2 ? args.get(2) : null, outputField); + } } @SuppressWarnings("unchecked") From 41081c0a20397e74b15e975c6dc9a9a31a7f3c6e Mon Sep 17 00:00:00 2001 From: Przemyslaw Witek Date: Tue, 21 Oct 2025 14:26:39 +0200 Subject: [PATCH 11/16] Apply spotless --- .../xpack/esql/core/expression/TypeResolutions.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/x-pack/plugin/esql-core/src/main/java/org/elasticsearch/xpack/esql/core/expression/TypeResolutions.java b/x-pack/plugin/esql-core/src/main/java/org/elasticsearch/xpack/esql/core/expression/TypeResolutions.java index 1b723e536602d..c74cfbfa91215 100644 --- a/x-pack/plugin/esql-core/src/main/java/org/elasticsearch/xpack/esql/core/expression/TypeResolutions.java +++ b/x-pack/plugin/esql-core/src/main/java/org/elasticsearch/xpack/esql/core/expression/TypeResolutions.java @@ -238,7 +238,14 @@ public static TypeResolution isType( } return new TypeResolution( - errorStringIncompatibleTypes(errorMessagePrefix, operationName, paramOrd, name(e), e.dataType(), acceptedTypesForErrorMsg(acceptedTypes)) + errorStringIncompatibleTypes( + errorMessagePrefix, + operationName, + paramOrd, + name(e), + e.dataType(), + acceptedTypesForErrorMsg(acceptedTypes) + ) ); } From 334423a260c9690ae3f963741c6de0ab9d4a460d Mon Sep 17 00:00:00 2001 From: Przemyslaw Witek Date: Tue, 21 Oct 2025 14:56:11 +0200 Subject: [PATCH 12/16] Fix stats_top.empNoByHireDateByBirthYear by fixing the order of rows --- .../src/main/resources/stats_top.csv-spec | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/x-pack/plugin/esql/qa/testFixtures/src/main/resources/stats_top.csv-spec b/x-pack/plugin/esql/qa/testFixtures/src/main/resources/stats_top.csv-spec index ad5c2001c5d24..b99a7b232bcf9 100644 --- a/x-pack/plugin/esql/qa/testFixtures/src/main/resources/stats_top.csv-spec +++ b/x-pack/plugin/esql/qa/testFixtures/src/main/resources/stats_top.csv-spec @@ -385,22 +385,23 @@ FROM employees | EVAL birth_year = DATE_EXTRACT("year", birth_date) | STATS v = TOP(birth_year, 20, "asc", emp_no) BY birth_year | KEEP birth_year, v +| SORT birth_year ; birth_year:long | v:integer -null | null +1952 | [10009, 10020, 10022, 10063, 10066, 10072, 10076, 10097] 1953 | [10001, 10006, 10011, 10019, 10023, 10026, 10035, 10051, 10059, 10067, 10100] -1964 | [10002, 10077, 10092, 10093] -1959 | [10003, 10015, 10031, 10036, 10039, 10064, 10078, 10083, 10087] 1954 | [10004, 10018, 10053, 10057, 10058, 10073, 10088, 10096] 1955 | [10005, 10070, 10074, 10091] +1956 | [10014, 10029, 10033, 10055, 10099] 1957 | [10007, 10054, 10080, 10094] 1958 | [10008, 10017, 10024, 10025, 10030, 10050, 10071] -1952 | [10009, 10020, 10022, 10063, 10066, 10072, 10076, 10097] -1963 | [10010, 10013, 10028, 10037, 10065, 10082, 10089] +1959 | [10003, 10015, 10031, 10036, 10039, 10064, 10078, 10083, 10087] 1960 | [10012, 10021, 10032, 10038, 10069, 10075, 10081, 10084] -1956 | [10014, 10029, 10033, 10055, 10099] 1961 | [10016, 10052, 10056, 10060, 10062, 10079, 10090, 10098] 1962 | [10027, 10034, 10061, 10068, 10085, 10086] +1963 | [10010, 10013, 10028, 10037, 10065, 10082, 10089] +1964 | [10002, 10077, 10092, 10093] 1965 | 10095 +null | null ; From fafc62c2d344ad6dcd2b3cda1b4d2bb2225073bb Mon Sep 17 00:00:00 2001 From: Przemyslaw Witek Date: Tue, 28 Oct 2025 13:45:14 +0100 Subject: [PATCH 13/16] Apply review comment --- x-pack/plugin/esql/compute/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugin/esql/compute/build.gradle b/x-pack/plugin/esql/compute/build.gradle index 44f9bdd331238..3abfd64df3748 100644 --- a/x-pack/plugin/esql/compute/build.gradle +++ b/x-pack/plugin/esql/compute/build.gradle @@ -51,7 +51,7 @@ spotless { * Generated files go here. */ toggleOffOn('begin generated imports', 'end generated imports') - targetExclude "src/main/generated*/**/*.java" + targetExclude "src/main/generated/**/*.java" } } From 983dccd027b1fb38cf655534f6544944c7b9da2a Mon Sep 17 00:00:00 2001 From: elasticsearchmachine Date: Tue, 28 Oct 2025 12:52:49 +0000 Subject: [PATCH 14/16] [CI] Auto commit changes from spotless --- .../compute/aggregation/TopDoubleDoubleAggregator.java | 8 +++++++- .../compute/aggregation/TopDoubleFloatAggregator.java | 8 +++++++- .../compute/aggregation/TopDoubleIntAggregator.java | 8 +++++++- .../compute/aggregation/TopDoubleLongAggregator.java | 8 +++++++- .../compute/aggregation/TopFloatDoubleAggregator.java | 8 +++++++- .../compute/aggregation/TopFloatFloatAggregator.java | 8 +++++++- .../compute/aggregation/TopFloatLongAggregator.java | 8 +++++++- .../compute/aggregation/TopIntDoubleAggregator.java | 8 +++++++- .../compute/aggregation/TopLongDoubleAggregator.java | 8 +++++++- .../compute/aggregation/TopLongFloatAggregator.java | 8 +++++++- .../compute/data/sort/DoubleDoubleBucketedSort.java | 1 - .../compute/data/sort/DoubleFloatBucketedSort.java | 2 +- .../compute/data/sort/DoubleIntBucketedSort.java | 2 +- .../compute/data/sort/DoubleLongBucketedSort.java | 2 +- .../compute/data/sort/FloatFloatBucketedSort.java | 1 - .../compute/data/sort/FloatIntBucketedSort.java | 2 +- .../compute/data/sort/FloatLongBucketedSort.java | 2 +- .../compute/data/sort/IntIntBucketedSort.java | 1 - .../compute/data/sort/IntLongBucketedSort.java | 2 +- 19 files changed, 76 insertions(+), 19 deletions(-) diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopDoubleDoubleAggregator.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopDoubleDoubleAggregator.java index 45cd12e43c182..5f0c40496c8cc 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopDoubleDoubleAggregator.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopDoubleDoubleAggregator.java @@ -62,7 +62,13 @@ public static void combine(GroupingState state, int groupId, double v, double ou state.add(groupId, v, outputValue); } - public static void combineIntermediate(GroupingState state, int groupId, DoubleBlock values, DoubleBlock outputValues, int valuesPosition) { + public static void combineIntermediate( + GroupingState state, + int groupId, + DoubleBlock values, + DoubleBlock outputValues, + int valuesPosition + ) { int start = values.getFirstValueIndex(valuesPosition); int end = start + values.getValueCount(valuesPosition); for (int i = start; i < end; i++) { diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopDoubleFloatAggregator.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopDoubleFloatAggregator.java index da103d70c0a54..d4a775b37fbc0 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopDoubleFloatAggregator.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopDoubleFloatAggregator.java @@ -62,7 +62,13 @@ public static void combine(GroupingState state, int groupId, double v, float out state.add(groupId, v, outputValue); } - public static void combineIntermediate(GroupingState state, int groupId, DoubleBlock values, FloatBlock outputValues, int valuesPosition) { + public static void combineIntermediate( + GroupingState state, + int groupId, + DoubleBlock values, + FloatBlock outputValues, + int valuesPosition + ) { int start = values.getFirstValueIndex(valuesPosition); int end = start + values.getValueCount(valuesPosition); for (int i = start; i < end; i++) { diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopDoubleIntAggregator.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopDoubleIntAggregator.java index 2b0790c303e59..b0f17eb3bcff3 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopDoubleIntAggregator.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopDoubleIntAggregator.java @@ -62,7 +62,13 @@ public static void combine(GroupingState state, int groupId, double v, int outpu state.add(groupId, v, outputValue); } - public static void combineIntermediate(GroupingState state, int groupId, DoubleBlock values, IntBlock outputValues, int valuesPosition) { + public static void combineIntermediate( + GroupingState state, + int groupId, + DoubleBlock values, + IntBlock outputValues, + int valuesPosition + ) { int start = values.getFirstValueIndex(valuesPosition); int end = start + values.getValueCount(valuesPosition); for (int i = start; i < end; i++) { diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopDoubleLongAggregator.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopDoubleLongAggregator.java index 57dd898fce1e4..dc745b7e954b4 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopDoubleLongAggregator.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopDoubleLongAggregator.java @@ -62,7 +62,13 @@ public static void combine(GroupingState state, int groupId, double v, long outp state.add(groupId, v, outputValue); } - public static void combineIntermediate(GroupingState state, int groupId, DoubleBlock values, LongBlock outputValues, int valuesPosition) { + public static void combineIntermediate( + GroupingState state, + int groupId, + DoubleBlock values, + LongBlock outputValues, + int valuesPosition + ) { int start = values.getFirstValueIndex(valuesPosition); int end = start + values.getValueCount(valuesPosition); for (int i = start; i < end; i++) { diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopFloatDoubleAggregator.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopFloatDoubleAggregator.java index ae4ba17da2529..d79dc9fa99e1e 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopFloatDoubleAggregator.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopFloatDoubleAggregator.java @@ -62,7 +62,13 @@ public static void combine(GroupingState state, int groupId, float v, double out state.add(groupId, v, outputValue); } - public static void combineIntermediate(GroupingState state, int groupId, FloatBlock values, DoubleBlock outputValues, int valuesPosition) { + public static void combineIntermediate( + GroupingState state, + int groupId, + FloatBlock values, + DoubleBlock outputValues, + int valuesPosition + ) { int start = values.getFirstValueIndex(valuesPosition); int end = start + values.getValueCount(valuesPosition); for (int i = start; i < end; i++) { diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopFloatFloatAggregator.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopFloatFloatAggregator.java index e2876b5cddffa..955f6d9609623 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopFloatFloatAggregator.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopFloatFloatAggregator.java @@ -62,7 +62,13 @@ public static void combine(GroupingState state, int groupId, float v, float outp state.add(groupId, v, outputValue); } - public static void combineIntermediate(GroupingState state, int groupId, FloatBlock values, FloatBlock outputValues, int valuesPosition) { + public static void combineIntermediate( + GroupingState state, + int groupId, + FloatBlock values, + FloatBlock outputValues, + int valuesPosition + ) { int start = values.getFirstValueIndex(valuesPosition); int end = start + values.getValueCount(valuesPosition); for (int i = start; i < end; i++) { diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopFloatLongAggregator.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopFloatLongAggregator.java index 580d649abae42..ef2432265d570 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopFloatLongAggregator.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopFloatLongAggregator.java @@ -62,7 +62,13 @@ public static void combine(GroupingState state, int groupId, float v, long outpu state.add(groupId, v, outputValue); } - public static void combineIntermediate(GroupingState state, int groupId, FloatBlock values, LongBlock outputValues, int valuesPosition) { + public static void combineIntermediate( + GroupingState state, + int groupId, + FloatBlock values, + LongBlock outputValues, + int valuesPosition + ) { int start = values.getFirstValueIndex(valuesPosition); int end = start + values.getValueCount(valuesPosition); for (int i = start; i < end; i++) { diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopIntDoubleAggregator.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopIntDoubleAggregator.java index 10090a179b5bb..8d5558d555ec4 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopIntDoubleAggregator.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopIntDoubleAggregator.java @@ -62,7 +62,13 @@ public static void combine(GroupingState state, int groupId, int v, double outpu state.add(groupId, v, outputValue); } - public static void combineIntermediate(GroupingState state, int groupId, IntBlock values, DoubleBlock outputValues, int valuesPosition) { + public static void combineIntermediate( + GroupingState state, + int groupId, + IntBlock values, + DoubleBlock outputValues, + int valuesPosition + ) { int start = values.getFirstValueIndex(valuesPosition); int end = start + values.getValueCount(valuesPosition); for (int i = start; i < end; i++) { diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopLongDoubleAggregator.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopLongDoubleAggregator.java index 31c4f9096ca0e..c35db6fc8aed0 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopLongDoubleAggregator.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopLongDoubleAggregator.java @@ -62,7 +62,13 @@ public static void combine(GroupingState state, int groupId, long v, double outp state.add(groupId, v, outputValue); } - public static void combineIntermediate(GroupingState state, int groupId, LongBlock values, DoubleBlock outputValues, int valuesPosition) { + public static void combineIntermediate( + GroupingState state, + int groupId, + LongBlock values, + DoubleBlock outputValues, + int valuesPosition + ) { int start = values.getFirstValueIndex(valuesPosition); int end = start + values.getValueCount(valuesPosition); for (int i = start; i < end; i++) { diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopLongFloatAggregator.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopLongFloatAggregator.java index 66d699cfd3d32..7d8e6ce5bf805 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopLongFloatAggregator.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopLongFloatAggregator.java @@ -62,7 +62,13 @@ public static void combine(GroupingState state, int groupId, long v, float outpu state.add(groupId, v, outputValue); } - public static void combineIntermediate(GroupingState state, int groupId, LongBlock values, FloatBlock outputValues, int valuesPosition) { + public static void combineIntermediate( + GroupingState state, + int groupId, + LongBlock values, + FloatBlock outputValues, + int valuesPosition + ) { int start = values.getFirstValueIndex(valuesPosition); int end = start + values.getValueCount(valuesPosition); for (int i = start; i < end; i++) { diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleDoubleBucketedSort.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleDoubleBucketedSort.java index 6438cb1c99a62..6f6ad8a870eb8 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleDoubleBucketedSort.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleDoubleBucketedSort.java @@ -10,7 +10,6 @@ import org.elasticsearch.common.util.BigArrays; import org.elasticsearch.common.util.BitArray; import org.elasticsearch.common.util.DoubleArray; -import org.elasticsearch.common.util.DoubleArray; import org.elasticsearch.common.util.PageCacheRecycler; import org.elasticsearch.compute.data.Block; import org.elasticsearch.compute.data.BlockFactory; diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleFloatBucketedSort.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleFloatBucketedSort.java index f4bd6d9fdbf92..53a4cfd1b6ccc 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleFloatBucketedSort.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleFloatBucketedSort.java @@ -9,8 +9,8 @@ import org.elasticsearch.common.util.BigArrays; import org.elasticsearch.common.util.BitArray; -import org.elasticsearch.common.util.FloatArray; import org.elasticsearch.common.util.DoubleArray; +import org.elasticsearch.common.util.FloatArray; import org.elasticsearch.common.util.PageCacheRecycler; import org.elasticsearch.compute.data.Block; import org.elasticsearch.compute.data.BlockFactory; diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleIntBucketedSort.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleIntBucketedSort.java index c20fb8f9ce1a4..502647337a5f4 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleIntBucketedSort.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleIntBucketedSort.java @@ -9,8 +9,8 @@ import org.elasticsearch.common.util.BigArrays; import org.elasticsearch.common.util.BitArray; -import org.elasticsearch.common.util.IntArray; import org.elasticsearch.common.util.DoubleArray; +import org.elasticsearch.common.util.IntArray; import org.elasticsearch.common.util.PageCacheRecycler; import org.elasticsearch.compute.data.Block; import org.elasticsearch.compute.data.BlockFactory; diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleLongBucketedSort.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleLongBucketedSort.java index 6f84c762c3258..e1d57a4885c43 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleLongBucketedSort.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleLongBucketedSort.java @@ -9,8 +9,8 @@ import org.elasticsearch.common.util.BigArrays; import org.elasticsearch.common.util.BitArray; -import org.elasticsearch.common.util.LongArray; import org.elasticsearch.common.util.DoubleArray; +import org.elasticsearch.common.util.LongArray; import org.elasticsearch.common.util.PageCacheRecycler; import org.elasticsearch.compute.data.Block; import org.elasticsearch.compute.data.BlockFactory; diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/FloatFloatBucketedSort.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/FloatFloatBucketedSort.java index c3ad1e47f1698..86a63e6a5f5de 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/FloatFloatBucketedSort.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/FloatFloatBucketedSort.java @@ -10,7 +10,6 @@ import org.elasticsearch.common.util.BigArrays; import org.elasticsearch.common.util.BitArray; import org.elasticsearch.common.util.FloatArray; -import org.elasticsearch.common.util.FloatArray; import org.elasticsearch.common.util.PageCacheRecycler; import org.elasticsearch.compute.data.Block; import org.elasticsearch.compute.data.BlockFactory; diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/FloatIntBucketedSort.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/FloatIntBucketedSort.java index fefe511a88586..a4bc8d96de0d3 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/FloatIntBucketedSort.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/FloatIntBucketedSort.java @@ -9,8 +9,8 @@ import org.elasticsearch.common.util.BigArrays; import org.elasticsearch.common.util.BitArray; -import org.elasticsearch.common.util.IntArray; import org.elasticsearch.common.util.FloatArray; +import org.elasticsearch.common.util.IntArray; import org.elasticsearch.common.util.PageCacheRecycler; import org.elasticsearch.compute.data.Block; import org.elasticsearch.compute.data.BlockFactory; diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/FloatLongBucketedSort.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/FloatLongBucketedSort.java index 32aa8e9fdb191..b6c185ee58ca5 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/FloatLongBucketedSort.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/FloatLongBucketedSort.java @@ -9,8 +9,8 @@ import org.elasticsearch.common.util.BigArrays; import org.elasticsearch.common.util.BitArray; -import org.elasticsearch.common.util.LongArray; import org.elasticsearch.common.util.FloatArray; +import org.elasticsearch.common.util.LongArray; import org.elasticsearch.common.util.PageCacheRecycler; import org.elasticsearch.compute.data.Block; import org.elasticsearch.compute.data.BlockFactory; diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/IntIntBucketedSort.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/IntIntBucketedSort.java index 13cb37e886ce6..d3eb3e2a2b16f 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/IntIntBucketedSort.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/IntIntBucketedSort.java @@ -10,7 +10,6 @@ import org.elasticsearch.common.util.BigArrays; import org.elasticsearch.common.util.BitArray; import org.elasticsearch.common.util.IntArray; -import org.elasticsearch.common.util.IntArray; import org.elasticsearch.common.util.PageCacheRecycler; import org.elasticsearch.compute.data.Block; import org.elasticsearch.compute.data.BlockFactory; diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/IntLongBucketedSort.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/IntLongBucketedSort.java index dae223f67dc8d..6f7a04ce801bd 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/IntLongBucketedSort.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/IntLongBucketedSort.java @@ -9,8 +9,8 @@ import org.elasticsearch.common.util.BigArrays; import org.elasticsearch.common.util.BitArray; -import org.elasticsearch.common.util.LongArray; import org.elasticsearch.common.util.IntArray; +import org.elasticsearch.common.util.LongArray; import org.elasticsearch.common.util.PageCacheRecycler; import org.elasticsearch.compute.data.Block; import org.elasticsearch.compute.data.BlockFactory; From aaefe1796ca8f89329073883bdc3053e870a132f Mon Sep 17 00:00:00 2001 From: Przemyslaw Witek Date: Tue, 28 Oct 2025 15:11:41 +0100 Subject: [PATCH 15/16] Add "begin/end generated imports" directives to X-BucketedSort.java.st file --- .../compute/aggregation/TopDoubleDoubleAggregator.java | 8 +------- .../compute/aggregation/TopDoubleFloatAggregator.java | 8 +------- .../compute/aggregation/TopDoubleIntAggregator.java | 8 +------- .../compute/aggregation/TopDoubleLongAggregator.java | 8 +------- .../compute/aggregation/TopFloatDoubleAggregator.java | 8 +------- .../compute/aggregation/TopFloatFloatAggregator.java | 8 +------- .../compute/aggregation/TopFloatLongAggregator.java | 8 +------- .../compute/aggregation/TopIntDoubleAggregator.java | 8 +------- .../compute/aggregation/TopLongDoubleAggregator.java | 8 +------- .../compute/aggregation/TopLongFloatAggregator.java | 8 +------- .../compute/data/sort/DoubleBucketedSort.java | 2 ++ .../compute/data/sort/DoubleDoubleBucketedSort.java | 3 +++ .../compute/data/sort/DoubleFloatBucketedSort.java | 4 +++- .../compute/data/sort/DoubleIntBucketedSort.java | 4 +++- .../compute/data/sort/DoubleLongBucketedSort.java | 4 +++- .../compute/data/sort/FloatBucketedSort.java | 2 ++ .../compute/data/sort/FloatDoubleBucketedSort.java | 2 ++ .../compute/data/sort/FloatFloatBucketedSort.java | 3 +++ .../compute/data/sort/FloatIntBucketedSort.java | 4 +++- .../compute/data/sort/FloatLongBucketedSort.java | 4 +++- .../elasticsearch/compute/data/sort/IntBucketedSort.java | 2 ++ .../compute/data/sort/IntDoubleBucketedSort.java | 2 ++ .../compute/data/sort/IntFloatBucketedSort.java | 2 ++ .../compute/data/sort/IntIntBucketedSort.java | 3 +++ .../compute/data/sort/IntLongBucketedSort.java | 4 +++- .../elasticsearch/compute/data/sort/LongBucketedSort.java | 2 ++ .../compute/data/sort/LongDoubleBucketedSort.java | 2 ++ .../compute/data/sort/LongFloatBucketedSort.java | 2 ++ .../compute/data/sort/LongIntBucketedSort.java | 2 ++ .../compute/data/sort/LongLongBucketedSort.java | 2 ++ .../compute/data/sort/X-BucketedSort.java.st | 2 ++ 31 files changed, 61 insertions(+), 76 deletions(-) diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopDoubleDoubleAggregator.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopDoubleDoubleAggregator.java index 5f0c40496c8cc..45cd12e43c182 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopDoubleDoubleAggregator.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopDoubleDoubleAggregator.java @@ -62,13 +62,7 @@ public static void combine(GroupingState state, int groupId, double v, double ou state.add(groupId, v, outputValue); } - public static void combineIntermediate( - GroupingState state, - int groupId, - DoubleBlock values, - DoubleBlock outputValues, - int valuesPosition - ) { + public static void combineIntermediate(GroupingState state, int groupId, DoubleBlock values, DoubleBlock outputValues, int valuesPosition) { int start = values.getFirstValueIndex(valuesPosition); int end = start + values.getValueCount(valuesPosition); for (int i = start; i < end; i++) { diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopDoubleFloatAggregator.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopDoubleFloatAggregator.java index d4a775b37fbc0..da103d70c0a54 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopDoubleFloatAggregator.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopDoubleFloatAggregator.java @@ -62,13 +62,7 @@ public static void combine(GroupingState state, int groupId, double v, float out state.add(groupId, v, outputValue); } - public static void combineIntermediate( - GroupingState state, - int groupId, - DoubleBlock values, - FloatBlock outputValues, - int valuesPosition - ) { + public static void combineIntermediate(GroupingState state, int groupId, DoubleBlock values, FloatBlock outputValues, int valuesPosition) { int start = values.getFirstValueIndex(valuesPosition); int end = start + values.getValueCount(valuesPosition); for (int i = start; i < end; i++) { diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopDoubleIntAggregator.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopDoubleIntAggregator.java index b0f17eb3bcff3..2b0790c303e59 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopDoubleIntAggregator.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopDoubleIntAggregator.java @@ -62,13 +62,7 @@ public static void combine(GroupingState state, int groupId, double v, int outpu state.add(groupId, v, outputValue); } - public static void combineIntermediate( - GroupingState state, - int groupId, - DoubleBlock values, - IntBlock outputValues, - int valuesPosition - ) { + public static void combineIntermediate(GroupingState state, int groupId, DoubleBlock values, IntBlock outputValues, int valuesPosition) { int start = values.getFirstValueIndex(valuesPosition); int end = start + values.getValueCount(valuesPosition); for (int i = start; i < end; i++) { diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopDoubleLongAggregator.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopDoubleLongAggregator.java index dc745b7e954b4..57dd898fce1e4 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopDoubleLongAggregator.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopDoubleLongAggregator.java @@ -62,13 +62,7 @@ public static void combine(GroupingState state, int groupId, double v, long outp state.add(groupId, v, outputValue); } - public static void combineIntermediate( - GroupingState state, - int groupId, - DoubleBlock values, - LongBlock outputValues, - int valuesPosition - ) { + public static void combineIntermediate(GroupingState state, int groupId, DoubleBlock values, LongBlock outputValues, int valuesPosition) { int start = values.getFirstValueIndex(valuesPosition); int end = start + values.getValueCount(valuesPosition); for (int i = start; i < end; i++) { diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopFloatDoubleAggregator.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopFloatDoubleAggregator.java index d79dc9fa99e1e..ae4ba17da2529 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopFloatDoubleAggregator.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopFloatDoubleAggregator.java @@ -62,13 +62,7 @@ public static void combine(GroupingState state, int groupId, float v, double out state.add(groupId, v, outputValue); } - public static void combineIntermediate( - GroupingState state, - int groupId, - FloatBlock values, - DoubleBlock outputValues, - int valuesPosition - ) { + public static void combineIntermediate(GroupingState state, int groupId, FloatBlock values, DoubleBlock outputValues, int valuesPosition) { int start = values.getFirstValueIndex(valuesPosition); int end = start + values.getValueCount(valuesPosition); for (int i = start; i < end; i++) { diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopFloatFloatAggregator.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopFloatFloatAggregator.java index 955f6d9609623..e2876b5cddffa 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopFloatFloatAggregator.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopFloatFloatAggregator.java @@ -62,13 +62,7 @@ public static void combine(GroupingState state, int groupId, float v, float outp state.add(groupId, v, outputValue); } - public static void combineIntermediate( - GroupingState state, - int groupId, - FloatBlock values, - FloatBlock outputValues, - int valuesPosition - ) { + public static void combineIntermediate(GroupingState state, int groupId, FloatBlock values, FloatBlock outputValues, int valuesPosition) { int start = values.getFirstValueIndex(valuesPosition); int end = start + values.getValueCount(valuesPosition); for (int i = start; i < end; i++) { diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopFloatLongAggregator.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopFloatLongAggregator.java index ef2432265d570..580d649abae42 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopFloatLongAggregator.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopFloatLongAggregator.java @@ -62,13 +62,7 @@ public static void combine(GroupingState state, int groupId, float v, long outpu state.add(groupId, v, outputValue); } - public static void combineIntermediate( - GroupingState state, - int groupId, - FloatBlock values, - LongBlock outputValues, - int valuesPosition - ) { + public static void combineIntermediate(GroupingState state, int groupId, FloatBlock values, LongBlock outputValues, int valuesPosition) { int start = values.getFirstValueIndex(valuesPosition); int end = start + values.getValueCount(valuesPosition); for (int i = start; i < end; i++) { diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopIntDoubleAggregator.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopIntDoubleAggregator.java index 8d5558d555ec4..10090a179b5bb 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopIntDoubleAggregator.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopIntDoubleAggregator.java @@ -62,13 +62,7 @@ public static void combine(GroupingState state, int groupId, int v, double outpu state.add(groupId, v, outputValue); } - public static void combineIntermediate( - GroupingState state, - int groupId, - IntBlock values, - DoubleBlock outputValues, - int valuesPosition - ) { + public static void combineIntermediate(GroupingState state, int groupId, IntBlock values, DoubleBlock outputValues, int valuesPosition) { int start = values.getFirstValueIndex(valuesPosition); int end = start + values.getValueCount(valuesPosition); for (int i = start; i < end; i++) { diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopLongDoubleAggregator.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopLongDoubleAggregator.java index c35db6fc8aed0..31c4f9096ca0e 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopLongDoubleAggregator.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopLongDoubleAggregator.java @@ -62,13 +62,7 @@ public static void combine(GroupingState state, int groupId, long v, double outp state.add(groupId, v, outputValue); } - public static void combineIntermediate( - GroupingState state, - int groupId, - LongBlock values, - DoubleBlock outputValues, - int valuesPosition - ) { + public static void combineIntermediate(GroupingState state, int groupId, LongBlock values, DoubleBlock outputValues, int valuesPosition) { int start = values.getFirstValueIndex(valuesPosition); int end = start + values.getValueCount(valuesPosition); for (int i = start; i < end; i++) { diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopLongFloatAggregator.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopLongFloatAggregator.java index 7d8e6ce5bf805..66d699cfd3d32 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopLongFloatAggregator.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopLongFloatAggregator.java @@ -62,13 +62,7 @@ public static void combine(GroupingState state, int groupId, long v, float outpu state.add(groupId, v, outputValue); } - public static void combineIntermediate( - GroupingState state, - int groupId, - LongBlock values, - FloatBlock outputValues, - int valuesPosition - ) { + public static void combineIntermediate(GroupingState state, int groupId, LongBlock values, FloatBlock outputValues, int valuesPosition) { int start = values.getFirstValueIndex(valuesPosition); int end = start + values.getValueCount(valuesPosition); for (int i = start; i < end; i++) { diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleBucketedSort.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleBucketedSort.java index 995cf68cd6a50..18b10adfb3bdc 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleBucketedSort.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleBucketedSort.java @@ -7,6 +7,7 @@ package org.elasticsearch.compute.data.sort; +// begin generated imports import org.elasticsearch.common.util.BigArrays; import org.elasticsearch.common.util.BitArray; import org.elasticsearch.common.util.DoubleArray; @@ -21,6 +22,7 @@ import org.elasticsearch.search.sort.SortOrder; import java.util.stream.IntStream; +// end generated imports /** * Aggregates the top N {@code double} values per bucket. diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleDoubleBucketedSort.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleDoubleBucketedSort.java index 6f6ad8a870eb8..13e0743102bbd 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleDoubleBucketedSort.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleDoubleBucketedSort.java @@ -7,9 +7,11 @@ package org.elasticsearch.compute.data.sort; +// begin generated imports import org.elasticsearch.common.util.BigArrays; import org.elasticsearch.common.util.BitArray; import org.elasticsearch.common.util.DoubleArray; +import org.elasticsearch.common.util.DoubleArray; import org.elasticsearch.common.util.PageCacheRecycler; import org.elasticsearch.compute.data.Block; import org.elasticsearch.compute.data.BlockFactory; @@ -21,6 +23,7 @@ import org.elasticsearch.search.sort.SortOrder; import java.util.stream.IntStream; +// end generated imports /** * Aggregates the top N {@code double} values per bucket. diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleFloatBucketedSort.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleFloatBucketedSort.java index 53a4cfd1b6ccc..c7ba467561094 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleFloatBucketedSort.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleFloatBucketedSort.java @@ -7,10 +7,11 @@ package org.elasticsearch.compute.data.sort; +// begin generated imports import org.elasticsearch.common.util.BigArrays; import org.elasticsearch.common.util.BitArray; -import org.elasticsearch.common.util.DoubleArray; import org.elasticsearch.common.util.FloatArray; +import org.elasticsearch.common.util.DoubleArray; import org.elasticsearch.common.util.PageCacheRecycler; import org.elasticsearch.compute.data.Block; import org.elasticsearch.compute.data.BlockFactory; @@ -22,6 +23,7 @@ import org.elasticsearch.search.sort.SortOrder; import java.util.stream.IntStream; +// end generated imports /** * Aggregates the top N {@code double} values per bucket. diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleIntBucketedSort.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleIntBucketedSort.java index 502647337a5f4..0453025754edc 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleIntBucketedSort.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleIntBucketedSort.java @@ -7,10 +7,11 @@ package org.elasticsearch.compute.data.sort; +// begin generated imports import org.elasticsearch.common.util.BigArrays; import org.elasticsearch.common.util.BitArray; -import org.elasticsearch.common.util.DoubleArray; import org.elasticsearch.common.util.IntArray; +import org.elasticsearch.common.util.DoubleArray; import org.elasticsearch.common.util.PageCacheRecycler; import org.elasticsearch.compute.data.Block; import org.elasticsearch.compute.data.BlockFactory; @@ -22,6 +23,7 @@ import org.elasticsearch.search.sort.SortOrder; import java.util.stream.IntStream; +// end generated imports /** * Aggregates the top N {@code double} values per bucket. diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleLongBucketedSort.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleLongBucketedSort.java index e1d57a4885c43..7f518e05cfff8 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleLongBucketedSort.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleLongBucketedSort.java @@ -7,10 +7,11 @@ package org.elasticsearch.compute.data.sort; +// begin generated imports import org.elasticsearch.common.util.BigArrays; import org.elasticsearch.common.util.BitArray; -import org.elasticsearch.common.util.DoubleArray; import org.elasticsearch.common.util.LongArray; +import org.elasticsearch.common.util.DoubleArray; import org.elasticsearch.common.util.PageCacheRecycler; import org.elasticsearch.compute.data.Block; import org.elasticsearch.compute.data.BlockFactory; @@ -22,6 +23,7 @@ import org.elasticsearch.search.sort.SortOrder; import java.util.stream.IntStream; +// end generated imports /** * Aggregates the top N {@code double} values per bucket. diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/FloatBucketedSort.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/FloatBucketedSort.java index 5dee9e1555526..d34d6025298af 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/FloatBucketedSort.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/FloatBucketedSort.java @@ -7,6 +7,7 @@ package org.elasticsearch.compute.data.sort; +// begin generated imports import org.elasticsearch.common.util.BigArrays; import org.elasticsearch.common.util.BitArray; import org.elasticsearch.common.util.FloatArray; @@ -21,6 +22,7 @@ import org.elasticsearch.search.sort.SortOrder; import java.util.stream.IntStream; +// end generated imports /** * Aggregates the top N {@code float} values per bucket. diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/FloatDoubleBucketedSort.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/FloatDoubleBucketedSort.java index 9e66583b2373e..a5b9387476a6c 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/FloatDoubleBucketedSort.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/FloatDoubleBucketedSort.java @@ -7,6 +7,7 @@ package org.elasticsearch.compute.data.sort; +// begin generated imports import org.elasticsearch.common.util.BigArrays; import org.elasticsearch.common.util.BitArray; import org.elasticsearch.common.util.DoubleArray; @@ -22,6 +23,7 @@ import org.elasticsearch.search.sort.SortOrder; import java.util.stream.IntStream; +// end generated imports /** * Aggregates the top N {@code float} values per bucket. diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/FloatFloatBucketedSort.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/FloatFloatBucketedSort.java index 86a63e6a5f5de..6007954588c8d 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/FloatFloatBucketedSort.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/FloatFloatBucketedSort.java @@ -7,9 +7,11 @@ package org.elasticsearch.compute.data.sort; +// begin generated imports import org.elasticsearch.common.util.BigArrays; import org.elasticsearch.common.util.BitArray; import org.elasticsearch.common.util.FloatArray; +import org.elasticsearch.common.util.FloatArray; import org.elasticsearch.common.util.PageCacheRecycler; import org.elasticsearch.compute.data.Block; import org.elasticsearch.compute.data.BlockFactory; @@ -21,6 +23,7 @@ import org.elasticsearch.search.sort.SortOrder; import java.util.stream.IntStream; +// end generated imports /** * Aggregates the top N {@code float} values per bucket. diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/FloatIntBucketedSort.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/FloatIntBucketedSort.java index a4bc8d96de0d3..7e2bd07e982cf 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/FloatIntBucketedSort.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/FloatIntBucketedSort.java @@ -7,10 +7,11 @@ package org.elasticsearch.compute.data.sort; +// begin generated imports import org.elasticsearch.common.util.BigArrays; import org.elasticsearch.common.util.BitArray; -import org.elasticsearch.common.util.FloatArray; import org.elasticsearch.common.util.IntArray; +import org.elasticsearch.common.util.FloatArray; import org.elasticsearch.common.util.PageCacheRecycler; import org.elasticsearch.compute.data.Block; import org.elasticsearch.compute.data.BlockFactory; @@ -22,6 +23,7 @@ import org.elasticsearch.search.sort.SortOrder; import java.util.stream.IntStream; +// end generated imports /** * Aggregates the top N {@code float} values per bucket. diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/FloatLongBucketedSort.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/FloatLongBucketedSort.java index b6c185ee58ca5..22879a5dfc4c6 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/FloatLongBucketedSort.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/FloatLongBucketedSort.java @@ -7,10 +7,11 @@ package org.elasticsearch.compute.data.sort; +// begin generated imports import org.elasticsearch.common.util.BigArrays; import org.elasticsearch.common.util.BitArray; -import org.elasticsearch.common.util.FloatArray; import org.elasticsearch.common.util.LongArray; +import org.elasticsearch.common.util.FloatArray; import org.elasticsearch.common.util.PageCacheRecycler; import org.elasticsearch.compute.data.Block; import org.elasticsearch.compute.data.BlockFactory; @@ -22,6 +23,7 @@ import org.elasticsearch.search.sort.SortOrder; import java.util.stream.IntStream; +// end generated imports /** * Aggregates the top N {@code float} values per bucket. diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/IntBucketedSort.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/IntBucketedSort.java index 7dcec4461f0a5..fdc7ee9990eb3 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/IntBucketedSort.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/IntBucketedSort.java @@ -7,6 +7,7 @@ package org.elasticsearch.compute.data.sort; +// begin generated imports import org.elasticsearch.common.util.BigArrays; import org.elasticsearch.common.util.BitArray; import org.elasticsearch.common.util.IntArray; @@ -21,6 +22,7 @@ import org.elasticsearch.search.sort.SortOrder; import java.util.stream.IntStream; +// end generated imports /** * Aggregates the top N {@code int} values per bucket. diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/IntDoubleBucketedSort.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/IntDoubleBucketedSort.java index 9692a3490add6..52446bcf970a5 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/IntDoubleBucketedSort.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/IntDoubleBucketedSort.java @@ -7,6 +7,7 @@ package org.elasticsearch.compute.data.sort; +// begin generated imports import org.elasticsearch.common.util.BigArrays; import org.elasticsearch.common.util.BitArray; import org.elasticsearch.common.util.DoubleArray; @@ -22,6 +23,7 @@ import org.elasticsearch.search.sort.SortOrder; import java.util.stream.IntStream; +// end generated imports /** * Aggregates the top N {@code int} values per bucket. diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/IntFloatBucketedSort.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/IntFloatBucketedSort.java index 756f9894d887a..6253527023abd 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/IntFloatBucketedSort.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/IntFloatBucketedSort.java @@ -7,6 +7,7 @@ package org.elasticsearch.compute.data.sort; +// begin generated imports import org.elasticsearch.common.util.BigArrays; import org.elasticsearch.common.util.BitArray; import org.elasticsearch.common.util.FloatArray; @@ -22,6 +23,7 @@ import org.elasticsearch.search.sort.SortOrder; import java.util.stream.IntStream; +// end generated imports /** * Aggregates the top N {@code int} values per bucket. diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/IntIntBucketedSort.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/IntIntBucketedSort.java index d3eb3e2a2b16f..43b794c4ab8b9 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/IntIntBucketedSort.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/IntIntBucketedSort.java @@ -7,9 +7,11 @@ package org.elasticsearch.compute.data.sort; +// begin generated imports import org.elasticsearch.common.util.BigArrays; import org.elasticsearch.common.util.BitArray; import org.elasticsearch.common.util.IntArray; +import org.elasticsearch.common.util.IntArray; import org.elasticsearch.common.util.PageCacheRecycler; import org.elasticsearch.compute.data.Block; import org.elasticsearch.compute.data.BlockFactory; @@ -21,6 +23,7 @@ import org.elasticsearch.search.sort.SortOrder; import java.util.stream.IntStream; +// end generated imports /** * Aggregates the top N {@code int} values per bucket. diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/IntLongBucketedSort.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/IntLongBucketedSort.java index 6f7a04ce801bd..727747a11e33f 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/IntLongBucketedSort.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/IntLongBucketedSort.java @@ -7,10 +7,11 @@ package org.elasticsearch.compute.data.sort; +// begin generated imports import org.elasticsearch.common.util.BigArrays; import org.elasticsearch.common.util.BitArray; -import org.elasticsearch.common.util.IntArray; import org.elasticsearch.common.util.LongArray; +import org.elasticsearch.common.util.IntArray; import org.elasticsearch.common.util.PageCacheRecycler; import org.elasticsearch.compute.data.Block; import org.elasticsearch.compute.data.BlockFactory; @@ -22,6 +23,7 @@ import org.elasticsearch.search.sort.SortOrder; import java.util.stream.IntStream; +// end generated imports /** * Aggregates the top N {@code int} values per bucket. diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/LongBucketedSort.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/LongBucketedSort.java index e10ce05017d23..ec5fe667c61bb 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/LongBucketedSort.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/LongBucketedSort.java @@ -7,6 +7,7 @@ package org.elasticsearch.compute.data.sort; +// begin generated imports import org.elasticsearch.common.util.BigArrays; import org.elasticsearch.common.util.BitArray; import org.elasticsearch.common.util.LongArray; @@ -21,6 +22,7 @@ import org.elasticsearch.search.sort.SortOrder; import java.util.stream.IntStream; +// end generated imports /** * Aggregates the top N {@code long} values per bucket. diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/LongDoubleBucketedSort.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/LongDoubleBucketedSort.java index dd7bf77eaf6f6..7eb37a5157ac9 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/LongDoubleBucketedSort.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/LongDoubleBucketedSort.java @@ -7,6 +7,7 @@ package org.elasticsearch.compute.data.sort; +// begin generated imports import org.elasticsearch.common.util.BigArrays; import org.elasticsearch.common.util.BitArray; import org.elasticsearch.common.util.DoubleArray; @@ -22,6 +23,7 @@ import org.elasticsearch.search.sort.SortOrder; import java.util.stream.IntStream; +// end generated imports /** * Aggregates the top N {@code long} values per bucket. diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/LongFloatBucketedSort.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/LongFloatBucketedSort.java index db4d25aecfa74..cb2784b8567bc 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/LongFloatBucketedSort.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/LongFloatBucketedSort.java @@ -7,6 +7,7 @@ package org.elasticsearch.compute.data.sort; +// begin generated imports import org.elasticsearch.common.util.BigArrays; import org.elasticsearch.common.util.BitArray; import org.elasticsearch.common.util.FloatArray; @@ -22,6 +23,7 @@ import org.elasticsearch.search.sort.SortOrder; import java.util.stream.IntStream; +// end generated imports /** * Aggregates the top N {@code long} values per bucket. diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/LongIntBucketedSort.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/LongIntBucketedSort.java index 8e22b27791a2c..1fa12a4c500ec 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/LongIntBucketedSort.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/LongIntBucketedSort.java @@ -7,6 +7,7 @@ package org.elasticsearch.compute.data.sort; +// begin generated imports import org.elasticsearch.common.util.BigArrays; import org.elasticsearch.common.util.BitArray; import org.elasticsearch.common.util.IntArray; @@ -22,6 +23,7 @@ import org.elasticsearch.search.sort.SortOrder; import java.util.stream.IntStream; +// end generated imports /** * Aggregates the top N {@code long} values per bucket. diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/LongLongBucketedSort.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/LongLongBucketedSort.java index 49a824e0c88b0..5a16a56aaa9bf 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/LongLongBucketedSort.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/LongLongBucketedSort.java @@ -7,6 +7,7 @@ package org.elasticsearch.compute.data.sort; +// begin generated imports import org.elasticsearch.common.util.BigArrays; import org.elasticsearch.common.util.BitArray; import org.elasticsearch.common.util.LongArray; @@ -21,6 +22,7 @@ import org.elasticsearch.search.sort.SortOrder; import java.util.stream.IntStream; +// end generated imports /** * Aggregates the top N {@code long} values per bucket. diff --git a/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/data/sort/X-BucketedSort.java.st b/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/data/sort/X-BucketedSort.java.st index 70d7c5fb3f5e7..6afdb325402ae 100644 --- a/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/data/sort/X-BucketedSort.java.st +++ b/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/data/sort/X-BucketedSort.java.st @@ -7,6 +7,7 @@ package org.elasticsearch.compute.data.sort; +// begin generated imports import org.elasticsearch.common.util.BigArrays; import org.elasticsearch.common.util.BitArray; $if(hasExtra && !(long && Extralong))$ @@ -24,6 +25,7 @@ import org.elasticsearch.search.sort.BucketedSort; import org.elasticsearch.search.sort.SortOrder; import java.util.stream.IntStream; +// end generated imports /** * Aggregates the top N {@code $type$} values per bucket. From 7055231b8a159c2f412ed259356fb19ceaed81e2 Mon Sep 17 00:00:00 2001 From: elasticsearchmachine Date: Tue, 28 Oct 2025 14:27:00 +0000 Subject: [PATCH 16/16] [CI] Auto commit changes from spotless --- .../compute/aggregation/TopDoubleDoubleAggregator.java | 8 +++++++- .../compute/aggregation/TopDoubleFloatAggregator.java | 8 +++++++- .../compute/aggregation/TopDoubleIntAggregator.java | 8 +++++++- .../compute/aggregation/TopDoubleLongAggregator.java | 8 +++++++- .../compute/aggregation/TopFloatDoubleAggregator.java | 8 +++++++- .../compute/aggregation/TopFloatFloatAggregator.java | 8 +++++++- .../compute/aggregation/TopFloatLongAggregator.java | 8 +++++++- .../compute/aggregation/TopIntDoubleAggregator.java | 8 +++++++- .../compute/aggregation/TopLongDoubleAggregator.java | 8 +++++++- .../compute/aggregation/TopLongFloatAggregator.java | 8 +++++++- 10 files changed, 70 insertions(+), 10 deletions(-) diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopDoubleDoubleAggregator.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopDoubleDoubleAggregator.java index 45cd12e43c182..5f0c40496c8cc 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopDoubleDoubleAggregator.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopDoubleDoubleAggregator.java @@ -62,7 +62,13 @@ public static void combine(GroupingState state, int groupId, double v, double ou state.add(groupId, v, outputValue); } - public static void combineIntermediate(GroupingState state, int groupId, DoubleBlock values, DoubleBlock outputValues, int valuesPosition) { + public static void combineIntermediate( + GroupingState state, + int groupId, + DoubleBlock values, + DoubleBlock outputValues, + int valuesPosition + ) { int start = values.getFirstValueIndex(valuesPosition); int end = start + values.getValueCount(valuesPosition); for (int i = start; i < end; i++) { diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopDoubleFloatAggregator.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopDoubleFloatAggregator.java index da103d70c0a54..d4a775b37fbc0 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopDoubleFloatAggregator.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopDoubleFloatAggregator.java @@ -62,7 +62,13 @@ public static void combine(GroupingState state, int groupId, double v, float out state.add(groupId, v, outputValue); } - public static void combineIntermediate(GroupingState state, int groupId, DoubleBlock values, FloatBlock outputValues, int valuesPosition) { + public static void combineIntermediate( + GroupingState state, + int groupId, + DoubleBlock values, + FloatBlock outputValues, + int valuesPosition + ) { int start = values.getFirstValueIndex(valuesPosition); int end = start + values.getValueCount(valuesPosition); for (int i = start; i < end; i++) { diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopDoubleIntAggregator.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopDoubleIntAggregator.java index 2b0790c303e59..b0f17eb3bcff3 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopDoubleIntAggregator.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopDoubleIntAggregator.java @@ -62,7 +62,13 @@ public static void combine(GroupingState state, int groupId, double v, int outpu state.add(groupId, v, outputValue); } - public static void combineIntermediate(GroupingState state, int groupId, DoubleBlock values, IntBlock outputValues, int valuesPosition) { + public static void combineIntermediate( + GroupingState state, + int groupId, + DoubleBlock values, + IntBlock outputValues, + int valuesPosition + ) { int start = values.getFirstValueIndex(valuesPosition); int end = start + values.getValueCount(valuesPosition); for (int i = start; i < end; i++) { diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopDoubleLongAggregator.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopDoubleLongAggregator.java index 57dd898fce1e4..dc745b7e954b4 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopDoubleLongAggregator.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopDoubleLongAggregator.java @@ -62,7 +62,13 @@ public static void combine(GroupingState state, int groupId, double v, long outp state.add(groupId, v, outputValue); } - public static void combineIntermediate(GroupingState state, int groupId, DoubleBlock values, LongBlock outputValues, int valuesPosition) { + public static void combineIntermediate( + GroupingState state, + int groupId, + DoubleBlock values, + LongBlock outputValues, + int valuesPosition + ) { int start = values.getFirstValueIndex(valuesPosition); int end = start + values.getValueCount(valuesPosition); for (int i = start; i < end; i++) { diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopFloatDoubleAggregator.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopFloatDoubleAggregator.java index ae4ba17da2529..d79dc9fa99e1e 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopFloatDoubleAggregator.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopFloatDoubleAggregator.java @@ -62,7 +62,13 @@ public static void combine(GroupingState state, int groupId, float v, double out state.add(groupId, v, outputValue); } - public static void combineIntermediate(GroupingState state, int groupId, FloatBlock values, DoubleBlock outputValues, int valuesPosition) { + public static void combineIntermediate( + GroupingState state, + int groupId, + FloatBlock values, + DoubleBlock outputValues, + int valuesPosition + ) { int start = values.getFirstValueIndex(valuesPosition); int end = start + values.getValueCount(valuesPosition); for (int i = start; i < end; i++) { diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopFloatFloatAggregator.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopFloatFloatAggregator.java index e2876b5cddffa..955f6d9609623 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopFloatFloatAggregator.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopFloatFloatAggregator.java @@ -62,7 +62,13 @@ public static void combine(GroupingState state, int groupId, float v, float outp state.add(groupId, v, outputValue); } - public static void combineIntermediate(GroupingState state, int groupId, FloatBlock values, FloatBlock outputValues, int valuesPosition) { + public static void combineIntermediate( + GroupingState state, + int groupId, + FloatBlock values, + FloatBlock outputValues, + int valuesPosition + ) { int start = values.getFirstValueIndex(valuesPosition); int end = start + values.getValueCount(valuesPosition); for (int i = start; i < end; i++) { diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopFloatLongAggregator.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopFloatLongAggregator.java index 580d649abae42..ef2432265d570 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopFloatLongAggregator.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopFloatLongAggregator.java @@ -62,7 +62,13 @@ public static void combine(GroupingState state, int groupId, float v, long outpu state.add(groupId, v, outputValue); } - public static void combineIntermediate(GroupingState state, int groupId, FloatBlock values, LongBlock outputValues, int valuesPosition) { + public static void combineIntermediate( + GroupingState state, + int groupId, + FloatBlock values, + LongBlock outputValues, + int valuesPosition + ) { int start = values.getFirstValueIndex(valuesPosition); int end = start + values.getValueCount(valuesPosition); for (int i = start; i < end; i++) { diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopIntDoubleAggregator.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopIntDoubleAggregator.java index 10090a179b5bb..8d5558d555ec4 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopIntDoubleAggregator.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopIntDoubleAggregator.java @@ -62,7 +62,13 @@ public static void combine(GroupingState state, int groupId, int v, double outpu state.add(groupId, v, outputValue); } - public static void combineIntermediate(GroupingState state, int groupId, IntBlock values, DoubleBlock outputValues, int valuesPosition) { + public static void combineIntermediate( + GroupingState state, + int groupId, + IntBlock values, + DoubleBlock outputValues, + int valuesPosition + ) { int start = values.getFirstValueIndex(valuesPosition); int end = start + values.getValueCount(valuesPosition); for (int i = start; i < end; i++) { diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopLongDoubleAggregator.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopLongDoubleAggregator.java index 31c4f9096ca0e..c35db6fc8aed0 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopLongDoubleAggregator.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopLongDoubleAggregator.java @@ -62,7 +62,13 @@ public static void combine(GroupingState state, int groupId, long v, double outp state.add(groupId, v, outputValue); } - public static void combineIntermediate(GroupingState state, int groupId, LongBlock values, DoubleBlock outputValues, int valuesPosition) { + public static void combineIntermediate( + GroupingState state, + int groupId, + LongBlock values, + DoubleBlock outputValues, + int valuesPosition + ) { int start = values.getFirstValueIndex(valuesPosition); int end = start + values.getValueCount(valuesPosition); for (int i = start; i < end; i++) { diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopLongFloatAggregator.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopLongFloatAggregator.java index 66d699cfd3d32..7d8e6ce5bf805 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopLongFloatAggregator.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/TopLongFloatAggregator.java @@ -62,7 +62,13 @@ public static void combine(GroupingState state, int groupId, long v, float outpu state.add(groupId, v, outputValue); } - public static void combineIntermediate(GroupingState state, int groupId, LongBlock values, FloatBlock outputValues, int valuesPosition) { + public static void combineIntermediate( + GroupingState state, + int groupId, + LongBlock values, + FloatBlock outputValues, + int valuesPosition + ) { int start = values.getFirstValueIndex(valuesPosition); int end = start + values.getValueCount(valuesPosition); for (int i = start; i < end; i++) {