Skip to content

Commit a9abf27

Browse files
committed
[SQLite] Add a PQS option to test aggregate functions
1 parent 0254bf1 commit a9abf27

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

src/sqlancer/MainOptions.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ public class MainOptions {
6565
@Parameter(names = "--print-succeeding-statements", description = "Print statements that are successfully processed by the DBMS to stdout (not yet implemented for all oracles)", arity = 1)
6666
private boolean printSucceedingStatements; // NOPMD
6767

68+
@Parameter(names = "--pqs-test-aggregates", description = "Partially test aggregate functions when all tables contain only a single row.")
69+
private boolean testAggregateFunctions; // NOPMD
70+
6871
public int getMaxExpressionDepth() {
6972
return maxExpressionDepth;
7073
}
@@ -146,4 +149,8 @@ public long getRandomSeed() {
146149
return randomSeed;
147150
}
148151

152+
public boolean testAggregateFunctionsPQS() {
153+
return testAggregateFunctions;
154+
}
155+
149156
}

src/sqlancer/sqlite3/oracle/SQLite3PivotedQuerySynthesisOracle.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ public SQLite3Select getQuery() throws SQLException {
9797
allTables.addAll(tables);
9898
allTables.addAll(joinStatements.stream().map(join -> join.getTable()).collect(Collectors.toList()));
9999
boolean allTablesContainOneRow = allTables.stream().allMatch(t -> t.getNrRows() == 1);
100-
pivotRowExpression = getColExpressions(allTablesContainOneRow, columns, columnsWithoutRowid);
100+
boolean testAggregateFunctions = allTablesContainOneRow && globalState.getOptions().testAggregateFunctionsPQS();
101+
pivotRowExpression = getColExpressions(testAggregateFunctions, columns, columnsWithoutRowid);
101102
selectStatement.setFetchColumns(pivotRowExpression);
102103
localState.log("queryTargetedColumnsString: "
103104
+ fetchColumns.stream().map(c -> c.getFullQualifiedName()).collect(Collectors.joining(", ")));
@@ -141,13 +142,13 @@ private List<Join> getJoinStatements(SQLite3GlobalState globalState, List<SQLite
141142
return joinStatements;
142143
}
143144

144-
private List<SQLite3Expression> getColExpressions(boolean allTablesContainOneRow, List<SQLite3Column> columns,
145+
private List<SQLite3Expression> getColExpressions(boolean testAggregateFunctions, List<SQLite3Column> columns,
145146
List<SQLite3Column> columnsWithoutRowid) {
146147
List<SQLite3Expression> colExpressions = new ArrayList<>();
147148

148149
for (SQLite3Column c : fetchColumns) {
149150
SQLite3Expression colName = new SQLite3ColumnName(c, pivotRow.getValues().get(c));
150-
if (allTablesContainOneRow && Randomly.getBoolean()) {
151+
if (testAggregateFunctions && Randomly.getBoolean()) {
151152

152153
/*
153154
* PQS cannot detect omitted or incorrectly-fetched duplicate rows, so we can generate DISTINCT
@@ -174,7 +175,7 @@ private List<SQLite3Expression> getColExpressions(boolean allTablesContainOneRow
174175
colExpressions.add(colName);
175176
}
176177
}
177-
if (allTablesContainOneRow) {
178+
if (testAggregateFunctions) {
178179
SQLite3WindowFunction windowFunction = SQLite3WindowFunction.getRandom(columnsWithoutRowid, globalState);
179180
SQLite3Expression windowExpr = generateWindowFunction(columnsWithoutRowid, windowFunction, false);
180181
colExpressions.add(windowExpr);

0 commit comments

Comments
 (0)