Skip to content

Commit

Permalink
Fix AvgTests error on -0.0 avg (elastic#113272)
Browse files Browse the repository at this point in the history
  • Loading branch information
ivancea authored Oct 22, 2024
1 parent f8e931d commit d65a030
Show file tree
Hide file tree
Showing 6 changed files with 276 additions and 360 deletions.
6 changes: 0 additions & 6 deletions muted-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,6 @@ tests:
- class: org.elasticsearch.packaging.test.WindowsServiceTests
method: test80JavaOptsInEnvVar
issue: https://github.com/elastic/elasticsearch/issues/113219
- 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.packaging.test.WindowsServiceTests
method: test81JavaOptsInJvmOptions
issue: https://github.com/elastic/elasticsearch/issues/113313
Expand Down Expand Up @@ -236,9 +233,6 @@ tests:
- class: org.elasticsearch.xpack.inference.InferenceCrudIT
method: testGet
issue: https://github.com/elastic/elasticsearch/issues/114135
- class: org.elasticsearch.xpack.esql.expression.function.aggregate.AvgTests
method: "testFold {TestCase=<double> #7}"
issue: https://github.com/elastic/elasticsearch/issues/114175
- class: org.elasticsearch.xpack.ilm.ExplainLifecycleIT
method: testStepInfoPreservedOnAutoRetry
issue: https://github.com/elastic/elasticsearch/issues/114220
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,15 +163,7 @@ private void aggregateSingleMode(Expression expression) {
result = extractResultFromAggregator(aggregator, PlannerUtils.toElementType(testCase.expectedType()));
}

assertThat(result, not(equalTo(Double.NaN)));
assert testCase.getMatcher().matches(Double.POSITIVE_INFINITY) == false;
assertThat(result, not(equalTo(Double.POSITIVE_INFINITY)));
assert testCase.getMatcher().matches(Double.NEGATIVE_INFINITY) == false;
assertThat(result, not(equalTo(Double.NEGATIVE_INFINITY)));
assertThat(result, testCase.getMatcher());
if (testCase.getExpectedWarnings() != null) {
assertWarnings(testCase.getExpectedWarnings());
}
assertTestCaseResultAndWarnings(result);
}

private void aggregateGroupingSingleMode(Expression expression) {
Expand Down Expand Up @@ -263,15 +255,7 @@ private void aggregateWithIntermediates(Expression expression) {
result = extractResultFromAggregator(aggregator, PlannerUtils.toElementType(testCase.expectedType()));
}

assertThat(result, not(equalTo(Double.NaN)));
assert testCase.getMatcher().matches(Double.POSITIVE_INFINITY) == false;
assertThat(result, not(equalTo(Double.POSITIVE_INFINITY)));
assert testCase.getMatcher().matches(Double.NEGATIVE_INFINITY) == false;
assertThat(result, not(equalTo(Double.NEGATIVE_INFINITY)));
assertThat(result, testCase.getMatcher());
if (testCase.getExpectedWarnings() != null) {
assertWarnings(testCase.getExpectedWarnings());
}
assertTestCaseResultAndWarnings(result);
}

private void evaluate(Expression evaluableExpression) {
Expand All @@ -288,15 +272,7 @@ private void evaluate(Expression evaluableExpression) {
if (testCase.expectedType() == DataType.UNSIGNED_LONG && result != null) {
result = NumericUtils.unsignedLongAsBigInteger((Long) result);
}
assertThat(result, not(equalTo(Double.NaN)));
assert testCase.getMatcher().matches(Double.POSITIVE_INFINITY) == false;
assertThat(result, not(equalTo(Double.POSITIVE_INFINITY)));
assert testCase.getMatcher().matches(Double.NEGATIVE_INFINITY) == false;
assertThat(result, not(equalTo(Double.NEGATIVE_INFINITY)));
assertThat(result, testCase.getMatcher());
if (testCase.getExpectedWarnings() != null) {
assertWarnings(testCase.getExpectedWarnings());
}
assertTestCaseResultAndWarnings(result);
}

private void resolveExpression(Expression expression, Consumer<Expression> onAggregator, Consumer<Expression> onEvaluableExpression) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,10 @@
import static org.hamcrest.Matchers.either;
import static org.hamcrest.Matchers.endsWith;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.nullValue;

/**
Expand Down Expand Up @@ -754,6 +756,34 @@ public static void testFunctionInfo() {
assertEquals(returnFromSignature, returnTypes);
}

/**
* Asserts the result of a test case matches the expected result and warnings.
* <p>
* The {@code result} parameter should be an object as returned by {@link #toJavaObjectUnsignedLongAware}.
* </p>
*/
@SuppressWarnings("unchecked")
protected final void assertTestCaseResultAndWarnings(Object result) {
if (result instanceof Iterable<?>) {
var collectionResult = (Iterable<Object>) result;
assertThat(collectionResult, not(hasItem(Double.NaN)));
assertThat(collectionResult, not(hasItem(Double.POSITIVE_INFINITY)));
assertThat(collectionResult, not(hasItem(Double.NEGATIVE_INFINITY)));
}

assert testCase.getMatcher().matches(Double.NaN) == false;
assertThat(result, not(equalTo(Double.NaN)));
assert testCase.getMatcher().matches(Double.POSITIVE_INFINITY) == false;
assertThat(result, not(equalTo(Double.POSITIVE_INFINITY)));
assert testCase.getMatcher().matches(Double.NEGATIVE_INFINITY) == false;
assertThat(result, not(equalTo(Double.NEGATIVE_INFINITY)));
assertThat(result, testCase.getMatcher());

if (testCase.getExpectedWarnings() != null) {
assertWarnings(testCase.getExpectedWarnings());
}
}

protected final void assertTypeResolutionFailure(Expression expression) {
assertTrue("expected unresolved", expression.typeResolved().unresolved());
assertThat(expression.typeResolved().message(), equalTo(testCase.getExpectedTypeError()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import static org.hamcrest.Matchers.either;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.nullValue;
import static org.hamcrest.Matchers.sameInstance;

Expand Down Expand Up @@ -127,15 +126,7 @@ public final void testEvaluate() {
result = toJavaObjectUnsignedLongAware(block, 0);
}
}
assertThat(result, not(equalTo(Double.NaN)));
assert testCase.getMatcher().matches(Double.POSITIVE_INFINITY) == false;
assertThat(result, not(equalTo(Double.POSITIVE_INFINITY)));
assert testCase.getMatcher().matches(Double.NEGATIVE_INFINITY) == false;
assertThat(result, not(equalTo(Double.NEGATIVE_INFINITY)));
assertThat(result, testCase.getMatcher());
if (testCase.getExpectedWarnings() != null) {
assertWarnings(testCase.getExpectedWarnings());
}
assertTestCaseResultAndWarnings(result);
}

/**
Expand Down
Loading

0 comments on commit d65a030

Please sign in to comment.