Skip to content

Commit a97ccb2

Browse files
committed
Generic Postgres classes
1 parent d57676a commit a97ccb2

5 files changed

Lines changed: 20 additions & 14 deletions

File tree

src/sqlancer/Main.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
import sqlancer.duckdb.DuckDBProvider;
3333
import sqlancer.mariadb.MariaDBProvider;
3434
import sqlancer.mysql.MySQLProvider;
35+
import sqlancer.postgres.PostgresGlobalState;
36+
import sqlancer.postgres.PostgresOptions;
37+
import sqlancer.postgres.PostgresSchema;
3538
import sqlancer.postgres.PostgresProvider;
3639
import sqlancer.sqlite3.SQLite3Provider;
3740
import sqlancer.tidb.TiDBProvider;
@@ -535,14 +538,15 @@ private boolean run(MainOptions options, ExecutorService execService,
535538
return threadsShutdown == 0 ? 0 : options.getErrorExitCode();
536539
}
537540

541+
@SuppressWarnings("unchecked")
538542
static List<DatabaseProvider<?, ?>> getDBMSProviders() {
539543
List<DatabaseProvider<?, ?>> providers = new ArrayList<>();
540544
providers.add(new SQLite3Provider());
541545
providers.add(new CockroachDBProvider());
542546
providers.add(new MySQLProvider());
543547
providers.add(new MariaDBProvider());
544548
providers.add(new TiDBProvider());
545-
providers.add(new PostgresProvider());
549+
providers.add(new PostgresProvider<PostgresGlobalState<PostgresOptions, PostgresSchema>, PostgresOptions>((Class<PostgresGlobalState<PostgresOptions, PostgresSchema>>)(Object)PostgresGlobalState.class, PostgresOptions.class));
546550
providers.add(new ClickHouseProvider());
547551
providers.add(new DuckDBProvider());
548552
providers.add(new CitusProvider());

src/sqlancer/citus/CitusGlobalState.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import sqlancer.postgres.PostgresGlobalState;
66

7-
public class CitusGlobalState extends PostgresGlobalState {
7+
public class CitusGlobalState extends PostgresGlobalState<CitusOptions, CitusSchema> {
88

99
private boolean repartition;
1010

@@ -16,6 +16,7 @@ public boolean getRepartition() {
1616
return repartition;
1717
}
1818

19+
// TODO: What if this doesn't exist - why can't the function in PostgresGlobalState call S.fromConnection()?
1920
@Override
2021
protected void updateSchema() throws SQLException {
2122
// FIXME: Will casting lose CitusSchema information?

src/sqlancer/citus/CitusProvider.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,17 @@
2323
import sqlancer.postgres.PostgresSchema.PostgresDataType;
2424
import sqlancer.postgres.PostgresSchema.PostgresTable;
2525

26-
public class CitusProvider extends PostgresProvider {
26+
public class CitusProvider extends PostgresProvider<CitusGlobalState, CitusOptions> {
2727
// FIXME:
28-
protected final Set<String> errors = new HashSet<>();
28+
private static final Set<String> errors = new HashSet<>();
2929

3030
public CitusProvider() {
3131
// how to change the extension of the super class?
32-
super();
32+
super(CitusGlobalState.class, CitusOptions.class);
3333
CitusCommon.addCitusErrors(errors);
3434
}
3535

36-
private class WorkerNode{
36+
/* private class WorkerNode{
3737
3838
private final String host;
3939
private final int port;
@@ -155,10 +155,10 @@ public void generateDatabase(CitusGlobalState globalState) throws SQLException {
155155
// allow repartition joins
156156
globalState.executeStatement(new QueryAdapter("SET citus.enable_repartition_joins to ON;\n", errors));
157157
}
158-
}
158+
} */
159159

160160
//FIXME: pass in Postgres or CitusGlobalState?
161-
@Override
161+
/* @Override
162162
public Connection createDatabase(PostgresGlobalState globalState) throws SQLException {
163163
// returns connection to coordinator node, test database
164164
Connection con = super.createDatabase(globalState);
@@ -247,7 +247,7 @@ public Connection createDatabase(PostgresGlobalState globalState) throws SQLExce
247247
con = DriverManager.getConnection(testURL, username, password);
248248
return con;
249249
}
250-
250+
*/
251251
@Override
252252
public String getDBMSName() {
253253
return "citus";

src/sqlancer/postgres/PostgresGlobalState.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import sqlancer.GlobalState;
1111
import sqlancer.Randomly;
1212

13-
public class PostgresGlobalState extends GlobalState<PostgresOptions, PostgresSchema> {
13+
public class PostgresGlobalState<O extends PostgresOptions, S extends PostgresSchema> extends GlobalState<O, S> {
1414

1515
private List<String> operators;
1616
private List<String> collates;
@@ -91,7 +91,7 @@ public String getRandomOpclass() {
9191

9292
@Override
9393
protected void updateSchema() throws SQLException {
94-
setSchema(PostgresSchema.fromConnection(getConnection(), getDatabaseName()));
94+
setSchema((S) S.fromConnection(getConnection(), getDatabaseName()));
9595
}
9696

9797
}

src/sqlancer/postgres/PostgresProvider.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import sqlancer.AbstractAction;
1616
import sqlancer.CompositeTestOracle;
17+
import sqlancer.GlobalState;
1718
import sqlancer.IgnoreMeException;
1819
import sqlancer.ProviderAdapter;
1920
import sqlancer.Query;
@@ -52,14 +53,14 @@
5253

5354
// EXISTS
5455
// IN
55-
public class PostgresProvider extends ProviderAdapter<PostgresGlobalState, PostgresOptions> {
56+
public class PostgresProvider<G extends PostgresGlobalState<O, ?>, O extends PostgresOptions> extends ProviderAdapter<G, O> {
5657

5758
public static boolean generateOnlyKnown;
5859

5960
private PostgresGlobalState globalState;
6061

61-
public PostgresProvider() {
62-
super(PostgresGlobalState.class, PostgresOptions.class);
62+
public PostgresProvider(Class<G> globalClass, Class<O> optionsClass) {
63+
super(globalClass, optionsClass);
6364
}
6465

6566
public enum Action implements AbstractAction<PostgresGlobalState> {

0 commit comments

Comments
 (0)