Search in sources :

Example 16 with AllowAllAccessControl

use of io.trino.security.AllowAllAccessControl in project trino by trinodb.

the class TestCreateMaterializedViewTask method testCreateMaterializedViewWithExistingView.

@Test
public void testCreateMaterializedViewWithExistingView() {
    CreateMaterializedView statement = new CreateMaterializedView(Optional.empty(), QualifiedName.of("test_mv"), simpleQuery(selectList(new AllColumns()), table(QualifiedName.of("catalog", "schema", "mock_table"))), false, false, ImmutableList.of(), Optional.empty());
    assertTrinoExceptionThrownBy(() -> getFutureValue(new CreateMaterializedViewTask(plannerContext, new AllowAllAccessControl(), parser, analyzerFactory, materializedViewPropertyManager, new FeaturesConfig()).execute(statement, queryStateMachine, ImmutableList.of(), WarningCollector.NOOP))).hasErrorCode(ALREADY_EXISTS).hasMessage("Materialized view already exists");
    assertEquals(metadata.getCreateMaterializedViewCallCount(), 1);
}
Also used : CreateMaterializedView(io.trino.sql.tree.CreateMaterializedView) AllowAllAccessControl(io.trino.security.AllowAllAccessControl) FeaturesConfig(io.trino.FeaturesConfig) AllColumns(io.trino.sql.tree.AllColumns) Test(org.testng.annotations.Test)

Example 17 with AllowAllAccessControl

use of io.trino.security.AllowAllAccessControl in project trino by trinodb.

the class TestCreateMaterializedViewTask method testCreateMaterializedViewWithDefaultProperties.

@Test
public void testCreateMaterializedViewWithDefaultProperties() {
    QualifiedName materializedViewName = QualifiedName.of("catalog", "schema", "mv");
    CreateMaterializedView statement = new CreateMaterializedView(Optional.empty(), materializedViewName, simpleQuery(selectList(new AllColumns()), table(QualifiedName.of("catalog", "schema", "mock_table"))), false, true, ImmutableList.of(// set foo to DEFAULT
    new Property(new Identifier("foo")), // set bar to DEFAULT
    new Property(new Identifier("bar"))), Optional.empty());
    getFutureValue(new CreateMaterializedViewTask(plannerContext, new AllowAllAccessControl(), parser, analyzerFactory, materializedViewPropertyManager, new FeaturesConfig()).execute(statement, queryStateMachine, ImmutableList.of(), WarningCollector.NOOP));
    Optional<MaterializedViewDefinition> definitionOptional = metadata.getMaterializedView(testSession, QualifiedObjectName.valueOf(materializedViewName.toString()));
    assertThat(definitionOptional).isPresent();
    Map<String, Object> properties = definitionOptional.get().getProperties();
    assertThat(properties.get("foo")).isEqualTo(DEFAULT_MATERIALIZED_VIEW_FOO_PROPERTY_VALUE);
    assertThat(properties.get("bar")).isEqualTo(DEFAULT_MATERIALIZED_VIEW_BAR_PROPERTY_VALUE);
}
Also used : FeaturesConfig(io.trino.FeaturesConfig) QualifiedName(io.trino.sql.tree.QualifiedName) AllColumns(io.trino.sql.tree.AllColumns) CreateMaterializedView(io.trino.sql.tree.CreateMaterializedView) Identifier(io.trino.sql.tree.Identifier) MaterializedViewDefinition(io.trino.metadata.MaterializedViewDefinition) AllowAllAccessControl(io.trino.security.AllowAllAccessControl) Property(io.trino.sql.tree.Property) PropertyMetadata.integerProperty(io.trino.spi.session.PropertyMetadata.integerProperty) PropertyMetadata.stringProperty(io.trino.spi.session.PropertyMetadata.stringProperty) Test(org.testng.annotations.Test)

Example 18 with AllowAllAccessControl

use of io.trino.security.AllowAllAccessControl in project trino by trinodb.

the class TestCreateMaterializedViewTask method setUp.

@BeforeMethod
public void setUp() {
    queryRunner = LocalQueryRunner.create(TEST_SESSION);
    transactionManager = queryRunner.getTransactionManager();
    queryRunner.createCatalog(CATALOG_NAME, MockConnectorFactory.builder().withGetMaterializedViewProperties(() -> ImmutableList.<PropertyMetadata<?>>builder().add(stringProperty("foo", "test materialized view property", DEFAULT_MATERIALIZED_VIEW_FOO_PROPERTY_VALUE, false)).add(integerProperty("bar", "test materialized view property", DEFAULT_MATERIALIZED_VIEW_BAR_PROPERTY_VALUE, false)).build()).build(), ImmutableMap.of());
    materializedViewPropertyManager = queryRunner.getMaterializedViewPropertyManager();
    testSession = testSessionBuilder().build();
    metadata = new MockMetadata(new CatalogName(CATALOG_NAME));
    plannerContext = plannerContextBuilder().withMetadata(metadata).build();
    parser = queryRunner.getSqlParser();
    analyzerFactory = new AnalyzerFactory(createTestingStatementAnalyzerFactory(plannerContext, new AllowAllAccessControl(), new TablePropertyManager(), new AnalyzePropertyManager()), new StatementRewrite(ImmutableSet.of()));
    queryStateMachine = stateMachine(transactionManager, createTestMetadataManager(), new AllowAllAccessControl());
}
Also used : AllowAllAccessControl(io.trino.security.AllowAllAccessControl) StatementRewrite(io.trino.sql.rewrite.StatementRewrite) AbstractMockMetadata(io.trino.metadata.AbstractMockMetadata) PropertyMetadata(io.trino.spi.session.PropertyMetadata) CatalogName(io.trino.connector.CatalogName) TablePropertyManager(io.trino.metadata.TablePropertyManager) AnalyzerFactory(io.trino.sql.analyzer.AnalyzerFactory) StatementAnalyzerFactory.createTestingStatementAnalyzerFactory(io.trino.sql.analyzer.StatementAnalyzerFactory.createTestingStatementAnalyzerFactory) StatementAnalyzerFactory(io.trino.sql.analyzer.StatementAnalyzerFactory) AnalyzePropertyManager(io.trino.metadata.AnalyzePropertyManager) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 19 with AllowAllAccessControl

