use of com.alibaba.cobar.parser.ast.expression.primary.Identifier 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.primary.Identifier in project cobar by alibaba.
the class MySQLDMLParser method tableFactor.
private TableReference tableFactor() throws SQLSyntaxErrorException {
String alias = null;
switch(lexer.token()) {
case PUNC_LEFT_PAREN:
lexer.nextToken();
Object ref = trsOrQuery();
match(PUNC_RIGHT_PAREN);
if (ref instanceof QueryExpression) {
alias = as();
return new SubqueryFactor((QueryExpression) ref, alias);
}
return (TableReferences) ref;
case IDENTIFIER:
Identifier table = identifier();
alias = as();
List<IndexHint> hintList = hintList();
return new TableRefFactor(table, alias, hintList);
default:
throw err("unexpected token for tableFactor: " + lexer.token());
}
}
use of com.alibaba.cobar.parser.ast.expression.primary.Identifier in project cobar by alibaba.
the class MySQLDMLReplaceParser method replace.
/**
* nothing has been pre-consumed <code><pre>
* 'REPLACE' ('LOW_PRIORITY' | 'DELAYED')? ('INTO')? tableName
* ( 'SET' colName ('='|':=') (expr|'DEFAULT') (',' colName ('='|':=') (expr|'DEFAULT'))*
* | '(' ( colName (','colName)* ')' ( '(' 'SELECT' ... ')'
* | 'SELECT' ...
* |('VALUES'|'VALUE') value ( ',' value )*
* )
* | 'SELECT' ... ')'
* )
* | 'SELECT' ...
* |('VALUES'|'VALUE') value ( ',' value )*
* )
* value := '(' (expr|'DEFAULT') ( ',' (expr|'DEFAULT'))* ')'
* </pre></code>
*/
public DMLReplaceStatement replace() throws SQLSyntaxErrorException {
match(KW_REPLACE);
DMLReplaceStatement.ReplaceMode mode = DMLReplaceStatement.ReplaceMode.UNDEF;
switch(lexer.token()) {
case KW_LOW_PRIORITY:
lexer.nextToken();
mode = DMLReplaceStatement.ReplaceMode.LOW;
break;
case KW_DELAYED:
lexer.nextToken();
mode = DMLReplaceStatement.ReplaceMode.DELAY;
break;
}
if (lexer.token() == KW_INTO) {
lexer.nextToken();
}
Identifier table = identifier();
List<Identifier> columnNameList;
List<RowExpression> rowList;
QueryExpression select;
List<Expression> tempRowValue;
switch(lexer.token()) {
case KW_SET:
lexer.nextToken();
columnNameList = new LinkedList<Identifier>();
tempRowValue = new LinkedList<Expression>();
for (; ; lexer.nextToken()) {
Identifier id = identifier();
match(OP_EQUALS, OP_ASSIGN);
Expression expr = exprParser.expression();
columnNameList.add(id);
tempRowValue.add(expr);
if (lexer.token() != PUNC_COMMA) {
break;
}
}
rowList = new ArrayList<RowExpression>(1);
rowList.add(new RowExpression(tempRowValue));
return new DMLReplaceStatement(mode, table, columnNameList, rowList);
case IDENTIFIER:
if (!"VALUE".equals(lexer.stringValueUppercase())) {
break;
}
case KW_VALUES:
lexer.nextToken();
columnNameList = null;
rowList = rowList();
return new DMLReplaceStatement(mode, table, columnNameList, rowList);
case KW_SELECT:
columnNameList = null;
select = select();
return new DMLReplaceStatement(mode, table, columnNameList, select);
case PUNC_LEFT_PAREN:
switch(lexer.nextToken()) {
case PUNC_LEFT_PAREN:
case KW_SELECT:
columnNameList = null;
select = selectPrimary();
match(PUNC_RIGHT_PAREN);
return new DMLReplaceStatement(mode, table, columnNameList, select);
}
columnNameList = idList();
match(PUNC_RIGHT_PAREN);
switch(lexer.token()) {
case PUNC_LEFT_PAREN:
case KW_SELECT:
select = selectPrimary();
return new DMLReplaceStatement(mode, table, columnNameList, select);
case KW_VALUES:
lexer.nextToken();
break;
default:
matchIdentifier("VALUE");
}
rowList = rowList();
return new DMLReplaceStatement(mode, table, columnNameList, rowList);
}
throw err("unexpected token for replace: " + lexer.token());
}
use of com.alibaba.cobar.parser.ast.expression.primary.Identifier in project cobar by alibaba.
the class PartitionKeyVisitor method visit.
@Override
public void visit(ComparisionNullSafeEqualsExpression node) {
Expression left = node.getLeftOprand();
Expression right = node.getRightOprand();
visitChild(2, false, false, left, right);
if (verdictColumn) {
if (left instanceof Identifier) {
comparisionEquals((Identifier) left, right.evaluation(evaluationParameter), true, node);
} else if (right instanceof Identifier) {
comparisionEquals((Identifier) right, left.evaluation(evaluationParameter), true, node);
}
}
}
use of com.alibaba.cobar.parser.ast.expression.primary.Identifier in project cobar by alibaba.
the class PartitionKeyVisitor method visit.
@Override
public void visit(ComparisionEqualsExpression node) {
Expression left = node.getLeftOprand();
Expression right = node.getRightOprand();
visitChild(2, false, false, left, right);
if (verdictColumn) {
if (left instanceof Identifier) {
comparisionEquals((Identifier) left, right.evaluation(evaluationParameter), false, node);
} else if (right instanceof Identifier) {
comparisionEquals((Identifier) right, left.evaluation(evaluationParameter), false, node);
}
}
}
Aggregations