Skip to content

Commit a72a293

Browse files
committed
Add REST tests and fix parsing
1 parent cc4d17e commit a72a293

File tree

2 files changed

+40
-5
lines changed

2 files changed

+40
-5
lines changed

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

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -687,14 +687,45 @@ public void testErrorMessageForInvalidIntervalParams() throws IOException {
687687
);
688688
}
689689

690-
public void testErrorMessageForArrayValuesInParams() throws IOException {
690+
public void testArrayValuesAllowedInValueParams() throws IOException {
691+
Map<String, Object> responseMap = runEsql(
692+
RequestObjectBuilder.jsonBuilder()
693+
.query("row a = ?n1 | eval s = ?n2")
694+
.params("[{\"n1\" : [\"a1\", \"a2\"]}, {\"n2\" : [1, 2]}]")
695+
);
696+
System.out.println(responseMap);
697+
698+
ListMatcher values = matchesList().item(
699+
matchesList().item(matchesList().item("a1").item("a2")).item(matchesList().item(1).item(2))
700+
);
701+
702+
assertResultMap(
703+
responseMap,
704+
matchesList().item(matchesMap().entry("name", "a").entry("type", "keyword"))
705+
.item(matchesMap().entry("name", "s").entry("type", "integer")),
706+
values
707+
);
708+
}
709+
710+
public void testErrorMessageForArrayValuesInNonValueParams() throws IOException {
691711
ResponseException re = expectThrows(
692712
ResponseException.class,
693-
() -> runEsql(RequestObjectBuilder.jsonBuilder().query("row a = 1 | eval x = ?").params("[{\"n1\": [5, 6, 7]}]"))
713+
() -> runEsql(
714+
RequestObjectBuilder.jsonBuilder().query("row a = 1 | eval ?n1 = 5").params("[{\"n1\" : {\"identifier\" : [\"integer\"]}}]")
715+
)
716+
);
717+
assertThat(
718+
EntityUtils.toString(re.getResponse().getEntity()),
719+
containsString("\"Failed to parse params: [1:47] n1={identifier=[integer]} parameter is multivalued")
720+
);
721+
722+
re = expectThrows(
723+
ResponseException.class,
724+
() -> runEsql(RequestObjectBuilder.jsonBuilder().query("row a = 1 | keep ?n1").params("[{\"n1\" : {\"pattern\" : [\"a*\"]}}]"))
694725
);
695726
assertThat(
696727
EntityUtils.toString(re.getResponse().getEntity()),
697-
containsString("Failed to parse params: [1:45] n1=[5, 6, 7] is not supported as a parameter")
728+
containsString("\"Failed to parse params: [1:43] n1={pattern=[a*]} parameter is multivalued")
698729
);
699730
}
700731

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/parser/ExpressionBuilder.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,8 +1047,12 @@ private Expression visitParam(EsqlBaseParser.ParameterContext ctx, QueryParam pa
10471047
return new UnresolvedAttribute(source, value.toString());
10481048
}
10491049
}
1050-
if ((type == KEYWORD || type == TEXT) && value instanceof String) {
1051-
value = BytesRefs.toBytesRef(value);
1050+
if ((type == KEYWORD || type == TEXT)) {
1051+
if (value instanceof String) {
1052+
value = BytesRefs.toBytesRef(value);
1053+
} else if (value instanceof List<?> list) {
1054+
value = list.stream().map(v -> v instanceof String ? BytesRefs.toBytesRef(v) : v).toList();
1055+
}
10521056
}
10531057
return new Literal(source, value, type);
10541058
}

0 commit comments

Comments
 (0)