Search in sources :

Example 11 with AllColumns

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

the class TestSqlParser method testQueryPeriod.

@Test
public void testQueryPeriod() {
    Expression rangeValue = new TimestampLiteral(location(1, 37), "2021-03-01 00:00:01");
    QueryPeriod queryPeriod = new QueryPeriod(location(1, 17), QueryPeriod.RangeType.TIMESTAMP, rangeValue);
    Table table = new Table(location(1, 15), qualifiedName(location(1, 15), "t"), queryPeriod);
    assertThat(statement("SELECT * FROM t FOR TIMESTAMP AS OF TIMESTAMP '2021-03-01 00:00:01'")).isEqualTo(new Query(location(1, 1), Optional.empty(), new QuerySpecification(location(1, 1), new Select(location(1, 1), false, ImmutableList.of(new AllColumns(location(1, 8), Optional.empty(), ImmutableList.of()))), Optional.of(table), Optional.empty(), Optional.empty(), Optional.empty(), ImmutableList.of(), Optional.empty(), Optional.empty(), Optional.empty()), Optional.empty(), Optional.empty(), Optional.empty()));
    rangeValue = new StringLiteral(location(1, 35), "version1");
    queryPeriod = new QueryPeriod(new NodeLocation(1, 17), QueryPeriod.RangeType.VERSION, rangeValue);
    table = new Table(location(1, 15), qualifiedName(location(1, 15), "t"), queryPeriod);
    assertThat(statement("SELECT * FROM t FOR VERSION AS OF 'version1'")).isEqualTo(new Query(location(1, 1), Optional.empty(), new QuerySpecification(location(1, 1), new Select(location(1, 1), false, ImmutableList.of(new AllColumns(location(1, 8), Optional.empty(), ImmutableList.of()))), Optional.of(table), Optional.empty(), Optional.empty(), Optional.empty(), ImmutableList.of(), Optional.empty(), Optional.empty(), Optional.empty()), Optional.empty(), Optional.empty(), Optional.empty()));
}
Also used : QuerySpecification(io.trino.sql.tree.QuerySpecification) 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) TimestampLiteral(io.trino.sql.tree.TimestampLiteral) QueryPeriod(io.trino.sql.tree.QueryPeriod) 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) NodeLocation(io.trino.sql.tree.NodeLocation) DereferenceExpression(io.trino.sql.tree.DereferenceExpression) LogicalExpression(io.trino.sql.tree.LogicalExpression) SearchedCaseExpression(io.trino.sql.tree.SearchedCaseExpression) CoalesceExpression(io.trino.sql.tree.CoalesceExpression) QuantifiedComparisonExpression(io.trino.sql.tree.QuantifiedComparisonExpression) SimpleCaseExpression(io.trino.sql.tree.SimpleCaseExpression) SubqueryExpression(io.trino.sql.tree.SubqueryExpression) LambdaExpression(io.trino.sql.tree.LambdaExpression) SubscriptExpression(io.trino.sql.tree.SubscriptExpression) NullIfExpression(io.trino.sql.tree.NullIfExpression) NotExpression(io.trino.sql.tree.NotExpression) ArithmeticBinaryExpression(io.trino.sql.tree.ArithmeticBinaryExpression) ComparisonExpression(io.trino.sql.tree.ComparisonExpression) IfExpression(io.trino.sql.tree.IfExpression) Expression(io.trino.sql.tree.Expression) CreateTableAsSelect(io.trino.sql.tree.CreateTableAsSelect) Select(io.trino.sql.tree.Select) AllColumns(io.trino.sql.tree.AllColumns) Test(org.junit.jupiter.api.Test)

Example 12 with AllColumns

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

the class TestSqlParser method testSelectWithLimit.

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

Example 13 with AllColumns

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

the class TestSqlParser method testExplain.

@Test
public void testExplain() {
    assertStatement("EXPLAIN SELECT * FROM t", new Explain(simpleQuery(selectList(new AllColumns()), table(QualifiedName.of("t"))), ImmutableList.of()));
    assertStatement("EXPLAIN (TYPE LOGICAL) SELECT * FROM t", new Explain(simpleQuery(selectList(new AllColumns()), table(QualifiedName.of("t"))), ImmutableList.of(new ExplainType(ExplainType.Type.LOGICAL))));
    assertStatement("EXPLAIN (TYPE LOGICAL, FORMAT TEXT) SELECT * FROM t", new Explain(simpleQuery(selectList(new AllColumns()), table(QualifiedName.of("t"))), ImmutableList.of(new ExplainType(ExplainType.Type.LOGICAL), new ExplainFormat(ExplainFormat.Type.TEXT))));
    assertStatementIsInvalid("EXPLAIN VERBOSE SELECT * FROM t").withMessageStartingWith("line 1:9: mismatched input 'VERBOSE'. Expecting: '(', 'ALTER', 'ANALYZE', 'CALL',");
    assertStatementIsInvalid("EXPLAIN VERBOSE (type LOGICAL) SELECT * FROM t").withMessageStartingWith("line 1:9: mismatched input 'VERBOSE'. Expecting: '(', 'ALTER', 'ANALYZE', 'CALL',");
}
Also used : ExplainType(io.trino.sql.tree.ExplainType) ExplainFormat(io.trino.sql.tree.ExplainFormat) Explain(io.trino.sql.tree.Explain) AllColumns(io.trino.sql.tree.AllColumns) Test(org.junit.jupiter.api.Test)

