Search in sources :

Example 6 with AllColumns

use of io.trino.sql.tree.AllColumns in project trino by trinodb.

the class TestCreateMaterializedViewTask method testCreateMaterializedViewIfNotExists.

@Test
public void testCreateMaterializedViewIfNotExists() {
    CreateMaterializedView statement = new CreateMaterializedView(Optional.empty(), QualifiedName.of("test_mv"), simpleQuery(selectList(new AllColumns()), table(QualifiedName.of("catalog", "schema", "mock_table"))), false, true, ImmutableList.of(), Optional.empty());
    getFutureValue(new CreateMaterializedViewTask(plannerContext, new AllowAllAccessControl(), parser, analyzerFactory, materializedViewPropertyManager, new FeaturesConfig()).execute(statement, queryStateMachine, ImmutableList.of(), WarningCollector.NOOP));
    assertEquals(metadata.getCreateMaterializedViewCallCount(), 1);
}
Also used : CreateMaterializedView(io.trino.sql.tree.CreateMaterializedView) AllowAllAccessControl(io.trino.security.AllowAllAccessControl) FeaturesConfig(io.trino.FeaturesConfig) AllColumns(io.trino.sql.tree.AllColumns) Test(org.testng.annotations.Test)

Example 7 with AllColumns

use of io.trino.sql.tree.AllColumns in project trino by trinodb.

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 : CreateTable(io.trino.sql.tree.CreateTable) DropTable(io.trino.sql.tree.DropTable) Table(io.trino.sql.tree.Table) TruncateTable(io.trino.sql.tree.TruncateTable) RenameTable(io.trino.sql.tree.RenameTable) NaturalJoin(io.trino.sql.tree.NaturalJoin) Join(io.trino.sql.tree.Join) AllColumns(io.trino.sql.tree.AllColumns) NaturalJoin(io.trino.sql.tree.NaturalJoin) JoinOn(io.trino.sql.tree.JoinOn) Test(org.junit.jupiter.api.Test)

Example 8 with AllColumns

use of io.trino.sql.tree.AllColumns in project trino by trinodb.

the class TestSqlParser method testUnnest.

@Test
public void testUnnest() {
    assertStatement("SELECT * FROM t CROSS JOIN UNNEST(a)", simpleQuery(selectList(new AllColumns()), new Join(Join.Type.CROSS, new Table(QualifiedName.of("t")), new Unnest(ImmutableList.of(new Identifier("a")), false), Optional.empty())));
    assertStatement("SELECT * FROM t CROSS JOIN UNNEST(a, b) WITH ORDINALITY", simpleQuery(selectList(new AllColumns()), new Join(Join.Type.CROSS, new Table(QualifiedName.of("t")), new Unnest(ImmutableList.of(new Identifier("a"), new Identifier("b")), true), Optional.empty())));
    assertStatement("SELECT * FROM t FULL JOIN UNNEST(a) AS tmp (c) ON true", simpleQuery(selectList(new AllColumns()), new Join(Join.Type.FULL, new Table(QualifiedName.of("t")), new AliasedRelation(new Unnest(ImmutableList.of(new Identifier("a")), false), new Identifier("tmp"), ImmutableList.of(new Identifier("c"))), Optional.of(new JoinOn(BooleanLiteral.TRUE_LITERAL)))));
}
Also used : CreateTable(io.trino.sql.tree.CreateTable) DropTable(io.trino.sql.tree.DropTable) Table(io.trino.sql.tree.Table) TruncateTable(io.trino.sql.tree.TruncateTable) RenameTable(io.trino.sql.tree.RenameTable) QueryUtil.quotedIdentifier(io.trino.sql.QueryUtil.quotedIdentifier) Identifier(io.trino.sql.tree.Identifier) NaturalJoin(io.trino.sql.tree.NaturalJoin) Join(io.trino.sql.tree.Join) AllColumns(io.trino.sql.tree.AllColumns) Unnest(io.trino.sql.tree.Unnest) JoinOn(io.trino.sql.tree.JoinOn) AliasedRelation(io.trino.sql.tree.AliasedRelation) Test(org.junit.jupiter.api.Test)

Example 9 with AllColumns

use of io.trino.sql.tree.AllColumns in project trino by trinodb.

the class TestSqlParser method testShowStatsForQuery.

