use of com.alibaba.cobar.parser.ast.expression.Expression in project cobar by alibaba.
the class MySQLOutputASTVisitor method visit.
@Override
public void visit(Identifier node) {
Expression parent = node.getParent();
if (parent != null) {
parent.accept(this);
appendable.append('.');
}
appendable.append(node.getIdText());
}
use of com.alibaba.cobar.parser.ast.expression.Expression in project cobar by alibaba.
the class MySQLOutputASTVisitor method visit.
@Override
public void visit(StraightJoin node) {
TableReference left = node.getLeftTableRef();
boolean paren = left.getPrecedence() < node.getPrecedence();
if (paren)
appendable.append('(');
left.accept(this);
if (paren)
appendable.append(')');
appendable.append(" STRAIGHT_JOIN ");
TableReference right = node.getRightTableRef();
paren = right.getPrecedence() <= node.getPrecedence();
if (paren)
appendable.append('(');
right.accept(this);
if (paren)
appendable.append(')');
Expression on = node.getOnCond();
if (on != null) {
appendable.append(" ON ");
on.accept(this);
}
}
use of com.alibaba.cobar.parser.ast.expression.Expression in project cobar by alibaba.
the class MySQLOutputASTVisitor method visit.
@Override
public void visit(DMLInsertStatement node) {
appendable.append("INSERT ");
switch(node.getMode()) {
case DELAY:
appendable.append("DELAYED ");
break;
case HIGH:
appendable.append("HIGH_PRIORITY ");
break;
case LOW:
appendable.append("LOW_PRIORITY ");
break;
case UNDEF:
break;
default:
throw new IllegalArgumentException("unknown mode for INSERT: " + node.getMode());
}
if (node.isIgnore())
appendable.append("IGNORE ");
appendable.append("INTO ");
node.getTable().accept(this);
appendable.append(' ');
List<Identifier> cols = node.getColumnNameList();
if (cols != null && !cols.isEmpty()) {
appendable.append('(');
printList(cols);
appendable.append(") ");
}
QueryExpression select = node.getSelect();
if (select == null) {
appendable.append("VALUES ");
List<RowExpression> rows = node.getRowList();
if (rows != null && !rows.isEmpty()) {
boolean isFst = true;
for (RowExpression row : rows) {
if (row == null || row.getRowExprList().isEmpty())
continue;
if (isFst)
isFst = false;
else
appendable.append(", ");
appendable.append('(');
printList(row.getRowExprList());
appendable.append(')');
}
} else {
throw new IllegalArgumentException("at least one row for INSERT");
}
} else {
select.accept(this);
}
List<Pair<Identifier, Expression>> dup = node.getDuplicateUpdate();
if (dup != null && !dup.isEmpty()) {
appendable.append(" ON DUPLICATE KEY UPDATE ");
boolean isFst = true;
for (Pair<Identifier, Expression> p : dup) {
if (isFst)
isFst = false;
else
appendable.append(", ");
p.getKey().accept(this);
appendable.append(" = ");
p.getValue().accept(this);
}
}
}
use of com.alibaba.cobar.parser.ast.expression.Expression in project cobar by alibaba.
the class MySQLOutputASTVisitor method visit.
@Override
public void visit(Trim node) {
String functionName = node.getFunctionName();
appendable.append(functionName).append('(');
Expression remStr = node.getRemainString();
switch(node.getDirection()) {
case DEFAULT:
if (remStr != null) {
remStr.accept(this);
appendable.append(" FROM ");
}
break;
case BOTH:
appendable.append("BOTH ");
if (remStr != null)
remStr.accept(this);
appendable.append(" FROM ");
break;
case LEADING:
appendable.append("LEADING ");
if (remStr != null)
remStr.accept(this);
appendable.append(" FROM ");
break;
case TRAILING:
appendable.append("TRAILING ");
if (remStr != null)
remStr.accept(this);
appendable.append(" FROM ");
break;
default:
throw new IllegalArgumentException("unknown trim direction: " + node.getDirection());
}
Expression str = node.getString();
str.accept(this);
appendable.append(')');
}
use of com.alibaba.cobar.parser.ast.expression.Expression 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