-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Support unknown keyword (#2141)
- Loading branch information
Showing
13 changed files
with
200 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
src/main/java/net/sf/jsqlparser/expression/operators/relational/IsUnknownExpression.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/*- | ||
* #%L | ||
* JSQLParser library | ||
* %% | ||
* Copyright (C) 2004 - 2025 JSQLParser | ||
* %% | ||
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0 | ||
* #L% | ||
*/ | ||
package net.sf.jsqlparser.expression.operators.relational; | ||
|
||
import net.sf.jsqlparser.expression.Expression; | ||
import net.sf.jsqlparser.expression.ExpressionVisitor; | ||
import net.sf.jsqlparser.parser.ASTNodeAccessImpl; | ||
|
||
public class IsUnknownExpression extends ASTNodeAccessImpl implements Expression { | ||
|
||
private Expression leftExpression; | ||
private boolean isNot = false; | ||
|
||
public Expression getLeftExpression() { | ||
return leftExpression; | ||
} | ||
|
||
public void setLeftExpression(Expression expression) { | ||
leftExpression = expression; | ||
} | ||
|
||
public boolean isNot() { | ||
return isNot; | ||
} | ||
|
||
public void setNot(boolean isNot) { | ||
this.isNot = isNot; | ||
} | ||
|
||
@Override | ||
public <T, S> T accept(ExpressionVisitor<T> expressionVisitor, S context) { | ||
return expressionVisitor.visit(this, context); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return leftExpression + " IS" + (isNot ? " NOT" : "") + " UNKNOWN"; | ||
} | ||
|
||
public IsUnknownExpression withLeftExpression(Expression leftExpression) { | ||
this.setLeftExpression(leftExpression); | ||
return this; | ||
} | ||
|
||
public IsUnknownExpression withNot(boolean isNot) { | ||
this.setNot(isNot); | ||
return this; | ||
} | ||
|
||
public <E extends Expression> E getLeftExpression(Class<E> type) { | ||
return type.cast(getLeftExpression()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/test/java/net/sf/jsqlparser/expression/operators/relational/IsUnknownExpressionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/*- | ||
* #%L | ||
* JSQLParser library | ||
* %% | ||
* Copyright (C) 2004 - 2023 JSQLParser | ||
* %% | ||
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0 | ||
* #L% | ||
*/ | ||
package net.sf.jsqlparser.expression.operators.relational; | ||
|
||
import net.sf.jsqlparser.schema.Column; | ||
import net.sf.jsqlparser.test.TestUtils; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.ValueSource; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; | ||
|
||
class IsUnknownExpressionTest { | ||
|
||
@ParameterizedTest | ||
@ValueSource(strings = { | ||
"SELECT * FROM mytable WHERE 1 IS UNKNOWN", | ||
"SELECT * FROM mytable WHERE 1 IS NOT UNKNOWN", | ||
}) | ||
public void testIsUnknownExpression(String sqlStr) { | ||
assertDoesNotThrow(() -> TestUtils.assertSqlCanBeParsedAndDeparsed(sqlStr)); | ||
} | ||
|
||
@Test | ||
void testStringConstructor() { | ||
Column column = new Column("x"); | ||
|
||
IsUnknownExpression defaultIsUnknownExpression = | ||
new IsUnknownExpression().withLeftExpression(column); | ||
TestUtils.assertExpressionCanBeDeparsedAs(defaultIsUnknownExpression, "x IS UNKNOWN"); | ||
|
||
IsUnknownExpression isUnknownExpression = | ||
new IsUnknownExpression().withLeftExpression(column).withNot(false); | ||
TestUtils.assertExpressionCanBeDeparsedAs(isUnknownExpression, "x IS UNKNOWN"); | ||
|
||
IsUnknownExpression isNotUnknownExpression = | ||
new IsUnknownExpression().withLeftExpression(column).withNot(true); | ||
TestUtils.assertExpressionCanBeDeparsedAs(isNotUnknownExpression, "x IS NOT UNKNOWN"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters