Search in sources :

Example 11 with AllColumns

use of io.prestosql.sql.tree.AllColumns in project hetu-core by openlookeng.

the class TestSqlParser method testSelectWithGroupBy.

@Test
public void testSelectWithGroupBy() {
    assertStatement("SELECT * FROM table1 GROUP BY a", new Query(Optional.empty(), new QuerySpecification(selectList(new AllColumns()), Optional.of(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()), Optional.empty(), Optional.empty(), Optional.empty()));
    assertStatement("SELECT * FROM table1 GROUP BY a, b", new Query(Optional.empty(), new QuerySpecification(selectList(new AllColumns()), Optional.of(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()), Optional.empty(), Optional.empty(), Optional.empty()));
    assertStatement("SELECT * FROM table1 GROUP BY ()", new Query(Optional.empty(), new QuerySpecification(selectList(new AllColumns()), Optional.of(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()), Optional.empty(), Optional.empty(), Optional.empty()));
    assertStatement("SELECT * FROM table1 GROUP BY GROUPING SETS (a)", new Query(Optional.empty(), new QuerySpecification(selectList(new AllColumns()), Optional.of(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()), Optional.empty(), Optional.empty(), Optional.empty()));
    assertStatement("SELECT a, b, GROUPING(a, b) FROM table1 GROUP BY GROUPING SETS ((a), (b))", new Query(Optional.empty(), new QuerySpecification(selectList(DereferenceExpression.from(QualifiedName.of("a")), DereferenceExpression.from(QualifiedName.of("b")), new GroupingOperation(Optional.empty(), ImmutableList.of(QualifiedName.of("a"), QualifiedName.of("b")))), Optional.of(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()), Optional.empty(), Optional.empty(), Optional.empty()));
    assertStatement("SELECT * FROM table1 GROUP BY ALL GROUPING SETS ((a, b), (a), ()), CUBE (c), ROLLUP (d)", new Query(Optional.empty(), new QuerySpecification(selectList(new AllColumns()), Optional.of(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()), Optional.empty(), Optional.empty(), Optional.empty()));
    assertStatement("SELECT * FROM table1 GROUP BY DISTINCT GROUPING SETS ((a, b), (a), ()), CUBE (c), ROLLUP (d)", new Query(Optional.empty(), new QuerySpecification(selectList(new AllColumns()), Optional.of(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()), Optional.empty(), Optional.empty(), Optional.empty()));
}
Also used : GroupingSets(io.prestosql.sql.tree.GroupingSets) QuerySpecification(io.prestosql.sql.tree.QuerySpecification) SimpleGroupBy(io.prestosql.sql.tree.SimpleGroupBy) Table(io.prestosql.sql.tree.Table) CreateTable(io.prestosql.sql.tree.CreateTable) VacuumTable(io.prestosql.sql.tree.VacuumTable) DropTable(io.prestosql.sql.tree.DropTable) RenameTable(io.prestosql.sql.tree.RenameTable) GroupBy(io.prestosql.sql.tree.GroupBy) SimpleGroupBy(io.prestosql.sql.tree.SimpleGroupBy) Identifier(io.prestosql.sql.tree.Identifier) QueryUtil.quotedIdentifier(io.prestosql.sql.QueryUtil.quotedIdentifier) QueryUtil.simpleQuery(io.prestosql.sql.QueryUtil.simpleQuery) Query(io.prestosql.sql.tree.Query) WithQuery(io.prestosql.sql.tree.WithQuery) Rollup(io.prestosql.sql.tree.Rollup) Cube(io.prestosql.sql.tree.Cube) CreateCube(io.prestosql.sql.tree.CreateCube) DropCube(io.prestosql.sql.tree.DropCube) InsertCube(io.prestosql.sql.tree.InsertCube) AllColumns(io.prestosql.sql.tree.AllColumns) GroupingOperation(io.prestosql.sql.tree.GroupingOperation) Test(org.testng.annotations.Test)

Example 12 with AllColumns

use of io.prestosql.sql.tree.AllColumns in project hetu-core by openlookeng.

the class TestSqlParser method testInsertOverwrite.

@Test
public void testInsertOverwrite() {
    QualifiedName table = QualifiedName.of("a");
    Query query = simpleQuery(selectList(new AllColumns()), table(QualifiedName.of("t")));
    assertStatement("INSERT OVERWRITE a SELECT * FROM t", new Insert(table, Optional.empty(), query, true));
    assertStatement("INSERT OVERWRITE a (c1, c2) SELECT * FROM t", new Insert(table, Optional.of(ImmutableList.of(identifier("c1"), identifier("c2"))), query, true));
}
Also used : QueryUtil.simpleQuery(io.prestosql.sql.QueryUtil.simpleQuery) Query(io.prestosql.sql.tree.Query) WithQuery(io.prestosql.sql.tree.WithQuery) QualifiedName(io.prestosql.sql.tree.QualifiedName) AllColumns(io.prestosql.sql.tree.AllColumns) Insert(io.prestosql.sql.tree.Insert) Test(org.testng.annotations.Test)

Example 13 with AllColumns

use of io.prestosql.sql.tree.AllColumns in project hetu-core by openlookeng.

the class TestSqlParser method testSelectWithLimit.

@Test
public void testSelectWithLimit() {
    assertStatement("SELECT * FROM table1 LIMIT 2", new Query(Optional.empty(), new QuerySpecification(selectList(new AllColumns()), Optional.of(new Table(QualifiedName.of("table1"))), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.of(new Limit("2"))), Optional.empty(), Optional.empty(), Optional.empty()));
    assertStatement("SELECT * FROM table1 LIMIT ALL", new Query(Optional.empty(), new QuerySpecification(selectList(new AllColumns()), Optional.of(new Table(QualifiedName.of("table1"))), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.of(new Limit("ALL"))), Optional.empty(), Optional.empty(), Optional.empty()));
    Query valuesQuery = query(values(row(new LongLiteral("1"), new StringLiteral("1")), row(new LongLiteral("2"), new StringLiteral("2"))));
    assertStatement("SELECT * FROM (VALUES (1, '1'), (2, '2')) LIMIT ALL", simpleQuery(selectList(new AllColumns()), subquery(valuesQuery), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.of(new Limit("ALL"))));
}
Also used : QuerySpecification(io.prestosql.sql.tree.QuerySpecification) Table(io.prestosql.sql.tree.Table) CreateTable(io.prestosql.sql.tree.CreateTable) VacuumTable(io.prestosql.sql.tree.VacuumTable) DropTable(io.prestosql.sql.tree.DropTable) RenameTable(io.prestosql.sql.tree.RenameTable) QueryUtil.simpleQuery(io.prestosql.sql.QueryUtil.simpleQuery) Query(io.prestosql.sql.tree.Query) WithQuery(io.prestosql.sql.tree.WithQuery) StringLiteral(io.prestosql.sql.tree.StringLiteral) LongLiteral(io.prestosql.sql.tree.LongLiteral) AllColumns(io.prestosql.sql.tree.AllColumns) Limit(io.prestosql.sql.tree.Limit) Test(org.testng.annotations.Test)

Example 14 with AllColumns

use of io.prestosql.sql.tree.AllColumns in project hetu-core by openlookeng.

the class TestSqlParser method testExplain.

@Test
public void testExplain() {
    assertStatement("EXPLAIN SELECT * FROM t", new Explain(simpleQuery(selectList(new AllColumns()), table(QualifiedName.of("t"))), false, false, ImmutableList.of()));
    assertStatement("EXPLAIN (TYPE LOGICAL) SELECT * FROM t", new Explain(simpleQuery(selectList(new AllColumns()), table(QualifiedName.of("t"))), false, false, ImmutableList.of(new ExplainType(ExplainType.Type.LOGICAL))));
    assertStatement("EXPLAIN (TYPE LOGICAL, FORMAT TEXT) SELECT * FROM t", new Explain(simpleQuery(selectList(new AllColumns()), table(QualifiedName.of("t"))), false, false, ImmutableList.of(new ExplainType(ExplainType.Type.LOGICAL), new ExplainFormat(ExplainFormat.Type.TEXT))));
}
Also used : ExplainType(io.prestosql.sql.tree.ExplainType) ExplainFormat(io.prestosql.sql.tree.ExplainFormat) Explain(io.prestosql.sql.tree.Explain) AllColumns(io.prestosql.sql.tree.AllColumns) Test(org.testng.annotations.Test)

Example 15 with AllColumns

use of io.prestosql.sql.tree.AllColumns in project hetu-core by openlookeng.

the class TestSqlParser method testWith.

@Test
public void testWith() {
    assertStatement("WITH a (t, u) AS (SELECT * FROM x), b AS (SELECT * FROM y) TABLE z", new Query(Optional.of(new With(false, ImmutableList.of(new WithQuery(identifier("a"), simpleQuery(selectList(new AllColumns()), table(QualifiedName.of("x"))), Optional.of(ImmutableList.of(identifier("t"), identifier("u")))), new WithQuery(identifier("b"), simpleQuery(selectList(new AllColumns()), table(QualifiedName.of("y"))), Optional.empty())))), new Table(QualifiedName.of("z")), Optional.empty(), Optional.empty(), Optional.empty()));
    assertStatement("WITH RECURSIVE a AS (SELECT * FROM x) TABLE y", new Query(Optional.of(new With(true, ImmutableList.of(new WithQuery(identifier("a"), simpleQuery(selectList(new AllColumns()), table(QualifiedName.of("x"))), Optional.empty())))), new Table(QualifiedName.of("y")), Optional.empty(), Optional.empty(), Optional.empty()));
}
Also used : Table(io.prestosql.sql.tree.Table) CreateTable(io.prestosql.sql.tree.CreateTable) VacuumTable(io.prestosql.sql.tree.VacuumTable) DropTable(io.prestosql.sql.tree.DropTable) RenameTable(io.prestosql.sql.tree.RenameTable) QueryUtil.simpleQuery(io.prestosql.sql.QueryUtil.simpleQuery) Query(io.prestosql.sql.tree.Query) WithQuery(io.prestosql.sql.tree.WithQuery) WithQuery(io.prestosql.sql.tree.WithQuery) AllColumns(io.prestosql.sql.tree.AllColumns) With(io.prestosql.sql.tree.With) Test(org.testng.annotations.Test)

Aggregations

AllColumns (io.prestosql.sql.tree.AllColumns)20 Test (org.testng.annotations.Test)19 Query (io.prestosql.sql.tree.Query)14 QueryUtil.simpleQuery (io.prestosql.sql.QueryUtil.simpleQuery)13 WithQuery (io.prestosql.sql.tree.WithQuery)11 Table (io.prestosql.sql.tree.Table)9 CreateTable (io.prestosql.sql.tree.CreateTable)8 DropTable (io.prestosql.sql.tree.DropTable)8 LongLiteral (io.prestosql.sql.tree.LongLiteral)8 RenameTable (io.prestosql.sql.tree.RenameTable)8 VacuumTable (io.prestosql.sql.tree.VacuumTable)8 StringLiteral (io.prestosql.sql.tree.StringLiteral)6 Identifier (io.prestosql.sql.tree.Identifier)5 QualifiedName (io.prestosql.sql.tree.QualifiedName)5 QuerySpecification (io.prestosql.sql.tree.QuerySpecification)5 QueryUtil.quotedIdentifier (io.prestosql.sql.QueryUtil.quotedIdentifier)4 AliasedRelation (io.prestosql.sql.tree.AliasedRelation)3 Session (io.prestosql.Session)2 PreparedQuery (io.prestosql.execution.QueryPreparer.PreparedQuery)2 ComparisonExpression (io.prestosql.sql.tree.ComparisonExpression)2