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'");
}
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));
}
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)))));
}
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()));
}
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()));
}
Aggregations