Skip to content

Commit 89ebbf5

Browse files
committed
Remove window function generation from generateIntExpression
1 parent 063f1c7 commit 89ebbf5

1 file changed

Lines changed: 8 additions & 12 deletions

File tree

src/sqlancer/postgres/gen/PostgresExpressionGenerator.java

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import sqlancer.common.gen.ExpressionGenerator;
1616
import sqlancer.common.gen.NoRECGenerator;
1717
import sqlancer.common.gen.TLPWhereGenerator;
18-
import sqlancer.common.schema.AbstractTables;
1918
import sqlancer.postgres.PostgresBugs;
2019
import sqlancer.postgres.PostgresCompoundDataType;
2120
import sqlancer.postgres.PostgresGlobalState;
@@ -231,8 +230,7 @@ private PostgresExpression generateBooleanExpression(int depth) {
231230
}
232231

233232
private PostgresDataType getMeaningfulType() {
234-
// make it more likely that the expression does not only consist of constant
235-
// expressions
233+
// make it more likely that the expression does not only consist of constant expressions
236234
if (Randomly.getBooleanWithSmallProbability() || columns == null || columns.isEmpty()) {
237235
return PostgresDataType.getRandomType();
238236
} else {
@@ -425,7 +423,7 @@ private PostgresExpression generateTextExpression(int depth) {
425423
}
426424
}
427425

428-
private PostgresExpression generateWindowFunction(int depth, PostgresDataType returnType) {
426+
public PostgresExpression generateWindowFunction(int depth, PostgresDataType returnType) {
429427
List<PostgresExpression> arguments = generateWindowFunctionArguments(depth);
430428
List<PostgresExpression> partitionBy = generatePartitionByExpressions(depth);
431429
List<PostgresOrderByTerm> orderBy = generateOrderByExpressions(depth);
@@ -508,8 +506,9 @@ private PostgresExpression generateBitExpression(int depth) {
508506
}
509507
}
510508

509+
// Removed WINDOW_FUNCTION option from the integer expression generation.
511510
private enum IntExpression {
512-
UNARY_OPERATION, FUNCTION, CAST, BINARY_ARITHMETIC_EXPRESSION, WINDOW_FUNCTION
511+
UNARY_OPERATION, FUNCTION, CAST, BINARY_ARITHMETIC_EXPRESSION
513512
}
514513

515514
private PostgresExpression generateIntExpression(int depth) {
@@ -527,8 +526,6 @@ private PostgresExpression generateIntExpression(int depth) {
527526
case BINARY_ARITHMETIC_EXPRESSION:
528527
return new PostgresBinaryArithmeticOperation(generateExpression(depth + 1, PostgresDataType.INT),
529528
generateExpression(depth + 1, PostgresDataType.INT), PostgresBinaryOperator.getRandom());
530-
case WINDOW_FUNCTION:
531-
return generateWindowFunction(depth + 1, PostgresDataType.INT);
532529
default:
533530
throw new AssertionError();
534531
}
@@ -718,7 +715,8 @@ public PostgresExpression isNull(PostgresExpression expr) {
718715
}
719716

720717
@Override
721-
public PostgresExpressionGenerator setTablesAndColumns(AbstractTables<PostgresTable, PostgresColumn> targetTables) {
718+
public PostgresExpressionGenerator setTablesAndColumns(
719+
sqlancer.common.schema.AbstractTables<PostgresTable, PostgresColumn> targetTables) {
722720
this.targetTables = targetTables.getTables();
723721
this.columns = targetTables.getColumns();
724722
return this;
@@ -806,7 +804,7 @@ public String generateOptimizedQueryString(PostgresSelect select, PostgresExpres
806804
select.setFetchColumns(Arrays.asList(allColumns));
807805
}
808806
select.setWhereClause(whereCondition);
809-
if (Randomly.getBooleanWithSmallProbability()) {
807+
if (Randomly.getBooleanWithRatherLowProbability()) {
810808
select.setOrderByClauses(generateOrderBys());
811809
}
812810
select.setSelectType(SelectType.ALL);
@@ -839,7 +837,7 @@ public boolean mutate(PostgresSelect select) {
839837
mutators.add(this::mutateWhere);
840838
mutators.add(this::mutateGroupBy);
841839
mutators.add(this::mutateHaving);
842-
mutators.add(this::mutateWindowFunction); // Add window function mutation
840+
mutators.add(this::mutateWindowFunction);
843841
if (!PostgresBugs.bug18643) {
844842
mutators.add(this::mutateAnd);
845843
mutators.add(this::mutateOr);
@@ -852,13 +850,11 @@ public boolean mutate(PostgresSelect select) {
852850
private boolean mutateWindowFunction(PostgresSelect select) {
853851
List<PostgresExpression> windowFunctions = select.getWindowFunctions();
854852
if (windowFunctions == null || windowFunctions.isEmpty()) {
855-
// Add a new window function
856853
windowFunctions = new ArrayList<>();
857854
windowFunctions.add(generateWindowFunction(0, PostgresDataType.INT));
858855
select.setWindowFunctions(windowFunctions);
859856
return false;
860857
} else {
861-
// Remove a random window function
862858
windowFunctions.remove(Randomly.fromList(windowFunctions));
863859
if (windowFunctions.isEmpty()) {
864860
select.setWindowFunctions(null);

0 commit comments

Comments
 (0)