Skip to content

Commit 61bfb68

Browse files
Merge Master
2 parents ab6f9d5 + fb6e950 commit 61bfb68

37 files changed

+1187
-275
lines changed

.github/release.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
changelog:
2+
categories:
3+
- title: Bugs solved
4+
labels:
5+
- "bug"
6+
- title: Changes and new Features
7+
labels:
8+
- "*"

README.md

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,26 +54,16 @@ To help JSqlParser's development you are encouraged to provide
5454

5555
Any requests for examples or any particular documentation will be most welcome.
5656

57-
## Extensions in the latest SNAPSHOT version 4.5
57+
## Extensions in the latest SNAPSHOT version 4.6
58+
59+
* support for named windows in window expressions: `SELECT sum(c) OVER winName FROM mytable WINDOW winName AS (PARTITION BY pcol)`
5860

5961
Additionally, we have fixed many errors and improved the code quality and the test coverage.
6062

6163
## Extensions of JSqlParser releases
6264

6365
* [Release Notes](https://github.com/JSQLParser/JSqlParser/releases)
6466
* Modifications before GitHub's release tagging are listed in the [Older Releases](https://github.com/JSQLParser/JSqlParser/wiki/Older-Releases) page.
65-
* UnsupportedStatement support instead of throwing Exceptions
66-
* support for **RETURNING** clause of a **DELETE** statement
67-
* Add support for `... ALTER COLUMN ... DROP DEFAULT`
68-
* `INSERT` supports `SetOperations` (e. g. `INSERT INTO ... SELECT ... FROM ... UNION SELECT ... FROM ...`), those `SetOperations` are used both for `SELECT` and `VALUES` clauses (API change) in order to simplify the Grammar
69-
* `(WITH ... SELECT ...)` statements within brackets are now supported
70-
* Postgres `NATURAL { INNER | LEFT | RIGHT } JOIN` support
71-
* extended support for Hive dialect `GROUPING SETS`
72-
* support for Postgresql **drop** function
73-
* support table option **character set** and **index** options
74-
* support Postgresql optional **TABLE** in **TRUNCATE**
75-
* support for `ANALYZE mytable`
76-
7767

7868
## Building from the sources
7969

build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,15 +168,15 @@ spotbugsMain {
168168

169169
spotbugs {
170170
// fail only on P1 and without the net.sf.jsqlparser.parser.*
171-
excludeFilter = file("spotBugsExcludeFilter.xml")
171+
excludeFilter = file("config/spotbugs/spotBugsExcludeFilter.xml")
172172

173173
// do not run over the test, although we should do that eventually
174174
spotbugsTest.enabled = false
175175
}
176176

177177
pmd {
178178
consoleOutput = false
179-
toolVersion = "6.44.0"
179+
toolVersion = "6.46.0"
180180

181181
sourceSets = [sourceSets.main]
182182

@@ -185,7 +185,7 @@ pmd {
185185

186186
//rulesMinimumPriority = 1
187187

188-
ruleSetFiles = files("ruleset.xml")
188+
ruleSetFiles = files("config/pmd/ruleset.xml")
189189

190190
pmdMain {
191191
excludes = [

ruleset.xml renamed to config/pmd/ruleset.xml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,17 @@ under the License.
6666
<rule ref="category/java/design.xml/SimplifiedTernary" />
6767
<rule ref="category/java/design.xml/UselessOverridingMethod" />
6868
<rule ref="category/java/design.xml/AvoidThrowingNullPointerException" />
69-
70-
<!-- for Codazy -->
69+
70+
<!--
71+
<rule ref="category/java/design.xml/NPathComplexity">
72+
<properties>
73+
<property name="reportLevel" value="200" />
74+
</properties>
75+
</rule>
76+
-->
77+
78+
79+
<!-- for Codazy -->
7180
<rule ref="category/java/design.xml/CyclomaticComplexity" />
7281
<rule ref="category/java/design.xml/ExcessiveMethodLength" />
7382
<rule ref="category/java/bestpractices.xml/SwitchStmtsShouldHaveDefault" />
File renamed without changes.

pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<modelVersion>4.0.0</modelVersion>
33
<groupId>com.github.jsqlparser</groupId>
44
<artifactId>jsqlparser</artifactId>
5-
<version>4.5-SNAPSHOT</version>
5+
<version>4.6-SNAPSHOT</version>
66
<name>JSQLParser library</name>
77
<inceptionYear>2004</inceptionYear>
88
<organization>
@@ -121,7 +121,7 @@
121121
<configuration>
122122
<rulesets>
123123
<!-- Custom local file system rule set -->
124-
<ruleset>${project.basedir}/ruleset.xml</ruleset>
124+
<ruleset>${project.basedir}/config/pmd/ruleset.xml</ruleset>
125125
</rulesets>
126126
<excludes>
127127
<exclude>**/*Bean.java</exclude>
@@ -625,7 +625,7 @@
625625

626626
<properties>
627627
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
628-
<pmdVersion>6.36.0</pmdVersion>
628+
<pmdVersion>6.46.0</pmdVersion>
629629
</properties>
630630

631631
<description>JSqlParser parses an SQL statement and translate it into a hierarchy of Java classes.

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

Lines changed: 37 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,14 @@
1616
import net.sf.jsqlparser.statement.select.OrderByElement;
1717

1818
/**
19-
* Analytic function. The name of the function is variable but the parameters following the special
20-
* analytic function path. e.g. row_number() over (order by test). Additional there can be an
21-
* expression for an analytical aggregate like sum(col) or the "all collumns" wildcard like
22-
* count(*).
19+
* Analytic function. The name of the function is variable but the parameters following the special analytic function
20+
* path. e.g. row_number() over (order by test). Additional there can be an expression for an analytical aggregate like
21+
* sum(col) or the "all collumns" wildcard like count(*).
2322
*
2423
* @author tw
2524
*/
2625
public class AnalyticExpression extends ASTNodeAccessImpl implements Expression {
2726

28-
private final OrderByClause orderBy = new OrderByClause();
29-
private final PartitionByClause partitionBy = new PartitionByClause();
3027
private String name;
3128
private Expression expression;
3229
private Expression offset;
@@ -39,8 +36,9 @@ public class AnalyticExpression extends ASTNodeAccessImpl implements Expression
3936
private boolean ignoreNulls = false; //IGNORE NULLS inside function parameters
4037
private boolean ignoreNullsOutside = false; //IGNORE NULLS outside function parameters
4138
private Expression filterExpression = null;
42-
private WindowElement windowElement = null;
4339
private List<OrderByElement> funcOrderBy = null;
40+
private String windowName = null; // refers to an external window definition (paritionBy, orderBy, windowElement)
41+
private WindowDefinition windowDef = new WindowDefinition();
4442

4543
public AnalyticExpression() {
4644
}
@@ -76,11 +74,11 @@ public void accept(ExpressionVisitor expressionVisitor) {
7674
}
7775

7876
public List<OrderByElement> getOrderByElements() {
79-
return orderBy.getOrderByElements();
77+
return windowDef.orderBy.getOrderByElements();
8078
}
8179

8280
public void setOrderByElements(List<OrderByElement> orderByElements) {
83-
orderBy.setOrderByElements(orderByElements);
81+
windowDef.orderBy.setOrderByElements(orderByElements);
8482
}
8583

8684
public KeepExpression getKeep() {
@@ -92,19 +90,19 @@ public void setKeep(KeepExpression keep) {
9290
}
9391

9492
public ExpressionList getPartitionExpressionList() {
95-
return partitionBy.getPartitionExpressionList();
93+
return windowDef.partitionBy.getPartitionExpressionList();
9694
}
9795

9896
public void setPartitionExpressionList(ExpressionList partitionExpressionList) {
9997
setPartitionExpressionList(partitionExpressionList, false);
10098
}
10199

102100
public void setPartitionExpressionList(ExpressionList partitionExpressionList, boolean brackets) {
103-
partitionBy.setPartitionExpressionList(partitionExpressionList, brackets);
101+
windowDef.partitionBy.setPartitionExpressionList(partitionExpressionList, brackets);
104102
}
105103

106104
public boolean isPartitionByBrackets() {
107-
return partitionBy.isBrackets();
105+
return windowDef.partitionBy.isBrackets();
108106
}
109107

110108
public String getName() {
@@ -140,11 +138,11 @@ public void setDefaultValue(Expression defaultValue) {
140138
}
141139

142140
public WindowElement getWindowElement() {
143-
return windowElement;
141+
return windowDef.windowElement;
144142
}
145143

146144
public void setWindowElement(WindowElement windowElement) {
147-
this.windowElement = windowElement;
145+
windowDef.windowElement = windowElement;
148146
}
149147

150148
public AnalyticType getType() {
@@ -187,6 +185,22 @@ public void setIgnoreNullsOutside(boolean ignoreNullsOutside) {
187185
this.ignoreNullsOutside = ignoreNullsOutside;
188186
}
189187

188+
public String getWindowName() {
189+
return windowName;
190+
}
191+
192+
public void setWindowName(String windowName) {
193+
this.windowName = windowName;
194+
}
195+
196+
public WindowDefinition getWindowDefinition() {
197+
return windowDef;
198+
}
199+
200+
public void setWindowDefinition(WindowDefinition windowDef) {
201+
this.windowDef = windowDef;
202+
}
203+
190204
@Override
191205
@SuppressWarnings({"PMD.CyclomaticComplexity", "PMD.NPathComplexity", "PMD.MissingBreakInSwitch"})
192206
public String toString() {
@@ -210,11 +224,11 @@ public String toString() {
210224
if (isIgnoreNulls()) {
211225
b.append(" IGNORE NULLS");
212226
}
213-
if (funcOrderBy!=null) {
227+
if (funcOrderBy != null) {
214228
b.append(" ORDER BY ");
215-
b.append( funcOrderBy.stream().map(OrderByElement::toString).collect(joining(", ")));
229+
b.append(funcOrderBy.stream().map(OrderByElement::toString).collect(joining(", ")));
216230
}
217-
231+
218232
b.append(") ");
219233
if (keep != null) {
220234
b.append(keep.toString()).append(" ");
@@ -232,7 +246,7 @@ public String toString() {
232246
if (isIgnoreNullsOutside()) {
233247
b.append("IGNORE NULLS ");
234248
}
235-
249+
236250
switch (type) {
237251
case FILTER_ONLY:
238252
return b.toString();
@@ -242,20 +256,14 @@ public String toString() {
242256
default:
243257
b.append("OVER");
244258
}
245-
b.append(" (");
246259

247-
partitionBy.toStringPartitionBy(b);
248-
orderBy.toStringOrderByElements(b);
249-
250-
if (windowElement != null) {
251-
if (orderBy.getOrderByElements() != null) {
252-
b.append(' ');
253-
}
254-
b.append(windowElement);
260+
if (windowName != null) {
261+
b.append(" ").append(windowName);
262+
} else {
263+
b.append(" ");
264+
b.append(windowDef.toString());
255265
}
256266

257-
b.append(")");
258-
259267
return b.toString();
260268
}
261269

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*-
2+
* #%L
3+
* JSQLParser library
4+
* %%
5+
* Copyright (C) 2004 - 2022 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 java.util.List;
13+
import net.sf.jsqlparser.expression.operators.relational.ExpressionList;
14+
import net.sf.jsqlparser.statement.select.OrderByElement;
15+
16+
public class WindowDefinition {
17+
18+
final OrderByClause orderBy = new OrderByClause();
19+
final PartitionByClause partitionBy = new PartitionByClause();
20+
WindowElement windowElement = null;
21+
private String windowName;
22+
23+
public WindowElement getWindowElement() {
24+
return windowElement;
25+
}
26+
27+
public void setWindowElement(WindowElement windowElement) {
28+
this.windowElement = windowElement;
29+
}
30+
31+
public List<OrderByElement> getOrderByElements() {
32+
return orderBy.getOrderByElements();
33+
}
34+
35+
public void setOrderByElements(List<OrderByElement> orderByElements) {
36+
orderBy.setOrderByElements(orderByElements);
37+
}
38+
39+
public ExpressionList getPartitionExpressionList() {
40+
return partitionBy.getPartitionExpressionList();
41+
}
42+
43+
public void setPartitionExpressionList(ExpressionList partitionExpressionList) {
44+
setPartitionExpressionList(partitionExpressionList, false);
45+
}
46+
47+
public void setPartitionExpressionList(ExpressionList partitionExpressionList, boolean brackets) {
48+
partitionBy.setPartitionExpressionList(partitionExpressionList, brackets);
49+
}
50+
51+
public String getWindowName() {
52+
return windowName;
53+
}
54+
55+
public void setWindowName(String windowName) {
56+
this.windowName = windowName;
57+
}
58+
59+
public WindowDefinition withWindowName(String windowName) {
60+
setWindowName(windowName);
61+
return this;
62+
}
63+
64+
@Override
65+
public String toString() {
66+
StringBuilder b = new StringBuilder();
67+
if (windowName != null) {
68+
b.append(windowName).append(" AS ");
69+
}
70+
b.append("(");
71+
partitionBy.toStringPartitionBy(b);
72+
orderBy.toStringOrderByElements(b);
73+
74+
if (windowElement != null) {
75+
if (orderBy.getOrderByElements() != null) {
76+
b.append(' ');
77+
}
78+
b.append(windowElement);
79+
}
80+
b.append(")");
81+
return b.toString();
82+
}
83+
}

src/main/java/net/sf/jsqlparser/parser/AbstractJSqlParser.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,21 @@ public P withAllowComplexParsing(boolean allowComplexParsing) {
3232
public P withUnsupportedStatements(boolean allowUnsupportedStatements) {
3333
return withFeature(Feature.allowUnsupportedStatements, allowUnsupportedStatements);
3434
}
35+
36+
public P withTimeOut(int timeOutMillSeconds) {
37+
return withFeature(Feature.timeOut, timeOutMillSeconds);
38+
}
3539

3640
public P withFeature(Feature f, boolean enabled) {
3741
getConfiguration().setValue(f, enabled);
3842
return me();
3943
}
4044

45+
public P withFeature(Feature f, int value) {
46+
getConfiguration().setValue(f, value);
47+
return me();
48+
}
49+
4150
public abstract FeatureConfiguration getConfiguration();
4251

4352
public abstract P me();
@@ -46,6 +55,10 @@ public boolean getAsBoolean(Feature f) {
4655
return getConfiguration().getAsBoolean(f);
4756
}
4857

58+
public Integer getAsInteger(Feature f) {
59+
return getConfiguration().getAsInteger(f);
60+
}
61+
4962
public void setErrorRecovery(boolean errorRecovery) {
5063
this.errorRecovery = errorRecovery;
5164
}

0 commit comments

Comments
 (0)