Skip to content

Commit ced0d00

Browse files
feat: Clickhouse GLOBAL IN ...
- sourced from https://github.com/herbert2008/JSqlParser/tree/clickhouse_global_in - resolves PR #1794
2 parents da13d7d + a9ed798 commit ced0d00

File tree

4 files changed

+32
-32
lines changed

4 files changed

+32
-32
lines changed

src/main/java/net/sf/jsqlparser/expression/operators/relational/InExpression.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public class InExpression extends ASTNodeAccessImpl
1717
implements Expression, SupportsOldOracleJoinSyntax {
1818

1919
private Expression leftExpression;
20+
private boolean global = false;
2021
private boolean not = false;
2122
private Expression rightExpression;
2223
private int oldOracleJoinSyntax = NO_ORACLE_JOIN;
@@ -56,6 +57,15 @@ public final void setLeftExpression(Expression expression) {
5657
leftExpression = expression;
5758
}
5859

60+
public boolean isGlobal() {
61+
return global;
62+
}
63+
64+
public InExpression setGlobal(boolean b) {
65+
global = b;
66+
return this;
67+
}
68+
5969
public boolean isNot() {
6070
return not;
6171
}
@@ -87,6 +97,9 @@ public String toString() {
8797
statementBuilder.append(getLeftExpressionString());
8898

8999
statementBuilder.append(" ");
100+
if (global) {
101+
statementBuilder.append("GLOBAL ");
102+
}
90103
if (not) {
91104
statementBuilder.append("NOT ");
92105
}
@@ -124,6 +137,11 @@ public InExpression withOraclePriorPosition(int priorPosition) {
124137
return this;
125138
}
126139

140+
public InExpression withGlobal(boolean global) {
141+
this.setGlobal(global);
142+
return this;
143+
}
144+
127145
public InExpression withNot(boolean not) {
128146
this.setNot(not);
129147
return this;

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,9 @@ public void visit(InExpression inExpression) {
247247
.getOldOracleJoinSyntax() == SupportsOldOracleJoinSyntax.ORACLE_JOIN_RIGHT) {
248248
buffer.append("(+)");
249249
}
250+
if (inExpression.isGlobal()) {
251+
buffer.append(" GLOBAL");
252+
}
250253
if (inExpression.isNot()) {
251254
buffer.append(" NOT");
252255
}

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3464,15 +3464,18 @@ Expression InExpression() #InExpression :
34643464
{
34653465
Token token;
34663466
int oldOracleJoin = 0;
3467-
boolean usesNot = false;
3467+
boolean usingNot = false;
3468+
boolean usingGlobal = false;
34683469
Expression leftExpression;
34693470
Expression rightExpression;
34703471
}
34713472
{
34723473
leftExpression=SimpleExpression()
34733474
[ "(" "+" ")" { oldOracleJoin=EqualsTo.ORACLE_JOIN_RIGHT; } ]
34743475

3475-
[<K_NOT> { usesNot=true; } ] <K_IN>
3476+
[<K_GLOBAL> { usingGlobal=true; } ]
3477+
[<K_NOT> { usingNot=true; } ]
3478+
<K_IN>
34763479
(
34773480
LOOKAHEAD(2) token=<S_CHAR_LITERAL> { rightExpression = new StringValue(token.image); }
34783481
| LOOKAHEAD(3) rightExpression = Function()
@@ -3483,7 +3486,8 @@ Expression InExpression() #InExpression :
34833486
{
34843487
InExpression inExpression = new InExpression(leftExpression, rightExpression)
34853488
.withOldOracleJoinSyntax(oldOracleJoin)
3486-
.withNot(usesNot);
3489+
.withNot(usingNot)
3490+
.setGlobal(usingGlobal);
34873491
linkAST(inExpression,jjtThis);
34883492
return inExpression;
34893493
}

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

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
package net.sf.jsqlparser.statement.select;
1111

1212
import net.sf.jsqlparser.JSQLParserException;
13-
import org.junit.jupiter.api.Assertions;
1413
import org.junit.jupiter.api.Test;
1514

1615
import static net.sf.jsqlparser.test.TestUtils.assertSqlCanBeParsedAndDeparsed;
@@ -37,33 +36,9 @@ public void testFunctionWithAttributesIssue1742() throws JSQLParserException {
3736
}
3837

3938
@Test
40-
public void testSelectUsingFinal() throws JSQLParserException {
41-
String sqlStr = "SELECT column FROM table_name AS tn FINAL";
42-
assertSqlCanBeParsedAndDeparsed(sqlStr, true);
43-
44-
// check that FINAL is reserved keyword and won't be read as an Alias
45-
sqlStr = "SELECT column FROM table_name FINAL";
46-
PlainSelect select = (PlainSelect) assertSqlCanBeParsedAndDeparsed(sqlStr, true);
47-
48-
Assertions.assertTrue(select.isUsingFinal());
49-
Assertions.assertFalse(select.withUsingFinal(false).toString().contains("FINAL"));
50-
}
51-
52-
@Test
53-
public void testLimitBy() throws JSQLParserException {
54-
String sqlStr = "SELECT * FROM limit_by ORDER BY id, val LIMIT 1, 2 BY id";
55-
assertSqlCanBeParsedAndDeparsed(sqlStr, true);
56-
57-
sqlStr = "SELECT\n"
58-
+ " domainWithoutWWW(URL) AS domain,\n"
59-
+ " domainWithoutWWW(REFERRER_URL) AS referrer,\n"
60-
+ " device_type,\n"
61-
+ " count() cnt\n"
62-
+ "FROM hits\n"
63-
+ "GROUP BY domain, referrer, device_type\n"
64-
+ "ORDER BY cnt DESC\n"
65-
+ "LIMIT 5 BY domain, device_type\n"
66-
+ "LIMIT 100";
67-
assertSqlCanBeParsedAndDeparsed(sqlStr, true);
39+
public void testGlobalIn() throws JSQLParserException {
40+
String sql =
41+
"SELECT lo_linenumber,lo_orderkey from lo_linenumber where lo_linenumber global in (1,2,3)";
42+
assertSqlCanBeParsedAndDeparsed(sql, true);
6843
}
6944
}

0 commit comments

Comments
 (0)