Skip to content
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

feat:support clickhouse global keyword in IN Expression #1794

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class InExpression extends ASTNodeAccessImpl implements Expression, Suppo

private Expression leftExpression;
private ItemsList rightItemsList;
private boolean global = false;
private boolean not = false;
private Expression rightExpression;
private int oldOracleJoinSyntax = NO_ORACLE_JOIN;
Expand Down Expand Up @@ -69,6 +70,13 @@ public final void setLeftExpression(Expression expression) {
leftExpression = expression;
}

public boolean isGlobal() {
return global;
}

public void setGlobal(boolean b) {
global = b;
}
public boolean isNot() {
return not;
}
Expand Down Expand Up @@ -100,6 +108,9 @@ public String toString() {
statementBuilder.append(getLeftExpressionString());

statementBuilder.append(" ");
if (global) {
statementBuilder.append("GLOBAL ");
}
if (not) {
statementBuilder.append("NOT ");
}
Expand Down Expand Up @@ -141,6 +152,11 @@ public InExpression withOraclePriorPosition(int priorPosition) {
return this;
}

public InExpression withGlobal(boolean global) {
this.setGlobal(global);
return this;
}

public InExpression withNot(boolean not) {
this.setNot(not);
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,9 @@ public void visit(InExpression inExpression) {
.getOldOracleJoinSyntax() == SupportsOldOracleJoinSyntax.ORACLE_JOIN_RIGHT) {
buffer.append("(+)");
}
if (inExpression.isGlobal()) {
buffer.append(" GLOBAL");
}
if (inExpression.isNot()) {
buffer.append(" NOT");
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt
Original file line number Diff line number Diff line change
Expand Up @@ -3314,7 +3314,7 @@ Expression InExpression() #InExpression :
leftExpression=SimpleExpression() { result.setLeftExpression(leftExpression); }
[ "(" "+" ")" { result.setOldOracleJoinSyntax(EqualsTo.ORACLE_JOIN_RIGHT); } ]

[<K_NOT> { result.setNot(true); } ] <K_IN>
[<K_GLOBAL> { result.setGlobal(true); } ][<K_NOT> { result.setNot(true); } ] <K_IN>
(
LOOKAHEAD(2) token=<S_CHAR_LITERAL> { result.setRightExpression(new StringValue(token.image)); }
| LOOKAHEAD(3) rightExpression = Function() { result.setRightExpression(rightExpression); }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,11 @@ public void testFunctionWithAttributesIssue1742() throws JSQLParserException {
sql = "SELECT schemaName.f1(arguments).f2(arguments).f3.f4 from dual";
assertSqlCanBeParsedAndDeparsed(sql, true);
}

@Test
public void testGlobalIn() throws JSQLParserException {
String sql =
"SELECT lo_linenumber,lo_orderkey from lo_linenumber where lo_linenumber global in (1,2,3)";
assertSqlCanBeParsedAndDeparsed(sql, true);
}
}