Skip to content

Commit 1251218

Browse files
authored
Reword lookup join error messages (elastic#129312) (elastic#129484)
(cherry picked from commit 85e3fb7)
1 parent f8df526 commit 1251218

File tree

6 files changed

+46
-10
lines changed

6 files changed

+46
-10
lines changed

x-pack/plugin/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,8 @@ tasks.named("yamlRestTestV7CompatTransform").configure({ task ->
228228
task.skipTest("esql/40_unsupported_types/unsupported with sort", "TODO: support for subset of metric fields")
229229
task.skipTest("esql/63_enrich_int_range/Invalid age as double", "TODO: require disable allow_partial_results")
230230
task.skipTest("esql/191_lookup_join_on_datastreams/data streams not supported in LOOKUP JOIN", "Added support for aliases in JOINs")
231+
task.skipTest("esql/190_lookup_join/non-lookup index", "Error message changed")
232+
task.skipTest("esql/192_lookup_join_on_aliases/alias-pattern-multiple", "Error message changed")
231233
})
232234

233235

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -937,6 +937,11 @@ public enum Cap {
937937
*/
938938
ENABLE_LOOKUP_JOIN_ON_ALIASES,
939939

940+
/**
941+
* Lookup error messages were updated to make them a bit easier to understand.
942+
*/
943+
UPDATE_LOOKUP_JOIN_ERROR_MESSAGES,
944+
940945
/**
941946
* Allow lookup join on mixed numeric fields, among byte, short, int, long, half_float, scaled_float, float and double.
942947
*/

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/plan/logical/join/LookupJoin.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,24 @@ public void postAnalysisVerification(Failures failures) {
9090
var indexNameWithModes = esr.indexNameWithModes();
9191
if (indexNameWithModes.size() != 1) {
9292
failures.add(
93-
fail(esr, "invalid [{}] resolution in lookup mode to [{}] indices", esr.indexPattern(), indexNameWithModes.size())
93+
fail(
94+
esr,
95+
"Lookup Join requires a single lookup mode index; [{}] resolves to [{}] indices",
96+
esr.indexPattern(),
97+
indexNameWithModes.size()
98+
)
9499
);
95-
} else if (indexNameWithModes.values().iterator().next() != IndexMode.LOOKUP) {
100+
return;
101+
}
102+
var indexAndMode = indexNameWithModes.entrySet().iterator().next();
103+
if (indexAndMode.getValue() != IndexMode.LOOKUP) {
96104
failures.add(
97105
fail(
98106
esr,
99-
"invalid [{}] resolution in lookup mode to an index in [{}] mode",
107+
"Lookup Join requires a single lookup mode index; [{}] resolves to [{}] in [{}] mode",
100108
esr.indexPattern(),
101-
indexNameWithModes.values().iterator().next()
109+
indexAndMode.getKey(),
110+
indexAndMode.getValue()
102111
)
103112
);
104113
}

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/analysis/AnalyzerTests.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2298,12 +2298,18 @@ public void testLookupJoinIndexMode() {
22982298
AnalyzerTestUtils.analyzer(lookupResolutionAsIndex, indexResolutionAsLookup)
22992299
)
23002300
);
2301-
assertThat(e.getMessage(), containsString("1:70: invalid [test] resolution in lookup mode to an index in [standard] mode"));
2301+
assertThat(
2302+
e.getMessage(),
2303+
containsString("1:70: Lookup Join requires a single lookup mode index; [test] resolves to [test] in [standard] mode")
2304+
);
23022305
e = expectThrows(
23032306
VerificationException.class,
23042307
() -> analyze("FROM test | LOOKUP JOIN test ON languages", AnalyzerTestUtils.analyzer(indexResolution, indexResolutionAsLookup))
23052308
);
2306-
assertThat(e.getMessage(), containsString("1:25: invalid [test] resolution in lookup mode to an index in [standard] mode"));
2309+
assertThat(
2310+
e.getMessage(),
2311+
containsString("1:25: Lookup Join requires a single lookup mode index; [test] resolves to [test] in [standard] mode")
2312+
);
23072313
}
23082314

23092315
public void testImplicitCasting() {

x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/esql/190_lookup_join.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,22 @@ basic:
7878
- match: {values.1: [2, "yellow"]}
7979

8080
---
81-
non-lookup index:
81+
fails with non-lookup index:
82+
- requires:
83+
capabilities:
84+
- method: POST
85+
path: /_query
86+
parameters: []
87+
capabilities: [update_lookup_join_error_messages]
88+
reason: "checks updated error messages"
8289
- do:
8390
esql.query:
8491
body:
8592
query: 'FROM test-lookup-1 | SORT key | LOOKUP JOIN test ON key | LIMIT 3'
8693
catch: "bad_request"
8794

8895
- match: { error.type: "verification_exception" }
89-
- contains: { error.reason: "Found 1 problem\nline 1:45: invalid [test] resolution in lookup mode to an index in [standard] mode" }
96+
- contains: { error.reason: "Found 1 problem\nline 1:45: Lookup Join requires a single lookup mode index; [test] resolves to [test] in [standard] mode" }
9097

9198
---
9299
pattern-multiple:

x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/esql/192_lookup_join_on_aliases.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,15 +186,22 @@ alias-repeated-index:
186186
- match: {values.1: [2, "yellow"]}
187187

188188
---
189-
alias-pattern-multiple:
189+
fails when alias or pattern resolves to multiple:
190+
- requires:
191+
capabilities:
192+
- method: POST
193+
path: /_query
194+
parameters: []
195+
capabilities: [update_lookup_join_error_messages]
196+
reason: "checks updated error messages"
190197
- do:
191198
esql.query:
192199
body:
193200
query: 'FROM test-lookup-1 | LOOKUP JOIN test-lookup-alias-pattern-multiple ON key'
194201
catch: "bad_request"
195202

196203
- match: { error.type: "verification_exception" }
197-
- contains: { error.reason: "Found 1 problem\nline 1:34: invalid [test-lookup-alias-pattern-multiple] resolution in lookup mode to [4] indices" }
204+
- contains: { error.reason: "Found 1 problem\nline 1:34: Lookup Join requires a single lookup mode index; [test-lookup-alias-pattern-multiple] resolves to [4] indices" }
198205

199206
---
200207
alias-pattern-single:

0 commit comments

Comments
 (0)