EQL: implement cidrMatch function#54186
Conversation
|
Pinging @elastic/es-search (:Search/EQL) |
| return; | ||
| } | ||
|
|
||
| CreateIndexRequest request = new CreateIndexRequest(testIndexName) |
There was a problem hiding this comment.
Needed mapping to IP type, this creating the index with mapping.
| for (Expression addr: addresses) { | ||
| // Currently we have limited enum for ordinal numbers | ||
| // So just using default here for error messaging | ||
| resolution = isStringAndExact(addr, sourceText(), ParamOrdinal.DEFAULT); |
There was a problem hiding this comment.
The current enum for error messages doesn't work great for variadic type of function. Open to suggestions.
There was a problem hiding this comment.
I added a method here in my wildcard PR:
There was a problem hiding this comment.
Also, should these fields also be isStringAndExact? and an isFoldable check?
Here's how I approached that
There was a problem hiding this comment.
Cool! Will update after your PR merges.
The ParamOrdinal falls back to ParamOrdinal.DEFAULT after 4 params anyways. Maybe make enum longer if we still want to use enum there?
There was a problem hiding this comment.
For how to handle functions that deal with a variable list of parameters, I suggest having a look at org.elasticsearch.xpack.sql.expression.predicate.conditional.Case or org.elasticsearch.xpack.sql.expression.predicate.conditional.Coalesce since these are functions that have a variable list of parameters.
There was a problem hiding this comment.
Relying on the same def builder here that was merged with wildcard function for now.
Updated to align with wildcard impl usage of ParamOrdinal.
...l/src/main/java/org/elasticsearch/xpack/eql/expression/function/scalar/string/CIDRMatch.java
Outdated
Show resolved
Hide resolved
| // String | ||
| new FunctionDefinition[] { | ||
| def(Substring.class, Substring::new, "substring"), | ||
| def(CIDRMatch.class, CIDRMatch::new, "cidrmatch"), |
There was a problem hiding this comment.
I prefer listing the functions in alphabetical order.
| import static org.elasticsearch.xpack.ql.expression.TypeResolutions.isStringAndExact; | ||
|
|
||
| /** | ||
| * EQL specific cidrMatch function |
There was a problem hiding this comment.
Personal preference, but I would like to see a useful description of the function. Not even the original EQL documentation is clear imo: https://eql.readthedocs.io/en/latest/query-guide/functions.html
There was a problem hiding this comment.
Added a couple of more lines with a link to the EQL doc.
| for (Expression addr: addresses) { | ||
| // Currently we have limited enum for ordinal numbers | ||
| // So just using default here for error messaging | ||
| resolution = isStringAndExact(addr, sourceText(), ParamOrdinal.DEFAULT); |
There was a problem hiding this comment.
For how to handle functions that deal with a variable list of parameters, I suggest having a look at org.elasticsearch.xpack.sql.expression.predicate.conditional.Case or org.elasticsearch.xpack.sql.expression.predicate.conditional.Coalesce since these are functions that have a variable list of parameters.
|
Will address the code review comments and make some adjustments once the wildcard function PR (#54020) is merged, since will have some conflicts and can reuse some code between the functions. |
|
@elastic/es-ql |
|
@elasticmachine run elasticsearch-ci/docs |
|
@elasticmachine run elasticsearch-ci/2 |
costin
left a comment
There was a problem hiding this comment.
Looks good to me - left a comment re: #54795 (waiting for the build to pass before merging).
I would also like some tests regarding incorrect arguments - what if the given string is non-numeric or contains an invalid IP.
How does the current EQL implementation handle that - I'm fine with addressing this in a separate PR however I'd like to have an issue tracking this so it doesn't get lost.
That is, how do we validate and protect against invalid parameters.
| return new CIDRMatch(source(), newChildren.get(0), newChildren.subList(1, newChildren.size())); | ||
| } | ||
|
|
||
| public ScalarFunction asFunction() { |
|
@costin regarding validation if the string is a valid IP address the original EQL implementation does validation with regex matching etc. In our case I was not sure if we need to add any additional validation, but pass the string down to elasticsearch and let it match against the IP type of field or handle the error if the value can not be used for matching. |
Related to #54132