Search in sources :

Example 1 with UnsupportedSyntaxException

use of com.pingcap.tikv.exception.UnsupportedSyntaxException in project tispark by pingcap.

the class AstBuilder method visitMathExpressionAtom.

@Override
public Expression visitMathExpressionAtom(MySqlParser.MathExpressionAtomContext ctx) {
    Expression left = visitChildren(ctx.left);
    Expression right = visitChildren(ctx.right);
    switch(ctx.mathOperator().getText()) {
        case "+":
            return ArithmeticBinaryExpression.plus(left, right);
        case "-":
            return ArithmeticBinaryExpression.minus(left, right);
        case "*":
            return ArithmeticBinaryExpression.multiply(left, right);
        case "/":
        case "div":
            return ArithmeticBinaryExpression.divide(left, right);
    }
    throw new UnsupportedSyntaxException(ctx.toString() + ": it is not supported right now");
}
Also used : UnsupportedSyntaxException(com.pingcap.tikv.exception.UnsupportedSyntaxException) Expression(com.pingcap.tikv.expression.Expression) ArithmeticBinaryExpression(com.pingcap.tikv.expression.ArithmeticBinaryExpression) ComparisonBinaryExpression(com.pingcap.tikv.expression.ComparisonBinaryExpression) LogicalBinaryExpression(com.pingcap.tikv.expression.LogicalBinaryExpression)

Example 2 with UnsupportedSyntaxException

use of com.pingcap.tikv.exception.UnsupportedSyntaxException in project tispark by pingcap.

the class AstBuilder method visitBinaryComparisonPredicate.

@Override
public Expression visitBinaryComparisonPredicate(MySqlParser.BinaryComparisonPredicateContext ctx) {
    Expression left = visitChildren(ctx.left);
    Expression right = visitChildren(ctx.right);
    switch(ctx.comparisonOperator().getText()) {
        case "<":
            return ComparisonBinaryExpression.lessThan(left, right);
        case "<=":
            return ComparisonBinaryExpression.lessEqual(left, right);
        case "=":
            return ComparisonBinaryExpression.equal(left, right);
        case ">":
            return ComparisonBinaryExpression.greaterThan(left, right);
        case ">=":
            return ComparisonBinaryExpression.greaterEqual(left, right);
    }
    throw new UnsupportedSyntaxException(ctx.toString() + ": it is not possible reach to this line of code");
}
Also used : UnsupportedSyntaxException(com.pingcap.tikv.exception.UnsupportedSyntaxException) Expression(com.pingcap.tikv.expression.Expression) ArithmeticBinaryExpression(com.pingcap.tikv.expression.ArithmeticBinaryExpression) ComparisonBinaryExpression(com.pingcap.tikv.expression.ComparisonBinaryExpression) LogicalBinaryExpression(com.pingcap.tikv.expression.LogicalBinaryExpression)

Example 3 with UnsupportedSyntaxException

use of com.pingcap.tikv.exception.UnsupportedSyntaxException in project tispark by pingcap.

the class AstBuilder method visitLogicalExpression.

public Expression visitLogicalExpression(MySqlParser.LogicalExpressionContext ctx) {
    ExpressionContext left = ctx.expression(0);
    ExpressionContext right = ctx.expression(1);
    switch(ctx.logicalOperator().getText()) {
        case "and":
            return LogicalBinaryExpression.and(visitChildren(left), visitChildren(right));
        case "or":
            return LogicalBinaryExpression.or(visitChildren(left), visitChildren(right));
        case "xor":
            return LogicalBinaryExpression.xor(visitChildren(left), visitChildren(right));
    }
    throw new UnsupportedSyntaxException(ctx.toString() + ": it is not possible reach to this line of code");
}
Also used : UnsupportedSyntaxException(com.pingcap.tikv.exception.UnsupportedSyntaxException) ExpressionContext(com.pingcap.tikv.parser.MySqlParser.ExpressionContext)

Example 4 with UnsupportedSyntaxException

use of com.pingcap.tikv.exception.UnsupportedSyntaxException in project tispark by pingcap.

the class TiParser method parseExpression.

public Expression parseExpression(String command) {
    if (command.equals(""))
        throw new UnsupportedSyntaxException("cannot parse empty command");
    MySqlLexer lexer = new MySqlLexer(new CaseChangingCharStream(CharStreams.fromString(command), true));
    CommonTokenStream cmnTokStrm = new CommonTokenStream(lexer);
    MySqlParser parser = new MySqlParser(cmnTokStrm);
    try {
        // first, try parsing with potentially faster SLL mode
        parser.getInterpreter().setPredictionMode(PredictionMode.SLL);
        return astBuilder.visitExpressions(parser.expressions());
    } catch (ParseCancellationException e) {
        // if we fail, parse with LL mode
        // rewind input stream
        cmnTokStrm.seek(0);
        parser.reset();
        // Try Again.
        parser.getInterpreter().setPredictionMode(PredictionMode.LL);
        return astBuilder.visitExpressions(parser.expressions());
    }
}
Also used : CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) UnsupportedSyntaxException(com.pingcap.tikv.exception.UnsupportedSyntaxException) ParseCancellationException(org.antlr.v4.runtime.misc.ParseCancellationException)

Aggregations

UnsupportedSyntaxException (com.pingcap.tikv.exception.UnsupportedSyntaxException)4 ArithmeticBinaryExpression (com.pingcap.tikv.expression.ArithmeticBinaryExpression)2 ComparisonBinaryExpression (com.pingcap.tikv.expression.ComparisonBinaryExpression)2 Expression (com.pingcap.tikv.expression.Expression)2 LogicalBinaryExpression (com.pingcap.tikv.expression.LogicalBinaryExpression)2 ExpressionContext (com.pingcap.tikv.parser.MySqlParser.ExpressionContext)1 CommonTokenStream (org.antlr.v4.runtime.CommonTokenStream)1 ParseCancellationException (org.antlr.v4.runtime.misc.ParseCancellationException)1