Skip to content

Commit 7ed3546

Browse files
Fix cases with mix of constant_keyword and other types
1 parent 9f3beb1 commit 7ed3546

File tree

2 files changed

+104
-2
lines changed

2 files changed

+104
-2
lines changed

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/stats/SearchContextStats.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,8 @@ public String constantValue(String name) {
338338
} else if (thisVal.equals(val) == false) {
339339
return null;
340340
}
341+
} else {
342+
return null;
341343
}
342344
}
343345
return val;

x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/esql/30_types.yml

Lines changed: 102 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,27 @@ constant_keyword:
4949
- { "index": { } }
5050
- { "color": "blue" }
5151

52+
- do:
53+
indices.create:
54+
index: test_3
55+
body:
56+
mappings:
57+
properties:
58+
kind:
59+
type: keyword
60+
color:
61+
type: keyword
62+
63+
- do:
64+
bulk:
65+
index: test_3
66+
refresh: true
67+
body:
68+
- { "index": { } }
69+
- { "kind":"not a constant", "color": "pink" }
70+
- { "index": { } }
71+
- { "kind": "still no constant", "color": "pink" }
72+
5273
- do:
5374
allowed_warnings_regex:
5475
- "No limit defined, adding default limit of \\[.*\\]"
@@ -121,6 +142,21 @@ constant_keyword:
121142
- length: {values: 1}
122143
- match: {values.0.0: wow such constant}
123144

145+
- do:
146+
allowed_warnings_regex:
147+
- "No limit defined, adding default limit of \\[.*\\]"
148+
esql.query:
149+
body:
150+
query: 'from test,test_2 | where kind == "wow such constant" | keep color, kind'
151+
- match: {columns.0.name: color}
152+
- match: {columns.0.type: keyword}
153+
- match: { columns.1.name: kind }
154+
- match: { columns.1.type: keyword }
155+
- length: {values: 1}
156+
- match: {values.0.0: red}
157+
- match: {values.0.1: "wow such constant"}
158+
159+
124160
- do:
125161
allowed_warnings_regex:
126162
- "No limit defined, adding default limit of \\[.*\\]"
@@ -135,20 +171,84 @@ constant_keyword:
135171
- match: {values.0.0: red}
136172
- match: {values.0.1: "wow such constant"}
137173

174+
- do:
175+
allowed_warnings_regex:
176+
- "No limit defined, adding default limit of \\[.*\\]"
177+
esql.query:
178+
body:
179+
query: 'from test,test_2 | where kind == "wow such constant" | keep color, kind'
180+
- match: {columns.0.name: color}
181+
- match: {columns.0.type: keyword}
182+
- match: { columns.1.name: kind }
183+
- match: { columns.1.type: keyword }
184+
- length: {values: 1}
185+
- match: {values.0.0: red}
186+
- match: {values.0.1: "wow such constant"}
187+
138188

139189
- do:
140190
allowed_warnings_regex:
141191
- "No limit defined, adding default limit of \\[.*\\]"
142192
esql.query:
143193
body:
144-
query: 'from test* | where kind >= "a" | keep color, kind | sort color'
194+
query: 'from test* | where kind == "wow such constant" | keep color, kind'
145195
- match: {columns.0.name: color}
146196
- match: {columns.0.type: keyword}
147197
- match: { columns.1.name: kind }
148198
- match: { columns.1.type: keyword }
149-
- length: {values: 2}
199+
- length: {values: 1}
200+
- match: {values.0.0: red}
201+
- match: {values.0.1: "wow such constant"}
202+
203+
204+
- do:
205+
allowed_warnings_regex:
206+
- "No limit defined, adding default limit of \\[.*\\]"
207+
esql.query:
208+
body:
209+
query: 'from test* | where kind == "not a constant" | keep color, kind'
210+
- match: {columns.0.name: color}
211+
- match: {columns.0.type: keyword}
212+
- match: { columns.1.name: kind }
213+
- match: { columns.1.type: keyword }
214+
- length: {values: 1}
215+
- match: {values.0.0: pink}
216+
- match: {values.0.1: "not a constant"}
217+
218+
- do:
219+
allowed_warnings_regex:
220+
- "No limit defined, adding default limit of \\[.*\\]"
221+
esql.query:
222+
body:
223+
query: 'from test* | where kind >= "a" | keep color, kind | sort color, kind'
224+
- match: {columns.0.name: color}
225+
- match: {columns.0.type: keyword}
226+
- match: { columns.1.name: kind }
227+
- match: { columns.1.type: keyword }
228+
- length: {values: 4}
150229
- match: {values.0.0: blue}
151230
- match: {values.0.1: "a different constant"}
231+
- match: {values.1.0: pink}
232+
- match: {values.1.1: "not a constant"}
233+
- match: {values.2.0: pink}
234+
- match: {values.2.1: "still no constant"}
235+
- match: {values.3.0: red}
236+
- match: {values.3.1: "wow such constant"}
237+
238+
239+
- do:
240+
allowed_warnings_regex:
241+
- "No limit defined, adding default limit of \\[.*\\]"
242+
esql.query:
243+
body:
244+
query: 'from test* | where kind >= "o" | keep color, kind | sort color, kind'
245+
- match: {columns.0.name: color}
246+
- match: {columns.0.type: keyword}
247+
- match: { columns.1.name: kind }
248+
- match: { columns.1.type: keyword }
249+
- length: {values: 2}
250+
- match: {values.0.0: pink}
251+
- match: {values.0.1: "still no constant"}
152252
- match: {values.1.0: red}
153253
- match: {values.1.1: "wow such constant"}
154254

0 commit comments

Comments
 (0)