Skip to content

Commit

Permalink
Match expressions use constants as query string, to match the functio…
Browse files Browse the repository at this point in the history
…n parameters checks
  • Loading branch information
carlosdelest committed Oct 30, 2024
1 parent 598d5bc commit f70f64e
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 43 deletions.
2 changes: 1 addition & 1 deletion x-pack/plugin/esql/src/main/antlr/EsqlBaseParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ regexBooleanExpression
;

matchBooleanExpression
: fieldExp=qualifiedName COLON queryString=primaryExpression
: fieldExp=qualifiedName COLON queryString=constant
;

valueExpression
Expand Down

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -2290,7 +2290,7 @@ public void testMetricWithGroupKeyAsAgg() {
}
}

public void testMatchOperator() {
public void testMatchOperatorConstantQueryString() {
var plan = statement("FROM test | WHERE field:\"value\"");
var filter = as(plan, Filter.class);
var match = (Match) filter.condition();
Expand All @@ -2301,5 +2301,27 @@ public void testMatchOperator() {

public void testInvalidMatchOperator() {
expectError("from test | WHERE field:", "line 1:25: mismatched input '<EOF>' expecting {QUOTED_STRING, ");
expectError(
"from test | WHERE field:CONCAT(\"hello\", \"world\")",
"line 1:25: mismatched input 'CONCAT' expecting {QUOTED_STRING, INTEGER_LITERAL, DECIMAL_LITERAL, "
);
expectError("from test | WHERE field:123::STRING", "line 1:28: mismatched input '::' expecting {<EOF>, '|', 'and', 'or'}");
expectError(
"from test | WHERE field:(true OR false)",
"line 1:25: extraneous input '(' expecting {QUOTED_STRING, INTEGER_LITERAL, DECIMAL_LITERAL, "
);
expectError(
"from test | WHERE field:another_field_or_value",
"line 1:25: mismatched input 'another_field_or_value' expecting {QUOTED_STRING, INTEGER_LITERAL, DECIMAL_LITERAL, "
);
expectError("from test | WHERE field:2+3", "line 1:26: mismatched input '+' expecting {<EOF>, '|', 'and', 'or'}");
expectError(
"from test | WHERE \"field\":\"value\"",
"line 1:26: mismatched input ':' expecting {<EOF>, '|', 'and', '::', 'or', '+', '-', '*', '/', '%'}"
);
expectError(
"from test | WHERE CONCAT(\"field\", 1):\"value\"",
"line 1:37: mismatched input ':' expecting {<EOF>, '|', 'and', '::', 'or', '+', '-', '*', '/', '%'}"
);
}
}

0 comments on commit f70f64e

Please sign in to comment.