Skip to content

Conversation

@aleksmaus
Copy link
Contributor

@aleksmaus aleksmaus commented Mar 25, 2020

Related to #54132

@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-search (:Search/EQL)

return;
}

CreateIndexRequest request = new CreateIndexRequest(testIndexName)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current enum for error messages doesn't work great for variadic type of function. Open to suggestions.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a method here in my wildcard PR:

public static ParamOrdinal fromIndex(int index) {
switch (index) {
case 0: return ParamOrdinal.FIRST;
case 1: return ParamOrdinal.SECOND;
case 2: return ParamOrdinal.THIRD;
case 3: return ParamOrdinal.FOURTH;
default: return ParamOrdinal.DEFAULT;
}
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, should these fields also be isStringAndExact? and an isFoldable check?
Here's how I approached that

lastResolution = isFoldable(p, sourceText(), ParamOrdinal.fromIndex(index));
if (lastResolution.unresolved()) {
break;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Relying on the same def builder here that was merged with wildcard function for now.
Updated to align with wildcard impl usage of ParamOrdinal.

Copy link
Contributor

@astefan astefan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left few comments.

// String
new FunctionDefinition[] {
def(Substring.class, Substring::new, "substring"),
def(CIDRMatch.class, CIDRMatch::new, "cidrmatch"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer listing the functions in alphabetical order.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep. Updated.

import static org.elasticsearch.xpack.ql.expression.TypeResolutions.isStringAndExact;

/**
* EQL specific cidrMatch function
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@aleksmaus
Copy link
Contributor Author

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.

@matriv
Copy link
Contributor

matriv commented Mar 30, 2020

@elastic/es-ql

@aleksmaus
Copy link
Contributor Author

@elasticmachine run elasticsearch-ci/docs

@aleksmaus
Copy link
Contributor Author

@elasticmachine run elasticsearch-ci/2

@aleksmaus aleksmaus requested review from astefan and rw-access April 6, 2020 12:54
Copy link
Member

@costin costin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update to take into account #54795 - reduces the class and removes a separate optimizer rule.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, will do once #54795 is merged.

Copy link
Contributor

@astefan astefan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@aleksmaus
Copy link
Contributor Author

@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.
Correct me if I'm wrong.

@aleksmaus aleksmaus merged commit 99b9a18 into elastic:master Apr 7, 2020
aleksmaus added a commit to aleksmaus/elasticsearch that referenced this pull request Apr 7, 2020
aleksmaus added a commit that referenced this pull request Apr 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants