Skip to content

Commit 0c3d47d

Browse files
authored
ESQL: Fix validation NPE in Enrich and add extra @nullable annotations (#128260)
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 7e4d96e commit 0c3d47d

File tree

4 files changed

+16
-7
lines changed

4 files changed

+16
-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
@@ -182,7 +182,7 @@ protected abstract QueryList queryList(
182182
T request,
183183
SearchExecutionContext context,
184184
Block inputBlock,
185-
DataType inputDataType,
185+
@Nullable DataType inputDataType,
186186
Warnings warnings
187187
);
188188

@@ -200,7 +200,7 @@ protected static QueryList termQueryList(
200200
MappedFieldType field,
201201
SearchExecutionContext searchExecutionContext,
202202
Block block,
203-
DataType inputDataType
203+
@Nullable DataType inputDataType
204204
) {
205205
return switch (inputDataType) {
206206
case IP -> QueryList.ipTermQueryList(field, searchExecutionContext, (BytesRefBlock) block);

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.elasticsearch.compute.data.Page;
2525
import org.elasticsearch.compute.operator.Warnings;
2626
import org.elasticsearch.compute.operator.lookup.QueryList;
27+
import org.elasticsearch.core.Nullable;
2728
import org.elasticsearch.core.Releasables;
2829
import org.elasticsearch.index.mapper.MappedFieldType;
2930
import org.elasticsearch.index.mapper.RangeFieldMapper;
@@ -103,7 +104,7 @@ protected QueryList queryList(
103104
TransportRequest request,
104105
SearchExecutionContext context,
105106
Block inputBlock,
106-
DataType inputDataType,
107+
@Nullable DataType inputDataType,
107108
Warnings warnings
108109
) {
109110
MappedFieldType fieldType = context.getFieldType(request.matchField);
@@ -128,8 +129,8 @@ protected LookupResponse readLookupResponse(StreamInput in, BlockFactory blockFa
128129
return new LookupResponse(in, blockFactory);
129130
}
130131

131-
private static void validateTypes(DataType inputDataType, MappedFieldType fieldType) {
132-
if (fieldType instanceof RangeFieldMapper.RangeFieldType rangeType) {
132+
private static void validateTypes(@Nullable DataType inputDataType, MappedFieldType fieldType) {
133+
if (fieldType instanceof RangeFieldMapper.RangeFieldType rangeType && inputDataType != null) {
133134
// For range policy types, the ENRICH index field type will be one of a list of supported range types,
134135
// which need to match the input data type (eg. ip-range -> ip, date-range -> date, etc.)
135136
if (rangeTypesCompatible(rangeType.rangeType(), inputDataType) == false) {
@@ -142,7 +143,7 @@ private static void validateTypes(DataType inputDataType, MappedFieldType fieldT
142143
// For geo_match, type validation is done earlier, in the Analyzer.
143144
}
144145

145-
private static boolean rangeTypesCompatible(RangeType rangeType, DataType inputDataType) {
146+
private static boolean rangeTypesCompatible(RangeType rangeType, @Nullable DataType inputDataType) {
146147
if (inputDataType.noText() == DataType.KEYWORD) {
147148
// We allow runtime parsing of string types to numeric types
148149
return true;

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.elasticsearch.compute.data.Page;
2020
import org.elasticsearch.compute.operator.Warnings;
2121
import org.elasticsearch.compute.operator.lookup.QueryList;
22+
import org.elasticsearch.core.Nullable;
2223
import org.elasticsearch.core.Releasables;
2324
import org.elasticsearch.index.query.SearchExecutionContext;
2425
import org.elasticsearch.index.shard.ShardId;
@@ -83,7 +84,7 @@ protected QueryList queryList(
8384
TransportRequest request,
8485
SearchExecutionContext context,
8586
Block inputBlock,
86-
DataType inputDataType,
87+
@Nullable DataType inputDataType,
8788
Warnings warnings
8889
) {
8990
return termQueryList(context.getFieldType(request.matchField), context, inputBlock, inputDataType).onlySingleValues(

0 commit comments

Comments
 (0)