Search in sources :

Example 1 with StatementRewrite

use of io.trino.sql.rewrite.StatementRewrite in project trino by trinodb.

the class TestCreateMaterializedViewTask method testCreateDenyPermission.

@Test
public void testCreateDenyPermission() {
    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(), Optional.empty());
    TestingAccessControlManager accessControl = new TestingAccessControlManager(transactionManager, emptyEventListenerManager());
    accessControl.loadSystemAccessControl(AllowAllSystemAccessControl.NAME, ImmutableMap.of());
    accessControl.deny(privilege("test_mv", CREATE_MATERIALIZED_VIEW));
    StatementAnalyzerFactory statementAnalyzerFactory = createTestingStatementAnalyzerFactory(plannerContext, accessControl, new TablePropertyManager(), new AnalyzePropertyManager());
    AnalyzerFactory analyzerFactory = new AnalyzerFactory(statementAnalyzerFactory, new StatementRewrite(ImmutableSet.of()));
    assertThatThrownBy(() -> getFutureValue(new CreateMaterializedViewTask(plannerContext, accessControl, parser, analyzerFactory, materializedViewPropertyManager, new FeaturesConfig()).execute(statement, queryStateMachine, ImmutableList.of(), WarningCollector.NOOP))).isInstanceOf(AccessDeniedException.class).hasMessageContaining("Cannot create materialized view catalog.schema.test_mv");
}
Also used : AccessDeniedException(io.trino.spi.security.AccessDeniedException) CreateMaterializedView(io.trino.sql.tree.CreateMaterializedView) FeaturesConfig(io.trino.FeaturesConfig) StatementRewrite(io.trino.sql.rewrite.StatementRewrite) AllColumns(io.trino.sql.tree.AllColumns) TablePropertyManager(io.trino.metadata.TablePropertyManager) TestingAccessControlManager(io.trino.testing.TestingAccessControlManager) StatementAnalyzerFactory.createTestingStatementAnalyzerFactory(io.trino.sql.analyzer.StatementAnalyzerFactory.createTestingStatementAnalyzerFactory) StatementAnalyzerFactory(io.trino.sql.analyzer.StatementAnalyzerFactory) AnalyzePropertyManager(io.trino.metadata.AnalyzePropertyManager) AnalyzerFactory(io.trino.sql.analyzer.AnalyzerFactory) StatementAnalyzerFactory.createTestingStatementAnalyzerFactory(io.trino.sql.analyzer.StatementAnalyzerFactory.createTestingStatementAnalyzerFactory) StatementAnalyzerFactory(io.trino.sql.analyzer.StatementAnalyzerFactory) Test(org.testng.annotations.Test)

Example 2 with StatementRewrite

use of io.trino.sql.rewrite.StatementRewrite in project trino by trinodb.

the class TestCreateViewTask method setUp.

@Override
@BeforeMethod
public void setUp() {
    super.setUp();
    parser = new SqlParser();
    analyzerFactory = new AnalyzerFactory(createTestingStatementAnalyzerFactory(plannerContext, new AllowAllAccessControl(), new TablePropertyManager(), new AnalyzePropertyManager()), new StatementRewrite(ImmutableSet.of()));
    QualifiedObjectName tableName = qualifiedObjectName("mock_table");
    metadata.createTable(testSession, CATALOG_NAME, someTable(tableName), false);
}
Also used : AllowAllAccessControl(io.trino.security.AllowAllAccessControl) StatementRewrite(io.trino.sql.rewrite.StatementRewrite) SqlParser(io.trino.sql.parser.SqlParser) TablePropertyManager(io.trino.metadata.TablePropertyManager) QualifiedObjectName(io.trino.metadata.QualifiedObjectName) AnalyzerFactory(io.trino.sql.analyzer.AnalyzerFactory) StatementAnalyzerFactory.createTestingStatementAnalyzerFactory(io.trino.sql.analyzer.StatementAnalyzerFactory.createTestingStatementAnalyzerFactory) AnalyzePropertyManager(io.trino.metadata.AnalyzePropertyManager) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 3 with StatementRewrite

