-
Notifications
You must be signed in to change notification settings - Fork 25.6k
EQL: Introduce support for sequence maxspan #58635
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
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d8ab429
Encapsulate timestamp and timebreaker into Ordinal
costin 3a1593f
Stop descending from leaking inside the runtime
costin f1c310a
Add maxspan check
costin a98bcba
Enable integration tests with maxspan
costin 5b2a97e
Convert windows filetime to unix time
costin b4c19d5
Address feedback
costin bf69b59
Merge remote-tracking branch 'remotes/upstream/master' into eql/span-…
costin 9d5ae33
Disable unsupported tests
costin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,8 @@ | |
| import org.elasticsearch.search.builder.SearchSourceBuilder; | ||
| import org.elasticsearch.xpack.eql.EqlIllegalArgumentException; | ||
| import org.elasticsearch.xpack.eql.execution.search.QueryRequest; | ||
| import org.elasticsearch.xpack.eql.execution.sequence.Ordinal; | ||
| import org.elasticsearch.xpack.eql.util.ReversedIterator; | ||
| import org.elasticsearch.xpack.ql.execution.search.extractor.HitExtractor; | ||
|
|
||
| import java.util.List; | ||
|
|
@@ -22,19 +24,25 @@ public class Criterion implements QueryRequest { | |
| private final HitExtractor tiebreakerExtractor; | ||
|
|
||
| // search after markers | ||
| private Object[] startMarker; | ||
| private Object[] stopMarker; | ||
| private Ordinal startMarker; | ||
| private Ordinal stopMarker; | ||
|
|
||
| private boolean reverse; | ||
|
|
||
| //TODO: should accept QueryRequest instead of another SearchSourceBuilder | ||
| public Criterion(SearchSourceBuilder searchSource, List<HitExtractor> searchAfterExractors, HitExtractor timestampExtractor, | ||
| HitExtractor tiebreakerExtractor) { | ||
| public Criterion(SearchSourceBuilder searchSource, | ||
| List<HitExtractor> searchAfterExractors, | ||
| HitExtractor timestampExtractor, | ||
| HitExtractor tiebreakerExtractor, | ||
| boolean reverse) { | ||
| this.searchSource = searchSource; | ||
| this.keyExtractors = searchAfterExractors; | ||
| this.timestampExtractor = timestampExtractor; | ||
| this.tiebreakerExtractor = tiebreakerExtractor; | ||
|
|
||
| this.startMarker = null; | ||
| this.stopMarker = null; | ||
| this.reverse = reverse; | ||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -54,54 +62,45 @@ public HitExtractor tiebreakerExtractor() { | |
| return tiebreakerExtractor; | ||
| } | ||
|
|
||
| public long timestamp(SearchHit hit) { | ||
| @SuppressWarnings({ "unchecked" }) | ||
| public Ordinal ordinal(SearchHit hit) { | ||
|
|
||
| Object ts = timestampExtractor.extract(hit); | ||
| if (ts instanceof Number) { | ||
| return ((Number) ts).longValue(); | ||
| if (ts instanceof Number == false) { | ||
| throw new EqlIllegalArgumentException("Expected timestamp as long but got {}", ts); | ||
| } | ||
| throw new EqlIllegalArgumentException("Expected timestamp as long but got {}", ts); | ||
| } | ||
|
|
||
| @SuppressWarnings({ "unchecked" }) | ||
| public Comparable<Object> tiebreaker(SearchHit hit) { | ||
| if (tiebreakerExtractor == null) { | ||
| return null; | ||
| } | ||
| Object tb = tiebreakerExtractor.extract(hit); | ||
| if (tb instanceof Comparable) { | ||
| return (Comparable<Object>) tb; | ||
| } | ||
| throw new EqlIllegalArgumentException("Expected tiebreaker to be Comparable but got {}", tb); | ||
| } | ||
| long timestamp = ((Number) ts).longValue(); | ||
| Comparable<Object> tiebreaker = null; | ||
|
|
||
| public Object[] startMarker() { | ||
| return startMarker; | ||
| if (tiebreakerExtractor != null) { | ||
| Object tb = tiebreakerExtractor.extract(hit); | ||
| if (tb instanceof Comparable == false) { | ||
| throw new EqlIllegalArgumentException("Expected tiebreaker to be Comparable but got {}", tb); | ||
| } | ||
| tiebreaker = (Comparable<Object>) tb; | ||
| } | ||
| return new Ordinal(timestamp, tiebreaker); | ||
| } | ||
|
|
||
| public Object[] stopMarker() { | ||
| return stopMarker; | ||
| public void startMarker(Ordinal ordinal) { | ||
| startMarker = ordinal; | ||
| } | ||
|
|
||
| private Object[] marker(SearchHit hit) { | ||
| long timestamp = timestamp(hit); | ||
| Object tiebreaker = null; | ||
| if (tiebreakerExtractor() != null) { | ||
| tiebreaker = tiebreaker(hit); | ||
| } | ||
|
|
||
| return tiebreaker != null ? new Object[] { timestamp, tiebreaker } : new Object[] { timestamp }; | ||
| public void stopMarker(Ordinal ordinal) { | ||
| stopMarker = ordinal; | ||
| } | ||
|
|
||
| public void startMarker(SearchHit hit) { | ||
| startMarker = marker(hit); | ||
| public Ordinal nextMarker() { | ||
| return startMarker.compareTo(stopMarker) < 1 ? startMarker : stopMarker; | ||
| } | ||
|
|
||
| public void stopMarker(SearchHit hit) { | ||
| stopMarker = marker(hit); | ||
| public Criterion useMarker(Ordinal marker) { | ||
| searchSource.searchAfter(marker.toArray()); | ||
| return this; | ||
| } | ||
|
|
||
| public Criterion useMarker(Object[] marker) { | ||
| searchSource.searchAfter(marker); | ||
| return this; | ||
| public Iterable<SearchHit> iterateable(List<SearchHit> hits) { | ||
|
||
| return () -> reverse ? new ReversedIterator<>(hits) : hits.iterator(); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you change this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because timestamp is not unix time but rather window filetime (see this comment and until the dataset gets updated, working on a separate field is the cleaner.