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
50 changes: 50 additions & 0 deletions src/main/java/net/sf/jsqlparser/statement/select/Join.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public class Join extends ASTNodeAccessImpl {
private boolean simple = false;
private boolean cross = false;
private boolean semi = false;
private boolean any = false;
private boolean all = false;
private boolean straight = false;
private boolean apply = false;
private boolean fetch = false;
Expand Down Expand Up @@ -186,6 +188,48 @@ public Join withSemi(boolean b) {
return this;
}

/**
* Whether is an "ANY" join
*
* @return true if is an "ANY" join
*/
public boolean isAny() {
return any;
}

public void setAny(boolean b) {
if (b) {
all = false;
}
any = b;
}

public Join withAny(boolean b) {
this.setAny(b);
return this;
}

/**
* Whether is an "ALL" join
*
* @return true if is an "ALL" join
*/
public boolean isAll() {
return all;
}

public void setAll(boolean b) {
if (b) {
any = false;
}
all = b;
}

public Join withAll(boolean b) {
this.setAll(b);
return this;
}

/**
* Whether is a "LEFT" join
*
Expand Down Expand Up @@ -421,6 +465,12 @@ public String toString() {
builder.append("NATURAL ");
}

if (isAny()) {
builder.append("ANY ");
} else if (isAll()) {
builder.append("ALL ");
}

if (isRight()) {
builder.append("RIGHT ");
} else if (isFull()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,12 @@ public void deparseJoin(Join join) {
builder.append(" NATURAL");
}

if (join.isAny()) {
builder.append(" ANY");
} else if (join.isAll()) {
builder.append(" ALL");
}

if (join.isRight()) {
builder.append(" RIGHT");
} else if (join.isFull()) {
Expand Down
5 changes: 3 additions & 2 deletions src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt
Original file line number Diff line number Diff line change
Expand Up @@ -4964,17 +4964,18 @@ Join JoinerExpression() #JoinerExpression:
}
{
[ <K_GLOBAL> { join.setGlobal(true); } ]
[ <K_ANY> { join.setAny(true); } | <K_ALL> { join.setAll(true); } ]
[ <K_NATURAL> { join.setNatural(true); } ]

[
(
<K_LEFT> { join.setLeft(true); } [ <K_SEMI> { join.setSemi(true); } | <K_OUTER> { join.setOuter(true); } ]
<K_LEFT> { join.setLeft(true); } [ <K_SEMI> { join.setSemi(true); } | <K_OUTER> { join.setOuter(true); } | <K_ANY> { join.setAny(true); } | <K_ALL> { join.setAll(true); } ]
|
(
<K_RIGHT> { join.setRight(true); }
|
<K_FULL> { join.setFull(true); }
) [ <K_OUTER> { join.setOuter(true); } ]
) [ <K_OUTER> { join.setOuter(true); } | <K_ANY> { join.setAny(true); } | <K_ALL> { join.setAll(true); } ]
|
<K_INNER> { join.setInner(true); }
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,46 @@ public void testGlobalJoin() throws JSQLParserException {
assertSqlCanBeParsedAndDeparsed(sql, true);
}

@Test
public void testGlobalAnyLeftJoin() throws JSQLParserException {
String sql = "SELECT * FROM events e GLOBAL ANY LEFT JOIN users u ON e.user_id = u.id";
PlainSelect select = (PlainSelect) assertSqlCanBeParsedAndDeparsed(sql, true);
Join join = select.getJoins().get(0);
Assertions.assertTrue(join.isGlobal());
Assertions.assertTrue(join.isAny());
Assertions.assertTrue(join.isLeft());
}

@Test
public void testGlobalAllRightJoin() throws JSQLParserException {
String sql = "SELECT * FROM events e GLOBAL ALL RIGHT JOIN users u ON e.user_id = u.id";
PlainSelect select = (PlainSelect) assertSqlCanBeParsedAndDeparsed(sql, true);
Join join = select.getJoins().get(0);
Assertions.assertTrue(join.isGlobal());
Assertions.assertTrue(join.isAll());
Assertions.assertTrue(join.isRight());
}

@Test
public void testLeftAnyJoinOrderVariant() throws JSQLParserException {
String sql = "SELECT * FROM events e LEFT ANY JOIN users u ON e.user_id = u.id";
Select statement = (Select) CCJSqlParserUtil.parse(sql);
PlainSelect select = (PlainSelect) statement.getSelectBody();
Join join = select.getJoins().get(0);
Assertions.assertTrue(join.isAny());
Assertions.assertTrue(join.isLeft());
}

@Test
public void testRightAllJoinOrderVariant() throws JSQLParserException {
String sql = "SELECT * FROM events e RIGHT ALL JOIN users u ON e.user_id = u.id";
Select statement = (Select) CCJSqlParserUtil.parse(sql);
PlainSelect select = (PlainSelect) statement.getSelectBody();
Join join = select.getJoins().get(0);
Assertions.assertTrue(join.isAll());
Assertions.assertTrue(join.isRight());
}

@Test
public void testFunctionWithAttributesIssue1742() throws JSQLParserException {
String sql = "SELECT f1(arguments).f2.f3 from dual";
Expand Down