Skip to content

EQL: Use the implicit tiebreaker sort value in the search queries #72089

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 4 commits into from
Apr 27, 2021

Conversation

astefan
Copy link
Contributor

@astefan astefan commented Apr 22, 2021

Following the recent addition of a default tiebreaker for PIT requests, EQL sequence queries that use search_after should also include in the list of its values (a timestamp and an optional EQL tiebreaker) the additional default tiebreaker value.

@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-ql (Team:QL)

@astefan
Copy link
Contributor Author

astefan commented Apr 22, 2021

@elasticmachine update branch

@astefan astefan requested a review from bpintea April 23, 2021 16:02
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.

LGTM

}
// this tiebreaker is null
else {
// nulls are last so unless both are null (equal)
// this ordinal is greater (after) then the other tiebreaker
// so fall through to 1
if (o.tiebreaker == null) {
return 0;
return Long.valueOf(implicitTiebreaker).compareTo(Long.valueOf(o.implicitTiebreaker));
Copy link
Member

Choose a reason for hiding this comment

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

Long.compare(implicitTieBreaker, o.implicitTiebreaker)


@Override
public int hashCode() {
return 35;
Copy link
Member

Choose a reason for hiding this comment

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

? Ideally should be a prime such as 31 or a relative constant such as ImplicitTiebreakerHitExtractor.class.hashCode()

Copy link
Contributor

@bpintea bpintea left a comment

Choose a reason for hiding this comment

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

LGTM


Object implicitTbreaker = implicitTiebreaker.extract(hit);
if (implicitTbreaker instanceof Number == false) {
throw new EqlIllegalArgumentException("Expected _shard_doc/implicit tiebreaker as long but got [{}]", implicitTbreaker);
Copy link
Contributor

Choose a reason for hiding this comment

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

Regarding the error message, could the value be a non-long integer?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@bpintea no. Always long.

Copy link
Contributor

Choose a reason for hiding this comment

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

Would then the instance check agains a Long be also appropriate? (just FMI, its prolly slightly safer the way it is now)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd leave it as is, for the reason you mentioned but also to be consistent with the approach throughout that method.

return o.tiebreaker != null ? tiebreaker.compareTo(o.tiebreaker) : -1;
if (o.tiebreaker != null) {
if (tiebreaker.compareTo(o.tiebreaker) == 0) {
return Long.valueOf(implicitTiebreaker).compareTo(Long.valueOf(o.implicitTiebreaker));
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess Costin's longs comparison applies here as well.

Copy link
Contributor

@matriv matriv left a comment

Choose a reason for hiding this comment

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

LGTM. nice!

@astefan astefan merged commit fa92fc4 into elastic:master Apr 27, 2021
@astefan astefan deleted the eql_pit_tiebreaker branch April 27, 2021 06:47
astefan added a commit to astefan/elasticsearch that referenced this pull request Apr 27, 2021
astefan added a commit that referenced this pull request Apr 27, 2021
astefan added a commit to astefan/elasticsearch that referenced this pull request Apr 27, 2021
astefan added a commit that referenced this pull request Apr 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants