use of io.trino.connector.MockConnectorTableHandle in project trino by trinodb.
the class TestEventListenerBasic method createQueryRunner.
@Override
protected QueryRunner createQueryRunner() throws Exception {
Session session = testSessionBuilder().setSystemProperty("task_concurrency", "1").setCatalog("tpch").setSchema("tiny").setClientInfo("{\"clientVersion\":\"testVersion\"}").build();
DistributedQueryRunner queryRunner = DistributedQueryRunner.builder(session).setNodeCount(1).build();
queryRunner.installPlugin(new TpchPlugin());
queryRunner.installPlugin(new TestingEventListenerPlugin(generatedEvents));
queryRunner.installPlugin(new ResourceGroupManagerPlugin());
queryRunner.createCatalog("tpch", "tpch");
queryRunner.installPlugin(new Plugin() {
@Override
public Iterable<ConnectorFactory> getConnectorFactories() {
MockConnectorFactory connectorFactory = MockConnectorFactory.builder().withListTables((session, s) -> ImmutableList.of(new SchemaTableName("default", "tests_table"))).withGetColumns(schemaTableName -> ImmutableList.of(new ColumnMetadata("test_varchar", createVarcharType(15)), new ColumnMetadata("test_bigint", BIGINT))).withGetTableHandle((session, schemaTableName) -> {
if (!schemaTableName.getTableName().startsWith("create")) {
return new MockConnectorTableHandle(schemaTableName);
}
return null;
}).withApplyProjection((session, handle, projections, assignments) -> {
if (((MockConnectorTableHandle) handle).getTableName().getTableName().equals("tests_table")) {
throw new RuntimeException("Throw from apply projection");
}
return Optional.empty();
}).withGetViews((connectorSession, prefix) -> {
ConnectorViewDefinition definition = new ConnectorViewDefinition("SELECT nationkey AS test_column FROM tpch.tiny.nation", Optional.empty(), Optional.empty(), ImmutableList.of(new ConnectorViewDefinition.ViewColumn("test_column", BIGINT.getTypeId())), Optional.empty(), Optional.empty(), true);
SchemaTableName viewName = new SchemaTableName("default", "test_view");
return ImmutableMap.of(viewName, definition);
}).withGetMaterializedViews((connectorSession, prefix) -> {
ConnectorMaterializedViewDefinition definition = new ConnectorMaterializedViewDefinition("SELECT nationkey AS test_column FROM tpch.tiny.nation", Optional.empty(), Optional.empty(), Optional.empty(), ImmutableList.of(new Column("test_column", BIGINT.getTypeId())), Optional.empty(), Optional.of("alice"), ImmutableMap.of());
SchemaTableName materializedViewName = new SchemaTableName("default", "test_materialized_view");
return ImmutableMap.of(materializedViewName, definition);
}).withRowFilter(schemaTableName -> {
if (schemaTableName.getTableName().equals("test_table_with_row_filter")) {
return new ViewExpression("user", Optional.of("tpch"), Optional.of("tiny"), "EXISTS (SELECT 1 FROM nation WHERE name = test_varchar)");
}
return null;
}).withColumnMask((schemaTableName, columnName) -> {
if (schemaTableName.getTableName().equals("test_table_with_column_mask") && columnName.equals("test_varchar")) {
return new ViewExpression("user", Optional.of("tpch"), Optional.of("tiny"), "(SELECT cast(max(orderkey) AS varchar(15)) FROM orders)");
}
return null;
}).build();
return ImmutableList.of(connectorFactory);
}
});
queryRunner.createCatalog("mock", "mock", ImmutableMap.of());
queryRunner.getCoordinator().getResourceGroupManager().get().setConfigurationManager("file", ImmutableMap.of("resource-groups.config-file", getResourceFilePath("resource_groups_config_simple.json")));
queries = new EventsAwaitingQueries(generatedEvents, queryRunner, Duration.ofSeconds(1));
return queryRunner;
}
use of io.trino.connector.MockConnectorTableHandle in project trino by trinodb.
the class TestGrantOnTable method initClass.
@BeforeClass
public void initClass() throws Exception {
queryRunner = DistributedQueryRunner.builder(admin).build();
MockConnectorFactory connectorFactory = MockConnectorFactory.builder().withListSchemaNames(session -> ImmutableList.of("default")).withListTables((session, schemaName) -> "default".equalsIgnoreCase(schemaName) ? ImmutableList.of(table) : ImmutableList.of()).withGetTableHandle((session, tableName) -> tableName.equals(table) ? new MockConnectorTableHandle(tableName) : null).withSchemaGrants(new MutableGrants<>()).withTableGrants(tableGrants).build();
queryRunner.installPlugin(new MockConnectorPlugin(connectorFactory));
queryRunner.createCatalog("local", "mock");
assertions = new QueryAssertions(queryRunner);
tableGrants.grant(new TrinoPrincipal(USER, "admin"), table, EnumSet.allOf(Privilege.class), true);
}
use of io.trino.connector.MockConnectorTableHandle in project trino by trinodb.
the class TestDenyOnSchema method initClass.
@BeforeClass
public void initClass() throws Exception {
queryRunner = DistributedQueryRunner.builder(admin).setAdditionalModule(binder -> {
newOptionalBinder(binder, SystemSecurityMetadata.class).setBinding().toInstance(new DisabledSystemSecurityMetadata() {
@Override
public void denySchemaPrivileges(Session session, CatalogSchemaName schemaName, Set<Privilege> privileges, TrinoPrincipal grantee) {
assertThat(expectedSchemaName).isEqualTo(schemaName);
assertThat(expectedPrivileges).isEqualTo(privileges);
assertThat(expectedGrantee).isEqualTo(grantee);
assertThat(denyCalled).isFalse();
denyCalled = true;
}
});
}).build();
MockConnectorFactory connectorFactory = MockConnectorFactory.builder().withListSchemaNames(session -> ImmutableList.of("default")).withListTables((session, schemaName) -> "default".equalsIgnoreCase(schemaName) ? ImmutableList.of(table) : ImmutableList.of()).withGetTableHandle((session, tableName) -> tableName.equals(table) ? new MockConnectorTableHandle(tableName) : null).build();
queryRunner.installPlugin(new MockConnectorPlugin(connectorFactory));
queryRunner.createCatalog("local", "mock");
assertions = new QueryAssertions(queryRunner);
tableGrants.grant(new TrinoPrincipal(USER, "admin"), table, EnumSet.allOf(Privilege.class), true);
}
use of io.trino.connector.MockConnectorTableHandle in project trino by trinodb.
the class TestDenyOnTable method initClass.
@BeforeClass
public void initClass() throws Exception {
queryRunner = DistributedQueryRunner.builder(admin).setAdditionalModule(binder -> {
newOptionalBinder(binder, SystemSecurityMetadata.class).setBinding().toInstance(new DisabledSystemSecurityMetadata() {
@Override
public void denyTablePrivileges(Session session, QualifiedObjectName tableName, Set<Privilege> privileges, TrinoPrincipal grantee) {
assertThat(expectedTableName).isEqualTo(tableName);
assertThat(expectedPrivileges).isEqualTo(privileges);
assertThat(expectedGrantee).isEqualTo(grantee);
assertThat(denyCalled).isFalse();
denyCalled = true;
}
});
}).build();
MockConnectorFactory connectorFactory = MockConnectorFactory.builder().withListSchemaNames(session -> ImmutableList.of("default")).withListTables((session, schemaName) -> "default".equalsIgnoreCase(schemaName) ? ImmutableList.of(table) : ImmutableList.of()).withGetTableHandle((session, tableName) -> tableName.equals(table) ? new MockConnectorTableHandle(tableName) : null).build();
queryRunner.installPlugin(new MockConnectorPlugin(connectorFactory));
queryRunner.createCatalog("local", "mock");
assertions = new QueryAssertions(queryRunner);
tableGrants.grant(new TrinoPrincipal(USER, "admin"), table, EnumSet.allOf(Privilege.class), true);
}
use of io.trino.connector.MockConnectorTableHandle in project trino by trinodb.
the class TestMockConnector method createQueryRunner.
@Override
protected QueryRunner createQueryRunner() throws Exception {
DistributedQueryRunner queryRunner = DistributedQueryRunner.builder(testSessionBuilder().build()).build();
queryRunner.installPlugin(new TpchPlugin());
queryRunner.createCatalog("tpch", "tpch");
queryRunner.installPlugin(new MockConnectorPlugin(MockConnectorFactory.builder().withListSchemaNames(connectionSession -> ImmutableList.of("default")).withGetColumns(schemaTableName -> {
if (schemaTableName.equals(new SchemaTableName("default", "nation"))) {
return TPCH_NATION_SCHEMA;
}
return ImmutableList.of(new ColumnMetadata("nationkey", BIGINT));
}).withGetTableHandle((session, tableName) -> {
if (tableName.equals(new SchemaTableName("default", "new_table"))) {
return null;
}
return new MockConnectorTableHandle(tableName);
}).withGetMaterializedViewProperties(() -> ImmutableList.of(durationProperty("refresh_interval", "Time interval after which materialized view will be refreshed", null, false))).withGetMaterializedViews((session, schemaTablePrefix) -> ImmutableMap.of(new SchemaTableName("default", "test_materialized_view"), new ConnectorMaterializedViewDefinition("SELECT nationkey FROM mock.default.test_table", Optional.of(new CatalogSchemaTableName("mock", "default", "test_storage")), Optional.of("mock"), Optional.of("default"), ImmutableList.of(new Column("nationkey", BIGINT.getTypeId())), Optional.empty(), Optional.of("alice"), ImmutableMap.of()))).withData(schemaTableName -> {
if (schemaTableName.equals(new SchemaTableName("default", "nation"))) {
return TPCH_NATION_DATA;
}
throw new UnsupportedOperationException();
}).withProcedures(ImmutableSet.of(new TestProcedure().get())).withSchemaProperties(() -> ImmutableList.<PropertyMetadata<?>>builder().add(booleanProperty("boolean_schema_property", "description", false, false)).build()).withTableProperties(() -> ImmutableList.<PropertyMetadata<?>>builder().add(integerProperty("integer_table_property", "description", 0, false)).build()).build()));
queryRunner.createCatalog("mock", "mock");
return queryRunner;
}
Aggregations