Skip to content

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

shmuelhanoch
Copy link

Part of #98545.

Copy link

❌ Author of the following commits did not sign a Contributor Agreement:
d195b7a

Please, read and sign the above mentioned agreement if you want to contribute to this project

@elasticsearchmachine elasticsearchmachine added needs:triage Requires assignment of a team area label v9.1.0 labels May 5, 2025
@shmuelhanoch shmuelhanoch added the Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) label May 5, 2025
@elasticsearchmachine elasticsearchmachine removed the Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) label May 5, 2025
@luigidellaquila luigidellaquila added >enhancement and removed needs:triage Requires assignment of a team area label labels May 5, 2025
@elasticsearchmachine elasticsearchmachine added the needs:triage Requires assignment of a team area label label May 5, 2025
@luigidellaquila luigidellaquila added :Analytics/ES|QL AKA ESQL and removed needs:triage Requires assignment of a team area label labels May 5, 2025
@elasticsearchmachine elasticsearchmachine added the Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) label May 5, 2025
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-analytical-engine (Team:Analytics)

Copy link
Contributor

@luigidellaquila luigidellaquila left a 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);
Copy link
Contributor

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
Copy link
Contributor

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) {
Copy link
Contributor

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
Copy link
Contributor

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" },
Copy link
Contributor

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.

@luigidellaquila
Copy link
Contributor

Please also add some tests for pathological cases, like very large numbers and null values.

@nik9000 nik9000 mentioned this pull request May 6, 2025
82 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Analytics/ES|QL AKA ESQL >enhancement Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) v9.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants