use of com.alibaba.cobar.parser.ast.expression.Expression in project cobar by alibaba.
the class MySQLDMLInsertParser method onDuplicateUpdate.
/**
* @return null for not exist
*/
private List<Pair<Identifier, Expression>> onDuplicateUpdate() throws SQLSyntaxErrorException {
if (lexer.token() != KW_ON) {
return null;
}
lexer.nextToken();
matchIdentifier("DUPLICATE");
match(KW_KEY);
match(KW_UPDATE);
List<Pair<Identifier, Expression>> list;
Identifier col = identifier();
match(OP_EQUALS, OP_ASSIGN);
Expression expr = exprParser.expression();
if (lexer.token() == PUNC_COMMA) {
list = new LinkedList<Pair<Identifier, Expression>>();
list.add(new Pair<Identifier, Expression>(col, expr));
for (; lexer.token() == PUNC_COMMA; ) {
lexer.nextToken();
col = identifier();
match(OP_EQUALS, OP_ASSIGN);
expr = exprParser.expression();
list.add(new Pair<Identifier, Expression>(col, expr));
}
return list;
}
list = new ArrayList<Pair<Identifier, Expression>>(1);
list.add(new Pair<Identifier, Expression>(col, expr));
return list;
}
use of com.alibaba.cobar.parser.ast.expression.Expression in project cobar by alibaba.
the class MySQLExprParser method arithmeticTermOperatorExpression.
/**
* <code>higherExpr ( ('+'|'-') higherExpr)+</code>
*/
private Expression arithmeticTermOperatorExpression(String consumed, String consumedUp) throws SQLSyntaxErrorException {
Expression temp;
for (Expression expr = arithmeticFactorOperatorExpression(consumed, consumedUp); ; ) {
switch(lexer.token()) {
case OP_PLUS:
lexer.nextToken();
temp = arithmeticFactorOperatorExpression(null, null);
expr = new ArithmeticAddExpression(expr, temp).setCacheEvalRst(cacheEvalRst);
break;
case OP_MINUS:
lexer.nextToken();
temp = arithmeticFactorOperatorExpression(null, null);
expr = new ArithmeticSubtractExpression(expr, temp).setCacheEvalRst(cacheEvalRst);
break;
default:
return expr;
}
}
}
use of com.alibaba.cobar.parser.ast.expression.Expression in project cobar by alibaba.
the class MySQLExprParser method bitXORExpression.
/**
* <code>higherExpr ('^' higherExpr)+</code>
*/
private Expression bitXORExpression(String consumed, String consumedUp) throws SQLSyntaxErrorException {
Expression temp;
for (Expression expr = unaryOpExpression(consumed, consumedUp); ; ) {
switch(lexer.token()) {
case OP_CARET:
lexer.nextToken();
temp = unaryOpExpression(null, null);
expr = new BitXORExpression(expr, temp).setCacheEvalRst(cacheEvalRst);
break;
default:
return expr;
}
}
}
use of com.alibaba.cobar.parser.ast.expression.Expression in project cobar by alibaba.
the class MySQLExprParser method bitAndExpression.
private Expression bitAndExpression(String consumed, String consumedUp) throws SQLSyntaxErrorException {
for (Expression expr = bitShiftExpression(consumed, consumedUp); ; ) {
switch(lexer.token()) {
case OP_AMPERSAND:
lexer.nextToken();
Expression newExpr = bitShiftExpression(null, null);
expr = new BitAndExpression(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 ordinaryFunction.
/**
* id has been consumed. id must be a function name. current token must be
* {@link MySQLToken#PUNC_LEFT_PAREN}
*
* @param idUpper must be name of a function
* @return never null
*/
private FunctionExpression ordinaryFunction(String id, String idUpper) throws SQLSyntaxErrorException {
idUpper = Identifier.unescapeName(idUpper);
match(PUNC_LEFT_PAREN);
FunctionExpression funcExpr;
if (lexer.token() == PUNC_RIGHT_PAREN) {
lexer.nextToken();
funcExpr = functionManager.createFunctionExpression(idUpper, null);
} else {
List<Expression> args = expressionList(new LinkedList<Expression>());
funcExpr = functionManager.createFunctionExpression(idUpper, args);
}
if (funcExpr == null) {
throw new SQLSyntaxErrorException(id + "() is not a function");
}
funcExpr.setCacheEvalRst(cacheEvalRst);
return funcExpr;
}
Aggregations