Skip to content

Commit 39a4493

Browse files
map as function argument
1 parent 1866299 commit 39a4493

File tree

33 files changed

+3049
-2058
lines changed

33 files changed

+3049
-2058
lines changed

docs/reference/esql/functions/parameters/match.asciidoc

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/esql/functions/signature/match.svg

Lines changed: 1 addition & 1 deletion
Loading

docs/reference/esql/functions/types/match.asciidoc

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/esql/functions/types/match_operator.asciidoc

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

x-pack/plugin/esql-core/src/main/java/org/elasticsearch/xpack/esql/core/querydsl/query/MatchQuery.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,10 @@ public MatchQuery(Source source, String name, Object text, Map<String, String> o
6060
this.name = name;
6161
this.text = text;
6262
this.options = options;
63-
this.boost = null;
64-
this.fuzziness = null;
63+
String boost = options.get("boost");
64+
String fuzziness = options.get("fuzziness");
65+
this.boost = boost == null ? null : Double.valueOf(boost);
66+
this.fuzziness = fuzziness == null ? null : Fuzziness.fromString(fuzziness);
6567
}
6668

6769
public MatchQuery(Source source, String name, Object text, Double boost, Fuzziness fuzziness) {

x-pack/plugin/esql/compute/gen/src/main/java/org/elasticsearch/compute/gen/ConsumeProcessor.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public Set<String> getSupportedAnnotationTypes() {
3939
"org.elasticsearch.injection.guice.Inject",
4040
"org.elasticsearch.xpack.esql.expression.function.FunctionInfo",
4141
"org.elasticsearch.xpack.esql.expression.function.Param",
42+
"org.elasticsearch.xpack.esql.expression.function.MapParam",
4243
"org.elasticsearch.rest.ServerlessScope",
4344
"org.elasticsearch.xcontent.ParserConstructor",
4445
"org.elasticsearch.core.UpdateForV9",

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,3 +197,30 @@ emp_no:integer | first_name:keyword | last_name:keyword
197197
10041 | Uri | Lenart
198198
10043 | Yishay | Tzvieli
199199
;
200+
201+
mapCount
202+
required_capability: optional_named_argument_map_for_function
203+
row x = 1
204+
| eval y = map_count({"option1":"value2", "option2":2, "option3":3.0, "option4":true})
205+
;
206+
207+
x:integer |y:long
208+
1 |4
209+
;
210+
211+
matchWithOptions
212+
required_capability: match_function
213+
required_capability: optional_named_argument_map_for_function
214+
FROM books
215+
| WHERE MATCH(author, "Faulkner", {"fuzziness":"auto", "boost":2, "analyzer":"whitespace"})
216+
| KEEP book_no, author
217+
| SORT book_no
218+
| LIMIT 5;
219+
220+
book_no:keyword | author:text
221+
2378 | [Carol Faulkner, Holly Byers Ochoa, Lucretia Mott]
222+
2713 | William Faulkner
223+
2847 | Colleen Faulkner
224+
2883 | William Faulkner
225+
3293 | Danny Faulkner
226+
;

x-pack/plugin/esql/src/main/antlr/EsqlBaseLexer.g4

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,9 @@ ASTERISK : '*';
216216
SLASH : '/';
217217
PERCENT : '%';
218218

219+
LEFT_BRACES : {this.isDevVersion()}? '{';
220+
RIGHT_BRACES : {this.isDevVersion()}? '}';
221+
219222
NESTED_WHERE : WHERE -> type(WHERE);
220223

221224
NAMED_OR_POSITIONAL_PARAM

x-pack/plugin/esql/src/main/antlr/EsqlBaseLexer.tokens

Lines changed: 69 additions & 67 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

x-pack/plugin/esql/src/main/antlr/EsqlBaseParser.g4

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,26 @@ primaryExpression
102102
;
103103

104104
functionExpression
105-
: functionName LP (ASTERISK | (booleanExpression (COMMA booleanExpression)*))? RP
105+
: functionName LP (ASTERISK | (functionArgument (COMMA functionArgument)*))? RP
106106
;
107107

108108
functionName
109109
: identifierOrParameter
110110
;
111111

112+
functionArgument
113+
: booleanExpression #functionArgumentDefault
114+
| {this.isDevVersion()}? LEFT_BRACES namedConstants RIGHT_BRACES #functionArgumentWithName
115+
;
116+
117+
namedConstants
118+
: namedConstant (COMMA namedConstant)*
119+
;
120+
121+
namedConstant
122+
: key=string COLON value=constant
123+
;
124+
112125
dataType
113126
: identifier #toDataType
114127
;

0 commit comments

Comments
 (0)