-
Notifications
You must be signed in to change notification settings - Fork 25.8k
ESQL: AVG aggregation tests and ignore complex surrogates #110579
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
de249a6
cc71f76
04f6327
031988d
88e510e
435eab2
31241e2
8258564
7423f8f
e4f8b89
3b1291b
40f480f
81f059b
63e6d6d
e1c1426
80cc03b
8be98ed
a1d2437
7cd74fb
36804bc
8252962
7d52560
0153061
995276e
dbe3435
18b2be9
5392e92
d3fff55
289a827
12b4908
4749b41
e014d20
e85e657
3c65007
c48b393
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
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 |
|---|---|---|
|
|
@@ -15,6 +15,8 @@ | |
| import org.elasticsearch.compute.data.Page; | ||
| import org.elasticsearch.core.Releasables; | ||
| import org.elasticsearch.xpack.esql.core.expression.Expression; | ||
| import org.elasticsearch.xpack.esql.core.expression.FieldAttribute; | ||
| import org.elasticsearch.xpack.esql.core.expression.Literal; | ||
| import org.elasticsearch.xpack.esql.core.type.DataType; | ||
| import org.elasticsearch.xpack.esql.core.util.NumericUtils; | ||
| import org.elasticsearch.xpack.esql.expression.SurrogateExpression; | ||
|
|
@@ -251,6 +253,13 @@ private void resolveExpression(Expression expression, Consumer<Expression> onAgg | |
| expression = new FoldNull().rule(expression); | ||
| assertThat(expression.dataType(), equalTo(testCase.expectedType())); | ||
|
|
||
| assumeTrue( | ||
| "Surrogate expression with non-trivial children cannot be evaluated", | ||
| expression.children() | ||
| .stream() | ||
| .allMatch(child -> child instanceof FieldAttribute || child instanceof DeepCopy || child instanceof Literal) | ||
| ); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is the right thing to do for now because it doesn't block the rest of the aggs. It's really a shame most of the tests for AVG don't pick up, but that's life sometimes. We'll get there. |
||
|
|
||
| if (expression instanceof AggregateFunction == false) { | ||
| onEvaluableExpression.accept(expression); | ||
| return; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| /* | ||
| * 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 com.carrotsearch.randomizedtesting.annotations.Name; | ||
| import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; | ||
|
|
||
| import org.elasticsearch.xpack.esql.core.expression.Expression; | ||
| import org.elasticsearch.xpack.esql.core.tree.Source; | ||
| import org.elasticsearch.xpack.esql.core.type.DataType; | ||
| import org.elasticsearch.xpack.esql.expression.function.AbstractAggregationTestCase; | ||
| import org.elasticsearch.xpack.esql.expression.function.MultiRowTestCaseSupplier; | ||
| import org.elasticsearch.xpack.esql.expression.function.TestCaseSupplier; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.function.Supplier; | ||
| import java.util.stream.Collectors; | ||
| import java.util.stream.Stream; | ||
|
|
||
| import static org.hamcrest.Matchers.equalTo; | ||
|
|
||
| public class AvgTests extends AbstractAggregationTestCase { | ||
| public AvgTests(@Name("TestCase") Supplier<TestCaseSupplier.TestCase> testCaseSupplier) { | ||
| this.testCase = testCaseSupplier.get(); | ||
| } | ||
|
|
||
| @ParametersFactory | ||
| public static Iterable<Object[]> parameters() { | ||
| var suppliers = new ArrayList<TestCaseSupplier>(); | ||
|
|
||
| Stream.of( | ||
| MultiRowTestCaseSupplier.intCases(1, 1000, Integer.MIN_VALUE, Integer.MAX_VALUE, true), | ||
| MultiRowTestCaseSupplier.longCases(1, 1000, Long.MIN_VALUE, Long.MAX_VALUE, true), | ||
| MultiRowTestCaseSupplier.doubleCases(1, 1000, -Double.MAX_VALUE, Double.MAX_VALUE, true) | ||
| ).flatMap(List::stream).map(AvgTests::makeSupplier).collect(Collectors.toCollection(() -> suppliers)); | ||
|
|
||
| suppliers.add( | ||
| // Folding | ||
| new TestCaseSupplier( | ||
| List.of(DataType.INTEGER), | ||
| () -> new TestCaseSupplier.TestCase( | ||
| List.of(TestCaseSupplier.TypedData.multiRow(List.of(200), DataType.INTEGER, "field")), | ||
| "Avg[field=Attribute[channel=0]]", | ||
| DataType.DOUBLE, | ||
| equalTo(200.) | ||
| ) | ||
| ) | ||
| ); | ||
|
|
||
| return parameterSuppliersFromTypedDataWithDefaultChecks(suppliers); | ||
| } | ||
|
|
||
| @Override | ||
| protected Expression build(Source source, List<Expression> args) { | ||
| return new Avg(source, args.get(0)); | ||
| } | ||
|
|
||
| private static TestCaseSupplier makeSupplier(TestCaseSupplier.TypedDataSupplier fieldSupplier) { | ||
| return new TestCaseSupplier(List.of(fieldSupplier.type()), () -> { | ||
| var fieldTypedData = fieldSupplier.get(); | ||
|
|
||
| Object expected = switch (fieldTypedData.type().widenSmallNumeric()) { | ||
| case INTEGER -> fieldTypedData.multiRowData() | ||
| .stream() | ||
| .map(v -> (Integer) v) | ||
| .collect(Collectors.summarizingInt(Integer::intValue)) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've found that sometimes we don't line up with these fancy methods in
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As this works with doubles, I guess the worst that could happen is we comparing doubles with an error margin (Which I think was commented already somewhere?). If some test fails because of that, we can use it as an example and do it
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
| .getAverage(); | ||
| case LONG -> fieldTypedData.multiRowData() | ||
| .stream() | ||
| .map(v -> (Long) v) | ||
| .collect(Collectors.summarizingLong(Long::longValue)) | ||
| .getAverage(); | ||
| case DOUBLE -> fieldTypedData.multiRowData() | ||
| .stream() | ||
| .map(v -> (Double) v) | ||
| .collect(Collectors.summarizingDouble(Double::doubleValue)) | ||
| .getAverage(); | ||
| default -> throw new IllegalStateException("Unexpected value: " + fieldTypedData.type()); | ||
| }; | ||
|
|
||
| return new TestCaseSupplier.TestCase( | ||
| List.of(fieldTypedData), | ||
| "Avg[field=Attribute[channel=0]]", | ||
| DataType.DOUBLE, | ||
| equalTo(expected) | ||
| ); | ||
| }); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added the existing examples here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