use of com.alibaba.cobar.parser.ast.expression.Expression in project cobar by alibaba.
the class MySQLOutputASTVisitor method visit.
@Override
public void visit(GroupBy node) {
appendable.append("GROUP BY ");
boolean isFst = true;
for (Pair<Expression, SortOrder> p : node.getOrderByList()) {
if (isFst)
isFst = false;
else
appendable.append(", ");
Expression col = p.getKey();
col.accept(this);
switch(p.getValue()) {
case DESC:
appendable.append(" DESC");
break;
}
}
if (node.isWithRollup()) {
appendable.append(" WITH ROLLUP");
}
}
use of com.alibaba.cobar.parser.ast.expression.Expression in project cobar by alibaba.
the class MySQLOutputASTVisitor method visit.
@Override
public void visit(ComparisionIsExpression node) {
Expression comparee = node.getOperand();
boolean paren = comparee.getPrecedence() < node.getPrecedence();
if (paren)
appendable.append('(');
comparee.accept(this);
if (paren)
appendable.append(')');
switch(node.getMode()) {
case IS_NULL:
appendable.append(" IS NULL");
break;
case IS_TRUE:
appendable.append(" IS TRUE");
break;
case IS_FALSE:
appendable.append(" IS FALSE");
break;
case IS_UNKNOWN:
appendable.append(" IS UNKNOWN");
break;
case IS_NOT_NULL:
appendable.append(" IS NOT NULL");
break;
case IS_NOT_TRUE:
appendable.append(" IS NOT TRUE");
break;
case IS_NOT_FALSE:
appendable.append(" IS NOT FALSE");
break;
case IS_NOT_UNKNOWN:
appendable.append(" IS NOT UNKNOWN");
break;
default:
throw new IllegalArgumentException("unknown mode for IS expression: " + node.getMode());
}
}
use of com.alibaba.cobar.parser.ast.expression.Expression in project cobar by alibaba.
the class MySQLOutputASTVisitor method visit.
@Override
public void visit(DMLDeleteStatement node) {
appendable.append("DELETE ");
if (node.isLowPriority())
appendable.append("LOW_PRIORITY ");
if (node.isQuick())
appendable.append("QUICK ");
if (node.isIgnore())
appendable.append("IGNORE ");
TableReferences tableRefs = node.getTableRefs();
if (tableRefs == null) {
appendable.append("FROM ");
node.getTableNames().get(0).accept(this);
} else {
printList(node.getTableNames());
appendable.append(" FROM ");
node.getTableRefs().accept(this);
}
Expression where = node.getWhereCondition();
if (where != null) {
appendable.append(" WHERE ");
where.accept(this);
}
OrderBy orderBy = node.getOrderBy();
if (orderBy != null) {
appendable.append(' ');
orderBy.accept(this);
}
Limit limit = node.getLimit();
if (limit != null) {
appendable.append(' ');
limit.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(Cast node) {
String functionName = node.getFunctionName();
appendable.append(functionName).append('(');
node.getExpr().accept(this);
appendable.append(" AS ");
String typeName = node.getTypeName();
appendable.append(typeName);
Expression info1 = node.getTypeInfo1();
if (info1 != null) {
appendable.append('(');
info1.accept(this);
Expression info2 = node.getTypeInfo2();
if (info2 != null) {
appendable.append(", ");
info2.accept(this);
}
appendable.append(')');
}
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(ShowGrants node) {
appendable.append("SHOW GRANTS");
Expression user = node.getUser();
if (user != null) {
appendable.append(" FOR ");
user.accept(this);
}
}
Aggregations