Skip to content

Commit 3906494

Browse files
committed
Merge remote-tracking branch 'felixbarny/bulk-meta' into bulk-meta
2 parents c949f3e + d967c35 commit 3906494

File tree

8 files changed

+89
-58
lines changed

8 files changed

+89
-58
lines changed

docs/changelog/138681.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 138681
2+
summary: Field caps to support `project_routing` also in the body of the request
3+
area: Search
4+
type: enhancement
5+
issues: []

muted-tests.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,9 @@ tests:
439439
- class: org.elasticsearch.xpack.unsignedlong.UnsignedLongSyntheticSourceNativeArrayIntegrationTests
440440
method: testSynthesizeArrayRandom
441441
issue: https://github.com/elastic/elasticsearch/issues/138684
442+
- class: org.elasticsearch.index.mapper.HalfFloatSyntheticSourceNativeArrayIntegrationTests
443+
method: testSynthesizeArrayRandom
444+
issue: https://github.com/elastic/elasticsearch/issues/138730
442445

443446
# Examples:
444447
#

server/src/main/java/org/elasticsearch/action/fieldcaps/FieldCapabilitiesRequest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,10 @@ public ResolvedIndexExpressions getResolvedIndexExpressions() {
280280
return resolvedIndexExpressions;
281281
}
282282

