Search in sources :

Example 11 with Identifier

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

the class TestCreateTableTask method testCreateWithNotNullColumns.

@Test
public void testCreateWithNotNullColumns() {
    metadata.setConnectorCapabilities(NOT_NULL_COLUMN_CONSTRAINT);
    List<TableElement> inputColumns = ImmutableList.of(new ColumnDefinition(identifier("a"), toSqlType(DATE), true, emptyList(), Optional.empty()), new ColumnDefinition(identifier("b"), toSqlType(VARCHAR), false, emptyList(), Optional.empty()), new ColumnDefinition(identifier("c"), toSqlType(VARBINARY), false, emptyList(), Optional.empty()));
    CreateTable statement = new CreateTable(QualifiedName.of("test_table"), inputColumns, true, ImmutableList.of(), Optional.empty());
    CreateTableTask createTableTask = new CreateTableTask(plannerContext, new AllowAllAccessControl(), columnPropertyManager, tablePropertyManager);
    getFutureValue(createTableTask.internalExecute(statement, testSession, emptyList(), output -> {
    }));
    assertEquals(metadata.getCreateTableCallCount(), 1);
    List<ColumnMetadata> columns = metadata.getReceivedTableMetadata().get(0).getColumns();
    assertEquals(columns.size(), 3);
    assertEquals(columns.get(0).getName(), "a");
    assertEquals(columns.get(0).getType().getDisplayName().toUpperCase(ENGLISH), "DATE");
    assertTrue(columns.get(0).isNullable());
    assertEquals(columns.get(1).getName(), "b");
    assertEquals(columns.get(1).getType().getDisplayName().toUpperCase(ENGLISH), "VARCHAR");
    assertFalse(columns.get(1).isNullable());
    assertEquals(columns.get(2).getName(), "c");
    assertEquals(columns.get(2).getType().getDisplayName().toUpperCase(ENGLISH), "VARBINARY");
    assertFalse(columns.get(2).isNullable());
}
Also used : TransactionManager(io.trino.transaction.TransactionManager) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Test(org.testng.annotations.Test) TestingTableHandle(io.trino.testing.TestingMetadata.TestingTableHandle) AfterMethod(org.testng.annotations.AfterMethod) SHOW_CREATE_TABLE(io.trino.testing.TestingAccessControlManager.TestingPrivilegeType.SHOW_CREATE_TABLE) TrinoExceptionAssert.assertTrinoExceptionThrownBy(io.trino.testing.assertions.TrinoExceptionAssert.assertTrinoExceptionThrownBy) TestingConnectorTransactionHandle(io.trino.sql.planner.TestingConnectorTransactionHandle) NOT_SUPPORTED(io.trino.spi.StandardErrorCode.NOT_SUPPORTED) CatalogName(io.trino.connector.CatalogName) MockConnectorFactory(io.trino.connector.MockConnectorFactory) Map(java.util.Map) TEST_SESSION(io.trino.SessionTestUtils.TEST_SESSION) ALREADY_EXISTS(io.trino.spi.StandardErrorCode.ALREADY_EXISTS) TestingAccessControlManager(io.trino.testing.TestingAccessControlManager) Property(io.trino.sql.tree.Property) ENGLISH(java.util.Locale.ENGLISH) Assert.assertFalse(org.testng.Assert.assertFalse) Identifier(io.trino.sql.tree.Identifier) SMALLINT(io.trino.spi.type.SmallintType.SMALLINT) TableElement(io.trino.sql.tree.TableElement) ImmutableMap(com.google.common.collect.ImmutableMap) INCLUDING(io.trino.sql.tree.LikeClause.PropertiesOption.INCLUDING) Collections.emptyList(java.util.Collections.emptyList) TypeSignatureTranslator.toSqlType(io.trino.sql.analyzer.TypeSignatureTranslator.toSqlType) BeforeMethod(org.testng.annotations.BeforeMethod) Set(java.util.Set) TrinoException(io.trino.spi.TrinoException) SchemaTableName(io.trino.spi.connector.SchemaTableName) TableMetadata(io.trino.metadata.TableMetadata) List(java.util.List) TestingSession.testSessionBuilder(io.trino.testing.TestingSession.testSessionBuilder) CreateTable(io.trino.sql.tree.CreateTable) BIGINT(io.trino.spi.type.BigintType.BIGINT) Optional(java.util.Optional) ColumnPropertyManager(io.trino.metadata.ColumnPropertyManager) DATE(io.trino.spi.type.DateType.DATE) Session(io.trino.Session) PlannerContext(io.trino.sql.PlannerContext) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) AccessDeniedException(io.trino.spi.security.AccessDeniedException) SELECT_COLUMN(io.trino.testing.TestingAccessControlManager.TestingPrivilegeType.SELECT_COLUMN) AllowAllAccessControl(io.trino.security.AllowAllAccessControl) ColumnMetadata(io.trino.spi.connector.ColumnMetadata) Assert.assertEquals(org.testng.Assert.assertEquals) ConnectorTableMetadata(io.trino.spi.connector.ConnectorTableMetadata) VARCHAR(io.trino.spi.type.VarcharType.VARCHAR) ImmutableList(com.google.common.collect.ImmutableList) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) TestingPlannerContext.plannerContextBuilder(io.trino.sql.planner.TestingPlannerContext.plannerContextBuilder) LocalQueryRunner(io.trino.testing.LocalQueryRunner) Objects.requireNonNull(java.util.Objects.requireNonNull) ColumnHandle(io.trino.spi.connector.ColumnHandle) INVALID_TABLE_PROPERTY(io.trino.spi.StandardErrorCode.INVALID_TABLE_PROPERTY) VARBINARY(io.trino.spi.type.VarbinaryType.VARBINARY) EventListenerConfig(io.trino.eventlistener.EventListenerConfig) PropertyMetadata.stringProperty(io.trino.spi.session.PropertyMetadata.stringProperty) QueryUtil.identifier(io.trino.sql.QueryUtil.identifier) Sets.immutableEnumSet(com.google.common.collect.Sets.immutableEnumSet) NOT_NULL_COLUMN_CONSTRAINT(io.trino.spi.connector.ConnectorCapabilities.NOT_NULL_COLUMN_CONSTRAINT) StringLiteral(io.trino.sql.tree.StringLiteral) Collections.emptySet(java.util.Collections.emptySet) ConnectorCapabilities(io.trino.spi.connector.ConnectorCapabilities) MoreFutures.getFutureValue(io.airlift.concurrent.MoreFutures.getFutureValue) QualifiedName(io.trino.sql.tree.QualifiedName) LikeClause(io.trino.sql.tree.LikeClause) AbstractMockMetadata(io.trino.metadata.AbstractMockMetadata) TableHandle(io.trino.metadata.TableHandle) TestingAccessControlManager.privilege(io.trino.testing.TestingAccessControlManager.privilege) QualifiedObjectName(io.trino.metadata.QualifiedObjectName) EventListenerManager(io.trino.eventlistener.EventListenerManager) TablePropertyManager(io.trino.metadata.TablePropertyManager) Assert.assertTrue(org.testng.Assert.assertTrue) ColumnDefinition(io.trino.sql.tree.ColumnDefinition) ColumnMetadata(io.trino.spi.connector.ColumnMetadata) AllowAllAccessControl(io.trino.security.AllowAllAccessControl) CreateTable(io.trino.sql.tree.CreateTable) TableElement(io.trino.sql.tree.TableElement) ColumnDefinition(io.trino.sql.tree.ColumnDefinition) Test(org.testng.annotations.Test)

