use of com.alibaba.cobar.parser.ast.expression.primary.Identifier in project cobar by alibaba.
the class PartitionKeyVisitor method visit.
@Override
public void visit(DMLUpdateStatement node) {
TableReference tr = node.getTableRefs();
visitChild(1, false, false, tr);
List<Pair<Identifier, Expression>> assignmentList = node.getValues();
if (assignmentList != null && !assignmentList.isEmpty()) {
List<ASTNode> list = new ArrayList<ASTNode>(assignmentList.size() * 2);
for (Pair<Identifier, Expression> p : assignmentList) {
if (p == null)
continue;
list.add(p.getKey());
list.add(p.getValue());
}
visitChild(2, false, false, list);
}
Expression where = node.getWhere();
visitChild(2, verdictColumn, false, where);
OrderBy order = node.getOrderBy();
visitChild(2, false, false, order);
}
use of com.alibaba.cobar.parser.ast.expression.primary.Identifier in project cobar by alibaba.
the class PartitionKeyVisitor method insertReplace.
private void insertReplace(DMLInsertReplaceStatement node) {
Identifier table = node.getTable();
List<Identifier> collist = node.getColumnNameList();
QueryExpression query = node.getSelect();
List<RowExpression> rows = node.getRowList();
tableAsTableFactor(table);
String tableName = table.getIdTextUpUnescape();
visitChild(2, false, false, collist);
if (query != null) {
query.accept(this);
return;
}
for (RowExpression row : rows) {
visitChild(2, false, false, row);
}
Map<String, List<Object>> colVals = ensureColumnValueByTable(tableName);
Map<String, Map<Object, Set<Pair<Expression, ASTNode>>>> colValsIndex = ensureColumnValueIndexByTable(tableName);
if (collist != null) {
for (int i = 0; i < collist.size(); ++i) {
String colName = collist.get(i).getIdTextUpUnescape();
if (isRuledColumn(tableName, colName)) {
List<Object> valueList = ensureColumnValueList(colVals, colName);
Map<Object, Set<Pair<Expression, ASTNode>>> valMap = ensureColumnValueIndexObjMap(colValsIndex, colName);
for (RowExpression row : rows) {
Expression expr = row.getRowExprList().get(i);
Object value = expr == null ? null : expr.evaluation(evaluationParameter);
if (value != Expression.UNEVALUATABLE) {
valueList.add(value);
addIntoColumnValueIndex(valMap, value, row, node);
}
}
}
}
}
}
use of com.alibaba.cobar.parser.ast.expression.primary.Identifier in project cobar by alibaba.
the class MySQLOutputASTVisitor method visit.
@Override
public void visit(DMLUpdateStatement node) {
appendable.append("UPDATE ");
if (node.isLowPriority()) {
appendable.append("LOW_PRIORITY ");
}
if (node.isIgnore()) {
appendable.append("IGNORE ");
}
node.getTableRefs().accept(this);
appendable.append(" SET ");
boolean isFst = true;
for (Pair<Identifier, Expression> p : node.getValues()) {
if (isFst)
isFst = false;
else
appendable.append(", ");
p.getKey().accept(this);
appendable.append(" = ");
p.getValue().accept(this);
}
Expression where = node.getWhere();
if (where != null) {
appendable.append(" WHERE ");
where.accept(this);
}
OrderBy order = node.getOrderBy();
if (order != null) {
appendable.append(' ');
order.accept(this);
}
Limit limit = node.getLimit();
if (limit != null) {
appendable.append(' ');
limit.accept(this);
}
}
use of com.alibaba.cobar.parser.ast.expression.primary.Identifier in project cobar by alibaba.
the class MySQLOutputASTVisitor method visit.
@Override
public void visit(TableRefFactor node) {
Identifier table = node.getTable();
table.accept(this);
String alias = node.getAlias();
if (alias != null) {
appendable.append(" AS ").append(alias);
}
List<IndexHint> list = node.getHintList();
if (list != null && !list.isEmpty()) {
appendable.append(' ');
printList(list, " ");
}
}
use of com.alibaba.cobar.parser.ast.expression.primary.Identifier in project cobar by alibaba.
the class MySQLOutputASTVisitor method visit.
@Override
public void visit(MTSRollbackStatement node) {
appendable.append("ROLLBACK");
Identifier savepoint = node.getSavepoint();
if (savepoint == null) {
MTSRollbackStatement.CompleteType type = node.getCompleteType();
switch(type) {
case CHAIN:
appendable.append(" AND CHAIN");
break;
case NO_CHAIN:
appendable.append(" AND NO CHAIN");
break;
case NO_RELEASE:
appendable.append(" NO RELEASE");
break;
case RELEASE:
appendable.append(" RELEASE");
break;
case UN_DEF:
break;
default:
throw new IllegalArgumentException("unrecgnized complete type: " + type);
}
} else {
appendable.append(" TO SAVEPOINT ");
savepoint.accept(this);
}
}
Aggregations