Skip to content

Commit

Permalink
fix oracle window between dialect error
Browse files Browse the repository at this point in the history
Signed-off-by: bantao <bantao@foxmail.com>
  • Loading branch information
bantao authored and lizongbo committed Apr 29, 2024
1 parent 48ea6cb commit 18d6872
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -928,6 +928,10 @@ protected SQLAggregateExpr parseAggregateExpr(String methodName) {
endExpr = relational();
}

final SQLOver.WindowingBound endBound = parseWindowingBound();
if (endBound != null) {
over.setWindowingBetweenEndBound(endBound);
}
SQLExpr expr = new SQLBetweenExpr(null, beginExpr, endExpr);
windowing.setExpr(expr);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ public boolean visit(OracleAnalytic x) {
if (x.isWindowingPreceding()) {
print0(ucase ? " PRECEDING" : " preceding");
}
if (x.isWindowingBetweenEndFollowing()) {
print0(ucase ? " FOLLOWING" : " following");
}

print(')');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,44 @@ public void test_0() throws Exception {
assertEquals("SELECT J01.COL_A, J01.COL_B, \"SUM\"(J01.COL_C) OVER (PARTITION BY J01.COL_A ORDER BY J01.COL_B NULLS FIRST ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS COL_C\n" +
"FROM TAB_A J01", stmt.toString());
}
public void test_1() throws Exception {
String sql = "SELECT\n" +
"J01.COL_A,\n" +
"J01.COL_B,\n" +
"\"SUM\"(J01.COL_C) OVER (\n" +
"PARTITION BY J01.COL_A ORDER BY J01.COL_B NULLS FIRST ROWS BETWEEN 5 PRECEDING AND 8 FOLLOWING\n" +
") AS COL_C\n" +
"FROM\n" +
"TAB_A J01";

List<SQLStatement> statementList = SQLUtils.parseStatements(sql, JdbcConstants.ORACLE);

assertEquals(1, statementList.size());

SQLSelectStatement stmt = (SQLSelectStatement) statementList.get(0);
System.out.println(stmt.toString());

assertEquals("SELECT J01.COL_A, J01.COL_B, \"SUM\"(J01.COL_C) OVER (PARTITION BY J01.COL_A ORDER BY J01.COL_B NULLS FIRST ROWS BETWEEN 5 PRECEDING AND 8 FOLLOWING) AS COL_C\n" +
"FROM TAB_A J01", stmt.toString());
}

public void test_2() throws Exception {
String sql = "SELECT\n" +
"J01.COL_A,\n" +
"J01.COL_B,\n" +
"\"SUM\"(J01.COL_C) OVER (\n" +
"PARTITION BY J01.COL_A ORDER BY J01.COL_B NULLS FIRST ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING\n" +
") AS COL_C\n" +
"FROM\n" +
"TAB_A J01";

List<SQLStatement> statementList = SQLUtils.parseStatements(sql, JdbcConstants.ORACLE);

assertEquals(1, statementList.size());

SQLSelectStatement stmt = (SQLSelectStatement) statementList.get(0);
System.out.println(stmt.toString());
assertEquals("SELECT J01.COL_A, J01.COL_B, \"SUM\"(J01.COL_C) OVER (PARTITION BY J01.COL_A ORDER BY J01.COL_B NULLS FIRST ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS COL_C\n" +
"FROM TAB_A J01", stmt.toString());
}
}

0 comments on commit 18d6872

Please sign in to comment.