Skip to content

Commit 861f108

Browse files
committed
Update Count types docs and tests
1 parent 9a5c860 commit 861f108

File tree

5 files changed

+29
-2
lines changed

5 files changed

+29
-2
lines changed

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

Lines changed: 1 addition & 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/kibana/definition/functions/count.json

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

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/aggregate/Count.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ public Count(
7979
"cartesian_point",
8080
"cartesian_shape",
8181
"date",
82+
"date_nanos",
8283
"double",
8384
"geo_point",
8485
"geo_shape",

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/MultiRowTestCaseSupplier.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ public final class MultiRowTestCaseSupplier {
3636

3737
private MultiRowTestCaseSupplier() {}
3838

39+
public static List<TypedDataSupplier> nullCases(int minRows, int maxRows) {
40+
List<TypedDataSupplier> cases = new ArrayList<>();
41+
42+
addSuppliers(cases, minRows, maxRows, "null", DataType.NULL, () -> null);
43+
44+
return cases;
45+
}
46+
3947
public static List<TypedDataSupplier> intCases(int minRows, int maxRows, int min, int max, boolean includeZero) {
4048
List<TypedDataSupplier> cases = new ArrayList<>();
4149

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/CountTests.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.math.BigInteger;
2222
import java.util.ArrayList;
2323
import java.util.List;
24+
import java.util.Objects;
2425
import java.util.function.Supplier;
2526
import java.util.stream.Collectors;
2627
import java.util.stream.Stream;
@@ -37,11 +38,13 @@ public static Iterable<Object[]> parameters() {
3738
var suppliers = new ArrayList<TestCaseSupplier>();
3839

3940
Stream.of(
41+
MultiRowTestCaseSupplier.nullCases(1, 1000),
4042
MultiRowTestCaseSupplier.intCases(1, 1000, Integer.MIN_VALUE, Integer.MAX_VALUE, true),
4143
MultiRowTestCaseSupplier.longCases(1, 1000, Long.MIN_VALUE, Long.MAX_VALUE, true),
4244
MultiRowTestCaseSupplier.ulongCases(1, 1000, BigInteger.ZERO, UNSIGNED_LONG_MAX, true),
4345
MultiRowTestCaseSupplier.doubleCases(1, 1000, -Double.MAX_VALUE, Double.MAX_VALUE, true),
4446
MultiRowTestCaseSupplier.dateCases(1, 1000),
47+
MultiRowTestCaseSupplier.dateNanosCases(1, 1000),
4548
MultiRowTestCaseSupplier.booleanCases(1, 1000),
4649
MultiRowTestCaseSupplier.ipCases(1, 1000),
4750
MultiRowTestCaseSupplier.versionCases(1, 1000),
@@ -54,10 +57,12 @@ public static Iterable<Object[]> parameters() {
5457

5558
// No rows
5659
for (var dataType : List.of(
60+
DataType.NULL,
5761
DataType.INTEGER,
5862
DataType.LONG,
5963
DataType.DOUBLE,
6064
DataType.DATETIME,
65+
DataType.DATE_NANOS,
6166
DataType.BOOLEAN,
6267
DataType.IP,
6368
DataType.VERSION,
@@ -93,13 +98,13 @@ protected Expression build(Source source, List<Expression> args) {
9398
private static TestCaseSupplier makeSupplier(TestCaseSupplier.TypedDataSupplier fieldSupplier) {
9499
return new TestCaseSupplier(fieldSupplier.name(), List.of(fieldSupplier.type()), () -> {
95100
var fieldTypedData = fieldSupplier.get();
96-
var rowCount = fieldTypedData.multiRowData().size();
101+
var rowCount = fieldTypedData.multiRowData().stream().filter(Objects::nonNull).count();
97102

98103
return new TestCaseSupplier.TestCase(
99104
List.of(fieldTypedData),
100105
"Count[field=Attribute[channel=0]]",
101106
DataType.LONG,
102-
equalTo((long) rowCount)
107+
equalTo(rowCount)
103108
);
104109
});
105110
}

0 commit comments

Comments
 (0)