use of com.alibaba.cobar.parser.ast.expression.primary.literal.IntervalPrimary in project cobar by alibaba.
the class MySQLExprParser method intervalExpression.
/**
* first <code>INTERVAL</code> has been consumed
*/
private Expression intervalExpression() throws SQLSyntaxErrorException {
Expression fstExpr;
List<Expression> argList = null;
if (lexer.token() == PUNC_LEFT_PAREN) {
if (lexer.nextToken() == KW_SELECT) {
fstExpr = subQuery();
match(PUNC_RIGHT_PAREN);
} else {
fstExpr = expression();
if (lexer.token() == PUNC_COMMA) {
lexer.nextToken();
argList = new LinkedList<Expression>();
argList.add(fstExpr);
argList = expressionList(argList);
} else {
match(PUNC_RIGHT_PAREN);
}
}
} else {
fstExpr = expression();
}
if (argList != null) {
return new Interval(argList).setCacheEvalRst(cacheEvalRst);
}
return new IntervalPrimary(fstExpr, intervalPrimaryUnit()).setCacheEvalRst(cacheEvalRst);
}
use of com.alibaba.cobar.parser.ast.expression.primary.literal.IntervalPrimary in project cobar by alibaba.
the class MySQLOutputASTVisitor method visit.
@Override
public void visit(IntervalPrimary node) {
appendable.append("INTERVAL ");
Expression quantity = node.getQuantity();
boolean paren = quantity.getPrecedence() < node.getPrecedence();
if (paren)
appendable.append('(');
quantity.accept(this);
if (paren)
appendable.append(')');
IntervalPrimary.Unit unit = node.getUnit();
appendable.append(' ').append(unit.name());
}
Aggregations