Skip to content

Commit 8908988

Browse files
committed
Add support for STRAIGHT_JOIN
1 parent 749ad55 commit 8908988

File tree

4 files changed

+31
-4
lines changed

4 files changed

+31
-4
lines changed

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public class Join extends ASTNodeAccessImpl {
2626
private boolean simple = false;
2727
private boolean cross = false;
2828
private boolean semi = false;
29+
private boolean straight = false;
2930
private FromItem rightItem;
3031
private Expression onExpression;
3132
private List<Column> usingColumns;
@@ -47,6 +48,14 @@ public void setInner(boolean b) {
4748
inner = b;
4849
}
4950

51+
public boolean isStraight() {
52+
return straight;
53+
}
54+
55+
public void setStraight(boolean b) {
56+
straight = b;
57+
}
58+
5059
/**
5160
* Whether is a "OUTER" join
5261
*
@@ -210,7 +219,13 @@ public String toString() {
210219
type += "SEMI ";
211220
}
212221

213-
return type + "JOIN " + rightItem + ((joinWindow != null) ? " WITHIN " + joinWindow : "")
222+
if (!isStraight()) {
223+
type += "JOIN ";
224+
} else {
225+
type = "STRAIGHT_JOIN ";
226+
}
227+
228+
return type + rightItem + ((joinWindow != null) ? " WITHIN " + joinWindow : "")
214229
+ ((onExpression != null) ? " ON " + onExpression + "" : "")
215230
+ PlainSelect.getFormatedList(usingColumns, "USING", true, true);
216231
}

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,11 @@ public void deparseJoin(Join join) {
356356
buffer.append(" SEMI");
357357
}
358358

359-
buffer.append(" JOIN ");
359+
if (!join.isStraight()) {
360+
buffer.append(" JOIN ");
361+
} else {
362+
buffer.append(" STRAIGHT_JOIN ");
363+
}
360364

361365
}
362366

src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ TOKEN: /* SQL Keywords. prefixed with K_ to avoid name clashes */
183183
| <K_IN:"IN">
184184
| <K_INDEX: "INDEX">
185185
| <K_INNER:"INNER">
186+
| <K_STRAIGHT:"STRAIGHT_JOIN">
186187
| <K_INSERT:"INSERT">
187188
| <K_INTERSECT:"INTERSECT">
188189
| <K_INTERVAL:"INTERVAL">
@@ -1711,10 +1712,11 @@ Join JoinerExpression() #JoinerExpression:
17111712
) [ <K_OUTER> { join.setOuter(true); } ]
17121713
| <K_INNER> { join.setInner(true); }
17131714
| <K_NATURAL> { join.setNatural(true); }
1714-
| <K_CROSS> { join.setCross(true); }
1715+
| <K_CROSS> { join.setCross(true); }
17151716
]
17161717

1717-
( <K_JOIN> | "," { join.setSimple(true); } (<K_OUTER> { join.setOuter(true); } )? )
1718+
( <K_JOIN> | "," { join.setSimple(true); } (<K_OUTER> { join.setOuter(true); } )?
1719+
| <K_STRAIGHT> { join.setStraight(true); } )
17181720

17191721
right=FromItem()
17201722

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1613,6 +1613,12 @@ public void testCastTypeProblem2() throws JSQLParserException {
16131613
assertSqlCanBeParsedAndDeparsed(stmt);
16141614
}
16151615

1616+
@Test
1617+
public void testStraightJoin() throws JSQLParserException {
1618+
String stmt = "SELECT col FROM tbl STRAIGHT_JOIN tbl2 ON tbl.id = tbl2.id";
1619+
assertSqlCanBeParsedAndDeparsed(stmt);
1620+
}
1621+
16161622
@Test
16171623
public void testCastTypeProblem3() throws JSQLParserException {
16181624
String stmt = "SELECT col1::varchar (256) FROM tabelle1";

0 commit comments

Comments
 (0)