Skip to content

Commit 4ccd68e

Browse files
authored
ES|QL: Fix decay tests (elastic#136401)
1 parent 9371a61 commit 4ccd68e

File tree

2 files changed

+17
-21
lines changed

2 files changed

+17
-21
lines changed

muted-tests.yml

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -435,15 +435,9 @@ tests:
435435
- class: org.elasticsearch.xpack.esql.qa.single_node.GenerativeForkIT
436436
method: test {csv-spec:spatial_shapes.ConvertFromStringParseError}
437437
issue: https://github.com/elastic/elasticsearch/issues/134254
438-
- class: org.elasticsearch.xpack.esql.expression.function.scalar.score.DecayTests
439-
method: "testEvaluateBlockWithNulls {TestCase=<double>, <double>, <double>, <_source> #11}"
440-
issue: https://github.com/elastic/elasticsearch/issues/134447
441438
- class: org.elasticsearch.action.admin.cluster.state.TransportClusterStateActionTests
442439
method: testGetClusterStateWithDefaultProjectOnly
443440
issue: https://github.com/elastic/elasticsearch/issues/134450
444-
- class: org.elasticsearch.xpack.esql.expression.function.scalar.score.DecayTests
445-
method: "testEvaluateBlockWithNulls {TestCase=<date_nanos>, <date_nanos>, <time_duration>, <_source> #11}"
446-
issue: https://github.com/elastic/elasticsearch/issues/134509
447441
- class: org.elasticsearch.xpack.esql.plugin.CanMatchIT
448442
method: testAliasFilters
449443
issue: https://github.com/elastic/elasticsearch/issues/134512
@@ -468,9 +462,6 @@ tests:
468462
- class: org.elasticsearch.aggregations.bucket.AggregationReductionCircuitBreakingIT
469463
method: testCBTrippingOnReduction
470464
issue: https://github.com/elastic/elasticsearch/issues/134667
471-
- class: org.elasticsearch.xpack.esql.expression.function.scalar.score.DecayTests
472-
method: "testEvaluateBlockWithNulls {TestCase=<integer>, <integer>, <integer>, <_source> #2}"
473-
issue: https://github.com/elastic/elasticsearch/issues/134679
474465
- class: org.elasticsearch.xpack.esql.ccq.MultiClusterSpecIT
475466
method: test {csv-spec:fork.ForkBeforeStatsByWithWhere}
476467
issue: https://github.com/elastic/elasticsearch/issues/134817
@@ -522,12 +513,6 @@ tests:
522513
- class: org.elasticsearch.search.sort.FieldSortIT
523514
method: testSortMixedFieldTypes
524515
issue: https://github.com/elastic/elasticsearch/issues/129445
525-
- class: org.elasticsearch.xpack.esql.expression.function.scalar.score.DecayTests
526-
method: "testEvaluateInManyThreads {TestCase=<double>, <double>, <double>, <_source> #17}"
527-
issue: https://github.com/elastic/elasticsearch/issues/135357
528-
- class: org.elasticsearch.xpack.esql.expression.function.scalar.score.DecayTests
529-
method: "testEvaluateBlockWithoutNulls {TestCase=<date_nanos>, <date_nanos>, <time_duration>, <_source> #12}"
530-
issue: https://github.com/elastic/elasticsearch/issues/135394
531516
- class: org.elasticsearch.gradle.TestClustersPluginFuncTest
532517
method: override jdk usage via ES_JAVA_HOME for known jdk os incompatibilities
533518
issue: https://github.com/elastic/elasticsearch/issues/135413

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/score/DecayTests.java

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,11 @@
2121
import org.elasticsearch.xpack.esql.core.type.DataType;
2222
import org.elasticsearch.xpack.esql.expression.function.AbstractScalarFunctionTestCase;
2323
import org.elasticsearch.xpack.esql.expression.function.TestCaseSupplier;
24+
import org.hamcrest.Matcher;
2425
import org.junit.BeforeClass;
2526

27+
import java.math.BigDecimal;
28+
import java.math.RoundingMode;
2629
import java.time.Duration;
2730
import java.time.Instant;
2831
import java.time.LocalDateTime;
@@ -666,7 +669,7 @@ private static List<TestCaseSupplier> intRandomTestCases() {
666669
),
667670
startsWith("DecayIntEvaluator["),
668671
DataType.DOUBLE,
669-
closeTo(scoreScriptNumericResult, Math.ulp(scoreScriptNumericResult))
672+
decayValueMatcher(scoreScriptNumericResult)
670673
);
671674
}));
672675
}
@@ -740,7 +743,7 @@ private static List<TestCaseSupplier> longRandomTestCases() {
740743
),
741744
startsWith("DecayLongEvaluator["),
742745
DataType.DOUBLE,
743-
equalTo(scoreScriptNumericResult)
746+
decayValueMatcher(scoreScriptNumericResult)
744747
);
745748
}));
746749
}
@@ -810,7 +813,7 @@ private static List<TestCaseSupplier> doubleRandomTestCases() {
810813
),
811814
startsWith("DecayDoubleEvaluator["),
812815
DataType.DOUBLE,
813-
closeTo(scoreScriptNumericResult, Math.ulp(scoreScriptNumericResult))
816+
decayValueMatcher(scoreScriptNumericResult)
814817
);
815818
}));
816819
}
@@ -908,7 +911,7 @@ private static List<TestCaseSupplier> geoPointRandomTestCases() {
908911
),
909912
startsWith("DecayGeoPointEvaluator["),
910913
DataType.DOUBLE,
911-
closeTo(scoreScriptNumericResult, Math.ulp(scoreScriptNumericResult))
914+
decayValueMatcher(scoreScriptNumericResult)
912915
);
913916
}));
914917
}
@@ -1087,7 +1090,7 @@ private static List<TestCaseSupplier> datetimeRandomTestCases() {
10871090
),
10881091
startsWith("DecayDatetimeEvaluator["),
10891092
DataType.DOUBLE,
1090-
closeTo(scoreScriptNumericResult, Math.ulp(scoreScriptNumericResult))
1093+
decayValueMatcher(scoreScriptNumericResult)
10911094
);
10921095
}));
10931096
}
@@ -1174,7 +1177,7 @@ private static List<TestCaseSupplier> dateNanosRandomTestCases() {
11741177
),
11751178
startsWith("DecayDateNanosEvaluator["),
11761179
DataType.DOUBLE,
1177-
closeTo(scoreScriptNumericResult, 1e-10)
1180+
decayValueMatcher(scoreScriptNumericResult)
11781181
);
11791182
})
11801183
);
@@ -1229,4 +1232,12 @@ private static MapExpression createOptionsMap(Object offset, Double decay, Strin
12291232

12301233
return new MapExpression(Source.EMPTY, keyValuePairs);
12311234
}
1235+
1236+
private static Matcher<Double> decayValueMatcher(Double value) {
1237+
if (value == Double.POSITIVE_INFINITY || value == Double.NEGATIVE_INFINITY) {
1238+
return equalTo(value);
1239+
}
1240+
1241+
return closeTo(BigDecimal.valueOf(value).setScale(4, RoundingMode.CEILING).doubleValue(), 0.001);
1242+
}
12321243
}

0 commit comments

Comments
 (0)