Skip to content

Commit 777a08b

Browse files
committed
added cross join syntax support
1 parent e551a16 commit 777a08b

File tree

5 files changed

+30
-1
lines changed

5 files changed

+30
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Original project websites:
99

1010
## Extensions Version 0.8.3
1111

12+
* Added support for cross join
1213
* Allowed complex expressions in extract from
1314
* Corrected cast expression to make type parameters usable (e.g. cast(col1 as varchar(255))
1415
* Added support for column comma list in partition by statements

src/main/java/net/sf/jsqlparser/statement/select/Join.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public class Join {
3838
private boolean full = false;
3939
private boolean inner = false;
4040
private boolean simple = false;
41+
private boolean cross = false;
4142
private FromItem rightItem;
4243
private Expression onExpression;
4344
private List<Column> usingColumns;
@@ -133,6 +134,14 @@ public void setFull(boolean b) {
133134
full = b;
134135
}
135136

137+
public boolean isCross() {
138+
return cross;
139+
}
140+
141+
public void setCross(boolean cross) {
142+
this.cross = cross;
143+
}
144+
136145
/**
137146
* Returns the right item of the join
138147
*/
@@ -182,6 +191,8 @@ public String toString() {
182191
type += "FULL ";
183192
} else if (isLeft()) {
184193
type += "LEFT ";
194+
} else if (isCross()) {
195+
type += "CROSS ";
185196
}
186197

187198
if (isOuter()) {

src/main/java/net/sf/jsqlparser/util/deparser/SelectDeParser.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,8 @@ public void deparseJoin(Join join) {
264264
buffer.append(" FULL");
265265
} else if (join.isLeft()) {
266266
buffer.append(" LEFT");
267+
} else if (join.isCross()) {
268+
buffer.append(" CROSS");
267269
}
268270

269271
if (join.isOuter()) {

src/main/javacc/net/sf/jsqlparser/parser/JSqlParserCC.jj

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ TOKEN: /* SQL Keywords. prefixed with K_ to avoid name clashes */
189189
| <K_DROP:"DROP">
190190
| <K_JOIN:"JOIN">
191191
| <K_LEFT:"LEFT">
192+
| <K_CROSS:"CROSS">
192193
| <K_FROM:"FROM">
193194
| <K_OPEN:"OPEN">
194195
| <K_CASE:"CASE">
@@ -855,12 +856,21 @@ Join JoinerExpression():
855856
List<Column> columns = null;
856857
}
857858
{
858-
859+
/*
860+
Refactor to be more restrictive.
861+
left [outer] join
862+
right [outer] join
863+
full [outer] join
864+
[inner] join
865+
cross join
866+
natural join
867+
*/
859868
[ (
860869
<K_LEFT> { join.setLeft(true); }
861870
| <K_RIGHT> { join.setRight(true); }
862871
| <K_FULL> { join.setFull(true); }
863872
| <K_NATURAL> { join.setNatural(true); }
873+
| <K_CROSS> { join.setCross(true); }
864874
)
865875
]
866876

src/test/java/net/sf/jsqlparser/test/select/SelectTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -799,6 +799,11 @@ public void testMultiTableJoin() throws JSQLParserException {
799799
String stmt = "SELECT * FROM taba INNER JOIN tabb ON taba.a = tabb.a, tabc LEFT JOIN tabd ON tabc.c = tabd.c";
800800
assertSqlCanBeParsedAndDeparsed(stmt);
801801
}
802+
803+
public void testTableCrossJoin() throws JSQLParserException {
804+
String stmt = "SELECT * FROM taba CROSS JOIN tabb";
805+
assertSqlCanBeParsedAndDeparsed(stmt);
806+
}
802807

803808
public void testLateral1() throws JSQLParserException {
804809
String stmt = "SELECT O.ORDERID, O.CUSTNAME, OL.LINETOTAL FROM ORDERS AS O, LATERAL(SELECT SUM(NETAMT) AS LINETOTAL FROM ORDERLINES AS LINES WHERE LINES.ORDERID = O.ORDERID) AS OL";

0 commit comments

Comments
 (0)