Example 14 with AllColumns

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

the class TestSqlParser method testCreateMaterializedView.

@Test
public void testCreateMaterializedView() {
    Query query = simpleQuery(selectList(new AllColumns()), table(QualifiedName.of("t")));
    Optional<NodeLocation> location = Optional.empty();
    assertStatement("CREATE MATERIALIZED VIEW a AS SELECT * FROM t", new CreateMaterializedView(location, QualifiedName.of("a"), query, false, false, new ArrayList<>(), Optional.empty()));
    Query query2 = simpleQuery(selectList(new AllColumns()), table(QualifiedName.of("catalog2", "schema2", "tab")));
    assertStatement("CREATE OR REPLACE MATERIALIZED VIEW catalog.schema.matview COMMENT 'A simple materialized view'" + " AS SELECT * FROM catalog2.schema2.tab", new CreateMaterializedView(location, QualifiedName.of("catalog", "schema", "matview"), query2, true, false, new ArrayList<>(), Optional.of("A simple materialized view")));
    assertStatement("CREATE OR REPLACE MATERIALIZED VIEW catalog.schema.matview COMMENT 'A simple materialized view'" + " AS SELECT * FROM catalog2.schema2.tab", new CreateMaterializedView(location, QualifiedName.of("catalog", "schema", "matview"), query2, true, false, new ArrayList<>(), Optional.of("A simple materialized view")));
    List<Property> properties = ImmutableList.of(new Property(new Identifier("partitioned_by"), new ArrayConstructor(ImmutableList.of(new StringLiteral("dateint")))));
    assertStatement("CREATE OR REPLACE MATERIALIZED VIEW catalog.schema.matview COMMENT 'A simple materialized view'" + "WITH (partitioned_by = ARRAY ['dateint'])" + " AS SELECT * FROM catalog2.schema2.tab", new CreateMaterializedView(location, QualifiedName.of("catalog", "schema", "matview"), query2, true, false, properties, Optional.of("A simple materialized view")));
    Query query3 = new Query(Optional.of(new With(false, ImmutableList.of(new WithQuery(identifier("a"), simpleQuery(selectList(new AllColumns()), table(QualifiedName.of("x"))), Optional.of(ImmutableList.of(identifier("t"), identifier("u")))), new WithQuery(identifier("b"), simpleQuery(selectList(new AllColumns()), table(QualifiedName.of("a"))), Optional.empty())))), new Table(QualifiedName.of("b")), Optional.empty(), Optional.empty(), Optional.empty());
    assertStatement("CREATE OR REPLACE MATERIALIZED VIEW catalog.schema.matview COMMENT 'A partitioned materialized view' " + "WITH (partitioned_by = ARRAY ['dateint'])" + " AS WITH a (t, u) AS (SELECT * FROM x), b AS (SELECT * FROM a) TABLE b", new CreateMaterializedView(location, QualifiedName.of("catalog", "schema", "matview"), query3, true, false, properties, Optional.of("A partitioned materialized view")));
}
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) ArrayList(java.util.ArrayList) AllColumns(io.trino.sql.tree.AllColumns) With(io.trino.sql.tree.With) CreateMaterializedView(io.trino.sql.tree.CreateMaterializedView) QueryUtil.quotedIdentifier(io.trino.sql.QueryUtil.quotedIdentifier) Identifier(io.trino.sql.tree.Identifier) NodeLocation(io.trino.sql.tree.NodeLocation) StringLiteral(io.trino.sql.tree.StringLiteral) WithQuery(io.trino.sql.tree.WithQuery) ArrayConstructor(io.trino.sql.tree.ArrayConstructor) Property(io.trino.sql.tree.Property) Test(org.junit.jupiter.api.Test)

Example 15 with AllColumns

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

the class TestSqlParser method testValues.

@Test
public void testValues() {
    Query valuesQuery = query(values(row(new StringLiteral("a"), new LongLiteral("1"), new DoubleLiteral("2.2")), row(new StringLiteral("b"), new LongLiteral("2"), new DoubleLiteral("3.3"))));
    assertStatement("VALUES ('a', 1, 2.2e0), ('b', 2, 3.3e0)", valuesQuery);
    assertStatement("SELECT * FROM (VALUES ('a', 1, 2.2e0), ('b', 2, 3.3e0))", simpleQuery(selectList(new AllColumns()), subquery(valuesQuery)));
}
Also used : 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) DoubleLiteral(io.trino.sql.tree.DoubleLiteral) AllColumns(io.trino.sql.tree.AllColumns) 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