Skip to content

Commit 4bef952

Browse files
Merge remote-tracking branch 'origin/master' into Keywords
# Conflicts: # src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt
2 parents 2af3cd5 + bc891e7 commit 4bef952

152 files changed

Lines changed: 3666 additions & 3418 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

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

pom.xml

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,21 @@
3232
<scope>test</scope>
3333
</dependency>
3434
<dependency>
35-
<groupId>junit</groupId>
36-
<artifactId>junit</artifactId>
37-
<version>4.13.1</version>
38-
<scope>test</scope>
35+
<groupId>org.junit.jupiter</groupId>
36+
<artifactId>junit-jupiter</artifactId>
37+
<version>5.8.1</version>
38+
<scope>test</scope>
3939
</dependency>
4040
<dependency>
4141
<groupId>org.mockito</groupId>
4242
<artifactId>mockito-core</artifactId>
43-
<version>2.28.2</version>
43+
<version>3.12.4</version>
44+
<scope>test</scope>
45+
</dependency>
46+
<dependency>
47+
<groupId>org.mockito</groupId>
48+
<artifactId>mockito-junit-jupiter</artifactId>
49+
<version>3.12.4</version>
4450
<scope>test</scope>
4551
</dependency>
4652
<dependency>
@@ -61,7 +67,12 @@
6167
<version>1.4.200</version>
6268
<scope>test</scope>
6369
</dependency>
64-
70+
<dependency>
71+
<groupId>org.hamcrest</groupId>
72+
<artifactId>hamcrest-all</artifactId>
73+
<version>1.3</version>
74+
<scope>test</scope>
75+
</dependency>
6576
</dependencies>
6677

