RelationParser { static Parser<Relation> query( Parser<Expression> expr, Parser<Expression> cond, Parser<Relation> rel) { return union(select(expr, cond, rel)); }  static Parser<Relation> query();  }
@Test public void testQuery() { Parser<Relation> parser = RelationParser.query(ExpressionParser.NUMBER, ExpressionParser.NUMBER, TABLE); 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 a union select distinct 2 from b", new UnionRelation( new Select(false, Arrays.asList(new Projection(ExpressionParserTest.number(1), null)), Arrays.asList(table("a")), null, null, null), false, new Select(true, Arrays.asList(new Projection(ExpressionParserTest.number(2), null)), Arrays.asList(table("b")), null, null, null))); }
@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)); }