use of io.trino.sql.tree.GroupBy in project trino by trinodb.
the class TestSqlParser method testSelectWithGroupBy.
@Test
public void testSelectWithGroupBy() {
assertStatement("SELECT * FROM table1 GROUP BY a", simpleQuery(selectList(new AllColumns()), new Table(QualifiedName.of("table1")), Optional.empty(), Optional.of(new GroupBy(false, ImmutableList.of(new SimpleGroupBy(ImmutableList.of(new Identifier("a")))))), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty()));
assertStatement("SELECT * FROM table1 GROUP BY a, b", simpleQuery(selectList(new AllColumns()), new Table(QualifiedName.of("table1")), Optional.empty(), Optional.of(new GroupBy(false, ImmutableList.of(new SimpleGroupBy(ImmutableList.of(new Identifier("a"))), new SimpleGroupBy(ImmutableList.of(new Identifier("b")))))), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty()));
assertStatement("SELECT * FROM table1 GROUP BY ()", simpleQuery(selectList(new AllColumns()), new Table(QualifiedName.of("table1")), Optional.empty(), Optional.of(new GroupBy(false, ImmutableList.of(new SimpleGroupBy(ImmutableList.of())))), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty()));
assertStatement("SELECT * FROM table1 GROUP BY GROUPING SETS (a)", simpleQuery(selectList(new AllColumns()), new Table(QualifiedName.of("table1")), Optional.empty(), Optional.of(new GroupBy(false, ImmutableList.of(new GroupingSets(ImmutableList.of(ImmutableList.of(new Identifier("a"))))))), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty()));
assertStatement("SELECT a, b, GROUPING(a, b) FROM table1 GROUP BY GROUPING SETS ((a), (b))", simpleQuery(selectList(DereferenceExpression.from(QualifiedName.of("a")), DereferenceExpression.from(QualifiedName.of("b")), new GroupingOperation(Optional.empty(), ImmutableList.of(QualifiedName.of("a"), QualifiedName.of("b")))), new Table(QualifiedName.of("table1")), Optional.empty(), Optional.of(new GroupBy(false, ImmutableList.of(new GroupingSets(ImmutableList.of(ImmutableList.of(new Identifier("a")), ImmutableList.of(new Identifier("b"))))))), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty()));
assertStatement("SELECT * FROM table1 GROUP BY ALL GROUPING SETS ((a, b), (a), ()), CUBE (c), ROLLUP (d)", simpleQuery(selectList(new AllColumns()), new Table(QualifiedName.of("table1")), Optional.empty(), Optional.of(new GroupBy(false, ImmutableList.of(new GroupingSets(ImmutableList.of(ImmutableList.of(new Identifier("a"), new Identifier("b")), ImmutableList.of(new Identifier("a")), ImmutableList.of())), new Cube(ImmutableList.of(new Identifier("c"))), new Rollup(ImmutableList.of(new Identifier("d")))))), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty()));
assertStatement("SELECT * FROM table1 GROUP BY DISTINCT GROUPING SETS ((a, b), (a), ()), CUBE (c), ROLLUP (d)", simpleQuery(selectList(new AllColumns()), new Table(QualifiedName.of("table1")), Optional.empty(), Optional.of(new GroupBy(true, ImmutableList.of(new GroupingSets(ImmutableList.of(ImmutableList.of(new Identifier("a"), new Identifier("b")), ImmutableList.of(new Identifier("a")), ImmutableList.of())), new Cube(ImmutableList.of(new Identifier("c"))), new Rollup(ImmutableList.of(new Identifier("d")))))), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty()));
}
Aggregations