Skip to content

Commit aa125c1

Browse files
committed
add to Citus errors
1 parent 3bddd40 commit aa125c1

4 files changed

Lines changed: 26 additions & 30 deletions

File tree

src/sqlancer/citus/CitusProvider.java

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,9 @@ private static void distributeTable(List<PostgresColumn> columns, String tableNa
209209
if (columns.size() != 0) {
210210
PostgresColumn columnToDistribute = Randomly.fromList(columns);
211211
String template = "SELECT create_distributed_table(?, ?);";
212-
QueryAdapter query = new QueryAdapter(template, errors);
213-
globalState.executeStatement(query, tableName, columnToDistribute.getName());
212+
String filled = "SELECT create_distributed_table('" + tableName + "', '" + columnToDistribute.getName() + "');";
213+
QueryAdapter query = new QueryAdapter(filled, errors);
214+
globalState.executeStatement(query, template, tableName, columnToDistribute.getName());
214215
// distribution column cannot take NULL value
215216
// TODO: find a way to protect from SQL injection without '' around string input
216217
query = new QueryAdapter(
@@ -224,8 +225,9 @@ private static List<String> getTableConstraints(String tableName, CitusGlobalSta
224225
throws SQLException {
225226
List<String> constraints = new ArrayList<>();
226227
String template = "SELECT constraint_type FROM information_schema.table_constraints WHERE table_name = ? AND (constraint_type = 'PRIMARY KEY' OR constraint_type = 'UNIQUE' or constraint_type = 'EXCLUDE');";
227-
QueryAdapter query = new QueryAdapter(template);
228-
ResultSet rs = query.executeAndGet(globalState, tableName);
228+
String filled = "SELECT constraint_type FROM information_schema.table_constraints WHERE table_name = '" + tableName + "' AND (constraint_type = 'PRIMARY KEY' OR constraint_type = 'UNIQUE' or constraint_type = 'EXCLUDE');";
229+
QueryAdapter query = new QueryAdapter(filled);
230+
ResultSet rs = query.executeAndGet(globalState, template, tableName);
229231
while (rs.next()) {
230232
constraints.add(rs.getString("constraint_type"));
231233
}
@@ -238,8 +240,9 @@ private static void createDistributedTable(String tableName, CitusGlobalState gl
238240
List<String> tableConstraints = getTableConstraints(tableName, globalState, con);
239241
if (tableConstraints.size() == 0) {
240242
String template = "SELECT column_name, data_type FROM information_schema.columns WHERE table_name = ?;";
241-
QueryAdapter query = new QueryAdapter(template);
242-
ResultSet rs = query.executeAndGet(globalState, tableName);
243+
String filled = "SELECT column_name, data_type FROM information_schema.columns WHERE table_name = '" + tableName + "';";
244+
QueryAdapter query = new QueryAdapter(filled);
245+
ResultSet rs = query.executeAndGet(globalState, template, tableName);
243246
while (rs.next()) {
244247
String columnName = rs.getString("column_name");
245248
String dataType = rs.getString("data_type");
@@ -252,8 +255,9 @@ private static void createDistributedTable(String tableName, CitusGlobalState gl
252255
} else {
253256
HashMap<PostgresColumn, List<String>> columnConstraints = new HashMap<>();
254257
String template = "SELECT c.column_name, c.data_type, tc.constraint_type FROM information_schema.table_constraints tc JOIN information_schema.constraint_column_usage AS ccu USING (constraint_schema, constraint_name) JOIN information_schema.columns AS c ON c.table_schema = tc.constraint_schema AND tc.table_name = c.table_name AND ccu.column_name = c.column_name WHERE (constraint_type = 'PRIMARY KEY' OR constraint_type = 'UNIQUE' OR constraint_type = 'EXCLUDE') AND c.table_name = ?;";
255-
QueryAdapter query = new QueryAdapter(template);
256-
ResultSet rs = query.executeAndGet(globalState, tableName);
258+
String filled = "SELECT c.column_name, c.data_type, tc.constraint_type FROM information_schema.table_constraints tc JOIN information_schema.constraint_column_usage AS ccu USING (constraint_schema, constraint_name) JOIN information_schema.columns AS c ON c.table_schema = tc.constraint_schema AND tc.table_name = c.table_name AND ccu.column_name = c.column_name WHERE (constraint_type = 'PRIMARY KEY' OR constraint_type = 'UNIQUE' OR constraint_type = 'EXCLUDE') AND c.table_name = '" + tableName + "';";
259+
QueryAdapter query = new QueryAdapter(filled);
260+
ResultSet rs = query.executeAndGet(globalState, template, tableName);
257261
while (rs.next()) {
258262
String columnName = rs.getString("column_name");
259263
String dataType = rs.getString("data_type");
@@ -282,14 +286,15 @@ private static void createDistributedTable(String tableName, CitusGlobalState gl
282286
@Override
283287
public void generateDatabase(PostgresGlobalState globalState) throws SQLException {
284288
// TODO: function reading? add to Postgres implementation?
285-
createTables(globalState);
289+
createTables(globalState, Randomly.fromOptions(4, 5, 6));
286290
for (PostgresTable table : globalState.getSchema().getDatabaseTables()) {
287291
if (!(table.getTableType() == TableType.TEMPORARY || Randomly.getBooleanWithRatherLowProbability())) {
288292
if (Randomly.getBooleanWithRatherLowProbability()) {
289293
// create reference table
290294
String template = "SELECT create_reference_table(?);";
291-
QueryAdapter query = new QueryAdapter(template, errors);
292-
globalState.executeStatement(query, table.getName());
295+
String filled = "SELECT create_reference_table('" + table.getName() + "');";
296+
QueryAdapter query = new QueryAdapter(filled, errors);
297+
globalState.executeStatement(query, template, table.getName());
293298
} else {
294299
// create distributed table
295300
createDistributedTable(table.getName(), (CitusGlobalState) globalState,
@@ -413,20 +418,6 @@ public Connection createDatabase(PostgresGlobalState globalState) throws SQLExce
413418
}
414419
}
415420

416-
@Override
417-
protected void createTables(PostgresGlobalState globalState) throws SQLException {
418-
while (globalState.getSchema().getDatabaseTables().size() < Randomly.fromOptions(4, 5, 6)) {
419-
try {
420-
String tableName = SQLite3Common.createTableName(globalState.getSchema().getDatabaseTables().size());
421-
Query createTable = CitusTableGenerator.generate(tableName, globalState.getSchema(), generateOnlyKnown,
422-
globalState);
423-
globalState.executeStatement(createTable);
424-
} catch (IgnoreMeException e) {
425-
426-
}
427-
}
428-
}
429-
430421
@Override
431422
protected void prepareTables(PostgresGlobalState globalState) throws SQLException {
432423
StatementExecutor<PostgresGlobalState, Action> se = new StatementExecutor<>(globalState, Action.values(),

src/sqlancer/citus/gen/CitusCommon.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ public static void addCitusErrors(Collection<String> errors) {
5454
errors.add("failed to evaluate partition key in insert");
5555
errors.add("cannot perform an INSERT without a partition column value");
5656
errors.add("cannot perform an INSERT with NULL in the partition column");
57+
errors.add("ERROR: LIMIT must not be negative");
58+
errors.add("value too long for type");
5759

5860
// current errors to be removed once upgraded to PostgreSQL 13?
5961
errors.add("unrecognized configuration parameter \"enable_hashagg_disk\"");

src/sqlancer/postgres/PostgresProvider.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ protected static int mapActions(PostgresGlobalState globalState, Action a) {
199199

200200
@Override
201201
public void generateDatabase(PostgresGlobalState globalState) throws SQLException {
202-
createTables(globalState);
202+
createTables(globalState, Randomly.fromOptions(4, 5, 6));
203203
prepareTables(globalState);
204204
}
205205

@@ -285,8 +285,8 @@ protected void readFunctions(PostgresGlobalState globalState) throws SQLExceptio
285285
}
286286
}
287287

288-
protected void createTables(PostgresGlobalState globalState) throws SQLException {
289-
while (globalState.getSchema().getDatabaseTables().size() < Randomly.fromOptions(1, 2)) {
288+
protected void createTables(PostgresGlobalState globalState, int numTables) throws SQLException {
289+
while (globalState.getSchema().getDatabaseTables().size() < numTables) {
290290
try {
291291
String tableName = SQLite3Common.createTableName(globalState.getSchema().getDatabaseTables().size());
292292
Query createTable = PostgresTableGenerator.generate(tableName, globalState.getSchema(),

src/sqlancer/postgres/gen/PostgresAlterTableGenerator.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ public Query generate() {
249249
break;
250250
case ADD_TABLE_CONSTRAINT:
251251
sb.append("ADD ");
252+
sb.append("CONSTRAINT '" + r.getChar() +"' ");
252253
PostgresCommon.addTableConstraint(sb, randomTable, globalState, errors);
253254
errors.add("multiple primary keys for table");
254255
errors.add("could not create unique index");
@@ -281,8 +282,10 @@ public Query generate() {
281282
sb.append("CONSTRAINT '" + r.getChar() +"' ");
282283
sb.append(Randomly.fromOptions("UNIQUE", "PRIMARY KEY"));
283284
errors.add("not valid");
284-
sb.append(" USING INDEX ");
285-
sb.append(randomTable.getRandomIndex().getIndexName());
285+
if (randomTable.hasIndexes()) {
286+
sb.append(" USING INDEX ");
287+
sb.append(randomTable.getRandomIndex().getIndexName());
288+
}
286289
errors.add("is not a unique index");
287290
errors.add("is already associated with a constraint");
288291
errors.add("Cannot create a primary key or unique constraint using such an index");

0 commit comments

Comments
 (0)