@Test
public void testShowStatsForQuery() {
    String[] tableNames = { "t", "s.t", "c.s.t" };
    for (String fullName : tableNames) {
        QualifiedName qualifiedName = makeQualifiedName(fullName);
        // Simple SELECT
        assertStatement(format("SHOW STATS FOR (SELECT * FROM %s)", qualifiedName), createShowStats(qualifiedName, ImmutableList.of(new AllColumns()), Optional.empty()));
        // SELECT with predicate
        assertStatement(format("SHOW STATS FOR (SELECT * FROM %s WHERE field > 0)", qualifiedName), createShowStats(qualifiedName, ImmutableList.of(new AllColumns()), Optional.of(new ComparisonExpression(ComparisonExpression.Operator.GREATER_THAN, new Identifier("field"), new LongLiteral("0")))));
        // SELECT with more complex predicate
        assertStatement(format("SHOW STATS FOR (SELECT * FROM %s WHERE field > 0 or field < 0)", qualifiedName), createShowStats(qualifiedName, ImmutableList.of(new AllColumns()), Optional.of(LogicalExpression.or(new ComparisonExpression(ComparisonExpression.Operator.GREATER_THAN, new Identifier("field"), new LongLiteral("0")), new ComparisonExpression(ComparisonExpression.Operator.LESS_THAN, new Identifier("field"), new LongLiteral("0"))))));
    }
    // SELECT with LIMIT
    assertThat(statement("SHOW STATS FOR (SELECT * FROM t LIMIT 10)")).isEqualTo(new ShowStats(Optional.of(location(1, 1)), new TableSubquery(new Query(location(1, 17), Optional.empty(), new QuerySpecification(location(1, 17), new Select(location(1, 17), false, ImmutableList.of(new AllColumns(location(1, 24), Optional.empty(), ImmutableList.of()))), Optional.of(new Table(location(1, 31), QualifiedName.of(ImmutableList.of(new Identifier(location(1, 31), "t", false))))), Optional.empty(), Optional.empty(), Optional.empty(), ImmutableList.of(), Optional.empty(), Optional.empty(), Optional.of(new Limit(location(1, 33), new LongLiteral(location(1, 39), "10")))), Optional.empty(), Optional.empty(), Optional.empty()))));
    // SELECT with ORDER BY ... LIMIT
    assertThat(statement("SHOW STATS FOR (SELECT * FROM t ORDER BY field LIMIT 10)")).isEqualTo(new ShowStats(Optional.of(location(1, 1)), new TableSubquery(new Query(location(1, 17), Optional.empty(), new QuerySpecification(location(1, 17), new Select(location(1, 17), false, ImmutableList.of(new AllColumns(location(1, 24), Optional.empty(), ImmutableList.of()))), Optional.of(new Table(location(1, 31), QualifiedName.of(ImmutableList.of(new Identifier(location(1, 31), "t", false))))), Optional.empty(), Optional.empty(), Optional.empty(), ImmutableList.of(), Optional.of(new OrderBy(location(1, 33), ImmutableList.of(new SortItem(location(1, 42), new Identifier(location(1, 42), "field", false), ASCENDING, UNDEFINED)))), Optional.empty(), Optional.of(new Limit(location(1, 48), new LongLiteral(location(1, 54), "10")))), Optional.empty(), Optional.empty(), Optional.empty()))));
    // SELECT with WITH
    assertThat(statement("SHOW STATS FOR (\n" + "   WITH t AS (SELECT 1 )\n" + "   SELECT * FROM t)")).isEqualTo(new ShowStats(Optional.of(location(1, 1)), new TableSubquery(new Query(location(2, 4), Optional.of(new With(location(2, 4), false, ImmutableList.of(new WithQuery(location(2, 9), new Identifier(location(2, 9), "t", false), new Query(location(2, 15), Optional.empty(), new QuerySpecification(location(2, 15), new Select(location(2, 15), false, ImmutableList.of(new SingleColumn(location(2, 22), new LongLiteral(location(2, 22), "1"), Optional.empty()))), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), ImmutableList.of(), Optional.empty(), Optional.empty(), Optional.empty()), Optional.empty(), Optional.empty(), Optional.empty()), Optional.empty())))), new QuerySpecification(location(3, 4), new Select(location(3, 4), false, ImmutableList.of(new AllColumns(location(3, 11), Optional.empty(), ImmutableList.of()))), Optional.of(new Table(location(3, 18), QualifiedName.of(ImmutableList.of(new Identifier(location(3, 18), "t", false))))), Optional.empty(), Optional.empty(), Optional.empty(), ImmutableList.of(), Optional.empty(), Optional.empty(), Optional.empty()), Optional.empty(), Optional.empty(), Optional.empty()))));
}
Also used : OrderBy(io.trino.sql.tree.OrderBy) CreateTable(io.trino.sql.tree.CreateTable) DropTable(io.trino.sql.tree.DropTable) Table(io.trino.sql.tree.Table) TruncateTable(io.trino.sql.tree.TruncateTable) RenameTable(io.trino.sql.tree.RenameTable) QueryUtil.simpleQuery(io.trino.sql.QueryUtil.simpleQuery) Query(io.trino.sql.tree.Query) WithQuery(io.trino.sql.tree.WithQuery) LongLiteral(io.trino.sql.tree.LongLiteral) QualifiedName(io.trino.sql.tree.QualifiedName) AllColumns(io.trino.sql.tree.AllColumns) SingleColumn(io.trino.sql.tree.SingleColumn) TableSubquery(io.trino.sql.tree.TableSubquery) With(io.trino.sql.tree.With) QuantifiedComparisonExpression(io.trino.sql.tree.QuantifiedComparisonExpression) ComparisonExpression(io.trino.sql.tree.ComparisonExpression) QuerySpecification(io.trino.sql.tree.QuerySpecification) SortItem(io.trino.sql.tree.SortItem) QueryUtil.quotedIdentifier(io.trino.sql.QueryUtil.quotedIdentifier) Identifier(io.trino.sql.tree.Identifier) ShowStats(io.trino.sql.tree.ShowStats) WithQuery(io.trino.sql.tree.WithQuery) CreateTableAsSelect(io.trino.sql.tree.CreateTableAsSelect) Select(io.trino.sql.tree.Select) Limit(io.trino.sql.tree.Limit) Test(org.junit.jupiter.api.Test)

