@Test
public void testCompleteQuery() {

  Parser<Relation> parser = RelationParser.query();
  TerminalParserTest.assertParser(parser, "select 1 from t",
      new Select(false, 
          Arrays.asList(new Projection(ExpressionParserTest.number(1), null)),
          Arrays.asList(table("t")),
          null, null, null));
  TerminalParserTest.assertParser(parser, "select 1 from (select * from table) t",
      new Select(false, 
          Arrays.asList(new Projection(ExpressionParserTest.number(1), null)),
          Arrays.<Relation>asList(new AliasedRelation(
              new Select(false, 
                  Arrays.asList(new Projection(ExpressionParserTest.wildcard(), null)),
                  Arrays.asList(table("table")),
                  null, null, null),
              "t")),
          null, null, null));
  TerminalParserTest.assertParser(parser, "select 1 from t where x > 1",
      new Select(false, 
          Arrays.asList(new Projection(ExpressionParserTest.number(1), null)),
          Arrays.asList(table("t")),
          new BinaryExpression(ExpressionParserTest.name("x"), Op.GT, ExpressionParserTest.number(1)), null, null));
  TerminalParserTest.assertParser(parser, "select 1 from t where exists (select * from t2)",
      new Select(false, 
          Arrays.asList(new Projection(ExpressionParserTest.number(1), null)),
          Arrays.asList(table("t")),
          new UnaryRelationalExpression(
              new Select(false, 
                  Arrays.asList(new Projection(ExpressionParserTest.wildcard(), null)),
                  Arrays.asList(table("t2")),
                  null, null, null),
              Op.EXISTS), null, null));
  TerminalParserTest.assertParser(parser, "select case when exists (select * from t1) then 1 end from t",
      new Select(false, 
          Arrays.asList(new Projection(
              ExpressionParserTest.fullCase(new UnaryRelationalExpression(
                  new Select(false, 
                      Arrays.asList(new Projection(ExpressionParserTest.wildcard(), null)),
                      Arrays.asList(table("t1")),
                      null, null, null), Op.EXISTS), ExpressionParserTest.number(1), null),
                  null)),
          Arrays.asList(table("t")),
          null, null, null));
}