Skip to content

Commit 44b292a

Browse files
committed
Introduce an isNull() method in the ExpressionGenerator class
1 parent c8cab2f commit 44b292a

8 files changed

Lines changed: 47 additions & 0 deletions

File tree

src/sqlancer/clickhouse/gen/ClickHouseExpressionGenerator.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import sqlancer.clickhouse.ast.ClickHouseExpression;
1919
import sqlancer.clickhouse.ast.ClickHouseUnaryPostfixOperation;
2020
import sqlancer.clickhouse.ast.ClickHouseUnaryPrefixOperation;
21+
import sqlancer.clickhouse.ast.ClickHouseUnaryPostfixOperation.ClickHouseUnaryPostfixOperator;
2122
import sqlancer.clickhouse.ast.ClickHouseUnaryPrefixOperation.ClickHouseUnaryPrefixOperator;
2223
import sqlancer.gen.TypedExpressionGenerator;
2324

@@ -175,4 +176,9 @@ public ClickHouseExpression generatePredicate() {
175176
public ClickHouseExpression negatePredicate(ClickHouseExpression predicate) {
176177
return new ClickHouseUnaryPrefixOperation(predicate, ClickHouseUnaryPrefixOperator.NOT);
177178
}
179+
180+
@Override
181+
public ClickHouseExpression isNull(ClickHouseExpression expr) {
182+
return new ClickHouseUnaryPostfixOperation(expr, ClickHouseUnaryPostfixOperator.IS_NULL, false);
183+
}
178184
}

src/sqlancer/cockroachdb/gen/CockroachDBExpressionGenerator.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,4 +353,9 @@ public CockroachDBExpression negatePredicate(CockroachDBExpression predicate) {
353353
return new CockroachDBNotOperation(predicate);
354354
}
355355

356+
@Override
357+
public CockroachDBExpression isNull(CockroachDBExpression expr) {
358+
return new CockroachDBUnaryPostfixOperation(expr, CockroachDBUnaryPostfixOperator.IS_NULL);
359+
}
360+
356361
}

src/sqlancer/duckdb/gen/DuckDBExpressionGenerator.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,4 +438,9 @@ public Node<DuckDBExpression> negatePredicate(Node<DuckDBExpression> predicate)
438438
return new NewUnaryPrefixOperatorNode<>(predicate, DuckDBUnaryPrefixOperator.NOT);
439439
}
440440

441+
@Override
442+
public Node<DuckDBExpression> isNull(Node<DuckDBExpression> expr) {
443+
return new NewUnaryPostfixOperatorNode<>(expr, DuckDBUnaryPostfixOperator.IS_NULL);
444+
}
445+
441446
}

src/sqlancer/gen/ExpressionGenerator.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,14 @@ public interface ExpressionGenerator<E> {
1919
*/
2020
E negatePredicate(E predicate);
2121

22+
/**
23+
* Checks if an expression evaluates to NULL (i.e., implements the IS NULL operator).
24+
*
25+
* @param expr
26+
* the expression
27+
*
28+
* @return an expression that checks whether the expression evaluates to NULL.
29+
*/
30+
E isNull(E expr);
31+
2232
}

src/sqlancer/mysql/gen/MySQLExpressionGenerator.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,4 +193,9 @@ public MySQLExpression negatePredicate(MySQLExpression predicate) {
193193
return new MySQLUnaryPrefixOperation(predicate, MySQLUnaryPrefixOperator.NOT);
194194
}
195195

196+
@Override
197+
public MySQLExpression isNull(MySQLExpression expr) {
198+
return new MySQLUnaryPostfixOperation(expr, MySQLUnaryPostfixOperation.UnaryPostfixOperator.IS_NULL, false);
199+
}
200+
196201
}

src/sqlancer/postgres/gen/PostgresExpressionGenerator.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,4 +585,9 @@ public PostgresExpression negatePredicate(PostgresExpression predicate) {
585585
return new PostgresPrefixOperation(predicate, PostgresPrefixOperation.PrefixOperator.NOT);
586586
}
587587

588+
@Override
589+
public PostgresExpression isNull(PostgresExpression expr) {
590+
return new PostgresPostfixOperation(expr, PostfixOperator.IS_NULL);
591+
}
592+
588593
}

src/sqlancer/sqlite3/gen/SQLite3ExpressionGenerator.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import sqlancer.sqlite3.ast.SQLite3Expression.SQLite3OrderingTerm;
3030
import sqlancer.sqlite3.ast.SQLite3Expression.SQLite3OrderingTerm.Ordering;
3131
import sqlancer.sqlite3.ast.SQLite3Expression.SQLite3PostfixText;
32+
import sqlancer.sqlite3.ast.SQLite3Expression.SQLite3PostfixUnaryOperation;
3233
import sqlancer.sqlite3.ast.SQLite3Expression.SQLite3PostfixUnaryOperation.PostfixUnaryOperator;
3334
import sqlancer.sqlite3.ast.SQLite3Expression.Sqlite3BinaryOperation;
3435
import sqlancer.sqlite3.ast.SQLite3Expression.Sqlite3BinaryOperation.BinaryOperator;
@@ -651,4 +652,9 @@ public SQLite3Expression negatePredicate(SQLite3Expression predicate) {
651652
return new SQLite3UnaryOperation(UnaryOperator.NOT, predicate);
652653
}
653654

655+
@Override
656+
public SQLite3Expression isNull(SQLite3Expression expr) {
657+
return new SQLite3PostfixUnaryOperation(PostfixUnaryOperator.ISNULL, expr);
658+
}
659+
654660
}

src/sqlancer/tidb/TiDBExpressionGenerator.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,4 +175,9 @@ public TiDBExpression negatePredicate(TiDBExpression predicate) {
175175
return new TiDBUnaryPrefixOperation(predicate, TiDBUnaryPrefixOperator.NOT);
176176
}
177177

178+
@Override
179+
public TiDBExpression isNull(TiDBExpression expr) {
180+
return new TiDBUnaryPostfixOperation(expr, TiDBUnaryPostfixOperator.IS_NULL);
181+
}
182+
178183
}

0 commit comments

Comments
 (0)