-
Notifications
You must be signed in to change notification settings - Fork 25.2k
ESQL: add scalb function #127696
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?
ESQL: add scalb function #127696
Conversation
❌ Author of the following commits did not sign a Contributor Agreement: Please, read and sign the above mentioned agreement if you want to contribute to this project |
Pinging @elastic/es-analytical-engine (Team:Analytics) |
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.
Thanks @shmuelhanoch
I'm adding here some notes about what we discussed off-line
@@ -592,3 +592,10 @@ s:double | emp_no:integer | salary:integer | salary_change:double | |||
-1.0 | 10004 | 36174 | [-0.35, 1.13, 3.65, 13.48] | |||
-1.0 | 10005 | 63528 | [-2.14, 13.07] | |||
; | |||
|
|||
scalb | |||
row x = 3.0, y = 10 | eval z = scalb(x, y); |
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.
To make this pass in mixed-cluster tests, you'll need a new capability (see EsqlCapabilities) and you'll have to add a required_capability
to the test. You'll find a lot of examples of how to do it in CSV tests.
@@ -47,7 +47,6 @@ public class Round extends EsqlScalarFunction implements OptionalArgument { | |||
|
|||
private final Expression field, decimals; | |||
|
|||
// @TODO: add support for "integer", "long", "unsigned_long" once tests are fixed |
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.
👍 this is fixed already
} | ||
|
||
@Evaluator(warnExceptions = { ArithmeticException.class }) | ||
static double process(double d, int scaleFactor) { |
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.
You could have another process() method with a @Fixed
second parameter (see DateParse function for an example), it will make the computation for the very common case where the scale factor is a constant.
@@ -592,3 +592,10 @@ s:double | emp_no:integer | salary:integer | salary_change:double | |||
-1.0 | 10004 | 36174 | [-0.35, 1.13, 3.65, 13.48] | |||
-1.0 | 10005 | 63528 | [-2.14, 13.07] | |||
; | |||
|
|||
scalb |
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.
Please add a few more tests here, eg. with:
- an index as the source of the query (multiple records in the result)
- both foldable and non-foldable parameters
- usage of the function in a WHERE condition
) Expression d, | ||
@Param( | ||
name = "scaleFactor", | ||
type = { "integer" }, |
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.
We could support long
as a scale factor as well.
You'll need more process()
methods for that.
Please also add some tests for pathological cases, like very large numbers and null values. |
Part of #98545.