sqlancer.duckdb.test.DuckDBQueryPartitioningBase Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sqlancer Show documentation
Show all versions of sqlancer Show documentation
SQLancer finds logic bugs in Database Management Systems through automatic testing
package sqlancer.duckdb.test;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import sqlancer.Randomly;
import sqlancer.common.ast.newast.ColumnReferenceNode;
import sqlancer.common.ast.newast.Node;
import sqlancer.common.ast.newast.TableReferenceNode;
import sqlancer.common.gen.ExpressionGenerator;
import sqlancer.common.oracle.TernaryLogicPartitioningOracleBase;
import sqlancer.common.oracle.TestOracle;
import sqlancer.duckdb.DuckDBErrors;
import sqlancer.duckdb.DuckDBProvider.DuckDBGlobalState;
import sqlancer.duckdb.DuckDBSchema;
import sqlancer.duckdb.DuckDBSchema.DuckDBColumn;
import sqlancer.duckdb.DuckDBSchema.DuckDBTable;
import sqlancer.duckdb.DuckDBSchema.DuckDBTables;
import sqlancer.duckdb.ast.DuckDBExpression;
import sqlancer.duckdb.ast.DuckDBJoin;
import sqlancer.duckdb.ast.DuckDBSelect;
import sqlancer.duckdb.gen.DuckDBExpressionGenerator;
public class DuckDBQueryPartitioningBase
extends TernaryLogicPartitioningOracleBase, DuckDBGlobalState> implements TestOracle {
DuckDBSchema s;
DuckDBTables targetTables;
DuckDBExpressionGenerator gen;
DuckDBSelect select;
public DuckDBQueryPartitioningBase(DuckDBGlobalState state) {
super(state);
DuckDBErrors.addExpressionErrors(errors);
}
@Override
public void check() throws SQLException {
s = state.getSchema();
targetTables = s.getRandomTableNonEmptyTables();
gen = new DuckDBExpressionGenerator(state).setColumns(targetTables.getColumns());
initializeTernaryPredicateVariants();
select = new DuckDBSelect();
select.setFetchColumns(generateFetchColumns());
List tables = targetTables.getTables();
List> tableList = tables.stream()
.map(t -> new TableReferenceNode(t)).collect(Collectors.toList());
List> joins = DuckDBJoin.getJoins(tableList, state);
select.setJoinList(joins.stream().collect(Collectors.toList()));
select.setFromList(tableList.stream().collect(Collectors.toList()));
select.setWhereClause(null);
}
List> generateFetchColumns() {
List> columns = new ArrayList<>();
if (Randomly.getBoolean()) {
columns.add(new ColumnReferenceNode<>(new DuckDBColumn("*", null, false, false)));
} else {
columns = Randomly.nonEmptySubset(targetTables.getColumns()).stream()
.map(c -> new ColumnReferenceNode(c)).collect(Collectors.toList());
}
return columns;
}
@Override
protected ExpressionGenerator> getGen() {
return gen;
}
}