mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
sql parser improved db2 support
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user