use of io.trino.sql.tree.Identifier in project trino by trinodb.
the class TestSqlParser method testLambda.
@Test
public void testLambda() {
assertExpression("() -> x", new LambdaExpression(ImmutableList.of(), new Identifier("x")));
assertExpression("x -> sin(x)", new LambdaExpression(ImmutableList.of(new LambdaArgumentDeclaration(identifier("x"))), new FunctionCall(QualifiedName.of("sin"), ImmutableList.of(new Identifier("x")))));
assertExpression("(x, y) -> mod(x, y)", new LambdaExpression(ImmutableList.of(new LambdaArgumentDeclaration(identifier("x")), new LambdaArgumentDeclaration(identifier("y"))), new FunctionCall(QualifiedName.of("mod"), ImmutableList.of(new Identifier("x"), new Identifier("y")))));
}
use of io.trino.sql.tree.Identifier in project trino by trinodb.
the class TestSqlParser method testSetTimeZone.
@Test
public void testSetTimeZone() {
assertThat(statement("SET TIME ZONE LOCAL")).isEqualTo(new SetTimeZone(location(1, 1), Optional.empty()));
assertThat(statement("SET TIME ZONE 'America/Los_Angeles'")).isEqualTo(new SetTimeZone(location(1, 1), Optional.of(new StringLiteral(location(1, 15), "America/Los_Angeles"))));
assertThat(statement("SET TIME ZONE concat_ws('/', 'America', 'Los_Angeles')")).isEqualTo(new SetTimeZone(location(1, 1), Optional.of(new FunctionCall(location(1, 15), QualifiedName.of(ImmutableList.of(new Identifier(location(1, 15), "concat_ws", false))), ImmutableList.of(new StringLiteral(location(1, 25), "/"), new StringLiteral(location(1, 30), "America"), new StringLiteral(location(1, 41), "Los_Angeles"))))));
assertThat(statement("SET TIME ZONE '-08:00'")).isEqualTo(new SetTimeZone(location(1, 1), Optional.of(new StringLiteral(location(1, 15), "-08:00"))));
assertThat(statement("SET TIME ZONE INTERVAL '10' HOUR")).isEqualTo(new SetTimeZone(location(1, 1), Optional.of(new IntervalLiteral(location(1, 15), "10", Sign.POSITIVE, IntervalField.HOUR, Optional.empty()))));
assertThat(statement("SET TIME ZONE INTERVAL -'08:00' HOUR TO MINUTE")).isEqualTo(new SetTimeZone(location(1, 1), Optional.of(new IntervalLiteral(location(1, 15), "08:00", Sign.NEGATIVE, IntervalField.HOUR, Optional.of(IntervalField.MINUTE)))));
}
use of io.trino.sql.tree.Identifier 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")));
}
use of io.trino.sql.tree.Identifier in project trino by trinodb.
the class TestSqlParser method testGrant.
@Test
public void testGrant() {
assertStatement("GRANT INSERT, DELETE ON t TO u", new Grant(Optional.of(ImmutableList.of("INSERT", "DELETE")), Optional.empty(), QualifiedName.of("t"), new PrincipalSpecification(PrincipalSpecification.Type.UNSPECIFIED, new Identifier("u")), false));
assertStatement("GRANT UPDATE ON t TO u", new Grant(Optional.of(ImmutableList.of("UPDATE")), Optional.empty(), QualifiedName.of("t"), new PrincipalSpecification(PrincipalSpecification.Type.UNSPECIFIED, new Identifier("u")), false));
assertStatement("GRANT SELECT ON t TO ROLE PUBLIC WITH GRANT OPTION", new Grant(Optional.of(ImmutableList.of("SELECT")), Optional.empty(), QualifiedName.of("t"), new PrincipalSpecification(PrincipalSpecification.Type.ROLE, new Identifier("PUBLIC")), true));
assertStatement("GRANT ALL PRIVILEGES ON TABLE t TO USER u", new Grant(Optional.empty(), Optional.of(GrantOnType.TABLE), QualifiedName.of("t"), new PrincipalSpecification(PrincipalSpecification.Type.USER, new Identifier("u")), false));
assertStatement("GRANT DELETE ON \"t\" TO ROLE \"public\" WITH GRANT OPTION", new Grant(Optional.of(ImmutableList.of("DELETE")), Optional.empty(), QualifiedName.of("t"), new PrincipalSpecification(PrincipalSpecification.Type.ROLE, new Identifier("public")), true));
assertStatement("GRANT SELECT ON SCHEMA s TO USER u", new Grant(Optional.of(ImmutableList.of("SELECT")), Optional.of(GrantOnType.SCHEMA), QualifiedName.of("s"), new PrincipalSpecification(PrincipalSpecification.Type.USER, new Identifier("u")), false));
}
use of io.trino.sql.tree.Identifier in project trino by trinodb.
the class TestSqlParser method testAggregationWithOrderBy.
@Test
public void testAggregationWithOrderBy() {
assertExpression("array_agg(x ORDER BY x DESC)", new FunctionCall(Optional.empty(), QualifiedName.of("array_agg"), Optional.empty(), Optional.empty(), Optional.of(new OrderBy(ImmutableList.of(new SortItem(identifier("x"), DESCENDING, UNDEFINED)))), false, Optional.empty(), Optional.empty(), ImmutableList.of(identifier("x"))));
assertStatement("SELECT array_agg(x ORDER BY t.y) FROM t", simpleQuery(selectList(new FunctionCall(Optional.empty(), QualifiedName.of("array_agg"), Optional.empty(), Optional.empty(), Optional.of(new OrderBy(ImmutableList.of(new SortItem(new DereferenceExpression(new Identifier("t"), identifier("y")), ASCENDING, UNDEFINED)))), false, Optional.empty(), Optional.empty(), ImmutableList.of(new Identifier("x")))), table(QualifiedName.of("t"))));
}
Aggregations