2020import org .elasticsearch .xpack .ql .tree .NodeUtils ;
2121import org .elasticsearch .xpack .ql .tree .Source ;
2222import org .elasticsearch .xpack .ql .type .DataTypes ;
23- import org .elasticsearch .xpack .ql .util .Holder ;
2423
2524import static java .util .Collections .emptyList ;
2625import static org .elasticsearch .xpack .ql .tree .Source .synthetic ;
@@ -46,29 +45,25 @@ public LogicalPlan postAnalyze(LogicalPlan plan, EqlConfiguration configuration)
4645
4746 // implicit project + fetch size (if needed)
4847
49- Holder <Boolean > hasJoin = new Holder <>(Boolean .FALSE );
50-
5148 Source projectCtx = synthetic ("<implicit-project>" );
52- if (plan .anyMatch (Sequence .class ::isInstance )) {
53- hasJoin .set (Boolean .TRUE );
49+ final boolean isSequence = plan .anyMatch (Sequence .class ::isInstance );
50+ final boolean isSample = plan .anyMatch (Sample .class ::isInstance );
51+ if (isSequence || isSample ) {
5452 // first per KeyedFilter
5553 plan = plan .transformUp (KeyedFilter .class , k -> {
56- Project p = new Project (projectCtx , k .child (), k .extractionAttributes ());
57-
58- // TODO: this could be incorporated into the query generation
59- LogicalPlan fetchSize = new LimitWithOffset (
60- synthetic ("<fetch-size>" ),
61- new Literal (synthetic ("<fetch-value>" ), configuration .fetchSize (), DataTypes .INTEGER ),
62- p
63- );
64-
65- return new KeyedFilter (k .source (), fetchSize , k .keys (), k .timestamp (), k .tiebreaker ());
54+ LogicalPlan newPlan = new Project (projectCtx , k .child (), isSequence ? k .extractionAttributes () : k . keys ());
55+ if ( isSequence ) {
56+ // TODO: this could be incorporated into the query generation
57+ newPlan = new LimitWithOffset (
58+ synthetic ("<fetch-size>" ),
59+ new Literal (synthetic ("<fetch-value>" ), configuration .fetchSize (), DataTypes .INTEGER ),
60+ newPlan
61+ );
62+ }
63+ return new KeyedFilter (k .source (), newPlan , k .keys (), k .timestamp (), k .tiebreaker ());
6664 });
67- }
68-
69- hasJoin .set (hasJoin .get () || plan .anyMatch (Sample .class ::isInstance ));
70- // in case of event queries, filter everything
71- if (hasJoin .get () == false ) {
65+ } else {
66+ // in case of event queries, filter everything
7267 plan = new Project (projectCtx , plan , emptyList ());
7368 }
7469 }
0 commit comments