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");
}
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");
}
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");
}
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());
}
}
Aggregations