Skip to content

support clickhouse global keyword in join #1615

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
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
13 changes: 13 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 @@ -21,6 +21,7 @@ public class Join extends ASTNodeAccessImpl {
private boolean right = false;
private boolean left = false;
private boolean natural = false;
private boolean global = false;
private boolean full = false;
private boolean inner = false;
private boolean simple = false;
Expand Down Expand Up @@ -166,6 +167,10 @@ public boolean isNatural() {
return natural;
}

public boolean isGlobal() {
return global;
}

public Join withNatural(boolean b) {
this.setNatural(b);
return this;
Expand All @@ -175,6 +180,10 @@ public void setNatural(boolean b) {
natural = b;
}

public void setGlobal(boolean b) {
global = b;
}

/**
* Whether is a "FULL" join
*
Expand Down Expand Up @@ -299,6 +308,10 @@ public void setJoinWindow(KSQLJoinWindow joinWindow) {
public String toString() {
StringBuilder builder = new StringBuilder();

if(isGlobal()){
builder.append("GLOBAL ");
}

if (isSimple() && isOuter()) {
builder.append("OUTER ").append(rightItem);
} else if (isSimple()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,10 @@ public void visit(SubJoin subjoin) {

@SuppressWarnings({"PMD.CyclomaticComplexity"})
public void deparseJoin(Join join) {
if(join.isGlobal()){
buffer.append(" GLOBAL ");
}

if (join.isSimple() && join.isOuter()) {
buffer.append(", OUTER ");
} else if (join.isSimple()) {
Expand Down
1 change: 1 addition & 0 deletions src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt
Original file line number Diff line number Diff line change
Expand Up @@ -2719,6 +2719,7 @@ Join JoinerExpression() #JoinerExpression:

}
{
[ <K_GLOBAL> { join.setGlobal(true); } ]
[ <K_NATURAL> { join.setNatural(true); } ]

[
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2019 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.statement.select;

import org.junit.jupiter.api.Test;

import static net.sf.jsqlparser.test.TestUtils.assertSqlCanBeParsedAndDeparsed;

public class ClickHouseTest {

@Test
public void testGlobalJoin() throws Exception {
String sql = "SELECT a.*,b.* from lineorder_all as a global left join supplier_all as b on a.LOLINENUMBER=b.SSUPPKEY";
assertSqlCanBeParsedAndDeparsed(sql, true);
}
}