use of com.facebook.presto.sql.tree.AllColumns in project presto by prestodb.
the class TestPrepareTask method testPrepareNameExists.
@Test
public void testPrepareNameExists() {
Session session = testSessionBuilder().addPreparedStatement("my_query", "SELECT bar, baz from foo").build();
Query query = simpleQuery(selectList(new AllColumns()), table(QualifiedName.of("foo")));
String sqlString = "PREPARE my_query FROM SELECT * FROM foo";
Map<String, String> statements = executePrepare("my_query", query, sqlString, session);
assertEquals(statements, ImmutableMap.of("my_query", "SELECT *\nFROM\n foo\n"));
}
use of com.facebook.presto.sql.tree.AllColumns in project presto by prestodb.
the class TestUnwrapExecute method testExecuteStatement.
@Test
public void testExecuteStatement() throws Exception {
Session session = testSessionBuilder().addPreparedStatement("my_query", "SELECT * FROM foo").build();
Statement statement = SQL_PARSER.createStatement("EXECUTE my_query");
assertEquals(unwrapExecuteStatement(statement, SQL_PARSER, session), simpleQuery(selectList(new AllColumns()), table(QualifiedName.of("foo"))));
}
use of com.facebook.presto.sql.tree.AllColumns in project presto by prestodb.
the class TestSqlParser method testSelectWithGroupBy.
@Test
public void testSelectWithGroupBy() throws Exception {
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()));
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()));
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()));
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(QualifiedName.of("a"))))))), 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(QualifiedName.of("a"), QualifiedName.of("b")), ImmutableList.of(QualifiedName.of("a")), ImmutableList.of())), new Cube(ImmutableList.of(QualifiedName.of("c"))), new Rollup(ImmutableList.of(QualifiedName.of("d")))))), 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(QualifiedName.of("a"), QualifiedName.of("b")), ImmutableList.of(QualifiedName.of("a")), ImmutableList.of())), new Cube(ImmutableList.of(QualifiedName.of("c"))), new Rollup(ImmutableList.of(QualifiedName.of("d")))))), Optional.empty(), Optional.empty(), Optional.empty()), Optional.empty(), Optional.empty()));
}
use of com.facebook.presto.sql.tree.AllColumns in project presto by prestodb.
the class TestSqlParser method testInsertInto.
@Test
public void testInsertInto() throws Exception {
QualifiedName table = QualifiedName.of("a");
Query query = simpleQuery(selectList(new AllColumns()), table(QualifiedName.of("t")));
assertStatement("INSERT INTO a SELECT * FROM t", new Insert(table, Optional.empty(), query));
assertStatement("INSERT INTO a (c1, c2) SELECT * FROM t", new Insert(table, Optional.of(ImmutableList.of("c1", "c2")), query));
}
use of com.facebook.presto.sql.tree.AllColumns in project presto by prestodb.
the class TestSqlParser method testLimitAll.
@Test
public void testLimitAll() {
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.of("ALL")));
}
Aggregations