sql parser improved window function support, fix #4059

This commit is contained in:
高铁
2020-12-12 20:09:33 +08:00
parent ae675fec72
commit 031fede035
7 changed files with 72 additions and 8 deletions
@@ -77,8 +77,11 @@ public class OracleAnalytic extends SQLOver implements SQLReplaceable, OracleExp
return x;
}
public void setWindowing(OracleAnalyticWindowing windowing) {
this.windowing = windowing;
public void setWindowing(OracleAnalyticWindowing x) {
if (x != null) {
x.setParent(this);
}
this.windowing = x;
}
public SQLDataType computeDataType() {
@@ -899,6 +899,11 @@ public class OracleExprParser extends SQLExprParser {
beginExpr = relational();
}
final SQLOver.WindowingBound beginBound = parseWindowingBound();
if (beginBound != null) {
over.setWindowingBetweenBeginBound(beginBound);
}
accept(Token.AND);
SQLExpr endExpr;
if (lexer.identifierEquals(FnvHash.Constants.CURRENT)) {
@@ -109,7 +109,25 @@ public class OracleOutputVisitor extends SQLASTOutputVisitor implements OracleAS
public boolean visit(OracleAnalyticWindowing x) {
print0(x.getType().name().toUpperCase());
print(' ');
x.getExpr().accept(this);
SQLExpr expr = x.getExpr();
if (expr instanceof SQLBetweenExpr && x.getParent() instanceof SQLOver) {
SQLOver over = (SQLOver) x.getParent();
SQLBetweenExpr betweenExpr = (SQLBetweenExpr) expr;
SQLOver.WindowingBound beginBound = over.getWindowingBetweenBeginBound();
if (beginBound != null) {
betweenExpr.getBeginExpr().accept(this);
print(' ');
print0(ucase ? beginBound.name : beginBound.name_lower);
print0(ucase ? " AND " : " and ");
betweenExpr.getEndExpr().accept(this);
return false;
}
}
expr.accept(this);
return false;
}
@@ -2299,7 +2299,7 @@ public class SQLExprParser extends SQLParser {
accept(Token.RPAREN);
}
private SQLOver.WindowingBound parseWindowingBound() {
protected SQLOver.WindowingBound parseWindowingBound() {
if (lexer.identifierEquals(FnvHash.Constants.PRECEDING)) {
lexer.nextToken();
return SQLOver.WindowingBound.PRECEDING;