use of io.trino.spi.Plugin in project TiBigData by tidb-incubator.
the class ConnectorsPluginTest method testCreateConnector.
@Test
public void testCreateConnector() {
Plugin plugin = new ConnectorsPlugin();
ConnectorFactory factory = getOnlyElement(plugin.getConnectorFactories());
factory.create("tidb", ConfigUtils.getProperties(), new TestingConnectorContext());
}
use of io.trino.spi.Plugin in project trino by trinodb.
the class TestJmxStats method testJmxStatsExposure.
@Test
public void testJmxStatsExposure() throws Exception {
Plugin plugin = new JdbcPlugin("base-jdbc", new TestingH2JdbcModule());
ConnectorFactory factory = getOnlyElement(plugin.getConnectorFactories());
factory.create("test", ImmutableMap.of("connection-url", "jdbc:driver:"), new TestingConnectorContext());
MBeanServer mbeanServer = getPlatformMBeanServer();
Set<ObjectName> objectNames = mbeanServer.queryNames(new ObjectName("io.trino.plugin.jdbc:*"), null);
assertTrue(objectNames.containsAll(ImmutableSet.of(new ObjectName("io.trino.plugin.jdbc:type=ConnectionFactory,name=test"), new ObjectName("io.trino.plugin.jdbc:type=JdbcClient,name=test"))));
for (ObjectName objectName : objectNames) {
MBeanInfo mbeanInfo = mbeanServer.getMBeanInfo(objectName);
assertNotEquals(mbeanInfo.getAttributes().length, 0, format("Object %s doesn't expose JMX stats", objectName.getCanonicalName()));
}
}
use of io.trino.spi.Plugin in project trino by trinodb.
the class PluginManager method loadPlugin.
private void loadPlugin(PluginClassLoader pluginClassLoader) {
ServiceLoader<Plugin> serviceLoader = ServiceLoader.load(Plugin.class, pluginClassLoader);
List<Plugin> plugins = ImmutableList.copyOf(serviceLoader);
checkState(!plugins.isEmpty(), "No service providers of type %s in the classpath: %s", Plugin.class.getName(), asList(pluginClassLoader.getURLs()));
for (Plugin plugin : plugins) {
log.info("Installing %s", plugin.getClass().getName());
installPlugin(plugin, pluginClassLoader::duplicate);
}
}
use of io.trino.spi.Plugin in project trino by trinodb.
the class TestDeltaLakePerTransactionMetastoreCache method createQueryRunner.
private DistributedQueryRunner createQueryRunner(boolean enablePerTransactionHiveMetastoreCaching) throws Exception {
boolean createdDeltaLake = false;
if (dockerizedMinioDataLake == null) {
// share environment between testcases to speed things up
dockerizedMinioDataLake = createDockerizedMinioDataLakeForDeltaLake(BUCKET_NAME);
createdDeltaLake = true;
}
Session session = testSessionBuilder().setCatalog(DELTA_CATALOG).setSchema("default").build();
DistributedQueryRunner queryRunner = DistributedQueryRunner.builder(session).build();
queryRunner.installPlugin(new Plugin() {
@Override
public Iterable<ConnectorFactory> getConnectorFactories() {
return ImmutableList.of(new ConnectorFactory() {
@Override
public String getName() {
return TEST_DELTA_CONNECTOR_NAME;
}
@Override
public Connector create(String catalogName, Map<String, String> config, ConnectorContext context) {
return InternalDeltaLakeConnectorFactory.createConnector(catalogName, config, context, new AbstractConfigurationAwareModule() {
@Override
protected void setup(Binder binder) {
newOptionalBinder(binder, ThriftMetastoreClientFactory.class).setDefault().to(DefaultThriftMetastoreClientFactory.class).in(Scopes.SINGLETON);
binder.bind(MetastoreLocator.class).to(StaticMetastoreLocator.class).in(Scopes.SINGLETON);
configBinder(binder).bindConfig(StaticMetastoreConfig.class);
configBinder(binder).bindConfig(ThriftMetastoreConfig.class);
binder.bind(ThriftMetastore.class).to(ThriftHiveMetastore.class).in(Scopes.SINGLETON);
newExporter(binder).export(ThriftMetastore.class).as((generator) -> generator.generatedNameOf(ThriftHiveMetastore.class));
install(new ThriftMetastoreAuthenticationModule());
binder.bind(Boolean.class).annotatedWith(HideNonDeltaLakeTables.class).toInstance(false);
binder.bind(BridgingHiveMetastoreFactory.class).in(Scopes.SINGLETON);
}
@Provides
@Singleton
@RawHiveMetastoreFactory
public HiveMetastoreFactory getCountingHiveMetastoreFactory(BridgingHiveMetastoreFactory bridgingHiveMetastoreFactory) {
return new HiveMetastoreFactory() {
@Override
public boolean isImpersonationEnabled() {
return false;
}
@Override
public HiveMetastore createMetastore(Optional<ConnectorIdentity> identity) {
HiveMetastore bridgingHiveMetastore = bridgingHiveMetastoreFactory.createMetastore(identity);
// bind HiveMetastore which counts method executions
return Reflection.newProxy(HiveMetastore.class, (proxy, method, args) -> {
String methodName = method.getName();
long count = hiveMetastoreInvocationCounts.getOrDefault(methodName, 0L);
hiveMetastoreInvocationCounts.put(methodName, count + 1);
return method.invoke(bridgingHiveMetastore, args);
});
}
};
}
});
}
});
}
});
ImmutableMap.Builder<String, String> deltaLakeProperties = ImmutableMap.builder();
deltaLakeProperties.put("hive.metastore.uri", dockerizedMinioDataLake.getTestingHadoop().getMetastoreAddress());
deltaLakeProperties.put("hive.s3.aws-access-key", MINIO_ACCESS_KEY);
deltaLakeProperties.put("hive.s3.aws-secret-key", MINIO_SECRET_KEY);
deltaLakeProperties.put("hive.s3.endpoint", dockerizedMinioDataLake.getMinioAddress());
deltaLakeProperties.put("hive.s3.path-style-access", "true");
// use test value so we do not get clash with default bindings)
deltaLakeProperties.put("hive.metastore", "test");
if (!enablePerTransactionHiveMetastoreCaching) {
// almost disable the cache; 0 is not allowed as config property value
deltaLakeProperties.put("hive.per-transaction-metastore-cache-maximum-size", "1");
}
queryRunner.createCatalog(DELTA_CATALOG, TEST_DELTA_CONNECTOR_NAME, deltaLakeProperties.buildOrThrow());
if (createdDeltaLake) {
List<TpchTable<? extends TpchEntity>> tpchTables = List.of(TpchTable.NATION, TpchTable.REGION);
tpchTables.forEach(table -> {
String tableName = table.getTableName();
dockerizedMinioDataLake.copyResources("io/trino/plugin/deltalake/testing/resources/databricks/" + tableName, tableName);
queryRunner.execute(format("CREATE TABLE %s.%s.%s (dummy int) WITH (location = 's3://%s/%3$s')", DELTA_CATALOG, "default", tableName, BUCKET_NAME));
});
}
return queryRunner;
}
use of io.trino.spi.Plugin in project trino by trinodb.
the class TestDeltaLakePlugin method testCreateConnector.
@Test
public void testCreateConnector() {
Plugin plugin = new TestingDeltaLakePlugin();
ConnectorFactory factory = getOnlyElement(plugin.getConnectorFactories());
factory.create("test", ImmutableMap.of("hive.metastore.uri", "thrift://foo:1234"), new TestingConnectorContext());
}
Aggregations