Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 23 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# [JSqlParser 5.1 Website](https://jsqlparser.github.io/JSqlParser) <img src="src/site/sphinx/_images/logo-no-background.svg" alt="drawing" width="200" align="right"/>


[![Gradle CI](https://github.com/JSQLParser/JSqlParser/actions/workflows/ci.yml/badge.svg)](https://github.com/JSQLParser/JSqlParser/actions/workflows/ci.yml)
[![Coverage Status](https://coveralls.io/repos/JSQLParser/JSqlParser/badge.svg?branch=master)](https://coveralls.io/r/JSQLParser/JSqlParser?branch=master)
[![Maven deploy snapshot](https://github.com/JSQLParser/JSqlParser/actions/workflows/maven_deploy.yml/badge.svg)](https://github.com/JSQLParser/JSqlParser/actions/workflows/maven_deploy.yml)
[![Gradle CI](https://github.com/JSQLParser/JSqlParser/actions/workflows/gradle.yml/badge.svg)](https://github.com/JSQLParser/JSqlParser/actions/workflows/gradle.yml)
[![Coverage Status](https://coveralls.io/repos/JSQLParser/JSqlParser/badge.svg?branch=master)](https://coveralls.io/r/JSQLParser/JSqlParser?branch=master)
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/6f9a2d7eb98f45969749e101322634a1)](https://www.codacy.com/gh/JSQLParser/JSqlParser/dashboard?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=JSQLParser/JSqlParser&amp;utm_campaign=Badge_Grade)
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.github.jsqlparser/jsqlparser/badge.svg)](http://maven-badges.herokuapp.com/maven-central/com.github.jsqlparser/jsqlparser) [![Javadocs](https://www.javadoc.io/badge/com.github.jsqlparser/jsqlparser.svg)](https://www.javadoc.io/doc/com.github.jsqlparser/jsqlparser)
[![Gitter](https://badges.gitter.im/JSQLParser/JSqlParser.svg)](https://gitter.im/JSQLParser/JSqlParser?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
Expand All @@ -26,7 +26,7 @@ SQL Text
└─where: expression.operators.relational.EqualsTo
├─Column: a
└─Column: b
*/
*/
```

```java
Expand All @@ -49,8 +49,24 @@ Column b = (Column) equalsTo.getRightExpression();
Assertions.assertEquals("a", a.getColumnName());
Assertions.assertEquals("b", b.getColumnName());
```
## Support for `Piped SQL`

Work is progressing for parsing `Piped SQL`, a much saner and more logical way to write queries in its semantic order.
```sql
FROM Produce
|> WHERE
item != 'bananas'
AND category IN ('fruit', 'nut')
|> AGGREGATE COUNT(*) AS num_items, SUM(sales) AS total_sales
GROUP BY item
|> ORDER BY item DESC;
```

For details, please see https://storage.googleapis.com/gweb-research2023-media/pubtools/1004848.pdf, https://cloud.google.com/bigquery/docs/reference/standard-sql/pipe-syntax and https://duckdb.org/docs/sql/query_syntax/from.html#from-first-syntax

## Java Version

JSQLParser-4.9 was the last JDK8 compatible version. The recent JSQLParser-5.0 depends on JDK11 and introduces API breaking changes to the AST Visitors. Please see the Migration Guide for the details.
JSQLParser-4.9 was the last JDK8 compatible version. JSQLParser-5.0 and later depend on JDK11 and introduce API breaking changes to the AST Visitors. Please see the Migration Guide for the details.

## [Supported Grammar and Syntax](https://jsqlparser.github.io/JSqlParser/syntax.html)

Expand All @@ -60,7 +76,7 @@ JSQLParser-4.9 was the last JDK8 compatible version. The recent JSQLParser-5.0 d
|-----------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------|
| Oracle<br>MS SQL Server and Sybase<br>Postgres<br>MySQL and MariaDB<br>DB2<br>H2 and HSQLDB and Derby<br>SQLite | `SELECT`<br>`INSERT`, `UPDATE`, `UPSERT`, `MERGE`<br>`DELETE`, `TRUNCATE TABLE`<br>`CREATE ...`, `ALTER ....`, `DROP ...`<br>`WITH ...` |
| Salesforce SOQL | `INCLUDES`, `EXCLUDES` |
| Piped SQL (also know as FROM SQL) | |
| Piped SQL (also known as FROM SQL) | |

**JSqlParser** can also be used to create SQL Statements from Java Code with a fluent API (see [Samples](https://jsqlparser.github.io/JSqlParser/usage.html#build-a-sql-statements)).

Expand All @@ -75,7 +91,7 @@ If you like JSqlParser then please check out its related projects:
## Alternatives to JSqlParser?
[**General SQL Parser**](http://www.sqlparser.com/features/introduce.php?utm_source=github-jsqlparser&utm_medium=text-general) looks pretty good, with extended SQL syntax (like PL/SQL and T-SQL) and java + .NET APIs. The tool is commercial (license available online), with a free download option.

Alternatively the dual-licensed [JOOQ](https://www.jooq.org/doc/latest/manual/sql-building/sql-parser/) provides a hand-written Parser supporting a lot of RDBMS, translation between dialects, SQL transformation, can be used as a JDBC proxy for translation and transformation purposes.
Alternatively the dual-licensed [JOOQ](https://www.jooq.org/doc/latest/manual/sql-building/sql-parser/) provides a handwritten Parser supporting a lot of RDBMS, translation between dialects, SQL transformation, can be used as a JDBC proxy for translation and transformation purposes.

## [Documentation](https://jsqlparser.github.io/JSqlParser)
1. [Samples](https://jsqlparser.github.io/JSqlParser/usage.html#parse-a-sql-statements)
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
module net.sf.jsqlparser {
requires java.sql;
requires java.logging;
requires java.desktop;

exports net.sf.jsqlparser;
exports net.sf.jsqlparser.expression;
Expand Down Expand Up @@ -38,6 +39,7 @@
exports net.sf.jsqlparser.statement.grant;
exports net.sf.jsqlparser.statement.insert;
exports net.sf.jsqlparser.statement.merge;
exports net.sf.jsqlparser.statement.piped;
exports net.sf.jsqlparser.statement.refresh;
exports net.sf.jsqlparser.statement.select;
exports net.sf.jsqlparser.statement.show;
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/net/sf/jsqlparser/expression/Expression.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,4 @@ default <T> void accept(ExpressionVisitor<T> expressionVisitor) {
this.accept(expressionVisitor, null);
}

;


}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import net.sf.jsqlparser.expression.operators.relational.TSQLLeftJoin;
import net.sf.jsqlparser.expression.operators.relational.TSQLRightJoin;
import net.sf.jsqlparser.schema.Column;
import net.sf.jsqlparser.statement.piped.FromQuery;
import net.sf.jsqlparser.statement.select.AllColumns;
import net.sf.jsqlparser.statement.select.AllTableColumns;
import net.sf.jsqlparser.statement.select.ParenthesedSelect;
Expand Down Expand Up @@ -687,4 +688,6 @@ default void visit(Inverse inverse) {
}

<S> T visit(CosineSimilarity cosineSimilarity, S context);

<S> T visit(FromQuery fromQuery, S context);
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import net.sf.jsqlparser.expression.operators.relational.TSQLLeftJoin;
import net.sf.jsqlparser.expression.operators.relational.TSQLRightJoin;
import net.sf.jsqlparser.schema.Column;
import net.sf.jsqlparser.statement.piped.FromQuery;
import net.sf.jsqlparser.statement.select.AllColumns;
import net.sf.jsqlparser.statement.select.AllTableColumns;
import net.sf.jsqlparser.statement.select.OrderByElement;
Expand Down Expand Up @@ -819,4 +820,9 @@ public <S> T visit(CosineSimilarity cosineSimilarity, S context) {
return null;
}

@Override
public <S> T visit(FromQuery fromQuery, S context) {
return null;
}

}
5 changes: 5 additions & 0 deletions src/main/java/net/sf/jsqlparser/parser/ASTNodeAccessImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,9 @@ public <T extends ASTNodeAccess> T getParent(Class<T> clazz) {

return clazz.cast(parent.jjtGetValue());
}

@Override
public String toString() {
return appendTo(new StringBuilder()).toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public class ParserKeywordsUtils {
{"EXCEPT", RESTRICTED_SQL2016},
{"EXCLUDES", RESTRICTED_JSQLPARSER},
{"EXISTS", RESTRICTED_SQL2016},
{"EXTEND", RESTRICTED_JSQLPARSER},
{"FALSE", RESTRICTED_SQL2016},
{"FETCH", RESTRICTED_SQL2016},
{"FINAL", RESTRICTED_JSQLPARSER},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,5 +323,4 @@ default void visit(ParenthesedUpdate parenthesedUpdate) {
default void visit(ParenthesedDelete parenthesedDelete) {
this.visit(parenthesedDelete, null);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package net.sf.jsqlparser.statement.piped;

import net.sf.jsqlparser.statement.select.SelectItem;

import java.util.ArrayList;

public class AggregatePipeOperator extends PipeOperator {
private final ArrayList<SelectItem<?>> selectItems = new ArrayList<>();
private final ArrayList<SelectItem<?>> groupItems = new ArrayList<>();
private boolean usingShortHandOrdering = false;

public AggregatePipeOperator(SelectItem<?> selectItem) {
selectItems.add(selectItem);
}

public ArrayList<SelectItem<?>> getSelectItems() {
return selectItems;
}

public ArrayList<SelectItem<?>> getGroupItems() {
return groupItems;
}

public AggregatePipeOperator add(SelectItem<?> selectItem) {
selectItems.add(selectItem);
return this;
}

public AggregatePipeOperator with(SelectItem<?> selectItem) {
return this.add(selectItem);
}

public AggregatePipeOperator addGroupItem(SelectItem<?> selectItem) {
groupItems.add(selectItem);
return this;
}

public AggregatePipeOperator withGroupItem(SelectItem<?> selectItem) {
return this.addGroupItem(selectItem);
}

public boolean isUsingShortHandOrdering() {
return usingShortHandOrdering;
}

public AggregatePipeOperator setShorthandOrdering(boolean usingShortHandOrdering) {
this.usingShortHandOrdering = usingShortHandOrdering;
return this;
}

@Override
public <T, S> T accept(PipeOperatorVisitor<T> visitor, S context) {
return visitor.visit(this, context);
}

@Override
public StringBuilder appendTo(StringBuilder builder) {
builder.append("|> ").append("AGGREGATE");
int i = 0;
for (SelectItem<?> selectItem : selectItems) {
builder.append(i++ > 0 ? ", " : " ").append(selectItem);
}
builder.append("\n");

if (!groupItems.isEmpty()) {
builder.append("\t").append("GROUP");
if (isUsingShortHandOrdering()) {
builder.append(" AND ORDER");
}
builder.append(" BY");
i = 0;
for (SelectItem<?> selectItem : groupItems) {
builder.append(i++ > 0 ? ", " : " ").append(selectItem);
}
builder.append("\n");
}

return builder;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package net.sf.jsqlparser.statement.piped;

import net.sf.jsqlparser.expression.Alias;

public class AsPipeOperator extends PipeOperator {
private Alias alias;

public AsPipeOperator(Alias alias) {
this.alias = alias;
}

public Alias getAlias() {
return alias;
}

public AsPipeOperator setAlias(Alias alias) {
this.alias = alias;
return this;
}

@Override
public <T, S> T accept(PipeOperatorVisitor<T> visitor, S context) {
return visitor.visit(this, context);
}

@Override
public StringBuilder appendTo(StringBuilder builder) {
builder.append("|> ").append(alias);
builder.append("\n");
return builder;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package net.sf.jsqlparser.statement.piped;

public class CallPipeOperator extends PipeOperator {

@Override
public <T, S> T accept(PipeOperatorVisitor<T> visitor, S context) {
return visitor.visit(this, context);
}
}
Loading
Loading