Skip to content

Commit 3b991e4

Browse files
authored
Merge pull request #774 from tomershay/support_straight_join_hint
Add support for STRAIGHT_JOIN
2 parents 0c46591 + 8908988 commit 3b991e4

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
@@ -354,7 +354,11 @@ public void deparseJoin(Join join) {
354354
buffer.append(" SEMI");
355355
}
356356

357-
buffer.append(" JOIN ");
357+
if (!join.isStraight()) {
358+
buffer.append(" JOIN ");
359+
} else {
360+
buffer.append(" STRAIGHT_JOIN ");
361+
}
358362

359363
}
360364

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ TOKEN: /* SQL Keywords. prefixed with K_ to avoid name clashes */
189189
| <K_IN:"IN">
190190
| <K_INDEX: "INDEX">
191191
| <K_INNER:"INNER">
192+
| <K_STRAIGHT:"STRAIGHT_JOIN">
192193
| <K_INSERT:"INSERT">
193194
| <K_INTERSECT:"INTERSECT">
194195
| <K_INTERVAL:"INTERVAL">
@@ -1740,10 +1741,11 @@ Join JoinerExpression() #JoinerExpression:
17401741
) [ <K_OUTER> { join.setOuter(true); } ]
17411742
| <K_INNER> { join.setInner(true); }
17421743
| <K_NATURAL> { join.setNatural(true); }
1743-
| <K_CROSS> { join.setCross(true); }
1744+
| <K_CROSS> { join.setCross(true); }
17441745
]
17451746

1746-
( <K_JOIN> | "," { join.setSimple(true); } (<K_OUTER> { join.setOuter(true); } )? )
1747+
( <K_JOIN> | "," { join.setSimple(true); } (<K_OUTER> { join.setOuter(true); } )?
1748+
| <K_STRAIGHT> { join.setStraight(true); } )
17471749

17481750
right=FromItem()
17491751

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1618,6 +1618,12 @@ public void testCastTypeProblem2() throws JSQLParserException {
16181618
assertSqlCanBeParsedAndDeparsed(stmt);
16191619
}
16201620

1621+
@Test
1622+
public void testStraightJoin() throws JSQLParserException {
1623+
String stmt = "SELECT col FROM tbl STRAIGHT_JOIN tbl2 ON tbl.id = tbl2.id";
1624+
assertSqlCanBeParsedAndDeparsed(stmt);
1625+
}
1626+
16211627
@Test
16221628
public void testCastTypeProblem3() throws JSQLParserException {
16231629
String stmt = "SELECT col1::varchar (256) FROM tabelle1";

0 commit comments

Comments
 (0)