Skip to content

Commit bc891e7

Browse files
author
Tobias Warneke
committed
fixes #1429
1 parent 18e0d57 commit bc891e7

File tree

5 files changed

+27
-2
lines changed

5 files changed

+27
-2
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ Also I would like to know about needed examples or documentation stuff.
5656

5757
## Extensions in the latest SNAPSHOT version 4.3
5858

59+
* moved to JUnit 5 as a test framework
60+
* added **IGNORE NULLS** to window functions
61+
5962
Additionally, we have fixed many errors and improved the code quality and the test coverage.
6063

6164
## Extensions of JSqlParser releases

src/main/java/net/sf/jsqlparser/expression/AnalyticExpression.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ public class AnalyticExpression extends ASTNodeAccessImpl implements Expression
3636
private AnalyticType type = AnalyticType.OVER;
3737
private boolean distinct = false;
3838
private boolean unique = false;
39-
private boolean ignoreNulls = false;
39+
private boolean ignoreNulls = false; //IGNORE NULLS inside function parameters
40+
private boolean ignoreNullsOutside = false; //IGNORE NULLS outside function parameters
4041
private Expression filterExpression = null;
4142
private WindowElement windowElement = null;
4243
private List<OrderByElement> funcOrderBy = null;
@@ -178,6 +179,14 @@ public void setIgnoreNulls(boolean ignoreNulls) {
178179
this.ignoreNulls = ignoreNulls;
179180
}
180181

182+
public boolean isIgnoreNullsOutside() {
183+
return ignoreNullsOutside;
184+
}
185+
186+
public void setIgnoreNullsOutside(boolean ignoreNullsOutside) {
187+
this.ignoreNullsOutside = ignoreNullsOutside;
188+
}
189+
181190
@Override
182191
@SuppressWarnings({"PMD.CyclomaticComplexity", "PMD.NPathComplexity", "PMD.MissingBreakInSwitch"})
183192
public String toString() {
@@ -220,6 +229,10 @@ public String toString() {
220229
}
221230
}
222231

232+
if (isIgnoreNullsOutside()) {
233+
b.append("IGNORE NULLS ");
234+
}
235+
223236
switch (type) {
224237
case FILTER_ONLY:
225238
return b.toString();

src/main/java/net/sf/jsqlparser/util/deparser/ExpressionDeParser.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,10 @@ public void visit(AnalyticExpression aexpr) {
674674
buffer.append(" ");
675675
}
676676
}
677+
678+
if (aexpr.isIgnoreNullsOutside()) {
679+
buffer.append("IGNORE NULLS ");
680+
}
677681

678682
switch (aexpr.getType()) {
679683
case FILTER_ONLY:

src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4184,7 +4184,7 @@ void windowFun(AnalyticExpression retval):{
41844184
WindowElement windowElement = null;
41854185
boolean partitionByBrackets = false;
41864186
} {
4187-
(<K_OVER> {retval.setType(AnalyticType.OVER);}
4187+
([<K_IGNORE> <K_NULLS> { retval.setIgnoreNullsOutside(true); } ] <K_OVER> {retval.setType(AnalyticType.OVER);}
41884188
| <K_WITHIN> <K_GROUP> {retval.setType(AnalyticType.WITHIN_GROUP);} )
41894189

41904190
"("

src/test/java/net/sf/jsqlparser/statement/select/SelectTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4972,4 +4972,9 @@ public void testLogicalExpressionSelectItemIssue1381() throws JSQLParserExceptio
49724972
public void testKeywordAtIssue1414() throws JSQLParserException {
49734973
assertSqlCanBeParsedAndDeparsed("SELECT * FROM table1 at");
49744974
}
4975+
4976+
@Test
4977+
public void testIgnoreNullsForWindowFunctionsIssue1429() throws JSQLParserException {
4978+
assertSqlCanBeParsedAndDeparsed("SELECT lag(mydata) IGNORE NULLS OVER (ORDER BY sortorder) AS previous_status FROM mytable");
4979+
}
49754980
}

0 commit comments

Comments
 (0)