Search in sources :

Example 26 with AllColumns

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

the class TestSqlParser method testExplainAnalyze.

@Test
public void testExplainAnalyze() {
    assertStatement("EXPLAIN ANALYZE SELECT * FROM t", new ExplainAnalyze(simpleQuery(selectList(new AllColumns()), table(QualifiedName.of("t"))), false));
    assertStatement("EXPLAIN ANALYZE VERBOSE SELECT * FROM t", new ExplainAnalyze(simpleQuery(selectList(new AllColumns()), table(QualifiedName.of("t"))), true));
    assertStatementIsInvalid("EXPLAIN ANALYZE (type DISTRIBUTED) SELECT * FROM t").withMessage("line 1:18: mismatched input 'type'. Expecting: '(', 'SELECT', 'TABLE', 'VALUES'");
    assertStatementIsInvalid("EXPLAIN ANALYZE VERBOSE (type DISTRIBUTED) SELECT * FROM t").withMessage("line 1:26: mismatched input 'type'. Expecting: '(', 'SELECT', 'TABLE', 'VALUES'");
}
Also used : ExplainAnalyze(io.trino.sql.tree.ExplainAnalyze) AllColumns(io.trino.sql.tree.AllColumns) Test(org.junit.jupiter.api.Test)

Example 27 with AllColumns

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

the class TestSqlParser method testInsertInto.

@Test
public void testInsertInto() {
    Table table = new Table(QualifiedName.of("a", "b/c", "d"));
    Query query = simpleQuery(selectList(new AllColumns()), table(QualifiedName.of("t")));
    assertStatement("INSERT INTO a.\"b/c\".d SELECT * FROM t", new Insert(table, Optional.empty(), query));
    assertStatement("INSERT INTO a.\"b/c\".d (c1, c2) SELECT * FROM t", new Insert(table, Optional.of(ImmutableList.of(identifier("c1"), identifier("c2"))), query));
}
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) AllColumns(io.trino.sql.tree.AllColumns) Insert(io.trino.sql.tree.Insert) MergeInsert(io.trino.sql.tree.MergeInsert) Test(org.junit.jupiter.api.Test)

Example 28 with AllColumns

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

the class TestSqlParser method testPrepareWithParameters.

@Test
public void testPrepareWithParameters() {
    assertStatement("PREPARE myquery FROM SELECT ?, ? FROM foo", new Prepare(identifier("myquery"), simpleQuery(selectList(new Parameter(0), new Parameter(1)), table(QualifiedName.of("foo")))));
    assertStatement("PREPARE myquery FROM SELECT * FROM foo LIMIT ?", new Prepare(identifier("myquery"), simpleQuery(selectList(new AllColumns()), table(QualifiedName.of("foo")), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.of(new Limit(new Parameter(0))))));
    assertStatement("PREPARE myquery FROM SELECT ?, ? FROM foo LIMIT ?", new Prepare(identifier("myquery"), simpleQuery(selectList(new Parameter(0), new Parameter(1)), table(QualifiedName.of("foo")), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.of(new Limit(new Parameter(2))))));
    assertStatement("PREPARE myquery FROM SELECT ? FROM foo FETCH FIRST ? ROWS ONLY", new Prepare(identifier("myquery"), simpleQuery(selectList(new Parameter(0)), table(QualifiedName.of("foo")), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.of(new FetchFirst(new Parameter(1))))));
    assertStatement("PREPARE myquery FROM SELECT ?, ? FROM foo FETCH NEXT ? ROWS WITH TIES", new Prepare(identifier("myquery"), simpleQuery(selectList(new Parameter(0), new Parameter(1)), table(QualifiedName.of("foo")), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.of(new FetchFirst(new Parameter(2), true)))));
    assertStatement("PREPARE myquery FROM SELECT ?, ? FROM foo OFFSET ? ROWS", new Prepare(identifier("myquery"), simpleQuery(selectList(new Parameter(0), new Parameter(1)), table(QualifiedName.of("foo")), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.of(new Offset(new Parameter(2))), Optional.empty())));
    assertStatement("PREPARE myquery FROM SELECT ? FROM foo OFFSET ? ROWS LIMIT ?", new Prepare(identifier("myquery"), simpleQuery(selectList(new Parameter(0)), table(QualifiedName.of("foo")), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.of(new Offset(new Parameter(1))), Optional.of(new Limit(new Parameter(2))))));
    assertStatement("PREPARE myquery FROM SELECT ? FROM foo OFFSET ? ROWS FETCH FIRST ? ROWS WITH TIES", new Prepare(identifier("myquery"), simpleQuery(selectList(new Parameter(0)), table(QualifiedName.of("foo")), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.of(new Offset(new Parameter(1))), Optional.of(new FetchFirst(new Parameter(2), true)))));
}
Also used : Prepare(io.trino.sql.tree.Prepare) Parameter(io.trino.sql.tree.Parameter) AllColumns(io.trino.sql.tree.AllColumns) Limit(io.trino.sql.tree.Limit) FetchFirst(io.trino.sql.tree.FetchFirst) Offset(io.trino.sql.tree.Offset) Test(org.junit.jupiter.api.Test)

