From ad8aead8ad3f7d9e90d60888733fc78dd7dc23d5 Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Sun, 21 Sep 2025 13:03:06 -0400 Subject: [PATCH 1/3] WIP --- .../elasticsearch/compute/ann/Position.java | 23 ++++ .../compute/gen/AggregatorImplementer.java | 34 ++---- .../compute/gen/ConsumeProcessor.java | 4 +- .../compute/gen/EvaluatorImplementer.java | 3 + .../gen/GroupingAggregatorImplementer.java | 41 +++---- .../compute/gen/argument/Argument.java | 7 ++ .../gen/argument/PositionArgument.java | 108 ++++++++++++++++++ ...esianShapeDocValuesAggregatorFunction.java | 16 +-- ...peDocValuesGroupingAggregatorFunction.java | 24 +--- ...ntGeoShapeDocValuesAggregatorFunction.java | 16 +-- ...peDocValuesGroupingAggregatorFunction.java | 24 +--- ...tentCartesianShapeDocValuesAggregator.java | 10 +- ...tialExtentGeoShapeDocValuesAggregator.java | 10 +- .../spatial/SpatialExtentGroupingState.java | 32 +++--- ...entGroupingStateWrappedLongitudeState.java | 20 ++-- .../spatial/SpatialExtentState.java | 32 +++--- ...atialExtentStateWrappedLongitudeState.java | 20 ++-- .../function/scalar/multivalue/MvAppend.java | 11 +- .../multivalue/MvPSeriesWeightedSum.java | 3 +- .../scalar/multivalue/MvPercentile.java | 7 +- .../function/scalar/multivalue/MvSlice.java | 11 +- .../function/scalar/multivalue/MvZip.java | 3 +- .../function/scalar/spatial/StDistance.java | 22 ++-- 23 files changed, 285 insertions(+), 196 deletions(-) create mode 100644 x-pack/plugin/esql/compute/ann/src/main/java/org/elasticsearch/compute/ann/Position.java create mode 100644 x-pack/plugin/esql/compute/gen/src/main/java/org/elasticsearch/compute/gen/argument/PositionArgument.java diff --git a/x-pack/plugin/esql/compute/ann/src/main/java/org/elasticsearch/compute/ann/Position.java b/x-pack/plugin/esql/compute/ann/src/main/java/org/elasticsearch/compute/ann/Position.java new file mode 100644 index 0000000000000..78bfe7f644a6a --- /dev/null +++ b/x-pack/plugin/esql/compute/ann/src/main/java/org/elasticsearch/compute/ann/Position.java @@ -0,0 +1,23 @@ +/* + * 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.ann; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Used on parameters on methods annotated with {@link Evaluator} or in + * {@link Aggregator} or {@link GroupingAggregator} to indicate an argument + * that is the position in a block. + */ +@Target(ElementType.PARAMETER) +@Retention(RetentionPolicy.SOURCE) +public @interface Position { +} diff --git a/x-pack/plugin/esql/compute/gen/src/main/java/org/elasticsearch/compute/gen/AggregatorImplementer.java b/x-pack/plugin/esql/compute/gen/src/main/java/org/elasticsearch/compute/gen/AggregatorImplementer.java index f7bd4d0695aed..2ad45561a7d9d 100644 --- a/x-pack/plugin/esql/compute/gen/src/main/java/org/elasticsearch/compute/gen/AggregatorImplementer.java +++ b/x-pack/plugin/esql/compute/gen/src/main/java/org/elasticsearch/compute/gen/AggregatorImplementer.java @@ -19,7 +19,8 @@ import org.elasticsearch.compute.ann.IntermediateState; import org.elasticsearch.compute.gen.Methods.TypeMatcher; import org.elasticsearch.compute.gen.argument.Argument; -import org.elasticsearch.compute.gen.argument.ArrayArgument; +import org.elasticsearch.compute.gen.argument.BlockArgument; +import org.elasticsearch.compute.gen.argument.PositionArgument; import org.elasticsearch.compute.gen.argument.StandardArgument; import java.util.ArrayList; @@ -110,12 +111,13 @@ public AggregatorImplementer( requireName("combine"), requireArgsStartsWith(requireType(aggState.declaredType()), requireAnyType("")) ); - this.aggParams = combine.getParameters().stream().skip(1).map(v -> { + this.aggParams = combine.getParameters().stream().skip(1).flatMap(v -> { Argument a = Argument.fromParameter(types, v); return switch (a) { - case StandardArgument sa -> new AggregationParameter(sa.name(), sa.type(), false); - case ArrayArgument aa -> new AggregationParameter(aa.name(), aa.componentType(), true); - default -> throw new IllegalArgumentException("unsupported argument [" + a + "]"); + case StandardArgument sa -> Stream.of(new AggregationParameter(sa.name(), sa.type(), false)); + case BlockArgument ba -> Stream.of(new AggregationParameter(ba.name(), Types.elementType(ba.type()), true)); + case PositionArgument pa -> Stream.of(); + default -> throw new IllegalArgumentException("unsupported argument [" + declarationType + "][" + a + "]"); }; }).toList(); @@ -435,22 +437,10 @@ private MethodSpec addRawBlock(boolean masked) { if (aggParams.size() > 1) { throw new IllegalArgumentException("array mode not supported for multiple args"); } - builder.addStatement("int start = $L.getFirstValueIndex(p)", aggParams.getFirst().blockName()); - builder.addStatement("int end = start + $L.getValueCount(p)", aggParams.getFirst().blockName()); - // TODO move this to the top of the loop - builder.addStatement( - "$L[] valuesArray = new $L[end - start]", - aggParams.getFirst().arrayType(), - aggParams.getFirst().arrayType() + warningsBlock( + builder, + () -> builder.addStatement("$T.combine(state, p, $L)", declarationType, aggParams.getFirst().blockName()) ); - builder.beginControlFlow("for (int i = start; i < end; i++)"); - builder.addStatement( - "valuesArray[i-start] = $L.get$L(i)", - aggParams.getFirst().blockName(), - capitalize(aggParams.getFirst().arrayType()) - ); - builder.endControlFlow(); - combineRawInputForArray(builder, "valuesArray"); } else { if (first == null && aggState.hasSeen()) { builder.addStatement("state.seen(true)"); @@ -547,10 +537,6 @@ private void invokeCombineRawInput(TypeName returnType, MethodSpec.Builder build builder.addStatement(pattern.toString(), params.toArray()); } - private void combineRawInputForArray(MethodSpec.Builder builder, String arrayVariable) { - warningsBlock(builder, () -> builder.addStatement("$T.combine(state, $L)", declarationType, arrayVariable)); - } - private void warningsBlock(MethodSpec.Builder builder, Runnable block) { if (warnExceptions.isEmpty() == false) { builder.beginControlFlow("try"); diff --git a/x-pack/plugin/esql/compute/gen/src/main/java/org/elasticsearch/compute/gen/ConsumeProcessor.java b/x-pack/plugin/esql/compute/gen/src/main/java/org/elasticsearch/compute/gen/ConsumeProcessor.java index 1321fbd172a50..98cbf62b24653 100644 --- a/x-pack/plugin/esql/compute/gen/src/main/java/org/elasticsearch/compute/gen/ConsumeProcessor.java +++ b/x-pack/plugin/esql/compute/gen/src/main/java/org/elasticsearch/compute/gen/ConsumeProcessor.java @@ -8,6 +8,7 @@ package org.elasticsearch.compute.gen; import org.elasticsearch.compute.ann.Fixed; +import org.elasticsearch.compute.ann.Position; import java.util.List; import java.util.Set; @@ -44,7 +45,8 @@ public Set getSupportedAnnotationTypes() { "org.elasticsearch.xpack.esql.expression.function.MapParam", "org.elasticsearch.rest.ServerlessScope", "org.elasticsearch.xcontent.ParserConstructor", - Fixed.class.getName() + Fixed.class.getName(), + Position.class.getName() ); } diff --git a/x-pack/plugin/esql/compute/gen/src/main/java/org/elasticsearch/compute/gen/EvaluatorImplementer.java b/x-pack/plugin/esql/compute/gen/src/main/java/org/elasticsearch/compute/gen/EvaluatorImplementer.java index 06e4c79dc1dae..665b3e2644cbe 100644 --- a/x-pack/plugin/esql/compute/gen/src/main/java/org/elasticsearch/compute/gen/EvaluatorImplementer.java +++ b/x-pack/plugin/esql/compute/gen/src/main/java/org/elasticsearch/compute/gen/EvaluatorImplementer.java @@ -66,6 +66,9 @@ public EvaluatorImplementer( elements.getPackageOf(declarationType).toString(), declarationType.getSimpleName() + extraName + "Evaluator" ); + if (this.processFunction.hasBlockType) { + System.err.println("ADFADSF " + declarationType); + } this.processOutputsMultivalued = this.processFunction.hasBlockType && (this.processFunction.builderArg != null); } diff --git a/x-pack/plugin/esql/compute/gen/src/main/java/org/elasticsearch/compute/gen/GroupingAggregatorImplementer.java b/x-pack/plugin/esql/compute/gen/src/main/java/org/elasticsearch/compute/gen/GroupingAggregatorImplementer.java index 3a8a780e5f81e..a6669f895bb16 100644 --- a/x-pack/plugin/esql/compute/gen/src/main/java/org/elasticsearch/compute/gen/GroupingAggregatorImplementer.java +++ b/x-pack/plugin/esql/compute/gen/src/main/java/org/elasticsearch/compute/gen/GroupingAggregatorImplementer.java @@ -20,7 +20,8 @@ import org.elasticsearch.compute.gen.AggregatorImplementer.AggregationParameter; import org.elasticsearch.compute.gen.AggregatorImplementer.AggregationState; import org.elasticsearch.compute.gen.argument.Argument; -import org.elasticsearch.compute.gen.argument.ArrayArgument; +import org.elasticsearch.compute.gen.argument.BlockArgument; +import org.elasticsearch.compute.gen.argument.PositionArgument; import org.elasticsearch.compute.gen.argument.StandardArgument; import java.util.ArrayList; @@ -37,7 +38,6 @@ import javax.lang.model.util.Elements; import static java.util.stream.Collectors.joining; -import static org.elasticsearch.compute.gen.AggregatorImplementer.capitalize; import static org.elasticsearch.compute.gen.Methods.optionalStaticMethod; import static org.elasticsearch.compute.gen.Methods.requireAnyArgs; import static org.elasticsearch.compute.gen.Methods.requireAnyType; @@ -118,12 +118,13 @@ public GroupingAggregatorImplementer( requireName("combine"), combineArgs(aggState) ); - this.aggParams = combine.getParameters().stream().skip(aggState.declaredType().isPrimitive() ? 1 : 2).map(v -> { + this.aggParams = combine.getParameters().stream().skip(aggState.declaredType().isPrimitive() ? 1 : 2).flatMap(v -> { Argument a = Argument.fromParameter(types, v); return switch (a) { - case StandardArgument sa -> new AggregationParameter(sa.name(), sa.type(), false); - case ArrayArgument aa -> new AggregationParameter(aa.name(), aa.componentType(), true); - default -> throw new IllegalArgumentException("unsupported argument [" + a + "]"); + case StandardArgument sa -> Stream.of(new AggregationParameter(sa.name(), sa.type(), false)); + case BlockArgument ba -> Stream.of(new AggregationParameter(ba.name(), Types.elementType(ba.type()), true)); + case PositionArgument pa -> Stream.of(); + default -> throw new IllegalArgumentException("unsupported argument [" + declarationType + "][" + a + "]"); }; }).toList(); @@ -476,21 +477,14 @@ private MethodSpec addRawInputLoop(TypeName groupsType, boolean valuesAreVector) if (aggParams.size() > 1) { throw new IllegalArgumentException("array mode not supported for multiple args"); } - String arrayType = aggParams.getFirst().type().toString().replace("[]", ""); - builder.addStatement("int valuesStart = $L.getFirstValueIndex(valuesPosition)", aggParams.getFirst().blockName()); - builder.addStatement( - "int valuesEnd = valuesStart + $L.getValueCount(valuesPosition)", - aggParams.getFirst().blockName() - ); - builder.addStatement("$L[] valuesArray = new $L[valuesEnd - valuesStart]", arrayType, arrayType); - builder.beginControlFlow("for (int v = valuesStart; v < valuesEnd; v++)"); - builder.addStatement( - "valuesArray[v-valuesStart] = $L.get$L(v)", - aggParams.getFirst().blockName(), - capitalize(aggParams.getFirst().arrayType()) + warningsBlock( + builder, + () -> builder.addStatement( + "$T.combine(state, groupId, valuesPosition, $L)", + declarationType, + aggParams.getFirst().blockName() + ) ); - builder.endControlFlow(); - combineRawInputForArray(builder, "valuesArray"); } else { for (AggregationParameter p : aggParams) { builder.addStatement("int $L = $L.getFirstValueIndex(valuesPosition)", p.startName(), p.blockName()); @@ -536,6 +530,9 @@ private void invokeCombineRawInput(TypeName returnType, MethodSpec.Builder build pattern.append("$T.combine(state, groupId"); params.add(declarationType); } + if (aggParams.getFirst().isArray()) { + pattern.append(", p"); + } for (AggregationParameter p : aggParams) { pattern.append(", $L"); params.add(p.valueName()); @@ -547,10 +544,6 @@ private void invokeCombineRawInput(TypeName returnType, MethodSpec.Builder build builder.addStatement(pattern.toString(), params.toArray()); } - private void combineRawInputForArray(MethodSpec.Builder builder, String arrayVariable) { - warningsBlock(builder, () -> builder.addStatement("$T.combine(state, groupId, $L)", declarationType, arrayVariable)); - } - private boolean shouldWrapAddInput(boolean valuesAreVector) { return optionalStaticMethod( declarationType, diff --git a/x-pack/plugin/esql/compute/gen/src/main/java/org/elasticsearch/compute/gen/argument/Argument.java b/x-pack/plugin/esql/compute/gen/src/main/java/org/elasticsearch/compute/gen/argument/Argument.java index dbb89a3eb4165..56777ea46b985 100644 --- a/x-pack/plugin/esql/compute/gen/src/main/java/org/elasticsearch/compute/gen/argument/Argument.java +++ b/x-pack/plugin/esql/compute/gen/src/main/java/org/elasticsearch/compute/gen/argument/Argument.java @@ -13,6 +13,7 @@ import com.squareup.javapoet.TypeSpec; import org.elasticsearch.compute.ann.Fixed; +import org.elasticsearch.compute.ann.Position; import org.elasticsearch.compute.gen.Types; import java.util.List; @@ -41,6 +42,12 @@ static Argument fromParameter(javax.lang.model.util.Types types, VariableElement Types.extendsSuper(types, v.asType(), "org.elasticsearch.core.Releasable") ); } + + Position position = v.getAnnotation(Position.class); + if (position != null) { + return new PositionArgument(); + } + if (type instanceof ClassName c && c.simpleName().equals("Builder") && c.enclosingClassName() != null diff --git a/x-pack/plugin/esql/compute/gen/src/main/java/org/elasticsearch/compute/gen/argument/PositionArgument.java b/x-pack/plugin/esql/compute/gen/src/main/java/org/elasticsearch/compute/gen/argument/PositionArgument.java new file mode 100644 index 0000000000000..7f40a87c68efa --- /dev/null +++ b/x-pack/plugin/esql/compute/gen/src/main/java/org/elasticsearch/compute/gen/argument/PositionArgument.java @@ -0,0 +1,108 @@ +/* + * 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.gen.argument; + +import com.squareup.javapoet.MethodSpec; +import com.squareup.javapoet.TypeName; +import com.squareup.javapoet.TypeSpec; + +import java.util.List; + +/** + * The position in a block. + */ +public record PositionArgument() implements Argument { + @Override + public TypeName dataType(boolean blockStyle) { + return TypeName.INT; + } + + @Override + public String paramName(boolean blockStyle) { + // No need to pass it + return null; + } + + @Override + public void declareField(TypeSpec.Builder builder) { + // Nothing to do + } + + @Override + public void declareFactoryField(TypeSpec.Builder builder) { + // Nothing to do + } + + @Override + public void implementCtor(MethodSpec.Builder builder) { + // Nothing to do + } + + @Override + public void implementFactoryCtor(MethodSpec.Builder builder) { + // Nothing to do + } + + @Override + public String factoryInvocation(MethodSpec.Builder factoryMethodBuilder) { + return null; + } + + @Override + public void evalToBlock(MethodSpec.Builder builder) { + // nothing to do + } + + @Override + public void closeEvalToBlock(MethodSpec.Builder builder) { + // nothing to do + } + + @Override + public void resolveVectors(MethodSpec.Builder builder, String invokeBlockEval) { + // nothing to do + } + + @Override + public void createScratch(MethodSpec.Builder builder) { + // nothing to do + } + + @Override + public void skipNull(MethodSpec.Builder builder) { + // nothing to do + } + + @Override + public void allBlocksAreNull(MethodSpec.Builder builder) { + // nothing to do + } + + @Override + public void read(MethodSpec.Builder builder, boolean blockStyle) { + // nothing to do + } + + @Override + public void buildInvocation(StringBuilder pattern, List args, boolean blockStyle) { + pattern.append("p"); + } + + @Override + public void buildToStringInvocation(StringBuilder pattern, List args, String prefix) { + // nothing to do + } + + @Override + public String closeInvocation() { + return null; + } + + @Override + public void sumBaseRamBytesUsed(MethodSpec.Builder builder) {} +} diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/spatial/SpatialExtentCartesianShapeDocValuesAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/spatial/SpatialExtentCartesianShapeDocValuesAggregatorFunction.java index 0a4fdd3cd1e55..375a55ab21a4b 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/spatial/SpatialExtentCartesianShapeDocValuesAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/spatial/SpatialExtentCartesianShapeDocValuesAggregatorFunction.java @@ -101,13 +101,7 @@ private void addRawBlock(IntBlock valuesBlock) { if (valuesBlock.isNull(p)) { continue; } - int start = valuesBlock.getFirstValueIndex(p); - int end = start + valuesBlock.getValueCount(p); - int[] valuesArray = new int[end - start]; - for (int i = start; i < end; i++) { - valuesArray[i-start] = valuesBlock.getInt(i); - } - SpatialExtentCartesianShapeDocValuesAggregator.combine(state, valuesArray); + SpatialExtentCartesianShapeDocValuesAggregator.combine(state, p, valuesBlock); } } @@ -119,13 +113,7 @@ private void addRawBlock(IntBlock valuesBlock, BooleanVector mask) { if (valuesBlock.isNull(p)) { continue; } - int start = valuesBlock.getFirstValueIndex(p); - int end = start + valuesBlock.getValueCount(p); - int[] valuesArray = new int[end - start]; - for (int i = start; i < end; i++) { - valuesArray[i-start] = valuesBlock.getInt(i); - } - SpatialExtentCartesianShapeDocValuesAggregator.combine(state, valuesArray); + SpatialExtentCartesianShapeDocValuesAggregator.combine(state, p, valuesBlock); } } diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/spatial/SpatialExtentCartesianShapeDocValuesGroupingAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/spatial/SpatialExtentCartesianShapeDocValuesGroupingAggregatorFunction.java index 3d4be828e3132..fe582508e5f34 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/spatial/SpatialExtentCartesianShapeDocValuesGroupingAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/spatial/SpatialExtentCartesianShapeDocValuesGroupingAggregatorFunction.java @@ -123,13 +123,7 @@ private void addRawInput(int positionOffset, IntArrayBlock groups, IntBlock valu int groupEnd = groupStart + groups.getValueCount(groupPosition); for (int g = groupStart; g < groupEnd; g++) { int groupId = groups.getInt(g); - int valuesStart = valuesBlock.getFirstValueIndex(valuesPosition); - int valuesEnd = valuesStart + valuesBlock.getValueCount(valuesPosition); - int[] valuesArray = new int[valuesEnd - valuesStart]; - for (int v = valuesStart; v < valuesEnd; v++) { - valuesArray[v-valuesStart] = valuesBlock.getInt(v); - } - SpatialExtentCartesianShapeDocValuesAggregator.combine(state, groupId, valuesArray); + SpatialExtentCartesianShapeDocValuesAggregator.combine(state, groupId, valuesPosition, valuesBlock); } } } @@ -190,13 +184,7 @@ private void addRawInput(int positionOffset, IntBigArrayBlock groups, IntBlock v int groupEnd = groupStart + groups.getValueCount(groupPosition); for (int g = groupStart; g < groupEnd; g++) { int groupId = groups.getInt(g); - int valuesStart = valuesBlock.getFirstValueIndex(valuesPosition); - int valuesEnd = valuesStart + valuesBlock.getValueCount(valuesPosition); - int[] valuesArray = new int[valuesEnd - valuesStart]; - for (int v = valuesStart; v < valuesEnd; v++) { - valuesArray[v-valuesStart] = valuesBlock.getInt(v); - } - SpatialExtentCartesianShapeDocValuesAggregator.combine(state, groupId, valuesArray); + SpatialExtentCartesianShapeDocValuesAggregator.combine(state, groupId, valuesPosition, valuesBlock); } } } @@ -251,13 +239,7 @@ private void addRawInput(int positionOffset, IntVector groups, IntBlock valuesBl continue; } int groupId = groups.getInt(groupPosition); - int valuesStart = valuesBlock.getFirstValueIndex(valuesPosition); - int valuesEnd = valuesStart + valuesBlock.getValueCount(valuesPosition); - int[] valuesArray = new int[valuesEnd - valuesStart]; - for (int v = valuesStart; v < valuesEnd; v++) { - valuesArray[v-valuesStart] = valuesBlock.getInt(v); - } - SpatialExtentCartesianShapeDocValuesAggregator.combine(state, groupId, valuesArray); + SpatialExtentCartesianShapeDocValuesAggregator.combine(state, groupId, valuesPosition, valuesBlock); } } diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/spatial/SpatialExtentGeoShapeDocValuesAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/spatial/SpatialExtentGeoShapeDocValuesAggregatorFunction.java index f9ab34a775263..2f9823713b365 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/spatial/SpatialExtentGeoShapeDocValuesAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/spatial/SpatialExtentGeoShapeDocValuesAggregatorFunction.java @@ -103,13 +103,7 @@ private void addRawBlock(IntBlock valuesBlock) { if (valuesBlock.isNull(p)) { continue; } - int start = valuesBlock.getFirstValueIndex(p); - int end = start + valuesBlock.getValueCount(p); - int[] valuesArray = new int[end - start]; - for (int i = start; i < end; i++) { - valuesArray[i-start] = valuesBlock.getInt(i); - } - SpatialExtentGeoShapeDocValuesAggregator.combine(state, valuesArray); + SpatialExtentGeoShapeDocValuesAggregator.combine(state, p, valuesBlock); } } @@ -121,13 +115,7 @@ private void addRawBlock(IntBlock valuesBlock, BooleanVector mask) { if (valuesBlock.isNull(p)) { continue; } - int start = valuesBlock.getFirstValueIndex(p); - int end = start + valuesBlock.getValueCount(p); - int[] valuesArray = new int[end - start]; - for (int i = start; i < end; i++) { - valuesArray[i-start] = valuesBlock.getInt(i); - } - SpatialExtentGeoShapeDocValuesAggregator.combine(state, valuesArray); + SpatialExtentGeoShapeDocValuesAggregator.combine(state, p, valuesBlock); } } diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/spatial/SpatialExtentGeoShapeDocValuesGroupingAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/spatial/SpatialExtentGeoShapeDocValuesGroupingAggregatorFunction.java index 0cf7a3b7ae910..4f3c7028794fc 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/spatial/SpatialExtentGeoShapeDocValuesGroupingAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/spatial/SpatialExtentGeoShapeDocValuesGroupingAggregatorFunction.java @@ -125,13 +125,7 @@ private void addRawInput(int positionOffset, IntArrayBlock groups, IntBlock valu int groupEnd = groupStart + groups.getValueCount(groupPosition); for (int g = groupStart; g < groupEnd; g++) { int groupId = groups.getInt(g); - int valuesStart = valuesBlock.getFirstValueIndex(valuesPosition); - int valuesEnd = valuesStart + valuesBlock.getValueCount(valuesPosition); - int[] valuesArray = new int[valuesEnd - valuesStart]; - for (int v = valuesStart; v < valuesEnd; v++) { - valuesArray[v-valuesStart] = valuesBlock.getInt(v); - } - SpatialExtentGeoShapeDocValuesAggregator.combine(state, groupId, valuesArray); + SpatialExtentGeoShapeDocValuesAggregator.combine(state, groupId, valuesPosition, valuesBlock); } } } @@ -202,13 +196,7 @@ private void addRawInput(int positionOffset, IntBigArrayBlock groups, IntBlock v int groupEnd = groupStart + groups.getValueCount(groupPosition); for (int g = groupStart; g < groupEnd; g++) { int groupId = groups.getInt(g); - int valuesStart = valuesBlock.getFirstValueIndex(valuesPosition); - int valuesEnd = valuesStart + valuesBlock.getValueCount(valuesPosition); - int[] valuesArray = new int[valuesEnd - valuesStart]; - for (int v = valuesStart; v < valuesEnd; v++) { - valuesArray[v-valuesStart] = valuesBlock.getInt(v); - } - SpatialExtentGeoShapeDocValuesAggregator.combine(state, groupId, valuesArray); + SpatialExtentGeoShapeDocValuesAggregator.combine(state, groupId, valuesPosition, valuesBlock); } } } @@ -273,13 +261,7 @@ private void addRawInput(int positionOffset, IntVector groups, IntBlock valuesBl continue; } int groupId = groups.getInt(groupPosition); - int valuesStart = valuesBlock.getFirstValueIndex(valuesPosition); - int valuesEnd = valuesStart + valuesBlock.getValueCount(valuesPosition); - int[] valuesArray = new int[valuesEnd - valuesStart]; - for (int v = valuesStart; v < valuesEnd; v++) { - valuesArray[v-valuesStart] = valuesBlock.getInt(v); - } - SpatialExtentGeoShapeDocValuesAggregator.combine(state, groupId, valuesArray); + SpatialExtentGeoShapeDocValuesAggregator.combine(state, groupId, valuesPosition, valuesBlock); } } diff --git a/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/spatial/SpatialExtentCartesianShapeDocValuesAggregator.java b/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/spatial/SpatialExtentCartesianShapeDocValuesAggregator.java index 1305139ab2c29..a927ac514223a 100644 --- a/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/spatial/SpatialExtentCartesianShapeDocValuesAggregator.java +++ b/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/spatial/SpatialExtentCartesianShapeDocValuesAggregator.java @@ -10,6 +10,8 @@ import org.elasticsearch.compute.ann.Aggregator; import org.elasticsearch.compute.ann.GroupingAggregator; import org.elasticsearch.compute.ann.IntermediateState; +import org.elasticsearch.compute.ann.Position; +import org.elasticsearch.compute.data.IntBlock; /** * Computes the extent of a set of cartesian shapes read from doc-values, which means they are encoded as an array of integers. @@ -35,11 +37,11 @@ public static SpatialExtentGroupingState initGrouping() { return new SpatialExtentGroupingState(PointType.CARTESIAN); } - public static void combine(SpatialExtentState current, int[] values) { - current.add(values); + public static void combine(SpatialExtentState current, @Position int p, IntBlock values) { + current.add(p, values); } - public static void combine(SpatialExtentGroupingState current, int groupId, int[] values) { - current.add(groupId, values); + public static void combine(SpatialExtentGroupingState current, int groupId, @Position int p, IntBlock values) { + current.add(groupId, p, values); } } diff --git a/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/spatial/SpatialExtentGeoShapeDocValuesAggregator.java b/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/spatial/SpatialExtentGeoShapeDocValuesAggregator.java index 26f8ae156aacc..42c449b29a3e0 100644 --- a/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/spatial/SpatialExtentGeoShapeDocValuesAggregator.java +++ b/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/spatial/SpatialExtentGeoShapeDocValuesAggregator.java @@ -10,6 +10,8 @@ import org.elasticsearch.compute.ann.Aggregator; import org.elasticsearch.compute.ann.GroupingAggregator; import org.elasticsearch.compute.ann.IntermediateState; +import org.elasticsearch.compute.ann.Position; +import org.elasticsearch.compute.data.IntBlock; /** * Computes the extent of a set of geo shapes read from doc-values, which means they are encoded as an array of integers. @@ -38,11 +40,11 @@ public static SpatialExtentGroupingStateWrappedLongitudeState initGrouping() { return new SpatialExtentGroupingStateWrappedLongitudeState(); } - public static void combine(SpatialExtentStateWrappedLongitudeState current, int[] values) { - current.add(values); + public static void combine(SpatialExtentStateWrappedLongitudeState current, @Position int p, IntBlock values) { + current.add(p, values); } - public static void combine(SpatialExtentGroupingStateWrappedLongitudeState current, int groupId, int[] values) { - current.add(groupId, values); + public static void combine(SpatialExtentGroupingStateWrappedLongitudeState current, int groupId, @Position int p, IntBlock values) { + current.add(groupId, p, values); } } diff --git a/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/spatial/SpatialExtentGroupingState.java b/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/spatial/SpatialExtentGroupingState.java index b2411d59ac298..b492b5ce64f1e 100644 --- a/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/spatial/SpatialExtentGroupingState.java +++ b/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/spatial/SpatialExtentGroupingState.java @@ -13,6 +13,7 @@ import org.elasticsearch.compute.aggregation.AbstractArrayState; import org.elasticsearch.compute.aggregation.SeenGroupIds; import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.IntBlock; import org.elasticsearch.compute.data.IntVector; import org.elasticsearch.compute.operator.DriverContext; import org.elasticsearch.geometry.Geometry; @@ -78,25 +79,28 @@ public void toIntermediate(Block[] blocks, int offset, IntVector selected, Drive * This method is used when extents are extracted from the doc-values field by the {@link GeometryDocValueReader}. * This optimization is enabled when the field has doc-values and is only used in the ST_EXTENT aggregation. */ - public void add(int groupId, int[] values) { - if (values.length == 6) { + public void add(int groupId, int p, IntBlock values) { + int count = values.getValueCount(p); + if (count == 6) { // Values are stored according to the order defined in the Extent class - int top = values[0]; - int bottom = values[1]; - int negLeft = values[2]; - int negRight = values[3]; - int posLeft = values[4]; - int posRight = values[5]; + int i = values.getFirstValueIndex(p); + int top = values.getInt(i++); + int bottom = values.getInt(i++); + int negLeft = values.getInt(i++); + int negRight = values.getInt(i++); + int posLeft = values.getInt(i++); + int posRight = values.getInt(i); add(groupId, Math.min(negLeft, posLeft), Math.max(negRight, posRight), top, bottom); - } else if (values.length == 4) { + } else if (count == 4) { // Values are stored according to the order defined in the Rectangle class - int minX = values[0]; - int maxX = values[1]; - int maxY = values[2]; - int minY = values[3]; + int i = values.getFirstValueIndex(p); + int minX = values.getInt(i++); + int maxX = values.getInt(i++); + int maxY = values.getInt(i++); + int minY = values.getInt(i); add(groupId, minX, maxX, maxY, minY); } else { - throw new IllegalArgumentException("Expected 4 or 6 values, got " + values.length); + throw new IllegalArgumentException("Expected 4 or 6 values, got " + count); } } diff --git a/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/spatial/SpatialExtentGroupingStateWrappedLongitudeState.java b/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/spatial/SpatialExtentGroupingStateWrappedLongitudeState.java index 5eadbc83435b0..1606cdf0c9f6d 100644 --- a/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/spatial/SpatialExtentGroupingStateWrappedLongitudeState.java +++ b/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/spatial/SpatialExtentGroupingStateWrappedLongitudeState.java @@ -14,6 +14,7 @@ import org.elasticsearch.compute.aggregation.GroupingAggregatorState; import org.elasticsearch.compute.aggregation.SeenGroupIds; import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.IntBlock; import org.elasticsearch.compute.data.IntVector; import org.elasticsearch.compute.operator.DriverContext; import org.elasticsearch.geometry.Geometry; @@ -122,17 +123,18 @@ public void add(int groupId, long encoded) { * This method is used when extents are extracted from the doc-values field by the {@link GeometryDocValueReader}. * This optimization is enabled when the field has doc-values and is only used in the ST_EXTENT aggregation. */ - public void add(int groupId, int[] values) { - if (values.length != 6) { - throw new IllegalArgumentException("Expected 6 values, got " + values.length); + public void add(int groupId, int p, IntBlock values) { + if (values.getValueCount(p) != 6) { + throw new IllegalArgumentException("Expected 6 values, got " + values.getValueCount(p)); } // Values are stored according to the order defined in the Extent class - int top = values[0]; - int bottom = values[1]; - int negLeft = values[2]; - int negRight = values[3]; - int posLeft = values[4]; - int posRight = values[5]; + int i = values.getFirstValueIndex(p); + int top = values.getInt(i++); + int bottom = values.getInt(i++); + int negLeft = values.getInt(i++); + int negRight = values.getInt(i++); + int posLeft = values.getInt(i++); + int posRight = values.getInt(i); add(groupId, top, bottom, negLeft, negRight, posLeft, posRight); } diff --git a/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/spatial/SpatialExtentState.java b/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/spatial/SpatialExtentState.java index cd52d346b09f4..5f5ee80fa0e68 100644 --- a/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/spatial/SpatialExtentState.java +++ b/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/spatial/SpatialExtentState.java @@ -10,6 +10,7 @@ import org.apache.lucene.util.BytesRef; import org.elasticsearch.compute.aggregation.AggregatorState; import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.IntBlock; import org.elasticsearch.compute.operator.DriverContext; import org.elasticsearch.geometry.Geometry; import org.elasticsearch.geometry.Rectangle; @@ -60,25 +61,28 @@ public void add(Geometry geo) { * This method is used when extents are extracted from the doc-values field by the {@link GeometryDocValueReader}. * This optimization is enabled when the field has doc-values and is only used in the ST_EXTENT aggregation. */ - public void add(int[] values) { - if (values.length == 6) { + public void add(int p, IntBlock values) { + int count = values.getValueCount(p); + if (count == 6) { // Values are stored according to the order defined in the Extent class - int top = values[0]; - int bottom = values[1]; - int negLeft = values[2]; - int negRight = values[3]; - int posLeft = values[4]; - int posRight = values[5]; + int i = values.getFirstValueIndex(p); + int top = values.getInt(i++); + int bottom = values.getInt(i++); + int negLeft = values.getInt(i++); + int negRight = values.getInt(i++); + int posLeft = values.getInt(i++); + int posRight = values.getInt(i); add(Math.min(negLeft, posLeft), Math.max(negRight, posRight), top, bottom); - } else if (values.length == 4) { + } else if (count == 4) { // Values are stored according to the order defined in the Rectangle class - int minX = values[0]; - int maxX = values[1]; - int maxY = values[2]; - int minY = values[3]; + int i = values.getFirstValueIndex(p); + int minX = values.getInt(i++); + int maxX = values.getInt(i++); + int maxY = values.getInt(i++); + int minY = values.getInt(i); add(minX, maxX, maxY, minY); } else { - throw new IllegalArgumentException("Expected 4 or 6 values, got " + values.length); + throw new IllegalArgumentException("Expected 4 or 6 values, got " + count); } } diff --git a/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/spatial/SpatialExtentStateWrappedLongitudeState.java b/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/spatial/SpatialExtentStateWrappedLongitudeState.java index 86b41b5b8359c..a01a744ecfb19 100644 --- a/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/spatial/SpatialExtentStateWrappedLongitudeState.java +++ b/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/spatial/SpatialExtentStateWrappedLongitudeState.java @@ -11,6 +11,7 @@ import org.apache.lucene.util.BytesRef; import org.elasticsearch.compute.aggregation.AggregatorState; import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.IntBlock; import org.elasticsearch.compute.operator.DriverContext; import org.elasticsearch.geometry.Geometry; import org.elasticsearch.geometry.Rectangle; @@ -70,17 +71,18 @@ public void add(Geometry geo) { * This method is used when extents are extracted from the doc-values field by the {@link GeometryDocValueReader}. * This optimization is enabled when the field has doc-values and is only used in the ST_EXTENT aggregation. */ - public void add(int[] values) { - if (values.length != 6) { - throw new IllegalArgumentException("Expected 6 values, got " + values.length); + public void add(int p, IntBlock values) { + if (values.getValueCount(p) != 6) { + throw new IllegalArgumentException("Expected 6 values, got " + values.getValueCount(p)); } + int i = values.getFirstValueIndex(p); // Values are stored according to the order defined in the Extent class - int top = values[0]; - int bottom = values[1]; - int negLeft = values[2]; - int negRight = values[3]; - int posLeft = values[4]; - int posRight = values[5]; + int top = values.getInt(i++); + int bottom = values.getInt(i++); + int negLeft = values.getInt(i++); + int negRight = values.getInt(i++); + int posLeft = values.getInt(i++); + int posRight = values.getInt(i); add(top, bottom, negLeft, negRight, posLeft, posRight); } diff --git a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/multivalue/MvAppend.java b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/multivalue/MvAppend.java index 10966f99fb902..20b196c05e571 100644 --- a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/multivalue/MvAppend.java +++ b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/multivalue/MvAppend.java @@ -12,6 +12,7 @@ import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.compute.ann.Evaluator; +import org.elasticsearch.compute.ann.Position; import org.elasticsearch.compute.data.BooleanBlock; import org.elasticsearch.compute.data.BytesRefBlock; import org.elasticsearch.compute.data.DoubleBlock; @@ -210,7 +211,7 @@ public boolean equals(Object obj) { } @Evaluator(extraName = "Int") - static void process(IntBlock.Builder builder, int position, IntBlock field1, IntBlock field2) { + static void process(IntBlock.Builder builder, @Position int position, IntBlock field1, IntBlock field2) { int count1 = field1.getValueCount(position); int count2 = field2.getValueCount(position); if (count1 == 0 || count2 == 0) { @@ -231,7 +232,7 @@ static void process(IntBlock.Builder builder, int position, IntBlock field1, Int } @Evaluator(extraName = "Boolean") - static void process(BooleanBlock.Builder builder, int position, BooleanBlock field1, BooleanBlock field2) { + static void process(BooleanBlock.Builder builder, @Position int position, BooleanBlock field1, BooleanBlock field2) { int count1 = field1.getValueCount(position); int count2 = field2.getValueCount(position); if (count1 == 0 || count2 == 0) { @@ -252,7 +253,7 @@ static void process(BooleanBlock.Builder builder, int position, BooleanBlock fie } @Evaluator(extraName = "Long") - static void process(LongBlock.Builder builder, int position, LongBlock field1, LongBlock field2) { + static void process(LongBlock.Builder builder, @Position int position, LongBlock field1, LongBlock field2) { int count1 = field1.getValueCount(position); int count2 = field2.getValueCount(position); if (count1 == 0 || count2 == 0) { @@ -272,7 +273,7 @@ static void process(LongBlock.Builder builder, int position, LongBlock field1, L } @Evaluator(extraName = "Double") - static void process(DoubleBlock.Builder builder, int position, DoubleBlock field1, DoubleBlock field2) { + static void process(DoubleBlock.Builder builder,@Position int position, DoubleBlock field1, DoubleBlock field2) { int count1 = field1.getValueCount(position); int count2 = field2.getValueCount(position); if (count1 == 0 || count2 == 0) { @@ -293,7 +294,7 @@ static void process(DoubleBlock.Builder builder, int position, DoubleBlock field } @Evaluator(extraName = "BytesRef") - static void process(BytesRefBlock.Builder builder, int position, BytesRefBlock field1, BytesRefBlock field2) { + static void process(BytesRefBlock.Builder builder, @Position int position, BytesRefBlock field1, BytesRefBlock field2) { int count1 = field1.getValueCount(position); int count2 = field2.getValueCount(position); if (count1 == 0 || count2 == 0) { diff --git a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/multivalue/MvPSeriesWeightedSum.java b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/multivalue/MvPSeriesWeightedSum.java index a7cbb4daae16f..4acc2513e2fa1 100644 --- a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/multivalue/MvPSeriesWeightedSum.java +++ b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/multivalue/MvPSeriesWeightedSum.java @@ -12,6 +12,7 @@ import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.compute.ann.Evaluator; import org.elasticsearch.compute.ann.Fixed; +import org.elasticsearch.compute.ann.Position; import org.elasticsearch.compute.data.DoubleBlock; import org.elasticsearch.compute.operator.EvalOperator; import org.elasticsearch.search.aggregations.metrics.CompensatedSum; @@ -143,7 +144,7 @@ public DataType dataType() { @Evaluator(extraName = "Double", warnExceptions = ArithmeticException.class) static void process( DoubleBlock.Builder builder, - int position, + @Position int position, DoubleBlock block, @Fixed(includeInToString = false, scope = THREAD_LOCAL) CompensatedSum sum, @Fixed double p diff --git a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/multivalue/MvPercentile.java b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/multivalue/MvPercentile.java index 6798f45665aee..74f6e76dd060e 100644 --- a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/multivalue/MvPercentile.java +++ b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/multivalue/MvPercentile.java @@ -13,6 +13,7 @@ import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.compute.ann.Evaluator; import org.elasticsearch.compute.ann.Fixed; +import org.elasticsearch.compute.ann.Position; import org.elasticsearch.compute.data.DoubleBlock; import org.elasticsearch.compute.data.IntBlock; import org.elasticsearch.compute.data.LongBlock; @@ -165,7 +166,7 @@ static class LongSortingScratch { @Evaluator(extraName = "Double", warnExceptions = IllegalArgumentException.class) static void process( DoubleBlock.Builder builder, - int position, + @Position int position, DoubleBlock values, double percentile, @Fixed(includeInToString = false, scope = THREAD_LOCAL) DoubleSortingScratch scratch @@ -188,7 +189,7 @@ static void process( @Evaluator(extraName = "Integer", warnExceptions = IllegalArgumentException.class) static void process( IntBlock.Builder builder, - int position, + @Position int position, IntBlock values, double percentile, @Fixed(includeInToString = false, scope = THREAD_LOCAL) IntSortingScratch scratch @@ -211,7 +212,7 @@ static void process( @Evaluator(extraName = "Long", warnExceptions = IllegalArgumentException.class) static void process( LongBlock.Builder builder, - int position, + @Position int position, LongBlock values, double percentile, @Fixed(includeInToString = false, scope = THREAD_LOCAL) LongSortingScratch scratch diff --git a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/multivalue/MvSlice.java b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/multivalue/MvSlice.java index cdefb4db19d76..4ad3426b94719 100644 --- a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/multivalue/MvSlice.java +++ b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/multivalue/MvSlice.java @@ -12,6 +12,7 @@ import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.compute.ann.Evaluator; +import org.elasticsearch.compute.ann.Position; import org.elasticsearch.compute.data.BooleanBlock; import org.elasticsearch.compute.data.BytesRefBlock; import org.elasticsearch.compute.data.DoubleBlock; @@ -264,7 +265,7 @@ static void checkStartEnd(int start, int end) throws InvalidArgumentException { } @Evaluator(extraName = "Boolean", warnExceptions = { InvalidArgumentException.class }) - static void process(BooleanBlock.Builder builder, int position, BooleanBlock field, int start, int end) { + static void process(BooleanBlock.Builder builder, @Position int position, BooleanBlock field, int start, int end) { int fieldValueCount = field.getValueCount(position); checkStartEnd(start, end); int first = field.getFirstValueIndex(position); @@ -288,7 +289,7 @@ static void process(BooleanBlock.Builder builder, int position, BooleanBlock fie } @Evaluator(extraName = "Int", warnExceptions = { InvalidArgumentException.class }) - static void process(IntBlock.Builder builder, int position, IntBlock field, int start, int end) { + static void process(IntBlock.Builder builder, @Position int position, IntBlock field, int start, int end) { int fieldValueCount = field.getValueCount(position); checkStartEnd(start, end); int first = field.getFirstValueIndex(position); @@ -312,7 +313,7 @@ static void process(IntBlock.Builder builder, int position, IntBlock field, int } @Evaluator(extraName = "Long", warnExceptions = { InvalidArgumentException.class }) - static void process(LongBlock.Builder builder, int position, LongBlock field, int start, int end) { + static void process(LongBlock.Builder builder, @Position int position, LongBlock field, int start, int end) { int fieldValueCount = field.getValueCount(position); checkStartEnd(start, end); int first = field.getFirstValueIndex(position); @@ -336,7 +337,7 @@ static void process(LongBlock.Builder builder, int position, LongBlock field, in } @Evaluator(extraName = "Double", warnExceptions = { InvalidArgumentException.class }) - static void process(DoubleBlock.Builder builder, int position, DoubleBlock field, int start, int end) { + static void process(DoubleBlock.Builder builder, @Position int position, DoubleBlock field, int start, int end) { int fieldValueCount = field.getValueCount(position); checkStartEnd(start, end); int first = field.getFirstValueIndex(position); @@ -360,7 +361,7 @@ static void process(DoubleBlock.Builder builder, int position, DoubleBlock field } @Evaluator(extraName = "BytesRef", warnExceptions = { InvalidArgumentException.class }) - static void process(BytesRefBlock.Builder builder, int position, BytesRefBlock field, int start, int end) { + static void process(BytesRefBlock.Builder builder, @Position int position, BytesRefBlock field, int start, int end) { int fieldValueCount = field.getValueCount(position); checkStartEnd(start, end); // append null here ? int first = field.getFirstValueIndex(position); diff --git a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/multivalue/MvZip.java b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/multivalue/MvZip.java index e35f50115b604..ded86c934b68c 100644 --- a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/multivalue/MvZip.java +++ b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/multivalue/MvZip.java @@ -14,6 +14,7 @@ import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.lucene.BytesRefs; import org.elasticsearch.compute.ann.Evaluator; +import org.elasticsearch.compute.ann.Position; import org.elasticsearch.compute.data.BytesRefBlock; import org.elasticsearch.compute.operator.EvalOperator; import org.elasticsearch.xpack.esql.core.expression.Expression; @@ -163,7 +164,7 @@ private static void buildOneSide(BytesRefBlock.Builder builder, int start, int e } @Evaluator - static void process(BytesRefBlock.Builder builder, int position, BytesRefBlock leftField, BytesRefBlock rightField, BytesRef delim) { + static void process(BytesRefBlock.Builder builder, @Position int position, BytesRefBlock leftField, BytesRefBlock rightField, BytesRef delim) { int leftFieldValueCount = leftField.getValueCount(position); int rightFieldValueCount = rightField.getValueCount(position); diff --git a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/spatial/StDistance.java b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/spatial/StDistance.java index e318d79848cc4..5ca4d0b3c656a 100644 --- a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/spatial/StDistance.java +++ b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/spatial/StDistance.java @@ -14,6 +14,7 @@ import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.compute.ann.Evaluator; import org.elasticsearch.compute.ann.Fixed; +import org.elasticsearch.compute.ann.Position; import org.elasticsearch.compute.data.BytesRefBlock; import org.elasticsearch.compute.data.DoubleBlock; import org.elasticsearch.compute.data.LongBlock; @@ -354,42 +355,47 @@ private EvalOperator.ExpressionEvaluator.Factory toEvaluator( } @Evaluator(extraName = "GeoSourceAndConstant", warnExceptions = { IllegalArgumentException.class }) - static void processGeoSourceAndConstant(DoubleBlock.Builder results, int p, BytesRefBlock left, @Fixed Point right) { + static void processGeoSourceAndConstant(DoubleBlock.Builder results, @Position int p, BytesRefBlock left, @Fixed Point right) { GEO.distanceSourceAndConstant(results, p, left, right); } @Evaluator(extraName = "GeoSourceAndSource", warnExceptions = { IllegalArgumentException.class }) - static void processGeoSourceAndSource(DoubleBlock.Builder results, int p, BytesRefBlock left, BytesRefBlock right) { + static void processGeoSourceAndSource(DoubleBlock.Builder results, @Position int p, BytesRefBlock left, BytesRefBlock right) { GEO.distanceSourceAndSource(results, p, left, right); } @Evaluator(extraName = "GeoPointDocValuesAndConstant", warnExceptions = { IllegalArgumentException.class }) - static void processGeoPointDocValuesAndConstant(DoubleBlock.Builder results, int p, LongBlock left, @Fixed Point right) { + static void processGeoPointDocValuesAndConstant(DoubleBlock.Builder results, @Position int p, LongBlock left, @Fixed Point right) { GEO.distancePointDocValuesAndConstant(results, p, left, right); } @Evaluator(extraName = "GeoPointDocValuesAndSource", warnExceptions = { IllegalArgumentException.class }) - static void processGeoPointDocValuesAndSource(DoubleBlock.Builder results, int p, LongBlock left, BytesRefBlock right) { + static void processGeoPointDocValuesAndSource(DoubleBlock.Builder results, @Position int p, LongBlock left, BytesRefBlock right) { GEO.distancePointDocValuesAndSource(results, p, left, right); } @Evaluator(extraName = "CartesianSourceAndConstant", warnExceptions = { IllegalArgumentException.class }) - static void processCartesianSourceAndConstant(DoubleBlock.Builder results, int p, BytesRefBlock left, @Fixed Point right) { + static void processCartesianSourceAndConstant(DoubleBlock.Builder results, @Position int p, BytesRefBlock left, @Fixed Point right) { CARTESIAN.distanceSourceAndConstant(results, p, left, right); } @Evaluator(extraName = "CartesianSourceAndSource", warnExceptions = { IllegalArgumentException.class }) - static void processCartesianSourceAndSource(DoubleBlock.Builder results, int p, BytesRefBlock left, BytesRefBlock right) { + static void processCartesianSourceAndSource(DoubleBlock.Builder results, @Position int p, BytesRefBlock left, BytesRefBlock right) { CARTESIAN.distanceSourceAndSource(results, p, left, right); } @Evaluator(extraName = "CartesianPointDocValuesAndConstant", warnExceptions = { IllegalArgumentException.class }) - static void processCartesianPointDocValuesAndConstant(DoubleBlock.Builder results, int p, LongBlock left, @Fixed Point right) { + static void processCartesianPointDocValuesAndConstant( + DoubleBlock.Builder results, + @Position int p, + LongBlock left, + @Fixed Point right + ) { CARTESIAN.distancePointDocValuesAndConstant(results, p, left, right); } @Evaluator(extraName = "CartesianPointDocValuesAndSource") - static void processCartesianPointDocValuesAndSource(DoubleBlock.Builder results, int p, LongBlock left, BytesRefBlock right) { + static void processCartesianPointDocValuesAndSource(DoubleBlock.Builder results, @Position int p, LongBlock left, BytesRefBlock right) { CARTESIAN.distancePointDocValuesAndSource(results, p, left, right); } } From 6a6e605ec58bd5bef4daf09d2b139c59a5adfe16 Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Sun, 21 Sep 2025 14:04:32 -0400 Subject: [PATCH 2/3] ESQL: Standardize block args Standardizes how aggs and scalars work with arguments that take all values at a position. Aggs were using an arrays of values that we had to copy all of the values into the array. And allocate it. Scalars passed down the `Block` and the scalar read from the block on it's own. That's generally more efficient and not a lot harder. So I standardized on that. Previously scalars that took a `Block` parameter also took an implicit builder and position parameter. But aggs don't need the builder. And *do* need the position. This makes both of those parameters explicit rather than implicit. --- .../compute/gen/EvaluatorImplementer.java | 10 +---- .../scalar/spatial/SpatialContains.java | 36 ++++++++++++------ .../scalar/spatial/SpatialDisjoint.java | 38 ++++++++++++------- .../scalar/spatial/SpatialIntersects.java | 38 ++++++++++++------- .../scalar/spatial/SpatialWithin.java | 30 ++++++++++----- .../function/scalar/spatial/StGeohash.java | 9 +++-- .../function/scalar/spatial/StGeohex.java | 9 +++-- .../function/scalar/spatial/StGeotile.java | 9 +++-- 8 files changed, 110 insertions(+), 69 deletions(-) diff --git a/x-pack/plugin/esql/compute/gen/src/main/java/org/elasticsearch/compute/gen/EvaluatorImplementer.java b/x-pack/plugin/esql/compute/gen/src/main/java/org/elasticsearch/compute/gen/EvaluatorImplementer.java index 665b3e2644cbe..20915c56ef206 100644 --- a/x-pack/plugin/esql/compute/gen/src/main/java/org/elasticsearch/compute/gen/EvaluatorImplementer.java +++ b/x-pack/plugin/esql/compute/gen/src/main/java/org/elasticsearch/compute/gen/EvaluatorImplementer.java @@ -66,9 +66,6 @@ public EvaluatorImplementer( elements.getPackageOf(declarationType).toString(), declarationType.getSimpleName() + extraName + "Evaluator" ); - if (this.processFunction.hasBlockType) { - System.err.println("ADFADSF " + declarationType); - } this.processOutputsMultivalued = this.processFunction.hasBlockType && (this.processFunction.builderArg != null); } @@ -222,7 +219,7 @@ private MethodSpec realEval(boolean blockStyle) { StringBuilder pattern = new StringBuilder(); List args = new ArrayList<>(); - pattern.append(processOutputsMultivalued ? "$T.$N(result, p, " : "$T.$N("); + pattern.append("$T.$N("); args.add(declarationType); args.add(processFunction.function.getSimpleName()); processFunction.args.stream().forEach(a -> { @@ -315,10 +312,7 @@ static class ProcessFunction { } builderArg = ba; } else if (arg instanceof BlockArgument) { - if (builderArg != null && args.size() == 2 && hasBlockType == false) { - args.clear(); - hasBlockType = true; - } + hasBlockType = true; } args.add(arg); } diff --git a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/spatial/SpatialContains.java b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/spatial/SpatialContains.java index b15d04aa792d9..918cd176805cc 100644 --- a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/spatial/SpatialContains.java +++ b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/spatial/SpatialContains.java @@ -16,6 +16,7 @@ import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.compute.ann.Evaluator; import org.elasticsearch.compute.ann.Fixed; +import org.elasticsearch.compute.ann.Position; import org.elasticsearch.compute.data.BooleanBlock; import org.elasticsearch.compute.data.BytesRefBlock; import org.elasticsearch.compute.data.LongBlock; @@ -312,48 +313,61 @@ public SpatialRelatesFunction surrogate() { } @Evaluator(extraName = "GeoSourceAndConstant", warnExceptions = { IllegalArgumentException.class, IOException.class }) - static void processGeoSourceAndConstant(BooleanBlock.Builder results, int p, BytesRefBlock left, @Fixed Component2D[] right) + static void processGeoSourceAndConstant(BooleanBlock.Builder results, @Position int p, BytesRefBlock left, @Fixed Component2D[] right) throws IOException { GEO.processSourceAndConstant(results, p, left, right); } @Evaluator(extraName = "GeoSourceAndSource", warnExceptions = { IllegalArgumentException.class, IOException.class }) - static void processGeoSourceAndSource(BooleanBlock.Builder builder, int p, BytesRefBlock left, BytesRefBlock right) throws IOException { + static void processGeoSourceAndSource(BooleanBlock.Builder builder, @Position int p, BytesRefBlock left, BytesRefBlock right) + throws IOException { GEO.processSourceAndSource(builder, p, left, right); } @Evaluator(extraName = "GeoPointDocValuesAndConstant", warnExceptions = { IllegalArgumentException.class, IOException.class }) - static void processGeoPointDocValuesAndConstant(BooleanBlock.Builder builder, int p, LongBlock left, @Fixed Component2D[] right) - throws IOException { + static void processGeoPointDocValuesAndConstant( + BooleanBlock.Builder builder, + @Position int p, + LongBlock left, + @Fixed Component2D[] right + ) throws IOException { GEO.processPointDocValuesAndConstant(builder, p, left, right); } @Evaluator(extraName = "GeoPointDocValuesAndSource", warnExceptions = { IllegalArgumentException.class, IOException.class }) - static void processGeoPointDocValuesAndSource(BooleanBlock.Builder builder, int p, LongBlock left, BytesRefBlock right) + static void processGeoPointDocValuesAndSource(BooleanBlock.Builder builder, @Position int p, LongBlock left, BytesRefBlock right) throws IOException { GEO.processPointDocValuesAndSource(builder, p, left, right); } @Evaluator(extraName = "CartesianSourceAndConstant", warnExceptions = { IllegalArgumentException.class, IOException.class }) - static void processCartesianSourceAndConstant(BooleanBlock.Builder builder, int p, BytesRefBlock left, @Fixed Component2D[] right) - throws IOException { + static void processCartesianSourceAndConstant( + BooleanBlock.Builder builder, + @Position int p, + BytesRefBlock left, + @Fixed Component2D[] right + ) throws IOException { CARTESIAN.processSourceAndConstant(builder, p, left, right); } @Evaluator(extraName = "CartesianSourceAndSource", warnExceptions = { IllegalArgumentException.class, IOException.class }) - static void processCartesianSourceAndSource(BooleanBlock.Builder builder, int p, BytesRefBlock left, BytesRefBlock right) + static void processCartesianSourceAndSource(BooleanBlock.Builder builder, @Position int p, BytesRefBlock left, BytesRefBlock right) throws IOException { CARTESIAN.processSourceAndSource(builder, p, left, right); } @Evaluator(extraName = "CartesianPointDocValuesAndConstant", warnExceptions = { IllegalArgumentException.class, IOException.class }) - static void processCartesianPointDocValuesAndConstant(BooleanBlock.Builder builder, int p, LongBlock left, @Fixed Component2D[] right) - throws IOException { + static void processCartesianPointDocValuesAndConstant( + BooleanBlock.Builder builder, + @Position int p, + LongBlock left, + @Fixed Component2D[] right + ) throws IOException { CARTESIAN.processPointDocValuesAndConstant(builder, p, left, right); } @Evaluator(extraName = "CartesianPointDocValuesAndSource", warnExceptions = { IllegalArgumentException.class, IOException.class }) - static void processCartesianPointDocValuesAndSource(BooleanBlock.Builder builder, int p, LongBlock left, BytesRefBlock right) + static void processCartesianPointDocValuesAndSource(BooleanBlock.Builder builder, @Position int p, LongBlock left, BytesRefBlock right) throws IOException { CARTESIAN.processPointDocValuesAndSource(builder, p, left, right); } diff --git a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/spatial/SpatialDisjoint.java b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/spatial/SpatialDisjoint.java index e4d2fbaa78151..d85410d59a78e 100644 --- a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/spatial/SpatialDisjoint.java +++ b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/spatial/SpatialDisjoint.java @@ -15,6 +15,7 @@ import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.compute.ann.Evaluator; import org.elasticsearch.compute.ann.Fixed; +import org.elasticsearch.compute.ann.Position; import org.elasticsearch.compute.data.BooleanBlock; import org.elasticsearch.compute.data.BytesRefBlock; import org.elasticsearch.compute.data.LongBlock; @@ -269,7 +270,7 @@ private Object foldGeoGrid(FoldContext ctx, Expression spatialExp, Expression gr @Evaluator(extraName = "GeoSourceAndConstantGrid", warnExceptions = { IllegalArgumentException.class, IOException.class }) static void processGeoSourceAndConstantGrid( BooleanBlock.Builder results, - int p, + @Position int p, BytesRefBlock wkb, @Fixed long gridId, @Fixed DataType gridType @@ -280,7 +281,7 @@ static void processGeoSourceAndConstantGrid( @Evaluator(extraName = "GeoPointDocValuesAndConstantGrid", warnExceptions = { IllegalArgumentException.class, IOException.class }) static void processGeoPointDocValuesAndConstantGrid( BooleanBlock.Builder results, - int p, + @Position int p, LongBlock encodedPoints, @Fixed long gridId, @Fixed DataType gridType @@ -291,7 +292,7 @@ static void processGeoPointDocValuesAndConstantGrid( @Evaluator(extraName = "GeoSourceAndSourceGrid", warnExceptions = { IllegalArgumentException.class, IOException.class }) static void processGeoSourceAndSourceGrid( BooleanBlock.Builder results, - int p, + @Position int p, BytesRefBlock wkb, LongBlock gridId, @Fixed DataType gridType @@ -302,7 +303,7 @@ static void processGeoSourceAndSourceGrid( @Evaluator(extraName = "GeoPointDocValuesAndSourceGrid", warnExceptions = { IllegalArgumentException.class, IOException.class }) static void processGeoPointDocValuesAndSourceGrid( BooleanBlock.Builder results, - int p, + @Position int p, LongBlock encodedPoints, LongBlock gridIds, @Fixed DataType gridType @@ -311,48 +312,57 @@ static void processGeoPointDocValuesAndSourceGrid( } @Evaluator(extraName = "GeoSourceAndConstant", warnExceptions = { IllegalArgumentException.class, IOException.class }) - static void processGeoSourceAndConstant(BooleanBlock.Builder results, int p, BytesRefBlock left, @Fixed Component2D right) + static void processGeoSourceAndConstant(BooleanBlock.Builder results, @Position int p, BytesRefBlock left, @Fixed Component2D right) throws IOException { GEO.processSourceAndConstant(results, p, left, right); } @Evaluator(extraName = "GeoSourceAndSource", warnExceptions = { IllegalArgumentException.class, IOException.class }) - static void processGeoSourceAndSource(BooleanBlock.Builder builder, int p, BytesRefBlock left, BytesRefBlock right) throws IOException { + static void processGeoSourceAndSource(BooleanBlock.Builder builder, @Position int p, BytesRefBlock left, BytesRefBlock right) + throws IOException { GEO.processSourceAndSource(builder, p, left, right); } @Evaluator(extraName = "GeoPointDocValuesAndConstant", warnExceptions = { IllegalArgumentException.class, IOException.class }) - static void processGeoPointDocValuesAndConstant(BooleanBlock.Builder builder, int p, LongBlock left, @Fixed Component2D right) + static void processGeoPointDocValuesAndConstant(BooleanBlock.Builder builder, @Position int p, LongBlock left, @Fixed Component2D right) throws IOException { GEO.processPointDocValuesAndConstant(builder, p, left, right); } @Evaluator(extraName = "GeoPointDocValuesAndSource", warnExceptions = { IllegalArgumentException.class, IOException.class }) - static void processGeoPointDocValuesAndSource(BooleanBlock.Builder builder, int p, LongBlock left, BytesRefBlock right) + static void processGeoPointDocValuesAndSource(BooleanBlock.Builder builder, @Position int p, LongBlock left, BytesRefBlock right) throws IOException { GEO.processPointDocValuesAndSource(builder, p, left, right); } @Evaluator(extraName = "CartesianSourceAndConstant", warnExceptions = { IllegalArgumentException.class, IOException.class }) - static void processCartesianSourceAndConstant(BooleanBlock.Builder builder, int p, BytesRefBlock left, @Fixed Component2D right) - throws IOException { + static void processCartesianSourceAndConstant( + BooleanBlock.Builder builder, + @Position int p, + BytesRefBlock left, + @Fixed Component2D right + ) throws IOException { CARTESIAN.processSourceAndConstant(builder, p, left, right); } @Evaluator(extraName = "CartesianSourceAndSource", warnExceptions = { IllegalArgumentException.class, IOException.class }) - static void processCartesianSourceAndSource(BooleanBlock.Builder builder, int p, BytesRefBlock left, BytesRefBlock right) + static void processCartesianSourceAndSource(BooleanBlock.Builder builder, @Position int p, BytesRefBlock left, BytesRefBlock right) throws IOException { CARTESIAN.processSourceAndSource(builder, p, left, right); } @Evaluator(extraName = "CartesianPointDocValuesAndConstant", warnExceptions = { IllegalArgumentException.class, IOException.class }) - static void processCartesianPointDocValuesAndConstant(BooleanBlock.Builder builder, int p, LongBlock left, @Fixed Component2D right) - throws IOException { + static void processCartesianPointDocValuesAndConstant( + BooleanBlock.Builder builder, + @Position int p, + LongBlock left, + @Fixed Component2D right + ) throws IOException { CARTESIAN.processPointDocValuesAndConstant(builder, p, left, right); } @Evaluator(extraName = "CartesianPointDocValuesAndSource", warnExceptions = { IllegalArgumentException.class, IOException.class }) - static void processCartesianPointDocValuesAndSource(BooleanBlock.Builder builder, int p, LongBlock left, BytesRefBlock right) + static void processCartesianPointDocValuesAndSource(BooleanBlock.Builder builder, @Position int p, LongBlock left, BytesRefBlock right) throws IOException { CARTESIAN.processPointDocValuesAndSource(builder, p, left, right); } diff --git a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/spatial/SpatialIntersects.java b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/spatial/SpatialIntersects.java index 9b87a5efb1510..505198bacca78 100644 --- a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/spatial/SpatialIntersects.java +++ b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/spatial/SpatialIntersects.java @@ -15,6 +15,7 @@ import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.compute.ann.Evaluator; import org.elasticsearch.compute.ann.Fixed; +import org.elasticsearch.compute.ann.Position; import org.elasticsearch.compute.data.BooleanBlock; import org.elasticsearch.compute.data.BytesRefBlock; import org.elasticsearch.compute.data.LongBlock; @@ -267,7 +268,7 @@ private Object foldGeoGrid(FoldContext ctx, Expression spatialExp, Expression gr @Evaluator(extraName = "GeoSourceAndConstantGrid", warnExceptions = { IllegalArgumentException.class, IOException.class }) static void processGeoSourceAndConstantGrid( BooleanBlock.Builder results, - int p, + @Position int p, BytesRefBlock wkb, @Fixed long gridId, @Fixed DataType gridType @@ -278,7 +279,7 @@ static void processGeoSourceAndConstantGrid( @Evaluator(extraName = "GeoPointDocValuesAndConstantGrid", warnExceptions = { IllegalArgumentException.class, IOException.class }) static void processGeoPointDocValuesAndConstantGrid( BooleanBlock.Builder results, - int p, + @Position int p, LongBlock encodedPoints, @Fixed long gridId, @Fixed DataType gridType @@ -289,7 +290,7 @@ static void processGeoPointDocValuesAndConstantGrid( @Evaluator(extraName = "GeoSourceAndSourceGrid", warnExceptions = { IllegalArgumentException.class, IOException.class }) static void processGeoSourceAndSourceGrid( BooleanBlock.Builder results, - int p, + @Position int p, BytesRefBlock wkb, LongBlock gridId, @Fixed DataType gridType @@ -300,7 +301,7 @@ static void processGeoSourceAndSourceGrid( @Evaluator(extraName = "GeoPointDocValuesAndSourceGrid", warnExceptions = { IllegalArgumentException.class, IOException.class }) static void processGeoPointDocValuesAndSourceGrid( BooleanBlock.Builder results, - int p, + @Position int p, LongBlock encodedPoints, LongBlock gridIds, @Fixed DataType gridType @@ -309,48 +310,57 @@ static void processGeoPointDocValuesAndSourceGrid( } @Evaluator(extraName = "GeoSourceAndConstant", warnExceptions = { IllegalArgumentException.class, IOException.class }) - static void processGeoSourceAndConstant(BooleanBlock.Builder results, int p, BytesRefBlock left, @Fixed Component2D right) + static void processGeoSourceAndConstant(BooleanBlock.Builder results, @Position int p, BytesRefBlock left, @Fixed Component2D right) throws IOException { GEO.processSourceAndConstant(results, p, left, right); } @Evaluator(extraName = "GeoSourceAndSource", warnExceptions = { IllegalArgumentException.class, IOException.class }) - static void processGeoSourceAndSource(BooleanBlock.Builder builder, int p, BytesRefBlock left, BytesRefBlock right) throws IOException { + static void processGeoSourceAndSource(BooleanBlock.Builder builder, @Position int p, BytesRefBlock left, BytesRefBlock right) + throws IOException { GEO.processSourceAndSource(builder, p, left, right); } @Evaluator(extraName = "GeoPointDocValuesAndConstant", warnExceptions = { IllegalArgumentException.class, IOException.class }) - static void processGeoPointDocValuesAndConstant(BooleanBlock.Builder builder, int p, LongBlock left, @Fixed Component2D right) + static void processGeoPointDocValuesAndConstant(BooleanBlock.Builder builder, @Position int p, LongBlock left, @Fixed Component2D right) throws IOException { GEO.processPointDocValuesAndConstant(builder, p, left, right); } @Evaluator(extraName = "GeoPointDocValuesAndSource", warnExceptions = { IllegalArgumentException.class, IOException.class }) - static void processGeoPointDocValuesAndSource(BooleanBlock.Builder builder, int p, LongBlock left, BytesRefBlock right) + static void processGeoPointDocValuesAndSource(BooleanBlock.Builder builder, @Position int p, LongBlock left, BytesRefBlock right) throws IOException { GEO.processPointDocValuesAndSource(builder, p, left, right); } @Evaluator(extraName = "CartesianSourceAndConstant", warnExceptions = { IllegalArgumentException.class, IOException.class }) - static void processCartesianSourceAndConstant(BooleanBlock.Builder builder, int p, BytesRefBlock left, @Fixed Component2D right) - throws IOException { + static void processCartesianSourceAndConstant( + BooleanBlock.Builder builder, + @Position int p, + BytesRefBlock left, + @Fixed Component2D right + ) throws IOException { CARTESIAN.processSourceAndConstant(builder, p, left, right); } @Evaluator(extraName = "CartesianSourceAndSource", warnExceptions = { IllegalArgumentException.class, IOException.class }) - static void processCartesianSourceAndSource(BooleanBlock.Builder builder, int p, BytesRefBlock left, BytesRefBlock right) + static void processCartesianSourceAndSource(BooleanBlock.Builder builder, @Position int p, BytesRefBlock left, BytesRefBlock right) throws IOException { CARTESIAN.processSourceAndSource(builder, p, left, right); } @Evaluator(extraName = "CartesianPointDocValuesAndConstant", warnExceptions = { IllegalArgumentException.class, IOException.class }) - static void processCartesianPointDocValuesAndConstant(BooleanBlock.Builder builder, int p, LongBlock left, @Fixed Component2D right) - throws IOException { + static void processCartesianPointDocValuesAndConstant( + BooleanBlock.Builder builder, + @Position int p, + LongBlock left, + @Fixed Component2D right + ) throws IOException { CARTESIAN.processPointDocValuesAndConstant(builder, p, left, right); } @Evaluator(extraName = "CartesianPointDocValuesAndSource", warnExceptions = { IllegalArgumentException.class, IOException.class }) - static void processCartesianPointDocValuesAndSource(BooleanBlock.Builder builder, int p, LongBlock left, BytesRefBlock right) + static void processCartesianPointDocValuesAndSource(BooleanBlock.Builder builder, @Position int p, LongBlock left, BytesRefBlock right) throws IOException { CARTESIAN.processPointDocValuesAndSource(builder, p, left, right); } diff --git a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/spatial/SpatialWithin.java b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/spatial/SpatialWithin.java index 9fcece1ce65bc..c9ce24945df12 100644 --- a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/spatial/SpatialWithin.java +++ b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/spatial/SpatialWithin.java @@ -15,6 +15,7 @@ import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.compute.ann.Evaluator; import org.elasticsearch.compute.ann.Fixed; +import org.elasticsearch.compute.ann.Position; import org.elasticsearch.compute.data.BooleanBlock; import org.elasticsearch.compute.data.BytesRefBlock; import org.elasticsearch.compute.data.LongBlock; @@ -224,48 +225,57 @@ public SpatialRelatesFunction surrogate() { } @Evaluator(extraName = "GeoSourceAndConstant", warnExceptions = { IllegalArgumentException.class, IOException.class }) - static void processGeoSourceAndConstant(BooleanBlock.Builder results, int p, BytesRefBlock left, @Fixed Component2D right) + static void processGeoSourceAndConstant(BooleanBlock.Builder results, @Position int p, BytesRefBlock left, @Fixed Component2D right) throws IOException { GEO.processSourceAndConstant(results, p, left, right); } @Evaluator(extraName = "GeoSourceAndSource", warnExceptions = { IllegalArgumentException.class, IOException.class }) - static void processGeoSourceAndSource(BooleanBlock.Builder builder, int p, BytesRefBlock left, BytesRefBlock right) throws IOException { + static void processGeoSourceAndSource(BooleanBlock.Builder builder, @Position int p, BytesRefBlock left, BytesRefBlock right) + throws IOException { GEO.processSourceAndSource(builder, p, left, right); } @Evaluator(extraName = "GeoPointDocValuesAndConstant", warnExceptions = { IllegalArgumentException.class, IOException.class }) - static void processGeoPointDocValuesAndConstant(BooleanBlock.Builder builder, int p, LongBlock left, @Fixed Component2D right) + static void processGeoPointDocValuesAndConstant(BooleanBlock.Builder builder, @Position int p, LongBlock left, @Fixed Component2D right) throws IOException { GEO.processPointDocValuesAndConstant(builder, p, left, right); } @Evaluator(extraName = "GeoPointDocValuesAndSource", warnExceptions = { IllegalArgumentException.class, IOException.class }) - static void processGeoPointDocValuesAndSource(BooleanBlock.Builder builder, int p, LongBlock left, BytesRefBlock right) + static void processGeoPointDocValuesAndSource(BooleanBlock.Builder builder, @Position int p, LongBlock left, BytesRefBlock right) throws IOException { GEO.processPointDocValuesAndSource(builder, p, left, right); } @Evaluator(extraName = "CartesianSourceAndConstant", warnExceptions = { IllegalArgumentException.class, IOException.class }) - static void processCartesianSourceAndConstant(BooleanBlock.Builder builder, int p, BytesRefBlock left, @Fixed Component2D right) - throws IOException { + static void processCartesianSourceAndConstant( + BooleanBlock.Builder builder, + @Position int p, + BytesRefBlock left, + @Fixed Component2D right + ) throws IOException { CARTESIAN.processSourceAndConstant(builder, p, left, right); } @Evaluator(extraName = "CartesianSourceAndSource", warnExceptions = { IllegalArgumentException.class, IOException.class }) - static void processCartesianSourceAndSource(BooleanBlock.Builder builder, int p, BytesRefBlock left, BytesRefBlock right) + static void processCartesianSourceAndSource(BooleanBlock.Builder builder, @Position int p, BytesRefBlock left, BytesRefBlock right) throws IOException { CARTESIAN.processSourceAndSource(builder, p, left, right); } @Evaluator(extraName = "CartesianPointDocValuesAndConstant", warnExceptions = { IllegalArgumentException.class, IOException.class }) - static void processCartesianPointDocValuesAndConstant(BooleanBlock.Builder builder, int p, LongBlock left, @Fixed Component2D right) - throws IOException { + static void processCartesianPointDocValuesAndConstant( + BooleanBlock.Builder builder, + @Position int p, + LongBlock left, + @Fixed Component2D right + ) throws IOException { CARTESIAN.processPointDocValuesAndConstant(builder, p, left, right); } @Evaluator(extraName = "CartesianPointDocValuesAndSource", warnExceptions = { IllegalArgumentException.class, IOException.class }) - static void processCartesianPointDocValuesAndSource(BooleanBlock.Builder builder, int p, LongBlock left, BytesRefBlock right) + static void processCartesianPointDocValuesAndSource(BooleanBlock.Builder builder, @Position int p, LongBlock left, BytesRefBlock right) throws IOException { CARTESIAN.processPointDocValuesAndSource(builder, p, left, right); } diff --git a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/spatial/StGeohash.java b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/spatial/StGeohash.java index b1fffe95b9b23..b8f87ae23b90b 100644 --- a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/spatial/StGeohash.java +++ b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/spatial/StGeohash.java @@ -13,6 +13,7 @@ import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.compute.ann.Evaluator; import org.elasticsearch.compute.ann.Fixed; +import org.elasticsearch.compute.ann.Position; import org.elasticsearch.compute.data.BytesRefBlock; import org.elasticsearch.compute.data.LongBlock; import org.elasticsearch.compute.operator.DriverContext; @@ -219,19 +220,19 @@ public Object fold(FoldContext ctx) { } @Evaluator(extraName = "FromFieldAndLiteral", warnExceptions = { IllegalArgumentException.class }) - static void fromFieldAndLiteral(LongBlock.Builder results, int p, BytesRefBlock wkbBlock, @Fixed int precision) { + static void fromFieldAndLiteral(LongBlock.Builder results, @Position int p, BytesRefBlock wkbBlock, @Fixed int precision) { fromWKB(results, p, wkbBlock, precision, unboundedGrid); } @Evaluator(extraName = "FromFieldDocValuesAndLiteral", warnExceptions = { IllegalArgumentException.class }) - static void fromFieldDocValuesAndLiteral(LongBlock.Builder results, int p, LongBlock encoded, @Fixed int precision) { + static void fromFieldDocValuesAndLiteral(LongBlock.Builder results, @Position int p, LongBlock encoded, @Fixed int precision) { fromEncodedLong(results, p, encoded, precision, unboundedGrid); } @Evaluator(extraName = "FromFieldAndLiteralAndLiteral", warnExceptions = { IllegalArgumentException.class }) static void fromFieldAndLiteralAndLiteral( LongBlock.Builder results, - int p, + @Position int p, BytesRefBlock in, @Fixed(includeInToString = false, scope = THREAD_LOCAL) GeoHashBoundedGrid bounds ) { @@ -241,7 +242,7 @@ static void fromFieldAndLiteralAndLiteral( @Evaluator(extraName = "FromFieldDocValuesAndLiteralAndLiteral", warnExceptions = { IllegalArgumentException.class }) static void fromFieldDocValuesAndLiteralAndLiteral( LongBlock.Builder results, - int p, + @Position int p, LongBlock encoded, @Fixed(includeInToString = false, scope = THREAD_LOCAL) GeoHashBoundedGrid bounds ) { diff --git a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/spatial/StGeohex.java b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/spatial/StGeohex.java index 2315af2e2cbe9..08adbde76e0d5 100644 --- a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/spatial/StGeohex.java +++ b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/spatial/StGeohex.java @@ -13,6 +13,7 @@ import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.compute.ann.Evaluator; import org.elasticsearch.compute.ann.Fixed; +import org.elasticsearch.compute.ann.Position; import org.elasticsearch.compute.data.BytesRefBlock; import org.elasticsearch.compute.data.LongBlock; import org.elasticsearch.compute.operator.DriverContext; @@ -225,19 +226,19 @@ public Object fold(FoldContext ctx) { } @Evaluator(extraName = "FromFieldAndLiteral", warnExceptions = { IllegalArgumentException.class }) - static void fromFieldAndLiteral(LongBlock.Builder results, int p, BytesRefBlock wkbBlock, @Fixed int precision) { + static void fromFieldAndLiteral(LongBlock.Builder results, @Position int p, BytesRefBlock wkbBlock, @Fixed int precision) { fromWKB(results, p, wkbBlock, precision, unboundedGrid); } @Evaluator(extraName = "FromFieldDocValuesAndLiteral", warnExceptions = { IllegalArgumentException.class }) - static void fromFieldDocValuesAndLiteral(LongBlock.Builder results, int p, LongBlock encoded, @Fixed int precision) { + static void fromFieldDocValuesAndLiteral(LongBlock.Builder results, @Position int p, LongBlock encoded, @Fixed int precision) { fromEncodedLong(results, p, encoded, precision, unboundedGrid); } @Evaluator(extraName = "FromFieldAndLiteralAndLiteral", warnExceptions = { IllegalArgumentException.class }) static void fromFieldAndLiteralAndLiteral( LongBlock.Builder results, - int p, + @Position int p, BytesRefBlock in, @Fixed(includeInToString = false, scope = THREAD_LOCAL) GeoHexBoundedGrid bounds ) { @@ -247,7 +248,7 @@ static void fromFieldAndLiteralAndLiteral( @Evaluator(extraName = "FromFieldDocValuesAndLiteralAndLiteral", warnExceptions = { IllegalArgumentException.class }) static void fromFieldDocValuesAndLiteralAndLiteral( LongBlock.Builder results, - int p, + @Position int p, LongBlock encoded, @Fixed(includeInToString = false, scope = THREAD_LOCAL) GeoHexBoundedGrid bounds ) { diff --git a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/spatial/StGeotile.java b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/spatial/StGeotile.java index 25264d696f731..3e12ecef07d07 100644 --- a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/spatial/StGeotile.java +++ b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/spatial/StGeotile.java @@ -13,6 +13,7 @@ import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.compute.ann.Evaluator; import org.elasticsearch.compute.ann.Fixed; +import org.elasticsearch.compute.ann.Position; import org.elasticsearch.compute.data.BytesRefBlock; import org.elasticsearch.compute.data.LongBlock; import org.elasticsearch.compute.operator.DriverContext; @@ -216,19 +217,19 @@ public Object fold(FoldContext ctx) { } @Evaluator(extraName = "FromFieldAndLiteral", warnExceptions = { IllegalArgumentException.class }) - static void fromFieldAndLiteral(LongBlock.Builder results, int p, BytesRefBlock wkbBlock, @Fixed int precision) { + static void fromFieldAndLiteral(LongBlock.Builder results, @Position int p, BytesRefBlock wkbBlock, @Fixed int precision) { fromWKB(results, p, wkbBlock, precision, unboundedGrid); } @Evaluator(extraName = "FromFieldDocValuesAndLiteral", warnExceptions = { IllegalArgumentException.class }) - static void fromFieldDocValuesAndLiteral(LongBlock.Builder results, int p, LongBlock encoded, @Fixed int precision) { + static void fromFieldDocValuesAndLiteral(LongBlock.Builder results, @Position int p, LongBlock encoded, @Fixed int precision) { fromEncodedLong(results, p, encoded, precision, unboundedGrid); } @Evaluator(extraName = "FromFieldAndLiteralAndLiteral", warnExceptions = { IllegalArgumentException.class }) static void fromFieldAndLiteralAndLiteral( LongBlock.Builder results, - int p, + @Position int p, BytesRefBlock in, @Fixed(includeInToString = false, scope = THREAD_LOCAL) GeoTileBoundedGrid bounds ) { @@ -238,7 +239,7 @@ static void fromFieldAndLiteralAndLiteral( @Evaluator(extraName = "FromFieldDocValuesAndLiteralAndLiteral", warnExceptions = { IllegalArgumentException.class }) static void fromFieldDocValuesAndLiteralAndLiteral( LongBlock.Builder results, - int p, + @Position int p, LongBlock encoded, @Fixed(includeInToString = false, scope = THREAD_LOCAL) GeoTileBoundedGrid bounds ) { From 8b32da7f45d7f555e6fd5b5be004585b11db9e38 Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Sun, 21 Sep 2025 14:17:46 -0400 Subject: [PATCH 3/3] format --- .../expression/function/scalar/multivalue/MvAppend.java | 2 +- .../esql/expression/function/scalar/multivalue/MvZip.java | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/multivalue/MvAppend.java b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/multivalue/MvAppend.java index 20b196c05e571..a950fca954101 100644 --- a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/multivalue/MvAppend.java +++ b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/multivalue/MvAppend.java @@ -273,7 +273,7 @@ static void process(LongBlock.Builder builder, @Position int position, LongBlock } @Evaluator(extraName = "Double") - static void process(DoubleBlock.Builder builder,@Position int position, DoubleBlock field1, DoubleBlock field2) { + static void process(DoubleBlock.Builder builder, @Position int position, DoubleBlock field1, DoubleBlock field2) { int count1 = field1.getValueCount(position); int count2 = field2.getValueCount(position); if (count1 == 0 || count2 == 0) { diff --git a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/multivalue/MvZip.java b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/multivalue/MvZip.java index ded86c934b68c..2c4136bc59e9b 100644 --- a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/multivalue/MvZip.java +++ b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/multivalue/MvZip.java @@ -164,7 +164,13 @@ private static void buildOneSide(BytesRefBlock.Builder builder, int start, int e } @Evaluator - static void process(BytesRefBlock.Builder builder, @Position int position, BytesRefBlock leftField, BytesRefBlock rightField, BytesRef delim) { + static void process( + BytesRefBlock.Builder builder, + @Position int position, + BytesRefBlock leftField, + BytesRefBlock rightField, + BytesRef delim + ) { int leftFieldValueCount = leftField.getValueCount(position); int rightFieldValueCount = rightField.getValueCount(position);