Skip to content

Commit

Permalink
Extract order table columns definition to separate method
Browse files Browse the repository at this point in the history
  • Loading branch information
pajaks authored and wendigo committed Jun 28, 2024
1 parent a0751aa commit d8e2e3c
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -160,43 +160,22 @@ public void testShowCreateTable()
")");
}

@Test
@Override
public void testSelectInformationSchemaColumns()
protected @Language("SQL") String getOrdersTableWithColumns()
{
String catalog = getSession().getCatalog().get();
String schema = getSession().getSchema().get();
String schemaPattern = schema.replaceAll(".$", "_");

@Language("SQL") String ordersTableWithColumns = "VALUES " +
"('orders', 'orderkey'), " +
"('orders', 'custkey'), " +
"('orders', 'orderstatus'), " +
"('orders', 'totalprice'), " +
"('orders', 'orderdate'), " +
"('orders', '__time'), " +
"('orders', 'orderpriority'), " +
"('orders', 'clerk'), " +
"('orders', 'shippriority'), " +
"('orders', 'comment')";

assertQuery("SELECT table_schema FROM information_schema.columns WHERE table_schema = '" + schema + "' GROUP BY table_schema", "VALUES '" + schema + "'");
assertQuery("SELECT table_name FROM information_schema.columns WHERE table_name = 'orders' GROUP BY table_name", "VALUES 'orders'");
assertQuery("SELECT table_name, column_name FROM information_schema.columns WHERE table_schema = '" + schema + "' AND table_name = 'orders'", ordersTableWithColumns);
assertQuery("SELECT table_name, column_name FROM information_schema.columns WHERE table_schema = '" + schema + "' AND table_name LIKE '%rders'", ordersTableWithColumns);
assertQuery("SELECT table_name, column_name FROM information_schema.columns WHERE table_schema LIKE '" + schemaPattern + "' AND table_name LIKE '_rder_'", ordersTableWithColumns);
assertQuery(
"SELECT table_name, column_name FROM information_schema.columns " +
"WHERE table_catalog = '" + catalog + "' AND table_schema = '" + schema + "' AND table_name LIKE '%orders%'",
ordersTableWithColumns);

assertQuerySucceeds("SELECT * FROM information_schema.columns");
assertQuery("SELECT DISTINCT table_name, column_name FROM information_schema.columns WHERE table_name LIKE '_rders'", ordersTableWithColumns);
assertQuerySucceeds("SELECT * FROM information_schema.columns WHERE table_catalog = '" + catalog + "'");
assertQuerySucceeds("SELECT * FROM information_schema.columns WHERE table_catalog = '" + catalog + "' AND table_schema = '" + schema + "'");
assertQuery("SELECT table_name, column_name FROM information_schema.columns WHERE table_catalog = '" + catalog + "' AND table_schema = '" + schema + "' AND table_name LIKE '_rders'", ordersTableWithColumns);
assertQuerySucceeds("SELECT * FROM information_schema.columns WHERE table_catalog = '" + catalog + "' AND table_name LIKE '%'");
assertQuery("SELECT column_name FROM information_schema.columns WHERE table_catalog = 'something_else'", "SELECT '' WHERE false");
return """
VALUES
('orders', 'orderkey'),
('orders', 'custkey'),
('orders', 'orderstatus'),
('orders', 'totalprice'),
('orders', 'orderdate'),
('orders', '__time'),
('orders', 'orderpriority'),
('orders', 'clerk'),
('orders', 'shippriority'),
('orders', 'comment')
""";
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,10 @@ public void testSelectAll()
assertQuery("SELECT orderkey, custkey, orderstatus, totalprice, orderdate, orderpriority, clerk, shippriority, comment FROM orders");
}

