From a2519547f5c1b97b5fea562ea7c3df5f1a0b721f Mon Sep 17 00:00:00 2001 From: Luigi Dell'Aquila Date: Wed, 4 Jun 2025 15:22:47 +0200 Subject: [PATCH 1/2] ES|QL: Split JOIN yaml tests so that non-alias queries run also on bwc (#128884) --- .../xpack/esql/action/EsqlCapabilities.java | 2 +- .../esql/enrich/LookupFromIndexService.java | 2 +- .../test/esql/190_lookup_join.yml | 85 +------ .../test/esql/192_lookup_join_on_aliases.yml | 211 ++++++++++++++++++ 4 files changed, 214 insertions(+), 86 deletions(-) create mode 100644 x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/esql/192_lookup_join_on_aliases.yml diff --git a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/action/EsqlCapabilities.java b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/action/EsqlCapabilities.java index 67b6bd0d4fe4b..76e54de0b6c1f 100644 --- a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/action/EsqlCapabilities.java +++ b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/action/EsqlCapabilities.java @@ -904,7 +904,7 @@ public enum Cap { /** * Enable support for index aliases in lookup joins */ - ENABLE_LOOKUP_JOIN_ON_ALIASES(JOIN_LOOKUP_V12.isEnabled()), + ENABLE_LOOKUP_JOIN_ON_ALIASES, /** * Allow lookup join on mixed numeric fields, among byte, short, int, long, half_float, scaled_float, float and double. 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 3512b45960784..a2b4ba12b0a69 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 @@ -190,7 +190,7 @@ public void writeTo(StreamOutput out) throws IOException { if (out.getTransportVersion().onOrAfter(TransportVersions.JOIN_ON_ALIASES_8_19)) { out.writeString(indexPattern); } else if (indexPattern.equals(shardId.getIndexName()) == false) { - throw new EsqlIllegalArgumentException("Aliases and index patterns are not allowed for LOOKUP JOIN []", indexPattern); + throw new EsqlIllegalArgumentException("Aliases and index patterns are not allowed for LOOKUP JOIN [{}]", indexPattern); } out.writeString(inputDataType.typeName()); diff --git a/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/esql/190_lookup_join.yml b/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/esql/190_lookup_join.yml index 300ca80af56c4..ee1ef599971e0 100644 --- a/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/esql/190_lookup_join.yml +++ b/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/esql/190_lookup_join.yml @@ -6,7 +6,7 @@ setup: - method: POST path: /_query parameters: [] - capabilities: [join_lookup_v12, enable_lookup_join_on_aliases] + capabilities: [join_lookup_v12] reason: "uses LOOKUP JOIN" - do: indices.create: @@ -44,19 +44,6 @@ setup: type: long color: type: keyword - - do: - indices.update_aliases: - body: - actions: - - add: - index: test-lookup-1 - alias: test-lookup-alias - - add: - index: test-lookup-* - alias: test-lookup-alias-pattern-multiple - - add: - index: test-lookup-1* - alias: test-lookup-alias-pattern-single - do: bulk: index: "test" @@ -101,76 +88,6 @@ non-lookup index: - match: { error.type: "verification_exception" } - contains: { error.reason: "Found 1 problem\nline 1:45: invalid [test] resolution in lookup mode to an index in [standard] mode" } ---- - -"Alias as lookup index": - - skip: - awaits_fix: "LOOKUP JOIN does not support index aliases for now" - - do: - esql.query: - body: - query: 'FROM test | SORT key | LOOKUP JOIN test-lookup-alias ON key | LIMIT 3' - - - match: {columns.0.name: "key"} - - match: {columns.0.type: "long"} - - match: {columns.1.name: "color"} - - match: {columns.1.type: "keyword"} - - match: {values.0: [1, "cyan"]} - - match: {values.1: [2, "yellow"]} - ---- -alias-repeated-alias: - - do: - esql.query: - body: - query: 'FROM test-lookup-alias | SORT key | LOOKUP JOIN test-lookup-alias ON key | LIMIT 3' - - - match: {columns.0.name: "key"} - - match: {columns.0.type: "long"} - - match: {columns.1.name: "color"} - - match: {columns.1.type: "keyword"} - - match: {values.0: [1, "cyan"]} - - match: {values.1: [2, "yellow"]} - ---- -alias-repeated-index: - - do: - esql.query: - body: - query: 'FROM test-lookup-1 | SORT key | LOOKUP JOIN test-lookup-alias ON key | LIMIT 3' - - - match: {columns.0.name: "key"} - - match: {columns.0.type: "long"} - - match: {columns.1.name: "color"} - - match: {columns.1.type: "keyword"} - - match: {values.0: [1, "cyan"]} - - match: {values.1: [2, "yellow"]} - ---- -alias-pattern-multiple: - - do: - esql.query: - body: - query: 'FROM test-lookup-1 | LOOKUP JOIN test-lookup-alias-pattern-multiple ON key' - catch: "bad_request" - - - match: { error.type: "verification_exception" } - - contains: { error.reason: "Found 1 problem\nline 1:34: invalid [test-lookup-alias-pattern-multiple] resolution in lookup mode to [2] indices" } - ---- -alias-pattern-single: - - do: - esql.query: - body: - query: 'FROM test | SORT key | LOOKUP JOIN test-lookup-alias-pattern-single ON key | LIMIT 3' - - - match: {columns.0.name: "key"} - - match: {columns.0.type: "long"} - - match: {columns.1.name: "color"} - - match: {columns.1.type: "keyword"} - - match: {values.0: [1, "cyan"]} - - match: {values.1: [2, "yellow"]} - --- pattern-multiple: - do: diff --git a/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/esql/192_lookup_join_on_aliases.yml b/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/esql/192_lookup_join_on_aliases.yml new file mode 100644 index 0000000000000..5c8b85ed82c3b --- /dev/null +++ b/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/esql/192_lookup_join_on_aliases.yml @@ -0,0 +1,211 @@ +--- +setup: + - requires: + test_runner_features: [capabilities, contains, allowed_warnings] + capabilities: + - method: POST + path: /_query + parameters: [] + capabilities: [enable_lookup_join_on_aliases] + reason: "uses LOOKUP JOIN on aliases" + - do: + indices.create: + index: test + body: + mappings: + properties: + key: + type: long + color: + type: keyword + - do: + indices.create: + index: test-mv + body: + mappings: + properties: + key: + type: long + color: + type: keyword + - do: + indices.create: + index: test-lookup-1 + body: + settings: + index: + mode: lookup + mappings: + properties: + key: + type: long + color: + type: keyword + - do: + indices.create: + index: test-lookup-2 + body: + settings: + index: + mode: lookup + mappings: + properties: + key: + type: long + color: + type: keyword + - do: + indices.create: + index: test-lookup-mv + body: + settings: + index: + mode: lookup + mappings: + properties: + key: + type: long + color: + type: keyword + - do: + indices.create: + index: test-lookup-no-key + body: + settings: + index: + mode: lookup + mappings: + properties: + no-key: + type: long + color: + type: keyword + - do: + indices.update_aliases: + body: + actions: + - add: + index: test-lookup-1 + alias: test-lookup-alias + - add: + index: test-lookup-* + alias: test-lookup-alias-pattern-multiple + - add: + index: test-lookup-1* + alias: test-lookup-alias-pattern-single + - do: + bulk: + index: "test" + refresh: true + body: + - { "index": { } } + - { "key": 1, "color": "red" } + - { "index": { } } + - { "key": 2, "color": "blue" } + - do: + bulk: + index: "test-lookup-1" + refresh: true + body: + - { "index": { } } + - { "key": 1, "color": "cyan" } + - { "index": { } } + - { "key": 2, "color": "yellow" } + - do: + bulk: + index: "test-mv" + refresh: true + body: + - { "index": { } } + - { "key": 1, "color": "red" } + - { "index": { } } + - { "key": 2, "color": "blue" } + - { "index": { } } + - { "key": [0, 1, 2], "color": null } + - do: + bulk: + index: "test-lookup-mv" + refresh: true + body: + - { "index": { } } + - { "key": 1, "color": "cyan" } + - { "index": { } } + - { "key": 2, "color": "yellow" } + - { "index": { } } + - { "key": [0, 1, 2], "color": "green" } + - do: + bulk: + index: "test-lookup-no-key" + refresh: true + body: + - { "index": { } } + - { "no-key": 1, "color": "cyan" } + - { "index": { } } + - { "no-key": 2, "color": "yellow" } + +--- +alias-as-lookup-index: + - do: + esql.query: + body: + query: 'FROM test | SORT key | LOOKUP JOIN test-lookup-alias ON key | LIMIT 3' + + - match: {columns.0.name: "key"} + - match: {columns.0.type: "long"} + - match: {columns.1.name: "color"} + - match: {columns.1.type: "keyword"} + - match: {values.0: [1, "cyan"]} + - match: {values.1: [2, "yellow"]} + +--- +alias-repeated-alias: + - do: + esql.query: + body: + query: 'FROM test-lookup-alias | SORT key | LOOKUP JOIN test-lookup-alias ON key | LIMIT 3' + + - match: {columns.0.name: "key"} + - match: {columns.0.type: "long"} + - match: {columns.1.name: "color"} + - match: {columns.1.type: "keyword"} + - match: {values.0: [1, "cyan"]} + - match: {values.1: [2, "yellow"]} + +--- +alias-repeated-index: + - do: + esql.query: + body: + query: 'FROM test-lookup-1 | SORT key | LOOKUP JOIN test-lookup-alias ON key | LIMIT 3' + + - match: {columns.0.name: "key"} + - match: {columns.0.type: "long"} + - match: {columns.1.name: "color"} + - match: {columns.1.type: "keyword"} + - match: {values.0: [1, "cyan"]} + - match: {values.1: [2, "yellow"]} + +--- +alias-pattern-multiple: + - do: + esql.query: + body: + query: 'FROM test-lookup-1 | LOOKUP JOIN test-lookup-alias-pattern-multiple ON key' + catch: "bad_request" + + - match: { error.type: "verification_exception" } + - contains: { error.reason: "Found 1 problem\nline 1:34: invalid [test-lookup-alias-pattern-multiple] resolution in lookup mode to [2] indices" } + +--- +alias-pattern-single: + - do: + esql.query: + body: + query: 'FROM test | SORT key | LOOKUP JOIN test-lookup-alias-pattern-single ON key | LIMIT 3' + + - match: {columns.0.name: "key"} + - match: {columns.0.type: "long"} + - match: {columns.1.name: "color"} + - match: {columns.1.type: "keyword"} + - match: {values.0: [1, "cyan"]} + - match: {values.1: [2, "yellow"]} From c7a677a74842be5c3782ab6ec1badcf9804c3fa6 Mon Sep 17 00:00:00 2001 From: Luigi Dell'Aquila Date: Wed, 4 Jun 2025 16:50:59 +0200 Subject: [PATCH 2/2] Fix test --- .../rest-api-spec/test/esql/192_lookup_join_on_aliases.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/esql/192_lookup_join_on_aliases.yml b/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/esql/192_lookup_join_on_aliases.yml index 5c8b85ed82c3b..c77f92e72c159 100644 --- a/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/esql/192_lookup_join_on_aliases.yml +++ b/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/esql/192_lookup_join_on_aliases.yml @@ -194,7 +194,7 @@ alias-pattern-multiple: catch: "bad_request" - match: { error.type: "verification_exception" } - - contains: { error.reason: "Found 1 problem\nline 1:34: invalid [test-lookup-alias-pattern-multiple] resolution in lookup mode to [2] indices" } + - contains: { error.reason: "Found 1 problem\nline 1:34: invalid [test-lookup-alias-pattern-multiple] resolution in lookup mode to [4] indices" } --- alias-pattern-single: