Skip to content

Commit eb5bbd4

Browse files
committed
Two more tests fixes
1 parent 113f9a8 commit eb5bbd4

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public static List<Object[]> params() {
3131
continue;
3232
}
3333
for (boolean nullAllowed : new boolean[] { false, true }) {
34-
if (e == ElementType.AGGREGATE_METRIC_DOUBLE) {
34+
if (e == ElementType.AGGREGATE_METRIC_DOUBLE || e == ElementType.DATE_RANGE) {
3535
// doesn't support multi-values
3636
params.add(new Object[] { e, nullAllowed, 0, 1 });
3737
continue;

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ static void assertBlockValues(Block block, List<List<Object>> expectedBlockValue
4242
valueCount,
4343
expectedRowValues
4444
);
45+
case DATE_RANGE -> assertDteRangeValues((DateRangeBlock) block, firstValueIndex, valueCount, expectedRowValues);
4546
default -> throw new IllegalArgumentException("Unsupported element type [" + block.elementType() + "]");
4647
}
4748
}
@@ -117,4 +118,12 @@ private static void assertAggregateMetricRowValues(
117118
assertThat(block.countBlock().getInt(firstValueIndex + valueIndex), is(equalTo(expectedValue.count())));
118119
}
119120
}
121+
122+
private static void assertDteRangeValues(DateRangeBlock block, int firstValueIdx, int valueCount, List<Object> expectedRowValues) {
123+
for (int idx = 0; idx < valueCount; idx++) {
124+
var expectedValue = (DateRangeBlockBuilder.DateRangeLiteral) expectedRowValues.get(idx);
125+
assertThat(block.getFromBlock().getLong(firstValueIdx + idx), equalTo(expectedValue.from()));
126+
assertThat(block.getToBlock().getLong(firstValueIdx + idx), equalTo(expectedValue.to()));
127+
}
128+
}
120129
}

x-pack/plugin/esql/compute/src/test/java/org/elasticsearch/compute/operator/topn/ExtractorTests.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import org.elasticsearch.compute.data.Block;
1818
import org.elasticsearch.compute.data.BlockFactory;
1919
import org.elasticsearch.compute.data.BlockUtils;
20+
import org.elasticsearch.compute.data.DateRangeBlockBuilder;
2021
import org.elasticsearch.compute.data.DocVector;
2122
import org.elasticsearch.compute.data.ElementType;
2223
import org.elasticsearch.compute.lucene.AlwaysReferencedIndexedByShardId;
@@ -30,6 +31,7 @@
3031
import java.util.List;
3132
import java.util.function.Supplier;
3233

34+
import static org.elasticsearch.common.time.DateUtils.MAX_MILLIS_BEFORE_9999;
3335
import static org.hamcrest.Matchers.equalTo;
3436
import static org.hamcrest.Matchers.greaterThan;
3537

@@ -63,6 +65,9 @@ public static Iterable<Object[]> parameters() {
6365
)
6466
);
6567
}
68+
case DATE_RANGE -> cases.add(
69+
valueTestCase("date_range with nulls", e, TopNEncoder.DEFAULT_UNSORTABLE, ExtractorTests::randomDateRange)
70+
);
6671
case FLOAT -> {
6772
}
6873
case BYTES_REF -> {
@@ -252,4 +257,10 @@ public static AggregateMetricDoubleLiteral randomAggregateMetricDouble(boolean a
252257
randomBoolean() ? randomInt() : null
253258
);
254259
}
260+
261+
private static DateRangeBlockBuilder.DateRangeLiteral randomDateRange() {
262+
var from = randomMillisUpToYear9999();
263+
var to = randomLongBetween(from + 1, MAX_MILLIS_BEFORE_9999);
264+
return new DateRangeBlockBuilder.DateRangeLiteral(from, to);
265+
}
255266
}

0 commit comments

Comments
 (0)