diff --git a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/aggregate/First.java b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/aggregate/First.java index 95ca792634ed9..a5b457d6e1f1e 100644 --- a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/aggregate/First.java +++ b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/aggregate/First.java @@ -91,6 +91,10 @@ public First withFilter(Expression filter) { return new First(source(), field(), filter, sort); } + public Expression sort() { + return sort; + } + @Override public DataType dataType() { return field().dataType(); diff --git a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/aggregate/Last.java b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/aggregate/Last.java index d775ed089714e..fa2bfdf1aaecf 100644 --- a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/aggregate/Last.java +++ b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/aggregate/Last.java @@ -91,6 +91,10 @@ public Last withFilter(Expression filter) { return new Last(source(), field(), filter, sort); } + public Expression sort() { + return sort; + } + @Override public DataType dataType() { return field().dataType(); diff --git a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/AbstractAggregationTestCase.java b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/AbstractAggregationTestCase.java index 5fff84f0cf021..4cd74ce80e42f 100644 --- a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/AbstractAggregationTestCase.java +++ b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/AbstractAggregationTestCase.java @@ -506,41 +506,46 @@ private void processPageGrouping(GroupingAggregator aggregator, Page inputPage, } private void assertAggregatorToString(Object aggregator) { - if (optIntoToAggregatorToStringChecks() == false) { - return; - } String expectedStart = switch (aggregator) { case Aggregator a -> "Aggregator[aggregatorFunction="; case GroupingAggregator a -> "GroupingAggregator[aggregatorFunction="; default -> throw new UnsupportedOperationException("can't check toString for [" + aggregator.getClass() + "]"); }; + String channels = initialInputChannels().stream().map(Object::toString).collect(Collectors.joining(", ")); String expectedEnd = switch (aggregator) { - case Aggregator a -> "AggregatorFunction[channels=[0]], mode=SINGLE]"; - case GroupingAggregator a -> "GroupingAggregatorFunction[channels=[0]], mode=SINGLE]"; + case Aggregator a -> "AggregatorFunction[channels=[" + channels + "]], mode=SINGLE]"; + case GroupingAggregator a -> "GroupingAggregatorFunction[channels=[" + channels + "]], mode=SINGLE]"; default -> throw new UnsupportedOperationException("can't check toString for [" + aggregator.getClass() + "]"); }; String toString = aggregator.toString(); assertThat(toString, startsWith(expectedStart)); - assertThat(toString.substring(expectedStart.length(), toString.length() - expectedEnd.length()), testCase.evaluatorToString()); assertThat(toString, endsWith(expectedEnd)); - } - - protected boolean optIntoToAggregatorToStringChecks() { - // TODO remove this when everyone has opted in - return false; + assertThat(toString.substring(expectedStart.length(), toString.length() - expectedEnd.length()), testCase.evaluatorToString()); } protected static String standardAggregatorName(String prefix, DataType type) { String typeName = switch (type) { case BOOLEAN -> "Boolean"; + case CARTESIAN_POINT -> "CartesianPoint"; + case CARTESIAN_SHAPE -> "CartesianShape"; + case GEO_POINT -> "GeoPoint"; + case GEO_SHAPE -> "GeoShape"; case KEYWORD, TEXT, VERSION -> "BytesRef"; - case DOUBLE -> "Double"; - case INTEGER -> "Int"; + case DOUBLE, COUNTER_DOUBLE -> "Double"; + case INTEGER, COUNTER_INTEGER -> "Int"; case IP -> "Ip"; - case DATETIME, DATE_NANOS, LONG, UNSIGNED_LONG -> "Long"; + case DATETIME, DATE_NANOS, LONG, COUNTER_LONG, UNSIGNED_LONG -> "Long"; + case NULL -> "Null"; default -> throw new UnsupportedOperationException("name for [" + type + "]"); }; return prefix + typeName; } + + protected static String standardAggregatorNameAllBytesTheSame(String prefix, DataType type) { + return standardAggregatorName(prefix, switch (type) { + case CARTESIAN_POINT, CARTESIAN_SHAPE, GEO_POINT, GEO_SHAPE, IP -> DataType.KEYWORD; + default -> type; + }); + } } diff --git a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/CountDistinctTests.java b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/CountDistinctTests.java index 33319f158daea..530591dc40d0d 100644 --- a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/CountDistinctTests.java +++ b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/CountDistinctTests.java @@ -127,7 +127,7 @@ private static TestCaseSupplier makeSupplier( return new TestCaseSupplier.TestCase( List.of(fieldTypedData, precisionTypedData), - "CountDistinct[field=Attribute[channel=0],precision=Attribute[channel=1]]", + standardAggregatorNameAllBytesTheSame("CountDistinct", fieldTypedData.type()), DataType.LONG, equalTo(result) ); @@ -149,7 +149,7 @@ private static TestCaseSupplier makeSupplier(TestCaseSupplier.TypedDataSupplier return new TestCaseSupplier.TestCase( List.of(fieldTypedData), - "CountDistinct[field=Attribute[channel=0]]", + standardAggregatorNameAllBytesTheSame("CountDistinct", fieldTypedData.type()), DataType.LONG, equalTo(result) ); diff --git a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/CountTests.java b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/CountTests.java index 863a8cc5f255b..db34c5777b63f 100644 --- a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/CountTests.java +++ b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/CountTests.java @@ -78,7 +78,7 @@ public static Iterable parameters() { List.of(dataType), () -> new TestCaseSupplier.TestCase( List.of(TestCaseSupplier.TypedData.multiRow(List.of(), dataType, "field")), - "Count[field=Attribute[channel=0]]", + "Count", DataType.LONG, equalTo(0L) ) @@ -100,12 +100,7 @@ private static TestCaseSupplier makeSupplier(TestCaseSupplier.TypedDataSupplier var fieldTypedData = fieldSupplier.get(); var rowCount = fieldTypedData.multiRowData().stream().filter(Objects::nonNull).count(); - return new TestCaseSupplier.TestCase( - List.of(fieldTypedData), - "Count[field=Attribute[channel=0]]", - DataType.LONG, - equalTo(rowCount) - ); + return new TestCaseSupplier.TestCase(List.of(fieldTypedData), "Count", DataType.LONG, equalTo(rowCount)); }); } } diff --git a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/FirstOverTimeTests.java b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/FirstOverTimeTests.java index 065f3fd35ebb1..49a50d697a4b6 100644 --- a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/FirstOverTimeTests.java +++ b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/FirstOverTimeTests.java @@ -85,7 +85,7 @@ private static TestCaseSupplier makeSupplier(TestCaseSupplier.TypedDataSupplier } return new TestCaseSupplier.TestCase( List.of(fieldTypedData, timestampsField), - "FirstOverTime[field=Attribute[channel=0],timestamp=Attribute[channel=1]]", + standardAggregatorName("First", fieldSupplier.type()) + "ByTimestamp", type, equalTo(expected) ); diff --git a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/FirstSerializationTests.java b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/FirstSerializationTests.java new file mode 100644 index 0000000000000..e4cc6ad5ebb9d --- /dev/null +++ b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/FirstSerializationTests.java @@ -0,0 +1,32 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +package org.elasticsearch.xpack.esql.expression.function.aggregate; + +import org.elasticsearch.xpack.esql.core.expression.Expression; +import org.elasticsearch.xpack.esql.expression.AbstractExpressionSerializationTests; + +import java.io.IOException; + +public class FirstSerializationTests extends AbstractExpressionSerializationTests { + @Override + protected First createTestInstance() { + return new First(randomSource(), randomChild(), randomChild()); + } + + @Override + protected First mutateInstance(First instance) throws IOException { + Expression field = instance.field(); + Expression sort = instance.sort(); + if (randomBoolean()) { + field = randomValueOtherThan(field, AbstractExpressionSerializationTests::randomChild); + } else { + sort = randomValueOtherThan(sort, AbstractExpressionSerializationTests::randomChild); + } + return new First(instance.source(), field, sort); + } +} diff --git a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/FirstTests.java b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/FirstTests.java index 1577ca2872b75..33ed1fa44b748 100644 --- a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/FirstTests.java +++ b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/FirstTests.java @@ -81,7 +81,7 @@ static TestCaseSupplier makeSupplier( } return new TestCaseSupplier.TestCase( List.of(values, sorts), - "unused", + standardAggregatorName(first ? "First" : "Last", values.type()) + "ByTimestamp", values.type(), anyOf(() -> Iterators.map(expected.iterator(), Matchers::equalTo)) ); diff --git a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/LastOverTimeTests.java b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/LastOverTimeTests.java index 0b2d2c8b53df6..0609346111a58 100644 --- a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/LastOverTimeTests.java +++ b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/LastOverTimeTests.java @@ -85,7 +85,7 @@ private static TestCaseSupplier makeSupplier(TestCaseSupplier.TypedDataSupplier } return new TestCaseSupplier.TestCase( List.of(fieldTypedData, timestampsField), - "LastOverTime[field=Attribute[channel=0],timestamp=Attribute[channel=1]]", + standardAggregatorName("Last", fieldSupplier.type()) + "ByTimestamp", type, equalTo(expected) ); diff --git a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/LastSerializationTests.java b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/LastSerializationTests.java new file mode 100644 index 0000000000000..81a68b6003a32 --- /dev/null +++ b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/LastSerializationTests.java @@ -0,0 +1,32 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +package org.elasticsearch.xpack.esql.expression.function.aggregate; + +import org.elasticsearch.xpack.esql.core.expression.Expression; +import org.elasticsearch.xpack.esql.expression.AbstractExpressionSerializationTests; + +import java.io.IOException; + +public class LastSerializationTests extends AbstractExpressionSerializationTests { + @Override + protected Last createTestInstance() { + return new Last(randomSource(), randomChild(), randomChild()); + } + + @Override + protected Last mutateInstance(Last instance) throws IOException { + Expression field = instance.field(); + Expression sort = instance.sort(); + if (randomBoolean()) { + field = randomValueOtherThan(field, AbstractExpressionSerializationTests::randomChild); + } else { + sort = randomValueOtherThan(sort, AbstractExpressionSerializationTests::randomChild); + } + return new Last(instance.source(), field, sort); + } +} diff --git a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/MaxTests.java b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/MaxTests.java index c5f69fb379fab..8df52dc3f433f 100644 --- a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/MaxTests.java +++ b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/MaxTests.java @@ -209,9 +209,4 @@ private static TestCaseSupplier makeSupplier(TestCaseSupplier.TypedDataSupplier ); }); } - - @Override - protected boolean optIntoToAggregatorToStringChecks() { - return true; - } } diff --git a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/MedianAbsoluteDeviationTests.java b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/MedianAbsoluteDeviationTests.java index 047e204c0e0c2..d283c7ab650dd 100644 --- a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/MedianAbsoluteDeviationTests.java +++ b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/MedianAbsoluteDeviationTests.java @@ -60,7 +60,7 @@ private static TestCaseSupplier makeSupplier(TestCaseSupplier.TypedDataSupplier return new TestCaseSupplier.TestCase( List.of(fieldTypedData), - "MedianAbsoluteDeviation[number=Attribute[channel=0]]", + standardAggregatorName("MedianAbsoluteDeviation", fieldSupplier.type()), DataType.DOUBLE, equalTo(expected) ); diff --git a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/MedianTests.java b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/MedianTests.java index 02a1d26932bab..64763d835cd83 100644 --- a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/MedianTests.java +++ b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/MedianTests.java @@ -101,9 +101,4 @@ private static TestCaseSupplier makeSupplier(TestCaseSupplier.TypedDataSupplier } }); } - - @Override - protected boolean optIntoToAggregatorToStringChecks() { - return true; - } } diff --git a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/MinTests.java b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/MinTests.java index 6e6e42f4b7f87..e52ab2ec325b2 100644 --- a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/MinTests.java +++ b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/MinTests.java @@ -209,9 +209,4 @@ private static TestCaseSupplier makeSupplier(TestCaseSupplier.TypedDataSupplier ); }); } - - @Override - protected boolean optIntoToAggregatorToStringChecks() { - return true; - } } diff --git a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/PercentileTests.java b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/PercentileTests.java index 0033f98222903..8b950a26890fa 100644 --- a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/PercentileTests.java +++ b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/PercentileTests.java @@ -80,7 +80,7 @@ private static TestCaseSupplier makeSupplier( return new TestCaseSupplier.TestCase( List.of(fieldTypedData, percentileTypedData), - "Percentile[number=Attribute[channel=0],percentile=Attribute[channel=1]]", + standardAggregatorName("Percentile", fieldSupplier.type()), DataType.DOUBLE, equalTo(expected) ); diff --git a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/RateTests.java b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/RateTests.java index 87dc4348adf74..ffea9bddb9907 100644 --- a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/RateTests.java +++ b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/RateTests.java @@ -120,7 +120,7 @@ private static TestCaseSupplier makeSupplier(TestCaseSupplier.TypedDataSupplier } return new TestCaseSupplier.TestCase( List.of(fieldTypedData, timestampsField), - "Rate[field=Attribute[channel=0],timestamp=Attribute[channel=1]]", + standardAggregatorName("Rate", fieldTypedData.type()), DataType.DOUBLE, matcher ); diff --git a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/SampleSerializationTests.java b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/SampleSerializationTests.java new file mode 100644 index 0000000000000..078557093a317 --- /dev/null +++ b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/SampleSerializationTests.java @@ -0,0 +1,36 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +package org.elasticsearch.xpack.esql.expression.function.aggregate; + +import org.elasticsearch.xpack.esql.core.expression.Expression; +import org.elasticsearch.xpack.esql.core.tree.Source; +import org.elasticsearch.xpack.esql.expression.AbstractExpressionSerializationTests; + +import java.io.IOException; + +public class SampleSerializationTests extends AbstractExpressionSerializationTests { + @Override + protected Sample createTestInstance() { + Source source = randomSource(); + Expression field = randomChild(); + Expression limit = randomChild(); + return new Sample(source, field, limit); + } + + @Override + protected Sample mutateInstance(Sample instance) throws IOException { + Source source = randomSource(); + Expression field = instance.field(); + Expression limit = instance.limitField(); + switch (between(0, 1)) { + case 0 -> field = randomValueOtherThan(field, AbstractExpressionSerializationTests::randomChild); + case 1 -> limit = randomValueOtherThan(limit, AbstractExpressionSerializationTests::randomChild); + } + return new Sample(source, field, limit); + } +} diff --git a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/SampleTests.java b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/SampleTests.java index 8b66da40ddb27..5c8e4948dec81 100644 --- a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/SampleTests.java +++ b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/SampleTests.java @@ -86,7 +86,7 @@ private static TestCaseSupplier makeSupplier( return new TestCaseSupplier.TestCase( List.of(fieldTypedData, limitTypedData), - "Sample[field=Attribute[channel=0], limit=Attribute[channel=1]]", + standardAggregatorNameAllBytesTheSame("Sample", fieldSupplier.type()), fieldSupplier.type(), subsetOfSize(rows, limit) ); diff --git a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/SpatialCentroidTests.java b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/SpatialCentroidTests.java index 25bb6e242cf8c..3c3cae6346cd5 100644 --- a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/SpatialCentroidTests.java +++ b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/SpatialCentroidTests.java @@ -86,7 +86,7 @@ private static TestCaseSupplier makeSupplier(TestCaseSupplier.TypedDataSupplier return new TestCaseSupplier.TestCase( List.of(fieldTypedData), - "SpatialCentroid[field=Attribute[channel=0]]", + standardAggregatorName("SpatialCentroid", fieldSupplier.type()) + "SourceValues", fieldTypedData.type(), centroidMatches(expectedX, expectedY, 1e-14) ); diff --git a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/SpatialExtentSerializationTests.java b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/SpatialExtentSerializationTests.java new file mode 100644 index 0000000000000..eacb95646651a --- /dev/null +++ b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/SpatialExtentSerializationTests.java @@ -0,0 +1,27 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +package org.elasticsearch.xpack.esql.expression.function.aggregate; + +import org.elasticsearch.xpack.esql.expression.AbstractExpressionSerializationTests; + +import java.io.IOException; + +public class SpatialExtentSerializationTests extends AbstractExpressionSerializationTests { + @Override + protected SpatialExtent createTestInstance() { + return new SpatialExtent(randomSource(), randomChild()); + } + + @Override + protected SpatialExtent mutateInstance(SpatialExtent instance) throws IOException { + return new SpatialExtent( + instance.source(), + randomValueOtherThan(instance.field(), AbstractExpressionSerializationTests::randomChild) + ); + } +} diff --git a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/SpatialExtentTests.java b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/SpatialExtentTests.java index a73a00741e3c5..fb0fd49c0c460 100644 --- a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/SpatialExtentTests.java +++ b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/SpatialExtentTests.java @@ -83,7 +83,7 @@ private static TestCaseSupplier makeSupplier(TestCaseSupplier.TypedDataSupplier Rectangle result = pointVisitor.getResult(); return new TestCaseSupplier.TestCase( List.of(fieldTypedData), - "SpatialExtent[field=Attribute[channel=0]]", + standardAggregatorName("SpatialExtent", fieldSupplier.type()) + "SourceValues", expectedType, new WellKnownBinaryBytesRefMatcher<>(RectangleMatcher.closeToFloat(result, 1e-3, pointType.encoder())) ); diff --git a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/StdDevSerializationTests.java b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/StdDevSerializationTests.java new file mode 100644 index 0000000000000..3dd7bbb321ccb --- /dev/null +++ b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/StdDevSerializationTests.java @@ -0,0 +1,24 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +package org.elasticsearch.xpack.esql.expression.function.aggregate; + +import org.elasticsearch.xpack.esql.expression.AbstractExpressionSerializationTests; + +import java.io.IOException; + +public class StdDevSerializationTests extends AbstractExpressionSerializationTests { + @Override + protected StdDev createTestInstance() { + return new StdDev(randomSource(), randomChild()); + } + + @Override + protected StdDev mutateInstance(StdDev instance) throws IOException { + return new StdDev(instance.source(), randomValueOtherThan(instance.field(), AbstractExpressionSerializationTests::randomChild)); + } +} diff --git a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/StdDevTests.java b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/StdDevTests.java index a429abf721739..d5ab15943ba98 100644 --- a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/StdDevTests.java +++ b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/StdDevTests.java @@ -64,7 +64,7 @@ private static TestCaseSupplier makeSupplier(TestCaseSupplier.TypedDataSupplier var expected = Double.isFinite(result) ? result : null; return new TestCaseSupplier.TestCase( List.of(fieldTypedData), - "StdDev[field=Attribute[channel=0]]", + standardAggregatorName("StdDev", fieldSupplier.type()), DataType.DOUBLE, equalTo(expected) ); diff --git a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/SumTests.java b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/SumTests.java index 6730c2591ebbf..0a50a6a88d6d3 100644 --- a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/SumTests.java +++ b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/SumTests.java @@ -51,7 +51,7 @@ public static Iterable parameters() { List.of(DataType.INTEGER), () -> new TestCaseSupplier.TestCase( List.of(TestCaseSupplier.TypedData.multiRow(List.of(200), DataType.INTEGER, "field")), - "Sum[field=Attribute[channel=0]]", + "SumInt", DataType.LONG, equalTo(200L) ) @@ -60,7 +60,7 @@ public static Iterable parameters() { List.of(DataType.LONG), () -> new TestCaseSupplier.TestCase( List.of(TestCaseSupplier.TypedData.multiRow(List.of(200L), DataType.LONG, "field")), - "Sum[field=Attribute[channel=0]]", + "SumLong", DataType.LONG, equalTo(200L) ) @@ -69,7 +69,7 @@ public static Iterable parameters() { List.of(DataType.DOUBLE), () -> new TestCaseSupplier.TestCase( List.of(TestCaseSupplier.TypedData.multiRow(List.of(200.), DataType.DOUBLE, "field")), - "Sum[field=Attribute[channel=0]]", + "SumDouble", DataType.DOUBLE, equalTo(200.) ) @@ -126,7 +126,12 @@ private static TestCaseSupplier makeSupplier(TestCaseSupplier.TypedDataSupplier ? DataType.DOUBLE : DataType.LONG; - return new TestCaseSupplier.TestCase(List.of(fieldTypedData), "Sum[field=Attribute[channel=0]]", dataType, equalTo(expected)); + return new TestCaseSupplier.TestCase( + List.of(fieldTypedData), + standardAggregatorName("Sum", fieldSupplier.type()), + dataType, + equalTo(expected) + ); }); } } diff --git a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/TopTests.java b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/TopTests.java index 7e10b3ac32c85..439bca401b72a 100644 --- a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/TopTests.java +++ b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/TopTests.java @@ -67,7 +67,7 @@ public static Iterable parameters() { new TestCaseSupplier.TypedData(1, DataType.INTEGER, "limit").forceLiteral(), new TestCaseSupplier.TypedData(new BytesRef("desc"), DataType.KEYWORD, "order").forceLiteral() ), - "Top[field=Attribute[channel=0], limit=Attribute[channel=1], order=Attribute[channel=2]]", + "MaxBoolean", DataType.BOOLEAN, equalTo(true) ) @@ -80,7 +80,7 @@ public static Iterable parameters() { new TestCaseSupplier.TypedData(1, DataType.INTEGER, "limit").forceLiteral(), new TestCaseSupplier.TypedData(new BytesRef("desc"), DataType.KEYWORD, "order").forceLiteral() ), - "Top[field=Attribute[channel=0], limit=Attribute[channel=1], order=Attribute[channel=2]]", + "MaxInt", DataType.INTEGER, equalTo(200) ) @@ -93,7 +93,7 @@ public static Iterable parameters() { new TestCaseSupplier.TypedData(1, DataType.INTEGER, "limit").forceLiteral(), new TestCaseSupplier.TypedData(new BytesRef("desc"), DataType.KEYWORD, "order").forceLiteral() ), - "Top[field=Attribute[channel=0], limit=Attribute[channel=1], order=Attribute[channel=2]]", + "MaxLong", DataType.LONG, equalTo(200L) ) @@ -106,7 +106,7 @@ public static Iterable parameters() { new TestCaseSupplier.TypedData(1, DataType.INTEGER, "limit").forceLiteral(), new TestCaseSupplier.TypedData(new BytesRef("desc"), DataType.KEYWORD, "order").forceLiteral() ), - "Top[field=Attribute[channel=0], limit=Attribute[channel=1], order=Attribute[channel=2]]", + "MaxDouble", DataType.DOUBLE, equalTo(200.) ) @@ -119,7 +119,7 @@ public static Iterable parameters() { new TestCaseSupplier.TypedData(1, DataType.INTEGER, "limit").forceLiteral(), new TestCaseSupplier.TypedData(new BytesRef("desc"), DataType.KEYWORD, "order").forceLiteral() ), - "Top[field=Attribute[channel=0], limit=Attribute[channel=1], order=Attribute[channel=2]]", + "MaxLong", DataType.DATETIME, equalTo(200L) ) @@ -141,7 +141,7 @@ public static Iterable parameters() { new TestCaseSupplier.TypedData(1, DataType.INTEGER, "limit").forceLiteral(), new TestCaseSupplier.TypedData(new BytesRef("desc"), DataType.KEYWORD, "order").forceLiteral() ), - "Top[field=Attribute[channel=0], limit=Attribute[channel=1], order=Attribute[channel=2]]", + "MaxIp", DataType.IP, equalTo(new BytesRef(InetAddressPoint.encode(InetAddresses.forString("ffff::")))) ) @@ -156,7 +156,7 @@ public static Iterable parameters() { new TestCaseSupplier.TypedData(1, DataType.INTEGER, "limit").forceLiteral(), new TestCaseSupplier.TypedData(new BytesRef("desc"), DataType.KEYWORD, "order").forceLiteral() ), - "Top[field=Attribute[channel=0], limit=Attribute[channel=1], order=Attribute[channel=2]]", + "MaxBoolean", DataType.BOOLEAN, equalTo(true) ) @@ -169,7 +169,7 @@ public static Iterable parameters() { new TestCaseSupplier.TypedData(1, DataType.INTEGER, "limit").forceLiteral(), new TestCaseSupplier.TypedData(new BytesRef("desc"), DataType.KEYWORD, "order").forceLiteral() ), - "Top[field=Attribute[channel=0], limit=Attribute[channel=1], order=Attribute[channel=2]]", + "MaxInt", DataType.INTEGER, equalTo(200) ) @@ -182,7 +182,7 @@ public static Iterable parameters() { new TestCaseSupplier.TypedData(1, DataType.INTEGER, "limit").forceLiteral(), new TestCaseSupplier.TypedData(new BytesRef("desc"), DataType.KEYWORD, "order").forceLiteral() ), - "Top[field=Attribute[channel=0], limit=Attribute[channel=1], order=Attribute[channel=2]]", + "MaxLong", DataType.LONG, equalTo(200L) ) @@ -195,7 +195,7 @@ public static Iterable parameters() { new TestCaseSupplier.TypedData(1, DataType.INTEGER, "limit").forceLiteral(), new TestCaseSupplier.TypedData(new BytesRef("desc"), DataType.KEYWORD, "order").forceLiteral() ), - "Top[field=Attribute[channel=0], limit=Attribute[channel=1], order=Attribute[channel=2]]", + "MaxDouble", DataType.DOUBLE, equalTo(200.) ) @@ -208,7 +208,7 @@ public static Iterable parameters() { new TestCaseSupplier.TypedData(1, DataType.INTEGER, "limit").forceLiteral(), new TestCaseSupplier.TypedData(new BytesRef("desc"), DataType.KEYWORD, "order").forceLiteral() ), - "Top[field=Attribute[channel=0], limit=Attribute[channel=1], order=Attribute[channel=2]]", + "MaxLong", DataType.DATETIME, equalTo(200L) ) @@ -225,7 +225,7 @@ public static Iterable parameters() { new TestCaseSupplier.TypedData(1, DataType.INTEGER, "limit").forceLiteral(), new TestCaseSupplier.TypedData(new BytesRef("desc"), DataType.KEYWORD, "order").forceLiteral() ), - "Top[field=Attribute[channel=0], limit=Attribute[channel=1], order=Attribute[channel=2]]", + "MaxIp", DataType.IP, equalTo(new BytesRef(InetAddressPoint.encode(InetAddresses.forString("127.0.0.1")))) ) @@ -310,7 +310,7 @@ private static TestCaseSupplier makeSupplier( limitTypedData, new TestCaseSupplier.TypedData(new BytesRef(order), DataType.KEYWORD, order + " order").forceLiteral() ), - "Top[field=Attribute[channel=0], limit=Attribute[channel=1], order=Attribute[channel=2]]", + standardAggregatorName("Top", fieldTypedData.type()), fieldSupplier.type(), equalTo(expected.size() == 1 ? expected.get(0) : expected) ); diff --git a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/ValuesTests.java b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/ValuesTests.java index f386f623e17dc..9639f25d8d883 100644 --- a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/ValuesTests.java +++ b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/ValuesTests.java @@ -76,7 +76,7 @@ private static TestCaseSupplier makeSupplier(TestCaseSupplier.TypedDataSupplier var expected = new HashSet<>(fieldTypedData.multiRowData()); return new TestCaseSupplier.TestCase( List.of(fieldTypedData), - "Values[field=Attribute[channel=0]]", + standardAggregatorNameAllBytesTheSame("Values", fieldSupplier.type()), fieldSupplier.type(), valuesInAnyOrder(expected) ); diff --git a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/WeightedAvgSerializationTests.java b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/WeightedAvgSerializationTests.java new file mode 100644 index 0000000000000..000d02fe342a3 --- /dev/null +++ b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/WeightedAvgSerializationTests.java @@ -0,0 +1,32 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +package org.elasticsearch.xpack.esql.expression.function.aggregate; + +import org.elasticsearch.xpack.esql.core.expression.Expression; +import org.elasticsearch.xpack.esql.expression.AbstractExpressionSerializationTests; + +import java.io.IOException; + +public class WeightedAvgSerializationTests extends AbstractExpressionSerializationTests { + @Override + protected WeightedAvg createTestInstance() { + return new WeightedAvg(randomSource(), randomChild(), randomChild()); + } + + @Override + protected WeightedAvg mutateInstance(WeightedAvg instance) throws IOException { + Expression field = instance.field(); + Expression weight = instance.weight(); + if (randomBoolean()) { + field = randomValueOtherThan(field, AbstractExpressionSerializationTests::randomChild); + } else { + weight = randomValueOtherThan(weight, AbstractExpressionSerializationTests::randomChild); + } + return new WeightedAvg(instance.source(), field, weight); + } +}