Skip to content

Commit adb558b

Browse files
[ES|QL] Fix MapExpression and named parameter related tests in StatementParserTests (#121075) (#121330)
* fix StatementParserTests.testNamedFunctionArgumentInMap, testNamedFunctionArgumentWithUnsupportedNamedParameterTypes * separate snapshot test from release test --------- Co-authored-by: Elastic Machine <[email protected]> (cherry picked from commit b381a1d) # Conflicts: # muted-tests.yml
1 parent 2e932be commit adb558b

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/parser/StatementParserTests.java

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2465,8 +2465,29 @@ by fn2(f3, {"option1":["string1","string2"],"option2":[1,2,3],"option3":2.0,"opt
24652465
assertEquals(List.of(referenceAttribute("bar", KEYWORD)), dissect.extractedFields());
24662466
UnresolvedRelation ur = as(dissect.child(), UnresolvedRelation.class);
24672467
assertEquals(ur, relation("test"));
2468+
}
24682469

2470+
public void testNamedFunctionArgumentInMapWithNamedParameters() {
24692471
// map entry values provided in named parameter, arrays are not supported by named parameters yet
2472+
assumeTrue(
2473+
"named parameters for identifiers and patterns require snapshot build",
2474+
EsqlCapabilities.Cap.NAMED_PARAMETER_FOR_FIELD_AND_FUNCTION_NAMES_SIMPLIFIED_SYNTAX.isEnabled()
2475+
);
2476+
LinkedHashMap<String, Object> expectedMap1 = new LinkedHashMap<>(4);
2477+
expectedMap1.put("option1", "string");
2478+
expectedMap1.put("option2", 1);
2479+
expectedMap1.put("option3", List.of(2.0, 3.0, 4.0));
2480+
expectedMap1.put("option4", List.of(true, false));
2481+
LinkedHashMap<String, Object> expectedMap2 = new LinkedHashMap<>(4);
2482+
expectedMap2.put("option1", List.of("string1", "string2"));
2483+
expectedMap2.put("option2", List.of(1, 2, 3));
2484+
expectedMap2.put("option3", 2.0);
2485+
expectedMap2.put("option4", true);
2486+
LinkedHashMap<String, Object> expectedMap3 = new LinkedHashMap<>(4);
2487+
expectedMap3.put("option1", "string");
2488+
expectedMap3.put("option2", 2.0);
2489+
expectedMap3.put("option3", List.of(1, 2, 3));
2490+
expectedMap3.put("option4", List.of(true, false));
24702491
assertEquals(
24712492
new Filter(
24722493
EMPTY,
@@ -2564,7 +2585,7 @@ by fn2(f3, {"option1":["string1","string2"],"option2":[1,2,3],"option3":2.0,"opt
25642585
)
25652586
);
25662587

2567-
plan = statement(
2588+
LogicalPlan plan = statement(
25682589
"""
25692590
from test
25702591
| dissect ?fn1(?n1, ?n2, {"option1":?n3,"option2":?n4,"option3":[2.0,3.0,4.0],"option4":[true,false]}) "%{bar}"
@@ -2584,16 +2605,16 @@ by fn2(f3, {"option1":["string1","string2"],"option2":[1,2,3],"option3":2.0,"opt
25842605
)
25852606
)
25862607
);
2587-
grok = as(plan, Grok.class);
2608+
Grok grok = as(plan, Grok.class);
25882609
assertEquals(function("fn2", List.of(attribute("f3"), mapExpression(expectedMap2))), grok.input());
25892610
assertEquals("%{WORD:foo}", grok.parser().pattern());
25902611
assertEquals(List.of(referenceAttribute("foo", KEYWORD)), grok.extractedFields());
2591-
dissect = as(grok.child(), Dissect.class);
2612+
Dissect dissect = as(grok.child(), Dissect.class);
25922613
assertEquals(function("fn1", List.of(attribute("f1"), attribute("f2"), mapExpression(expectedMap1))), dissect.input());
25932614
assertEquals("%{bar}", dissect.parser().pattern());
25942615
assertEquals("", dissect.parser().appendSeparator());
25952616
assertEquals(List.of(referenceAttribute("bar", KEYWORD)), dissect.extractedFields());
2596-
ur = as(dissect.child(), UnresolvedRelation.class);
2617+
UnresolvedRelation ur = as(dissect.child(), UnresolvedRelation.class);
25972618
assertEquals(ur, relation("test"));
25982619
}
25992620

@@ -2859,6 +2880,10 @@ public void testNamedFunctionArgumentInInvalidPositions() {
28592880
}
28602881

28612882
public void testNamedFunctionArgumentWithUnsupportedNamedParameterTypes() {
2883+
assumeTrue(
2884+
"named parameters for identifiers and patterns require snapshot build",
2885+
EsqlCapabilities.Cap.NAMED_PARAMETER_FOR_FIELD_AND_FUNCTION_NAMES_SIMPLIFIED_SYNTAX.isEnabled()
2886+
);
28622887
Map<String, String> commands = Map.ofEntries(
28632888
Map.entry("eval x = {}", "29"),
28642889
Map.entry("where {}", "26"),

0 commit comments

Comments
 (0)