SQL: Fix precedence of `::` psql like CAST operator (#40665)

Previously, an expression like `10 + 2::long` would be interpreted
as `CAST(10 + 2 AS LONG)` instead of `10 + CAST(2 AS LONG)`.


(cherry picked from commit e34cc2f38b1477e78788ee377938f42cc47187c7)
This commit is contained in:
Marios Trivyzas 2019-03-30 12:51:13 +01:00
parent 31776a4b15
commit 862fe612e0
No known key found for this signature in database
GPG Key ID: 8817B46B0CF36A3F
8 changed files with 744 additions and 687 deletions

View File

@ -210,11 +210,11 @@ valueExpression
| left=valueExpression operator=(ASTERISK | SLASH | PERCENT) right=valueExpression #arithmeticBinary
| left=valueExpression operator=(PLUS | MINUS) right=valueExpression #arithmeticBinary
| left=valueExpression comparisonOperator right=valueExpression #comparison
| valueExpression CAST_OP dataType #castOperatorExpression
;
primaryExpression
: castExpression #cast
| primaryExpression CAST_OP dataType #castOperatorExpression
| extractExpression #extract
| builtinDateTimeFunction #currentDateTimeFunction
| constant #constantDefault

View File

@ -416,7 +416,7 @@ abstract class ExpressionBuilder extends IdentifierBuilder {
@Override
public Object visitCastOperatorExpression(SqlBaseParser.CastOperatorExpressionContext ctx) {
return new Cast(source(ctx), expression(ctx.valueExpression()), typedParsing(ctx.dataType(), DataType.class));
return new Cast(source(ctx), expression(ctx.primaryExpression()), typedParsing(ctx.dataType(), DataType.class));
}
@Override

View File

@ -599,18 +599,6 @@ class SqlBaseBaseListener implements SqlBaseListener {
* <p>The default implementation does nothing.</p>
*/
@Override public void exitComparison(SqlBaseParser.ComparisonContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterCastOperatorExpression(SqlBaseParser.CastOperatorExpressionContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitCastOperatorExpression(SqlBaseParser.CastOperatorExpressionContext ctx) { }
/**
* {@inheritDoc}
*
@ -635,6 +623,18 @@ class SqlBaseBaseListener implements SqlBaseListener {
* <p>The default implementation does nothing.</p>
*/
@Override public void exitArithmeticUnary(SqlBaseParser.ArithmeticUnaryContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterDereference(SqlBaseParser.DereferenceContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitDereference(SqlBaseParser.DereferenceContext ctx) { }
/**
* {@inheritDoc}
*
@ -647,30 +647,6 @@ class SqlBaseBaseListener implements SqlBaseListener {
* <p>The default implementation does nothing.</p>
*/
@Override public void exitCast(SqlBaseParser.CastContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterExtract(SqlBaseParser.ExtractContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitExtract(SqlBaseParser.ExtractContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterCurrentDateTimeFunction(SqlBaseParser.CurrentDateTimeFunctionContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitCurrentDateTimeFunction(SqlBaseParser.CurrentDateTimeFunctionContext ctx) { }
/**
* {@inheritDoc}
*
@ -683,6 +659,30 @@ class SqlBaseBaseListener implements SqlBaseListener {
* <p>The default implementation does nothing.</p>
*/
@Override public void exitConstantDefault(SqlBaseParser.ConstantDefaultContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterExtract(SqlBaseParser.ExtractContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitExtract(SqlBaseParser.ExtractContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterParenthesizedExpression(SqlBaseParser.ParenthesizedExpressionContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitParenthesizedExpression(SqlBaseParser.ParenthesizedExpressionContext ctx) { }
/**
* {@inheritDoc}
*
@ -695,6 +695,18 @@ class SqlBaseBaseListener implements SqlBaseListener {
* <p>The default implementation does nothing.</p>
*/
@Override public void exitStar(SqlBaseParser.StarContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterCastOperatorExpression(SqlBaseParser.CastOperatorExpressionContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitCastOperatorExpression(SqlBaseParser.CastOperatorExpressionContext ctx) { }
/**
* {@inheritDoc}
*
@ -707,6 +719,18 @@ class SqlBaseBaseListener implements SqlBaseListener {
* <p>The default implementation does nothing.</p>
*/
@Override public void exitFunction(SqlBaseParser.FunctionContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterCurrentDateTimeFunction(SqlBaseParser.CurrentDateTimeFunctionContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitCurrentDateTimeFunction(SqlBaseParser.CurrentDateTimeFunctionContext ctx) { }
/**
* {@inheritDoc}
*
@ -719,30 +743,6 @@ class SqlBaseBaseListener implements SqlBaseListener {
* <p>The default implementation does nothing.</p>
*/
@Override public void exitSubqueryExpression(SqlBaseParser.SubqueryExpressionContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterDereference(SqlBaseParser.DereferenceContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitDereference(SqlBaseParser.DereferenceContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterParenthesizedExpression(SqlBaseParser.ParenthesizedExpressionContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitParenthesizedExpression(SqlBaseParser.ParenthesizedExpressionContext ctx) { }
/**
* {@inheritDoc}
*

View File

@ -354,13 +354,6 @@ class SqlBaseBaseVisitor<T> extends AbstractParseTreeVisitor<T> implements SqlBa
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitComparison(SqlBaseParser.ComparisonContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitCastOperatorExpression(SqlBaseParser.CastOperatorExpressionContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
@ -375,6 +368,13 @@ class SqlBaseBaseVisitor<T> extends AbstractParseTreeVisitor<T> implements SqlBa
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitArithmeticUnary(SqlBaseParser.ArithmeticUnaryContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitDereference(SqlBaseParser.DereferenceContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
@ -382,20 +382,6 @@ class SqlBaseBaseVisitor<T> extends AbstractParseTreeVisitor<T> implements SqlBa
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitCast(SqlBaseParser.CastContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitExtract(SqlBaseParser.ExtractContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitCurrentDateTimeFunction(SqlBaseParser.CurrentDateTimeFunctionContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
@ -403,6 +389,20 @@ class SqlBaseBaseVisitor<T> extends AbstractParseTreeVisitor<T> implements SqlBa
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitConstantDefault(SqlBaseParser.ConstantDefaultContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitExtract(SqlBaseParser.ExtractContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitParenthesizedExpression(SqlBaseParser.ParenthesizedExpressionContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
@ -410,6 +410,13 @@ class SqlBaseBaseVisitor<T> extends AbstractParseTreeVisitor<T> implements SqlBa
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitStar(SqlBaseParser.StarContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitCastOperatorExpression(SqlBaseParser.CastOperatorExpressionContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
@ -417,6 +424,13 @@ class SqlBaseBaseVisitor<T> extends AbstractParseTreeVisitor<T> implements SqlBa
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitFunction(SqlBaseParser.FunctionContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitCurrentDateTimeFunction(SqlBaseParser.CurrentDateTimeFunctionContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
@ -424,20 +438,6 @@ class SqlBaseBaseVisitor<T> extends AbstractParseTreeVisitor<T> implements SqlBa
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitSubqueryExpression(SqlBaseParser.SubqueryExpressionContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitDereference(SqlBaseParser.DereferenceContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitParenthesizedExpression(SqlBaseParser.ParenthesizedExpressionContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*

View File

@ -549,18 +549,6 @@ interface SqlBaseListener extends ParseTreeListener {
* @param ctx the parse tree
*/
void exitComparison(SqlBaseParser.ComparisonContext ctx);
/**
* Enter a parse tree produced by the {@code castOperatorExpression}
* labeled alternative in {@link SqlBaseParser#valueExpression}.
* @param ctx the parse tree
*/
void enterCastOperatorExpression(SqlBaseParser.CastOperatorExpressionContext ctx);
/**
* Exit a parse tree produced by the {@code castOperatorExpression}
* labeled alternative in {@link SqlBaseParser#valueExpression}.
* @param ctx the parse tree
*/
void exitCastOperatorExpression(SqlBaseParser.CastOperatorExpressionContext ctx);
/**
* Enter a parse tree produced by the {@code arithmeticBinary}
* labeled alternative in {@link SqlBaseParser#valueExpression}.
@ -585,6 +573,18 @@ interface SqlBaseListener extends ParseTreeListener {
* @param ctx the parse tree
*/
void exitArithmeticUnary(SqlBaseParser.ArithmeticUnaryContext ctx);
/**
* Enter a parse tree produced by the {@code dereference}
* labeled alternative in {@link SqlBaseParser#primaryExpression}.
* @param ctx the parse tree
*/
void enterDereference(SqlBaseParser.DereferenceContext ctx);
/**
* Exit a parse tree produced by the {@code dereference}
* labeled alternative in {@link SqlBaseParser#primaryExpression}.
* @param ctx the parse tree
*/
void exitDereference(SqlBaseParser.DereferenceContext ctx);
/**
* Enter a parse tree produced by the {@code cast}
* labeled alternative in {@link SqlBaseParser#primaryExpression}.
@ -597,30 +597,6 @@ interface SqlBaseListener extends ParseTreeListener {
* @param ctx the parse tree
*/
void exitCast(SqlBaseParser.CastContext ctx);
/**
* Enter a parse tree produced by the {@code extract}
* labeled alternative in {@link SqlBaseParser#primaryExpression}.
* @param ctx the parse tree
*/
void enterExtract(SqlBaseParser.ExtractContext ctx);
/**
* Exit a parse tree produced by the {@code extract}
* labeled alternative in {@link SqlBaseParser#primaryExpression}.
* @param ctx the parse tree
*/
void exitExtract(SqlBaseParser.ExtractContext ctx);
/**
* Enter a parse tree produced by the {@code currentDateTimeFunction}
* labeled alternative in {@link SqlBaseParser#primaryExpression}.
* @param ctx the parse tree
*/
void enterCurrentDateTimeFunction(SqlBaseParser.CurrentDateTimeFunctionContext ctx);
/**
* Exit a parse tree produced by the {@code currentDateTimeFunction}
* labeled alternative in {@link SqlBaseParser#primaryExpression}.
* @param ctx the parse tree
*/
void exitCurrentDateTimeFunction(SqlBaseParser.CurrentDateTimeFunctionContext ctx);
/**
* Enter a parse tree produced by the {@code constantDefault}
* labeled alternative in {@link SqlBaseParser#primaryExpression}.
@ -633,6 +609,30 @@ interface SqlBaseListener extends ParseTreeListener {
* @param ctx the parse tree
*/
void exitConstantDefault(SqlBaseParser.ConstantDefaultContext ctx);
/**
* Enter a parse tree produced by the {@code extract}
* labeled alternative in {@link SqlBaseParser#primaryExpression}.
* @param ctx the parse tree
*/
void enterExtract(SqlBaseParser.ExtractContext ctx);
/**
* Exit a parse tree produced by the {@code extract}
* labeled alternative in {@link SqlBaseParser#primaryExpression}.
* @param ctx the parse tree
*/
void exitExtract(SqlBaseParser.ExtractContext ctx);
/**
* Enter a parse tree produced by the {@code parenthesizedExpression}
* labeled alternative in {@link SqlBaseParser#primaryExpression}.
* @param ctx the parse tree
*/
void enterParenthesizedExpression(SqlBaseParser.ParenthesizedExpressionContext ctx);
/**
* Exit a parse tree produced by the {@code parenthesizedExpression}
* labeled alternative in {@link SqlBaseParser#primaryExpression}.
* @param ctx the parse tree
*/
void exitParenthesizedExpression(SqlBaseParser.ParenthesizedExpressionContext ctx);
/**
* Enter a parse tree produced by the {@code star}
* labeled alternative in {@link SqlBaseParser#primaryExpression}.
@ -645,6 +645,18 @@ interface SqlBaseListener extends ParseTreeListener {
* @param ctx the parse tree
*/
void exitStar(SqlBaseParser.StarContext ctx);
/**
* Enter a parse tree produced by the {@code castOperatorExpression}
* labeled alternative in {@link SqlBaseParser#primaryExpression}.
* @param ctx the parse tree
*/
void enterCastOperatorExpression(SqlBaseParser.CastOperatorExpressionContext ctx);
/**
* Exit a parse tree produced by the {@code castOperatorExpression}
* labeled alternative in {@link SqlBaseParser#primaryExpression}.
* @param ctx the parse tree
*/
void exitCastOperatorExpression(SqlBaseParser.CastOperatorExpressionContext ctx);
/**
* Enter a parse tree produced by the {@code function}
* labeled alternative in {@link SqlBaseParser#primaryExpression}.
@ -657,6 +669,18 @@ interface SqlBaseListener extends ParseTreeListener {
* @param ctx the parse tree
*/
void exitFunction(SqlBaseParser.FunctionContext ctx);
/**
* Enter a parse tree produced by the {@code currentDateTimeFunction}
* labeled alternative in {@link SqlBaseParser#primaryExpression}.
* @param ctx the parse tree
*/
void enterCurrentDateTimeFunction(SqlBaseParser.CurrentDateTimeFunctionContext ctx);
/**
* Exit a parse tree produced by the {@code currentDateTimeFunction}
* labeled alternative in {@link SqlBaseParser#primaryExpression}.
* @param ctx the parse tree
*/
void exitCurrentDateTimeFunction(SqlBaseParser.CurrentDateTimeFunctionContext ctx);
/**
* Enter a parse tree produced by the {@code subqueryExpression}
* labeled alternative in {@link SqlBaseParser#primaryExpression}.
@ -669,30 +693,6 @@ interface SqlBaseListener extends ParseTreeListener {
* @param ctx the parse tree
*/
void exitSubqueryExpression(SqlBaseParser.SubqueryExpressionContext ctx);
/**
* Enter a parse tree produced by the {@code dereference}
* labeled alternative in {@link SqlBaseParser#primaryExpression}.
* @param ctx the parse tree
*/
void enterDereference(SqlBaseParser.DereferenceContext ctx);
/**
* Exit a parse tree produced by the {@code dereference}
* labeled alternative in {@link SqlBaseParser#primaryExpression}.
* @param ctx the parse tree
*/
void exitDereference(SqlBaseParser.DereferenceContext ctx);
/**
* Enter a parse tree produced by the {@code parenthesizedExpression}
* labeled alternative in {@link SqlBaseParser#primaryExpression}.
* @param ctx the parse tree
*/
void enterParenthesizedExpression(SqlBaseParser.ParenthesizedExpressionContext ctx);
/**
* Exit a parse tree produced by the {@code parenthesizedExpression}
* labeled alternative in {@link SqlBaseParser#primaryExpression}.
* @param ctx the parse tree
*/
void exitParenthesizedExpression(SqlBaseParser.ParenthesizedExpressionContext ctx);
/**
* Enter a parse tree produced by {@link SqlBaseParser#builtinDateTimeFunction}.
* @param ctx the parse tree

View File

@ -330,13 +330,6 @@ interface SqlBaseVisitor<T> extends ParseTreeVisitor<T> {
* @return the visitor result
*/
T visitComparison(SqlBaseParser.ComparisonContext ctx);
/**
* Visit a parse tree produced by the {@code castOperatorExpression}
* labeled alternative in {@link SqlBaseParser#valueExpression}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitCastOperatorExpression(SqlBaseParser.CastOperatorExpressionContext ctx);
/**
* Visit a parse tree produced by the {@code arithmeticBinary}
* labeled alternative in {@link SqlBaseParser#valueExpression}.
@ -351,6 +344,13 @@ interface SqlBaseVisitor<T> extends ParseTreeVisitor<T> {
* @return the visitor result
*/
T visitArithmeticUnary(SqlBaseParser.ArithmeticUnaryContext ctx);
/**
* Visit a parse tree produced by the {@code dereference}
* labeled alternative in {@link SqlBaseParser#primaryExpression}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitDereference(SqlBaseParser.DereferenceContext ctx);
/**
* Visit a parse tree produced by the {@code cast}
* labeled alternative in {@link SqlBaseParser#primaryExpression}.
@ -358,20 +358,6 @@ interface SqlBaseVisitor<T> extends ParseTreeVisitor<T> {
* @return the visitor result
*/
T visitCast(SqlBaseParser.CastContext ctx);
/**
* Visit a parse tree produced by the {@code extract}
* labeled alternative in {@link SqlBaseParser#primaryExpression}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitExtract(SqlBaseParser.ExtractContext ctx);
/**
* Visit a parse tree produced by the {@code currentDateTimeFunction}
* labeled alternative in {@link SqlBaseParser#primaryExpression}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitCurrentDateTimeFunction(SqlBaseParser.CurrentDateTimeFunctionContext ctx);
/**
* Visit a parse tree produced by the {@code constantDefault}
* labeled alternative in {@link SqlBaseParser#primaryExpression}.
@ -379,6 +365,20 @@ interface SqlBaseVisitor<T> extends ParseTreeVisitor<T> {
* @return the visitor result
*/
T visitConstantDefault(SqlBaseParser.ConstantDefaultContext ctx);
/**
* Visit a parse tree produced by the {@code extract}
* labeled alternative in {@link SqlBaseParser#primaryExpression}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitExtract(SqlBaseParser.ExtractContext ctx);
/**
* Visit a parse tree produced by the {@code parenthesizedExpression}
* labeled alternative in {@link SqlBaseParser#primaryExpression}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitParenthesizedExpression(SqlBaseParser.ParenthesizedExpressionContext ctx);
/**
* Visit a parse tree produced by the {@code star}
* labeled alternative in {@link SqlBaseParser#primaryExpression}.
@ -386,6 +386,13 @@ interface SqlBaseVisitor<T> extends ParseTreeVisitor<T> {
* @return the visitor result
*/
T visitStar(SqlBaseParser.StarContext ctx);
/**
* Visit a parse tree produced by the {@code castOperatorExpression}
* labeled alternative in {@link SqlBaseParser#primaryExpression}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitCastOperatorExpression(SqlBaseParser.CastOperatorExpressionContext ctx);
/**
* Visit a parse tree produced by the {@code function}
* labeled alternative in {@link SqlBaseParser#primaryExpression}.
@ -393,6 +400,13 @@ interface SqlBaseVisitor<T> extends ParseTreeVisitor<T> {
* @return the visitor result
*/
T visitFunction(SqlBaseParser.FunctionContext ctx);
/**
* Visit a parse tree produced by the {@code currentDateTimeFunction}
* labeled alternative in {@link SqlBaseParser#primaryExpression}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitCurrentDateTimeFunction(SqlBaseParser.CurrentDateTimeFunctionContext ctx);
/**
* Visit a parse tree produced by the {@code subqueryExpression}
* labeled alternative in {@link SqlBaseParser#primaryExpression}.
@ -400,20 +414,6 @@ interface SqlBaseVisitor<T> extends ParseTreeVisitor<T> {
* @return the visitor result
*/
T visitSubqueryExpression(SqlBaseParser.SubqueryExpressionContext ctx);
/**
* Visit a parse tree produced by the {@code dereference}
* labeled alternative in {@link SqlBaseParser#primaryExpression}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitDereference(SqlBaseParser.DereferenceContext ctx);
/**
* Visit a parse tree produced by the {@code parenthesizedExpression}
* labeled alternative in {@link SqlBaseParser#primaryExpression}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitParenthesizedExpression(SqlBaseParser.ParenthesizedExpressionContext ctx);
/**
* Visit a parse tree produced by {@link SqlBaseParser#builtinDateTimeFunction}.
* @param ctx the parse tree

View File

@ -282,6 +282,19 @@ public class ExpressionTests extends ESTestCase {
assertEquals("line 1:12: Does not recognize type [InVaLiD]", ex.getMessage());
}
public void testCastOperatorPrecedence() {
Expression expr = parser.createExpression("(10* 2::long)");
assertEquals(Mul.class, expr.getClass());
Mul mul = (Mul) expr;
assertEquals(DataType.LONG, mul.dataType());
assertEquals(DataType.INTEGER, mul.left().dataType());
assertEquals(Cast.class, mul.right().getClass());
Cast cast = (Cast) mul.right();
assertEquals(DataType.INTEGER, cast.from());
assertEquals(DataType.LONG, cast.to());
assertEquals(DataType.LONG, cast.dataType());
}
public void testCastOperatorWithUnquotedDataType() {
Expression expr = parser.createExpression("(10* 2)::long");
assertEquals(Cast.class, expr.getClass());