@Test
public void testSchemaCompletionWithComplexSubquery() throws SqlParseException {

    String sql = "SELECT a, b " + "FROM (" + "   SELECT c, d, sum(p) " + "   FROM table1 t1, DB.table2 t2 "
            + "   WHERE t1.c > t2.d " + "   GROUP BY t.e" + "   HAVING sum(p) > 100" + "   ORDER BY t2.f" + ") at1 "
            + "INNER JOIN table3 t3 " + "ON at1.c = t3.c " + "WHERE t3.d > 0 " + "ORDER BY t3.e";
    String exceptSQL = "SELECT a, b " + "FROM (" + "   SELECT c, d, sum(p) "
            + "   FROM EDW.table1 t1, DB.table2 t2 " + "   WHERE t1.c > t2.d " + "   GROUP BY t.e"
            + "   HAVING sum(p) > 100" + "   ORDER BY t2.f" + ") at1 " + "INNER JOIN EDW.table3 t3 "
            + "ON at1.c = t3.c " + "WHERE t3.d > 0 " + "ORDER BY t3.e";
    Assert.assertEquals(exceptSQL, PushDownUtil.schemaCompletion(sql, "EDW"));
}