Search in sources :

Example 1 with AllColumns

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

the class TestSqlParser method testSelectWithOffset.

@Test
public void testSelectWithOffset() {
    assertStatement("SELECT * FROM table1 OFFSET 2 ROWS", 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.of(new Offset("2")), Optional.empty()), Optional.empty(), Optional.empty(), Optional.empty()));
    assertStatement("SELECT * FROM table1 OFFSET 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.of(new Offset("2")), Optional.empty()), 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')) OFFSET 2 ROWS", simpleQuery(selectList(new AllColumns()), subquery(valuesQuery), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.of(new Offset("2")), Optional.empty()));
    assertStatement("SELECT * FROM (VALUES (1, '1'), (2, '2')) OFFSET 2", simpleQuery(selectList(new AllColumns()), subquery(valuesQuery), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.of(new Offset("2")), Optional.empty()));
}
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) Offset(io.prestosql.sql.tree.Offset) Test(org.testng.annotations.Test)

Example 2 with AllColumns

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

the class TestSqlParser method testCreateView.

@Test
public void testCreateView() {
    Query query = simpleQuery(selectList(new AllColumns()), table(QualifiedName.of("t")));
    assertStatement("CREATE VIEW a AS SELECT * FROM t", new CreateView(QualifiedName.of("a"), query, false, Optional.empty()));
    assertStatement("CREATE OR REPLACE VIEW a AS SELECT * FROM t", new CreateView(QualifiedName.of("a"), query, true, Optional.empty()));
    assertStatement("CREATE VIEW a SECURITY DEFINER AS SELECT * FROM t", new CreateView(QualifiedName.of("a"), query, false, Optional.of(CreateView.Security.DEFINER)));
    assertStatement("CREATE VIEW a SECURITY INVOKER AS SELECT * FROM t", new CreateView(QualifiedName.of("a"), query, false, Optional.of(CreateView.Security.INVOKER)));
    assertStatement("CREATE VIEW bar.foo AS SELECT * FROM t", new CreateView(QualifiedName.of("bar", "foo"), query, false, Optional.empty()));
    assertStatement("CREATE VIEW \"awesome view\" AS SELECT * FROM t", new CreateView(QualifiedName.of("awesome view"), query, false, Optional.empty()));
    assertStatement("CREATE VIEW \"awesome schema\".\"awesome view\" AS SELECT * FROM t", new CreateView(QualifiedName.of("awesome schema", "awesome view"), query, false, Optional.empty()));
}
Also used : QueryUtil.simpleQuery(io.prestosql.sql.QueryUtil.simpleQuery) Query(io.prestosql.sql.tree.Query) WithQuery(io.prestosql.sql.tree.WithQuery) AllColumns(io.prestosql.sql.tree.AllColumns) CreateView(io.prestosql.sql.tree.CreateView) Test(org.testng.annotations.Test)

Example 3 with AllColumns

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

the class TestSqlParser method testShowStatsForQuery.

@Test
public void testShowStatsForQuery() {
    final String[] tableNames = { "t", "s.t", "c.s.t" };
    for (String fullName : tableNames) {
        QualifiedName qualifiedName = makeQualifiedName(fullName);
        assertStatement(format("SHOW STATS FOR (SELECT * FROM %s)", qualifiedName), createShowStats(qualifiedName, ImmutableList.of(new AllColumns()), Optional.empty()));
        assertStatement(format("SHOW STATS FOR (SELECT * FROM %s WHERE field > 0)", qualifiedName), createShowStats(qualifiedName, ImmutableList.of(new AllColumns()), Optional.of(new ComparisonExpression(GREATER_THAN, new Identifier("field"), new LongLiteral("0")))));
        assertStatement(format("SHOW STATS FOR (SELECT * FROM %s WHERE field > 0 or field < 0)", qualifiedName), createShowStats(qualifiedName, ImmutableList.of(new AllColumns()), Optional.of(new LogicalBinaryExpression(LogicalBinaryExpression.Operator.OR, new ComparisonExpression(GREATER_THAN, new Identifier("field"), new LongLiteral("0")), new ComparisonExpression(LESS_THAN, new Identifier("field"), new LongLiteral("0"))))));
    }
}
Also used : LogicalBinaryExpression(io.prestosql.sql.tree.LogicalBinaryExpression) ComparisonExpression(io.prestosql.sql.tree.ComparisonExpression) QuantifiedComparisonExpression(io.prestosql.sql.tree.QuantifiedComparisonExpression) Identifier(io.prestosql.sql.tree.Identifier) QueryUtil.quotedIdentifier(io.prestosql.sql.QueryUtil.quotedIdentifier) LongLiteral(io.prestosql.sql.tree.LongLiteral) QualifiedName(io.prestosql.sql.tree.QualifiedName) AllColumns(io.prestosql.sql.tree.AllColumns) Test(org.testng.annotations.Test)

Example 4 with AllColumns

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

the class TestSqlParser method testJoinPrecedence.

@Test
public void testJoinPrecedence() {
    assertStatement("SELECT * FROM a CROSS JOIN b LEFT JOIN c ON true", simpleQuery(selectList(new AllColumns()), new Join(Join.Type.LEFT, new Join(Join.Type.CROSS, new Table(QualifiedName.of("a")), new Table(QualifiedName.of("b")), Optional.empty()), new Table(QualifiedName.of("c")), Optional.of(new JoinOn(BooleanLiteral.TRUE_LITERAL)))));
    assertStatement("SELECT * FROM a CROSS JOIN b NATURAL JOIN c CROSS JOIN d NATURAL JOIN e", simpleQuery(selectList(new AllColumns()), new Join(Join.Type.INNER, new Join(Join.Type.CROSS, new Join(Join.Type.INNER, new Join(Join.Type.CROSS, new Table(QualifiedName.of("a")), new Table(QualifiedName.of("b")), Optional.empty()), new Table(QualifiedName.of("c")), Optional.of(new NaturalJoin())), new Table(QualifiedName.of("d")), Optional.empty()), new Table(QualifiedName.of("e")), Optional.of(new NaturalJoin()))));
}
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) Join(io.prestosql.sql.tree.Join) NaturalJoin(io.prestosql.sql.tree.NaturalJoin) AllColumns(io.prestosql.sql.tree.AllColumns) NaturalJoin(io.prestosql.sql.tree.NaturalJoin) JoinOn(io.prestosql.sql.tree.JoinOn) Test(org.testng.annotations.Test)

Example 5 with AllColumns

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

the class TestSqlParser method testValues.

@Test
public void testValues() {
    Query valuesQuery = query(values(row(new StringLiteral("a"), new LongLiteral("1"), new DoubleLiteral("2.2")), row(new StringLiteral("b"), new LongLiteral("2"), new DoubleLiteral("3.3"))));
    assertStatement("VALUES ('a', 1, 2.2e0), ('b', 2, 3.3e0)", valuesQuery);
    assertStatement("SELECT * FROM (VALUES ('a', 1, 2.2e0), ('b', 2, 3.3e0))", simpleQuery(selectList(new AllColumns()), subquery(valuesQuery)));
}
Also used : 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) DoubleLiteral(io.prestosql.sql.tree.DoubleLiteral) AllColumns(io.prestosql.sql.tree.AllColumns) 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