Skip to content

Commit 7364ff3

Browse files
Merge remote-tracking branch 'origin/piped_sql'
# Conflicts: # README.md
2 parents 0544a82 + 4a8d1f2 commit 7364ff3

File tree

95 files changed

+2693
-940
lines changed

Some content is hidden

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

95 files changed

+2693
-940
lines changed

README.md

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# [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"/>
22

3-
4-
[![Gradle CI](https://github.com/JSQLParser/JSqlParser/actions/workflows/ci.yml/badge.svg)](https://github.com/JSQLParser/JSqlParser/actions/workflows/ci.yml)
5-
[![Coverage Status](https://coveralls.io/repos/JSQLParser/JSqlParser/badge.svg?branch=master)](https://coveralls.io/r/JSQLParser/JSqlParser?branch=master)
3+
[![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)
4+
[![Gradle CI](https://github.com/JSQLParser/JSqlParser/actions/workflows/gradle.yml/badge.svg)](https://github.com/JSQLParser/JSqlParser/actions/workflows/gradle.yml)
5+
[![Coverage Status](https://coveralls.io/repos/JSQLParser/JSqlParser/badge.svg?branch=master)](https://coveralls.io/r/JSQLParser/JSqlParser?branch=master)
66
[![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)
77
[![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)
88
[![Gitter](https://badges.gitter.im/JSQLParser/JSqlParser.svg)](https://gitter.im/JSQLParser/JSqlParser?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
@@ -49,6 +49,22 @@ Column b = (Column) equalsTo.getRightExpression();
4949
Assertions.assertEquals("a", a.getColumnName());
5050
Assertions.assertEquals("b", b.getColumnName());
5151
```
52+
## Support for `Piped SQL`
53+
54+
Work is progressing for parsing `Piped SQL`, a much saner and more logical way to write queries in its semantic order.
55+
```sql
56+
FROM Produce
57+
|> WHERE
58+
item != 'bananas'
59+
AND category IN ('fruit', 'nut')
60+
|> AGGREGATE COUNT(*) AS num_items, SUM(sales) AS total_sales
61+
GROUP BY item
62+
|> ORDER BY item DESC;
63+
```
64+
65+
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
66+
67+
## Java Version
5268

5369
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.
5470

@@ -75,7 +91,7 @@ If you like JSqlParser then please check out its related projects:
7591
## Alternatives to JSqlParser?
7692
[**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.
7793

78-
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.
94+
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.
7995

8096
## [Documentation](https://jsqlparser.github.io/JSqlParser)
8197
1. [Samples](https://jsqlparser.github.io/JSqlParser/usage.html#parse-a-sql-statements)

src/main/java/module-info.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
exports net.sf.jsqlparser.statement.grant;
3939
exports net.sf.jsqlparser.statement.insert;
4040
exports net.sf.jsqlparser.statement.merge;
41+
exports net.sf.jsqlparser.statement.piped;
4142
exports net.sf.jsqlparser.statement.refresh;
4243
exports net.sf.jsqlparser.statement.select;
4344
exports net.sf.jsqlparser.statement.show;

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,4 @@ default <T> void accept(ExpressionVisitor<T> expressionVisitor) {
2020
this.accept(expressionVisitor, null);
2121
}
2222

23-
;
24-
25-
2623
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
import net.sf.jsqlparser.expression.operators.relational.TSQLLeftJoin;
5858
import net.sf.jsqlparser.expression.operators.relational.TSQLRightJoin;
5959
import net.sf.jsqlparser.schema.Column;
60+
import net.sf.jsqlparser.statement.piped.FromQuery;
6061
import net.sf.jsqlparser.statement.select.AllColumns;
6162
import net.sf.jsqlparser.statement.select.AllTableColumns;
6263
import net.sf.jsqlparser.statement.select.ParenthesedSelect;
@@ -687,4 +688,6 @@ default void visit(Inverse inverse) {
687688
}
688689

689690
<S> T visit(CosineSimilarity cosineSimilarity, S context);
691+
692+
<S> T visit(FromQuery fromQuery, S context);
690693
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
import net.sf.jsqlparser.expression.operators.relational.TSQLLeftJoin;
5858
import net.sf.jsqlparser.expression.operators.relational.TSQLRightJoin;
5959
import net.sf.jsqlparser.schema.Column;
60+
import net.sf.jsqlparser.statement.piped.FromQuery;
6061
import net.sf.jsqlparser.statement.select.AllColumns;
6162
import net.sf.jsqlparser.statement.select.AllTableColumns;
6263
import net.sf.jsqlparser.statement.select.OrderByElement;
@@ -819,4 +820,9 @@ public <S> T visit(CosineSimilarity cosineSimilarity, S context) {
819820
return null;
820821
}
821822

823+
@Override
824+
public <S> T visit(FromQuery fromQuery, S context) {
825+
return null;
826+
}
827+
822828
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,9 @@ public <T extends ASTNodeAccess> T getParent(Class<T> clazz) {
6565

6666
return clazz.cast(parent.jjtGetValue());
6767
}
68+
69+
@Override
70+
public String toString() {
71+
return appendTo(new StringBuilder()).toString();
72+
}
6873
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ public class ParserKeywordsUtils {
6868
{"EXCEPT", RESTRICTED_SQL2016},
6969
{"EXCLUDES", RESTRICTED_JSQLPARSER},
7070
{"EXISTS", RESTRICTED_SQL2016},
71+
{"EXTEND", RESTRICTED_JSQLPARSER},
7172
{"FALSE", RESTRICTED_SQL2016},
7273
{"FETCH", RESTRICTED_SQL2016},
7374
{"FINAL", RESTRICTED_JSQLPARSER},

src/main/java/net/sf/jsqlparser/statement/StatementVisitor.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,5 +323,4 @@ default void visit(ParenthesedUpdate parenthesedUpdate) {
323323
default void visit(ParenthesedDelete parenthesedDelete) {
324324
this.visit(parenthesedDelete, null);
325325
}
326-
327326
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package net.sf.jsqlparser.statement.piped;
2+
3+
import net.sf.jsqlparser.statement.select.SelectItem;
4+
5+
import java.util.ArrayList;
6+
7+
public class AggregatePipeOperator extends PipeOperator {
8+
private final ArrayList<SelectItem<?>> selectItems = new ArrayList<>();
9+
private final ArrayList<SelectItem<?>> groupItems = new ArrayList<>();
10+
private boolean usingShortHandOrdering = false;
11+
12+
public AggregatePipeOperator(SelectItem<?> selectItem) {
13+
selectItems.add(selectItem);
14+
}
15+
16+
public ArrayList<SelectItem<?>> getSelectItems() {
17+
return selectItems;
18+
}
19+
20+
public ArrayList<SelectItem<?>> getGroupItems() {
21+
return groupItems;
22+
}
23+
24+
public AggregatePipeOperator add(SelectItem<?> selectItem) {
25+
selectItems.add(selectItem);
26+
return this;
27+
}
28+
29+
public AggregatePipeOperator with(SelectItem<?> selectItem) {
30+
return this.add(selectItem);
31+
}
32+
33+
public AggregatePipeOperator addGroupItem(SelectItem<?> selectItem) {
34+
groupItems.add(selectItem);
35+
return this;
36+
}
37+
38+
public AggregatePipeOperator withGroupItem(SelectItem<?> selectItem) {
39+
return this.addGroupItem(selectItem);
40+
}
41+
42+
public boolean isUsingShortHandOrdering() {
43+
return usingShortHandOrdering;
44+
}
45+
46+
public AggregatePipeOperator setShorthandOrdering(boolean usingShortHandOrdering) {
47+
this.usingShortHandOrdering = usingShortHandOrdering;
48+
return this;
49+
}
50+
51+
@Override
52+
public <T, S> T accept(PipeOperatorVisitor<T> visitor, S context) {
53+
return visitor.visit(this, context);
54+
}
55+
56+
@Override
57+
public StringBuilder appendTo(StringBuilder builder) {
58+
builder.append("|> ").append("AGGREGATE");
59+
int i = 0;
60+
for (SelectItem<?> selectItem : selectItems) {
61+
builder.append(i++ > 0 ? ", " : " ").append(selectItem);
62+
}
63+
builder.append("\n");
64+
65+
if (!groupItems.isEmpty()) {
66+
builder.append("\t").append("GROUP");
67+
if (isUsingShortHandOrdering()) {
68+
builder.append(" AND ORDER");
69+
}
70+
builder.append(" BY");
71+
i = 0;
72+
for (SelectItem<?> selectItem : groupItems) {
73+
builder.append(i++ > 0 ? ", " : " ").append(selectItem);
74+
}
75+
builder.append("\n");
76+
}
77+
78+
return builder;
79+
}
80+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package net.sf.jsqlparser.statement.piped;
2+
3+
import net.sf.jsqlparser.expression.Alias;
4+
5+
public class AsPipeOperator extends PipeOperator {
6+
private Alias alias;
7+
8+
public AsPipeOperator(Alias alias) {
9+
this.alias = alias;
10+
}
11+
12+
public Alias getAlias() {
13+
return alias;
14+
}
15+
16+
public AsPipeOperator setAlias(Alias alias) {
17+
this.alias = alias;
18+
return this;
19+
}
20+
21+
@Override
22+
public <T, S> T accept(PipeOperatorVisitor<T> visitor, S context) {
23+
return visitor.visit(this, context);
24+
}
25+
26+
@Override
27+
public StringBuilder appendTo(StringBuilder builder) {
28+
builder.append("|> ").append(alias);
29+
builder.append("\n");
30+
return builder;
31+
}
32+
}

0 commit comments

Comments
 (0)