Skip to content

Commit 6a4b727

Browse files
committed
ESQL: Accept unsigned longs on MAX and MIN aggregations
1 parent f393dba commit 6a4b727

File tree

14 files changed

+128
-14
lines changed

14 files changed

+128
-14
lines changed

docs/reference/query-languages/esql/_snippets/functions/types/max.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/_snippets/functions/types/min.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/max.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.

docs/reference/query-languages/esql/kibana/definition/functions/min.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/qa/testFixtures/src/main/resources/stats.csv-spec

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ l:long
55
5
66
;
77

8+
maxOfUnsignedLong
9+
required_capability: agg_max_min_unsigned_long
10+
from ul_logs | stats ul = max(bytes_in);
11+
12+
ul:ul
13+
18446744073709551615
14+
;
15+
816
maxOfInteger
917
// tag::max[]
1018
FROM employees
@@ -18,6 +26,21 @@ MAX(languages):integer
1826
// end::max-result[]
1927
;
2028

29+
minOfLong
30+
from employees | stats l = min(languages.long);
31+
32+
l:long
33+
1
34+
;
35+
36+
minOfUnsignedLong
37+
required_capability: agg_max_min_unsigned_long
38+
from ul_logs | stats ul = min(bytes_in);
39+
40+
ul:ul
41+
0
42+
;
43+
2144
minOfInteger
2245
// tag::min[]
2346
FROM employees

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/action/EsqlCapabilities.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ public enum Cap {
9292
*/
9393
AGG_VALUES_SPATIAL,
9494

95+
/**
96+
* Accept unsigned longs on MAX and MIN aggregations.
97+
*/
98+
AGG_MAX_MIN_UNSIGNED_LONG,
99+
95100
/**
96101
* Does ESQL support async queries.
97102
*/

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public class Max extends AggregateFunction implements ToAggregator, SurrogateExp
4747
private static final Map<DataType, Supplier<AggregatorFunctionSupplier>> SUPPLIERS = Map.ofEntries(
4848
Map.entry(DataType.BOOLEAN, MaxBooleanAggregatorFunctionSupplier::new),
4949
Map.entry(DataType.LONG, MaxLongAggregatorFunctionSupplier::new),
50+
Map.entry(DataType.UNSIGNED_LONG, MaxLongAggregatorFunctionSupplier::new),
5051
Map.entry(DataType.DATETIME, MaxLongAggregatorFunctionSupplier::new),
5152
Map.entry(DataType.DATE_NANOS, MaxLongAggregatorFunctionSupplier::new),
5253
Map.entry(DataType.INTEGER, MaxIntAggregatorFunctionSupplier::new),
@@ -58,7 +59,7 @@ public class Max extends AggregateFunction implements ToAggregator, SurrogateExp
5859
);
5960

6061
@FunctionInfo(
61-
returnType = { "boolean", "double", "integer", "long", "date", "date_nanos", "ip", "keyword", "long", "version" },
62+
returnType = { "boolean", "double", "integer", "long", "date", "date_nanos", "ip", "keyword", "unsigned_long", "version" },
6263
description = "The maximum value of a field.",
6364
type = FunctionType.AGGREGATE,
6465
examples = {
@@ -86,7 +87,7 @@ public Max(
8687
"ip",
8788
"keyword",
8889
"text",
89-
"long",
90+
"unsigned_long",
9091
"version" }
9192
) Expression field
9293
) {
@@ -128,7 +129,13 @@ protected TypeResolution resolveType() {
128129
dt -> SUPPLIERS.containsKey(dt) || dt == DataType.AGGREGATE_METRIC_DOUBLE,
129130
sourceText(),
130131
DEFAULT,
131-
"representable except unsigned_long and spatial types"
132+
"boolean",
133+
"date",
134+
"ip",
135+
"string",
136+
"version",
137+
"aggregate_metric_double",
138+
"numeric except counter types"
132139
);
133140
}
134141

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public class Min extends AggregateFunction implements ToAggregator, SurrogateExp
4747
private static final Map<DataType, Supplier<AggregatorFunctionSupplier>> SUPPLIERS = Map.ofEntries(
4848
Map.entry(DataType.BOOLEAN, MinBooleanAggregatorFunctionSupplier::new),
4949
Map.entry(DataType.LONG, MinLongAggregatorFunctionSupplier::new),
50+
Map.entry(DataType.UNSIGNED_LONG, MinLongAggregatorFunctionSupplier::new),
5051
Map.entry(DataType.DATETIME, MinLongAggregatorFunctionSupplier::new),
5152
Map.entry(DataType.DATE_NANOS, MinLongAggregatorFunctionSupplier::new),
5253
Map.entry(DataType.INTEGER, MinIntAggregatorFunctionSupplier::new),
@@ -58,7 +59,7 @@ public class Min extends AggregateFunction implements ToAggregator, SurrogateExp
5859
);
5960

6061
@FunctionInfo(
61-
returnType = { "boolean", "double", "integer", "long", "date", "date_nanos", "ip", "keyword", "long", "version" },
62+
returnType = { "boolean", "double", "integer", "long", "date", "date_nanos", "ip", "keyword", "unsigned_long", "version" },
6263
description = "The minimum value of a field.",
6364
type = FunctionType.AGGREGATE,
6465
examples = {
@@ -86,7 +87,7 @@ public Min(
8687
"ip",
8788
"keyword",
8889
"text",
89-
"long",
90+
"unsigned_long",
9091
"version" }
9192
) Expression field
9293
) {
@@ -128,7 +129,13 @@ protected TypeResolution resolveType() {
128129
dt -> SUPPLIERS.containsKey(dt) || dt == DataType.AGGREGATE_METRIC_DOUBLE,
129130
sourceText(),
130131
DEFAULT,
131-
"representable except unsigned_long and spatial types"
132+
"boolean",
133+
"date",
134+
"ip",
135+
"string",
136+
"version",
137+
"aggregate_metric_double",
138+
"numeric except counter types"
132139
);
133140
}
134141

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/multivalue/MvMax.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,18 @@ public String getWriteableName() {
6969

7070
@Override
7171
protected TypeResolution resolveFieldType() {
72-
return isType(field(), t -> isSpatial(t) == false && isRepresentable(t), sourceText(), null, "representableNonSpatial");
72+
return isType(
73+
field(),
74+
t -> isSpatial(t) == false && isRepresentable(t),
75+
sourceText(),
76+
null,
77+
"boolean",
78+
"date",
79+
"ip",
80+
"string",
81+
"version",
82+
"numeric except counter types"
83+
);
7384
}
7485

7586
@Override

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/multivalue/MvMin.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,18 @@ public String getWriteableName() {
6969

7070
@Override
7171
protected TypeResolution resolveFieldType() {
72-
return isType(field(), t -> isSpatial(t) == false && isRepresentable(t), sourceText(), null, "representableNonSpatial");
72+
return isType(
73+
field(),
74+
t -> isSpatial(t) == false && isRepresentable(t),
75+
sourceText(),
76+
null,
77+
"boolean",
78+
"date",
79+
"ip",
80+
"string",
81+
"version",
82+
"numeric except counter types"
83+
);
7384
}
7485

7586
@Override

0 commit comments

Comments
 (0)