[ES|QL] Add function log(base, value)#104913
Conversation
…_bucket Committer: Fang Xing <fang.xing@elastic.co>
|
Documentation preview: |
|
Pinging @elastic/es-analytical-engine (Team:Analytics) |
luigidellaquila
left a comment
There was a problem hiding this comment.
Thank you very much @fang-xing-esql, it looks pretty good.
Kudos for the test coverage.
I added a few comments, mostly for possible improvements
x-pack/plugin/esql/qa/testFixtures/src/main/resources/math.csv-spec
Outdated
Show resolved
Hide resolved
...gin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/math/Log.java
Outdated
Show resolved
Hide resolved
| } | ||
|
|
||
| @Evaluator(warnExceptions = { ArithmeticException.class }) | ||
| static double process(double base, double value) { |
There was a problem hiding this comment.
In most of the cases the base will likely be a constant, so probably it makes sense to have a process(double value) method and a dedicated (and optimized) evaluator. See this as an example
There was a problem hiding this comment.
Discussed with Luigi, this enhancement can be deferred to a follow-up PR.
astefan
left a comment
There was a problem hiding this comment.
Please, add some csv-spec tests that use actual data from indices.
For example:
from employees | EVAL s = LOG(languages, salary) | keep emp_no, salary, s | limit 10
from employees | eval x = salary * 2 | eval s = log(x, x) | keep emp_no, salary, s | limit 10
from employees | rename languages as base | eval s = log(base, salary) | keep emp_no, salary, s | limit 10 | sort s nulls last
from employees | eval base = 2.5 | eval s = log(base, salary) * 0.5 | keep emp_no, salary, s | sort s nulls first | limit 5
More csv tests on indices are added. |
astefan
left a comment
There was a problem hiding this comment.
Left a small cosmetic comment, otherwise LGTM. Well done!
x-pack/plugin/esql/qa/testFixtures/src/main/resources/math.csv-spec
Outdated
Show resolved
Hide resolved
## Summary Sync with elastic/elasticsearch#104958 for support of builtin fn in STATS * validation ✅ * autocomplete ✅ * also fixed `STATS BY <field>` syntax  Sync with elastic/elasticsearch#104913 for new `log` function * validation ✅ - also warning for negative values * autocomplete ✅  Sync with elastic/elasticsearch#105064 for removal of `PROJECT` command * validation ✅ (both new and legacy syntax supported) * autocomplete ✅ (will only suggest new syntax)  Sync with elastic/elasticsearch#105221 for removal of mandatory brackets for `METADATA` command option * validation ✅ (added warning deprecation message when using brackets) * autocomplete ✅  Sync with elastic/elasticsearch#105224 for change of syntax for ENRICH ccq mode * validation ✅ * autocomplete ✅ (not directly promoted, the user has to type `_` to trigger it) * hover ✅ * code actions ✅   Do not merge until those 5 get merged. Additional things in this PR: * Added more tests for `callbacks` not passed scenario * covered more cases like those with `dissect` * Added more tests for signature params number (calling a function with an extra arg should return an error) * Cleaned up some more unused code * Improved messages on too many arguments for functions ### Checklist - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios
## Summary Sync with elastic/elasticsearch#104958 for support of builtin fn in STATS * validation ✅ * autocomplete ✅ * also fixed `STATS BY <field>` syntax  Sync with elastic/elasticsearch#104913 for new `log` function * validation ✅ - also warning for negative values * autocomplete ✅  Sync with elastic/elasticsearch#105064 for removal of `PROJECT` command * validation ✅ (both new and legacy syntax supported) * autocomplete ✅ (will only suggest new syntax)  Sync with elastic/elasticsearch#105221 for removal of mandatory brackets for `METADATA` command option * validation ✅ (added warning deprecation message when using brackets) * autocomplete ✅  Sync with elastic/elasticsearch#105224 for change of syntax for ENRICH ccq mode * validation ✅ * autocomplete ✅ (not directly promoted, the user has to type `_` to trigger it) * hover ✅ * code actions ✅   Do not merge until those 5 get merged. Additional things in this PR: * Added more tests for `callbacks` not passed scenario * covered more cases like those with `dissect` * Added more tests for signature params number (calling a function with an extra arg should return an error) * Cleaned up some more unused code * Improved messages on too many arguments for functions ### Checklist - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios
## Summary Sync with elastic/elasticsearch#104958 for support of builtin fn in STATS * validation ✅ * autocomplete ✅ * also fixed `STATS BY <field>` syntax  Sync with elastic/elasticsearch#104913 for new `log` function * validation ✅ - also warning for negative values * autocomplete ✅  Sync with elastic/elasticsearch#105064 for removal of `PROJECT` command * validation ✅ (both new and legacy syntax supported) * autocomplete ✅ (will only suggest new syntax)  Sync with elastic/elasticsearch#105221 for removal of mandatory brackets for `METADATA` command option * validation ✅ (added warning deprecation message when using brackets) * autocomplete ✅  Sync with elastic/elasticsearch#105224 for change of syntax for ENRICH ccq mode * validation ✅ * autocomplete ✅ (not directly promoted, the user has to type `_` to trigger it) * hover ✅ * code actions ✅   Do not merge until those 5 get merged. Additional things in this PR: * Added more tests for `callbacks` not passed scenario * covered more cases like those with `dissect` * Added more tests for signature params number (calling a function with an extra arg should return an error) * Cleaned up some more unused code * Improved messages on too many arguments for functions ### Checklist - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios
A scalar function log(based, value) returns the logarithm of a value for a particular base, as specified in the argument.
The arguments can be integer, long integer, unsigned long integer or double. If the arguments are not double, they are converted to one for processing by the function.
The result of the function is a double number.
The result can be null; if the argument is null, the result is the null value.