6778
<developers>
@@ -338,7 +349,7 @@
338349
<plugin>
339350
<groupId>org.apache.maven.plugins</groupId>
340351
<artifactId>maven-surefire-plugin</artifactId>
341-
<version>3.0.0-M4</version>
352+
<version>3.0.0-M5</version>
342353
<configuration>
343354
<trimStackTrace>false</trimStackTrace>
344355
</configuration>

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/expression/ExpressionVisitor.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ public interface ExpressionVisitor {
115115

116116
void visit(CastExpression cast);
117117

118+
void visit(TryCastExpression cast);
119+
118120
void visit(Modulo modulo);
119121

120122
void visit(AnalyticExpression aexpr);

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,11 @@ public void visit(CastExpression expr) {
304304
expr.getLeftExpression().accept(this);
305305
}
306306

307+
@Override
308+
public void visit(TryCastExpression expr) {
309+
expr.getLeftExpression().accept(this);
310+
}
311+
307312
@Override
308313
public void visit(Modulo expr) {
309314
visitBinaryExpression(expr);

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
import java.util.Arrays;
1313
import java.util.List;
14+
import java.util.Objects;
15+
1416
import net.sf.jsqlparser.parser.ASTNodeAccessImpl;
1517

1618
/**
@@ -95,4 +97,21 @@ public StringValue withValue(String value) {
9597
this.setValue(value);
9698
return this;
9799
}
100+
101+
@Override
102+
public boolean equals(Object o) {
103+
if (this == o) {
104+
return true;
105+
}
106+
if (o == null || getClass() != o.getClass()) {
107+
return false;
108+
}
109+
StringValue that = (StringValue) o;
110+
return Objects.equals(value, that.value) && Objects.equals(prefix, that.prefix);
111+
}
112+
113+
@Override
114+
public int hashCode() {
115+
return Objects.hash(value, prefix);
116+
}
98117
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
public class TimezoneExpression extends ASTNodeAccessImpl implements Expression {
1818

1919
private Expression leftExpression;
20-
private ArrayList<String> timezoneExpressions = new ArrayList<>();
20+
private ArrayList<Expression> timezoneExpressions = new ArrayList<>();
2121

2222
public Expression getLeftExpression() {
2323
return leftExpression;
@@ -32,19 +32,19 @@ public void accept(ExpressionVisitor expressionVisitor) {
3232
expressionVisitor.visit(this);
3333
}
3434

35-
public List<String> getTimezoneExpressions() {
35+
public List<Expression> getTimezoneExpressions() {
3636
return timezoneExpressions;
3737
}
3838

39-
public void addTimezoneExpression(String timezoneExpr) {
39+
public void addTimezoneExpression(Expression timezoneExpr) {
4040
this.timezoneExpressions.add(timezoneExpr);
4141
}
4242

4343
@Override
4444
public String toString() {
4545
String returnValue = getLeftExpression().toString();
46-
for (String expr : timezoneExpressions) {
47-
returnValue += " AT TIME ZONE " + expr;
46+
for (Expression expr : timezoneExpressions) {
47+
returnValue += " AT TIME ZONE " + expr.toString();
4848
}
4949

5050
return returnValue;
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/*-
2+
* #%L
3+
* JSQLParser library
4+
* %%
5+
* Copyright (C) 2004 - 2019 JSQLParser
6+
* %%
7+
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
8+
* #L%
9+
*/
10+
package net.sf.jsqlparser.expression;
11+
12+
import net.sf.jsqlparser.parser.ASTNodeAccessImpl;
13+
import net.sf.jsqlparser.statement.create.table.ColDataType;
14+
15+
public class TryCastExpression extends ASTNodeAccessImpl implements Expression {
16+
17+
private Expression leftExpression;
18+
private ColDataType type;
19+
private RowConstructor rowConstructor;
20+
private boolean useCastKeyword = true;
21+
22+
public RowConstructor getRowConstructor() {
23+
return rowConstructor;
24+
}
25+
26+
public void setRowConstructor(RowConstructor rowConstructor) {
27+
this.rowConstructor = rowConstructor;
28+
this.type = null;
29+
}
30+
31+
public TryCastExpression withRowConstructor(RowConstructor rowConstructor) {
32+
setRowConstructor(rowConstructor);
33+
return this;
34+
}
35+
36+
public ColDataType getType() {
37+
return type;
38+
}
39+
40+
public void setType(ColDataType type) {
41+
this.type = type;
42+
this.rowConstructor = null;
43+
}
44+
45+
public Expression getLeftExpression() {
46+
return leftExpression;
47+
}
48+
49+
public void setLeftExpression(Expression expression) {
50+
leftExpression = expression;
51+
}
52+
53+
@Override
54+
public void accept(ExpressionVisitor expressionVisitor) {
55+
expressionVisitor.visit(this);
56+
}
57+
58+
public boolean isUseCastKeyword() {
59+
return useCastKeyword;
60+
}
61+
62+
public void setUseCastKeyword(boolean useCastKeyword) {
63+
this.useCastKeyword = useCastKeyword;
64+
}
65+
66+
@Override
67+
public String toString() {
68+
if (useCastKeyword) {
69+
return rowConstructor!=null
70+
? "TRY_CAST(" + leftExpression + " AS " + rowConstructor.toString() + ")"
71+
: "TRY_CAST(" + leftExpression + " AS " + type.toString() + ")";
72+
} else {
73+
return leftExpression + "::" + type.toString();
74+
}
75+
}
76+
77+
public TryCastExpression withType(ColDataType type) {
78+
this.setType(type);
79+
return this;
80+
}
81+
82+
public TryCastExpression withUseCastKeyword(boolean useCastKeyword) {
83+
this.setUseCastKeyword(useCastKeyword);
84+
return this;
85+
}
86+
87+
public TryCastExpression withLeftExpression(Expression leftExpression) {
88+
this.setLeftExpression(leftExpression);
89+
return this;
90+
}
91+
92+
public <E extends Expression> E getLeftExpression(Class<E> type) {
93+
return type.cast(getLeftExpression());
94+
}
95+
}

src/main/java/net/sf/jsqlparser/expression/operators/relational/LikeExpression.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
public class LikeExpression extends BinaryExpression {
1717

1818
private boolean not = false;
19-
private String escape = null;
19+
private Expression escapeExpression = null;
2020
private boolean caseInsensitive = false;
2121

2222
public boolean isNot() {
@@ -40,19 +40,19 @@ public String getStringExpression() {
4040
@Override
4141
public String toString() {
4242
String retval = getLeftExpression() + " " + (not ? "NOT " : "") + getStringExpression() + " " + getRightExpression();
43-
if (escape != null) {
44-
retval += " ESCAPE " + "'" + escape + "'";
43+
if (escapeExpression != null) {
44+
retval += " ESCAPE " + escapeExpression ;
4545
}
4646

4747
return retval;
4848
}
4949

50-
public String getEscape() {
51-
return escape;
50+
public Expression getEscape() {
51+
return escapeExpression;
5252
}
5353

54-
public void setEscape(String escape) {
55-
this.escape = escape;
54+
public void setEscape(Expression escapeExpression) {
55+
this.escapeExpression = escapeExpression;
5656
}
5757

5858
public boolean isCaseInsensitive() {
@@ -63,7 +63,7 @@ public void setCaseInsensitive(boolean caseInsensitive) {
6363
this.caseInsensitive = caseInsensitive;
6464
}
6565

66-
public LikeExpression withEscape(String escape) {
66+
public LikeExpression withEscape(Expression escape) {
6767
this.setEscape(escape);
6868
return this;
6969
}

0 commit comments

Comments
 (0)