sql parser improved db2 support

This commit is contained in:
高铁
2016-03-18 16:34:02 +08:00
parent 793658499e
commit bf1ad5da0c
5 changed files with 122 additions and 0 deletions
@@ -25,6 +25,9 @@ public class SQLOver extends SQLObjectImpl {
protected final List<SQLExpr> partitionBy = new ArrayList<SQLExpr>();
protected SQLOrderBy orderBy;
// for db2
protected SQLExpr of;
public SQLOver(){
}
@@ -38,6 +41,7 @@ public class SQLOver extends SQLObjectImpl {
if (visitor.visit(this)) {
acceptChild(visitor, this.partitionBy);
acceptChild(visitor, this.orderBy);
acceptChild(visitor, this.of);
}
visitor.endVisit(this);
}
@@ -53,6 +57,17 @@ public class SQLOver extends SQLObjectImpl {
this.orderBy = orderBy;
}
public SQLExpr getOf() {
return of;
}
public void setOf(SQLExpr of) {
if (of != null) {
of.setParent(this);
}
this.of = of;
}
public List<SQLExpr> getPartitionBy() {
return partitionBy;
}
@@ -36,6 +36,7 @@ public class DB2Lexer extends Lexer {
map.put("FIRST", Token.FIRST);
map.put("ONLY", Token.ONLY);
map.put("OPTIMIZE", Token.OPTIMIZE);
map.put("OF", Token.OF);
DEFAULT_DB2_KEYWORDS = new Keywords(map);
}
@@ -1036,6 +1036,12 @@ public class SQLExprParser extends SQLParser {
}
over.setOrderBy(parseOrderBy());
if (lexer.token() == Token.OF) {
lexer.nextToken();
SQLExpr of = this.expr();
over.setOf(of);
}
accept(Token.RPAREN);
aggregateExpr.setOver(over);
@@ -1632,9 +1632,16 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
printAndAccept(x.getPartitionBy(), ", ");
print(' ');
}
if (x.getOrderBy() != null) {
x.getOrderBy().accept(this);
}
if (x.getOf() != null) {
print0(ucase ? " OF " : " of ");
x.getOf().accept(this);
}
print(')');
return false;
}