EQL: Add number function#55084
EQL: Add number function#55084rw-access merged 24 commits intoelastic:masterfrom rw-access:eql/number-function
Conversation
|
Pinging @elastic/es-ql (:Query Languages/EQL) |
astefan
left a comment
There was a problem hiding this comment.
Left a bunch of comments.
I think we need more integration and unit tests to cover all scenarios (see comment for the toml file).
Also, base argument has been left off in quite few places.
...java/org/elasticsearch/xpack/eql/expression/function/scalar/string/ToNumberFunctionPipe.java
Outdated
Show resolved
Hide resolved
|
|
||
| @Override | ||
| public final Pipe resolveAttributes(AttributeResolver resolver) { | ||
| Pipe newSource = source.resolveAttributes(resolver); |
There was a problem hiding this comment.
Did you forget the base here?
...java/org/elasticsearch/xpack/eql/expression/function/scalar/string/ToNumberFunctionPipe.java
Outdated
Show resolved
Hide resolved
...java/org/elasticsearch/xpack/eql/expression/function/scalar/string/ToNumberFunctionPipe.java
Outdated
Show resolved
Hide resolved
| def(EndsWith.class, EndsWith::new, "endswith"), | ||
| def(IndexOf.class, IndexOf::new, "indexof"), | ||
| def(Length.class, Length::new, "length"), | ||
| def(ToNumber.class, ToNumber::new, "number"), |
There was a problem hiding this comment.
I think we should add a new FunctionDefinition[] array for math/numerical functions.
There was a problem hiding this comment.
agreed. @aleksmaus has one in his PR. I wasn't sure if this was math or still string, since it's parsing from strings
| try { | ||
| return NumberFormat.getNumberInstance(Locale.US).parse(source.toString()); | ||
| } catch (ParseException e) { | ||
| throw new EqlIllegalArgumentException("Unable to convert [{}] to number of base [{}]", source, radix); |
There was a problem hiding this comment.
Here I would prefer to see in the error message the original base. If that is null because the user didn't provide one, then print radix.
...org/elasticsearch/xpack/eql/expression/function/scalar/string/ToNumberFunctionProcessor.java
Outdated
Show resolved
Hide resolved
...org/elasticsearch/xpack/eql/expression/function/scalar/string/ToNumberFunctionProcessor.java
Outdated
Show resolved
Hide resolved
...org/elasticsearch/xpack/eql/expression/function/scalar/string/ToNumberFunctionProcessor.java
Show resolved
Hide resolved
| expected_event_ids = [1, 2, 3, 5, 11] | ||
| description = "test built-in math functions" | ||
|
|
||
| [[queries]] |
There was a problem hiding this comment.
Can you add more tests here, please?
The way I see it, there are tests (just one) for no argument number function and for base 16. How about base 2, explicit base 10, and custom bases?
There was a problem hiding this comment.
I would still like to see here more tests.
There was a problem hiding this comment.
Added tests for the processor, and added integration tests here
867fc01
astefan
left a comment
There was a problem hiding this comment.
Looking better.
Added a second round of comments.
...ql/src/main/java/org/elasticsearch/xpack/eql/expression/function/scalar/string/ToNumber.java
Outdated
Show resolved
Hide resolved
...java/org/elasticsearch/xpack/eql/expression/function/scalar/string/ToNumberFunctionPipe.java
Outdated
Show resolved
Hide resolved
| * you may not use this file except in compliance with the Elastic License. | ||
| */ | ||
|
|
||
| package org.elasticsearch.xpack.eql.expression.function.scalar.string; |
There was a problem hiding this comment.
I believe we should add a new package for the numeric/math functions. At the moment this is ...function.scalar.string. ES SQL has .math. Probably worth doing the same here. Add a package ...function.scalar.math.
| expected_event_ids = [1, 2, 3, 5, 11] | ||
| description = "test built-in math functions" | ||
|
|
||
| [[queries]] |
There was a problem hiding this comment.
I would still like to see here more tests.
...ql/src/main/java/org/elasticsearch/xpack/eql/expression/function/scalar/string/ToNumber.java
Outdated
Show resolved
Hide resolved
...ql/src/main/java/org/elasticsearch/xpack/eql/expression/function/scalar/string/ToNumber.java
Outdated
Show resolved
Hide resolved
...va/org/elasticsearch/xpack/eql/expression/function/scalar/string/ToNumberProcessorTests.java
Show resolved
Hide resolved
astefan
left a comment
There was a problem hiding this comment.
LGTM. Left two very minor comments though.
.../eql/src/main/java/org/elasticsearch/xpack/eql/expression/function/scalar/math/ToNumber.java
Outdated
Show resolved
Hide resolved
| assertNull(process(null, null)); | ||
| assertNull(process(null, 8)); | ||
| assertNull(process(null, 10)); | ||
| assertNull(process(null, 16)); |
There was a problem hiding this comment.
assertNull(process(123, null)) is missing.
There was a problem hiding this comment.
ah. that's because if the base is null, then the base will be autodetected.
I don't know if there's a way to mention that the parameter was not supplied vs it was evaluated as false. I believe substring() and a few other functions have similar behavior
aleksmaus
left a comment
There was a problem hiding this comment.
Left one question, otherwise LGTM.
Thank you!
...a/org/elasticsearch/xpack/eql/expression/function/scalar/math/ToNumberFunctionProcessor.java
Outdated
Show resolved
Hide resolved
...a/org/elasticsearch/xpack/eql/expression/function/scalar/math/ToNumberFunctionProcessor.java
Outdated
Show resolved
Hide resolved
* EQL: Add number function * EQL: Fix the locale used for number for deterministic functionality * EQL: Add more ToNumber tests * EQL: Add more number ToNumberProcessor unit tests * EQL: Remove unnecessary overrides, fix processor methods * EQL: Remove additional unnecessary overrides * EQL: Lint fixes for ToNumber * EQL: ToNumber renames from PR feedback * EQL: Remove NumberFormat locale handling * EQL: Removed NumberFormat from ToNumber * EQL: Add number function tests * EQL: ToNumberProcessorTests formatting * EQL: Remove newline in ToNumberProcessorTests * EQL: Add number(..., null) test * EQL: Create expression.function.scalar.math package * EQL: Remove painless whitespace for ToNumber.asScript * EQL: Add Long support
Resolves #54471
Added function to parse numbers from strings.
One note is that the resolved DataType is double. Since it can return integer, float, or number. Double seemed to be the most inclusive.