From b05734bd9a89995cc76bc3893c9856ba20f67f3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Cea=20Fontenla?= Date: Wed, 21 May 2025 15:34:15 +0200 Subject: [PATCH 1/2] ESQL: Fix validation NPE in Enrich and add extra @Nullable annotations --- .../xpack/esql/enrich/AbstractLookupService.java | 4 ++-- .../xpack/esql/enrich/EnrichLookupService.java | 9 +++++---- .../xpack/esql/enrich/LookupFromIndexService.java | 3 ++- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/enrich/AbstractLookupService.java b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/enrich/AbstractLookupService.java index 42d03f4e1b161..012e82ee10bd2 100644 --- a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/enrich/AbstractLookupService.java +++ b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/enrich/AbstractLookupService.java @@ -182,7 +182,7 @@ protected abstract QueryList queryList( T request, SearchExecutionContext context, Block inputBlock, - DataType inputDataType, + @Nullable DataType inputDataType, Warnings warnings ); @@ -200,7 +200,7 @@ protected static QueryList termQueryList( MappedFieldType field, SearchExecutionContext searchExecutionContext, Block block, - DataType inputDataType + @Nullable DataType inputDataType ) { return switch (inputDataType) { case IP -> QueryList.ipTermQueryList(field, searchExecutionContext, (BytesRefBlock) block); diff --git a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/enrich/EnrichLookupService.java b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/enrich/EnrichLookupService.java index 67783c2556cd6..999bdef0427ea 100644 --- a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/enrich/EnrichLookupService.java +++ b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/enrich/EnrichLookupService.java @@ -24,6 +24,7 @@ import org.elasticsearch.compute.data.Page; import org.elasticsearch.compute.operator.Warnings; import org.elasticsearch.compute.operator.lookup.QueryList; +import org.elasticsearch.core.Nullable; import org.elasticsearch.core.Releasables; import org.elasticsearch.index.mapper.MappedFieldType; import org.elasticsearch.index.mapper.RangeFieldMapper; @@ -103,7 +104,7 @@ protected QueryList queryList( TransportRequest request, SearchExecutionContext context, Block inputBlock, - DataType inputDataType, + @Nullable DataType inputDataType, Warnings warnings ) { MappedFieldType fieldType = context.getFieldType(request.matchField); @@ -128,8 +129,8 @@ protected LookupResponse readLookupResponse(StreamInput in, BlockFactory blockFa return new LookupResponse(in, blockFactory); } - private static void validateTypes(DataType inputDataType, MappedFieldType fieldType) { - if (fieldType instanceof RangeFieldMapper.RangeFieldType rangeType) { + private static void validateTypes(@Nullable DataType inputDataType, MappedFieldType fieldType) { + if (fieldType instanceof RangeFieldMapper.RangeFieldType rangeType && inputDataType != null) { // For range policy types, the ENRICH index field type will be one of a list of supported range types, // which need to match the input data type (eg. ip-range -> ip, date-range -> date, etc.) if (rangeTypesCompatible(rangeType.rangeType(), inputDataType) == false) { @@ -142,7 +143,7 @@ private static void validateTypes(DataType inputDataType, MappedFieldType fieldT // For geo_match, type validation is done earlier, in the Analyzer. } - private static boolean rangeTypesCompatible(RangeType rangeType, DataType inputDataType) { + private static boolean rangeTypesCompatible(RangeType rangeType, @Nullable DataType inputDataType) { if (inputDataType.noText() == DataType.KEYWORD) { // We allow runtime parsing of string types to numeric types return true; diff --git a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/enrich/LookupFromIndexService.java b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/enrich/LookupFromIndexService.java index b372570ed5026..a7d62ed5d5b65 100644 --- a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/enrich/LookupFromIndexService.java +++ b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/enrich/LookupFromIndexService.java @@ -19,6 +19,7 @@ import org.elasticsearch.compute.data.Page; import org.elasticsearch.compute.operator.Warnings; import org.elasticsearch.compute.operator.lookup.QueryList; +import org.elasticsearch.core.Nullable; import org.elasticsearch.core.Releasables; import org.elasticsearch.index.query.SearchExecutionContext; import org.elasticsearch.index.shard.ShardId; @@ -83,7 +84,7 @@ protected QueryList queryList( TransportRequest request, SearchExecutionContext context, Block inputBlock, - DataType inputDataType, + @Nullable DataType inputDataType, Warnings warnings ) { return termQueryList(context.getFieldType(request.matchField), context, inputBlock, inputDataType).onlySingleValues( From 539a8ed2c95095a5b8f07c3d615e36951d6fb383 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Cea=20Fontenla?= Date: Wed, 21 May 2025 17:17:09 +0200 Subject: [PATCH 2/2] Update docs/changelog/128260.yaml --- docs/changelog/128260.yaml | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 docs/changelog/128260.yaml diff --git a/docs/changelog/128260.yaml b/docs/changelog/128260.yaml new file mode 100644 index 0000000000000..059e514685601 --- /dev/null +++ b/docs/changelog/128260.yaml @@ -0,0 +1,7 @@ +pr: 128260 +summary: Fix validation NPE in Enrich and add extra @Nullable annotations +area: ES|QL +type: bug +issues: + - 126297 + - 126253