283-
public void projectRouting(String projectRouting) {
283+
public void projectRouting(@Nullable String projectRouting) {
284+
if (this.projectRouting != null) {
285+
throw new IllegalArgumentException("project_routing is already set to [" + this.projectRouting + "]");
286+
}
284287
this.projectRouting = projectRouting;
285288
}
286289

server/src/main/java/org/elasticsearch/rest/action/RestFieldCapabilitiesAction.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,14 @@ public RestChannelConsumer prepareRequest(final RestRequest request, final NodeC
107107
private static final ParseField INDEX_FILTER_FIELD = new ParseField("index_filter");
108108
private static final ParseField RUNTIME_MAPPINGS_FIELD = new ParseField("runtime_mappings");
109109
private static final ParseField FIELDS_FIELD = new ParseField("fields");
110+
private static final ParseField PROJECT_ROUTING = new ParseField("project_routing");
110111

111112
private static final ObjectParser<FieldCapabilitiesRequest, Void> PARSER = new ObjectParser<>("field_caps_request");
112113

113114
static {
114115
PARSER.declareObject(FieldCapabilitiesRequest::indexFilter, (p, c) -> parseTopLevelQuery(p), INDEX_FILTER_FIELD);
115116
PARSER.declareObject(FieldCapabilitiesRequest::runtimeFields, (p, c) -> p.map(), RUNTIME_MAPPINGS_FIELD);
116117
PARSER.declareStringArray(fromList(String.class, FieldCapabilitiesRequest::fields), FIELDS_FIELD);
118+
PARSER.declareString(FieldCapabilitiesRequest::projectRouting, PROJECT_ROUTING);
117119
}
118120
}

x-pack/plugin/esql/qa/server/src/main/java/org/elasticsearch/xpack/esql/qa/rest/EsqlSpecTestCase.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,9 @@ private Object valueMapper(CsvTestUtils.Type type, Object value) {
380380
if (value == null) {
381381
return "null";
382382
}
383+
if (value instanceof CsvTestUtils.Range) {
384+
return value;
385+
}
383386
if (type == CsvTestUtils.Type.GEO_POINT || type == CsvTestUtils.Type.CARTESIAN_POINT) {
384387
// Point tests are failing in clustered integration tests because of tiny precision differences at very small scales
385388
if (value instanceof String wkt) {
@@ -421,6 +424,17 @@ private Object valueMapper(CsvTestUtils.Type type, Object value) {
421424
}
422425
}
423426
}
427+
if (type == CsvTestUtils.Type.DOUBLE || type == CsvTestUtils.Type.INTEGER || type == CsvTestUtils.Type.LONG) {
428+
if (value instanceof List<?> vs) {
429+
return vs.stream().map(v -> valueMapper(type, v)).toList();
430+
} else if (type == CsvTestUtils.Type.DOUBLE) {
431+
return ((Number) value).doubleValue();
432+
} else if (type == CsvTestUtils.Type.INTEGER) {
433+
return ((Number) value).intValue();
434+
} else if (type == CsvTestUtils.Type.LONG) {
435+
return ((Number) value).longValue();
436+
}
437+
}
424438
return value.toString();
425439
}
426440

x-pack/plugin/esql/qa/testFixtures/src/main/java/org/elasticsearch/xpack/esql/CsvAssert.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ public static void assertData(
236236

237237
var transformedExpected = valueTransformer.apply(expectedType, expectedValue);
238238
var transformedActual = valueTransformer.apply(expectedType, actualValue);
239-
if (Objects.equals(transformedExpected, transformedActual) == false) {
239+
if (equals(transformedExpected, transformedActual) == false) {
240240
dataFailures.add(new DataFailure(row, column, transformedExpected, transformedActual));
241241
}
242242
if (dataFailures.size() > 10) {
@@ -275,6 +275,24 @@ public static void assertData(
275275
}
276276
}
277277

278+
private static boolean equals(Object expected, Object actual) {
279+
if (expected instanceof List<?> expectedList && actual instanceof List<?> actualList) {
280+
if (expectedList.size() != actualList.size()) {
281+
return false;
282+
}
283+
for (int i = 0; i < expectedList.size(); i++) {
284+
if (equals(expectedList.get(i), actualList.get(i)) == false) {
285+
return false;
286+
}
287+
}
288+
return true;
289+
} else if (expected instanceof CsvTestUtils.Range expectedRange) {
290+
return expectedRange.includes(actual);
291+
} else {
292+
return Objects.equals(expected, actual);
293+
}
294+
}
295+
278296
private static void dataFailure(
279297
String description,
280298
List<DataFailure> dataFailures,

x-pack/plugin/esql/qa/testFixtures/src/main/java/org/elasticsearch/xpack/esql/CsvTestUtils.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,13 @@ public final class CsvTestUtils {
8282
public static final String COMMA_ESCAPING_REGEX = "(?<!\\" + ESCAPE_CHAR + "),";
8383
public static final String ESCAPED_COMMA_SEQUENCE = ESCAPE_CHAR + ",";
8484

85+
public record Range(Object lowerBound, Object upperBound) {
86+
@SuppressWarnings("unchecked")
87+
<T extends Comparable<T>> boolean includes(Object value) {
88+
return ((T) value).compareTo((T) lowerBound) >= 0 && ((T) value).compareTo((T) upperBound) <= 0;
89+
}
90+
}
91+
8592
private CsvTestUtils() {}
8693

8794
public static boolean isEnabled(String testName, String instructions, Version version) {
@@ -617,7 +624,16 @@ Object convert(String value) {
617624
if (value == null) {
618625
return null;
619626
}
620-
return converter.apply(value);
627+
if (Number.class.isAssignableFrom(clazz) && value.contains("..")) {
628+
// Numbers of the form "lower..upper" are parsed to a Range, indicating that
629+
// the expected value is within that range.
630+
int separator = value.indexOf("..");
631+
Object lowerBound = converter.apply(value.substring(0, separator).trim());
632+
Object upperBound = converter.apply(value.substring(separator + 2).trim());
633+
return new Range(lowerBound, upperBound);
634+
} else {
635+
return converter.apply(value);
636+
}
621637
}
622638

623639
Class<?> clazz() {

x-pack/plugin/esql/qa/testFixtures/src/main/resources/sample.csv-spec

Lines changed: 25 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
// they also assert the value of MV_COUNT(VALUES(...)), which is not adjusted for
66
// the sampling and therefore gives the size of the sample.
77
// All ranges are very loose, so that the tests should practically never fail.
8-
// The range checks are done in ES|QL, resulting in one boolean value (is_expected),
9-
// because the CSV tests don't support such assertions.
108

119
row
1210
required_capability: sample_v3
@@ -40,14 +38,10 @@ required_capability: sample_v3
4038
FROM employees
4139
| SAMPLE 0.5
4240
| STATS count = COUNT(), avg_emp_no = AVG(emp_no), sum_emp_no = SUM(emp_no)
43-
| EVAL is_expected = count >= 10 AND count <= 90 AND
44-
avg_emp_no > 10010 AND avg_emp_no < 10090 AND
45-
sum_emp_no > 10*10010 AND sum_emp_no < 90*10090
46-
| KEEP is_expected
4741
;
4842

49-
is_expected:boolean
50-
true
43+
count:long | avg_emp_no:double | sum_emp_no:long
44+
10..90 | 10010.0..10090.0 | 100100..908100
5145
;
5246

5347

@@ -58,13 +52,10 @@ FROM employees
5852
| SAMPLE 0.5
5953
| WHERE emp_no > 10050
6054
| STATS count = COUNT(), avg_emp_no = AVG(emp_no)
61-
| EVAL is_expected = count >= 2 AND count <= 48 AND
62-
avg_emp_no > 10055 AND avg_emp_no < 10095
63-
| KEEP is_expected
6455
;
6556

66-
is_expected:boolean
67-
true
57+
count:long | avg_emp_no:double
58+
2..48 | 10055..10095
6859
;
6960

7061

@@ -75,13 +66,10 @@ FROM employees
7566
| WHERE emp_no <= 10050
7667
| SAMPLE 0.5
7768
| STATS count = COUNT(), avg_emp_no = AVG(emp_no)
78-
| EVAL is_expected = count >= 2 AND count <= 48 AND
79-
avg_emp_no > 10005 AND avg_emp_no < 10045
80-
| KEEP is_expected
8169
;
8270

83-
is_expected:boolean
84-
true
71+
count:long | avg_emp_no:double
72+
2..48 | 10005..10045
8573
;
8674

8775

@@ -92,13 +80,10 @@ FROM employees
9280
| SAMPLE 0.5
9381
| SORT emp_no
9482
| STATS count = COUNT(), avg_emp_no = AVG(emp_no)
95-
| EVAL is_expected = count >= 10 AND count <= 90 AND
96-
avg_emp_no > 10010 AND avg_emp_no < 10090
97-
| KEEP is_expected
9883
;
9984

100-
is_expected:boolean
101-
true
85+
count:long | avg_emp_no:double
86+
10..90 | 10010..10090
10287
;
10388

10489

@@ -109,13 +94,10 @@ FROM employees
10994
| SORT emp_no
11095
| SAMPLE 0.5
11196
| STATS count = COUNT(), avg_emp_no = AVG(emp_no)
112-
| EVAL is_expected = count >= 10 AND count <= 90 AND
113-
avg_emp_no > 10010 AND avg_emp_no < 10090
114-
| KEEP is_expected
11597
;
11698

117-
is_expected:boolean
118-
true
99+
count:long | avg_emp_no:double
100+
10..90 | 10010..10090
119101
;
120102

121103

@@ -126,12 +108,10 @@ FROM employees
126108
| SAMPLE 0.5
127109
| LIMIT 10
128110
| STATS count = COUNT(emp_no)
129-
| EVAL is_expected = count == 10
130-
| KEEP is_expected
131111
;
132112

133-
is_expected:boolean
134-
true
113+
count:long
114+
10
135115
;
136116

137117

@@ -142,12 +122,10 @@ FROM employees
142122
| LIMIT 50
143123
| SAMPLE 0.5
144124
| STATS count = COUNT(emp_no)
145-
| EVAL is_expected = count >= 2 AND count <= 48
146-
| KEEP is_expected
147125
;
148126

149-
is_expected:boolean
150-
true
127+
count:long
128+
2..48
151129
;
152130

153131

@@ -160,12 +138,11 @@ ROW x = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27
160138
| MV_EXPAND y
161139
| STATS count = COUNT() BY x
162140
| STATS counts = VALUES(count)
163-
| EVAL is_expected = MV_COUNT(counts) == 1 AND MV_MIN(counts) == 2
164-
| KEEP is_expected
141+
165142
;
166143

167-
is_expected:boolean
168-
true
144+
counts:long
145+
2
169146
;
170147

171148

@@ -177,13 +154,11 @@ ROW x = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27
177154
| MV_EXPAND y
178155
| SAMPLE 0.85
179156
| STATS count = COUNT() BY x
180-
| STATS counts = VALUES(count)
181-
| EVAL is_expected = MV_COUNT(counts) == 2 AND MV_MIN(counts) == 1 AND MV_MAX(counts) == 2
182-
| KEEP is_expected
157+
| STATS counts = MV_SORT(VALUES(count))
183158
;
184159

185-
is_expected:boolean
186-
true
160+
counts:long
161+
[1,2]
187162
;
188163

189164

@@ -195,13 +170,10 @@ FROM employees
195170
| SAMPLE 0.8
196171
| SAMPLE 0.9
197172
| STATS count = COUNT(), avg_emp_no = AVG(emp_no)
198-
| EVAL is_expected = count >= 10 AND count <= 90 AND
199-
avg_emp_no > 10010 AND avg_emp_no < 10090
200-
| KEEP is_expected
201173
;
202174

203-
is_expected:boolean
204-
true
175+
count:long | avg_emp_no:double
176+
10..90 | 10010..10090
205177
;
206178

207179

@@ -213,13 +185,10 @@ FROM employees
213185
| STATS avg_salary = AVG(salary) BY job_positions
214186
| SAMPLE 0.8
215187
| STATS count = COUNT(), avg_avg_salary = AVG(avg_salary)
216-
| EVAL is_expected = count >= 1 AND count <= 16 AND
217-
avg_avg_salary > 25000 AND avg_avg_salary < 75000
218-
| KEEP is_expected
219188
;
220189

221-
is_expected:boolean
222-
true
190+
count:long | avg_avg_salary:double
191+
1..16 | 25000..75000
223192
;
224193

225194

@@ -251,6 +220,7 @@ emp_no:integer
251220
sampleStatsEval
252221
required_capability: fix_no_columns
253222
required_capability: sample_v3
223+
254224
FROM employees | SAMPLE 0.5 | LIMIT 10 | STATS count = COUNT() | EVAL is_expected = count > 0;
255225

256226
count:long | is_expected:boolean

0 commit comments

Comments
 (0)