-
Notifications
You must be signed in to change notification settings - Fork 25.6k
ES|QL: Add unsigned long and mixed numeric types support to Decay function #134440
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
d57a8e9
58a230c
408d4c9
c86e56c
f43b505
1319903
eee150f
13f103a
e35b86f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 |
|---|---|---|
|
|
@@ -102,6 +102,33 @@ public static Iterable<Object[]> parameters() { | |
| // Long random | ||
| testCaseSuppliers.addAll(longRandomTestCases()); | ||
|
|
||
| // Unsigned Long Linear | ||
| testCaseSuppliers.addAll(unsignedLongTestCase(0L, 10L, 10000000L, 200L, 0.33, "linear", 1.0)); | ||
|
||
| testCaseSuppliers.addAll(unsignedLongTestCase(10L, 10L, 10000000L, 200L, 0.33, "linear", 1.0)); | ||
| testCaseSuppliers.addAll(unsignedLongTestCase(50000L, 10L, 10000000L, 200L, 0.33, "linear", 0.99666407)); | ||
| testCaseSuppliers.addAll(unsignedLongTestCase(300000L, 10L, 10000000L, 200L, 0.33, "linear", 0.97991407)); | ||
| testCaseSuppliers.addAll(unsignedLongTestCase(123456789112123L, 10L, 10000000L, 200L, 0.33, "linear", 0.0)); | ||
|
|
||
| // Unsigned Long Exponential | ||
| testCaseSuppliers.addAll(unsignedLongTestCase(0L, 10L, 10000000L, 200L, 0.33, "exp", 1.0)); | ||
| testCaseSuppliers.addAll(unsignedLongTestCase(10L, 10L, 10000000L, 200L, 0.33, "exp", 1.0)); | ||
| testCaseSuppliers.addAll(unsignedLongTestCase(50000L, 10L, 10000000L, 200L, 0.33, "exp", 0.9944951761701727)); | ||
| testCaseSuppliers.addAll(unsignedLongTestCase(300000L, 10L, 10000000L, 200L, 0.33, "exp", 0.9673096701204178)); | ||
| testCaseSuppliers.addAll(unsignedLongTestCase(123456789112123L, 10L, 10000000L, 200L, 0.33, "exp", 0.0)); | ||
|
|
||
| // Unsigned Long Gaussian | ||
| testCaseSuppliers.addAll(unsignedLongTestCase(0L, 10L, 10000000L, 200L, 0.33, "gauss", 1.0)); | ||
| testCaseSuppliers.addAll(unsignedLongTestCase(10L, 10L, 10000000L, 200L, 0.33, "gauss", 1.0)); | ||
| testCaseSuppliers.addAll(unsignedLongTestCase(50000L, 10L, 10000000L, 200L, 0.33, "gauss", 0.999972516142306)); | ||
| testCaseSuppliers.addAll(unsignedLongTestCase(300000L, 10L, 10000000L, 200L, 0.33, "gauss", 0.9990040963055015)); | ||
| testCaseSuppliers.addAll(unsignedLongTestCase(123456789112123L, 10L, 10000000L, 200L, 0.33, "gauss", 0.0)); | ||
|
|
||
| // Unsigned Long defaults | ||
| testCaseSuppliers.addAll(unsignedLongTestCase(10L, 0L, 10L, null, null, null, 0.5)); | ||
|
|
||
| // Unsigned Long random | ||
| testCaseSuppliers.addAll(unsignedLongRandomTestCases()); | ||
|
|
||
| // Double Linear | ||
| testCaseSuppliers.addAll(doubleTestCase(0.0, 10.0, 10000000.0, 200.0, 0.25, "linear", 1.0)); | ||
| testCaseSuppliers.addAll(doubleTestCase(10.0, 10.0, 10000000.0, 200.0, 0.25, "linear", 1.0)); | ||
|
|
@@ -738,6 +765,69 @@ private static List<TestCaseSupplier> longRandomTestCases() { | |
| })); | ||
| } | ||
|
|
||
| private static List<TestCaseSupplier> unsignedLongTestCase( | ||
| long value, | ||
| long origin, | ||
| long scale, | ||
| Long offset, | ||
| Double decay, | ||
| String functionType, | ||
| double expected | ||
| ) { | ||
| return List.of( | ||
| new TestCaseSupplier( | ||
| List.of(DataType.UNSIGNED_LONG, DataType.UNSIGNED_LONG, DataType.UNSIGNED_LONG, DataType.SOURCE), | ||
| () -> new TestCaseSupplier.TestCase( | ||
| List.of( | ||
| new TestCaseSupplier.TypedData(value, DataType.UNSIGNED_LONG, "value"), | ||
| new TestCaseSupplier.TypedData(origin, DataType.UNSIGNED_LONG, "origin").forceLiteral(), | ||
| new TestCaseSupplier.TypedData(scale, DataType.UNSIGNED_LONG, "scale").forceLiteral(), | ||
| new TestCaseSupplier.TypedData(createOptionsMap(offset, decay, functionType), DataType.SOURCE, "options") | ||
| .forceLiteral() | ||
| ), | ||
| startsWith("DecayLongEvaluator["), | ||
| DataType.DOUBLE, | ||
| closeTo(expected, Math.ulp(expected)) | ||
| ) | ||
| ) | ||
| ); | ||
| } | ||
|
|
||
| private static List<TestCaseSupplier> unsignedLongRandomTestCases() { | ||
| return List.of( | ||
| new TestCaseSupplier(List.of(DataType.UNSIGNED_LONG, DataType.UNSIGNED_LONG, DataType.UNSIGNED_LONG, DataType.SOURCE), () -> { | ||
| long randomValue = randomLong(); | ||
carlosdelest marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| long randomOrigin = randomLong(); | ||
| long randomScale = randomLong(); | ||
| long randomOffset = randomLong(); | ||
| double randomDecay = randomDouble(); | ||
| String randomType = randomFrom("linear", "gauss", "exp"); | ||
|
|
||
| double scoreScriptNumericResult = longDecayWithScoreScript( | ||
| randomValue, | ||
| randomOrigin, | ||
| randomScale, | ||
| randomOffset, | ||
| randomDecay, | ||
| randomType | ||
| ); | ||
|
|
||
| return new TestCaseSupplier.TestCase( | ||
| List.of( | ||
| new TestCaseSupplier.TypedData(randomValue, DataType.UNSIGNED_LONG, "value"), | ||
| new TestCaseSupplier.TypedData(randomOrigin, DataType.UNSIGNED_LONG, "origin").forceLiteral(), | ||
| new TestCaseSupplier.TypedData(randomScale, DataType.UNSIGNED_LONG, "scale").forceLiteral(), | ||
| new TestCaseSupplier.TypedData(createOptionsMap(randomOffset, randomDecay, randomType), DataType.SOURCE, "options") | ||
| .forceLiteral() | ||
| ), | ||
| startsWith("DecayLongEvaluator["), | ||
| DataType.DOUBLE, | ||
| equalTo(scoreScriptNumericResult) | ||
| ); | ||
| }) | ||
| ); | ||
| } | ||
|
|
||
| private static double longDecayWithScoreScript(long value, long origin, long scale, long offset, double decay, String type) { | ||
| return switch (type) { | ||
| case "linear" -> new ScoreScriptUtils.DecayNumericLinear(origin, scale, offset, decay).decayNumericLinear(value); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.