RelationParser { static Parser<GroupBy> groupByClause(Parser<Expression> expr, Parser<Expression> cond) { return Parsers.sequence( TerminalParser.phrase("group by").next(list(expr)), TerminalParser.phrase("having").next(cond).optional(), GroupBy::new); }  static Parser<Relation> query();  }
@Test public void testGroupByClause() { Parser<GroupBy> parser = RelationParser.groupByClause(ExpressionParser.NUMBER, ExpressionParser.NUMBER); TerminalParserTest.assertParser(parser, "group by 1, 2", new GroupBy(Arrays.asList(ExpressionParserTest.number(1), ExpressionParserTest.number(2)), null)); TerminalParserTest.assertParser(parser, "group by 1, 2 having 3", new GroupBy(Arrays.asList(ExpressionParserTest.number(1), ExpressionParserTest.number(2)), ExpressionParserTest.number(3))); }