Skip to content

Commit b886a86

Browse files
authored
ESQL: Fix validation NPE in Enrich and add extra @nullable annotations (#128260) (#128452)
Fixes #126253 Fixes #126297 `inputDataType` may be null when in mixed cluster (<8.14). So `validateTypes()` should take that into account. Similar fix to #116583
1 parent deb0e61 commit b886a86

File tree

4 files changed

+26
-7
lines changed

4 files changed

+26
-7
lines changed

docs/changelog/128260.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
pr: 128260
2+
summary: Fix validation NPE in Enrich and add extra @Nullable annotations
3+
area: ES|QL
4+
type: bug
5+
issues:
6+
- 126297
7+
- 126253

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ public ThreadContext getThreadContext() {
177177
/**
178178
* Build a list of queries to perform inside the actual lookup.
179179
*/
180-
protected abstract QueryList queryList(T request, SearchExecutionContext context, Block inputBlock, DataType inputDataType);
180+
protected abstract QueryList queryList(T request, SearchExecutionContext context, Block inputBlock, @Nullable DataType inputDataType);
181181

182182
/**
183183
* Build the response.
@@ -193,7 +193,7 @@ protected static QueryList termQueryList(
193193
MappedFieldType field,
194194
SearchExecutionContext searchExecutionContext,
195195
Block block,
196-
DataType inputDataType
196+
@Nullable DataType inputDataType
197197
) {
198198
if (inputDataType == null) {
199199
return QueryList.rawTermQueryList(field, searchExecutionContext, block);

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.elasticsearch.compute.data.BlockStreamInput;
2424
import org.elasticsearch.compute.data.Page;
2525
import org.elasticsearch.compute.operator.lookup.QueryList;
26+
import org.elasticsearch.core.Nullable;
2627
import org.elasticsearch.core.Releasables;
2728
import org.elasticsearch.index.mapper.MappedFieldType;
2829
import org.elasticsearch.index.mapper.RangeFieldMapper;
@@ -98,7 +99,12 @@ protected TransportRequest transportRequest(EnrichLookupService.Request request,
9899
}
99100

100101
@Override
101-
protected QueryList queryList(TransportRequest request, SearchExecutionContext context, Block inputBlock, DataType inputDataType) {
102+
protected QueryList queryList(
103+
TransportRequest request,
104+
SearchExecutionContext context,
105+
Block inputBlock,
106+
@Nullable DataType inputDataType
107+
) {
102108
MappedFieldType fieldType = context.getFieldType(request.matchField);
103109
validateTypes(inputDataType, fieldType);
104110
return switch (request.matchType) {
@@ -121,8 +127,8 @@ protected LookupResponse readLookupResponse(StreamInput in, BlockFactory blockFa
121127
return new LookupResponse(in, blockFactory);
122128
}
123129

124-
private static void validateTypes(DataType inputDataType, MappedFieldType fieldType) {
125-
if (fieldType instanceof RangeFieldMapper.RangeFieldType rangeType) {
130+
private static void validateTypes(@Nullable DataType inputDataType, MappedFieldType fieldType) {
131+
if (fieldType instanceof RangeFieldMapper.RangeFieldType rangeType && inputDataType != null) {
126132
// For range policy types, the ENRICH index field type will be one of a list of supported range types,
127133
// which need to match the input data type (eg. ip-range -> ip, date-range -> date, etc.)
128134
if (rangeTypesCompatible(rangeType.rangeType(), inputDataType) == false) {
@@ -135,7 +141,7 @@ private static void validateTypes(DataType inputDataType, MappedFieldType fieldT
135141
// For geo_match, type validation is done earlier, in the Analyzer.
136142
}
137143

138-
private static boolean rangeTypesCompatible(RangeType rangeType, DataType inputDataType) {
144+
private static boolean rangeTypesCompatible(RangeType rangeType, @Nullable DataType inputDataType) {
139145
if (inputDataType.noText() == DataType.KEYWORD) {
140146
// We allow runtime parsing of string types to numeric types
141147
return true;

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import org.elasticsearch.compute.data.BlockStreamInput;
1919
import org.elasticsearch.compute.data.Page;
2020
import org.elasticsearch.compute.operator.lookup.QueryList;
21+
import org.elasticsearch.core.Nullable;
2122
import org.elasticsearch.core.Releasables;
2223
import org.elasticsearch.index.query.SearchExecutionContext;
2324
import org.elasticsearch.index.shard.ShardId;
@@ -76,7 +77,12 @@ protected TransportRequest transportRequest(LookupFromIndexService.Request reque
7677
}
7778

7879
@Override
79-
protected QueryList queryList(TransportRequest request, SearchExecutionContext context, Block inputBlock, DataType inputDataType) {
80+
protected QueryList queryList(
81+
TransportRequest request,
82+
SearchExecutionContext context,
83+
Block inputBlock,
84+
@Nullable DataType inputDataType
85+
) {
8086
return termQueryList(context.getFieldType(request.matchField), context, inputBlock, inputDataType).onlySingleValues();
8187
}
8288

0 commit comments

Comments
 (0)