Skip to content

Commit 9a5d6e3

Browse files
committed
Add "emitEmptyBuckets" parameter to the "Bucket" function.
1 parent 1ce5c7c commit 9a5d6e3

File tree

29 files changed

+751
-126
lines changed

29 files changed

+751
-126
lines changed

benchmarks/src/main/java/org/elasticsearch/benchmark/compute/operator/AggregatorBenchmark.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,11 +191,12 @@ private static Operator operator(DriverContext driverContext, String grouping, S
191191
new BlockHash.GroupSpec(2, ElementType.BYTES_REF)
192192
);
193193
case TOP_N_LONGS -> List.of(
194-
new BlockHash.GroupSpec(0, ElementType.LONG, null, new BlockHash.TopNDef(0, true, true, TOP_N_LIMIT))
194+
new BlockHash.GroupSpec(0, ElementType.LONG, null, new BlockHash.TopNDef(0, true, true, TOP_N_LIMIT), null)
195195
);
196196
default -> throw new IllegalArgumentException("unsupported grouping [" + grouping + "]");
197197
};
198198
return new HashAggregationOperator(
199+
groups,
199200
List.of(supplier(op, dataType, filter).groupingAggregatorFactory(AggregatorMode.SINGLE, List.of(groups.size()))),
200201
() -> BlockHash.build(groups, driverContext.blockFactory(), 16 * 1024, false),
201202
driverContext

benchmarks/src/main/java/org/elasticsearch/benchmark/compute/operator/ValuesAggregatorBenchmark.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ private static Operator operator(DriverContext driverContext, int groups, String
122122
}
123123
List<BlockHash.GroupSpec> groupSpec = List.of(new BlockHash.GroupSpec(0, ElementType.LONG));
124124
return new HashAggregationOperator(
125+
groupSpec,
125126
List.of(supplier(dataType).groupingAggregatorFactory(mode, List.of(1))),
126127
() -> BlockHash.build(groupSpec, driverContext.blockFactory(), 16 * 1024, false),
127128
driverContext

docs/reference/query-languages/esql/_snippets/functions/parameters/bucket.md

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

docs/reference/query-languages/esql/_snippets/functions/types/bucket.md

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

docs/reference/query-languages/esql/images/functions/bucket.svg

Lines changed: 1 addition & 1 deletion
Loading

docs/reference/query-languages/esql/images/functions/categorize.svg

Lines changed: 1 addition & 1 deletion
Loading

docs/reference/query-languages/esql/images/functions/top.svg

Lines changed: 1 addition & 1 deletion
Loading

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ public class GroupingAggregator implements Releasable {
2323

2424
private final AggregatorMode mode;
2525

26+
public AggregatorMode getMode() {
27+
return mode;
28+
}
29+
2630
public interface Factory extends Function<DriverContext, GroupingAggregator>, Describable {}
2731

2832
public GroupingAggregator(GroupingAggregatorFunction aggregatorFunction, AggregatorMode mode) {

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,12 @@ public abstract class BlockHash implements Releasable, SeenGroupIds {
127127
*/
128128
public record TopNDef(int order, boolean asc, boolean nullsFirst, int limit) {}
129129

130+
public interface EmptyBucketGenerator {
131+
int getEmptyBucketCount();
132+
133+
void generate(Block.Builder blockBuilder);
134+
}
135+
130136
/**
131137
* Configuration for a BlockHash group spec that is doing text categorization.
132138
*/
@@ -137,13 +143,19 @@ public enum OutputFormat {
137143
}
138144
}
139145

140-
public record GroupSpec(int channel, ElementType elementType, @Nullable CategorizeDef categorizeDef, @Nullable TopNDef topNDef) {
146+
public record GroupSpec(
147+
int channel,
148+
ElementType elementType,
149+
@Nullable CategorizeDef categorizeDef,
150+
@Nullable TopNDef topNDef,
151+
@Nullable EmptyBucketGenerator emptyBucketGenerator
152+
) {
141153
public GroupSpec(int channel, ElementType elementType) {
142-
this(channel, elementType, null, null);
154+
this(channel, elementType, null, null, null);
143155
}
144156

145157
public GroupSpec(int channel, ElementType elementType, CategorizeDef categorizeDef) {
146-
this(channel, elementType, categorizeDef, null);
158+
this(channel, elementType, categorizeDef, null, null);
147159
}
148160

149161
public boolean isCategorize() {

0 commit comments

Comments
 (0)