Skip to content

Commit a813c78

Browse files
committed
Two more tests
1 parent 7c63d6d commit a813c78

File tree

3 files changed

+59
-1
lines changed

3 files changed

+59
-1
lines changed

x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/operator/topn/ResultBuilder.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ static ResultBuilder resultBuilderFor(
6363
case NULL -> new ResultBuilderForNull(blockFactory);
6464
case DOC -> new ResultBuilderForDoc(blockFactory, positions);
6565
case AGGREGATE_METRIC_DOUBLE -> new ResultBuilderForAggregateMetricDouble(blockFactory, positions);
66+
case DATE_RANGE -> new ResultBuilderForDateRange(blockFactory, positions);
6667
default -> {
6768
assert false : "Result builder for [" + elementType + "]";
6869
throw new UnsupportedOperationException("Result builder for [" + elementType + "]");
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
package org.elasticsearch.compute.operator.topn;
9+
10+
import org.apache.lucene.util.BytesRef;
11+
import org.elasticsearch.compute.data.DateRangeBlockBuilder;
12+
import org.elasticsearch.compute.data.Block;
13+
import org.elasticsearch.compute.data.BlockFactory;
14+
import org.elasticsearch.index.mapper.BlockLoader;
15+
16+
import java.util.List;
17+
18+
public class ResultBuilderForDateRange implements ResultBuilder {
19+
20+
private final DateRangeBlockBuilder builder;
21+
22+
ResultBuilderForDateRange(BlockFactory blockFactory, int positions) {
23+
this.builder = blockFactory.newDateRangeBlockBuilder(positions);
24+
}
25+
26+
@Override
27+
public void decodeKey(BytesRef keys) {
28+
throw new AssertionError("DateRangeBlock can't be a key");
29+
}
30+
31+
@Override
32+
public void decodeValue(BytesRef values) {
33+
int count = TopNEncoder.DEFAULT_UNSORTABLE.decodeVInt(values);
34+
if (count == 0) {
35+
builder.appendNull();
36+
} else {
37+
builder.from().appendLong(TopNEncoder.DEFAULT_UNSORTABLE.decodeLong(values));
38+
builder.to().appendLong(TopNEncoder.DEFAULT_UNSORTABLE.decodeLong(values));
39+
}
40+
}
41+
42+
@Override
43+
public Block build() {
44+
return builder.build();
45+
}
46+
47+
@Override
48+
public String toString() {
49+
return "ResultBuilderForDateRange";
50+
}
51+
52+
@Override
53+
public void close() {
54+
builder.close();
55+
}
56+
}

x-pack/plugin/esql/compute/src/test/java/org/elasticsearch/compute/data/VectorBuilderTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ public static List<Object[]> params() {
3434
|| e == ElementType.NULL
3535
|| e == ElementType.DOC
3636
|| e == ElementType.COMPOSITE
37-
|| e == ElementType.AGGREGATE_METRIC_DOUBLE) {
37+
|| e == ElementType.AGGREGATE_METRIC_DOUBLE
38+
|| e == ElementType.DATE_RANGE) {
3839
continue;
3940
}
4041
params.add(new Object[] { e });

0 commit comments

Comments
 (0)