Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/sqlancer/timescaledb/TimescaleDBBugs.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package sqlancer.timescaledb;

public final class TimescaleDBBugs {
private TimescaleDBBugs() {

}
}
12 changes: 12 additions & 0 deletions src/sqlancer/timescaledb/TimescaleDBGlobalState.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package sqlancer.timescaledb;

import java.sql.SQLException;

import sqlancer.postgres.PostgresGlobalState;

public class TimescaleDBGlobalState extends PostgresGlobalState {
@Override
public TimescaleDBSchema readSchema() throws SQLException {
return TimescaleDBSchema.fromConnection(getConnection(), getDatabaseName());
}
}
27 changes: 27 additions & 0 deletions src/sqlancer/timescaledb/TimescaleDBOptions.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package sqlancer.timescaledb;

import java.sql.SQLException;
import java.util.Arrays;
import java.util.List;

import com.beust.jcommander.Parameter;

import sqlancer.OracleFactory;
import sqlancer.common.oracle.TestOracle;
import sqlancer.postgres.PostgresGlobalState;
import sqlancer.postgres.PostgresOptions;
import sqlancer.postgres.oracle.PostgresPivotedQuerySynthesisOracle;

public class TimescaleDBOptions extends PostgresOptions {
@Parameter(names = "--timescaledboracle", description = "Specifies which test oracle should be used for TimeScaleDB extension to PostgreSQL")
public List<TimescaleDBOracleFactory> timescaleDBOracle = Arrays.asList(TimescaleDBOracleFactory.PQS);

public enum TimescaleDBOracleFactory implements OracleFactory<PostgresGlobalState> {
PQS {
@Override
public TestOracle<PostgresGlobalState> create(PostgresGlobalState globalState) throws SQLException {
return new PostgresPivotedQuerySynthesisOracle(globalState);
}
},
}
}
30 changes: 30 additions & 0 deletions src/sqlancer/timescaledb/TimescaleDBProvider.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package sqlancer.timescaledb;

import com.google.auto.service.AutoService;

import sqlancer.DatabaseProvider;
import sqlancer.common.query.ExpectedErrors;
import sqlancer.postgres.PostgresGlobalState;
import sqlancer.postgres.PostgresOptions;
import sqlancer.postgres.PostgresProvider;
import sqlancer.timescaledb.gen.TimescaleDBCommon;

@AutoService(DatabaseProvider.class)
public class TimescaleDBProvider extends PostgresProvider {
@SuppressWarnings("unchecked")
public TimescaleDBProvider() {
super((Class<PostgresGlobalState>) (Object) TimescaleDBGlobalState.class,
(Class<PostgresOptions>) (Object) TimescaleDBOptions.class);
}

@Override
public String getDBMSName() {
return "timescaledb";
}

public static ExpectedErrors getTimescaleDBErrors() {
ExpectedErrors errors = new ExpectedErrors();
TimescaleDBCommon.addTimescaleDBErrors(errors);
return errors;
}
}
52 changes: 52 additions & 0 deletions src/sqlancer/timescaledb/TimescaleDBSchema.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package sqlancer.timescaledb;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.SQLIntegrityConstraintViolationException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import sqlancer.SQLConnection;
import sqlancer.postgres.PostgresSchema;

public class TimescaleDBSchema extends PostgresSchema {

public TimescaleDBSchema(List<TimescaleDBTable> databaseTables, String databaseName) {
super(new ArrayList<>(databaseTables), databaseName);
}

public static class TimescaleDBTable extends PostgresTable {
public TimescaleDBTable(String tableName, List<PostgresColumn> columns, List<PostgresIndex> indexes,
TableType tableType, List<PostgresStatisticsObject> statistics, boolean isView, boolean isInsertable) {
super(tableName, columns, indexes, tableType, statistics, isView, isInsertable);
}

public TimescaleDBTable(PostgresTable table) {
super(table.getName(), table.getColumns(), table.getIndexes(), table.getTableType(), table.getStatistics(),
table.isView(), table.isInsertable());
}
}

public static TimescaleDBSchema fromConnection(SQLConnection con, String databaseName) throws SQLException {
PostgresSchema schema = PostgresSchema.fromConnection(con, databaseName);
List<TimescaleDBTable> databaseTables = new ArrayList<>();
try (Statement s = con.createStatement();
ResultSet rs = s.executeQuery("SELECT table_name FROM information_schema.tables")) {
while (rs.next()) {
String tableName = rs.getString("table_name");

PostgresTable t = schema.getDatabaseTable(tableName);
if (t == null) {
continue;
}

TimescaleDBTable table = new TimescaleDBTable(t);
databaseTables.add(table);
}
} catch (SQLIntegrityConstraintViolationException e) {
throw new AssertionError(e);
}
return new TimescaleDBSchema(databaseTables, databaseName);
}
}
13 changes: 13 additions & 0 deletions src/sqlancer/timescaledb/gen/TimescaleDBCommon.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package sqlancer.timescaledb.gen;

import sqlancer.common.query.ExpectedErrors;

public final class TimescaleDBCommon {
private TimescaleDBCommon() {

}

public static void addTimescaleDBErrors(ExpectedErrors errors) {

}
}