Skip to content

Commit

Permalink
Merge github.com:JSQLParser/JSqlParser
Browse files Browse the repository at this point in the history
  • Loading branch information
manticore-projects committed Aug 3, 2022
2 parents 6b07f70 + fb6e950 commit 39a3476
Show file tree
Hide file tree
Showing 38 changed files with 1,191 additions and 274 deletions.
8 changes: 8 additions & 0 deletions .github/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
changelog:
categories:
- title: Bugs solved
labels:
- "bug"
- title: Changes and new Features
labels:
- "*"
16 changes: 3 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,26 +54,16 @@ To help JSqlParser's development you are encouraged to provide

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

## Extensions in the latest SNAPSHOT version 4.5
## Extensions in the latest SNAPSHOT version 4.6

* support for named windows in window expressions: `SELECT sum(c) OVER winName FROM mytable WINDOW winName AS (PARTITION BY pcol)`

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

## Extensions of JSqlParser releases

* [Release Notes](https://github.com/JSQLParser/JSqlParser/releases)
* Modifications before GitHub's release tagging are listed in the [Older Releases](https://github.com/JSQLParser/JSqlParser/wiki/Older-Releases) page.
* UnsupportedStatement support instead of throwing Exceptions
* support for **RETURNING** clause of a **DELETE** statement
* Add support for `... ALTER COLUMN ... DROP DEFAULT`
* `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
* `(WITH ... SELECT ...)` statements within brackets are now supported
* Postgres `NATURAL { INNER | LEFT | RIGHT } JOIN` support
* extended support for Hive dialect `GROUPING SETS`
* support for Postgresql **drop** function
* support table option **character set** and **index** options
* support Postgresql optional **TABLE** in **TRUNCATE**
* support for `ANALYZE mytable`


## Building from the sources

Expand Down
10 changes: 5 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ dependencies {
testImplementation 'org.mockito:mockito-junit-jupiter:4.+'

// enforce latest version of JavaCC
javacc 'net.java.dev.javacc:javacc:7.0.10'
javacc 'net.java.dev.javacc:javacc:7.0.11'
}

compileJavacc {
Expand Down Expand Up @@ -114,7 +114,7 @@ jacocoTestCoverageVerification {
limit {
counter = 'LINE'
value = 'MISSEDCOUNT'
maximum = 5513
maximum = 5700
}
excludes = [
'net.sf.jsqlparser.util.validation.*',
Expand Down Expand Up @@ -164,15 +164,15 @@ spotbugsMain {

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

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

pmd {
consoleOutput = false
toolVersion = "6.41.0"
toolVersion = "6.46.0"

sourceSets = [sourceSets.main]

Expand All @@ -181,7 +181,7 @@ pmd {

//rulesMinimumPriority = 1

ruleSetFiles = files("ruleset.xml")
ruleSetFiles = files("config/pmd/ruleset.xml")

pmdMain {
excludes = [
Expand Down
File renamed without changes.
13 changes: 11 additions & 2 deletions ruleset.xml → config/pmd/ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,17 @@ under the License.
<rule ref="category/java/design.xml/SimplifiedTernary" />
<rule ref="category/java/design.xml/UselessOverridingMethod" />
<rule ref="category/java/design.xml/AvoidThrowingNullPointerException" />

<!-- for Codazy -->

<!--
<rule ref="category/java/design.xml/NPathComplexity">
<properties>
<property name="reportLevel" value="200" />
</properties>
</rule>
-->


<!-- for Codazy -->
<rule ref="category/java/design.xml/CyclomaticComplexity" />
<rule ref="category/java/design.xml/ExcessiveMethodLength" />
<rule ref="category/java/bestpractices.xml/SwitchStmtsShouldHaveDefault" />
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.github.jsqlparser</groupId>
<artifactId>jsqlparser</artifactId>
<version>4.5-SNAPSHOT</version>
<version>4.6-SNAPSHOT</version>
<name>JSQLParser library</name>
<inceptionYear>2004</inceptionYear>
<organization>
Expand Down Expand Up @@ -114,7 +114,7 @@
<configuration>
<rulesets>
<!-- Custom local file system rule set -->
<ruleset>${project.basedir}/ruleset.xml</ruleset>
<ruleset>${project.basedir}/config/pmd/ruleset.xml</ruleset>
</rulesets>
<excludes>
<exclude>**/*Bean.java</exclude>
Expand Down Expand Up @@ -625,7 +625,7 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<pmdVersion>6.36.0</pmdVersion>
<pmdVersion>6.46.0</pmdVersion>
</properties>

<description>JSqlParser parses an SQL statement and translate it into a hierarchy of Java classes.
Expand Down
66 changes: 37 additions & 29 deletions src/main/java/net/sf/jsqlparser/expression/AnalyticExpression.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,14 @@
import net.sf.jsqlparser.statement.select.OrderByElement;

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

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

public AnalyticExpression() {
}
Expand Down Expand Up @@ -76,11 +74,11 @@ public void accept(ExpressionVisitor expressionVisitor) {
}

public List<OrderByElement> getOrderByElements() {
return orderBy.getOrderByElements();
return windowDef.orderBy.getOrderByElements();
}

public void setOrderByElements(List<OrderByElement> orderByElements) {
orderBy.setOrderByElements(orderByElements);
windowDef.orderBy.setOrderByElements(orderByElements);
}

public KeepExpression getKeep() {
Expand All @@ -92,19 +90,19 @@ public void setKeep(KeepExpression keep) {
}

public ExpressionList getPartitionExpressionList() {
return partitionBy.getPartitionExpressionList();
return windowDef.partitionBy.getPartitionExpressionList();
}

public void setPartitionExpressionList(ExpressionList partitionExpressionList) {
setPartitionExpressionList(partitionExpressionList, false);
}

public void setPartitionExpressionList(ExpressionList partitionExpressionList, boolean brackets) {
partitionBy.setPartitionExpressionList(partitionExpressionList, brackets);
windowDef.partitionBy.setPartitionExpressionList(partitionExpressionList, brackets);
}

public boolean isPartitionByBrackets() {
return partitionBy.isBrackets();
return windowDef.partitionBy.isBrackets();
}

public String getName() {
Expand Down Expand Up @@ -140,11 +138,11 @@ public void setDefaultValue(Expression defaultValue) {
}

public WindowElement getWindowElement() {
return windowElement;
return windowDef.windowElement;
}

public void setWindowElement(WindowElement windowElement) {
this.windowElement = windowElement;
windowDef.windowElement = windowElement;
}

public AnalyticType getType() {
Expand Down Expand Up @@ -187,6 +185,22 @@ public void setIgnoreNullsOutside(boolean ignoreNullsOutside) {
this.ignoreNullsOutside = ignoreNullsOutside;
}

public String getWindowName() {
return windowName;
}

public void setWindowName(String windowName) {
this.windowName = windowName;
}

public WindowDefinition getWindowDefinition() {
return windowDef;
}

public void setWindowDefinition(WindowDefinition windowDef) {
this.windowDef = windowDef;
}

@Override
@SuppressWarnings({"PMD.CyclomaticComplexity", "PMD.NPathComplexity", "PMD.MissingBreakInSwitch"})
public String toString() {
Expand All @@ -210,11 +224,11 @@ public String toString() {
if (isIgnoreNulls()) {
b.append(" IGNORE NULLS");
}
if (funcOrderBy!=null) {
if (funcOrderBy != null) {
b.append(" ORDER BY ");
b.append( funcOrderBy.stream().map(OrderByElement::toString).collect(joining(", ")));
b.append(funcOrderBy.stream().map(OrderByElement::toString).collect(joining(", ")));
}

b.append(") ");
if (keep != null) {
b.append(keep.toString()).append(" ");
Expand All @@ -232,7 +246,7 @@ public String toString() {
if (isIgnoreNullsOutside()) {
b.append("IGNORE NULLS ");
}

switch (type) {
case FILTER_ONLY:
return b.toString();
Expand All @@ -242,20 +256,14 @@ public String toString() {
default:
b.append("OVER");
}
b.append(" (");

partitionBy.toStringPartitionBy(b);
orderBy.toStringOrderByElements(b);

if (windowElement != null) {
if (orderBy.getOrderByElements() != null) {
b.append(' ');
}
b.append(windowElement);
if (windowName != null) {
b.append(" ").append(windowName);
} else {
b.append(" ");
b.append(windowDef.toString());
}

b.append(")");

return b.toString();
}

Expand Down
83 changes: 83 additions & 0 deletions src/main/java/net/sf/jsqlparser/expression/WindowDefinition.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2022 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression;

import java.util.List;
import net.sf.jsqlparser.expression.operators.relational.ExpressionList;
import net.sf.jsqlparser.statement.select.OrderByElement;

public class WindowDefinition {

final OrderByClause orderBy = new OrderByClause();
final PartitionByClause partitionBy = new PartitionByClause();
WindowElement windowElement = null;
private String windowName;

public WindowElement getWindowElement() {
return windowElement;
}

public void setWindowElement(WindowElement windowElement) {
this.windowElement = windowElement;
}

public List<OrderByElement> getOrderByElements() {
return orderBy.getOrderByElements();
}

public void setOrderByElements(List<OrderByElement> orderByElements) {
orderBy.setOrderByElements(orderByElements);
}

public ExpressionList getPartitionExpressionList() {
return partitionBy.getPartitionExpressionList();
}

public void setPartitionExpressionList(ExpressionList partitionExpressionList) {
setPartitionExpressionList(partitionExpressionList, false);
}

public void setPartitionExpressionList(ExpressionList partitionExpressionList, boolean brackets) {
partitionBy.setPartitionExpressionList(partitionExpressionList, brackets);
}

public String getWindowName() {
return windowName;
}

public void setWindowName(String windowName) {
this.windowName = windowName;
}

public WindowDefinition withWindowName(String windowName) {
setWindowName(windowName);
return this;
}

@Override
public String toString() {
StringBuilder b = new StringBuilder();
if (windowName != null) {
b.append(windowName).append(" AS ");
}
b.append("(");
partitionBy.toStringPartitionBy(b);
orderBy.toStringOrderByElements(b);

if (windowElement != null) {
if (orderBy.getOrderByElements() != null) {
b.append(' ');
}
b.append(windowElement);
}
b.append(")");
return b.toString();
}
}

0 comments on commit 39a3476

Please sign in to comment.