Skip to content

Commit

Permalink
SQL: allow LEFT and RIGHT as function names (#32066)
Browse files Browse the repository at this point in the history
Due to the way ANTLR works, any declared tokens need to be accounted for
manually inside function names (otherwise a different rule gets applied).

Fix #32046

(cherry picked from commit 20ea72e)
  • Loading branch information
costin committed Jul 16, 2018
1 parent fed84c3 commit b00de36
Show file tree
Hide file tree
Showing 9 changed files with 922 additions and 765 deletions.
7 changes: 6 additions & 1 deletion x-pack/plugin/sql/src/main/antlr/SqlBase.g4
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,12 @@ functionExpression
;
functionTemplate
: identifier '(' (setQuantifier? expression (',' expression)*)? ')'
: functionName '(' (setQuantifier? expression (',' expression)*)? ')'
;
functionName
: LEFT
| RIGHT
| identifier
;
constant
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -396,8 +396,7 @@ public Function visitExtractExpression(ExtractExpressionContext ctx) {
@Override
public Function visitFunctionExpression(FunctionExpressionContext ctx) {
FunctionTemplateContext template = ctx.functionTemplate();

String name = visitIdentifier(template.identifier());
String name = template.functionName().getText();
boolean isDistinct = template.setQuantifier() != null && template.setQuantifier().DISTINCT() != null;
UnresolvedFunction.ResolutionType resolutionType =
isDistinct ? UnresolvedFunction.ResolutionType.DISTINCT : UnresolvedFunction.ResolutionType.STANDARD;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,18 @@ class SqlBaseBaseListener implements SqlBaseListener {
* <p>The default implementation does nothing.</p>
*/
@Override public void exitFunctionTemplate(SqlBaseParser.FunctionTemplateContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterFunctionName(SqlBaseParser.FunctionNameContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitFunctionName(SqlBaseParser.FunctionNameContext ctx) { }
/**
* {@inheritDoc}
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,13 @@ class SqlBaseBaseVisitor<T> extends AbstractParseTreeVisitor<T> implements SqlBa
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitFunctionTemplate(SqlBaseParser.FunctionTemplateContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitFunctionName(SqlBaseParser.FunctionNameContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,16 @@ interface SqlBaseListener extends ParseTreeListener {
* @param ctx the parse tree
*/
void exitFunctionTemplate(SqlBaseParser.FunctionTemplateContext ctx);
/**
* Enter a parse tree produced by {@link SqlBaseParser#functionName}.
* @param ctx the parse tree
*/
void enterFunctionName(SqlBaseParser.FunctionNameContext ctx);
/**
* Exit a parse tree produced by {@link SqlBaseParser#functionName}.
* @param ctx the parse tree
*/
void exitFunctionName(SqlBaseParser.FunctionNameContext ctx);
/**
* Enter a parse tree produced by the {@code nullLiteral}
* labeled alternative in {@link SqlBaseParser#constant}.
Expand Down
Loading

0 comments on commit b00de36

Please sign in to comment.