use of io.trino.sql.rewrite.StatementRewrite in project trino by trinodb.

the class TestAnalyzer method createAnalyzer.

private Analyzer createAnalyzer(Session session, AccessControl accessControl) {
    StatementRewrite statementRewrite = new StatementRewrite(ImmutableSet.of(new ShowQueriesRewrite(plannerContext.getMetadata(), plannerContext.getFunctionManager(), SQL_PARSER, accessControl, new SessionPropertyManager(), new SchemaPropertyManager(), new ColumnPropertyManager(), tablePropertyManager, new MaterializedViewPropertyManager())));
    StatementAnalyzerFactory statementAnalyzerFactory = createTestingStatementAnalyzerFactory(plannerContext, accessControl, tablePropertyManager, analyzePropertyManager);
    AnalyzerFactory analyzerFactory = new AnalyzerFactory(statementAnalyzerFactory, statementRewrite);
    return analyzerFactory.createAnalyzer(session, emptyList(), emptyMap(), WarningCollector.NOOP);
}
Also used : ColumnPropertyManager(io.trino.metadata.ColumnPropertyManager) StatementRewrite(io.trino.sql.rewrite.StatementRewrite) SessionPropertyManager(io.trino.metadata.SessionPropertyManager) MaterializedViewPropertyManager(io.trino.metadata.MaterializedViewPropertyManager) ShowQueriesRewrite(io.trino.sql.rewrite.ShowQueriesRewrite) SchemaPropertyManager(io.trino.metadata.SchemaPropertyManager) StatementAnalyzerFactory.createTestingStatementAnalyzerFactory(io.trino.sql.analyzer.StatementAnalyzerFactory.createTestingStatementAnalyzerFactory) StatementAnalyzerFactory.createTestingStatementAnalyzerFactory(io.trino.sql.analyzer.StatementAnalyzerFactory.createTestingStatementAnalyzerFactory)

Example 4 with StatementRewrite

use of io.trino.sql.rewrite.StatementRewrite 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)

Aggregations

StatementAnalyzerFactory.createTestingStatementAnalyzerFactory (io.trino.sql.analyzer.StatementAnalyzerFactory.createTestingStatementAnalyzerFactory)4 StatementRewrite (io.trino.sql.rewrite.StatementRewrite)4 AnalyzePropertyManager (io.trino.metadata.AnalyzePropertyManager)3 TablePropertyManager (io.trino.metadata.TablePropertyManager)3 AnalyzerFactory (io.trino.sql.analyzer.AnalyzerFactory)3 AllowAllAccessControl (io.trino.security.AllowAllAccessControl)2 StatementAnalyzerFactory (io.trino.sql.analyzer.StatementAnalyzerFactory)2 BeforeMethod (org.testng.annotations.BeforeMethod)2 FeaturesConfig (io.trino.FeaturesConfig)1 CatalogName (io.trino.connector.CatalogName)1 AbstractMockMetadata (io.trino.metadata.AbstractMockMetadata)1 ColumnPropertyManager (io.trino.metadata.ColumnPropertyManager)1 MaterializedViewPropertyManager (io.trino.metadata.MaterializedViewPropertyManager)1 QualifiedObjectName (io.trino.metadata.QualifiedObjectName)1 SchemaPropertyManager (io.trino.metadata.SchemaPropertyManager)1 SessionPropertyManager (io.trino.metadata.SessionPropertyManager)1 AccessDeniedException (io.trino.spi.security.AccessDeniedException)1 PropertyMetadata (io.trino.spi.session.PropertyMetadata)1 SqlParser (io.trino.sql.parser.SqlParser)1 ShowQueriesRewrite (io.trino.sql.rewrite.ShowQueriesRewrite)1