Skip to content

Commit e639268

Browse files
committed
Add JavaDocs/comments
1 parent a633806 commit e639268

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@
3535
/**
3636
* BlockHash implementation for {@code Categorize} grouping function as first
3737
* grouping expression, followed by one or mode other grouping expressions.
38+
* <p>
39+
* For the first grouping (the {@code Categorize} grouping function), a
40+
* {@code CategorizeBlockHash} is used, which outputs integers (category IDs).
41+
* Next, a {@code PackedValuesBlockHash} is used on the category IDs and the
42+
* other groupings (which are not {@code Categorize}s).
3843
*/
3944
public class CategorizePackedValuesBlockHash extends BlockHash {
4045

@@ -112,6 +117,7 @@ private IntBlock getCategories(Page page) {
112117
public Block[] getKeys() {
113118
Block[] keys = packedValuesBlockHash.getKeys();
114119
if (aggregatorMode.isOutputPartial() == false) {
120+
// For final output, the keys are the category regexes.
115121
try (
116122
BytesRefBlock regexes = (BytesRefBlock) categorizeBlockHash.getKeys()[0];
117123
BytesRefBlock.Builder builder = blockFactory.newBytesRefBlockBuilder(keys[0].getPositionCount())
@@ -131,9 +137,15 @@ public Block[] getKeys() {
131137
keys[0] = builder.build();
132138
}
133139
} else {
140+
// For intermediate output, the keys are the delegate PackedValuesBlockHash's
141+
// keys, with the category IDs replaced by the categorizer's internal state
142+
// together with the list of category IDs.
134143
BytesRef state;
135144
try (BytesStreamOutput out = new BytesStreamOutput()) {
136145
out.writeBytesRef(categorizeBlockHash.serializeCategorizer());
146+
// It's a bit inefficient to copy the IntVector's values into an int[]
147+
// and discard the array soon after. IntVector should maybe expose the
148+
// underlying array instead. TODO: investigate whether that's worth it
137149
IntVector idsVector = (IntVector) keys[0].asVector();
138150
int[] idsArray = new int[idsVector.getPositionCount()];
139151
for (int i = 0; i < idsVector.getPositionCount(); i++) {

0 commit comments

Comments
 (0)