@@ -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 (),
0 commit comments