Skip to content

Commit b7e4bfa

Browse files
committed
Merge branch 'empty_bucket' of https://github.com/przemekwitek/elasticsearch into empty_bucket
2 parents d0d2ce3 + 1399d27 commit b7e4bfa

File tree

4 files changed

+19
-8
lines changed

4 files changed

+19
-8
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ public record TopNDef(int order, boolean asc, boolean nullsFirst, int limit) {}
129129

130130
public interface EmptyBucketGenerator {
131131
int getEmptyBucketCount();
132+
132133
Block generate(BlockFactory blockFactory, int maxPositionsInBucket);
133134
}
134135

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/grouping/Bucket.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,13 @@ public boolean foldable() {
263263
@Override
264264
public ExpressionEvaluator.Factory toEvaluator(ToEvaluator toEvaluator) {
265265
if (field.dataType() == DataType.DATETIME || field.dataType() == DataType.DATE_NANOS) {
266-
Rounding.Prepared preparedRounding =
267-
DatetimeEmptyBucketGenerator.determineRounding(field, buckets, from, to, toEvaluator.foldCtx());
266+
Rounding.Prepared preparedRounding = DatetimeEmptyBucketGenerator.determineRounding(
267+
field,
268+
buckets,
269+
from,
270+
to,
271+
toEvaluator.foldCtx()
272+
);
268273
return DateTrunc.evaluator(field.dataType(), source(), toEvaluator.apply(field), preparedRounding);
269274
}
270275
if (field.dataType().isNumeric()) {

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/grouping/DatetimeEmptyBucketGenerator.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,7 @@ public int getEmptyBucketCount() {
6868

6969
@Override
7070
public Block generate(BlockFactory blockFactory, int maxPositionsInBucket) {
71-
try (
72-
LongBlock.Builder newBlockBuilder = (LongBlock.Builder) ElementType.LONG.newBlockBuilder(maxPositionsInBucket, blockFactory)
73-
) {
71+
try (LongBlock.Builder newBlockBuilder = (LongBlock.Builder) ElementType.LONG.newBlockBuilder(maxPositionsInBucket, blockFactory)) {
7472
int i = 0;
7573
for (long bucket = rounding.round(from); bucket < to; bucket = rounding.nextRoundingValue(bucket)) {
7674
newBlockBuilder.appendLong(bucket);
@@ -85,7 +83,12 @@ public Block generate(BlockFactory blockFactory, int maxPositionsInBucket) {
8583
}
8684

8785
static Rounding.Prepared determineRounding(
88-
Expression field, Expression buckets, Expression from, Expression to, FoldContext foldContext) {
86+
Expression field,
87+
Expression buckets,
88+
Expression from,
89+
Expression to,
90+
FoldContext foldContext
91+
) {
8992
assert field.dataType() == DataType.DATETIME || field.dataType() == DataType.DATE_NANOS : "expected date type; got " + field;
9093
if (buckets.dataType().isWholeNumber()) {
9194
int b = ((Number) buckets.fold(foldContext)).intValue();

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/grouping/NumericEmptyBucketGenerator.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,10 @@ public int getEmptyBucketCount() {
4040
@Override
4141
public Block generate(BlockFactory blockFactory, int maxPositionsInBucket) {
4242
try (
43-
DoubleBlock.Builder newBlockBuilder =
44-
(DoubleBlock.Builder) ElementType.DOUBLE.newBlockBuilder(maxPositionsInBucket, blockFactory)
43+
DoubleBlock.Builder newBlockBuilder = (DoubleBlock.Builder) ElementType.DOUBLE.newBlockBuilder(
44+
maxPositionsInBucket,
45+
blockFactory
46+
)
4547
) {
4648
int i = 0;
4749
for (double bucket = round(Math.floor(from / roundTo) * roundTo, 2); bucket < to; bucket = round(bucket + roundTo, 2)) {

0 commit comments

Comments
 (0)