Example 12 with Identifier

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

the class TestDeallocateTask method executeDeallocate.

private Set<String> executeDeallocate(String statementName, String sqlString, Session session) {
    TransactionManager transactionManager = createTestTransactionManager();
    AccessControlManager accessControl = new AccessControlManager(transactionManager, emptyEventListenerManager(), new AccessControlConfig(), DefaultSystemAccessControl.NAME);
    accessControl.setSystemAccessControls(List.of(AllowAllSystemAccessControl.INSTANCE));
    QueryStateMachine stateMachine = QueryStateMachine.begin(Optional.empty(), sqlString, Optional.empty(), session, URI.create("fake://uri"), new ResourceGroupId("test"), false, transactionManager, accessControl, executor, metadata, WarningCollector.NOOP, Optional.empty());
    Deallocate deallocate = new Deallocate(new Identifier(statementName));
    new DeallocateTask().execute(deallocate, stateMachine, emptyList(), WarningCollector.NOOP);
    return stateMachine.getDeallocatedPreparedStatements();
}
Also used : AccessControlManager(io.trino.security.AccessControlManager) AccessControlConfig(io.trino.security.AccessControlConfig) Identifier(io.trino.sql.tree.Identifier) ResourceGroupId(io.trino.spi.resourcegroups.ResourceGroupId) Deallocate(io.trino.sql.tree.Deallocate) TransactionManager(io.trino.transaction.TransactionManager) InMemoryTransactionManager.createTestTransactionManager(io.trino.transaction.InMemoryTransactionManager.createTestTransactionManager)

Example 13 with Identifier

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

the class AstBuilder method visitAliasedRelation.

@Override
public Node visitAliasedRelation(SqlBaseParser.AliasedRelationContext context) {
    Relation child = (Relation) visit(context.relationPrimary());
    if (context.identifier() == null) {
        return child;
    }
    List<Identifier> aliases = null;
    if (context.columnAliases() != null) {
        aliases = visit(context.columnAliases().identifier(), Identifier.class);
    }
    return new AliasedRelation(getLocation(context), child, (Identifier) visit(context.identifier()), aliases);
}
Also used : AliasedRelation(io.trino.sql.tree.AliasedRelation) SampledRelation(io.trino.sql.tree.SampledRelation) Relation(io.trino.sql.tree.Relation) PatternRecognitionRelation(io.trino.sql.tree.PatternRecognitionRelation) Identifier(io.trino.sql.tree.Identifier) AliasedRelation(io.trino.sql.tree.AliasedRelation)

