Skip to content

Commit b13d467

Browse files
committed
Fix tests
1 parent ab1146d commit b13d467

File tree

3 files changed

+59
-32
lines changed

3 files changed

+59
-32
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -725,12 +725,12 @@ public void testArrayValuesNullsNotAllowedInValueParams() throws IOException {
725725
);
726726

727727
String error = EntityUtils.toString(re.getResponse().getEntity()).replaceAll("\\\\\n\s+\\\\", "");
728-
assertThat(error, containsString("[1:79] Parameter [a] contains a null value. Null values are not allowed for multivalues;"));
729-
assertThat(error, containsString("[1:101] Parameter [b] contains a null value. Null values are not allowed for multivalues;"));
730-
assertThat(error, containsString("[1:120] Parameter [c] contains a null value. Null values are not allowed for multivalues;"));
731-
assertThat(error, containsString("[1:142] Parameter [d] contains a null value. Null values are not allowed for multivalues;"));
732-
assertThat(error, containsString("[1:162] Parameter [e] contains a null value. Null values are not allowed for multivalues;"));
733-
assertThat(error, containsString("[1:192] Parameter [f] contains a null value. Null values are not allowed for multivalues;"));
728+
assertThat(error, containsString("[1:79] Parameter [a] contains a null value. Null values are not allowed for multivalues"));
729+
assertThat(error, containsString("[1:101] Parameter [b] contains a null value. Null values are not allowed for multivalues"));
730+
assertThat(error, containsString("[1:120] Parameter [c] contains a null value. Null values are not allowed for multivalues"));
731+
assertThat(error, containsString("[1:142] Parameter [d] contains a null value. Null values are not allowed for multivalues"));
732+
assertThat(error, containsString("[1:162] Parameter [e] contains a null value. Null values are not allowed for multivalues"));
733+
assertThat(error, containsString("[1:192] Parameter [f] contains a null value. Null values are not allowed for multivalues"));
734734
}
735735

736736
public void testArrayValuesAllowedInUnnamedParams() throws IOException {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,15 +375,15 @@ private static void checkParamValueValidity(
375375
"Parameter [" + entry.getKey() + "] contains a null value. Null values are not allowed for multivalues"
376376
)
377377
);
378-
continue;
378+
break;
379379
} else if (arrayType != null && arrayType != currentType) {
380380
errors.add(
381381
new XContentParseException(
382382
loc,
383383
"Parameter [" + entry.getKey() + "] has values from different types, found " + arrayType + " and " + currentType
384384
)
385385
);
386-
continue;
386+
break;
387387
}
388388
arrayType = currentType;
389389
}

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/action/EsqlQueryRequestTests.java

Lines changed: 51 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444