use of io.trino.security.AllowAllAccessControl in project trino by trinodb.

the class TestCreateMaterializedViewTask method testCreateMaterializedViewWithInvalidProperty.

@Test
public void testCreateMaterializedViewWithInvalidProperty() {
    CreateMaterializedView statement = new CreateMaterializedView(Optional.empty(), QualifiedName.of("test_mv"), simpleQuery(selectList(new AllColumns()), table(QualifiedName.of("catalog", "schema", "mock_table"))), false, true, ImmutableList.of(new Property(new Identifier("baz"), new StringLiteral("abc"))), Optional.empty());
    assertTrinoExceptionThrownBy(() -> getFutureValue(new CreateMaterializedViewTask(plannerContext, new AllowAllAccessControl(), parser, analyzerFactory, materializedViewPropertyManager, new FeaturesConfig()).execute(statement, queryStateMachine, ImmutableList.of(), WarningCollector.NOOP))).hasErrorCode(INVALID_MATERIALIZED_VIEW_PROPERTY).hasMessage("Catalog 'catalog' materialized view property 'baz' does not exist");
    assertEquals(metadata.getCreateMaterializedViewCallCount(), 0);
}
Also used : CreateMaterializedView(io.trino.sql.tree.CreateMaterializedView) Identifier(io.trino.sql.tree.Identifier) StringLiteral(io.trino.sql.tree.StringLiteral) AllowAllAccessControl(io.trino.security.AllowAllAccessControl) FeaturesConfig(io.trino.FeaturesConfig) AllColumns(io.trino.sql.tree.AllColumns) Property(io.trino.sql.tree.Property) PropertyMetadata.integerProperty(io.trino.spi.session.PropertyMetadata.integerProperty) PropertyMetadata.stringProperty(io.trino.spi.session.PropertyMetadata.stringProperty) Test(org.testng.annotations.Test)

Example 20 with AllowAllAccessControl

use of io.trino.security.AllowAllAccessControl in project trino by trinodb.

the class TestCreateSchemaTask method getCreateSchemaTask.

private CreateSchemaTask getCreateSchemaTask() {
    SchemaPropertyManager schemaPropertyManager = new SchemaPropertyManager();
    schemaPropertyManager.addProperties(new CatalogName(CATALOG_NAME), ImmutableList.of());
    return new CreateSchemaTask(plannerContext, new AllowAllAccessControl(), schemaPropertyManager);
}
Also used : AllowAllAccessControl(io.trino.security.AllowAllAccessControl) CatalogName(io.trino.connector.CatalogName) SchemaPropertyManager(io.trino.metadata.SchemaPropertyManager)

Aggregations

AllowAllAccessControl (io.trino.security.AllowAllAccessControl)28 Test (org.testng.annotations.Test)16 QualifiedObjectName (io.trino.metadata.QualifiedObjectName)9 TableHandle (io.trino.metadata.TableHandle)8 CatalogName (io.trino.connector.CatalogName)7 PropertyMetadata.stringProperty (io.trino.spi.session.PropertyMetadata.stringProperty)7 BeforeMethod (org.testng.annotations.BeforeMethod)7 Session (io.trino.Session)6 AbstractMockMetadata (io.trino.metadata.AbstractMockMetadata)6 TablePropertyManager (io.trino.metadata.TablePropertyManager)6 TransactionManager (io.trino.transaction.TransactionManager)6 ImmutableMap (com.google.common.collect.ImmutableMap)5 PlannerContext (io.trino.sql.PlannerContext)5 ColumnDefinition (io.trino.sql.tree.ColumnDefinition)5 CreateTable (io.trino.sql.tree.CreateTable)5 Identifier (io.trino.sql.tree.Identifier)5 Property (io.trino.sql.tree.Property)5 ImmutableList (com.google.common.collect.ImmutableList)4 Sets.immutableEnumSet (com.google.common.collect.Sets.immutableEnumSet)4 MoreFutures.getFutureValue (io.airlift.concurrent.MoreFutures.getFutureValue)4