Example 14 with Identifier

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

the class TestSqlParser method testAnalyze.

@Test
public void testAnalyze() {
    QualifiedName table = QualifiedName.of("foo");
    assertStatement("ANALYZE foo", new Analyze(table, ImmutableList.of()));
    assertStatement("ANALYZE foo WITH ( \"string\" = 'bar', \"long\" = 42, computed = concat('ban', 'ana'), a = ARRAY[ 'v1', 'v2' ] )", new Analyze(table, ImmutableList.of(new Property(new Identifier("string"), new StringLiteral("bar")), new Property(new Identifier("long"), new LongLiteral("42")), new Property(new Identifier("computed"), new FunctionCall(QualifiedName.of("concat"), ImmutableList.of(new StringLiteral("ban"), new StringLiteral("ana")))), new Property(new Identifier("a"), new ArrayConstructor(ImmutableList.of(new StringLiteral("v1"), new StringLiteral("v2")))))));
    assertStatement("EXPLAIN ANALYZE foo", new Explain(new Analyze(table, ImmutableList.of()), ImmutableList.of()));
    assertStatement("EXPLAIN ANALYZE ANALYZE foo", new ExplainAnalyze(new Analyze(table, ImmutableList.of()), false));
}
Also used : QueryUtil.quotedIdentifier(io.trino.sql.QueryUtil.quotedIdentifier) Identifier(io.trino.sql.tree.Identifier) StringLiteral(io.trino.sql.tree.StringLiteral) LongLiteral(io.trino.sql.tree.LongLiteral) ExplainAnalyze(io.trino.sql.tree.ExplainAnalyze) QualifiedName(io.trino.sql.tree.QualifiedName) Explain(io.trino.sql.tree.Explain) ArrayConstructor(io.trino.sql.tree.ArrayConstructor) FunctionCall(io.trino.sql.tree.FunctionCall) Property(io.trino.sql.tree.Property) ExplainAnalyze(io.trino.sql.tree.ExplainAnalyze) Analyze(io.trino.sql.tree.Analyze) Test(org.junit.jupiter.api.Test)

Example 15 with Identifier

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

the class TestSqlParser method testRevokeRoles.

@Test
public void testRevokeRoles() {
    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(), 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(), 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"))))), Optional.empty()));
    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"))))), Optional.empty()));
    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"))))), Optional.empty()));
    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"))))), Optional.empty()));
    assertStatement("REVOKE role1 FROM user1 IN my_catalog", new RevokeRoles(ImmutableSet.of(new Identifier("role1")), ImmutableSet.of(new PrincipalSpecification(PrincipalSpecification.Type.UNSPECIFIED, new Identifier("user1"))), false, Optional.empty(), Optional.of(new Identifier("my_catalog"))));
}
Also used : RevokeRoles(io.trino.sql.tree.RevokeRoles) QueryUtil.quotedIdentifier(io.trino.sql.QueryUtil.quotedIdentifier) Identifier(io.trino.sql.tree.Identifier) PrincipalSpecification(io.trino.sql.tree.PrincipalSpecification) GrantorSpecification(io.trino.sql.tree.GrantorSpecification) Test(org.junit.jupiter.api.Test)

Aggregations

Identifier (io.trino.sql.tree.Identifier)71 QueryUtil.quotedIdentifier (io.trino.sql.QueryUtil.quotedIdentifier)37 Test (org.junit.jupiter.api.Test)37 FunctionCall (io.trino.sql.tree.FunctionCall)19 StringLiteral (io.trino.sql.tree.StringLiteral)19 LongLiteral (io.trino.sql.tree.LongLiteral)18 Test (org.testng.annotations.Test)15 CreateTable (io.trino.sql.tree.CreateTable)14 Property (io.trino.sql.tree.Property)14 Expression (io.trino.sql.tree.Expression)13 Table (io.trino.sql.tree.Table)12 DropTable (io.trino.sql.tree.DropTable)11 AllColumns (io.trino.sql.tree.AllColumns)9 QualifiedName (io.trino.sql.tree.QualifiedName)9 PrincipalSpecification (io.trino.sql.tree.PrincipalSpecification)8 List (java.util.List)8 ImmutableList (com.google.common.collect.ImmutableList)6 Session (io.trino.Session)6 ComparisonExpression (io.trino.sql.tree.ComparisonExpression)6 ArithmeticBinaryExpression (io.trino.sql.tree.ArithmeticBinaryExpression)5