Skip to content

Commit a8253f1

Browse files
committed
use int builder
1 parent 1d8987c commit a8253f1

File tree

2 files changed

+40
-28
lines changed

2 files changed

+40
-28
lines changed

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

Lines changed: 20 additions & 14 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/X-ValuesAggregator.java.st

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,13 @@ $if(BytesRef)$
107107
return delegate;
108108
}
109109
BytesRefVector dict = valuesOrdinal.getDictionaryVector();
110-
final int[] hashIds = new int[dict.getPositionCount()];
110+
final IntVector hashIds;
111111
BytesRef spare = new BytesRef();
112-
for (int p = 0; p < dict.getPositionCount(); p++) {
113-
hashIds[p] = Math.toIntExact(BlockHash.hashOrdToGroup(state.bytes.add(dict.getBytesRef(p, spare))));
112+
try (var hashIdsBuilder = values.blockFactory().newIntVectorFixedBuilder(dict.getPositionCount())) {
113+
for (int p = 0; p < dict.getPositionCount(); p++) {
114+
hashIdsBuilder.appendInt(Math.toIntExact(BlockHash.hashOrdToGroup(state.bytes.add(dict.getBytesRef(p, spare)))));
115+
}
116+
hashIds = hashIdsBuilder.build();
114117
}
115118
IntBlock ordinalIds = valuesOrdinal.getOrdinalsBlock();
116119
return new GroupingAggregatorFunction.AddInput() {
@@ -130,7 +133,7 @@ $if(BytesRef)$
130133
int valuesStart = ordinalIds.getFirstValueIndex(groupPosition + positionOffset);
131134
int valuesEnd = valuesStart + ordinalIds.getValueCount(groupPosition + positionOffset);
132135
for (int v = valuesStart; v < valuesEnd; v++) {
133-
state.values.add(groupId, ordinalIds.getInt(v));
136+
state.values.add(groupId, hashIds.getInt(ordinalIds.getInt(v)));
134137
}
135138
}
136139
}
@@ -152,7 +155,7 @@ $if(BytesRef)$
152155
int valuesStart = ordinalIds.getFirstValueIndex(groupPosition + positionOffset);
153156
int valuesEnd = valuesStart + ordinalIds.getValueCount(groupPosition + positionOffset);
154157
for (int v = valuesStart; v < valuesEnd; v++) {
155-
state.values.add(groupId, ordinalIds.getInt(v));
158+
state.values.add(groupId, hashIds.getInt(ordinalIds.getInt(v)));
156159
}
157160
}
158161
}
@@ -168,14 +171,14 @@ $if(BytesRef)$
168171
int valuesStart = ordinalIds.getFirstValueIndex(groupPosition + positionOffset);
169172
int valuesEnd = valuesStart + ordinalIds.getValueCount(groupPosition + positionOffset);
170173
for (int v = valuesStart; v < valuesEnd; v++) {
171-
state.values.add(groupId, ordinalIds.getInt(v));
174+
state.values.add(groupId, hashIds.getInt(ordinalIds.getInt(v)));
172175
}
173176
}
174177
}
175178

176179
@Override
177180
public void close() {
178-
delegate.close();
181+
Releasables.close(hashIds, delegate);
179182
}
180183
};
181184
}
@@ -190,10 +193,13 @@ $if(BytesRef)$
190193
return delegate;
191194
}
192195
BytesRefVector dict = valuesOrdinal.getDictionaryVector();
193-
final int[] hashIds = new int[dict.getPositionCount()];
196+
final IntVector hashIds;
194197
BytesRef spare = new BytesRef();
195-
for (int p = 0; p < dict.getPositionCount(); p++) {
196-
hashIds[p] = Math.toIntExact(BlockHash.hashOrdToGroup(state.bytes.add(dict.getBytesRef(p, spare))));
198+
try (var hashIdsBuilder = values.blockFactory().newIntVectorFixedBuilder(dict.getPositionCount())) {
199+
for (int p = 0; p < dict.getPositionCount(); p++) {
200+
hashIdsBuilder.appendInt(Math.toIntExact(BlockHash.hashOrdToGroup(state.bytes.add(dict.getBytesRef(p, spare)))));
201+
}
202+
hashIds = hashIdsBuilder.build();
197203
}
198204
var ordinalIds = valuesOrdinal.getOrdinalsVector();
199205
return new GroupingAggregatorFunction.AddInput() {
@@ -207,7 +213,7 @@ $if(BytesRef)$
207213
int groupEnd = groupStart + groupIds.getValueCount(groupPosition);
208214
for (int g = groupStart; g < groupEnd; g++) {
209215
int groupId = groupIds.getInt(g);
210-
state.values.add(groupId, ordinalIds.getInt(groupPosition + positionOffset));
216+
state.values.add(groupId, hashIds.getInt(ordinalIds.getInt(groupPosition + positionOffset)));
211217
}
212218
}
213219
}
@@ -222,7 +228,7 @@ $if(BytesRef)$
222228
int groupEnd = groupStart + groupIds.getValueCount(groupPosition);
223229
for (int g = groupStart; g < groupEnd; g++) {
224230
int groupId = groupIds.getInt(g);
225-
state.values.add(groupId, ordinalIds.getInt(groupPosition + positionOffset));
231+
state.values.add(groupId, hashIds.getInt(ordinalIds.getInt(groupPosition + positionOffset)));
226232
}
227233
}
228234
}
@@ -231,13 +237,13 @@ $if(BytesRef)$
231237
public void add(int positionOffset, IntVector groupIds) {
232238
for (int groupPosition = 0; groupPosition < groupIds.getPositionCount(); groupPosition++) {
233239
int groupId = groupIds.getInt(groupPosition);
234-
state.values.add(groupId, ordinalIds.getInt(groupPosition + positionOffset));
240+
state.values.add(groupId, hashIds.getInt(ordinalIds.getInt(groupPosition + positionOffset)));
235241
}
236242
}
237243

238244
@Override
239245
public void close() {
240-
delegate.close();
246+
Releasables.close(hashIds, delegate);
241247
}
242248
};
243249
}

0 commit comments

Comments
 (0)