mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
sql parser improved window function support, fix #4059
This commit is contained in:
@@ -3886,4 +3886,8 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
public void setCheckExecuteTime(boolean checkExecuteTime) {
|
||||
this.checkExecuteTime = checkExecuteTime;
|
||||
}
|
||||
|
||||
public void forEach(Connection conn) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)) {
|
||||
|
||||
+19
-1
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user