Search in sources :

Example 6 with Identifier

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()));
}
Also used : OrderBy(io.prestosql.sql.tree.OrderBy) QuerySpecification(io.prestosql.sql.tree.QuerySpecification) SortItem(io.prestosql.sql.tree.SortItem) DereferenceExpression(io.prestosql.sql.tree.DereferenceExpression) Identifier(io.prestosql.sql.tree.Identifier) QueryUtil.quotedIdentifier(io.prestosql.sql.QueryUtil.quotedIdentifier) QueryUtil.simpleQuery(io.prestosql.sql.QueryUtil.simpleQuery) Query(io.prestosql.sql.tree.Query) WithQuery(io.prestosql.sql.tree.WithQuery) FunctionCall(io.prestosql.sql.tree.FunctionCall) Test(org.testng.annotations.Test)

Example 7 with Identifier

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()));
}
Also used : Identifier(io.prestosql.sql.tree.Identifier) QueryUtil.quotedIdentifier(io.prestosql.sql.QueryUtil.quotedIdentifier) StringLiteral(io.prestosql.sql.tree.StringLiteral) LongLiteral(io.prestosql.sql.tree.LongLiteral) CreateSchema(io.prestosql.sql.tree.CreateSchema) Property(io.prestosql.sql.tree.Property) Test(org.testng.annotations.Test)

Example 8 with Identifier

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"))))));
    }
}
Also used : LogicalBinaryExpression(io.prestosql.sql.tree.LogicalBinaryExpression) ComparisonExpression(io.prestosql.sql.tree.ComparisonExpression) QuantifiedComparisonExpression(io.prestosql.sql.tree.QuantifiedComparisonExpression) Identifier(io.prestosql.sql.tree.Identifier) QueryUtil.quotedIdentifier(io.prestosql.sql.QueryUtil.quotedIdentifier) LongLiteral(io.prestosql.sql.tree.LongLiteral) QualifiedName(io.prestosql.sql.tree.QualifiedName) AllColumns(io.prestosql.sql.tree.AllColumns) Test(org.testng.annotations.Test)

Example 9 with Identifier

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));
}
Also used : Identifier(io.prestosql.sql.tree.Identifier) QueryUtil.quotedIdentifier(io.prestosql.sql.QueryUtil.quotedIdentifier) ShowRoles(io.prestosql.sql.tree.ShowRoles) Test(org.testng.annotations.Test)

Example 10 with Identifier

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"))));
}
Also used : SetRole(io.prestosql.sql.tree.SetRole) Identifier(io.prestosql.sql.tree.Identifier) QueryUtil.quotedIdentifier(io.prestosql.sql.QueryUtil.quotedIdentifier) Test(org.testng.annotations.Test)

Aggregations

Identifier (io.prestosql.sql.tree.Identifier)65 Test (org.testng.annotations.Test)34 QueryUtil.quotedIdentifier (io.prestosql.sql.QueryUtil.quotedIdentifier)29 ComparisonExpression (io.prestosql.sql.tree.ComparisonExpression)20 Expression (io.prestosql.sql.tree.Expression)19 StringLiteral (io.prestosql.sql.tree.StringLiteral)17 LongLiteral (io.prestosql.sql.tree.LongLiteral)16 Property (io.prestosql.sql.tree.Property)16 ArrayList (java.util.ArrayList)16 FunctionCall (io.prestosql.sql.tree.FunctionCall)15 CreateTable (io.prestosql.sql.tree.CreateTable)14 QuantifiedComparisonExpression (io.prestosql.sql.tree.QuantifiedComparisonExpression)13 DereferenceExpression (io.prestosql.sql.tree.DereferenceExpression)12 QualifiedName (io.prestosql.sql.tree.QualifiedName)12 LogicalBinaryExpression (io.prestosql.sql.tree.LogicalBinaryExpression)11 Table (io.prestosql.sql.tree.Table)11 ArithmeticBinaryExpression (io.prestosql.sql.tree.ArithmeticBinaryExpression)10 CoalesceExpression (io.prestosql.sql.tree.CoalesceExpression)9 DropTable (io.prestosql.sql.tree.DropTable)9 IfExpression (io.prestosql.sql.tree.IfExpression)9