Skip to content
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/changelog/131775.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 131775
summary: Replace "representable" type error messages
area: ES|QL
type: enhancement
issues: []

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import static org.elasticsearch.xpack.esql.core.type.DataType.DATETIME;
import static org.elasticsearch.xpack.esql.core.type.DataType.IP;
import static org.elasticsearch.xpack.esql.core.type.DataType.NULL;
import static org.elasticsearch.xpack.esql.core.type.DataType.isSpatial;

public final class TypeResolutions {

Expand Down Expand Up @@ -71,6 +72,23 @@ public static TypeResolution isDate(Expression e, String operationName, ParamOrd
return isType(e, dt -> dt == DATETIME, operationName, paramOrd, "datetime");
}

/**
* @see DataType#isRepresentable(DataType)
*/
public static TypeResolution isRepresentableExceptCounters(Expression e, String operationName, ParamOrdinal paramOrd) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some helpers to centralize the logic and messages here

return isType(e, DataType::isRepresentable, operationName, paramOrd, "any type except counter types");
}

public static TypeResolution isRepresentableExceptCountersAndSpatial(Expression e, String operationName, ParamOrdinal paramOrd) {
return isType(
e,
(t) -> isSpatial(t) == false && DataType.isRepresentable(t),
operationName,
paramOrd,
"any type except counter and spatial types"
);
}

public static TypeResolution isExact(Expression e, String message) {
if (e instanceof FieldAttribute fa) {
EsField.Exact exact = fa.getExactInfo();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,20 @@ sample_boolean:boolean | sample_datetime:datetime
[false, true, true] | [1985-11-21T00:00:00.000Z, 1986-06-26T00:00:00.000Z, 1986-08-28T00:00:00.000Z] | [1.83, 2.03, 2.08] | [10001, 10002, 10003] | [Bezalel, Georgi, Parto] | [2, 4, 5]
;

sample unsigned_long
required_capability: agg_values_sample_unsigned_long

FROM ul_logs
| STATS v = MV_SLICE(MV_SORT(SAMPLE(bytes_in, 99)), 3, 5)
| MV_EXPAND v
;

v:ul
0
74330435873664882
154551962150890561
;


multivalued
required_capability: agg_sample
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,3 +194,14 @@ s:double | bytes_in:ul | bytes_out:ul
1.0 | 1957665857956635540 | 352442273299370793
1.0 | 2408213296071189837 | 419872666232023984
;

values
required_capability: agg_values_sample_unsigned_long
from ul_logs | stats v = values(bytes_in) | MV_EXPAND v | SORT v | LIMIT 3;

v:ul
0
74330435873664882
154551962150890561
;

Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ public enum Cap {
*/
AGG_MAX_MIN_UNSIGNED_LONG,

/**
* Accept unsigned longs on VALUES and SAMPLE aggregations.
*/
AGG_VALUES_SAMPLE_UNSIGNED_LONG,

/**
* Does ESQL support async queries.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,12 @@ public Count(
"aggregate_metric_double",
"boolean",
"cartesian_point",
"cartesian_shape",
"date",
"date_nanos",
"double",
"geo_point",
"geo_shape",
Comment on lines +80 to +85
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing types for the docs

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh. I thought the tests would catch that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly. We check that every type in tests appears there, but if it isn't tested, we do nothing. And Count didn't have "error types" tests to check that we tested all the types

"integer",
"ip",
"keyword",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,12 @@ public CountOverTime(
"aggregate_metric_double",
"boolean",
"cartesian_point",
"cartesian_shape",
"date",
"date_nanos",
"double",
"geo_point",
"geo_shape",
"integer",
"ip",
"keyword",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.ParamOrdinal.FIRST;
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.ParamOrdinal.SECOND;
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.isNotNullAndFoldable;
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.isRepresentableExceptCounters;
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.isType;

public class Sample extends AggregateFunction implements ToAggregator {
Expand All @@ -56,6 +57,7 @@ public class Sample extends AggregateFunction implements ToAggregator {
"ip",
"keyword",
"long",
"unsigned_long",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This trivially allowed unsigned longs, so just allowed it

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mostly copied this from Values, assuming that was correct

"version" },
description = "Collects sample values for a field.",
type = FunctionType.AGGREGATE,
Expand All @@ -78,6 +80,7 @@ public Sample(
"ip",
"keyword",
"long",
"unsigned_long",
"text",
"version" },
description = "The field to collect sample values for."
Expand Down Expand Up @@ -109,7 +112,7 @@ protected TypeResolution resolveType() {
if (childrenResolved() == false) {
return new TypeResolution("Unresolved children");
}
var typeResolution = isType(field(), dt -> dt != DataType.UNSIGNED_LONG, sourceText(), FIRST, "any type except unsigned_long").and(
var typeResolution = isRepresentableExceptCounters(field(), sourceText(), FIRST).and(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was technically allowing counters before, but I'm not sure we actually wanted it (?)

Also, it allowed things like date period, which led to illegal data type [date_period] 500 errors

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

isNotNullAndFoldable(limitField(), sourceText(), SECOND)
).and(isType(limitField(), dt -> dt == DataType.INTEGER, sourceText(), SECOND, "integer"));
if (typeResolution.unresolved()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class Values extends AggregateFunction implements ToAggregator {
private static final Map<DataType, Supplier<AggregatorFunctionSupplier>> SUPPLIERS = Map.ofEntries(
Map.entry(DataType.INTEGER, ValuesIntAggregatorFunctionSupplier::new),
Map.entry(DataType.LONG, ValuesLongAggregatorFunctionSupplier::new),
Map.entry(DataType.UNSIGNED_LONG, ValuesLongAggregatorFunctionSupplier::new),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This trivially allowed unsigned longs, so just allowed it

Map.entry(DataType.DATETIME, ValuesLongAggregatorFunctionSupplier::new),
Map.entry(DataType.DATE_NANOS, ValuesLongAggregatorFunctionSupplier::new),
Map.entry(DataType.DOUBLE, ValuesDoubleAggregatorFunctionSupplier::new),
Expand Down Expand Up @@ -72,6 +73,7 @@ public class Values extends AggregateFunction implements ToAggregator {
"ip",
"keyword",
"long",
"unsigned_long",
"version" },
preview = true,
appliesTo = { @FunctionAppliesTo(lifeCycle = FunctionAppliesToLifecycle.PREVIEW) },
Expand Down Expand Up @@ -111,6 +113,7 @@ public Values(
"ip",
"keyword",
"long",
"unsigned_long",
"text",
"version" }
) Expression v
Expand Down Expand Up @@ -153,7 +156,7 @@ public DataType dataType() {

@Override
protected TypeResolution resolveType() {
return TypeResolutions.isType(field(), SUPPLIERS::containsKey, sourceText(), DEFAULT, "any type except unsigned_long");
return TypeResolutions.isRepresentableExceptCounters(field(), sourceText(), DEFAULT);
}

@Override
Expand Down
Loading
Loading