Skip to content

Commit 242455f

Browse files
Address more code review comments
1 parent 40c6d7a commit 242455f

File tree

9 files changed

+86
-23
lines changed

9 files changed

+86
-23
lines changed

server/src/main/java/org/elasticsearch/index/mapper/MappedFieldType.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ public Query regexpQuery(
387387
}
388388

389389
/**
390-
* Returns a Lucine pushable Query for the current field
390+
* Returns a Lucene pushable Query for the current field
391391
* For now can only be AutomatonQuery or MatchAllDocsQuery() or MatchNoDocsQuery()
392392
*/
393393
public Query automatonQuery(

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -774,7 +774,7 @@ private Map<String, Object> lookupExplosion(int sensorDataCount, int lookupEntri
774774
}
775775
if (lookupEntries != lookupEntriesToKeep) {
776776
// add a filter to reduce the number of matches
777-
// we add both a Lucine pushable filter and a non-pushable filter
777+
// we add both a Lucene pushable filter and a non-pushable filter
778778
// this is to make sure that even if there are non-pushable filters the pushable filters is still applied
779779
query.append(" | WHERE ABS(filter_key) > -1 AND filter_key < ").append(lookupEntriesToKeep);
780780

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ Page buildPage(int positions, IntVector.Builder positionsBuilder, IntVector.Buil
159159
return page;
160160
}
161161

162-
private Query nextQuery() throws IOException {
162+
private Query nextQuery() {
163163
++queryPosition;
164164
while (isFinished() == false) {
165165
Query query = queryList.getQuery(queryPosition);

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

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5228,6 +5228,69 @@ id_int:integer | name_str:keyword | extra1:keyword | other1:keyword | other2:int
52285228
6 | null | corge | iota | 9000
52295229
;
52305230

5231+
lookupJoinWithCoalesceFilterOnRight
5232+
required_capability: join_lookup_v12
5233+
required_capability: lookup_join_on_multiple_fields
5234+
5235+
FROM multi_column_joinable
5236+
| LOOKUP JOIN multi_column_joinable_lookup ON id_int, is_active_bool
5237+
| WHERE COALESCE(other1, "zeta") == "zeta"
5238+
| KEEP id_int, name_str, extra1, other1, other2
5239+
| SORT id_int, name_str, extra1, other1, other2
5240+
| LIMIT 20
5241+
;
5242+
5243+
warning:Line 2:3: evaluation of [LOOKUP JOIN multi_column_joinable_lookup ON id_int, is_active_bool] failed, treating result as null. Only first 20 failures recorded.
5244+
warning:Line 2:3: java.lang.IllegalArgumentException: LOOKUP JOIN encountered multi-value
5245+
5246+
id_int:integer | name_str:keyword | extra1:keyword | other1:keyword | other2:integer
5247+
[1, 19, 21] | null | zyx | null | null
5248+
4 | David | qux | zeta | 6000
5249+
9 | null | waldo | null | null
5250+
10 | null | fred | null | null
5251+
15 | null | bar2 | null | null
5252+
[17, 18] | null | xyz | null | null
5253+
null | null | plugh | null | null
5254+
;
5255+
5256+
lookupJoinWithIsNullFilterOnRight
5257+
required_capability: join_lookup_v12
5258+
required_capability: lookup_join_on_multiple_fields
5259+
5260+
FROM multi_column_joinable
5261+
| LOOKUP JOIN multi_column_joinable_lookup ON id_int, is_active_bool
5262+
| WHERE other1 IS NULL
5263+
| KEEP id_int, name_str, extra1, other1, other2
5264+
| SORT id_int
5265+
;
5266+
5267+
warning:Line 2:3: evaluation of [LOOKUP JOIN multi_column_joinable_lookup ON id_int, is_active_bool] failed, treating result as null. Only first 20 failures recorded.
5268+
warning:Line 2:3: java.lang.IllegalArgumentException: LOOKUP JOIN encountered multi-value
5269+
5270+
id_int:integer | name_str:keyword | extra1:keyword | other1:keyword | other2:integer
5271+
[1, 19, 21] | null | zyx | null | null
5272+
9 | null | waldo | null | null
5273+
10 | null | fred | null | null
5274+
15 | null | bar2 | null | null
5275+
[17, 18] | null | xyz | null | null
5276+
null | null | plugh | null | null
5277+
;
5278+
5279+
lookupJoinWithIsNullJoinKey
5280+
required_capability: join_lookup_v12
5281+
required_capability: lookup_join_on_multiple_fields
5282+
5283+
FROM multi_column_joinable
5284+
| LOOKUP JOIN multi_column_joinable_lookup ON name_str
5285+
| WHERE name_str IS NULL
5286+
| KEEP id_int, name_str, extra1, other1, other2
5287+
| SORT id_int
5288+
;
5289+
5290+
id_int:integer | name_str:keyword | extra1:keyword | other1:keyword | other2:integer
5291+
null | null | corge | null | null
5292+
;
5293+
52315294
lookupJoinWithMixLeftAndRightFilters
52325295
required_capability: join_lookup_v12
52335296
required_capability: lookup_join_on_multiple_fields

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
* A {@link LookupEnrichQueryGenerator} that combines one or more {@link QueryList}s into a single query.
3838
* Each query in the resulting query will be a conjunction of all queries from the input lists at the same position.
3939
* In addition, we support an optional pre-join filter that will be applied to all queries if it is pushable.
40-
* If the pre-join filter cannot be pushed down to Lucine, it will be ignored.
40+
* If the pre-join filter cannot be pushed down to Lucene, it will be ignored.
4141
*/
4242
public class ExpressionQueryList implements LookupEnrichQueryGenerator {
4343
private static final Logger logger = LogManager.getLogger(ExpressionQueryList.class);
@@ -56,7 +56,7 @@ public ExpressionQueryList(
5656
}
5757
this.queryLists = queryLists;
5858
this.context = context;
59-
buildPrePostJoinFilter(rightPreJoinPlan, clusterService);
59+
buildPreJoinFilter(rightPreJoinPlan, clusterService);
6060
}
6161

6262
private void addToPreJoinFilters(org.elasticsearch.index.query.QueryBuilder query) {
@@ -70,7 +70,7 @@ private void addToPreJoinFilters(org.elasticsearch.index.query.QueryBuilder quer
7070
}
7171
}
7272

73-
private void buildPrePostJoinFilter(PhysicalPlan rightPreJoinPlan, ClusterService clusterService) {
73+
private void buildPreJoinFilter(PhysicalPlan rightPreJoinPlan, ClusterService clusterService) {
7474
if (rightPreJoinPlan instanceof EsQueryExec esQueryExec) {
7575
// this does not happen right now, as we only do local mapping on the lookup node
7676
// so we have EsSourceExec, not esQueryExec
@@ -79,12 +79,12 @@ private void buildPrePostJoinFilter(PhysicalPlan rightPreJoinPlan, ClusterServic
7979
}
8080
} else if (rightPreJoinPlan instanceof FilterExec filterExec) {
8181
List<Expression> candidateRightHandFilters = Predicates.splitAnd(filterExec.condition());
82+
LucenePushdownPredicates lucenePushdownPredicates = LucenePushdownPredicates.from(
83+
SearchContextStats.from(List.of(context)),
84+
new EsqlFlags(clusterService.getClusterSettings())
85+
);
8286
for (Expression filter : candidateRightHandFilters) {
8387
if (filter instanceof TranslationAware translationAware) {
84-
LucenePushdownPredicates lucenePushdownPredicates = LucenePushdownPredicates.from(
85-
SearchContextStats.from(List.of(context)),
86-
new EsqlFlags(clusterService.getClusterSettings())
87-
);
8888
if (TranslationAware.Translatable.YES.equals(translationAware.translatable(lucenePushdownPredicates))) {
8989
addToPreJoinFilters(translationAware.asQuery(lucenePushdownPredicates, TRANSLATOR_HANDLER).toQueryBuilder());
9090
}
@@ -96,10 +96,10 @@ private void buildPrePostJoinFilter(PhysicalPlan rightPreJoinPlan, ClusterServic
9696
}
9797
// call recursively to find other filters that might be present
9898
// either in another FilterExec or in an EsQueryExec
99-
buildPrePostJoinFilter(filterExec.child(), clusterService);
99+
buildPreJoinFilter(filterExec.child(), clusterService);
100100
} else if (rightPreJoinPlan instanceof UnaryExec unaryExec) {
101101
// there can be other nodes in the plan such as FieldExtractExec in the future
102-
buildPrePostJoinFilter(unaryExec.child(), clusterService);
102+
buildPreJoinFilter(unaryExec.child(), clusterService);
103103
}
104104
// else we do nothing, as the filters are optional and we don't want to fail the query if there are any errors
105105
// this also covers the case of rightPreJoinPlan being null

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ protected LookupEnrichQueryGenerator queryList(
123123

124124
PhysicalPlan physicalPlan = request.rightPreJoinPlan;
125125
physicalPlan = localLookupNodePlanning(physicalPlan);
126-
if (queryLists.size() == 1 && (physicalPlan instanceof FilterExec == false)) {
126+
if (queryLists.size() == 1 && physicalPlan instanceof FilterExec == false) {
127127
return queryLists.getFirst();
128128
}
129129
return new ExpressionQueryList(queryLists, context, physicalPlan, clusterService);
@@ -135,7 +135,7 @@ protected LookupEnrichQueryGenerator queryList(
135135
* For now, we will just do mapping of the logical plan to physical plan
136136
* In the future we can also do local physical and logical optimizations
137137
*/
138-
private PhysicalPlan localLookupNodePlanning(PhysicalPlan physicalPlan) {
138+
private static PhysicalPlan localLookupNodePlanning(PhysicalPlan physicalPlan) {
139139
if (physicalPlan instanceof FragmentExec fragmentExec) {
140140
try {
141141
LocalMapper localMapper = new LocalMapper();

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,15 @@ private static LogicalPlan pushDownPastJoin(Filter filter, Join join, FoldContex
168168
if (rightPushableFilters.isEmpty() == false) {
169169
if (join.right() instanceof Filter existingRightFilter) {
170170
// merge the unique AND filter components from rightPushableFilters and existingRightFilter.condition()
171+
171172
List<Expression> existingFilters = new ArrayList<>(Predicates.splitAnd(existingRightFilter.condition()));
173+
int sizeBefore = existingFilters.size();
172174
rightPushableFilters.stream().filter(e -> existingFilters.contains(e) == false).forEach(existingFilters::add);
173-
right = existingRightFilter.with(Predicates.combineAnd(existingFilters));
174-
join = (Join) join.replaceRight(right);
175-
optimizationApplied = true;
175+
if (sizeBefore != existingFilters.size()) {
176+
right = existingRightFilter.with(Predicates.combineAnd(existingFilters));
177+
join = (Join) join.replaceRight(right);
178+
optimizationApplied = true;
179+
} // else nothing needs to be updated
176180
} else {
177181
// create a new filter on top of the right child
178182
right = new Filter(right.source(), right, Predicates.combineAnd(rightPushableFilters));

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public class EsqlFlags {
4141
Setting.Property.NodeScope,
4242
Setting.Property.Dynamic
4343
);
44-
public static List<Setting<?>> allEsqlFlagsSettings = List.of(ESQL_STRING_LIKE_ON_INDEX, ESQL_ROUNDTO_PUSHDOWN_THRESHOLD);
44+
public static List<Setting<?>> ALL_ESQL_FLAGS_SETTINGS = List.of(ESQL_STRING_LIKE_ON_INDEX, ESQL_ROUNDTO_PUSHDOWN_THRESHOLD);
4545
private final boolean stringLikeOnIndex;
4646

4747
private final int roundToPushdownThreshold;
@@ -82,8 +82,4 @@ public boolean stringLikeOnIndex() {
8282
public int roundToPushdownThreshold() {
8383
return roundToPushdownThreshold;
8484
}
85-
86-
public static List<Setting<?>> listAll() {
87-
return allEsqlFlagsSettings;
88-
}
8985
}

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/enrich/LookupFromIndexOperatorTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ private LookupFromIndexService lookupService(DriverContext mainContext) {
257257
boolean beCranky = mainContext.bigArrays().breakerService() instanceof CrankyCircuitBreakerService;
258258
DiscoveryNode localNode = DiscoveryNodeUtils.create("node", "node");
259259
var builtInClusterSettings = new HashSet<>(ClusterSettings.BUILT_IN_CLUSTER_SETTINGS);
260-
builtInClusterSettings.addAll(EsqlFlags.listAll());
260+
builtInClusterSettings.addAll(EsqlFlags.ALL_ESQL_FLAGS_SETTINGS);
261261
ClusterService clusterService = ClusterServiceUtils.createClusterService(
262262
threadPool,
263263
localNode,

0 commit comments

Comments
 (0)