Skip to content

Commit 6845928

Browse files
committed
fix after merges
1 parent 5c4d0a8 commit 6845928

File tree

5 files changed

+44
-26
lines changed

5 files changed

+44
-26
lines changed

x-pack/plugin/esql/compute/gen/src/main/java/org/elasticsearch/compute/gen/GroupingAggregatorImplementer.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
import static org.elasticsearch.compute.gen.Types.INTERMEDIATE_STATE_DESC;
5959
import static org.elasticsearch.compute.gen.Types.INT_ARRAY_BLOCK;
6060
import static org.elasticsearch.compute.gen.Types.INT_BIG_ARRAY_BLOCK;
61+
import static org.elasticsearch.compute.gen.Types.INT_BLOCK;
6162
import static org.elasticsearch.compute.gen.Types.INT_VECTOR;
6263
import static org.elasticsearch.compute.gen.Types.LIST_AGG_FUNC_DESC;
6364
import static org.elasticsearch.compute.gen.Types.LIST_INTEGER;
@@ -615,7 +616,8 @@ private MethodSpec addIntermediateInput(TypeName groupsType) {
615616
requireName("combineIntermediate"),
616617
requireArgs(
617618
Stream.concat(
618-
Stream.of(aggState.declaredType(), TypeName.INT, INT_VECTOR), // aggState, positionOffset, groupIds
619+
// aggState, positionOffset, groupIds
620+
Stream.of(aggState.declaredType(), TypeName.INT, groupsIsBlock ? INT_BLOCK : INT_VECTOR),
619621
intermediateState.stream().map(AggregatorImplementer.IntermediateStateDesc::combineArgType)
620622
).map(Methods::requireType).toArray(Methods.TypeMatcher[]::new)
621623
)
@@ -626,7 +628,9 @@ private MethodSpec addIntermediateInput(TypeName groupsType) {
626628
.collect(Collectors.joining(", "));
627629
builder.addStatement("$T.combineIntermediate(state, positionOffset, groups, " + states + ")", declarationType);
628630
} else {
629-
if (intermediateState.stream().map(AggregatorImplementer.IntermediateStateDesc::elementType).anyMatch(n -> n.equals("BYTES_REF"))) {
631+
if (intermediateState.stream()
632+
.map(AggregatorImplementer.IntermediateStateDesc::elementType)
633+
.anyMatch(n -> n.equals("BYTES_REF"))) {
630634
builder.addStatement("$T scratch = new $T()", BYTES_REF, BYTES_REF);
631635
}
632636
builder.beginControlFlow("for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++)");

x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/ValuesBytesRefAggregator.java

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/ValuesBytesRefGroupingAggregatorFunction.java

Lines changed: 2 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/ValuesBytesRefAggregators.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,4 +222,32 @@ static void combineIntermediateInputValues(
222222
}
223223
}
224224
}
225+
226+
static void combineIntermediateInputValues(
227+
ValuesBytesRefAggregator.GroupingState state,
228+
int positionOffset,
229+
IntBlock groupIds,
230+
BytesRefBlock values
231+
) {
232+
final BytesRef scratch = new BytesRef();
233+
for (int groupPosition = 0; groupPosition < groupIds.getPositionCount(); groupPosition++) {
234+
if (groupIds.isNull(groupPosition)) {
235+
continue;
236+
}
237+
int groupStart = groupIds.getFirstValueIndex(groupPosition);
238+
int groupEnd = groupStart + groupIds.getValueCount(groupPosition);
239+
for (int g = groupStart; g < groupEnd; g++) {
240+
if (values.isNull(groupPosition + positionOffset)) {
241+
continue;
242+
}
243+
int groupId = groupIds.getInt(g);
244+
int valuesStart = values.getFirstValueIndex(groupPosition + positionOffset);
245+
int valuesEnd = valuesStart + values.getValueCount(groupPosition + positionOffset);
246+
for (int v = valuesStart; v < valuesEnd; v++) {
247+
var bytes = values.getBytesRef(v, scratch);
248+
state.addValue(groupId, bytes);
249+
}
250+
}
251+
}
252+
}
225253
}

x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/X-ValuesAggregator.java.st

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ $if(BytesRef)$
118118
ValuesBytesRefAggregators.combineIntermediateInputValues(state, positionOffset, groups, values);
119119
}
120120

121+
public static void combineIntermediate(GroupingState state, int positionOffset, IntBlock groups, $Type$Block values) {
122+
ValuesBytesRefAggregators.combineIntermediateInputValues(state, positionOffset, groups, values);
123+
}
124+
121125
$else$
122126
public static void combineIntermediate(GroupingState state, int groupId, $Type$Block values, int valuesPosition) {
123127
int start = values.getFirstValueIndex(valuesPosition);

0 commit comments

Comments
 (0)