use of com.alibaba.cobar.parser.ast.fragment.SortOrder 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.fragment.SortOrder in project cobar by alibaba.
the class MySQLDMLParser method groupBy.
/**
* nothing has been pre-consumed
*
* @return null if there is no order by
*/
protected GroupBy groupBy() throws SQLSyntaxErrorException {
if (lexer.token() != KW_GROUP) {
return null;
}
lexer.nextToken();
match(KW_BY);
Expression expr = exprParser.expression();
SortOrder order = SortOrder.ASC;
GroupBy groupBy;
switch(lexer.token()) {
case KW_DESC:
order = SortOrder.DESC;
case KW_ASC:
lexer.nextToken();
default:
break;
}
switch(lexer.token()) {
case KW_WITH:
lexer.nextToken();
matchIdentifier("ROLLUP");
return new GroupBy(expr, order, true);
case PUNC_COMMA:
break;
default:
return new GroupBy(expr, order, false);
}
for (groupBy = new GroupBy().addOrderByItem(expr, order); lexer.token() == PUNC_COMMA; ) {
lexer.nextToken();
order = SortOrder.ASC;
expr = exprParser.expression();
switch(lexer.token()) {
case KW_DESC:
order = SortOrder.DESC;
case KW_ASC:
lexer.nextToken();
default:
break;
}
groupBy.addOrderByItem(expr, order);
if (lexer.token() == KW_WITH) {
lexer.nextToken();
matchIdentifier("ROLLUP");
return groupBy.setWithRollup();
}
}
return groupBy;
}
use of com.alibaba.cobar.parser.ast.fragment.SortOrder in project cobar by alibaba.
the class MySQLDMLParser method orderBy.
/**
* nothing has been pre-consumed
*
* @return null if there is no order by
*/
protected OrderBy orderBy() throws SQLSyntaxErrorException {
if (lexer.token() != KW_ORDER) {
return null;
}
lexer.nextToken();
match(KW_BY);
Expression expr = exprParser.expression();
SortOrder order = SortOrder.ASC;
OrderBy orderBy;
switch(lexer.token()) {
case KW_DESC:
order = SortOrder.DESC;
case KW_ASC:
if (lexer.nextToken() != PUNC_COMMA) {
return new OrderBy(expr, order);
}
case PUNC_COMMA:
orderBy = new OrderBy();
orderBy.addOrderByItem(expr, order);
break;
default:
return new OrderBy(expr, order);
}
for (; lexer.token() == PUNC_COMMA; ) {
lexer.nextToken();
order = SortOrder.ASC;
expr = exprParser.expression();
switch(lexer.token()) {
case KW_DESC:
order = SortOrder.DESC;
case KW_ASC:
lexer.nextToken();
}
orderBy.addOrderByItem(expr, order);
}
return orderBy;
}
use of com.alibaba.cobar.parser.ast.fragment.SortOrder in project cobar by alibaba.
the class PartitionKeyVisitor method sortPairList.
private void sortPairList(List<Pair<Expression, SortOrder>> list) {
if (list == null || list.isEmpty())
return;
Expression[] exprs = new Expression[list.size()];
int i = 0;
for (Pair<Expression, SortOrder> p : list) {
exprs[i] = p.getKey();
++i;
}
visitChild(2, false, false, exprs);
}
use of com.alibaba.cobar.parser.ast.fragment.SortOrder in project cobar by alibaba.
the class MySQLOutputASTVisitor method visit.
@Override
public void visit(OrderBy node) {
appendable.append("ORDER 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;
}
}
}
Aggregations