Skip to content
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

Fix AvgTests error on -0.0 avg #113272

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
3 changes: 0 additions & 3 deletions muted-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,6 @@ tests:
- class: org.elasticsearch.index.mapper.FloatRangeFieldMapperTests
method: testSyntheticSourceKeepArrays
issue: https://github.com/elastic/elasticsearch/issues/113220
- class: org.elasticsearch.xpack.esql.expression.function.aggregate.AvgTests
method: "testFold {TestCase=<double> #2}"
issue: https://github.com/elastic/elasticsearch/issues/113225
- class: org.elasticsearch.index.mapper.DoubleRangeFieldMapperTests
method: testSyntheticSourceKeepAll
issue: https://github.com/elastic/elasticsearch/issues/113234
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,25 +64,26 @@ protected Expression build(Source source, List<Expression> args) {
private static TestCaseSupplier makeSupplier(TestCaseSupplier.TypedDataSupplier fieldSupplier) {
return new TestCaseSupplier(List.of(fieldSupplier.type()), () -> {
var fieldTypedData = fieldSupplier.get();
var fieldData = fieldTypedData.multiRowData();

Object expected = switch (fieldTypedData.type().widenSmallNumeric()) {
case INTEGER -> fieldTypedData.multiRowData()
.stream()
.map(v -> (Integer) v)
.collect(Collectors.summarizingInt(Integer::intValue))
.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());
};
Object expected = null;

if (fieldData.size() == 1) {
expected = fieldData.get(0);
} else if (fieldData.size() > 1) {
expected = switch (fieldTypedData.type().widenSmallNumeric()) {
case INTEGER -> fieldData.stream()
.map(v -> (Integer) v)
.collect(Collectors.summarizingInt(Integer::intValue))
.getAverage();
case LONG -> fieldData.stream().map(v -> (Long) v).collect(Collectors.summarizingLong(Long::longValue)).getAverage();
case DOUBLE -> fieldData.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),
Expand Down