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 67ce0cf709704..48269e7e2af9b 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 @@ -240,8 +240,10 @@ private TypeSpec type() { builder.addMethod(intermediateStateDesc()); builder.addMethod(intermediateBlockCount()); builder.addMethod(addRawInput()); - builder.addMethod(addRawVector()); - builder.addMethod(addRawBlock()); + builder.addMethod(addRawVector(false)); + builder.addMethod(addRawVector(true)); + builder.addMethod(addRawBlock(false)); + builder.addMethod(addRawBlock(true)); builder.addMethod(addIntermediateInput()); builder.addMethod(evaluateIntermediate()); builder.addMethod(evaluateFinal()); @@ -345,22 +347,48 @@ private MethodSpec intermediateBlockCount() { private MethodSpec addRawInput() { MethodSpec.Builder builder = MethodSpec.methodBuilder("addRawInput"); - builder.addAnnotation(Override.class).addModifiers(Modifier.PUBLIC).addParameter(PAGE, "page"); + builder.addAnnotation(Override.class).addModifiers(Modifier.PUBLIC).addParameter(PAGE, "page").addParameter(BOOLEAN_VECTOR, "mask"); if (stateTypeHasFailed) { builder.beginControlFlow("if (state.failed())"); builder.addStatement("return"); builder.endControlFlow(); } + builder.beginControlFlow("if (mask.isConstant())"); + { + builder.beginControlFlow("if (mask.getBoolean(0) == false)"); + { + builder.addComment("Entire page masked away"); + builder.addStatement("return"); + } + builder.endControlFlow(); + builder.addComment("No masking"); + builder.addStatement("$T block = page.getBlock(channels.get(0))", valueBlockType(init, combine)); + builder.addStatement("$T vector = block.asVector()", valueVectorType(init, combine)); + builder.beginControlFlow("if (vector != null)"); + builder.addStatement("addRawVector(vector)"); + builder.nextControlFlow("else"); + builder.addStatement("addRawBlock(block)"); + builder.endControlFlow(); + builder.addStatement("return"); + } + builder.endControlFlow(); + builder.addComment("Some positions masked away, others kept"); builder.addStatement("$T block = page.getBlock(channels.get(0))", valueBlockType(init, combine)); builder.addStatement("$T vector = block.asVector()", valueVectorType(init, combine)); - builder.beginControlFlow("if (vector != null)").addStatement("addRawVector(vector)"); - builder.nextControlFlow("else").addStatement("addRawBlock(block)").endControlFlow(); + builder.beginControlFlow("if (vector != null)"); + builder.addStatement("addRawVector(vector, mask)"); + builder.nextControlFlow("else"); + builder.addStatement("addRawBlock(block, mask)"); + builder.endControlFlow(); return builder.build(); } - private MethodSpec addRawVector() { + private MethodSpec addRawVector(boolean masked) { MethodSpec.Builder builder = MethodSpec.methodBuilder("addRawVector"); builder.addModifiers(Modifier.PRIVATE).addParameter(valueVectorType(init, combine), "vector"); + if (masked) { + builder.addParameter(BOOLEAN_VECTOR, "mask"); + } if (stateTypeHasSeen) { builder.addStatement("state.seen(true)"); @@ -372,6 +400,9 @@ private MethodSpec addRawVector() { builder.beginControlFlow("for (int i = 0; i < vector.getPositionCount(); i++)"); { + if (masked) { + builder.beginControlFlow("if (mask.getBoolean(i) == false)").addStatement("continue").endControlFlow(); + } combineRawInput(builder, "vector"); } builder.endControlFlow(); @@ -381,9 +412,12 @@ private MethodSpec addRawVector() { return builder.build(); } - private MethodSpec addRawBlock() { + private MethodSpec addRawBlock(boolean masked) { MethodSpec.Builder builder = MethodSpec.methodBuilder("addRawBlock"); builder.addModifiers(Modifier.PRIVATE).addParameter(valueBlockType(init, combine), "block"); + if (masked) { + builder.addParameter(BOOLEAN_VECTOR, "mask"); + } if (valuesIsBytesRef) { // Add bytes_ref scratch var that will only be used for bytes_ref blocks/vectors @@ -391,6 +425,9 @@ private MethodSpec addRawBlock() { } builder.beginControlFlow("for (int p = 0; p < block.getPositionCount(); p++)"); { + if (masked) { + builder.beginControlFlow("if (mask.getBoolean(p) == false)").addStatement("continue").endControlFlow(); + } builder.beginControlFlow("if (block.isNull(p))"); builder.addStatement("continue"); builder.endControlFlow(); diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/CountDistinctBooleanAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/CountDistinctBooleanAggregatorFunction.java index e9b4498d50265..37543714717de 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/CountDistinctBooleanAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/CountDistinctBooleanAggregatorFunction.java @@ -53,13 +53,29 @@ public int intermediateBlockCount() { } @Override - public void addRawInput(Page page) { + public void addRawInput(Page page, BooleanVector mask) { + if (mask.isConstant()) { + if (mask.getBoolean(0) == false) { + // Entire page masked away + return; + } + // No masking + BooleanBlock block = page.getBlock(channels.get(0)); + BooleanVector vector = block.asVector(); + if (vector != null) { + addRawVector(vector); + } else { + addRawBlock(block); + } + return; + } + // Some positions masked away, others kept BooleanBlock block = page.getBlock(channels.get(0)); BooleanVector vector = block.asVector(); if (vector != null) { - addRawVector(vector); + addRawVector(vector, mask); } else { - addRawBlock(block); + addRawBlock(block, mask); } } @@ -69,6 +85,15 @@ private void addRawVector(BooleanVector vector) { } } + private void addRawVector(BooleanVector vector, BooleanVector mask) { + for (int i = 0; i < vector.getPositionCount(); i++) { + if (mask.getBoolean(i) == false) { + continue; + } + CountDistinctBooleanAggregator.combine(state, vector.getBoolean(i)); + } + } + private void addRawBlock(BooleanBlock block) { for (int p = 0; p < block.getPositionCount(); p++) { if (block.isNull(p)) { @@ -82,6 +107,22 @@ private void addRawBlock(BooleanBlock block) { } } + private void addRawBlock(BooleanBlock block, BooleanVector mask) { + for (int p = 0; p < block.getPositionCount(); p++) { + if (mask.getBoolean(p) == false) { + continue; + } + if (block.isNull(p)) { + continue; + } + int start = block.getFirstValueIndex(p); + int end = start + block.getValueCount(p); + for (int i = start; i < end; i++) { + CountDistinctBooleanAggregator.combine(state, block.getBoolean(i)); + } + } + } + @Override public void addIntermediateInput(Page page) { assert channels.size() == intermediateBlockCount(); diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/CountDistinctBytesRefAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/CountDistinctBytesRefAggregatorFunction.java index 83917ba218285..77d7e88cf9a93 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/CountDistinctBytesRefAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/CountDistinctBytesRefAggregatorFunction.java @@ -11,6 +11,7 @@ import java.util.List; import org.apache.lucene.util.BytesRef; import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.BooleanVector; import org.elasticsearch.compute.data.BytesRefBlock; import org.elasticsearch.compute.data.BytesRefVector; import org.elasticsearch.compute.data.ElementType; @@ -56,13 +57,29 @@ public int intermediateBlockCount() { } @Override - public void addRawInput(Page page) { + public void addRawInput(Page page, BooleanVector mask) { + if (mask.isConstant()) { + if (mask.getBoolean(0) == false) { + // Entire page masked away + return; + } + // No masking + BytesRefBlock block = page.getBlock(channels.get(0)); + BytesRefVector vector = block.asVector(); + if (vector != null) { + addRawVector(vector); + } else { + addRawBlock(block); + } + return; + } + // Some positions masked away, others kept BytesRefBlock block = page.getBlock(channels.get(0)); BytesRefVector vector = block.asVector(); if (vector != null) { - addRawVector(vector); + addRawVector(vector, mask); } else { - addRawBlock(block); + addRawBlock(block, mask); } } @@ -73,6 +90,16 @@ private void addRawVector(BytesRefVector vector) { } } + private void addRawVector(BytesRefVector vector, BooleanVector mask) { + BytesRef scratch = new BytesRef(); + for (int i = 0; i < vector.getPositionCount(); i++) { + if (mask.getBoolean(i) == false) { + continue; + } + CountDistinctBytesRefAggregator.combine(state, vector.getBytesRef(i, scratch)); + } + } + private void addRawBlock(BytesRefBlock block) { BytesRef scratch = new BytesRef(); for (int p = 0; p < block.getPositionCount(); p++) { @@ -87,6 +114,23 @@ private void addRawBlock(BytesRefBlock block) { } } + private void addRawBlock(BytesRefBlock block, BooleanVector mask) { + BytesRef scratch = new BytesRef(); + for (int p = 0; p < block.getPositionCount(); p++) { + if (mask.getBoolean(p) == false) { + continue; + } + if (block.isNull(p)) { + continue; + } + int start = block.getFirstValueIndex(p); + int end = start + block.getValueCount(p); + for (int i = start; i < end; i++) { + CountDistinctBytesRefAggregator.combine(state, block.getBytesRef(i, scratch)); + } + } + } + @Override public void addIntermediateInput(Page page) { assert channels.size() == intermediateBlockCount(); diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/CountDistinctDoubleAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/CountDistinctDoubleAggregatorFunction.java index c720df313bd99..4f0604b4f03c4 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/CountDistinctDoubleAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/CountDistinctDoubleAggregatorFunction.java @@ -11,6 +11,7 @@ import java.util.List; import org.apache.lucene.util.BytesRef; import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.BooleanVector; import org.elasticsearch.compute.data.BytesRefBlock; import org.elasticsearch.compute.data.BytesRefVector; import org.elasticsearch.compute.data.DoubleBlock; @@ -58,13 +59,29 @@ public int intermediateBlockCount() { } @Override - public void addRawInput(Page page) { + public void addRawInput(Page page, BooleanVector mask) { + if (mask.isConstant()) { + if (mask.getBoolean(0) == false) { + // Entire page masked away + return; + } + // No masking + DoubleBlock block = page.getBlock(channels.get(0)); + DoubleVector vector = block.asVector(); + if (vector != null) { + addRawVector(vector); + } else { + addRawBlock(block); + } + return; + } + // Some positions masked away, others kept DoubleBlock block = page.getBlock(channels.get(0)); DoubleVector vector = block.asVector(); if (vector != null) { - addRawVector(vector); + addRawVector(vector, mask); } else { - addRawBlock(block); + addRawBlock(block, mask); } } @@ -74,6 +91,15 @@ private void addRawVector(DoubleVector vector) { } } + private void addRawVector(DoubleVector vector, BooleanVector mask) { + for (int i = 0; i < vector.getPositionCount(); i++) { + if (mask.getBoolean(i) == false) { + continue; + } + CountDistinctDoubleAggregator.combine(state, vector.getDouble(i)); + } + } + private void addRawBlock(DoubleBlock block) { for (int p = 0; p < block.getPositionCount(); p++) { if (block.isNull(p)) { @@ -87,6 +113,22 @@ private void addRawBlock(DoubleBlock block) { } } + private void addRawBlock(DoubleBlock block, BooleanVector mask) { + for (int p = 0; p < block.getPositionCount(); p++) { + if (mask.getBoolean(p) == false) { + continue; + } + if (block.isNull(p)) { + continue; + } + int start = block.getFirstValueIndex(p); + int end = start + block.getValueCount(p); + for (int i = start; i < end; i++) { + CountDistinctDoubleAggregator.combine(state, block.getDouble(i)); + } + } + } + @Override public void addIntermediateInput(Page page) { assert channels.size() == intermediateBlockCount(); diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/CountDistinctFloatAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/CountDistinctFloatAggregatorFunction.java index aad616eac95a1..00e5335138aa9 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/CountDistinctFloatAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/CountDistinctFloatAggregatorFunction.java @@ -11,6 +11,7 @@ import java.util.List; import org.apache.lucene.util.BytesRef; import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.BooleanVector; import org.elasticsearch.compute.data.BytesRefBlock; import org.elasticsearch.compute.data.BytesRefVector; import org.elasticsearch.compute.data.ElementType; @@ -58,13 +59,29 @@ public int intermediateBlockCount() { } @Override - public void addRawInput(Page page) { + public void addRawInput(Page page, BooleanVector mask) { + if (mask.isConstant()) { + if (mask.getBoolean(0) == false) { + // Entire page masked away + return; + } + // No masking + FloatBlock block = page.getBlock(channels.get(0)); + FloatVector vector = block.asVector(); + if (vector != null) { + addRawVector(vector); + } else { + addRawBlock(block); + } + return; + } + // Some positions masked away, others kept FloatBlock block = page.getBlock(channels.get(0)); FloatVector vector = block.asVector(); if (vector != null) { - addRawVector(vector); + addRawVector(vector, mask); } else { - addRawBlock(block); + addRawBlock(block, mask); } } @@ -74,6 +91,15 @@ private void addRawVector(FloatVector vector) { } } + private void addRawVector(FloatVector vector, BooleanVector mask) { + for (int i = 0; i < vector.getPositionCount(); i++) { + if (mask.getBoolean(i) == false) { + continue; + } + CountDistinctFloatAggregator.combine(state, vector.getFloat(i)); + } + } + private void addRawBlock(FloatBlock block) { for (int p = 0; p < block.getPositionCount(); p++) { if (block.isNull(p)) { @@ -87,6 +113,22 @@ private void addRawBlock(FloatBlock block) { } } + private void addRawBlock(FloatBlock block, BooleanVector mask) { + for (int p = 0; p < block.getPositionCount(); p++) { + if (mask.getBoolean(p) == false) { + continue; + } + if (block.isNull(p)) { + continue; + } + int start = block.getFirstValueIndex(p); + int end = start + block.getValueCount(p); + for (int i = start; i < end; i++) { + CountDistinctFloatAggregator.combine(state, block.getFloat(i)); + } + } + } + @Override public void addIntermediateInput(Page page) { assert channels.size() == intermediateBlockCount(); diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/CountDistinctIntAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/CountDistinctIntAggregatorFunction.java index 083c483a9c9bc..90b4947b77d92 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/CountDistinctIntAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/CountDistinctIntAggregatorFunction.java @@ -11,6 +11,7 @@ import java.util.List; import org.apache.lucene.util.BytesRef; import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.BooleanVector; import org.elasticsearch.compute.data.BytesRefBlock; import org.elasticsearch.compute.data.BytesRefVector; import org.elasticsearch.compute.data.ElementType; @@ -58,13 +59,29 @@ public int intermediateBlockCount() { } @Override - public void addRawInput(Page page) { + public void addRawInput(Page page, BooleanVector mask) { + if (mask.isConstant()) { + if (mask.getBoolean(0) == false) { + // Entire page masked away + return; + } + // No masking + IntBlock block = page.getBlock(channels.get(0)); + IntVector vector = block.asVector(); + if (vector != null) { + addRawVector(vector); + } else { + addRawBlock(block); + } + return; + } + // Some positions masked away, others kept IntBlock block = page.getBlock(channels.get(0)); IntVector vector = block.asVector(); if (vector != null) { - addRawVector(vector); + addRawVector(vector, mask); } else { - addRawBlock(block); + addRawBlock(block, mask); } } @@ -74,6 +91,15 @@ private void addRawVector(IntVector vector) { } } + private void addRawVector(IntVector vector, BooleanVector mask) { + for (int i = 0; i < vector.getPositionCount(); i++) { + if (mask.getBoolean(i) == false) { + continue; + } + CountDistinctIntAggregator.combine(state, vector.getInt(i)); + } + } + private void addRawBlock(IntBlock block) { for (int p = 0; p < block.getPositionCount(); p++) { if (block.isNull(p)) { @@ -87,6 +113,22 @@ private void addRawBlock(IntBlock block) { } } + private void addRawBlock(IntBlock block, BooleanVector mask) { + for (int p = 0; p < block.getPositionCount(); p++) { + if (mask.getBoolean(p) == false) { + continue; + } + if (block.isNull(p)) { + continue; + } + int start = block.getFirstValueIndex(p); + int end = start + block.getValueCount(p); + for (int i = start; i < end; i++) { + CountDistinctIntAggregator.combine(state, block.getInt(i)); + } + } + } + @Override public void addIntermediateInput(Page page) { assert channels.size() == intermediateBlockCount(); diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/CountDistinctLongAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/CountDistinctLongAggregatorFunction.java index ee6fb5b470442..99dc37d58a88c 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/CountDistinctLongAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/CountDistinctLongAggregatorFunction.java @@ -11,6 +11,7 @@ import java.util.List; import org.apache.lucene.util.BytesRef; import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.BooleanVector; import org.elasticsearch.compute.data.BytesRefBlock; import org.elasticsearch.compute.data.BytesRefVector; import org.elasticsearch.compute.data.ElementType; @@ -58,13 +59,29 @@ public int intermediateBlockCount() { } @Override - public void addRawInput(Page page) { + public void addRawInput(Page page, BooleanVector mask) { + if (mask.isConstant()) { + if (mask.getBoolean(0) == false) { + // Entire page masked away + return; + } + // No masking + LongBlock block = page.getBlock(channels.get(0)); + LongVector vector = block.asVector(); + if (vector != null) { + addRawVector(vector); + } else { + addRawBlock(block); + } + return; + } + // Some positions masked away, others kept LongBlock block = page.getBlock(channels.get(0)); LongVector vector = block.asVector(); if (vector != null) { - addRawVector(vector); + addRawVector(vector, mask); } else { - addRawBlock(block); + addRawBlock(block, mask); } } @@ -74,6 +91,15 @@ private void addRawVector(LongVector vector) { } } + private void addRawVector(LongVector vector, BooleanVector mask) { + for (int i = 0; i < vector.getPositionCount(); i++) { + if (mask.getBoolean(i) == false) { + continue; + } + CountDistinctLongAggregator.combine(state, vector.getLong(i)); + } + } + private void addRawBlock(LongBlock block) { for (int p = 0; p < block.getPositionCount(); p++) { if (block.isNull(p)) { @@ -87,6 +113,22 @@ private void addRawBlock(LongBlock block) { } } + private void addRawBlock(LongBlock block, BooleanVector mask) { + for (int p = 0; p < block.getPositionCount(); p++) { + if (mask.getBoolean(p) == false) { + continue; + } + if (block.isNull(p)) { + continue; + } + int start = block.getFirstValueIndex(p); + int end = start + block.getValueCount(p); + for (int i = start; i < end; i++) { + CountDistinctLongAggregator.combine(state, block.getLong(i)); + } + } + } + @Override public void addIntermediateInput(Page page) { assert channels.size() == intermediateBlockCount(); diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/MaxBooleanAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/MaxBooleanAggregatorFunction.java index 2ffbcfc2d9458..38de18bea776a 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/MaxBooleanAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/MaxBooleanAggregatorFunction.java @@ -53,13 +53,29 @@ public int intermediateBlockCount() { } @Override - public void addRawInput(Page page) { + public void addRawInput(Page page, BooleanVector mask) { + if (mask.isConstant()) { + if (mask.getBoolean(0) == false) { + // Entire page masked away + return; + } + // No masking + BooleanBlock block = page.getBlock(channels.get(0)); + BooleanVector vector = block.asVector(); + if (vector != null) { + addRawVector(vector); + } else { + addRawBlock(block); + } + return; + } + // Some positions masked away, others kept BooleanBlock block = page.getBlock(channels.get(0)); BooleanVector vector = block.asVector(); if (vector != null) { - addRawVector(vector); + addRawVector(vector, mask); } else { - addRawBlock(block); + addRawBlock(block, mask); } } @@ -70,6 +86,16 @@ private void addRawVector(BooleanVector vector) { } } + private void addRawVector(BooleanVector vector, BooleanVector mask) { + state.seen(true); + for (int i = 0; i < vector.getPositionCount(); i++) { + if (mask.getBoolean(i) == false) { + continue; + } + state.booleanValue(MaxBooleanAggregator.combine(state.booleanValue(), vector.getBoolean(i))); + } + } + private void addRawBlock(BooleanBlock block) { for (int p = 0; p < block.getPositionCount(); p++) { if (block.isNull(p)) { @@ -84,6 +110,23 @@ private void addRawBlock(BooleanBlock block) { } } + private void addRawBlock(BooleanBlock block, BooleanVector mask) { + for (int p = 0; p < block.getPositionCount(); p++) { + if (mask.getBoolean(p) == false) { + continue; + } + if (block.isNull(p)) { + continue; + } + state.seen(true); + int start = block.getFirstValueIndex(p); + int end = start + block.getValueCount(p); + for (int i = start; i < end; i++) { + state.booleanValue(MaxBooleanAggregator.combine(state.booleanValue(), block.getBoolean(i))); + } + } + } + @Override public void addIntermediateInput(Page page) { assert channels.size() == intermediateBlockCount(); diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/MaxBytesRefAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/MaxBytesRefAggregatorFunction.java index 62897c61ea80e..1a4d440d2b8bc 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/MaxBytesRefAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/MaxBytesRefAggregatorFunction.java @@ -56,13 +56,29 @@ public int intermediateBlockCount() { } @Override - public void addRawInput(Page page) { + public void addRawInput(Page page, BooleanVector mask) { + if (mask.isConstant()) { + if (mask.getBoolean(0) == false) { + // Entire page masked away + return; + } + // No masking + BytesRefBlock block = page.getBlock(channels.get(0)); + BytesRefVector vector = block.asVector(); + if (vector != null) { + addRawVector(vector); + } else { + addRawBlock(block); + } + return; + } + // Some positions masked away, others kept BytesRefBlock block = page.getBlock(channels.get(0)); BytesRefVector vector = block.asVector(); if (vector != null) { - addRawVector(vector); + addRawVector(vector, mask); } else { - addRawBlock(block); + addRawBlock(block, mask); } } @@ -73,6 +89,16 @@ private void addRawVector(BytesRefVector vector) { } } + private void addRawVector(BytesRefVector vector, BooleanVector mask) { + BytesRef scratch = new BytesRef(); + for (int i = 0; i < vector.getPositionCount(); i++) { + if (mask.getBoolean(i) == false) { + continue; + } + MaxBytesRefAggregator.combine(state, vector.getBytesRef(i, scratch)); + } + } + private void addRawBlock(BytesRefBlock block) { BytesRef scratch = new BytesRef(); for (int p = 0; p < block.getPositionCount(); p++) { @@ -87,6 +113,23 @@ private void addRawBlock(BytesRefBlock block) { } } + private void addRawBlock(BytesRefBlock block, BooleanVector mask) { + BytesRef scratch = new BytesRef(); + for (int p = 0; p < block.getPositionCount(); p++) { + if (mask.getBoolean(p) == false) { + continue; + } + if (block.isNull(p)) { + continue; + } + int start = block.getFirstValueIndex(p); + int end = start + block.getValueCount(p); + for (int i = start; i < end; i++) { + MaxBytesRefAggregator.combine(state, block.getBytesRef(i, scratch)); + } + } + } + @Override public void addIntermediateInput(Page page) { assert channels.size() == intermediateBlockCount(); diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/MaxDoubleAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/MaxDoubleAggregatorFunction.java index f78a8773ccfcd..266977e2a689c 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/MaxDoubleAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/MaxDoubleAggregatorFunction.java @@ -55,13 +55,29 @@ public int intermediateBlockCount() { } @Override - public void addRawInput(Page page) { + public void addRawInput(Page page, BooleanVector mask) { + if (mask.isConstant()) { + if (mask.getBoolean(0) == false) { + // Entire page masked away + return; + } + // No masking + DoubleBlock block = page.getBlock(channels.get(0)); + DoubleVector vector = block.asVector(); + if (vector != null) { + addRawVector(vector); + } else { + addRawBlock(block); + } + return; + } + // Some positions masked away, others kept DoubleBlock block = page.getBlock(channels.get(0)); DoubleVector vector = block.asVector(); if (vector != null) { - addRawVector(vector); + addRawVector(vector, mask); } else { - addRawBlock(block); + addRawBlock(block, mask); } } @@ -72,6 +88,16 @@ private void addRawVector(DoubleVector vector) { } } + private void addRawVector(DoubleVector vector, BooleanVector mask) { + state.seen(true); + for (int i = 0; i < vector.getPositionCount(); i++) { + if (mask.getBoolean(i) == false) { + continue; + } + state.doubleValue(MaxDoubleAggregator.combine(state.doubleValue(), vector.getDouble(i))); + } + } + private void addRawBlock(DoubleBlock block) { for (int p = 0; p < block.getPositionCount(); p++) { if (block.isNull(p)) { @@ -86,6 +112,23 @@ private void addRawBlock(DoubleBlock block) { } } + private void addRawBlock(DoubleBlock block, BooleanVector mask) { + for (int p = 0; p < block.getPositionCount(); p++) { + if (mask.getBoolean(p) == false) { + continue; + } + if (block.isNull(p)) { + continue; + } + state.seen(true); + int start = block.getFirstValueIndex(p); + int end = start + block.getValueCount(p); + for (int i = start; i < end; i++) { + state.doubleValue(MaxDoubleAggregator.combine(state.doubleValue(), block.getDouble(i))); + } + } + } + @Override public void addIntermediateInput(Page page) { assert channels.size() == intermediateBlockCount(); diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/MaxFloatAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/MaxFloatAggregatorFunction.java index 0dcef4341727d..3a4dcaa3289fe 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/MaxFloatAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/MaxFloatAggregatorFunction.java @@ -55,13 +55,29 @@ public int intermediateBlockCount() { } @Override - public void addRawInput(Page page) { + public void addRawInput(Page page, BooleanVector mask) { + if (mask.isConstant()) { + if (mask.getBoolean(0) == false) { + // Entire page masked away + return; + } + // No masking + FloatBlock block = page.getBlock(channels.get(0)); + FloatVector vector = block.asVector(); + if (vector != null) { + addRawVector(vector); + } else { + addRawBlock(block); + } + return; + } + // Some positions masked away, others kept FloatBlock block = page.getBlock(channels.get(0)); FloatVector vector = block.asVector(); if (vector != null) { - addRawVector(vector); + addRawVector(vector, mask); } else { - addRawBlock(block); + addRawBlock(block, mask); } } @@ -72,6 +88,16 @@ private void addRawVector(FloatVector vector) { } } + private void addRawVector(FloatVector vector, BooleanVector mask) { + state.seen(true); + for (int i = 0; i < vector.getPositionCount(); i++) { + if (mask.getBoolean(i) == false) { + continue; + } + state.floatValue(MaxFloatAggregator.combine(state.floatValue(), vector.getFloat(i))); + } + } + private void addRawBlock(FloatBlock block) { for (int p = 0; p < block.getPositionCount(); p++) { if (block.isNull(p)) { @@ -86,6 +112,23 @@ private void addRawBlock(FloatBlock block) { } } + private void addRawBlock(FloatBlock block, BooleanVector mask) { + for (int p = 0; p < block.getPositionCount(); p++) { + if (mask.getBoolean(p) == false) { + continue; + } + if (block.isNull(p)) { + continue; + } + state.seen(true); + int start = block.getFirstValueIndex(p); + int end = start + block.getValueCount(p); + for (int i = start; i < end; i++) { + state.floatValue(MaxFloatAggregator.combine(state.floatValue(), block.getFloat(i))); + } + } + } + @Override public void addIntermediateInput(Page page) { assert channels.size() == intermediateBlockCount(); diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/MaxIntAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/MaxIntAggregatorFunction.java index 6f83ee7224879..d5c0cea243499 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/MaxIntAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/MaxIntAggregatorFunction.java @@ -55,13 +55,29 @@ public int intermediateBlockCount() { } @Override - public void addRawInput(Page page) { + public void addRawInput(Page page, BooleanVector mask) { + if (mask.isConstant()) { + if (mask.getBoolean(0) == false) { + // Entire page masked away + return; + } + // No masking + IntBlock block = page.getBlock(channels.get(0)); + IntVector vector = block.asVector(); + if (vector != null) { + addRawVector(vector); + } else { + addRawBlock(block); + } + return; + } + // Some positions masked away, others kept IntBlock block = page.getBlock(channels.get(0)); IntVector vector = block.asVector(); if (vector != null) { - addRawVector(vector); + addRawVector(vector, mask); } else { - addRawBlock(block); + addRawBlock(block, mask); } } @@ -72,6 +88,16 @@ private void addRawVector(IntVector vector) { } } + private void addRawVector(IntVector vector, BooleanVector mask) { + state.seen(true); + for (int i = 0; i < vector.getPositionCount(); i++) { + if (mask.getBoolean(i) == false) { + continue; + } + state.intValue(MaxIntAggregator.combine(state.intValue(), vector.getInt(i))); + } + } + private void addRawBlock(IntBlock block) { for (int p = 0; p < block.getPositionCount(); p++) { if (block.isNull(p)) { @@ -86,6 +112,23 @@ private void addRawBlock(IntBlock block) { } } + private void addRawBlock(IntBlock block, BooleanVector mask) { + for (int p = 0; p < block.getPositionCount(); p++) { + if (mask.getBoolean(p) == false) { + continue; + } + if (block.isNull(p)) { + continue; + } + state.seen(true); + int start = block.getFirstValueIndex(p); + int end = start + block.getValueCount(p); + for (int i = start; i < end; i++) { + state.intValue(MaxIntAggregator.combine(state.intValue(), block.getInt(i))); + } + } + } + @Override public void addIntermediateInput(Page page) { assert channels.size() == intermediateBlockCount(); diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/MaxIpAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/MaxIpAggregatorFunction.java index 9f714246ea332..13c74775d2796 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/MaxIpAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/MaxIpAggregatorFunction.java @@ -56,13 +56,29 @@ public int intermediateBlockCount() { } @Override - public void addRawInput(Page page) { + public void addRawInput(Page page, BooleanVector mask) { + if (mask.isConstant()) { + if (mask.getBoolean(0) == false) { + // Entire page masked away + return; + } + // No masking + BytesRefBlock block = page.getBlock(channels.get(0)); + BytesRefVector vector = block.asVector(); + if (vector != null) { + addRawVector(vector); + } else { + addRawBlock(block); + } + return; + } + // Some positions masked away, others kept BytesRefBlock block = page.getBlock(channels.get(0)); BytesRefVector vector = block.asVector(); if (vector != null) { - addRawVector(vector); + addRawVector(vector, mask); } else { - addRawBlock(block); + addRawBlock(block, mask); } } @@ -73,6 +89,16 @@ private void addRawVector(BytesRefVector vector) { } } + private void addRawVector(BytesRefVector vector, BooleanVector mask) { + BytesRef scratch = new BytesRef(); + for (int i = 0; i < vector.getPositionCount(); i++) { + if (mask.getBoolean(i) == false) { + continue; + } + MaxIpAggregator.combine(state, vector.getBytesRef(i, scratch)); + } + } + private void addRawBlock(BytesRefBlock block) { BytesRef scratch = new BytesRef(); for (int p = 0; p < block.getPositionCount(); p++) { @@ -87,6 +113,23 @@ private void addRawBlock(BytesRefBlock block) { } } + private void addRawBlock(BytesRefBlock block, BooleanVector mask) { + BytesRef scratch = new BytesRef(); + for (int p = 0; p < block.getPositionCount(); p++) { + if (mask.getBoolean(p) == false) { + continue; + } + if (block.isNull(p)) { + continue; + } + int start = block.getFirstValueIndex(p); + int end = start + block.getValueCount(p); + for (int i = start; i < end; i++) { + MaxIpAggregator.combine(state, block.getBytesRef(i, scratch)); + } + } + } + @Override public void addIntermediateInput(Page page) { assert channels.size() == intermediateBlockCount(); diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/MaxLongAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/MaxLongAggregatorFunction.java index 8826128a68837..d2acff0509dfe 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/MaxLongAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/MaxLongAggregatorFunction.java @@ -55,13 +55,29 @@ public int intermediateBlockCount() { } @Override - public void addRawInput(Page page) { + public void addRawInput(Page page, BooleanVector mask) { + if (mask.isConstant()) { + if (mask.getBoolean(0) == false) { + // Entire page masked away + return; + } + // No masking + LongBlock block = page.getBlock(channels.get(0)); + LongVector vector = block.asVector(); + if (vector != null) { + addRawVector(vector); + } else { + addRawBlock(block); + } + return; + } + // Some positions masked away, others kept LongBlock block = page.getBlock(channels.get(0)); LongVector vector = block.asVector(); if (vector != null) { - addRawVector(vector); + addRawVector(vector, mask); } else { - addRawBlock(block); + addRawBlock(block, mask); } } @@ -72,6 +88,16 @@ private void addRawVector(LongVector vector) { } } + private void addRawVector(LongVector vector, BooleanVector mask) { + state.seen(true); + for (int i = 0; i < vector.getPositionCount(); i++) { + if (mask.getBoolean(i) == false) { + continue; + } + state.longValue(MaxLongAggregator.combine(state.longValue(), vector.getLong(i))); + } + } + private void addRawBlock(LongBlock block) { for (int p = 0; p < block.getPositionCount(); p++) { if (block.isNull(p)) { @@ -86,6 +112,23 @@ private void addRawBlock(LongBlock block) { } } + private void addRawBlock(LongBlock block, BooleanVector mask) { + for (int p = 0; p < block.getPositionCount(); p++) { + if (mask.getBoolean(p) == false) { + continue; + } + if (block.isNull(p)) { + continue; + } + state.seen(true); + int start = block.getFirstValueIndex(p); + int end = start + block.getValueCount(p); + for (int i = start; i < end; i++) { + state.longValue(MaxLongAggregator.combine(state.longValue(), block.getLong(i))); + } + } + } + @Override public void addIntermediateInput(Page page) { assert channels.size() == intermediateBlockCount(); diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/MedianAbsoluteDeviationDoubleAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/MedianAbsoluteDeviationDoubleAggregatorFunction.java index 4bcf08ce0fa35..068bb7a2bf0a5 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/MedianAbsoluteDeviationDoubleAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/MedianAbsoluteDeviationDoubleAggregatorFunction.java @@ -11,6 +11,7 @@ import java.util.List; import org.apache.lucene.util.BytesRef; import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.BooleanVector; import org.elasticsearch.compute.data.BytesRefBlock; import org.elasticsearch.compute.data.BytesRefVector; import org.elasticsearch.compute.data.DoubleBlock; @@ -55,13 +56,29 @@ public int intermediateBlockCount() { } @Override - public void addRawInput(Page page) { + public void addRawInput(Page page, BooleanVector mask) { + if (mask.isConstant()) { + if (mask.getBoolean(0) == false) { + // Entire page masked away + return; + } + // No masking + DoubleBlock block = page.getBlock(channels.get(0)); + DoubleVector vector = block.asVector(); + if (vector != null) { + addRawVector(vector); + } else { + addRawBlock(block); + } + return; + } + // Some positions masked away, others kept DoubleBlock block = page.getBlock(channels.get(0)); DoubleVector vector = block.asVector(); if (vector != null) { - addRawVector(vector); + addRawVector(vector, mask); } else { - addRawBlock(block); + addRawBlock(block, mask); } } @@ -71,6 +88,15 @@ private void addRawVector(DoubleVector vector) { } } + private void addRawVector(DoubleVector vector, BooleanVector mask) { + for (int i = 0; i < vector.getPositionCount(); i++) { + if (mask.getBoolean(i) == false) { + continue; + } + MedianAbsoluteDeviationDoubleAggregator.combine(state, vector.getDouble(i)); + } + } + private void addRawBlock(DoubleBlock block) { for (int p = 0; p < block.getPositionCount(); p++) { if (block.isNull(p)) { @@ -84,6 +110,22 @@ private void addRawBlock(DoubleBlock block) { } } + private void addRawBlock(DoubleBlock block, BooleanVector mask) { + for (int p = 0; p < block.getPositionCount(); p++) { + if (mask.getBoolean(p) == false) { + continue; + } + if (block.isNull(p)) { + continue; + } + int start = block.getFirstValueIndex(p); + int end = start + block.getValueCount(p); + for (int i = start; i < end; i++) { + MedianAbsoluteDeviationDoubleAggregator.combine(state, block.getDouble(i)); + } + } + } + @Override public void addIntermediateInput(Page page) { assert channels.size() == intermediateBlockCount(); diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/MedianAbsoluteDeviationFloatAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/MedianAbsoluteDeviationFloatAggregatorFunction.java index 38a16859140f8..71cb9964001f3 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/MedianAbsoluteDeviationFloatAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/MedianAbsoluteDeviationFloatAggregatorFunction.java @@ -11,6 +11,7 @@ import java.util.List; import org.apache.lucene.util.BytesRef; import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.BooleanVector; import org.elasticsearch.compute.data.BytesRefBlock; import org.elasticsearch.compute.data.BytesRefVector; import org.elasticsearch.compute.data.ElementType; @@ -55,13 +56,29 @@ public int intermediateBlockCount() { } @Override - public void addRawInput(Page page) { + public void addRawInput(Page page, BooleanVector mask) { + if (mask.isConstant()) { + if (mask.getBoolean(0) == false) { + // Entire page masked away + return; + } + // No masking + FloatBlock block = page.getBlock(channels.get(0)); + FloatVector vector = block.asVector(); + if (vector != null) { + addRawVector(vector); + } else { + addRawBlock(block); + } + return; + } + // Some positions masked away, others kept FloatBlock block = page.getBlock(channels.get(0)); FloatVector vector = block.asVector(); if (vector != null) { - addRawVector(vector); + addRawVector(vector, mask); } else { - addRawBlock(block); + addRawBlock(block, mask); } } @@ -71,6 +88,15 @@ private void addRawVector(FloatVector vector) { } } + private void addRawVector(FloatVector vector, BooleanVector mask) { + for (int i = 0; i < vector.getPositionCount(); i++) { + if (mask.getBoolean(i) == false) { + continue; + } + MedianAbsoluteDeviationFloatAggregator.combine(state, vector.getFloat(i)); + } + } + private void addRawBlock(FloatBlock block) { for (int p = 0; p < block.getPositionCount(); p++) { if (block.isNull(p)) { @@ -84,6 +110,22 @@ private void addRawBlock(FloatBlock block) { } } + private void addRawBlock(FloatBlock block, BooleanVector mask) { + for (int p = 0; p < block.getPositionCount(); p++) { + if (mask.getBoolean(p) == false) { + continue; + } + if (block.isNull(p)) { + continue; + } + int start = block.getFirstValueIndex(p); + int end = start + block.getValueCount(p); + for (int i = start; i < end; i++) { + MedianAbsoluteDeviationFloatAggregator.combine(state, block.getFloat(i)); + } + } + } + @Override public void addIntermediateInput(Page page) { assert channels.size() == intermediateBlockCount(); diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/MedianAbsoluteDeviationIntAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/MedianAbsoluteDeviationIntAggregatorFunction.java index db9dbdab52244..b4f547fb5b425 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/MedianAbsoluteDeviationIntAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/MedianAbsoluteDeviationIntAggregatorFunction.java @@ -11,6 +11,7 @@ import java.util.List; import org.apache.lucene.util.BytesRef; import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.BooleanVector; import org.elasticsearch.compute.data.BytesRefBlock; import org.elasticsearch.compute.data.BytesRefVector; import org.elasticsearch.compute.data.ElementType; @@ -55,13 +56,29 @@ public int intermediateBlockCount() { } @Override - public void addRawInput(Page page) { + public void addRawInput(Page page, BooleanVector mask) { + if (mask.isConstant()) { + if (mask.getBoolean(0) == false) { + // Entire page masked away + return; + } + // No masking + IntBlock block = page.getBlock(channels.get(0)); + IntVector vector = block.asVector(); + if (vector != null) { + addRawVector(vector); + } else { + addRawBlock(block); + } + return; + } + // Some positions masked away, others kept IntBlock block = page.getBlock(channels.get(0)); IntVector vector = block.asVector(); if (vector != null) { - addRawVector(vector); + addRawVector(vector, mask); } else { - addRawBlock(block); + addRawBlock(block, mask); } } @@ -71,6 +88,15 @@ private void addRawVector(IntVector vector) { } } + private void addRawVector(IntVector vector, BooleanVector mask) { + for (int i = 0; i < vector.getPositionCount(); i++) { + if (mask.getBoolean(i) == false) { + continue; + } + MedianAbsoluteDeviationIntAggregator.combine(state, vector.getInt(i)); + } + } + private void addRawBlock(IntBlock block) { for (int p = 0; p < block.getPositionCount(); p++) { if (block.isNull(p)) { @@ -84,6 +110,22 @@ private void addRawBlock(IntBlock block) { } } + private void addRawBlock(IntBlock block, BooleanVector mask) { + for (int p = 0; p < block.getPositionCount(); p++) { + if (mask.getBoolean(p) == false) { + continue; + } + if (block.isNull(p)) { + continue; + } + int start = block.getFirstValueIndex(p); + int end = start + block.getValueCount(p); + for (int i = start; i < end; i++) { + MedianAbsoluteDeviationIntAggregator.combine(state, block.getInt(i)); + } + } + } + @Override public void addIntermediateInput(Page page) { assert channels.size() == intermediateBlockCount(); diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/MedianAbsoluteDeviationLongAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/MedianAbsoluteDeviationLongAggregatorFunction.java index bf5fd51d7ed17..946e0243cf6f6 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/MedianAbsoluteDeviationLongAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/MedianAbsoluteDeviationLongAggregatorFunction.java @@ -11,6 +11,7 @@ import java.util.List; import org.apache.lucene.util.BytesRef; import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.BooleanVector; import org.elasticsearch.compute.data.BytesRefBlock; import org.elasticsearch.compute.data.BytesRefVector; import org.elasticsearch.compute.data.ElementType; @@ -55,13 +56,29 @@ public int intermediateBlockCount() { } @Override - public void addRawInput(Page page) { + public void addRawInput(Page page, BooleanVector mask) { + if (mask.isConstant()) { + if (mask.getBoolean(0) == false) { + // Entire page masked away + return; + } + // No masking + LongBlock block = page.getBlock(channels.get(0)); + LongVector vector = block.asVector(); + if (vector != null) { + addRawVector(vector); + } else { + addRawBlock(block); + } + return; + } + // Some positions masked away, others kept LongBlock block = page.getBlock(channels.get(0)); LongVector vector = block.asVector(); if (vector != null) { - addRawVector(vector); + addRawVector(vector, mask); } else { - addRawBlock(block); + addRawBlock(block, mask); } } @@ -71,6 +88,15 @@ private void addRawVector(LongVector vector) { } } + private void addRawVector(LongVector vector, BooleanVector mask) { + for (int i = 0; i < vector.getPositionCount(); i++) { + if (mask.getBoolean(i) == false) { + continue; + } + MedianAbsoluteDeviationLongAggregator.combine(state, vector.getLong(i)); + } + } + private void addRawBlock(LongBlock block) { for (int p = 0; p < block.getPositionCount(); p++) { if (block.isNull(p)) { @@ -84,6 +110,22 @@ private void addRawBlock(LongBlock block) { } } + private void addRawBlock(LongBlock block, BooleanVector mask) { + for (int p = 0; p < block.getPositionCount(); p++) { + if (mask.getBoolean(p) == false) { + continue; + } + if (block.isNull(p)) { + continue; + } + int start = block.getFirstValueIndex(p); + int end = start + block.getValueCount(p); + for (int i = start; i < end; i++) { + MedianAbsoluteDeviationLongAggregator.combine(state, block.getLong(i)); + } + } + } + @Override public void addIntermediateInput(Page page) { assert channels.size() == intermediateBlockCount(); diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/MinBooleanAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/MinBooleanAggregatorFunction.java index 101a6c7f9169a..9bd63ed8efbd8 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/MinBooleanAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/MinBooleanAggregatorFunction.java @@ -53,13 +53,29 @@ public int intermediateBlockCount() { } @Override - public void addRawInput(Page page) { + public void addRawInput(Page page, BooleanVector mask) { + if (mask.isConstant()) { + if (mask.getBoolean(0) == false) { + // Entire page masked away + return; + } + // No masking + BooleanBlock block = page.getBlock(channels.get(0)); + BooleanVector vector = block.asVector(); + if (vector != null) { + addRawVector(vector); + } else { + addRawBlock(block); + } + return; + } + // Some positions masked away, others kept BooleanBlock block = page.getBlock(channels.get(0)); BooleanVector vector = block.asVector(); if (vector != null) { - addRawVector(vector); + addRawVector(vector, mask); } else { - addRawBlock(block); + addRawBlock(block, mask); } } @@ -70,6 +86,16 @@ private void addRawVector(BooleanVector vector) { } } + private void addRawVector(BooleanVector vector, BooleanVector mask) { + state.seen(true); + for (int i = 0; i < vector.getPositionCount(); i++) { + if (mask.getBoolean(i) == false) { + continue; + } + state.booleanValue(MinBooleanAggregator.combine(state.booleanValue(), vector.getBoolean(i))); + } + } + private void addRawBlock(BooleanBlock block) { for (int p = 0; p < block.getPositionCount(); p++) { if (block.isNull(p)) { @@ -84,6 +110,23 @@ private void addRawBlock(BooleanBlock block) { } } + private void addRawBlock(BooleanBlock block, BooleanVector mask) { + for (int p = 0; p < block.getPositionCount(); p++) { + if (mask.getBoolean(p) == false) { + continue; + } + if (block.isNull(p)) { + continue; + } + state.seen(true); + int start = block.getFirstValueIndex(p); + int end = start + block.getValueCount(p); + for (int i = start; i < end; i++) { + state.booleanValue(MinBooleanAggregator.combine(state.booleanValue(), block.getBoolean(i))); + } + } + } + @Override public void addIntermediateInput(Page page) { assert channels.size() == intermediateBlockCount(); diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/MinBytesRefAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/MinBytesRefAggregatorFunction.java index 3346dd762f17f..2789f18a19dfc 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/MinBytesRefAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/MinBytesRefAggregatorFunction.java @@ -56,13 +56,29 @@ public int intermediateBlockCount() { } @Override - public void addRawInput(Page page) { + public void addRawInput(Page page, BooleanVector mask) { + if (mask.isConstant()) { + if (mask.getBoolean(0) == false) { + // Entire page masked away + return; + } + // No masking + BytesRefBlock block = page.getBlock(channels.get(0)); + BytesRefVector vector = block.asVector(); + if (vector != null) { + addRawVector(vector); + } else { + addRawBlock(block); + } + return; + } + // Some positions masked away, others kept BytesRefBlock block = page.getBlock(channels.get(0)); BytesRefVector vector = block.asVector(); if (vector != null) { - addRawVector(vector); + addRawVector(vector, mask); } else { - addRawBlock(block); + addRawBlock(block, mask); } } @@ -73,6 +89,16 @@ private void addRawVector(BytesRefVector vector) { } } + private void addRawVector(BytesRefVector vector, BooleanVector mask) { + BytesRef scratch = new BytesRef(); + for (int i = 0; i < vector.getPositionCount(); i++) { + if (mask.getBoolean(i) == false) { + continue; + } + MinBytesRefAggregator.combine(state, vector.getBytesRef(i, scratch)); + } + } + private void addRawBlock(BytesRefBlock block) { BytesRef scratch = new BytesRef(); for (int p = 0; p < block.getPositionCount(); p++) { @@ -87,6 +113,23 @@ private void addRawBlock(BytesRefBlock block) { } } + private void addRawBlock(BytesRefBlock block, BooleanVector mask) { + BytesRef scratch = new BytesRef(); + for (int p = 0; p < block.getPositionCount(); p++) { + if (mask.getBoolean(p) == false) { + continue; + } + if (block.isNull(p)) { + continue; + } + int start = block.getFirstValueIndex(p); + int end = start + block.getValueCount(p); + for (int i = start; i < end; i++) { + MinBytesRefAggregator.combine(state, block.getBytesRef(i, scratch)); + } + } + } + @Override public void addIntermediateInput(Page page) { assert channels.size() == intermediateBlockCount(); diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/MinDoubleAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/MinDoubleAggregatorFunction.java index 7d7544e5d8470..e736f91e0b38c 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/MinDoubleAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/MinDoubleAggregatorFunction.java @@ -55,13 +55,29 @@ public int intermediateBlockCount() { } @Override - public void addRawInput(Page page) { + public void addRawInput(Page page, BooleanVector mask) { + if (mask.isConstant()) { + if (mask.getBoolean(0) == false) { + // Entire page masked away + return; + } + // No masking + DoubleBlock block = page.getBlock(channels.get(0)); + DoubleVector vector = block.asVector(); + if (vector != null) { + addRawVector(vector); + } else { + addRawBlock(block); + } + return; + } + // Some positions masked away, others kept DoubleBlock block = page.getBlock(channels.get(0)); DoubleVector vector = block.asVector(); if (vector != null) { - addRawVector(vector); + addRawVector(vector, mask); } else { - addRawBlock(block); + addRawBlock(block, mask); } } @@ -72,6 +88,16 @@ private void addRawVector(DoubleVector vector) { } } + private void addRawVector(DoubleVector vector, BooleanVector mask) { + state.seen(true); + for (int i = 0; i < vector.getPositionCount(); i++) { + if (mask.getBoolean(i) == false) { + continue; + } + state.doubleValue(MinDoubleAggregator.combine(state.doubleValue(), vector.getDouble(i))); + } + } + private void addRawBlock(DoubleBlock block) { for (int p = 0; p < block.getPositionCount(); p++) { if (block.isNull(p)) { @@ -86,6 +112,23 @@ private void addRawBlock(DoubleBlock block) { } } + private void addRawBlock(DoubleBlock block, BooleanVector mask) { + for (int p = 0; p < block.getPositionCount(); p++) { + if (mask.getBoolean(p) == false) { + continue; + } + if (block.isNull(p)) { + continue; + } + state.seen(true); + int start = block.getFirstValueIndex(p); + int end = start + block.getValueCount(p); + for (int i = start; i < end; i++) { + state.doubleValue(MinDoubleAggregator.combine(state.doubleValue(), block.getDouble(i))); + } + } + } + @Override public void addIntermediateInput(Page page) { assert channels.size() == intermediateBlockCount(); diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/MinFloatAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/MinFloatAggregatorFunction.java index ecabcbdcf57bb..9d67ccb8fb736 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/MinFloatAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/MinFloatAggregatorFunction.java @@ -55,13 +55,29 @@ public int intermediateBlockCount() { } @Override - public void addRawInput(Page page) { + public void addRawInput(Page page, BooleanVector mask) { + if (mask.isConstant()) { + if (mask.getBoolean(0) == false) { + // Entire page masked away + return; + } + // No masking + FloatBlock block = page.getBlock(channels.get(0)); + FloatVector vector = block.asVector(); + if (vector != null) { + addRawVector(vector); + } else { + addRawBlock(block); + } + return; + } + // Some positions masked away, others kept FloatBlock block = page.getBlock(channels.get(0)); FloatVector vector = block.asVector(); if (vector != null) { - addRawVector(vector); + addRawVector(vector, mask); } else { - addRawBlock(block); + addRawBlock(block, mask); } } @@ -72,6 +88,16 @@ private void addRawVector(FloatVector vector) { } } + private void addRawVector(FloatVector vector, BooleanVector mask) { + state.seen(true); + for (int i = 0; i < vector.getPositionCount(); i++) { + if (mask.getBoolean(i) == false) { + continue; + } + state.floatValue(MinFloatAggregator.combine(state.floatValue(), vector.getFloat(i))); + } + } + private void addRawBlock(FloatBlock block) { for (int p = 0; p < block.getPositionCount(); p++) { if (block.isNull(p)) { @@ -86,6 +112,23 @@ private void addRawBlock(FloatBlock block) { } } + private void addRawBlock(FloatBlock block, BooleanVector mask) { + for (int p = 0; p < block.getPositionCount(); p++) { + if (mask.getBoolean(p) == false) { + continue; + } + if (block.isNull(p)) { + continue; + } + state.seen(true); + int start = block.getFirstValueIndex(p); + int end = start + block.getValueCount(p); + for (int i = start; i < end; i++) { + state.floatValue(MinFloatAggregator.combine(state.floatValue(), block.getFloat(i))); + } + } + } + @Override public void addIntermediateInput(Page page) { assert channels.size() == intermediateBlockCount(); diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/MinIntAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/MinIntAggregatorFunction.java index 0f2385cc120f9..a5ead0bd635c0 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/MinIntAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/MinIntAggregatorFunction.java @@ -55,13 +55,29 @@ public int intermediateBlockCount() { } @Override - public void addRawInput(Page page) { + public void addRawInput(Page page, BooleanVector mask) { + if (mask.isConstant()) { + if (mask.getBoolean(0) == false) { + // Entire page masked away + return; + } + // No masking + IntBlock block = page.getBlock(channels.get(0)); + IntVector vector = block.asVector(); + if (vector != null) { + addRawVector(vector); + } else { + addRawBlock(block); + } + return; + } + // Some positions masked away, others kept IntBlock block = page.getBlock(channels.get(0)); IntVector vector = block.asVector(); if (vector != null) { - addRawVector(vector); + addRawVector(vector, mask); } else { - addRawBlock(block); + addRawBlock(block, mask); } } @@ -72,6 +88,16 @@ private void addRawVector(IntVector vector) { } } + private void addRawVector(IntVector vector, BooleanVector mask) { + state.seen(true); + for (int i = 0; i < vector.getPositionCount(); i++) { + if (mask.getBoolean(i) == false) { + continue; + } + state.intValue(MinIntAggregator.combine(state.intValue(), vector.getInt(i))); + } + } + private void addRawBlock(IntBlock block) { for (int p = 0; p < block.getPositionCount(); p++) { if (block.isNull(p)) { @@ -86,6 +112,23 @@ private void addRawBlock(IntBlock block) { } } + private void addRawBlock(IntBlock block, BooleanVector mask) { + for (int p = 0; p < block.getPositionCount(); p++) { + if (mask.getBoolean(p) == false) { + continue; + } + if (block.isNull(p)) { + continue; + } + state.seen(true); + int start = block.getFirstValueIndex(p); + int end = start + block.getValueCount(p); + for (int i = start; i < end; i++) { + state.intValue(MinIntAggregator.combine(state.intValue(), block.getInt(i))); + } + } + } + @Override public void addIntermediateInput(Page page) { assert channels.size() == intermediateBlockCount(); diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/MinIpAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/MinIpAggregatorFunction.java index a47c901d70db4..60ba1993f45d8 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/MinIpAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/MinIpAggregatorFunction.java @@ -56,13 +56,29 @@ public int intermediateBlockCount() { } @Override - public void addRawInput(Page page) { + public void addRawInput(Page page, BooleanVector mask) { + if (mask.isConstant()) { + if (mask.getBoolean(0) == false) { + // Entire page masked away + return; + } + // No masking + BytesRefBlock block = page.getBlock(channels.get(0)); + BytesRefVector vector = block.asVector(); + if (vector != null) { + addRawVector(vector); + } else { + addRawBlock(block); + } + return; + } + // Some positions masked away, others kept BytesRefBlock block = page.getBlock(channels.get(0)); BytesRefVector vector = block.asVector(); if (vector != null) { - addRawVector(vector); + addRawVector(vector, mask); } else { - addRawBlock(block); + addRawBlock(block, mask); } } @@ -73,6 +89,16 @@ private void addRawVector(BytesRefVector vector) { } } + private void addRawVector(BytesRefVector vector, BooleanVector mask) { + BytesRef scratch = new BytesRef(); + for (int i = 0; i < vector.getPositionCount(); i++) { + if (mask.getBoolean(i) == false) { + continue; + } + MinIpAggregator.combine(state, vector.getBytesRef(i, scratch)); + } + } + private void addRawBlock(BytesRefBlock block) { BytesRef scratch = new BytesRef(); for (int p = 0; p < block.getPositionCount(); p++) { @@ -87,6 +113,23 @@ private void addRawBlock(BytesRefBlock block) { } } + private void addRawBlock(BytesRefBlock block, BooleanVector mask) { + BytesRef scratch = new BytesRef(); + for (int p = 0; p < block.getPositionCount(); p++) { + if (mask.getBoolean(p) == false) { + continue; + } + if (block.isNull(p)) { + continue; + } + int start = block.getFirstValueIndex(p); + int end = start + block.getValueCount(p); + for (int i = start; i < end; i++) { + MinIpAggregator.combine(state, block.getBytesRef(i, scratch)); + } + } + } + @Override public void addIntermediateInput(Page page) { assert channels.size() == intermediateBlockCount(); diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/MinLongAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/MinLongAggregatorFunction.java index 805729588158e..b7bab86d6423e 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/MinLongAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/MinLongAggregatorFunction.java @@ -55,13 +55,29 @@ public int intermediateBlockCount() { } @Override - public void addRawInput(Page page) { + public void addRawInput(Page page, BooleanVector mask) { + if (mask.isConstant()) { + if (mask.getBoolean(0) == false) { + // Entire page masked away + return; + } + // No masking + LongBlock block = page.getBlock(channels.get(0)); + LongVector vector = block.asVector(); + if (vector != null) { + addRawVector(vector); + } else { + addRawBlock(block); + } + return; + } + // Some positions masked away, others kept LongBlock block = page.getBlock(channels.get(0)); LongVector vector = block.asVector(); if (vector != null) { - addRawVector(vector); + addRawVector(vector, mask); } else { - addRawBlock(block); + addRawBlock(block, mask); } } @@ -72,6 +88,16 @@ private void addRawVector(LongVector vector) { } } + private void addRawVector(LongVector vector, BooleanVector mask) { + state.seen(true); + for (int i = 0; i < vector.getPositionCount(); i++) { + if (mask.getBoolean(i) == false) { + continue; + } + state.longValue(MinLongAggregator.combine(state.longValue(), vector.getLong(i))); + } + } + private void addRawBlock(LongBlock block) { for (int p = 0; p < block.getPositionCount(); p++) { if (block.isNull(p)) { @@ -86,6 +112,23 @@ private void addRawBlock(LongBlock block) { } } + private void addRawBlock(LongBlock block, BooleanVector mask) { + for (int p = 0; p < block.getPositionCount(); p++) { + if (mask.getBoolean(p) == false) { + continue; + } + if (block.isNull(p)) { + continue; + } + state.seen(true); + int start = block.getFirstValueIndex(p); + int end = start + block.getValueCount(p); + for (int i = start; i < end; i++) { + state.longValue(MinLongAggregator.combine(state.longValue(), block.getLong(i))); + } + } + } + @Override public void addIntermediateInput(Page page) { assert channels.size() == intermediateBlockCount(); diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/PercentileDoubleAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/PercentileDoubleAggregatorFunction.java index cd7a5b5974442..5a00e71baecd3 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/PercentileDoubleAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/PercentileDoubleAggregatorFunction.java @@ -11,6 +11,7 @@ import java.util.List; import org.apache.lucene.util.BytesRef; import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.BooleanVector; import org.elasticsearch.compute.data.BytesRefBlock; import org.elasticsearch.compute.data.BytesRefVector; import org.elasticsearch.compute.data.DoubleBlock; @@ -58,13 +59,29 @@ public int intermediateBlockCount() { } @Override - public void addRawInput(Page page) { + public void addRawInput(Page page, BooleanVector mask) { + if (mask.isConstant()) { + if (mask.getBoolean(0) == false) { + // Entire page masked away + return; + } + // No masking + DoubleBlock block = page.getBlock(channels.get(0)); + DoubleVector vector = block.asVector(); + if (vector != null) { + addRawVector(vector); + } else { + addRawBlock(block); + } + return; + } + // Some positions masked away, others kept DoubleBlock block = page.getBlock(channels.get(0)); DoubleVector vector = block.asVector(); if (vector != null) { - addRawVector(vector); + addRawVector(vector, mask); } else { - addRawBlock(block); + addRawBlock(block, mask); } } @@ -74,6 +91,15 @@ private void addRawVector(DoubleVector vector) { } } + private void addRawVector(DoubleVector vector, BooleanVector mask) { + for (int i = 0; i < vector.getPositionCount(); i++) { + if (mask.getBoolean(i) == false) { + continue; + } + PercentileDoubleAggregator.combine(state, vector.getDouble(i)); + } + } + private void addRawBlock(DoubleBlock block) { for (int p = 0; p < block.getPositionCount(); p++) { if (block.isNull(p)) { @@ -87,6 +113,22 @@ private void addRawBlock(DoubleBlock block) { } } + private void addRawBlock(DoubleBlock block, BooleanVector mask) { + for (int p = 0; p < block.getPositionCount(); p++) { + if (mask.getBoolean(p) == false) { + continue; + } + if (block.isNull(p)) { + continue; + } + int start = block.getFirstValueIndex(p); + int end = start + block.getValueCount(p); + for (int i = start; i < end; i++) { + PercentileDoubleAggregator.combine(state, block.getDouble(i)); + } + } + } + @Override public void addIntermediateInput(Page page) { assert channels.size() == intermediateBlockCount(); diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/PercentileFloatAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/PercentileFloatAggregatorFunction.java index 8f0ffd81e64b6..f3ce29a57d57a 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/PercentileFloatAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/PercentileFloatAggregatorFunction.java @@ -11,6 +11,7 @@ import java.util.List; import org.apache.lucene.util.BytesRef; import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.BooleanVector; import org.elasticsearch.compute.data.BytesRefBlock; import org.elasticsearch.compute.data.BytesRefVector; import org.elasticsearch.compute.data.ElementType; @@ -58,13 +59,29 @@ public int intermediateBlockCount() { } @Override - public void addRawInput(Page page) { + public void addRawInput(Page page, BooleanVector mask) { + if (mask.isConstant()) { + if (mask.getBoolean(0) == false) { + // Entire page masked away + return; + } + // No masking + FloatBlock block = page.getBlock(channels.get(0)); + FloatVector vector = block.asVector(); + if (vector != null) { + addRawVector(vector); + } else { + addRawBlock(block); + } + return; + } + // Some positions masked away, others kept FloatBlock block = page.getBlock(channels.get(0)); FloatVector vector = block.asVector(); if (vector != null) { - addRawVector(vector); + addRawVector(vector, mask); } else { - addRawBlock(block); + addRawBlock(block, mask); } } @@ -74,6 +91,15 @@ private void addRawVector(FloatVector vector) { } } + private void addRawVector(FloatVector vector, BooleanVector mask) { + for (int i = 0; i < vector.getPositionCount(); i++) { + if (mask.getBoolean(i) == false) { + continue; + } + PercentileFloatAggregator.combine(state, vector.getFloat(i)); + } + } + private void addRawBlock(FloatBlock block) { for (int p = 0; p < block.getPositionCount(); p++) { if (block.isNull(p)) { @@ -87,6 +113,22 @@ private void addRawBlock(FloatBlock block) { } } + private void addRawBlock(FloatBlock block, BooleanVector mask) { + for (int p = 0; p < block.getPositionCount(); p++) { + if (mask.getBoolean(p) == false) { + continue; + } + if (block.isNull(p)) { + continue; + } + int start = block.getFirstValueIndex(p); + int end = start + block.getValueCount(p); + for (int i = start; i < end; i++) { + PercentileFloatAggregator.combine(state, block.getFloat(i)); + } + } + } + @Override public void addIntermediateInput(Page page) { assert channels.size() == intermediateBlockCount(); diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/PercentileIntAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/PercentileIntAggregatorFunction.java index b9b1c2e90b768..8c4985e83012c 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/PercentileIntAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/PercentileIntAggregatorFunction.java @@ -11,6 +11,7 @@ import java.util.List; import org.apache.lucene.util.BytesRef; import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.BooleanVector; import org.elasticsearch.compute.data.BytesRefBlock; import org.elasticsearch.compute.data.BytesRefVector; import org.elasticsearch.compute.data.ElementType; @@ -58,13 +59,29 @@ public int intermediateBlockCount() { } @Override - public void addRawInput(Page page) { + public void addRawInput(Page page, BooleanVector mask) { + if (mask.isConstant()) { + if (mask.getBoolean(0) == false) { + // Entire page masked away + return; + } + // No masking + IntBlock block = page.getBlock(channels.get(0)); + IntVector vector = block.asVector(); + if (vector != null) { + addRawVector(vector); + } else { + addRawBlock(block); + } + return; + } + // Some positions masked away, others kept IntBlock block = page.getBlock(channels.get(0)); IntVector vector = block.asVector(); if (vector != null) { - addRawVector(vector); + addRawVector(vector, mask); } else { - addRawBlock(block); + addRawBlock(block, mask); } } @@ -74,6 +91,15 @@ private void addRawVector(IntVector vector) { } } + private void addRawVector(IntVector vector, BooleanVector mask) { + for (int i = 0; i < vector.getPositionCount(); i++) { + if (mask.getBoolean(i) == false) { + continue; + } + PercentileIntAggregator.combine(state, vector.getInt(i)); + } + } + private void addRawBlock(IntBlock block) { for (int p = 0; p < block.getPositionCount(); p++) { if (block.isNull(p)) { @@ -87,6 +113,22 @@ private void addRawBlock(IntBlock block) { } } + private void addRawBlock(IntBlock block, BooleanVector mask) { + for (int p = 0; p < block.getPositionCount(); p++) { + if (mask.getBoolean(p) == false) { + continue; + } + if (block.isNull(p)) { + continue; + } + int start = block.getFirstValueIndex(p); + int end = start + block.getValueCount(p); + for (int i = start; i < end; i++) { + PercentileIntAggregator.combine(state, block.getInt(i)); + } + } + } + @Override public void addIntermediateInput(Page page) { assert channels.size() == intermediateBlockCount(); diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/PercentileLongAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/PercentileLongAggregatorFunction.java index cc785ce55bb55..09093ddb3f42b 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/PercentileLongAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/PercentileLongAggregatorFunction.java @@ -11,6 +11,7 @@ import java.util.List; import org.apache.lucene.util.BytesRef; import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.BooleanVector; import org.elasticsearch.compute.data.BytesRefBlock; import org.elasticsearch.compute.data.BytesRefVector; import org.elasticsearch.compute.data.ElementType; @@ -58,13 +59,29 @@ public int intermediateBlockCount() { } @Override - public void addRawInput(Page page) { + public void addRawInput(Page page, BooleanVector mask) { + if (mask.isConstant()) { + if (mask.getBoolean(0) == false) { + // Entire page masked away + return; + } + // No masking + LongBlock block = page.getBlock(channels.get(0)); + LongVector vector = block.asVector(); + if (vector != null) { + addRawVector(vector); + } else { + addRawBlock(block); + } + return; + } + // Some positions masked away, others kept LongBlock block = page.getBlock(channels.get(0)); LongVector vector = block.asVector(); if (vector != null) { - addRawVector(vector); + addRawVector(vector, mask); } else { - addRawBlock(block); + addRawBlock(block, mask); } } @@ -74,6 +91,15 @@ private void addRawVector(LongVector vector) { } } + private void addRawVector(LongVector vector, BooleanVector mask) { + for (int i = 0; i < vector.getPositionCount(); i++) { + if (mask.getBoolean(i) == false) { + continue; + } + PercentileLongAggregator.combine(state, vector.getLong(i)); + } + } + private void addRawBlock(LongBlock block) { for (int p = 0; p < block.getPositionCount(); p++) { if (block.isNull(p)) { @@ -87,6 +113,22 @@ private void addRawBlock(LongBlock block) { } } + private void addRawBlock(LongBlock block, BooleanVector mask) { + for (int p = 0; p < block.getPositionCount(); p++) { + if (mask.getBoolean(p) == false) { + continue; + } + if (block.isNull(p)) { + continue; + } + int start = block.getFirstValueIndex(p); + int end = start + block.getValueCount(p); + for (int i = start; i < end; i++) { + PercentileLongAggregator.combine(state, block.getLong(i)); + } + } + } + @Override public void addIntermediateInput(Page page) { assert channels.size() == intermediateBlockCount(); diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/SumDoubleAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/SumDoubleAggregatorFunction.java index 354726f82b8f3..7f0e0b4e15158 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/SumDoubleAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/SumDoubleAggregatorFunction.java @@ -56,13 +56,29 @@ public int intermediateBlockCount() { } @Override - public void addRawInput(Page page) { + public void addRawInput(Page page, BooleanVector mask) { + if (mask.isConstant()) { + if (mask.getBoolean(0) == false) { + // Entire page masked away + return; + } + // No masking + DoubleBlock block = page.getBlock(channels.get(0)); + DoubleVector vector = block.asVector(); + if (vector != null) { + addRawVector(vector); + } else { + addRawBlock(block); + } + return; + } + // Some positions masked away, others kept DoubleBlock block = page.getBlock(channels.get(0)); DoubleVector vector = block.asVector(); if (vector != null) { - addRawVector(vector); + addRawVector(vector, mask); } else { - addRawBlock(block); + addRawBlock(block, mask); } } @@ -73,6 +89,16 @@ private void addRawVector(DoubleVector vector) { } } + private void addRawVector(DoubleVector vector, BooleanVector mask) { + state.seen(true); + for (int i = 0; i < vector.getPositionCount(); i++) { + if (mask.getBoolean(i) == false) { + continue; + } + SumDoubleAggregator.combine(state, vector.getDouble(i)); + } + } + private void addRawBlock(DoubleBlock block) { for (int p = 0; p < block.getPositionCount(); p++) { if (block.isNull(p)) { @@ -87,6 +113,23 @@ private void addRawBlock(DoubleBlock block) { } } + private void addRawBlock(DoubleBlock block, BooleanVector mask) { + for (int p = 0; p < block.getPositionCount(); p++) { + if (mask.getBoolean(p) == false) { + continue; + } + if (block.isNull(p)) { + continue; + } + state.seen(true); + int start = block.getFirstValueIndex(p); + int end = start + block.getValueCount(p); + for (int i = start; i < end; i++) { + SumDoubleAggregator.combine(state, block.getDouble(i)); + } + } + } + @Override public void addIntermediateInput(Page page) { assert channels.size() == intermediateBlockCount(); diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/SumFloatAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/SumFloatAggregatorFunction.java index 3dedc327294d5..d916b832d77ff 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/SumFloatAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/SumFloatAggregatorFunction.java @@ -58,13 +58,29 @@ public int intermediateBlockCount() { } @Override - public void addRawInput(Page page) { + public void addRawInput(Page page, BooleanVector mask) { + if (mask.isConstant()) { + if (mask.getBoolean(0) == false) { + // Entire page masked away + return; + } + // No masking + FloatBlock block = page.getBlock(channels.get(0)); + FloatVector vector = block.asVector(); + if (vector != null) { + addRawVector(vector); + } else { + addRawBlock(block); + } + return; + } + // Some positions masked away, others kept FloatBlock block = page.getBlock(channels.get(0)); FloatVector vector = block.asVector(); if (vector != null) { - addRawVector(vector); + addRawVector(vector, mask); } else { - addRawBlock(block); + addRawBlock(block, mask); } } @@ -75,6 +91,16 @@ private void addRawVector(FloatVector vector) { } } + private void addRawVector(FloatVector vector, BooleanVector mask) { + state.seen(true); + for (int i = 0; i < vector.getPositionCount(); i++) { + if (mask.getBoolean(i) == false) { + continue; + } + SumFloatAggregator.combine(state, vector.getFloat(i)); + } + } + private void addRawBlock(FloatBlock block) { for (int p = 0; p < block.getPositionCount(); p++) { if (block.isNull(p)) { @@ -89,6 +115,23 @@ private void addRawBlock(FloatBlock block) { } } + private void addRawBlock(FloatBlock block, BooleanVector mask) { + for (int p = 0; p < block.getPositionCount(); p++) { + if (mask.getBoolean(p) == false) { + continue; + } + if (block.isNull(p)) { + continue; + } + state.seen(true); + int start = block.getFirstValueIndex(p); + int end = start + block.getValueCount(p); + for (int i = start; i < end; i++) { + SumFloatAggregator.combine(state, block.getFloat(i)); + } + } + } + @Override public void addIntermediateInput(Page page) { assert channels.size() == intermediateBlockCount(); diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/SumIntAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/SumIntAggregatorFunction.java index e210429991aa6..5cd1abc35d28f 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/SumIntAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/SumIntAggregatorFunction.java @@ -57,13 +57,29 @@ public int intermediateBlockCount() { } @Override - public void addRawInput(Page page) { + public void addRawInput(Page page, BooleanVector mask) { + if (mask.isConstant()) { + if (mask.getBoolean(0) == false) { + // Entire page masked away + return; + } + // No masking + IntBlock block = page.getBlock(channels.get(0)); + IntVector vector = block.asVector(); + if (vector != null) { + addRawVector(vector); + } else { + addRawBlock(block); + } + return; + } + // Some positions masked away, others kept IntBlock block = page.getBlock(channels.get(0)); IntVector vector = block.asVector(); if (vector != null) { - addRawVector(vector); + addRawVector(vector, mask); } else { - addRawBlock(block); + addRawBlock(block, mask); } } @@ -74,6 +90,16 @@ private void addRawVector(IntVector vector) { } } + private void addRawVector(IntVector vector, BooleanVector mask) { + state.seen(true); + for (int i = 0; i < vector.getPositionCount(); i++) { + if (mask.getBoolean(i) == false) { + continue; + } + state.longValue(SumIntAggregator.combine(state.longValue(), vector.getInt(i))); + } + } + private void addRawBlock(IntBlock block) { for (int p = 0; p < block.getPositionCount(); p++) { if (block.isNull(p)) { @@ -88,6 +114,23 @@ private void addRawBlock(IntBlock block) { } } + private void addRawBlock(IntBlock block, BooleanVector mask) { + for (int p = 0; p < block.getPositionCount(); p++) { + if (mask.getBoolean(p) == false) { + continue; + } + if (block.isNull(p)) { + continue; + } + state.seen(true); + int start = block.getFirstValueIndex(p); + int end = start + block.getValueCount(p); + for (int i = start; i < end; i++) { + state.longValue(SumIntAggregator.combine(state.longValue(), block.getInt(i))); + } + } + } + @Override public void addIntermediateInput(Page page) { assert channels.size() == intermediateBlockCount(); diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/SumLongAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/SumLongAggregatorFunction.java index 38d1b3de78265..e7781f82b1021 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/SumLongAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/SumLongAggregatorFunction.java @@ -55,13 +55,29 @@ public int intermediateBlockCount() { } @Override - public void addRawInput(Page page) { + public void addRawInput(Page page, BooleanVector mask) { + if (mask.isConstant()) { + if (mask.getBoolean(0) == false) { + // Entire page masked away + return; + } + // No masking + LongBlock block = page.getBlock(channels.get(0)); + LongVector vector = block.asVector(); + if (vector != null) { + addRawVector(vector); + } else { + addRawBlock(block); + } + return; + } + // Some positions masked away, others kept LongBlock block = page.getBlock(channels.get(0)); LongVector vector = block.asVector(); if (vector != null) { - addRawVector(vector); + addRawVector(vector, mask); } else { - addRawBlock(block); + addRawBlock(block, mask); } } @@ -72,6 +88,16 @@ private void addRawVector(LongVector vector) { } } + private void addRawVector(LongVector vector, BooleanVector mask) { + state.seen(true); + for (int i = 0; i < vector.getPositionCount(); i++) { + if (mask.getBoolean(i) == false) { + continue; + } + state.longValue(SumLongAggregator.combine(state.longValue(), vector.getLong(i))); + } + } + private void addRawBlock(LongBlock block) { for (int p = 0; p < block.getPositionCount(); p++) { if (block.isNull(p)) { @@ -86,6 +112,23 @@ private void addRawBlock(LongBlock block) { } } + private void addRawBlock(LongBlock block, BooleanVector mask) { + for (int p = 0; p < block.getPositionCount(); p++) { + if (mask.getBoolean(p) == false) { + continue; + } + if (block.isNull(p)) { + continue; + } + state.seen(true); + int start = block.getFirstValueIndex(p); + int end = start + block.getValueCount(p); + for (int i = start; i < end; i++) { + state.longValue(SumLongAggregator.combine(state.longValue(), block.getLong(i))); + } + } + } + @Override public void addIntermediateInput(Page page) { assert channels.size() == intermediateBlockCount(); diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopBooleanAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopBooleanAggregatorFunction.java index 617ebfd004808..0580dc297a362 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopBooleanAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopBooleanAggregatorFunction.java @@ -58,13 +58,29 @@ public int intermediateBlockCount() { } @Override - public void addRawInput(Page page) { + public void addRawInput(Page page, BooleanVector mask) { + if (mask.isConstant()) { + if (mask.getBoolean(0) == false) { + // Entire page masked away + return; + } + // No masking + BooleanBlock block = page.getBlock(channels.get(0)); + BooleanVector vector = block.asVector(); + if (vector != null) { + addRawVector(vector); + } else { + addRawBlock(block); + } + return; + } + // Some positions masked away, others kept BooleanBlock block = page.getBlock(channels.get(0)); BooleanVector vector = block.asVector(); if (vector != null) { - addRawVector(vector); + addRawVector(vector, mask); } else { - addRawBlock(block); + addRawBlock(block, mask); } } @@ -74,6 +90,15 @@ private void addRawVector(BooleanVector vector) { } } + private void addRawVector(BooleanVector vector, BooleanVector mask) { + for (int i = 0; i < vector.getPositionCount(); i++) { + if (mask.getBoolean(i) == false) { + continue; + } + TopBooleanAggregator.combine(state, vector.getBoolean(i)); + } + } + private void addRawBlock(BooleanBlock block) { for (int p = 0; p < block.getPositionCount(); p++) { if (block.isNull(p)) { @@ -87,6 +112,22 @@ private void addRawBlock(BooleanBlock block) { } } + private void addRawBlock(BooleanBlock block, BooleanVector mask) { + for (int p = 0; p < block.getPositionCount(); p++) { + if (mask.getBoolean(p) == false) { + continue; + } + if (block.isNull(p)) { + continue; + } + int start = block.getFirstValueIndex(p); + int end = start + block.getValueCount(p); + for (int i = start; i < end; i++) { + TopBooleanAggregator.combine(state, block.getBoolean(i)); + } + } + } + @Override public void addIntermediateInput(Page page) { assert channels.size() == intermediateBlockCount(); diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleAggregatorFunction.java index 8549da42c0d85..899af1a58851b 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopDoubleAggregatorFunction.java @@ -10,6 +10,7 @@ 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; @@ -58,13 +59,29 @@ public int intermediateBlockCount() { } @Override - public void addRawInput(Page page) { + public void addRawInput(Page page, BooleanVector mask) { + if (mask.isConstant()) { + if (mask.getBoolean(0) == false) { + // Entire page masked away + return; + } + // No masking + DoubleBlock block = page.getBlock(channels.get(0)); + DoubleVector vector = block.asVector(); + if (vector != null) { + addRawVector(vector); + } else { + addRawBlock(block); + } + return; + } + // Some positions masked away, others kept DoubleBlock block = page.getBlock(channels.get(0)); DoubleVector vector = block.asVector(); if (vector != null) { - addRawVector(vector); + addRawVector(vector, mask); } else { - addRawBlock(block); + addRawBlock(block, mask); } } @@ -74,6 +91,15 @@ private void addRawVector(DoubleVector vector) { } } + private void addRawVector(DoubleVector vector, BooleanVector mask) { + for (int i = 0; i < vector.getPositionCount(); i++) { + if (mask.getBoolean(i) == false) { + continue; + } + TopDoubleAggregator.combine(state, vector.getDouble(i)); + } + } + private void addRawBlock(DoubleBlock block) { for (int p = 0; p < block.getPositionCount(); p++) { if (block.isNull(p)) { @@ -87,6 +113,22 @@ private void addRawBlock(DoubleBlock block) { } } + private void addRawBlock(DoubleBlock block, BooleanVector mask) { + for (int p = 0; p < block.getPositionCount(); p++) { + if (mask.getBoolean(p) == false) { + continue; + } + if (block.isNull(p)) { + continue; + } + int start = block.getFirstValueIndex(p); + int end = start + block.getValueCount(p); + for (int i = start; i < end; i++) { + TopDoubleAggregator.combine(state, block.getDouble(i)); + } + } + } + @Override public void addIntermediateInput(Page page) { assert channels.size() == intermediateBlockCount(); diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatAggregatorFunction.java index 40ac1432caee8..168e7685c5273 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopFloatAggregatorFunction.java @@ -10,6 +10,7 @@ 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; @@ -58,13 +59,29 @@ public int intermediateBlockCount() { } @Override - public void addRawInput(Page page) { + public void addRawInput(Page page, BooleanVector mask) { + if (mask.isConstant()) { + if (mask.getBoolean(0) == false) { + // Entire page masked away + return; + } + // No masking + FloatBlock block = page.getBlock(channels.get(0)); + FloatVector vector = block.asVector(); + if (vector != null) { + addRawVector(vector); + } else { + addRawBlock(block); + } + return; + } + // Some positions masked away, others kept FloatBlock block = page.getBlock(channels.get(0)); FloatVector vector = block.asVector(); if (vector != null) { - addRawVector(vector); + addRawVector(vector, mask); } else { - addRawBlock(block); + addRawBlock(block, mask); } } @@ -74,6 +91,15 @@ private void addRawVector(FloatVector vector) { } } + private void addRawVector(FloatVector vector, BooleanVector mask) { + for (int i = 0; i < vector.getPositionCount(); i++) { + if (mask.getBoolean(i) == false) { + continue; + } + TopFloatAggregator.combine(state, vector.getFloat(i)); + } + } + private void addRawBlock(FloatBlock block) { for (int p = 0; p < block.getPositionCount(); p++) { if (block.isNull(p)) { @@ -87,6 +113,22 @@ private void addRawBlock(FloatBlock block) { } } + private void addRawBlock(FloatBlock block, BooleanVector mask) { + for (int p = 0; p < block.getPositionCount(); p++) { + if (mask.getBoolean(p) == false) { + continue; + } + if (block.isNull(p)) { + continue; + } + int start = block.getFirstValueIndex(p); + int end = start + block.getValueCount(p); + for (int i = start; i < end; i++) { + TopFloatAggregator.combine(state, block.getFloat(i)); + } + } + } + @Override public void addIntermediateInput(Page page) { assert channels.size() == intermediateBlockCount(); diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntAggregatorFunction.java index f6e858b69a639..80964decf572d 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIntAggregatorFunction.java @@ -10,6 +10,7 @@ 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; @@ -58,13 +59,29 @@ public int intermediateBlockCount() { } @Override - public void addRawInput(Page page) { + public void addRawInput(Page page, BooleanVector mask) { + if (mask.isConstant()) { + if (mask.getBoolean(0) == false) { + // Entire page masked away + return; + } + // No masking + IntBlock block = page.getBlock(channels.get(0)); + IntVector vector = block.asVector(); + if (vector != null) { + addRawVector(vector); + } else { + addRawBlock(block); + } + return; + } + // Some positions masked away, others kept IntBlock block = page.getBlock(channels.get(0)); IntVector vector = block.asVector(); if (vector != null) { - addRawVector(vector); + addRawVector(vector, mask); } else { - addRawBlock(block); + addRawBlock(block, mask); } } @@ -74,6 +91,15 @@ private void addRawVector(IntVector vector) { } } + private void addRawVector(IntVector vector, BooleanVector mask) { + for (int i = 0; i < vector.getPositionCount(); i++) { + if (mask.getBoolean(i) == false) { + continue; + } + TopIntAggregator.combine(state, vector.getInt(i)); + } + } + private void addRawBlock(IntBlock block) { for (int p = 0; p < block.getPositionCount(); p++) { if (block.isNull(p)) { @@ -87,6 +113,22 @@ private void addRawBlock(IntBlock block) { } } + private void addRawBlock(IntBlock block, BooleanVector mask) { + for (int p = 0; p < block.getPositionCount(); p++) { + if (mask.getBoolean(p) == false) { + continue; + } + if (block.isNull(p)) { + continue; + } + int start = block.getFirstValueIndex(p); + int end = start + block.getValueCount(p); + for (int i = start; i < end; i++) { + TopIntAggregator.combine(state, block.getInt(i)); + } + } + } + @Override public void addIntermediateInput(Page page) { assert channels.size() == intermediateBlockCount(); diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIpAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIpAggregatorFunction.java index 43f4d78d59cd9..90d8d7c124244 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIpAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopIpAggregatorFunction.java @@ -11,6 +11,7 @@ import java.util.List; import org.apache.lucene.util.BytesRef; import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.BooleanVector; import org.elasticsearch.compute.data.BytesRefBlock; import org.elasticsearch.compute.data.BytesRefVector; import org.elasticsearch.compute.data.ElementType; @@ -59,13 +60,29 @@ public int intermediateBlockCount() { } @Override - public void addRawInput(Page page) { + public void addRawInput(Page page, BooleanVector mask) { + if (mask.isConstant()) { + if (mask.getBoolean(0) == false) { + // Entire page masked away + return; + } + // No masking + BytesRefBlock block = page.getBlock(channels.get(0)); + BytesRefVector vector = block.asVector(); + if (vector != null) { + addRawVector(vector); + } else { + addRawBlock(block); + } + return; + } + // Some positions masked away, others kept BytesRefBlock block = page.getBlock(channels.get(0)); BytesRefVector vector = block.asVector(); if (vector != null) { - addRawVector(vector); + addRawVector(vector, mask); } else { - addRawBlock(block); + addRawBlock(block, mask); } } @@ -76,6 +93,16 @@ private void addRawVector(BytesRefVector vector) { } } + private void addRawVector(BytesRefVector vector, BooleanVector mask) { + BytesRef scratch = new BytesRef(); + for (int i = 0; i < vector.getPositionCount(); i++) { + if (mask.getBoolean(i) == false) { + continue; + } + TopIpAggregator.combine(state, vector.getBytesRef(i, scratch)); + } + } + private void addRawBlock(BytesRefBlock block) { BytesRef scratch = new BytesRef(); for (int p = 0; p < block.getPositionCount(); p++) { @@ -90,6 +117,23 @@ private void addRawBlock(BytesRefBlock block) { } } + private void addRawBlock(BytesRefBlock block, BooleanVector mask) { + BytesRef scratch = new BytesRef(); + for (int p = 0; p < block.getPositionCount(); p++) { + if (mask.getBoolean(p) == false) { + continue; + } + if (block.isNull(p)) { + continue; + } + int start = block.getFirstValueIndex(p); + int end = start + block.getValueCount(p); + for (int i = start; i < end; i++) { + TopIpAggregator.combine(state, block.getBytesRef(i, scratch)); + } + } + } + @Override public void addIntermediateInput(Page page) { assert channels.size() == intermediateBlockCount(); diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongAggregatorFunction.java index c355e401478d8..18eef5a29b895 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/TopLongAggregatorFunction.java @@ -10,6 +10,7 @@ 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; @@ -58,13 +59,29 @@ public int intermediateBlockCount() { } @Override - public void addRawInput(Page page) { + public void addRawInput(Page page, BooleanVector mask) { + if (mask.isConstant()) { + if (mask.getBoolean(0) == false) { + // Entire page masked away + return; + } + // No masking + LongBlock block = page.getBlock(channels.get(0)); + LongVector vector = block.asVector(); + if (vector != null) { + addRawVector(vector); + } else { + addRawBlock(block); + } + return; + } + // Some positions masked away, others kept LongBlock block = page.getBlock(channels.get(0)); LongVector vector = block.asVector(); if (vector != null) { - addRawVector(vector); + addRawVector(vector, mask); } else { - addRawBlock(block); + addRawBlock(block, mask); } } @@ -74,6 +91,15 @@ private void addRawVector(LongVector vector) { } } + private void addRawVector(LongVector vector, BooleanVector mask) { + for (int i = 0; i < vector.getPositionCount(); i++) { + if (mask.getBoolean(i) == false) { + continue; + } + TopLongAggregator.combine(state, vector.getLong(i)); + } + } + private void addRawBlock(LongBlock block) { for (int p = 0; p < block.getPositionCount(); p++) { if (block.isNull(p)) { @@ -87,6 +113,22 @@ private void addRawBlock(LongBlock block) { } } + private void addRawBlock(LongBlock block, BooleanVector mask) { + for (int p = 0; p < block.getPositionCount(); p++) { + if (mask.getBoolean(p) == false) { + continue; + } + if (block.isNull(p)) { + continue; + } + int start = block.getFirstValueIndex(p); + int end = start + block.getValueCount(p); + for (int i = start; i < end; i++) { + TopLongAggregator.combine(state, block.getLong(i)); + } + } + } + @Override public void addIntermediateInput(Page page) { assert channels.size() == intermediateBlockCount(); diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/ValuesBooleanAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/ValuesBooleanAggregatorFunction.java index 3e9bc91e0039a..d71d9a7b45bdb 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/ValuesBooleanAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/ValuesBooleanAggregatorFunction.java @@ -52,13 +52,29 @@ public int intermediateBlockCount() { } @Override - public void addRawInput(Page page) { + public void addRawInput(Page page, BooleanVector mask) { + if (mask.isConstant()) { + if (mask.getBoolean(0) == false) { + // Entire page masked away + return; + } + // No masking + BooleanBlock block = page.getBlock(channels.get(0)); + BooleanVector vector = block.asVector(); + if (vector != null) { + addRawVector(vector); + } else { + addRawBlock(block); + } + return; + } + // Some positions masked away, others kept BooleanBlock block = page.getBlock(channels.get(0)); BooleanVector vector = block.asVector(); if (vector != null) { - addRawVector(vector); + addRawVector(vector, mask); } else { - addRawBlock(block); + addRawBlock(block, mask); } } @@ -68,6 +84,15 @@ private void addRawVector(BooleanVector vector) { } } + private void addRawVector(BooleanVector vector, BooleanVector mask) { + for (int i = 0; i < vector.getPositionCount(); i++) { + if (mask.getBoolean(i) == false) { + continue; + } + ValuesBooleanAggregator.combine(state, vector.getBoolean(i)); + } + } + private void addRawBlock(BooleanBlock block) { for (int p = 0; p < block.getPositionCount(); p++) { if (block.isNull(p)) { @@ -81,6 +106,22 @@ private void addRawBlock(BooleanBlock block) { } } + private void addRawBlock(BooleanBlock block, BooleanVector mask) { + for (int p = 0; p < block.getPositionCount(); p++) { + if (mask.getBoolean(p) == false) { + continue; + } + if (block.isNull(p)) { + continue; + } + int start = block.getFirstValueIndex(p); + int end = start + block.getValueCount(p); + for (int i = start; i < end; i++) { + ValuesBooleanAggregator.combine(state, block.getBoolean(i)); + } + } + } + @Override public void addIntermediateInput(Page page) { assert channels.size() == intermediateBlockCount(); diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/ValuesBytesRefAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/ValuesBytesRefAggregatorFunction.java index 24b88f59e38f4..56e79b64e3b86 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/ValuesBytesRefAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/ValuesBytesRefAggregatorFunction.java @@ -11,6 +11,7 @@ import java.util.List; import org.apache.lucene.util.BytesRef; import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.BooleanVector; import org.elasticsearch.compute.data.BytesRefBlock; import org.elasticsearch.compute.data.BytesRefVector; import org.elasticsearch.compute.data.ElementType; @@ -53,13 +54,29 @@ public int intermediateBlockCount() { } @Override - public void addRawInput(Page page) { + public void addRawInput(Page page, BooleanVector mask) { + if (mask.isConstant()) { + if (mask.getBoolean(0) == false) { + // Entire page masked away + return; + } + // No masking + BytesRefBlock block = page.getBlock(channels.get(0)); + BytesRefVector vector = block.asVector(); + if (vector != null) { + addRawVector(vector); + } else { + addRawBlock(block); + } + return; + } + // Some positions masked away, others kept BytesRefBlock block = page.getBlock(channels.get(0)); BytesRefVector vector = block.asVector(); if (vector != null) { - addRawVector(vector); + addRawVector(vector, mask); } else { - addRawBlock(block); + addRawBlock(block, mask); } } @@ -70,6 +87,16 @@ private void addRawVector(BytesRefVector vector) { } } + private void addRawVector(BytesRefVector vector, BooleanVector mask) { + BytesRef scratch = new BytesRef(); + for (int i = 0; i < vector.getPositionCount(); i++) { + if (mask.getBoolean(i) == false) { + continue; + } + ValuesBytesRefAggregator.combine(state, vector.getBytesRef(i, scratch)); + } + } + private void addRawBlock(BytesRefBlock block) { BytesRef scratch = new BytesRef(); for (int p = 0; p < block.getPositionCount(); p++) { @@ -84,6 +111,23 @@ private void addRawBlock(BytesRefBlock block) { } } + private void addRawBlock(BytesRefBlock block, BooleanVector mask) { + BytesRef scratch = new BytesRef(); + for (int p = 0; p < block.getPositionCount(); p++) { + if (mask.getBoolean(p) == false) { + continue; + } + if (block.isNull(p)) { + continue; + } + int start = block.getFirstValueIndex(p); + int end = start + block.getValueCount(p); + for (int i = start; i < end; i++) { + ValuesBytesRefAggregator.combine(state, block.getBytesRef(i, scratch)); + } + } + } + @Override public void addIntermediateInput(Page page) { assert channels.size() == intermediateBlockCount(); diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/ValuesDoubleAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/ValuesDoubleAggregatorFunction.java index a6295038dbd7a..3ec31b0fd5a4d 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/ValuesDoubleAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/ValuesDoubleAggregatorFunction.java @@ -10,6 +10,7 @@ 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; @@ -52,13 +53,29 @@ public int intermediateBlockCount() { } @Override - public void addRawInput(Page page) { + public void addRawInput(Page page, BooleanVector mask) { + if (mask.isConstant()) { + if (mask.getBoolean(0) == false) { + // Entire page masked away + return; + } + // No masking + DoubleBlock block = page.getBlock(channels.get(0)); + DoubleVector vector = block.asVector(); + if (vector != null) { + addRawVector(vector); + } else { + addRawBlock(block); + } + return; + } + // Some positions masked away, others kept DoubleBlock block = page.getBlock(channels.get(0)); DoubleVector vector = block.asVector(); if (vector != null) { - addRawVector(vector); + addRawVector(vector, mask); } else { - addRawBlock(block); + addRawBlock(block, mask); } } @@ -68,6 +85,15 @@ private void addRawVector(DoubleVector vector) { } } + private void addRawVector(DoubleVector vector, BooleanVector mask) { + for (int i = 0; i < vector.getPositionCount(); i++) { + if (mask.getBoolean(i) == false) { + continue; + } + ValuesDoubleAggregator.combine(state, vector.getDouble(i)); + } + } + private void addRawBlock(DoubleBlock block) { for (int p = 0; p < block.getPositionCount(); p++) { if (block.isNull(p)) { @@ -81,6 +107,22 @@ private void addRawBlock(DoubleBlock block) { } } + private void addRawBlock(DoubleBlock block, BooleanVector mask) { + for (int p = 0; p < block.getPositionCount(); p++) { + if (mask.getBoolean(p) == false) { + continue; + } + if (block.isNull(p)) { + continue; + } + int start = block.getFirstValueIndex(p); + int end = start + block.getValueCount(p); + for (int i = start; i < end; i++) { + ValuesDoubleAggregator.combine(state, block.getDouble(i)); + } + } + } + @Override public void addIntermediateInput(Page page) { assert channels.size() == intermediateBlockCount(); diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/ValuesFloatAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/ValuesFloatAggregatorFunction.java index c7385e87bfbf2..00ab8db1c4ac6 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/ValuesFloatAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/ValuesFloatAggregatorFunction.java @@ -10,6 +10,7 @@ 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; @@ -52,13 +53,29 @@ public int intermediateBlockCount() { } @Override - public void addRawInput(Page page) { + public void addRawInput(Page page, BooleanVector mask) { + if (mask.isConstant()) { + if (mask.getBoolean(0) == false) { + // Entire page masked away + return; + } + // No masking + FloatBlock block = page.getBlock(channels.get(0)); + FloatVector vector = block.asVector(); + if (vector != null) { + addRawVector(vector); + } else { + addRawBlock(block); + } + return; + } + // Some positions masked away, others kept FloatBlock block = page.getBlock(channels.get(0)); FloatVector vector = block.asVector(); if (vector != null) { - addRawVector(vector); + addRawVector(vector, mask); } else { - addRawBlock(block); + addRawBlock(block, mask); } } @@ -68,6 +85,15 @@ private void addRawVector(FloatVector vector) { } } + private void addRawVector(FloatVector vector, BooleanVector mask) { + for (int i = 0; i < vector.getPositionCount(); i++) { + if (mask.getBoolean(i) == false) { + continue; + } + ValuesFloatAggregator.combine(state, vector.getFloat(i)); + } + } + private void addRawBlock(FloatBlock block) { for (int p = 0; p < block.getPositionCount(); p++) { if (block.isNull(p)) { @@ -81,6 +107,22 @@ private void addRawBlock(FloatBlock block) { } } + private void addRawBlock(FloatBlock block, BooleanVector mask) { + for (int p = 0; p < block.getPositionCount(); p++) { + if (mask.getBoolean(p) == false) { + continue; + } + if (block.isNull(p)) { + continue; + } + int start = block.getFirstValueIndex(p); + int end = start + block.getValueCount(p); + for (int i = start; i < end; i++) { + ValuesFloatAggregator.combine(state, block.getFloat(i)); + } + } + } + @Override public void addIntermediateInput(Page page) { assert channels.size() == intermediateBlockCount(); diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/ValuesIntAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/ValuesIntAggregatorFunction.java index 19e578936cd14..5a0d7c893e607 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/ValuesIntAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/ValuesIntAggregatorFunction.java @@ -10,6 +10,7 @@ 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; @@ -52,13 +53,29 @@ public int intermediateBlockCount() { } @Override - public void addRawInput(Page page) { + public void addRawInput(Page page, BooleanVector mask) { + if (mask.isConstant()) { + if (mask.getBoolean(0) == false) { + // Entire page masked away + return; + } + // No masking + IntBlock block = page.getBlock(channels.get(0)); + IntVector vector = block.asVector(); + if (vector != null) { + addRawVector(vector); + } else { + addRawBlock(block); + } + return; + } + // Some positions masked away, others kept IntBlock block = page.getBlock(channels.get(0)); IntVector vector = block.asVector(); if (vector != null) { - addRawVector(vector); + addRawVector(vector, mask); } else { - addRawBlock(block); + addRawBlock(block, mask); } } @@ -68,6 +85,15 @@ private void addRawVector(IntVector vector) { } } + private void addRawVector(IntVector vector, BooleanVector mask) { + for (int i = 0; i < vector.getPositionCount(); i++) { + if (mask.getBoolean(i) == false) { + continue; + } + ValuesIntAggregator.combine(state, vector.getInt(i)); + } + } + private void addRawBlock(IntBlock block) { for (int p = 0; p < block.getPositionCount(); p++) { if (block.isNull(p)) { @@ -81,6 +107,22 @@ private void addRawBlock(IntBlock block) { } } + private void addRawBlock(IntBlock block, BooleanVector mask) { + for (int p = 0; p < block.getPositionCount(); p++) { + if (mask.getBoolean(p) == false) { + continue; + } + if (block.isNull(p)) { + continue; + } + int start = block.getFirstValueIndex(p); + int end = start + block.getValueCount(p); + for (int i = start; i < end; i++) { + ValuesIntAggregator.combine(state, block.getInt(i)); + } + } + } + @Override public void addIntermediateInput(Page page) { assert channels.size() == intermediateBlockCount(); diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/ValuesLongAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/ValuesLongAggregatorFunction.java index 420da87076a37..ca9a8347e3a41 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/ValuesLongAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/ValuesLongAggregatorFunction.java @@ -10,6 +10,7 @@ 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; @@ -52,13 +53,29 @@ public int intermediateBlockCount() { } @Override - public void addRawInput(Page page) { + public void addRawInput(Page page, BooleanVector mask) { + if (mask.isConstant()) { + if (mask.getBoolean(0) == false) { + // Entire page masked away + return; + } + // No masking + LongBlock block = page.getBlock(channels.get(0)); + LongVector vector = block.asVector(); + if (vector != null) { + addRawVector(vector); + } else { + addRawBlock(block); + } + return; + } + // Some positions masked away, others kept LongBlock block = page.getBlock(channels.get(0)); LongVector vector = block.asVector(); if (vector != null) { - addRawVector(vector); + addRawVector(vector, mask); } else { - addRawBlock(block); + addRawBlock(block, mask); } } @@ -68,6 +85,15 @@ private void addRawVector(LongVector vector) { } } + private void addRawVector(LongVector vector, BooleanVector mask) { + for (int i = 0; i < vector.getPositionCount(); i++) { + if (mask.getBoolean(i) == false) { + continue; + } + ValuesLongAggregator.combine(state, vector.getLong(i)); + } + } + private void addRawBlock(LongBlock block) { for (int p = 0; p < block.getPositionCount(); p++) { if (block.isNull(p)) { @@ -81,6 +107,22 @@ private void addRawBlock(LongBlock block) { } } + private void addRawBlock(LongBlock block, BooleanVector mask) { + for (int p = 0; p < block.getPositionCount(); p++) { + if (mask.getBoolean(p) == false) { + continue; + } + if (block.isNull(p)) { + continue; + } + int start = block.getFirstValueIndex(p); + int end = start + block.getValueCount(p); + for (int i = start; i < end; i++) { + ValuesLongAggregator.combine(state, block.getLong(i)); + } + } + } + @Override public void addIntermediateInput(Page page) { assert channels.size() == intermediateBlockCount(); diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/spatial/SpatialCentroidCartesianPointDocValuesAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/spatial/SpatialCentroidCartesianPointDocValuesAggregatorFunction.java index eef094ce2ecfa..a427c75c63fff 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/spatial/SpatialCentroidCartesianPointDocValuesAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/spatial/SpatialCentroidCartesianPointDocValuesAggregatorFunction.java @@ -12,6 +12,7 @@ import org.elasticsearch.compute.aggregation.AggregatorFunction; import org.elasticsearch.compute.aggregation.IntermediateStateDesc; 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; @@ -60,13 +61,29 @@ public int intermediateBlockCount() { } @Override - public void addRawInput(Page page) { + public void addRawInput(Page page, BooleanVector mask) { + if (mask.isConstant()) { + if (mask.getBoolean(0) == false) { + // Entire page masked away + return; + } + // No masking + LongBlock block = page.getBlock(channels.get(0)); + LongVector vector = block.asVector(); + if (vector != null) { + addRawVector(vector); + } else { + addRawBlock(block); + } + return; + } + // Some positions masked away, others kept LongBlock block = page.getBlock(channels.get(0)); LongVector vector = block.asVector(); if (vector != null) { - addRawVector(vector); + addRawVector(vector, mask); } else { - addRawBlock(block); + addRawBlock(block, mask); } } @@ -76,6 +93,15 @@ private void addRawVector(LongVector vector) { } } + private void addRawVector(LongVector vector, BooleanVector mask) { + for (int i = 0; i < vector.getPositionCount(); i++) { + if (mask.getBoolean(i) == false) { + continue; + } + SpatialCentroidCartesianPointDocValuesAggregator.combine(state, vector.getLong(i)); + } + } + private void addRawBlock(LongBlock block) { for (int p = 0; p < block.getPositionCount(); p++) { if (block.isNull(p)) { @@ -89,6 +115,22 @@ private void addRawBlock(LongBlock block) { } } + private void addRawBlock(LongBlock block, BooleanVector mask) { + for (int p = 0; p < block.getPositionCount(); p++) { + if (mask.getBoolean(p) == false) { + continue; + } + if (block.isNull(p)) { + continue; + } + int start = block.getFirstValueIndex(p); + int end = start + block.getValueCount(p); + for (int i = start; i < end; i++) { + SpatialCentroidCartesianPointDocValuesAggregator.combine(state, block.getLong(i)); + } + } + } + @Override public void addIntermediateInput(Page page) { assert channels.size() == intermediateBlockCount(); diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/spatial/SpatialCentroidCartesianPointSourceValuesAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/spatial/SpatialCentroidCartesianPointSourceValuesAggregatorFunction.java index bdc7c58a6c963..c2086f2ab3d98 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/spatial/SpatialCentroidCartesianPointSourceValuesAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/spatial/SpatialCentroidCartesianPointSourceValuesAggregatorFunction.java @@ -13,6 +13,7 @@ import org.elasticsearch.compute.aggregation.AggregatorFunction; import org.elasticsearch.compute.aggregation.IntermediateStateDesc; import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.BooleanVector; import org.elasticsearch.compute.data.BytesRefBlock; import org.elasticsearch.compute.data.BytesRefVector; import org.elasticsearch.compute.data.DoubleBlock; @@ -63,13 +64,29 @@ public int intermediateBlockCount() { } @Override - public void addRawInput(Page page) { + public void addRawInput(Page page, BooleanVector mask) { + if (mask.isConstant()) { + if (mask.getBoolean(0) == false) { + // Entire page masked away + return; + } + // No masking + BytesRefBlock block = page.getBlock(channels.get(0)); + BytesRefVector vector = block.asVector(); + if (vector != null) { + addRawVector(vector); + } else { + addRawBlock(block); + } + return; + } + // Some positions masked away, others kept BytesRefBlock block = page.getBlock(channels.get(0)); BytesRefVector vector = block.asVector(); if (vector != null) { - addRawVector(vector); + addRawVector(vector, mask); } else { - addRawBlock(block); + addRawBlock(block, mask); } } @@ -80,6 +97,16 @@ private void addRawVector(BytesRefVector vector) { } } + private void addRawVector(BytesRefVector vector, BooleanVector mask) { + BytesRef scratch = new BytesRef(); + for (int i = 0; i < vector.getPositionCount(); i++) { + if (mask.getBoolean(i) == false) { + continue; + } + SpatialCentroidCartesianPointSourceValuesAggregator.combine(state, vector.getBytesRef(i, scratch)); + } + } + private void addRawBlock(BytesRefBlock block) { BytesRef scratch = new BytesRef(); for (int p = 0; p < block.getPositionCount(); p++) { @@ -94,6 +121,23 @@ private void addRawBlock(BytesRefBlock block) { } } + private void addRawBlock(BytesRefBlock block, BooleanVector mask) { + BytesRef scratch = new BytesRef(); + for (int p = 0; p < block.getPositionCount(); p++) { + if (mask.getBoolean(p) == false) { + continue; + } + if (block.isNull(p)) { + continue; + } + int start = block.getFirstValueIndex(p); + int end = start + block.getValueCount(p); + for (int i = start; i < end; i++) { + SpatialCentroidCartesianPointSourceValuesAggregator.combine(state, block.getBytesRef(i, scratch)); + } + } + } + @Override public void addIntermediateInput(Page page) { assert channels.size() == intermediateBlockCount(); diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/spatial/SpatialCentroidGeoPointDocValuesAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/spatial/SpatialCentroidGeoPointDocValuesAggregatorFunction.java index fcd17d4c5cd86..0509c03ebf77c 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/spatial/SpatialCentroidGeoPointDocValuesAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/spatial/SpatialCentroidGeoPointDocValuesAggregatorFunction.java @@ -12,6 +12,7 @@ import org.elasticsearch.compute.aggregation.AggregatorFunction; import org.elasticsearch.compute.aggregation.IntermediateStateDesc; 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; @@ -60,13 +61,29 @@ public int intermediateBlockCount() { } @Override - public void addRawInput(Page page) { + public void addRawInput(Page page, BooleanVector mask) { + if (mask.isConstant()) { + if (mask.getBoolean(0) == false) { + // Entire page masked away + return; + } + // No masking + LongBlock block = page.getBlock(channels.get(0)); + LongVector vector = block.asVector(); + if (vector != null) { + addRawVector(vector); + } else { + addRawBlock(block); + } + return; + } + // Some positions masked away, others kept LongBlock block = page.getBlock(channels.get(0)); LongVector vector = block.asVector(); if (vector != null) { - addRawVector(vector); + addRawVector(vector, mask); } else { - addRawBlock(block); + addRawBlock(block, mask); } } @@ -76,6 +93,15 @@ private void addRawVector(LongVector vector) { } } + private void addRawVector(LongVector vector, BooleanVector mask) { + for (int i = 0; i < vector.getPositionCount(); i++) { + if (mask.getBoolean(i) == false) { + continue; + } + SpatialCentroidGeoPointDocValuesAggregator.combine(state, vector.getLong(i)); + } + } + private void addRawBlock(LongBlock block) { for (int p = 0; p < block.getPositionCount(); p++) { if (block.isNull(p)) { @@ -89,6 +115,22 @@ private void addRawBlock(LongBlock block) { } } + private void addRawBlock(LongBlock block, BooleanVector mask) { + for (int p = 0; p < block.getPositionCount(); p++) { + if (mask.getBoolean(p) == false) { + continue; + } + if (block.isNull(p)) { + continue; + } + int start = block.getFirstValueIndex(p); + int end = start + block.getValueCount(p); + for (int i = start; i < end; i++) { + SpatialCentroidGeoPointDocValuesAggregator.combine(state, block.getLong(i)); + } + } + } + @Override public void addIntermediateInput(Page page) { assert channels.size() == intermediateBlockCount(); diff --git a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/spatial/SpatialCentroidGeoPointSourceValuesAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/spatial/SpatialCentroidGeoPointSourceValuesAggregatorFunction.java index be7b8d9758d1c..10a29c841b79f 100644 --- a/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/spatial/SpatialCentroidGeoPointSourceValuesAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/spatial/SpatialCentroidGeoPointSourceValuesAggregatorFunction.java @@ -13,6 +13,7 @@ import org.elasticsearch.compute.aggregation.AggregatorFunction; import org.elasticsearch.compute.aggregation.IntermediateStateDesc; import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.BooleanVector; import org.elasticsearch.compute.data.BytesRefBlock; import org.elasticsearch.compute.data.BytesRefVector; import org.elasticsearch.compute.data.DoubleBlock; @@ -63,13 +64,29 @@ public int intermediateBlockCount() { } @Override - public void addRawInput(Page page) { + public void addRawInput(Page page, BooleanVector mask) { + if (mask.isConstant()) { + if (mask.getBoolean(0) == false) { + // Entire page masked away + return; + } + // No masking + BytesRefBlock block = page.getBlock(channels.get(0)); + BytesRefVector vector = block.asVector(); + if (vector != null) { + addRawVector(vector); + } else { + addRawBlock(block); + } + return; + } + // Some positions masked away, others kept BytesRefBlock block = page.getBlock(channels.get(0)); BytesRefVector vector = block.asVector(); if (vector != null) { - addRawVector(vector); + addRawVector(vector, mask); } else { - addRawBlock(block); + addRawBlock(block, mask); } } @@ -80,6 +97,16 @@ private void addRawVector(BytesRefVector vector) { } } + private void addRawVector(BytesRefVector vector, BooleanVector mask) { + BytesRef scratch = new BytesRef(); + for (int i = 0; i < vector.getPositionCount(); i++) { + if (mask.getBoolean(i) == false) { + continue; + } + SpatialCentroidGeoPointSourceValuesAggregator.combine(state, vector.getBytesRef(i, scratch)); + } + } + private void addRawBlock(BytesRefBlock block) { BytesRef scratch = new BytesRef(); for (int p = 0; p < block.getPositionCount(); p++) { @@ -94,6 +121,23 @@ private void addRawBlock(BytesRefBlock block) { } } + private void addRawBlock(BytesRefBlock block, BooleanVector mask) { + BytesRef scratch = new BytesRef(); + for (int p = 0; p < block.getPositionCount(); p++) { + if (mask.getBoolean(p) == false) { + continue; + } + if (block.isNull(p)) { + continue; + } + int start = block.getFirstValueIndex(p); + int end = start + block.getValueCount(p); + for (int i = start; i < end; i++) { + SpatialCentroidGeoPointSourceValuesAggregator.combine(state, block.getBytesRef(i, scratch)); + } + } + } + @Override public void addIntermediateInput(Page page) { assert channels.size() == intermediateBlockCount(); diff --git a/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/Aggregator.java b/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/Aggregator.java index 1a58a27e3377f..f0471a995f21e 100644 --- a/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/Aggregator.java +++ b/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/Aggregator.java @@ -9,6 +9,7 @@ import org.elasticsearch.compute.Describable; import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.BooleanVector; import org.elasticsearch.compute.data.Page; import org.elasticsearch.compute.operator.DriverContext; import org.elasticsearch.core.Releasable; @@ -16,9 +17,6 @@ import java.util.function.Function; public class Aggregator implements Releasable { - - public static final Object[] EMPTY_PARAMS = new Object[] {}; - private final AggregatorFunction aggregatorFunction; private final AggregatorMode mode; @@ -35,11 +33,14 @@ public int evaluateBlockCount() { return mode.isOutputPartial() ? aggregatorFunction.intermediateBlockCount() : 1; } - public void processPage(Page page) { + public void processPage(Page page, BooleanVector mask) { if (mode.isInputPartial()) { + if (mask.isConstant() == false || mask.getBoolean(0) == false) { + throw new IllegalStateException("can't mask intermediate input"); + } aggregatorFunction.addIntermediateInput(page); } else { - aggregatorFunction.addRawInput(page); + aggregatorFunction.addRawInput(page, mask); } } diff --git a/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/AggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/AggregatorFunction.java index 3d214ff3d2e0d..6050c774dd201 100644 --- a/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/AggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/AggregatorFunction.java @@ -8,18 +8,43 @@ package org.elasticsearch.compute.aggregation; import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.BooleanVector; import org.elasticsearch.compute.data.Page; +import org.elasticsearch.compute.operator.Driver; import org.elasticsearch.compute.operator.DriverContext; import org.elasticsearch.core.Releasable; +/** + * A non-grouped aggregation. + */ public interface AggregatorFunction extends Releasable { - - void addRawInput(Page page); - + /** + * Add a page worth of data to the aggregation. + * @param mask a mask to apply to the positions. If the position is {@code false} then + * the aggregation should skip it. + */ + void addRawInput(Page page, BooleanVector mask); + + /** + * Add a pre-aggregated page worth of "intermediate" input. This intermediate input + * will have been created by calling {@link #evaluateIntermediate} on this agg, though + * likely in a different {@link Driver} and maybe on a different + * physical node. + */ void addIntermediateInput(Page page); + /** + * Build pre-aggregated "intermediate" data to pass to the {@link #addIntermediateInput}. + * @param blocks write the output into this array + * @param offset write the first {@link Block} at this offset in {@code blocks} + */ void evaluateIntermediate(Block[] blocks, int offset, DriverContext driverContext); + /** + * Build the final results from running this agg. + * @param blocks write the output into this array + * @param offset write the first {@link Block} at this offset in {@code blocks} + */ void evaluateFinal(Block[] blocks, int offset, DriverContext driverContext); /** The number of blocks used by intermediate state. */ diff --git a/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/CountAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/CountAggregatorFunction.java index c32f6f4703a79..c6416f6d075db 100644 --- a/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/CountAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/CountAggregatorFunction.java @@ -72,13 +72,39 @@ private int blockIndex() { } @Override - public void addRawInput(Page page) { + public void addRawInput(Page page, BooleanVector mask) { Block block = page.getBlock(blockIndex()); LongState state = this.state; - int count = countAll ? block.getPositionCount() : block.getTotalValueCount(); + int count; + if (mask.isConstant()) { + if (mask.getBoolean(0) == false) { + return; + } + count = countAll ? block.getPositionCount() : block.getTotalValueCount(); + } else { + count = countMasked(block, mask); + } state.longValue(state.longValue() + count); } + private int countMasked(Block block, BooleanVector mask) { + int count = 0; + if (countAll) { + for (int p = 0; p < block.getPositionCount(); p++) { + if (mask.getBoolean(p)) { + count++; + } + } + return count; + } + for (int p = 0; p < block.getPositionCount(); p++) { + if (mask.getBoolean(p)) { + count += block.getValueCount(p); + } + } + return count; + } + @Override public void addIntermediateInput(Page page) { assert channels.size() == intermediateBlockCount(); diff --git a/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/FilteredAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/FilteredAggregatorFunction.java new file mode 100644 index 0000000000000..04d78673c42e8 --- /dev/null +++ b/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/FilteredAggregatorFunction.java @@ -0,0 +1,63 @@ +/* + * 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 org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.BooleanBlock; +import org.elasticsearch.compute.data.BooleanVector; +import org.elasticsearch.compute.data.Page; +import org.elasticsearch.compute.data.ToMask; +import org.elasticsearch.compute.operator.DriverContext; +import org.elasticsearch.compute.operator.EvalOperator; +import org.elasticsearch.core.Releasables; + +/** + * A {@link AggregatorFunction} that wraps another, filtering which positions + * are supplied to the aggregator. + *
+ * This works by running the filter and providing its results in the {@code mask} + * parameter for {@link #addRawInput}. + *
+ */ +record FilteredAggregatorFunction(AggregatorFunction next, EvalOperator.ExpressionEvaluator filter) implements AggregatorFunction { + @Override + public void addRawInput(Page page, BooleanVector mask) { + if (mask.isConstant() == false || mask.getBoolean(0) == false) { + throw new UnsupportedOperationException("can't filter twice"); + } + try (BooleanBlock filterResult = ((BooleanBlock) filter.eval(page)); ToMask m = filterResult.toMask()) { + // TODO warn on mv fields + next.addRawInput(page, m.mask()); + } + } + + @Override + public void addIntermediateInput(Page page) { + next.addIntermediateInput(page); + } + + @Override + public void evaluateIntermediate(Block[] blocks, int offset, DriverContext driverContext) { + next.evaluateIntermediate(blocks, offset, driverContext); + } + + @Override + public void evaluateFinal(Block[] blocks, int offset, DriverContext driverContext) { + next.evaluateFinal(blocks, offset, driverContext); + } + + @Override + public int intermediateBlockCount() { + return next.intermediateBlockCount(); + } + + @Override + public void close() { + Releasables.close(next, filter); + } +} diff --git a/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/FilteredAggregatorFunctionSupplier.java b/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/FilteredAggregatorFunctionSupplier.java index c8a8696c03449..ed63a283b3568 100644 --- a/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/FilteredAggregatorFunctionSupplier.java +++ b/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/FilteredAggregatorFunctionSupplier.java @@ -21,7 +21,17 @@ public record FilteredAggregatorFunctionSupplier(AggregatorFunctionSupplier next @Override public AggregatorFunction aggregator(DriverContext driverContext) { - throw new UnsupportedOperationException("TODO"); + AggregatorFunction next = this.next.aggregator(driverContext); + EvalOperator.ExpressionEvaluator filter = null; + try { + filter = this.filter.get(driverContext); + AggregatorFunction result = new FilteredAggregatorFunction(next, filter); + next = null; + filter = null; + return result; + } finally { + Releasables.closeExpectNoException(next, filter); + } } @Override diff --git a/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/FilteredGroupingAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/FilteredGroupingAggregatorFunction.java index c8dd80d7afe99..3e38b6d6fe9fa 100644 --- a/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/FilteredGroupingAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/FilteredGroupingAggregatorFunction.java @@ -23,6 +23,11 @@ /** * A {@link GroupingAggregatorFunction} that wraps another, filtering which positions * are supplied to the aggregator. + *+ * This filtering works by setting all of the group ids for filtered positions to + * {@code null}. {@link GroupingAggregatorFunction} will then skip collecting those + * positions. + *
*/ record FilteredGroupingAggregatorFunction(GroupingAggregatorFunction next, EvalOperator.ExpressionEvaluator filter) implements diff --git a/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/FromPartialAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/FromPartialAggregatorFunction.java index 8d4ce2971d34b..1f6270528593c 100644 --- a/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/FromPartialAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/FromPartialAggregatorFunction.java @@ -8,6 +8,7 @@ package org.elasticsearch.compute.aggregation; import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.BooleanVector; import org.elasticsearch.compute.data.CompositeBlock; import org.elasticsearch.compute.data.ElementType; import org.elasticsearch.compute.data.IntVector; @@ -41,7 +42,10 @@ public FromPartialAggregatorFunction(DriverContext driverContext, GroupingAggreg } @Override - public void addRawInput(Page page) { + public void addRawInput(Page page, BooleanVector mask) { + if (mask.isConstant() == false || mask.getBoolean(0) == false) { + throw new IllegalStateException("can't mask partial"); + } addIntermediateInput(page); } diff --git a/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/ToPartialAggregatorFunction.java b/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/ToPartialAggregatorFunction.java index 2083b8ebbfff2..6524af116d410 100644 --- a/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/ToPartialAggregatorFunction.java +++ b/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/ToPartialAggregatorFunction.java @@ -8,6 +8,7 @@ package org.elasticsearch.compute.aggregation; import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.BooleanVector; import org.elasticsearch.compute.data.CompositeBlock; import org.elasticsearch.compute.data.ElementType; import org.elasticsearch.compute.data.Page; @@ -37,8 +38,8 @@ public ToPartialAggregatorFunction(AggregatorFunction delegate, List