4545
import java.io.IOException;
4646
import java.util.ArrayList;
47-
import java.util.Arrays;
4847
import java.util.Collections;
4948
import java.util.List;
5049
import java.util.Locale;
@@ -109,7 +108,7 @@ public void testNamedParams() throws IOException {
109108
{"_n1" : "8.15.0"}, { "__n2" : 0.05}, {"__3" : -799810013},
110109
{"__4n" : "127.0.0.1"}, {"_n5" : "esql"}, {"_n6" : null}, {"_n7" : false},
111110
{"_n8": ["8.15.0", "8.19.0"]}, {"_n9": ["x", "y"]}, {"_n10": [true, false]}, {"_n11": [1.0, 1.1, 1.2]},
112-
{"_n12": [-799810013, 0, 799810013]}, {"_n13": [null, null, null]}
111+
{"_n12": [-799810013, 0, 799810013]}
113112
] }""";
114113

115114
List<QueryParam> params = List.of(
@@ -131,8 +130,7 @@ public void testNamedParams() throws IOException {
131130
new QueryParam("_n9", List.of("x", "y"), KEYWORD, ParserUtils.ParamClassification.VALUE),
132131
new QueryParam("_n10", List.of(true, false), BOOLEAN, ParserUtils.ParamClassification.VALUE),
133132
new QueryParam("_n11", List.of(1.0, 1.1, 1.2), DOUBLE, ParserUtils.ParamClassification.VALUE),
134-
new QueryParam("_n12", List.of(-799810013, 0, 799810013), DataType.INTEGER, ParserUtils.ParamClassification.VALUE),
135-
new QueryParam("_n13", Arrays.asList(null, null, null), NULL, ParserUtils.ParamClassification.VALUE)
133+
new QueryParam("_n12", List.of(-799810013, 0, 799810013), DataType.INTEGER, ParserUtils.ParamClassification.VALUE)
136134
// TODO add mixed null values, or check all elements, and separate into a new method
137135
);
138136
String json = String.format(Locale.ROOT, """
@@ -166,16 +164,15 @@ public void testNamedMultivaluedParams() throws IOException {
166164
String paramsString = """
167165
,"params":[
168166
{"_n1": ["8.15.0", "8.19.0"]}, {"_n2": ["x", "y"]}, {"_n3": [true, false]}, {"_n4": [1.0, 1.1, 1.2]},
169-
{"_n5": [-799810013, 0, 799810013]}, {"_n6": [null, null, null]}
167+
{"_n5": [-799810013, 0, 799810013]}
170168
] }""";
171169

172170
List<QueryParam> params = List.of(
173171
new QueryParam("_n1", List.of("8.15.0", "8.19.0"), KEYWORD, ParserUtils.ParamClassification.VALUE),
174172
new QueryParam("_n2", List.of("x", "y"), KEYWORD, ParserUtils.ParamClassification.VALUE),
175173
new QueryParam("_n3", List.of(true, false), BOOLEAN, ParserUtils.ParamClassification.VALUE),
176174
new QueryParam("_n4", List.of(1.0, 1.1, 1.2), DOUBLE, ParserUtils.ParamClassification.VALUE),
177-
new QueryParam("_n5", List.of(-799810013, 0, 799810013), DataType.INTEGER, ParserUtils.ParamClassification.VALUE),
178-
new QueryParam("_n6", Arrays.asList(null, null, null), NULL, ParserUtils.ParamClassification.VALUE)
175+
new QueryParam("_n5", List.of(-799810013, 0, 799810013), DataType.INTEGER, ParserUtils.ParamClassification.VALUE)
179176
);
180177
String json = String.format(Locale.ROOT, """
181178
{
@@ -336,23 +333,23 @@ public void testInvalidMultivaluedParams() throws IOException {
336333
Exception e1 = expectThrows(XContentParseException.class, () -> parseEsqlQueryRequestSync(json1));
337334
assertThat(
338335
e1.getCause().getMessage(),
339-
containsString("Failed to parse params: [3:2] _n1 parameter has values from different types, found NULL and KEYWORD")
336+
containsString(" [3:2] Parameter [_n1] contains a null value. Null values are not allowed for multivalues;")
340337
);
341338
assertThat(
342339
e1.getCause().getMessage(),
343-
containsString("[3:29] _n2 parameter has values from different types, found NULL and KEYWORD")
340+
containsString("[3:29] Parameter [_n2] contains a null value. Null values are not allowed for multivalues;")
344341
);
345342
assertThat(
346343
e1.getCause().getMessage(),
347-
containsString("[3:57] _n3 parameter has values from different types, found NULL and BOOLEAN")
344+
containsString("[3:57] Parameter [_n3] contains a null value. Null values are not allowed for multivalues;")
348345
);
349346
assertThat(
350347
e1.getCause().getMessage(),
351-
containsString("[4:2] _n4 parameter has values from different types, found NULL and DOUBLE")
348+
containsString("[4:2] Parameter [_n4] contains a null value. Null values are not allowed for multivalues;")
352349
);
353350
assertThat(
354351
e1.getCause().getMessage(),
355-
containsString("[4:30] _n5 parameter has values from different types, found NULL and INTEGER")
352+
containsString("[4:30] Parameter [_n5] contains a null value. Null values are not allowed for multivalues;")
356353
);
357354
assertThat(e1.getCause().getMessage(), containsString("[5:2] n6=[{value={a5=v5}}] is not supported as a parameter"));
358355
assertThat(e1.getCause().getMessage(), containsString("[5:40] n7=[{identifier=[x, y]}] is not supported as a parameter"));
@@ -388,18 +385,48 @@ public void testInvalidParamsForIdentifiersPatterns() throws IOException {
388385
message,
389386
containsString("[2:15] [v] is not a valid param attribute, a valid attribute is any of VALUE, IDENTIFIER, PATTERN; ")
390387
);
391-
assertThat(message, containsString("[2:38] [n2] has multiple param attributes [identifier, pattern],"));
392-
assertThat(message, containsString("only one of VALUE, IDENTIFIER, PATTERN can be defined in a param;"));
393-
assertThat(message, containsString("[2:38] [v2] is not a valid value for PATTERN parameter,"));
394-
assertThat(message, containsString("a valid value for PATTERN parameter is a string and contains *;"));
395-
assertThat(message, containsString("[3:1] [n3] has multiple param attributes [identifier, pattern],"));
396-
assertThat(message, containsString("only one of VALUE, IDENTIFIER, PATTERN can be defined in a param;"));
397-
assertThat(message, containsString("[3:1] [v3] is not a valid value for PATTERN parameter,"));
398-
assertThat(message, containsString("a valid value for PATTERN parameter is a string and contains *;"));
399-
assertThat(message, containsString("[3:51] [n4] has multiple param attributes [pattern, value],"));
400-
assertThat(message, containsString("only one of VALUE, IDENTIFIER, PATTERN can be defined in a param;"));
401-
assertThat(message, containsString("[3:51] [v4.1] is not a valid value for PATTERN parameter,"));
402-
assertThat(message, containsString("a valid value for PATTERN parameter is a string and contains *;"));
388+
assertThat(
389+
message,
390+
containsString(
391+
"[2:38] [n2] has multiple param attributes [identifier, pattern], "
392+
+ "only one of VALUE, IDENTIFIER, PATTERN can be defined in a param;"
393+
)
394+
);
395+
assertThat(
396+
message,
397+
containsString(
398+
"[2:38] [v2] is not a valid value for PATTERN parameter, "
399+
+ "a valid value for PATTERN parameter is a string and contains *;"
400+
)
401+
);
402+
assertThat(
403+
message,
404+
containsString(
405+
"[3:1] [n3] has multiple param attributes [identifier, pattern], "
406+
+ "only one of VALUE, IDENTIFIER, PATTERN can be defined in a param;"
407+
)
408+
);
409+
assertThat(
410+
message,
411+
containsString(
412+
"[3:1] [v3] is not a valid value for PATTERN parameter, "
413+
+ "a valid value for PATTERN parameter is a string and contains *;"
414+
)
415+
);
416+
assertThat(
417+
message,
418+
containsString(
419+
"[3:51] [n4] has multiple param attributes [pattern, value], "
420+
+ "only one of VALUE, IDENTIFIER, PATTERN can be defined in a param;"
421+
)
422+
);
423+
assertThat(
424+
message,
425+
containsString(
426+
"[3:51] [v4.1] is not a valid value for PATTERN parameter, "
427+
+ "a valid value for PATTERN parameter is a string and contains *;"
428+
)
429+
);
403430
assertThat(message, containsString("[4:1] n5={value={a5=v5}} is not supported as a parameter;"));
404431
assertThat(message, containsString("[4:36] [{a6.1=v6.1, a6.2=v6.2}] is not a valid value for IDENTIFIER parameter,"));
405432
assertThat(message, containsString("a valid value for IDENTIFIER parameter is a string;"));

0 commit comments

Comments
 (0)