Skip to content

Commit 2aa2b49

Browse files
Clean up, add more UTs
1 parent ba9ab52 commit 2aa2b49

File tree

11 files changed

+70
-101
lines changed

11 files changed

+70
-101
lines changed

test/external-modules/esql-heap-attack/src/javaRestTest/java/org/elasticsearch/xpack/esql/heap_attack/HeapAttackIT.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,6 @@ public void testLookupExplosionManyMatchesFiltered() throws IOException {
726726
// This test will only work with the expanding join optimization
727727
// that pushes the filter to the right side of the lookup.
728728
// Without the optimization, it will fail with circuit_breaking_exception
729-
// lookupEntries % reductionFactor must be 0 to ensure that the number of matches is reduced
730729
int sensorDataCount = 10000;
731730
int lookupEntries = 10000;
732731
int reductionFactor = 1000; // reduce the number of matches by this factor

x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/operator/lookup/LookupEnrichQueryGenerator.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
import org.apache.lucene.search.Query;
1111
import org.elasticsearch.core.Nullable;
1212

13-
import java.io.IOException;
14-
1513
/**
1614
* An interface to generates queries for the lookup and enrich operators.
1715
* This interface is used to retrieve queries based on a position index.
@@ -22,7 +20,7 @@ public interface LookupEnrichQueryGenerator {
2220
* Returns the query at the given position.
2321
*/
2422
@Nullable
25-
Query getQuery(int position) throws IOException;
23+
Query getQuery(int position);
2624

2725
/**
2826
* Returns the number of queries in this generator

x-pack/plugin/esql/qa/testFixtures/src/main/resources/lookup-join.csv-spec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5151,7 +5151,7 @@ null | null | fred | null | null
51515151
;
51525152

51535153

5154-
lookupJoinWithPushableFilterOnLeft
5154+
lookupJoinWithPushableFilterOnRight
51555155
required_capability: join_lookup_v12
51565156
required_capability: lookup_join_on_multiple_fields
51575157

@@ -5178,7 +5178,7 @@ id_int:integer | name_str:keyword | extra1:keyword | other1:keyword | other2:int
51785178
14 | Nina | foo2 | omicron | 15000
51795179
;
51805180

5181-
lookupJoinWithTwoPushableFiltersOnLeft
5181+
lookupJoinWithTwoPushableFiltersOnRight
51825182
required_capability: join_lookup_v12
51835183
required_capability: lookup_join_on_multiple_fields
51845184

x-pack/plugin/esql/src/internalClusterTest/java/org/elasticsearch/xpack/esql/action/LookupFromIndexIT.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
import org.elasticsearch.xpack.esql.core.expression.ReferenceAttribute;
6060
import org.elasticsearch.xpack.esql.core.tree.Source;
6161
import org.elasticsearch.xpack.esql.core.type.DataType;
62+
import org.elasticsearch.xpack.esql.core.type.EsField;
6263
import org.elasticsearch.xpack.esql.enrich.LookupFromIndexOperator;
6364
import org.elasticsearch.xpack.esql.enrich.MatchConfig;
6465
import org.elasticsearch.xpack.esql.expression.predicate.operator.comparison.GreaterThan;
@@ -228,16 +229,11 @@ public void populate(int docCount, List<String> expected, Predicate<Integer> fil
228229
}
229230
}
230231

231-
Expression buildGreaterThanFilter(long value) {
232+
private Expression buildGreaterThanFilter(long value) {
232233
FieldAttribute filterAttribute = new FieldAttribute(
233234
Source.EMPTY,
234235
"l",
235-
new org.elasticsearch.xpack.esql.core.type.EsField(
236-
"l",
237-
org.elasticsearch.xpack.esql.core.type.DataType.LONG,
238-
java.util.Collections.emptyMap(),
239-
true
240-
)
236+
new EsField("l", DataType.LONG, Collections.emptyMap(), true, EsField.TimeSeriesFieldType.NONE)
241237
);
242238
return new GreaterThan(Source.EMPTY, filterAttribute, new Literal(Source.EMPTY, value, DataType.LONG));
243239
}

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/enrich/AbstractLookupService.java

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
import org.elasticsearch.compute.lucene.read.ValuesSourceReaderOperator;
3939
import org.elasticsearch.compute.operator.Driver;
4040
import org.elasticsearch.compute.operator.DriverContext;
41-
import org.elasticsearch.compute.operator.FilterOperator;
4241
import org.elasticsearch.compute.operator.Operator;
4342
import org.elasticsearch.compute.operator.OutputOperator;
4443
import org.elasticsearch.compute.operator.ProjectOperator;
@@ -74,14 +73,10 @@
7473
import org.elasticsearch.xpack.esql.EsqlIllegalArgumentException;
7574
import org.elasticsearch.xpack.esql.core.expression.Alias;
7675
import org.elasticsearch.xpack.esql.core.expression.FieldAttribute;
77-
import org.elasticsearch.xpack.esql.core.expression.FoldContext;
7876
import org.elasticsearch.xpack.esql.core.expression.NamedExpression;
7977
import org.elasticsearch.xpack.esql.core.tree.Source;
8078
import org.elasticsearch.xpack.esql.core.type.DataType;
81-
import org.elasticsearch.xpack.esql.evaluator.EvalMapper;
82-
import org.elasticsearch.xpack.esql.plan.physical.FilterExec;
8379
import org.elasticsearch.xpack.esql.planner.EsPhysicalOperationProviders;
84-
import org.elasticsearch.xpack.esql.planner.Layout;
8580
import org.elasticsearch.xpack.esql.planner.PlannerUtils;
8681
import org.elasticsearch.xpack.esql.plugin.EsqlPlugin;
8782

@@ -351,6 +346,7 @@ private void doLookup(T request, CancellableTask task, ActionListener<List<Page>
351346
warnings
352347
);
353348
releasables.add(queryOperator);
349+
354350
List<Operator> operators = new ArrayList<>();
355351
if (request.extractFields.isEmpty() == false) {
356352
var extractFieldsOperator = extractFieldsOperator(shardContext.context, driverContext, request.extractFields);
@@ -418,27 +414,6 @@ public void onFailure(Exception e) {
418414
}
419415
}
420416

421-
private Operator filterExecOperator(
422-
FilterExec filterExec,
423-
Operator inputOperator, // not needed?
424-
EsPhysicalOperationProviders.ShardContext shardContext,
425-
DriverContext driverContext,
426-
Layout.Builder builder
427-
) {
428-
if (filterExec == null) {
429-
return null;
430-
}
431-
432-
var evaluatorFactory = EvalMapper.toEvaluator(
433-
FoldContext.small()/*is this correct*/,
434-
filterExec.condition(),
435-
builder.build(),
436-
List.of(shardContext)
437-
);
438-
var filterOperatorFactory = new FilterOperator.FilterOperatorFactory(evaluatorFactory);
439-
return filterOperatorFactory.get(driverContext);
440-
}
441-
442417
private static Operator extractFieldsOperator(
443418
EsPhysicalOperationProviders.ShardContext shardContext,
444419
DriverContext driverContext,

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/enrich/ExpressionQueryList.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ public ExpressionQueryList(
5454
}
5555

5656
private void buildPrePostJoinFilter(Expression optionalFilter, ClusterService clusterService) {
57-
// we support a FilterExec as the pre-join filter
58-
// if the filter Exec is not translatable to a QueryBuilder, we will apply it after the join
5957
try {
6058
// If the pre-join filter is a FilterExec, we can convert it to a QueryBuilder
6159
// try to convert it to a QueryBuilder, if not possible apply it after the join
@@ -71,9 +69,9 @@ private void buildPrePostJoinFilter(Expression optionalFilter, ClusterService cl
7169
}
7270
}
7371
// If the filter is not translatable we will not apply it for now
74-
// as performance testing showed no significant difference in performance.
75-
// We can revisit this in the future if needed.
76-
// The filter is optional, so that is OK
72+
// as performance testing showed no performance improvement.
73+
// We can revisit this in the future if needed, once we have more optimized workflow in place.
74+
// The filter is optional, so it is OK to ignore it if it cannot be translated.
7775
} catch (IOException e) {
7876
// as the filter is optional an error in its application will be ignored
7977
logger.error(() -> "Failed to translate optional pre-join filter: [" + optionalFilter + "]", e);

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/enrich/LookupFromIndexService.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ protected LookupEnrichQueryGenerator queryList(
101101
Block inputBlock,
102102
Warnings warnings
103103
) {
104-
105104
List<QueryList> queryLists = new ArrayList<>();
106105
for (int i = 0; i < request.matchFields.size(); i++) {
107106
MatchConfig matchField = request.matchFields.get(i);

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/optimizer/rules/logical/PushDownAndCombineFilters.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,8 @@ private static LogicalPlan pushDownPastJoin(Filter filter, Join join) {
156156
}
157157
// push the right scoped filter down to the right child
158158
if (scoped.rightFilters().isEmpty() == false && (join.right() instanceof Filter == false)) {
159-
// push the filter down to the right child
160159
List<Expression> rightPushableFilters = buildRightPushableFilters(scoped.rightFilters());
161160
if (rightPushableFilters.isEmpty() == false) {
162-
// right = new Filter(right.source(), right, Predicates.combineAnd(rightPushableFilters));
163-
// update the join with the new right child
164-
// join = (Join) join.replaceRight(right);
165161
Expression optionalRightHandSideFilters = Predicates.combineAnd(rightPushableFilters);
166162
join = join.withOptionalRightHandFilters(optionalRightHandSideFilters);
167163
optimizationApplied = true;

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/planner/mapper/LocalMapper.java

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import org.elasticsearch.xpack.esql.plan.logical.join.JoinConfig;
2424
import org.elasticsearch.xpack.esql.plan.logical.join.JoinTypes;
2525
import org.elasticsearch.xpack.esql.plan.physical.EsSourceExec;
26-
import org.elasticsearch.xpack.esql.plan.physical.FilterExec;
2726
import org.elasticsearch.xpack.esql.plan.physical.HashJoinExec;
2827
import org.elasticsearch.xpack.esql.plan.physical.LimitExec;
2928
import org.elasticsearch.xpack.esql.plan.physical.LocalSourceExec;
@@ -112,33 +111,19 @@ private PhysicalPlan mapBinary(BinaryPlan binary) {
112111
join.rightOutputFields()
113112
);
114113
}
115-
if (right instanceof FilterExec filterExec) {
116-
LookupJoinExec lookupJoinExec = getLookupJoinExec(join, filterExec.child(), left, config);
117-
if (lookupJoinExec != null) {
118-
// build the right child as a FilterExec with the original lookupJoinExec.right() as the child
119-
FilterExec newRightChild = filterExec.replaceChild(lookupJoinExec.right());
120-
return lookupJoinExec.replaceChildren(lookupJoinExec.left(), newRightChild);
121-
}
114+
if (right instanceof EsSourceExec source && source.indexMode() == IndexMode.LOOKUP) {
115+
return new LookupJoinExec(
116+
join.source(),
117+
left,
118+
right,
119+
config.leftFields(),
120+
config.rightFields(),
121+
join.rightOutputFields(),
122+
join.optionalRightHandFilters()
123+
);
122124
}
123-
LookupJoinExec lookupJoinExec = getLookupJoinExec(join, right, left, config);
124-
if (lookupJoinExec != null) return lookupJoinExec;
125125
}
126126

127127
return MapperUtils.unsupported(binary);
128128
}
129-
130-
private static LookupJoinExec getLookupJoinExec(Join join, PhysicalPlan right, PhysicalPlan left, JoinConfig config) {
131-
if (right instanceof EsSourceExec source && source.indexMode() == IndexMode.LOOKUP) {
132-
return new LookupJoinExec(
133-
join.source(),
134-
left,
135-
right,
136-
config.leftFields(),
137-
config.rightFields(),
138-
join.rightOutputFields(),
139-
join.optionalRightHandFilters()
140-
);
141-
}
142-
return null;
143-
}
144129
}

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/planner/mapper/Mapper.java

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import org.elasticsearch.xpack.esql.plan.logical.BinaryPlan;
1717
import org.elasticsearch.xpack.esql.plan.logical.Enrich;
1818
import org.elasticsearch.xpack.esql.plan.logical.EsRelation;
19-
import org.elasticsearch.xpack.esql.plan.logical.Filter;
2019
import org.elasticsearch.xpack.esql.plan.logical.Fork;
2120
import org.elasticsearch.xpack.esql.plan.logical.LeafPlan;
2221
import org.elasticsearch.xpack.esql.plan.logical.Limit;
@@ -227,23 +226,18 @@ private PhysicalPlan mapBinary(BinaryPlan bp) {
227226
join.rightOutputFields()
228227
);
229228
}
230-
if (right instanceof FragmentExec fragment) {
231-
boolean isIndexModeLookup = fragment.fragment() instanceof EsRelation relation && relation.indexMode() == IndexMode.LOOKUP;
232-
isIndexModeLookup = isIndexModeLookup
233-
|| fragment.fragment() instanceof Filter filter
234-
&& filter.child() instanceof EsRelation relation
235-
&& relation.indexMode() == IndexMode.LOOKUP;
236-
if (isIndexModeLookup) {
237-
return new LookupJoinExec(
238-
join.source(),
239-
left,
240-
right,
241-
config.leftFields(),
242-
config.rightFields(),
243-
join.rightOutputFields(),
244-
join.optionalRightHandFilters()
245-
);
246-
}
229+
if (right instanceof FragmentExec fragment
230+
&& fragment.fragment() instanceof EsRelation relation
231+
&& relation.indexMode() == IndexMode.LOOKUP) {
232+
return new LookupJoinExec(
233+
join.source(),
234+
left,
235+
right,
236+
config.leftFields(),
237+
config.rightFields(),
238+
join.rightOutputFields(),
239+
join.optionalRightHandFilters()
240+
);
247241
}
248242
}
249243

0 commit comments

Comments
 (0)