use of io.prestosql.sql.tree.Identifier in project hetu-core by openlookeng.
the class TestSqlParser method testAggregationWithOrderBy.
@Test
public void testAggregationWithOrderBy() {
assertExpression("array_agg(x ORDER BY x DESC)", new FunctionCall(QualifiedName.of("array_agg"), Optional.empty(), Optional.empty(), Optional.of(new OrderBy(ImmutableList.of(new SortItem(identifier("x"), DESCENDING, UNDEFINED)))), false, ImmutableList.of(identifier("x"))));
assertStatement("SELECT array_agg(x ORDER BY t.y) FROM t", new Query(Optional.empty(), new QuerySpecification(selectList(new FunctionCall(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, ImmutableList.of(new Identifier("x")))), Optional.of(table(QualifiedName.of("t"))), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty()), Optional.empty(), Optional.empty(), Optional.empty()));
}
use of io.prestosql.sql.tree.Identifier in project hetu-core by openlookeng.
the class TestSqlParser method testCreateSchema.
@Test
public void testCreateSchema() {
assertStatement("CREATE SCHEMA test", new CreateSchema(QualifiedName.of("test"), false, ImmutableList.of()));
assertStatement("CREATE SCHEMA IF NOT EXISTS test", new CreateSchema(QualifiedName.of("test"), true, ImmutableList.of()));
assertStatement("CREATE SCHEMA test WITH (a = 'apple', b = 123)", new CreateSchema(QualifiedName.of("test"), false, ImmutableList.of(new Property(new Identifier("a"), new StringLiteral("apple")), new Property(new Identifier("b"), new LongLiteral("123")))));
assertStatement("CREATE SCHEMA \"some name that contains space\"", new CreateSchema(QualifiedName.of("some name that contains space"), false, ImmutableList.of()));
}
use of io.prestosql.sql.tree.Identifier in project hetu-core by openlookeng.
the class TestSqlParser method testShowStatsForQuery.
@Test
public void testShowStatsForQuery() {
final String[] tableNames = { "t", "s.t", "c.s.t" };
for (String fullName : tableNames) {
QualifiedName qualifiedName = makeQualifiedName(fullName);
assertStatement(format("SHOW STATS FOR (SELECT * FROM %s)", qualifiedName), createShowStats(qualifiedName, ImmutableList.of(new AllColumns()), Optional.empty()));
assertStatement(format("SHOW STATS FOR (SELECT * FROM %s WHERE field > 0)", qualifiedName), createShowStats(qualifiedName, ImmutableList.of(new AllColumns()), Optional.of(new ComparisonExpression(GREATER_THAN, new Identifier("field"), new LongLiteral("0")))));
assertStatement(format("SHOW STATS FOR (SELECT * FROM %s WHERE field > 0 or field < 0)", qualifiedName), createShowStats(qualifiedName, ImmutableList.of(new AllColumns()), Optional.of(new LogicalBinaryExpression(LogicalBinaryExpression.Operator.OR, new ComparisonExpression(GREATER_THAN, new Identifier("field"), new LongLiteral("0")), new ComparisonExpression(LESS_THAN, new Identifier("field"), new LongLiteral("0"))))));
}
}
use of io.prestosql.sql.tree.Identifier in project hetu-core by openlookeng.
the class TestSqlParser method testShowRoles.
@Test
public void testShowRoles() {
assertStatement("SHOW ROLES", new ShowRoles(Optional.empty(), false));
assertStatement("SHOW ROLES FROM foo", new ShowRoles(Optional.of(new Identifier("foo")), false));
assertStatement("SHOW ROLES IN foo", new ShowRoles(Optional.of(new Identifier("foo")), false));
assertStatement("SHOW CURRENT ROLES", new ShowRoles(Optional.empty(), true));
assertStatement("SHOW CURRENT ROLES FROM foo", new ShowRoles(Optional.of(new Identifier("foo")), true));
assertStatement("SHOW CURRENT ROLES IN foo", new ShowRoles(Optional.of(new Identifier("foo")), true));
}
use of io.prestosql.sql.tree.Identifier in project hetu-core by openlookeng.
the class TestSqlParser method testSetRole.
@Test
public void testSetRole() {
assertStatement("SET ROLE ALL", new SetRole(SetRole.Type.ALL, Optional.empty()));
assertStatement("SET ROLE NONE", new SetRole(SetRole.Type.NONE, Optional.empty()));
assertStatement("SET ROLE role", new SetRole(SetRole.Type.ROLE, Optional.of(new Identifier("role"))));
assertStatement("SET ROLE \"role\"", new SetRole(SetRole.Type.ROLE, Optional.of(new Identifier("role"))));
}
Aggregations