Skip to content

Commit 88ea6ed

Browse files
authored
ESQL: Exclude exponential_histogram from unsupported functions (elastic#138901)
1 parent 7fe1d31 commit 88ea6ed

File tree

32 files changed

+98
-88
lines changed

32 files changed

+98
-88
lines changed

x-pack/plugin/esql-core/src/main/java/org/elasticsearch/xpack/esql/core/expression/TypeResolutions.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import static org.elasticsearch.xpack.esql.core.type.DataType.BOOLEAN;
2323
import static org.elasticsearch.xpack.esql.core.type.DataType.DATETIME;
2424
import static org.elasticsearch.xpack.esql.core.type.DataType.DENSE_VECTOR;
25+
import static org.elasticsearch.xpack.esql.core.type.DataType.EXPONENTIAL_HISTOGRAM;
2526
import static org.elasticsearch.xpack.esql.core.type.DataType.IP;
2627
import static org.elasticsearch.xpack.esql.core.type.DataType.NULL;
2728
import static org.elasticsearch.xpack.esql.core.type.DataType.isRepresentable;
@@ -79,31 +80,35 @@ public static TypeResolution isDate(Expression e, String operationName, ParamOrd
7980
/**
8081
* @see DataType#isRepresentable(DataType)
8182
*/
82-
public static TypeResolution isRepresentableExceptCountersDenseVectorAndAggregateMetricDouble(
83+
public static TypeResolution isRepresentableExceptCountersDenseVectorAggregateMetricDoubleAndExponentialHistogram(
8384
Expression e,
8485
String operationName,
8586
ParamOrdinal paramOrd
8687
) {
8788
return isType(
8889
e,
89-
dt -> isRepresentable(dt) && dt != DENSE_VECTOR && dt != AGGREGATE_METRIC_DOUBLE,
90+
dt -> isRepresentable(dt) && dt != DENSE_VECTOR && dt != AGGREGATE_METRIC_DOUBLE && dt != EXPONENTIAL_HISTOGRAM,
9091
operationName,
9192
paramOrd,
92-
"any type except counter types, dense_vector, or aggregate_metric_double"
93+
"any type except counter types, dense_vector, aggregate_metric_double or exponential_histogram"
9394
);
9495
}
9596

96-
public static TypeResolution isRepresentableExceptCountersSpatialDenseVectorAndAggregateMetricDouble(
97+
public static TypeResolution isRepresentableExceptCountersSpatialDenseVectorAggregateMetricDoubleAndExponentialHistogram(
9798
Expression e,
9899
String operationName,
99100
ParamOrdinal paramOrd
100101
) {
101102
return isType(
102103
e,
103-
(t) -> isSpatialOrGrid(t) == false && DataType.isRepresentable(t) && t != DENSE_VECTOR && t != AGGREGATE_METRIC_DOUBLE,
104+
(t) -> isSpatialOrGrid(t) == false
105+
&& DataType.isRepresentable(t)
106+
&& t != DENSE_VECTOR
107+
&& t != AGGREGATE_METRIC_DOUBLE
108+
&& t != EXPONENTIAL_HISTOGRAM,
104109
operationName,
105110
paramOrd,
106-
"any type except counter, spatial types, dense_vector, or aggregate_metric_double"
111+
"any type except counter, spatial types, dense_vector, aggregate_metric_double or exponential_histogram"
107112
);
108113
}
109114

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

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,13 @@
1414
import org.elasticsearch.xpack.esql.core.tree.NodeInfo;
1515
import org.elasticsearch.xpack.esql.core.tree.Source;
1616
import org.elasticsearch.xpack.esql.core.type.DataType;
17-
import org.elasticsearch.xpack.esql.expression.SurrogateExpression;
1817
import org.elasticsearch.xpack.esql.expression.function.Example;
1918
import org.elasticsearch.xpack.esql.expression.function.FunctionAppliesTo;
2019
import org.elasticsearch.xpack.esql.expression.function.FunctionAppliesToLifecycle;
2120
import org.elasticsearch.xpack.esql.expression.function.FunctionInfo;
2221
import org.elasticsearch.xpack.esql.expression.function.FunctionType;
2322
import org.elasticsearch.xpack.esql.expression.function.OptionalArgument;
2423
import org.elasticsearch.xpack.esql.expression.function.Param;
25-
import org.elasticsearch.xpack.esql.expression.predicate.operator.arithmetic.Div;
2624

2725
import java.io.IOException;
2826
import java.util.List;
@@ -33,7 +31,7 @@
3331
/**
3432
* Similar to {@link Avg}, but it is used to calculate the average value over a time series of values from the given field.
3533
*/
36-
public class AvgOverTime extends TimeSeriesAggregateFunction implements OptionalArgument, SurrogateExpression {
34+
public class AvgOverTime extends TimeSeriesAggregateFunction implements OptionalArgument {
3735
public static final NamedWriteableRegistry.Entry ENTRY = new NamedWriteableRegistry.Entry(
3836
Expression.class,
3937
"AvgOverTime",
@@ -103,13 +101,6 @@ public AvgOverTime withFilter(Expression filter) {
103101
return new AvgOverTime(source(), field(), filter, window());
104102
}
105103

106-
@Override
107-
public Expression surrogate() {
108-
Source s = source();
109-
Expression f = field();
110-
return new Div(s, new SumOverTime(s, f, filter(), window()), new CountOverTime(s, f, filter(), window()), dataType());
111-
}
112-
113104
@Override
114105
public AggregateFunction perTimeSeriesAggregation() {
115106
return new Avg(source(), field(), filter(), window(), SummationMode.LOSSY_LITERAL);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,10 @@ public Nullability nullable() {
146146
protected TypeResolution resolveType() {
147147
return isType(
148148
field(),
149-
dt -> dt.isCounter() == false && dt != DataType.DENSE_VECTOR,
149+
dt -> dt.isCounter() == false && dt != DataType.DENSE_VECTOR && dt != DataType.EXPONENTIAL_HISTOGRAM,
150150
sourceText(),
151151
DEFAULT,
152-
"any type except counter types or dense_vector"
152+
"any type except counter types, dense_vector or exponential_histogram"
153153
);
154154
}
155155

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

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,7 @@ public class Max extends AggregateFunction implements ToAggregator, SurrogateExp
6161
);
6262

6363
@FunctionInfo(
64-
returnType = {
65-
"boolean",
66-
"double",
67-
"integer",
68-
"long",
69-
"date",
70-
"date_nanos",
71-
"ip",
72-
"keyword",
73-
"unsigned_long",
74-
"version",
75-
"exponential_histogram" },
64+
returnType = { "boolean", "double", "integer", "long", "date", "date_nanos", "ip", "keyword", "unsigned_long", "version" },
7665
description = "The maximum value of a field.",
7766
type = FunctionType.AGGREGATE,
7867
examples = {

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.ParamOrdinal.FIRST;
4141
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.ParamOrdinal.SECOND;
4242
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.isNotNull;
43-
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.isRepresentableExceptCountersDenseVectorAndAggregateMetricDouble;
43+
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.isRepresentableExceptCountersDenseVectorAggregateMetricDoubleAndExponentialHistogram;
4444
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.isType;
4545
import static org.elasticsearch.xpack.esql.expression.Foldables.TypeResolutionValidator.forPostOptimizationValidation;
4646
import static org.elasticsearch.xpack.esql.expression.Foldables.TypeResolutionValidator.forPreOptimizationValidation;
@@ -122,9 +122,12 @@ protected TypeResolution resolveType() {
122122
if (childrenResolved() == false) {
123123
return new TypeResolution("Unresolved children");
124124
}
125-
var typeResolution = isRepresentableExceptCountersDenseVectorAndAggregateMetricDouble(field(), sourceText(), FIRST).and(
126-
isNotNull(limitField(), sourceText(), SECOND)
127-
).and(isType(limitField(), dt -> dt == DataType.INTEGER, sourceText(), SECOND, "integer"));
125+
var typeResolution = isRepresentableExceptCountersDenseVectorAggregateMetricDoubleAndExponentialHistogram(
126+
field(),
127+
sourceText(),
128+
FIRST
129+
).and(isNotNull(limitField(), sourceText(), SECOND))
130+
.and(isType(limitField(), dt -> dt == DataType.INTEGER, sourceText(), SECOND, "integer"));
128131
if (typeResolution.unresolved()) {
129132
return typeResolution;
130133
}

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,11 @@ public DataType dataType() {
165165

166166
@Override
167167
protected TypeResolution resolveType() {
168-
return TypeResolutions.isRepresentableExceptCountersDenseVectorAndAggregateMetricDouble(field(), sourceText(), DEFAULT);
168+
return TypeResolutions.isRepresentableExceptCountersDenseVectorAggregateMetricDoubleAndExponentialHistogram(
169+
field(),
170+
sourceText(),
171+
DEFAULT
172+
);
169173
}
170174

171175
@Override

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@ public PackDimension(Source source, Expression field) {
4141

4242
@Override
4343
protected TypeResolution resolveType() {
44-
return TypeResolutions.isRepresentableExceptCountersDenseVectorAndAggregateMetricDouble(field(), sourceText(), DEFAULT);
44+
return TypeResolutions.isRepresentableExceptCountersDenseVectorAggregateMetricDoubleAndExponentialHistogram(
45+
field(),
46+
sourceText(),
47+
DEFAULT
48+
);
4549
}
4650

4751
@Override

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040

4141
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.ParamOrdinal.FIRST;
4242
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.ParamOrdinal.SECOND;
43-
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.isRepresentableExceptCountersDenseVectorAndAggregateMetricDouble;
43+
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.isRepresentableExceptCountersDenseVectorAggregateMetricDoubleAndExponentialHistogram;
4444
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.isType;
4545

4646
/**
@@ -148,14 +148,18 @@ protected TypeResolution resolveType() {
148148
return new TypeResolution("Unresolved children");
149149
}
150150

151-
TypeResolution resolution = isRepresentableExceptCountersDenseVectorAndAggregateMetricDouble(field1, sourceText(), FIRST);
151+
TypeResolution resolution = isRepresentableExceptCountersDenseVectorAggregateMetricDoubleAndExponentialHistogram(
152+
field1,
153+
sourceText(),
154+
FIRST
155+
);
152156
if (resolution.unresolved()) {
153157
return resolution;
154158
}
155159
dataType = field1.dataType().noText();
156160
if (dataType == DataType.NULL) {
157161
dataType = field2.dataType().noText();
158-
return isRepresentableExceptCountersDenseVectorAndAggregateMetricDouble(field2, sourceText(), SECOND);
162+
return isRepresentableExceptCountersDenseVectorAggregateMetricDoubleAndExponentialHistogram(field2, sourceText(), SECOND);
159163
}
160164
return isType(field2, t -> t.noText() == dataType, sourceText(), SECOND, dataType.typeName());
161165
}

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141

4242
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.ParamOrdinal.FIRST;
4343
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.ParamOrdinal.SECOND;
44-
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.isRepresentableExceptCountersDenseVectorAndAggregateMetricDouble;
44+
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.isRepresentableExceptCountersDenseVectorAggregateMetricDoubleAndExponentialHistogram;
4545
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.isType;
4646

4747
/**
@@ -146,12 +146,16 @@ protected TypeResolution resolveType() {
146146
return new TypeResolution("Unresolved children");
147147
}
148148

149-
TypeResolution resolution = isRepresentableExceptCountersDenseVectorAndAggregateMetricDouble(left(), sourceText(), FIRST);
149+
TypeResolution resolution = isRepresentableExceptCountersDenseVectorAggregateMetricDoubleAndExponentialHistogram(
150+
left(),
151+
sourceText(),
152+
FIRST
153+
);
150154
if (resolution.unresolved()) {
151155
return resolution;
152156
}
153157
if (left().dataType() == DataType.NULL) {
154-
return isRepresentableExceptCountersDenseVectorAndAggregateMetricDouble(right(), sourceText(), SECOND);
158+
return isRepresentableExceptCountersDenseVectorAggregateMetricDoubleAndExponentialHistogram(right(), sourceText(), SECOND);
155159
}
156160
return isType(right(), t -> t.noText() == left().dataType().noText(), sourceText(), SECOND, left().dataType().noText().typeName());
157161
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import java.util.List;
2727

2828
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.ParamOrdinal.DEFAULT;
29-
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.isRepresentableExceptCountersDenseVectorAndAggregateMetricDouble;
29+
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.isRepresentableExceptCountersDenseVectorAggregateMetricDoubleAndExponentialHistogram;
3030

3131
/**
3232
* Reduce a multivalued field to a single valued field containing the count of values.
@@ -79,7 +79,7 @@ public String getWriteableName() {
7979

8080
@Override
8181
protected TypeResolution resolveFieldType() {
82-
return isRepresentableExceptCountersDenseVectorAndAggregateMetricDouble(field(), sourceText(), DEFAULT);
82+
return isRepresentableExceptCountersDenseVectorAggregateMetricDoubleAndExponentialHistogram(field(), sourceText(), DEFAULT);
8383
}
8484

8585
@Override

0 commit comments

Comments
 (0)