use of com.alibaba.cobar.parser.ast.expression.Expression in project cobar by alibaba.
the class MySQLExprParser method bitOrExpression.
/**
* @param consumed not null means that a token that has been pre-consumed
* stands for next token
*/
private Expression bitOrExpression(String consumed, String consumedUp) throws SQLSyntaxErrorException {
for (Expression expr = bitAndExpression(consumed, consumedUp); ; ) {
switch(lexer.token()) {
case OP_VERTICAL_BAR:
lexer.nextToken();
Expression newExpr = bitAndExpression(null, null);
expr = new BitOrExpression(expr, newExpr).setCacheEvalRst(cacheEvalRst);
break;
default:
return expr;
}
}
}
use of com.alibaba.cobar.parser.ast.expression.Expression in project cobar by alibaba.
the class MySQLExprParser method rightOprandOfIn.
/**
* @return {@link QueryExpression} or {@link InExpressionList}
*/
private Expression rightOprandOfIn() throws SQLSyntaxErrorException {
match(PUNC_LEFT_PAREN);
if (KW_SELECT == lexer.token()) {
QueryExpression subq = subQuery();
match(PUNC_RIGHT_PAREN);
return subq;
}
return new InExpressionList(expressionList(new LinkedList<Expression>())).setCacheEvalRst(cacheEvalRst);
}
use of com.alibaba.cobar.parser.ast.expression.Expression in project cobar by alibaba.
the class MySQLExprParser method logicalXORExpression.
/**
* <code>higherPRJExpr ( 'XOR' higherPRJExpr )*</code>
*
* @throws SQLSyntaxErrorException
*/
private Expression logicalXORExpression() throws SQLSyntaxErrorException {
for (Expression expr = logicalAndExpression(); ; ) {
switch(lexer.token()) {
case KW_XOR:
lexer.nextToken();
Expression newExpr = logicalAndExpression();
expr = new LogicalXORExpression(expr, newExpr).setCacheEvalRst(cacheEvalRst);
break;
default:
return expr;
}
}
}
use of com.alibaba.cobar.parser.ast.expression.Expression in project cobar by alibaba.
the class MySQLExprParser method timestampdiff.
/**
* first '(' has been consumed
*/
private Timestampdiff timestampdiff() throws SQLSyntaxErrorException {
IntervalPrimary.Unit unit = intervalPrimaryUnit();
match(PUNC_COMMA);
Expression interval = expression();
match(PUNC_COMMA);
Expression expr = expression();
match(PUNC_RIGHT_PAREN);
List<Expression> argument = new ArrayList<Expression>(2);
argument.add(interval);
argument.add(expr);
Timestampdiff func = new Timestampdiff(unit, argument);
func.setCacheEvalRst(cacheEvalRst);
return func;
}
use of com.alibaba.cobar.parser.ast.expression.Expression in project cobar by alibaba.
the class MySQLOutputASTVisitor method visit.
@Override
public void visit(CollateExpression node) {
Expression string = node.getString();
boolean paren = string.getPrecedence() < node.getPrecedence();
if (paren)
appendable.append('(');
string.accept(this);
if (paren)
appendable.append(')');
appendable.append(" COLLATE ").append(node.getCollateName());
}
Aggregations