Skip to content

EQL: startsWith function implementation#54400

Merged
astefan merged 7 commits intoelastic:masterfrom
astefan:53855_impl
Mar 31, 2020
Merged

EQL: startsWith function implementation#54400
astefan merged 7 commits intoelastic:masterfrom
astefan:53855_impl

Conversation

@astefan
Copy link
Copy Markdown
Contributor

@astefan astefan commented Mar 30, 2020

Addresses #53855

@elasticmachine
Copy link
Copy Markdown
Collaborator

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

@astefan
Copy link
Copy Markdown
Contributor Author

astefan commented Mar 30, 2020

@elasticmachine run elasticsearch-ci/bwc

if (source instanceof String == false && source instanceof Character == false) {
throw new EqlIllegalArgumentException("A string/char is required; received [{}]", source);
}
if (pattern == null) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

maybe open for discussion: return null only if he source is null and exception for the rest of params that should not be null?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sound good. Looks like another pattern that could be extracted/reused depending on which way we want to proceed with null handling for consistency between all functions.

return null;
}
if (pattern instanceof String == false && pattern instanceof Character == false) {
throw new EqlIllegalArgumentException("A string/char is required; received [{}]", pattern);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: just a suggestion maybe extract the function to avoid repetition, for example:
https://github.com/elastic/elasticsearch/pull/54380/files#diff-5ad1821091fb7e7473cbdfdded44fbcbR52

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I believe that, at one point after all these string functions are done, we need to refactor them and extract some common code in a base class, if possible of course.


@Override
public int hashCode() {
return Objects.hash(source());
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

should include the pattern in both equals and hashCode?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch. Will fix.

Copy link
Copy Markdown
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.

LGTM. Thank you!

@astefan
Copy link
Copy Markdown
Contributor Author

astefan commented Mar 30, 2020

@elasticmachine update branch

Copy link
Copy Markdown
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.

LGTM

@astefan astefan merged commit 666719f into elastic:master Mar 31, 2020
@astefan astefan deleted the 53855_impl branch March 31, 2020 12:43
astefan added a commit to astefan/elasticsearch that referenced this pull request Mar 31, 2020
astefan added a commit that referenced this pull request Mar 31, 2020
* EQL: startsWith function implementation (#54400)

(cherry picked from commit 666719f)

* EQL: endsWith function implementation (#54442)

(cherry picked from commit 554a4c8)
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.

4 participants