Search in sources :

Example 6 with AllColumns

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"));
}
Also used : Query(com.facebook.presto.sql.tree.Query) QueryUtil.simpleQuery(com.facebook.presto.sql.QueryUtil.simpleQuery) AllColumns(com.facebook.presto.sql.tree.AllColumns) Session(com.facebook.presto.Session) Test(org.testng.annotations.Test)

Example 7 with AllColumns

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"))));
}
Also used : SqlQueryManager.unwrapExecuteStatement(com.facebook.presto.execution.SqlQueryManager.unwrapExecuteStatement) Statement(com.facebook.presto.sql.tree.Statement) AllColumns(com.facebook.presto.sql.tree.AllColumns) Session(com.facebook.presto.Session) Test(org.testng.annotations.Test)

Example 8 with AllColumns

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()));
}
Also used : GroupingSets(com.facebook.presto.sql.tree.GroupingSets) QuerySpecification(com.facebook.presto.sql.tree.QuerySpecification) SimpleGroupBy(com.facebook.presto.sql.tree.SimpleGroupBy) CreateTable(com.facebook.presto.sql.tree.CreateTable) DropTable(com.facebook.presto.sql.tree.DropTable) Table(com.facebook.presto.sql.tree.Table) RenameTable(com.facebook.presto.sql.tree.RenameTable) SimpleGroupBy(com.facebook.presto.sql.tree.SimpleGroupBy) GroupBy(com.facebook.presto.sql.tree.GroupBy) Identifier(com.facebook.presto.sql.tree.Identifier) Query(com.facebook.presto.sql.tree.Query) QueryUtil.simpleQuery(com.facebook.presto.sql.QueryUtil.simpleQuery) WithQuery(com.facebook.presto.sql.tree.WithQuery) Rollup(com.facebook.presto.sql.tree.Rollup) Cube(com.facebook.presto.sql.tree.Cube) AllColumns(com.facebook.presto.sql.tree.AllColumns) Test(org.testng.annotations.Test)

Example 9 with AllColumns

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));
}
Also used : Query(com.facebook.presto.sql.tree.Query) QueryUtil.simpleQuery(com.facebook.presto.sql.QueryUtil.simpleQuery) WithQuery(com.facebook.presto.sql.tree.WithQuery) QualifiedName(com.facebook.presto.sql.tree.QualifiedName) AllColumns(com.facebook.presto.sql.tree.AllColumns) Insert(com.facebook.presto.sql.tree.Insert) Test(org.testng.annotations.Test)

Example 10 with AllColumns

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")));
}
Also used : Query(com.facebook.presto.sql.tree.Query) QueryUtil.simpleQuery(com.facebook.presto.sql.QueryUtil.simpleQuery) WithQuery(com.facebook.presto.sql.tree.WithQuery) StringLiteral(com.facebook.presto.sql.tree.StringLiteral) LongLiteral(com.facebook.presto.sql.tree.LongLiteral) AllColumns(com.facebook.presto.sql.tree.AllColumns) Test(org.testng.annotations.Test)

Aggregations

AllColumns (com.facebook.presto.sql.tree.AllColumns)15 Test (org.testng.annotations.Test)14 Query (com.facebook.presto.sql.tree.Query)9 QueryUtil.simpleQuery (com.facebook.presto.sql.QueryUtil.simpleQuery)8 WithQuery (com.facebook.presto.sql.tree.WithQuery)6 Table (com.facebook.presto.sql.tree.Table)5 CreateTable (com.facebook.presto.sql.tree.CreateTable)4 DropTable (com.facebook.presto.sql.tree.DropTable)4 LongLiteral (com.facebook.presto.sql.tree.LongLiteral)4 RenameTable (com.facebook.presto.sql.tree.RenameTable)4 StringLiteral (com.facebook.presto.sql.tree.StringLiteral)4 Identifier (com.facebook.presto.sql.tree.Identifier)3 QualifiedName (com.facebook.presto.sql.tree.QualifiedName)3 Session (com.facebook.presto.Session)2 SqlQueryManager.unwrapExecuteStatement (com.facebook.presto.execution.SqlQueryManager.unwrapExecuteStatement)2 ArithmeticBinaryExpression (com.facebook.presto.sql.tree.ArithmeticBinaryExpression)2 ComparisonExpression (com.facebook.presto.sql.tree.ComparisonExpression)2 Cube (com.facebook.presto.sql.tree.Cube)2 DereferenceExpression (com.facebook.presto.sql.tree.DereferenceExpression)2 Expression (com.facebook.presto.sql.tree.Expression)2