Example 29 with AllColumns

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

the class TestSqlParser method testSelectWithOffset.

@Test
public void testSelectWithOffset() {
    assertStatement("SELECT * FROM table1 OFFSET 2 ROWS", simpleQuery(selectList(new AllColumns()), new Table(QualifiedName.of("table1")), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.of(new Offset(new LongLiteral("2"))), Optional.empty()));
    assertStatement("SELECT * FROM table1 OFFSET 2", simpleQuery(selectList(new AllColumns()), new Table(QualifiedName.of("table1")), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.of(new Offset(new LongLiteral("2"))), 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(new LongLiteral("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(new LongLiteral("2"))), Optional.empty()));
}
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) Offset(io.trino.sql.tree.Offset) Test(org.junit.jupiter.api.Test)

Example 30 with AllColumns

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

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(), Optional.empty()));
    assertStatement("CREATE OR REPLACE VIEW a AS SELECT * FROM t", new CreateView(QualifiedName.of("a"), query, true, Optional.empty(), Optional.empty()));
    assertStatement("CREATE VIEW a SECURITY DEFINER AS SELECT * FROM t", new CreateView(QualifiedName.of("a"), query, false, Optional.empty(), Optional.of(CreateView.Security.DEFINER)));
    assertStatement("CREATE VIEW a SECURITY INVOKER AS SELECT * FROM t", new CreateView(QualifiedName.of("a"), query, false, Optional.empty(), Optional.of(CreateView.Security.INVOKER)));
    assertStatement("CREATE VIEW a COMMENT 'comment' SECURITY DEFINER AS SELECT * FROM t", new CreateView(QualifiedName.of("a"), query, false, Optional.of("comment"), Optional.of(CreateView.Security.DEFINER)));
    assertStatement("CREATE VIEW a COMMENT '' SECURITY INVOKER AS SELECT * FROM t", new CreateView(QualifiedName.of("a"), query, false, Optional.of(""), Optional.of(CreateView.Security.INVOKER)));
    assertStatement("CREATE VIEW a COMMENT 'comment' AS SELECT * FROM t", new CreateView(QualifiedName.of("a"), query, false, Optional.of("comment"), Optional.empty()));
    assertStatement("CREATE VIEW a COMMENT '' AS SELECT * FROM t", new CreateView(QualifiedName.of("a"), query, false, Optional.of(""), Optional.empty()));
    assertStatement("CREATE VIEW bar.foo AS SELECT * FROM t", new CreateView(QualifiedName.of("bar", "foo"), query, false, Optional.empty(), Optional.empty()));
    assertStatement("CREATE VIEW \"awesome view\" AS SELECT * FROM t", new CreateView(QualifiedName.of("awesome view"), query, false, Optional.empty(), 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(), Optional.empty()));
}
Also used : QueryUtil.simpleQuery(io.trino.sql.QueryUtil.simpleQuery) Query(io.trino.sql.tree.Query) WithQuery(io.trino.sql.tree.WithQuery) AllColumns(io.trino.sql.tree.AllColumns) CreateView(io.trino.sql.tree.CreateView) 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