Skip to content

EQL: Add string function #54470

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

Merged
merged 14 commits into from
Apr 10, 2020
Merged

EQL: Add string function #54470

merged 14 commits into from
Apr 10, 2020

Conversation

rw-access
Copy link
Contributor

Resolves #54465

@rw-access rw-access added the :Analytics/EQL EQL querying label Mar 30, 2020
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-ql (:Query Languages/EQL)

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 two comments.

}

public static Object doProcess(Object source) {
return source == null ? "null" : source.toString();
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not null the instance instead of "null" the string?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

per #54465 and https://github.com/endgameinc/eql/blob/master/eql/functions.py#L626 I was following a contract (we can change it, of course) that this function always returns a string. So I catch null directly, since I can't call a method on it. Here's the current behavior for how it folds string(null):

>>> import eql
>>> eql.parse_expression("string(null)")
String(value='None')

Copy link
Member

Choose a reason for hiding this comment

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

Since we're not using some concept of Optional, returning null instead of a string "null" is better since otherwise there's no way to differentiate between a string with "null" chars vs actual null since they would both be equivalent which is not what we want.

@rw-access rw-access changed the title EQL: Add string() function EQL: Add string function Mar 31, 2020
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 in general, but I do have an outstanding question that I posted it here

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.

Left some comments - LGTM otherwise

}

public static Object doProcess(Object source) {
return source == null ? "null" : source.toString();
Copy link
Member

Choose a reason for hiding this comment

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

Since we're not using some concept of Optional, returning null instead of a string "null" is better since otherwise there's no way to differentiate between a string with "null" chars vs actual null since they would both be equivalent which is not what we want.

*/
public class ToString extends ScalarFunction {

private final Expression source;
Copy link
Member

Choose a reason for hiding this comment

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

Please rename source to something else (delegate, target, value?) since it conflicts with Source source convention. While source was used in a couple of Processors, it was mainly to follow the function delegation and their official param names.
This applies to the whole PR.

note = "check that string(null) returns 'null'"
expected_event_ids = [1, 2]
query = 'process where opcode == 3 and string(ppid) == "null"'

Copy link
Contributor

Choose a reason for hiding this comment

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

The original idea was to keep this file unchanged from the original eql implementation
https://github.com/endgameinc/eql/blob/master/eql/etc/test_queries.toml
so we can sync up easier with the reference repo/impl

and add more queries into separate file(s), could be just one, could be individual files for specific extensions
started doing something like this in my other PR
https://github.com/elastic/elasticsearch/pull/54277/files/be0b67cdf5022f38ec3610a68bbb91af8b10b8b3#diff-00cfec987b028a9cc67295e57c02cf68R1

Copy link
Contributor

@aleksmaus aleksmaus left a comment

Choose a reason for hiding this comment

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

Left one comment, open for discussion, also agree on not returning "null" as string.
Other than that LGTM.

@rw-access rw-access merged commit 3106fd9 into elastic:master Apr 10, 2020
@rw-access rw-access deleted the eql/string-function branch April 10, 2020 15:47
rw-access added a commit that referenced this pull request Apr 10, 2020
* EQL: Add string() function
* EQL: Reorder queryfolder_tests
* EQL: Add test queries
* EQL: Fix InternalEqlScriptUtils.string and test case
* EQL: Fix testStringFunctionWithText error message
* EQL: Flatten ToStringFunctionPipe.equals
* EQL: Reorder painless whitelist
* EQL: Address feedback and remove string(null) handling
* EQL: Move string(pid) test over
* EQL: Rename source -> value
@rw-access
Copy link
Contributor Author

7.x backport 96a903b

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Analytics/EQL EQL querying
Projects
None yet
Development

Successfully merging this pull request may close these issues.

EQL: Implement string function
5 participants