Skip to content

Commit

Permalink
Revert "EQL: Avoid filtering on tiebreakers (elastic#63215)"
Browse files Browse the repository at this point in the history
This reverts commit 4d62198.
  • Loading branch information
costin committed Oct 5, 2020
1 parent 0c56516 commit 1eac692
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ query = '''
[ ERROR where true ]
[ STAT where true ]
'''
expected_event_ids = [1,2,3,1,2,3]
expected_event_ids = [1,2,3]

[[queries]]
name = "basicWithFilter"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
package org.elasticsearch.xpack.eql;

import org.elasticsearch.test.eql.EqlExtraSpecTestCase;
import org.elasticsearch.test.junit.annotations.TestLogging;

@TestLogging(value = "org.elasticsearch.xpack.eql:TRACE", reason = "results logging")
public class EqlExtraIT extends EqlExtraSpecTestCase {

public EqlExtraIT(String query, String name, long[] eventIds, boolean caseSensitive) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,29 @@
*
* Note that the range is not set at once on purpose since each query tends to have
* its own number of results separate from the others.
* As such, each query starts from where it left off to reach the current in-progress window
* As such, each query starts where it lefts to reach the current in-progress window
* as oppose to always operating with the exact same window.
*/
public class BoxedQueryRequest implements QueryRequest {

private final RangeQueryBuilder timestampRange;
private final RangeQueryBuilder tiebreakerRange;

private final SearchSourceBuilder searchSource;

private Ordinal from, to;
private Ordinal after;

public BoxedQueryRequest(QueryRequest original, String timestamp) {
public BoxedQueryRequest(QueryRequest original, String timestamp, String tiebreaker) {
// setup range queries and preserve their reference to simplify the update
timestampRange = rangeQuery(timestamp).timeZone("UTC").format("epoch_millis");
BoolQueryBuilder filter = boolQuery().filter(timestampRange);
if (tiebreaker != null) {
tiebreakerRange = rangeQuery(tiebreaker);
filter.filter(tiebreakerRange);
} else {
tiebreakerRange = null;
}

searchSource = original.searchSource();
// combine with existing query (if it exists)
Expand Down Expand Up @@ -65,6 +72,9 @@ public void nextAfter(Ordinal ordinal) {
public BoxedQueryRequest from(Ordinal begin) {
from = begin;
timestampRange.gte(begin != null ? begin.timestamp() : null);
if (tiebreakerRange != null) {
tiebreakerRange.gte(begin != null ? begin.tiebreaker() : null);
}
return this;
}

Expand All @@ -83,6 +93,9 @@ public Ordinal from() {
public BoxedQueryRequest to(Ordinal end) {
to = end;
timestampRange.lte(end != null ? end.timestamp() : null);
if (tiebreakerRange != null) {
tiebreakerRange.lte(end != null ? end.tiebreaker() : null);
}
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public Executable assemble(List<List<Attribute>> listOfKeys,
if (query instanceof EsQueryExec) {
SearchSourceBuilder source = ((EsQueryExec) query).source(session);
QueryRequest original = () -> source;
BoxedQueryRequest boxedRequest = new BoxedQueryRequest(original, timestampName);
BoxedQueryRequest boxedRequest = new BoxedQueryRequest(original, timestampName, tiebreakerName);
Criterion<BoxedQueryRequest> criterion =
new Criterion<>(i, boxedRequest, keyExtractors, tsExtractor, tbExtractor, i == 0 && descending);
criteria.add(criterion);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class TestCriterion extends Criterion<BoxedQueryRequest> {

TestCriterion(final int ordinal) {
super(ordinal,
new BoxedQueryRequest(() -> SearchSourceBuilder.searchSource().query(matchAllQuery()).size(ordinal), "timestamp"),
new BoxedQueryRequest(() -> SearchSourceBuilder.searchSource().query(matchAllQuery()).size(ordinal), "timestamp", null),
keyExtractors,
tsExtractor, tbExtractor, false);
this.ordinal = ordinal;
Expand Down

0 comments on commit 1eac692

Please sign in to comment.