Search in sources :

Example 11 with Identifier

use of com.facebook.presto.sql.tree.Identifier in project presto by prestodb.

the class TestSqlParser method testSetRole.

@Test
public void testSetRole() throws Exception {
    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(com.facebook.presto.sql.tree.SetRole) Identifier(com.facebook.presto.sql.tree.Identifier) QueryUtil.quotedIdentifier(com.facebook.presto.sql.QueryUtil.quotedIdentifier) Test(org.testng.annotations.Test)

Example 12 with Identifier

use of com.facebook.presto.sql.tree.Identifier in project presto by prestodb.

the class TestSqlParser method testCreateTable.

@Test
public void testCreateTable() {
    assertStatement("CREATE TABLE foo (a VARCHAR, b BIGINT COMMENT 'hello world', c IPADDRESS)", new CreateTable(QualifiedName.of("foo"), ImmutableList.of(new ColumnDefinition(identifier("a"), "VARCHAR", true, emptyList(), Optional.empty()), new ColumnDefinition(identifier("b"), "BIGINT", true, emptyList(), Optional.of("hello world")), new ColumnDefinition(identifier("c"), "IPADDRESS", true, emptyList(), Optional.empty())), false, ImmutableList.of(), Optional.empty()));
    assertStatement("CREATE TABLE IF NOT EXISTS bar (c TIMESTAMP)", new CreateTable(QualifiedName.of("bar"), ImmutableList.of(new ColumnDefinition(identifier("c"), "TIMESTAMP", true, emptyList(), Optional.empty())), true, ImmutableList.of(), Optional.empty()));
    // with properties
    assertStatement("CREATE TABLE IF NOT EXISTS bar (c TIMESTAMP WITH (nullable = true, compression = 'LZ4'))", new CreateTable(QualifiedName.of("bar"), ImmutableList.of(new ColumnDefinition(identifier("c"), "TIMESTAMP", true, ImmutableList.of(new Property(new Identifier("nullable"), BooleanLiteral.TRUE_LITERAL), new Property(new Identifier("compression"), new StringLiteral("LZ4"))), Optional.empty())), true, ImmutableList.of(), Optional.empty()));
    // with LIKE
    assertStatement("CREATE TABLE IF NOT EXISTS bar (LIKE like_table)", new CreateTable(QualifiedName.of("bar"), ImmutableList.of(new LikeClause(QualifiedName.of("like_table"), Optional.empty())), true, ImmutableList.of(), Optional.empty()));
    assertStatement("CREATE TABLE IF NOT EXISTS bar (c TIMESTAMP, LIKE like_table)", new CreateTable(QualifiedName.of("bar"), ImmutableList.of(new ColumnDefinition(identifier("c"), "TIMESTAMP", true, emptyList(), Optional.empty()), new LikeClause(QualifiedName.of("like_table"), Optional.empty())), true, ImmutableList.of(), Optional.empty()));
    assertStatement("CREATE TABLE IF NOT EXISTS bar (c TIMESTAMP, LIKE like_table, d DATE)", new CreateTable(QualifiedName.of("bar"), ImmutableList.of(new ColumnDefinition(identifier("c"), "TIMESTAMP", true, emptyList(), Optional.empty()), new LikeClause(QualifiedName.of("like_table"), Optional.empty()), new ColumnDefinition(identifier("d"), "DATE", true, emptyList(), Optional.empty())), true, ImmutableList.of(), Optional.empty()));
    assertStatement("CREATE TABLE IF NOT EXISTS bar (LIKE like_table INCLUDING PROPERTIES)", new CreateTable(QualifiedName.of("bar"), ImmutableList.of(new LikeClause(QualifiedName.of("like_table"), Optional.of(LikeClause.PropertiesOption.INCLUDING))), true, ImmutableList.of(), Optional.empty()));
    assertStatement("CREATE TABLE IF NOT EXISTS bar (c TIMESTAMP, LIKE like_table EXCLUDING PROPERTIES)", new CreateTable(QualifiedName.of("bar"), ImmutableList.of(new ColumnDefinition(identifier("c"), "TIMESTAMP", true, emptyList(), Optional.empty()), new LikeClause(QualifiedName.of("like_table"), Optional.of(LikeClause.PropertiesOption.EXCLUDING))), true, ImmutableList.of(), Optional.empty()));
    assertStatement("CREATE TABLE IF NOT EXISTS bar (c TIMESTAMP, LIKE like_table EXCLUDING PROPERTIES) COMMENT 'test'", new CreateTable(QualifiedName.of("bar"), ImmutableList.of(new ColumnDefinition(identifier("c"), "TIMESTAMP", true, emptyList(), Optional.empty()), new LikeClause(QualifiedName.of("like_table"), Optional.of(LikeClause.PropertiesOption.EXCLUDING))), true, ImmutableList.of(), Optional.of("test")));
}
Also used : LikeClause(com.facebook.presto.sql.tree.LikeClause) Identifier(com.facebook.presto.sql.tree.Identifier) QueryUtil.quotedIdentifier(com.facebook.presto.sql.QueryUtil.quotedIdentifier) StringLiteral(com.facebook.presto.sql.tree.StringLiteral) CreateTable(com.facebook.presto.sql.tree.CreateTable) Property(com.facebook.presto.sql.tree.Property) ColumnDefinition(com.facebook.presto.sql.tree.ColumnDefinition) Test(org.testng.annotations.Test)

Example 13 with Identifier

use of com.facebook.presto.sql.tree.Identifier in project presto by prestodb.

the class TestSqlParser method testShowRoles.

@Test
public void testShowRoles() throws Exception {
    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(com.facebook.presto.sql.tree.Identifier) QueryUtil.quotedIdentifier(com.facebook.presto.sql.QueryUtil.quotedIdentifier) ShowRoles(com.facebook.presto.sql.tree.ShowRoles) Test(org.testng.annotations.Test)

Example 14 with Identifier

use of com.facebook.presto.sql.tree.Identifier in project presto by prestodb.

the class TestSqlParser method testRevokeRoles.

@Test
public void testRevokeRoles() throws Exception {
    assertStatement("REVOKE role1 FROM user1", new RevokeRoles(ImmutableSet.of(new Identifier("role1")), ImmutableSet.of(new PrincipalSpecification(PrincipalSpecification.Type.UNSPECIFIED, new Identifier("user1"))), false, Optional.empty()));
    assertStatement("REVOKE ADMIN OPTION FOR role1, role2, role3 FROM user1, USER user2, ROLE role4", new RevokeRoles(ImmutableSet.of(new Identifier("role1"), new Identifier("role2"), new Identifier("role3")), ImmutableSet.of(new PrincipalSpecification(PrincipalSpecification.Type.UNSPECIFIED, new Identifier("user1")), new PrincipalSpecification(PrincipalSpecification.Type.USER, new Identifier("user2")), new PrincipalSpecification(PrincipalSpecification.Type.ROLE, new Identifier("role4"))), true, Optional.empty()));
    assertStatement("REVOKE ADMIN OPTION FOR role1 FROM user1 GRANTED BY admin", new RevokeRoles(ImmutableSet.of(new Identifier("role1")), ImmutableSet.of(new PrincipalSpecification(PrincipalSpecification.Type.UNSPECIFIED, new Identifier("user1"))), true, Optional.of(new GrantorSpecification(GrantorSpecification.Type.PRINCIPAL, Optional.of(new PrincipalSpecification(PrincipalSpecification.Type.UNSPECIFIED, new Identifier("admin")))))));
    assertStatement("REVOKE ADMIN OPTION FOR role1 FROM USER user1 GRANTED BY USER admin", new RevokeRoles(ImmutableSet.of(new Identifier("role1")), ImmutableSet.of(new PrincipalSpecification(PrincipalSpecification.Type.USER, new Identifier("user1"))), true, Optional.of(new GrantorSpecification(GrantorSpecification.Type.PRINCIPAL, Optional.of(new PrincipalSpecification(PrincipalSpecification.Type.USER, new Identifier("admin")))))));
    assertStatement("REVOKE role1 FROM ROLE role2 GRANTED BY ROLE admin", new RevokeRoles(ImmutableSet.of(new Identifier("role1")), ImmutableSet.of(new PrincipalSpecification(PrincipalSpecification.Type.ROLE, new Identifier("role2"))), false, Optional.of(new GrantorSpecification(GrantorSpecification.Type.PRINCIPAL, Optional.of(new PrincipalSpecification(PrincipalSpecification.Type.ROLE, new Identifier("admin")))))));
    assertStatement("REVOKE \"role1\" FROM ROLE \"role2\" GRANTED BY ROLE \"admin\"", new RevokeRoles(ImmutableSet.of(new Identifier("role1")), ImmutableSet.of(new PrincipalSpecification(PrincipalSpecification.Type.ROLE, new Identifier("role2"))), false, Optional.of(new GrantorSpecification(GrantorSpecification.Type.PRINCIPAL, Optional.of(new PrincipalSpecification(PrincipalSpecification.Type.ROLE, new Identifier("admin")))))));
}
Also used : RevokeRoles(com.facebook.presto.sql.tree.RevokeRoles) Identifier(com.facebook.presto.sql.tree.Identifier) QueryUtil.quotedIdentifier(com.facebook.presto.sql.QueryUtil.quotedIdentifier) PrincipalSpecification(com.facebook.presto.sql.tree.PrincipalSpecification) GrantorSpecification(com.facebook.presto.sql.tree.GrantorSpecification) Test(org.testng.annotations.Test)

Example 15 with Identifier

use of com.facebook.presto.sql.tree.Identifier in project presto by prestodb.

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(com.facebook.presto.sql.tree.LogicalBinaryExpression) QuantifiedComparisonExpression(com.facebook.presto.sql.tree.QuantifiedComparisonExpression) ComparisonExpression(com.facebook.presto.sql.tree.ComparisonExpression) Identifier(com.facebook.presto.sql.tree.Identifier) QueryUtil.quotedIdentifier(com.facebook.presto.sql.QueryUtil.quotedIdentifier) LongLiteral(com.facebook.presto.sql.tree.LongLiteral) QualifiedName(com.facebook.presto.sql.tree.QualifiedName) AllColumns(com.facebook.presto.sql.tree.AllColumns) Test(org.testng.annotations.Test)

Aggregations

Identifier (com.facebook.presto.sql.tree.Identifier)46 Test (org.testng.annotations.Test)31 QueryUtil.quotedIdentifier (com.facebook.presto.sql.QueryUtil.quotedIdentifier)27 LongLiteral (com.facebook.presto.sql.tree.LongLiteral)15 Query (com.facebook.presto.sql.tree.Query)11 FunctionCall (com.facebook.presto.sql.tree.FunctionCall)10 AllColumns (com.facebook.presto.sql.tree.AllColumns)9 DropTable (com.facebook.presto.sql.tree.DropTable)9 QualifiedName (com.facebook.presto.sql.tree.QualifiedName)9 QuerySpecification (com.facebook.presto.sql.tree.QuerySpecification)9 Table (com.facebook.presto.sql.tree.Table)9 ComparisonExpression (com.facebook.presto.sql.tree.ComparisonExpression)8 CreateTable (com.facebook.presto.sql.tree.CreateTable)8 Expression (com.facebook.presto.sql.tree.Expression)8 QueryUtil.simpleQuery (com.facebook.presto.sql.QueryUtil.simpleQuery)7 SingleColumn (com.facebook.presto.sql.tree.SingleColumn)7 StringLiteral (com.facebook.presto.sql.tree.StringLiteral)7 WithQuery (com.facebook.presto.sql.tree.WithQuery)7 CreateTableAsSelect (com.facebook.presto.sql.tree.CreateTableAsSelect)6 DereferenceExpression (com.facebook.presto.sql.tree.DereferenceExpression)6