Example 10 with AllColumns

use of io.trino.sql.tree.AllColumns in project trino by trinodb.

the class TestSqlParser method testSelectWithFetch.

@Test
public void testSelectWithFetch() {
    assertStatement("SELECT * FROM table1 FETCH FIRST 2 ROWS ONLY", simpleQuery(selectList(new AllColumns()), new Table(QualifiedName.of("table1")), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.of(new FetchFirst(new LongLiteral("2")))));
    assertStatement("SELECT * FROM table1 FETCH NEXT ROW ONLY", simpleQuery(selectList(new AllColumns()), new Table(QualifiedName.of("table1")), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.of(new FetchFirst(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')) FETCH FIRST ROW ONLY", simpleQuery(selectList(new AllColumns()), subquery(valuesQuery), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.of(new FetchFirst(Optional.empty()))));
    assertStatement("SELECT * FROM (VALUES (1, '1'), (2, '2')) FETCH FIRST ROW WITH TIES", simpleQuery(selectList(new AllColumns()), subquery(valuesQuery), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.of(new FetchFirst(Optional.empty(), true))));
    assertStatement("SELECT * FROM table1 FETCH FIRST 2 ROWS WITH TIES", simpleQuery(selectList(new AllColumns()), new Table(QualifiedName.of("table1")), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.of(new FetchFirst(new LongLiteral("2"), true))));
    assertStatement("SELECT * FROM table1 FETCH NEXT ROW WITH TIES", simpleQuery(selectList(new AllColumns()), new Table(QualifiedName.of("table1")), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.of(new FetchFirst(Optional.empty(), true))));
}
Also used : CreateTable(io.trino.sql.tree.CreateTable) DropTable(io.trino.sql.tree.DropTable) Table(io.trino.sql.tree.Table) TruncateTable(io.trino.sql.tree.TruncateTable) RenameTable(io.trino.sql.tree.RenameTable) QueryUtil.simpleQuery(io.trino.sql.QueryUtil.simpleQuery) Query(io.trino.sql.tree.Query) WithQuery(io.trino.sql.tree.WithQuery) StringLiteral(io.trino.sql.tree.StringLiteral) LongLiteral(io.trino.sql.tree.LongLiteral) AllColumns(io.trino.sql.tree.AllColumns) FetchFirst(io.trino.sql.tree.FetchFirst) Test(org.junit.jupiter.api.Test)

Aggregations

AllColumns (io.trino.sql.tree.AllColumns)30 Test (org.junit.jupiter.api.Test)19 Query (io.trino.sql.tree.Query)15 QueryUtil.simpleQuery (io.trino.sql.QueryUtil.simpleQuery)14 Table (io.trino.sql.tree.Table)13 CreateTable (io.trino.sql.tree.CreateTable)12 DropTable (io.trino.sql.tree.DropTable)12 RenameTable (io.trino.sql.tree.RenameTable)12 TruncateTable (io.trino.sql.tree.TruncateTable)12 WithQuery (io.trino.sql.tree.WithQuery)11 Identifier (io.trino.sql.tree.Identifier)9 StringLiteral (io.trino.sql.tree.StringLiteral)9 Test (org.testng.annotations.Test)9 LongLiteral (io.trino.sql.tree.LongLiteral)8 QueryUtil.quotedIdentifier (io.trino.sql.QueryUtil.quotedIdentifier)6 CreateMaterializedView (io.trino.sql.tree.CreateMaterializedView)6 FeaturesConfig (io.trino.FeaturesConfig)5 AllowAllAccessControl (io.trino.security.AllowAllAccessControl)5 CreateTableAsSelect (io.trino.sql.tree.CreateTableAsSelect)4 Property (io.trino.sql.tree.Property)4