improved odps sql parser for select_distribute_by. issue #1492

This commit is contained in:
wenshao
2016-11-18 22:12:54 +08:00
parent f412712241
commit df440aa78c
4 changed files with 65 additions and 11 deletions
@@ -35,7 +35,7 @@ public class OdpsSelectQueryBlock extends SQLSelectQueryBlock {
protected List<SQLHint> hints;
protected SQLExpr distributeBy;
protected List<SQLExpr> distributeBy = new ArrayList<SQLExpr>();
protected List<SQLSelectOrderByItem> sortBy = new ArrayList<SQLSelectOrderByItem>(2);
public OdpsSelectQueryBlock(){
@@ -50,14 +50,10 @@ public class OdpsSelectQueryBlock extends SQLSelectQueryBlock {
this.orderBy = orderBy;
}
public SQLExpr getDistributeBy() {
public List<SQLExpr> getDistributeBy() {
return distributeBy;
}
public void setDistributeBy(SQLExpr distributeBy) {
this.distributeBy = distributeBy;
}
public List<SQLSelectOrderByItem> getSortBy() {
return sortBy;
}
@@ -85,9 +85,7 @@ public class OdpsSelectParser extends SQLSelectParser {
if (lexer.token() == Token.DISTRIBUTE) {
lexer.nextToken();
accept(Token.BY);
SQLExpr distributeBy = this.expr();
queryBlock.setDistributeBy(distributeBy);
this.exprParser.exprList(queryBlock.getDistributeBy(), queryBlock);
if (identifierEquals("SORT")) {
lexer.nextToken();
@@ -513,10 +513,10 @@ public class OdpsOutputVisitor extends SQLASTOutputVisitor implements OdpsASTVis
x.getOrderBy().accept(this);
}
if (x.getDistributeBy() != null) {
if (x.getDistributeBy().size() > 0) {
println();
print0(ucase ? "DISTRIBUTE BY " : "distribute by ");
x.getDistributeBy().accept(this);
printAndAccept(x.getDistributeBy(), ", ");
if (!x.getSortBy().isEmpty()) {
print0(ucase ? " SORT BY " : " sort by ");