Skip to content

Commit

Permalink
update antlr
Browse files Browse the repository at this point in the history
  • Loading branch information
penghuo committed Feb 15, 2022
1 parent 5c6fc8c commit 02ed12f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
12 changes: 6 additions & 6 deletions sql/src/main/antlr/OpenSearchSQLParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ intervalUnit
| DAY_SECOND | DAY_MINUTE | DAY_HOUR | YEAR_MONTH
;

// Expressions, predicates
// predicates

// Simplified approach for expression
expression
Expand All @@ -265,7 +265,11 @@ predicate
| predicate IS nullNotnull #isNullPredicate
| left=predicate NOT? LIKE right=predicate #likePredicate
| left=predicate REGEXP right=predicate #regexpPredicate
| predicate NOT? IN predicateList #inList
| predicate NOT? IN '(' expressions ')' #inPredicate
;

expressions
: expression (',' expression)*
;

expressionAtom
Expand All @@ -289,10 +293,6 @@ nullNotnull
: NOT? NULL_LITERAL
;

predicateList
: '(' predicate (COMMA predicate)* ')'
;

functionCall
: scalarFunctionName LR_BRACKET functionArgs? RR_BRACKET #scalarFunctionCall
| specificFunction #specificFunctionCall
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,10 +238,14 @@ public UnresolvedExpression visitRegexpPredicate(RegexpPredicateContext ctx) {
}

@Override
public UnresolvedExpression visitInList(OpenSearchSQLParser.InListContext ctx) {
public UnresolvedExpression visitInPredicate(OpenSearchSQLParser.InPredicateContext ctx) {
UnresolvedExpression field = visit(ctx.predicate());
List<UnresolvedExpression> inLists =
ctx.predicateList().predicate().stream().map(this::visit).collect(Collectors.toList());
List<UnresolvedExpression> inLists = ctx
.expressions()
.expression()
.stream()
.map(this::visit)
.collect(Collectors.toList());
UnresolvedExpression in = AstDSL.in(field, inLists);
return ctx.NOT() != null ? AstDSL.not(in) : in;
}
Expand Down

0 comments on commit 02ed12f

Please sign in to comment.