public void testCompleteQuery() {
Parser<Relation> parser = RelationParser.query();
assertParser(parser, "select 1 from t",
new Select(false,
Arrays.asList(new Projection(number(1), null)),
Arrays.asList(table("t")),
null, null, null));
assertParser(parser, "select 1 from (select * from table) t",
new Select(false,
Arrays.asList(new Projection(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));
assertParser(parser, "select 1 from t where x > 1",
new Select(false,
Arrays.asList(new Projection(number(1), null)),
Arrays.asList(table("t")),
new BinaryExpression(ExpressionParserTest.name("x"), Op.GT, number(1)), null, null));
assertParser(parser, "select 1 from t where exists (select * from t2)",
new Select(false,
Arrays.asList(new Projection(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));
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), number(1), null),
null)),
Arrays.asList(table("t")),
null, null, null));