@Test
@Override // Override because updated_at_seconds column exists
public void testSelectInformationSchemaColumns()
@Override
protected @Language("SQL") String getOrdersTableWithColumns()
{
String catalog = getSession().getCatalog().get();
String schema = getSession().getSchema().get();
String schemaPattern = schema.replaceAll(".$", "_");

@Language("SQL") String ordersTableWithColumns = """
return """
VALUES
('orders', 'orderkey'),
('orders', 'custkey'),
Expand All @@ -121,24 +116,6 @@ public void testSelectInformationSchemaColumns()
('orders', 'shippriority'),
('orders', 'comment')
""";

assertQuery("SELECT table_schema FROM information_schema.columns WHERE table_schema = '" + schema + "' GROUP BY table_schema", "VALUES '" + schema + "'");
assertQuery("SELECT table_name FROM information_schema.columns WHERE table_name = 'orders' GROUP BY table_name", "VALUES 'orders'");
assertQuery("SELECT table_name, column_name FROM information_schema.columns WHERE table_schema = '" + schema + "' AND table_name = 'orders'", ordersTableWithColumns);
assertQuery("SELECT table_name, column_name FROM information_schema.columns WHERE table_schema = '" + schema + "' AND table_name LIKE '%rders'", ordersTableWithColumns);
assertQuery("SELECT table_name, column_name FROM information_schema.columns WHERE table_schema LIKE '" + schemaPattern + "' AND table_name LIKE '_rder_'", ordersTableWithColumns);
assertQuery(
"SELECT table_name, column_name FROM information_schema.columns " +
"WHERE table_catalog = '" + catalog + "' AND table_schema = '" + schema + "' AND table_name LIKE '%orders%'",
ordersTableWithColumns);

assertQuerySucceeds("SELECT * FROM information_schema.columns");
assertQuery("SELECT DISTINCT table_name, column_name FROM information_schema.columns WHERE table_name LIKE '_rders'", ordersTableWithColumns);
assertQuerySucceeds("SELECT * FROM information_schema.columns WHERE table_catalog = '" + catalog + "'");
assertQuerySucceeds("SELECT * FROM information_schema.columns WHERE table_catalog = '" + catalog + "' AND table_schema = '" + schema + "'");
assertQuery("SELECT table_name, column_name FROM information_schema.columns WHERE table_catalog = '" + catalog + "' AND table_schema = '" + schema + "' AND table_name LIKE '_rders'", ordersTableWithColumns);
assertQuerySucceeds("SELECT * FROM information_schema.columns WHERE table_catalog = '" + catalog + "' AND table_name LIKE '%'");
assertQuery("SELECT column_name FROM information_schema.columns WHERE table_catalog = 'something_else'", "SELECT '' WHERE false");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2067,16 +2067,7 @@ public void testSelectInformationSchemaColumns()
String schema = getSession().getSchema().get();
String schemaPattern = schema.replaceAll(".$", "_");

@Language("SQL") String ordersTableWithColumns = "VALUES " +
"('orders', 'orderkey'), " +
"('orders', 'custkey'), " +
"('orders', 'orderstatus'), " +
"('orders', 'totalprice'), " +
"('orders', 'orderdate'), " +
"('orders', 'orderpriority'), " +
"('orders', 'clerk'), " +
"('orders', 'shippriority'), " +
"('orders', 'comment')";
String ordersTableWithColumns = getOrdersTableWithColumns();

assertQuery("SELECT table_schema FROM information_schema.columns WHERE table_schema = '" + schema + "' GROUP BY table_schema", "VALUES '" + schema + "'");
assertQuery("SELECT table_name FROM information_schema.columns WHERE table_name = 'orders' GROUP BY table_name", "VALUES 'orders'");
Expand Down Expand Up @@ -2110,6 +2101,22 @@ public void testSelectInformationSchemaColumns()
"('views')");
}

protected @Language("SQL") String getOrdersTableWithColumns()
{
return """
VALUES
('orders', 'orderkey'),
('orders', 'custkey'),
('orders', 'orderstatus'),
('orders', 'totalprice'),
('orders', 'orderdate'),
('orders', 'orderpriority'),
('orders', 'clerk'),
('orders', 'shippriority'),
('orders', 'comment')
""";
}

@Test
public void testShowCreateInformationSchema()
{
Expand Down

0 comments on commit d8e2e3c

Please sign in to comment.