Java Code Examples for io.prestosql.spi.connector.ConnectorFactory

The following examples show how to use io.prestosql.spi.connector.ConnectorFactory. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: presto   Source File: TestKafkaPlugin.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testSpinup()
{
    KafkaPlugin plugin = new KafkaPlugin();

    ConnectorFactory factory = getOnlyElement(plugin.getConnectorFactories());
    assertInstanceOf(factory, KafkaConnectorFactory.class);

    Connector c = factory.create(
            "test-connector",
            ImmutableMap.<String, String>builder()
                    .put("kafka.table-names", "test")
                    .put("kafka.nodes", "localhost:9092")
                    .build(),
            new TestingConnectorContext());
    assertNotNull(c);
}
 
Example 2
Source Project: presto   Source File: TestRedisPlugin.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testStartup()
{
    RedisPlugin plugin = new RedisPlugin();

    ConnectorFactory factory = getOnlyElement(plugin.getConnectorFactories());
    assertInstanceOf(factory, RedisConnectorFactory.class);

    Connector c = factory.create(
            "test-connector",
            ImmutableMap.<String, String>builder()
                    .put("redis.table-names", "test")
                    .put("redis.nodes", "localhost:6379")
                    .build(),
            new TestingConnectorContext());
    assertNotNull(c);
}
 
Example 3
Source Project: presto   Source File: TestSystemConnector.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected QueryRunner createQueryRunner()
        throws Exception
{
    Session defaultSession = testSessionBuilder()
            .setCatalog("mock")
            .setSchema("default")
            .build();

    DistributedQueryRunner queryRunner = DistributedQueryRunner.builder(defaultSession).build();
    queryRunner.installPlugin(new Plugin()
    {
        @Override
        public Iterable<ConnectorFactory> getConnectorFactories()
        {
            MockConnectorFactory connectorFactory = MockConnectorFactory.builder()
                    .withGetViews((session, schemaTablePrefix) -> ImmutableMap.of())
                    .withListTables((session, s) -> ImmutableList.of(SCHEMA_TABLE_NAME))
                    .withGetColumns(tableName -> getColumns.apply(tableName))
                    .build();
            return ImmutableList.of(connectorFactory);
        }
    });
    queryRunner.createCatalog("mock", "mock", ImmutableMap.of());
    return queryRunner;
}
 
Example 4
Source Project: presto   Source File: TestCoordinatorDynamicFiltering.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Iterable<ConnectorFactory> getConnectorFactories()
{
    return ImmutableList.of(new ConnectorFactory()
    {
        private final ConnectorMetadata metadata = new TestingMetadata();

        @Override
        public String getName()
        {
            return "test";
        }

        @Override
        public ConnectorHandleResolver getHandleResolver()
        {
            return new TestingHandleResolver();
        }

        @Override
        public Connector create(String catalogName, Map<String, String> config, ConnectorContext context)
        {
            return new TestConnector(metadata, Duration.valueOf("10s"), expectedDynamicFilter);
        }
    });
}
 
Example 5
Source Project: presto   Source File: TestConnectorEventListener.java    License: Apache License 2.0 6 votes vote down vote up
@BeforeClass
private void setUp()
        throws Exception
{
    session = testSessionBuilder()
            .setSystemProperty("task_concurrency", "1")
            .setCatalog("tpch")
            .setSchema("tiny")
            .setClientInfo("{\"clientVersion\":\"testVersion\"}")
            .build();
    queryRunner = DistributedQueryRunner.builder(session).setNodeCount(1).build();
    queryRunner.installPlugin(new Plugin()
    {
        @Override
        public Iterable<ConnectorFactory> getConnectorFactories()
        {
            return ImmutableList.of(new MockConnectorFactory.Builder()
                    .withEventListener(new TestingEventListener(generatedEvents))
                    .build());
        }
    });
    queryRunner.createCatalog("mock-catalog", "mock");
    queries = new EventsAwaitingQueries(generatedEvents, queryRunner);
}
 
Example 6
Source Project: presto   Source File: TestBeginQuery.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Iterable<ConnectorFactory> getConnectorFactories()
{
    return ImmutableList.of(new ConnectorFactory()
    {
        @Override
        public String getName()
        {
            return "test";
        }

        @Override
        public ConnectorHandleResolver getHandleResolver()
        {
            return new TestingHandleResolver();
        }

        @Override
        public Connector create(String catalogName, Map<String, String> config, ConnectorContext context)
        {
            return new TestConnector(metadata);
        }
    });
}
 
Example 7
Source Project: presto   Source File: TestMetadataManager.java    License: Apache License 2.0 6 votes vote down vote up
@BeforeClass
public void setUp()
        throws Exception
{
    queryRunner = TpchQueryRunnerBuilder.builder().build();
    queryRunner.installPlugin(new Plugin()
    {
        @Override
        public Iterable<ConnectorFactory> getConnectorFactories()
        {
            MockConnectorFactory connectorFactory = MockConnectorFactory.builder()
                    .withListSchemaNames(session -> ImmutableList.of("UPPER_CASE_SCHEMA"))
                    .withListTables((session, schemaNameOrNull) -> {
                        throw new UnsupportedOperationException();
                    })
                    .withGetViews((session, prefix) -> ImmutableMap.of())
                    .build();
            return ImmutableList.of(connectorFactory);
        }
    });
    queryRunner.createCatalog("upper_case_schema_catalog", "mock");
    metadataManager = (MetadataManager) queryRunner.getMetadata();
}
 
Example 8
Source Project: presto   Source File: TestJmxStats.java    License: Apache License 2.0 6 votes vote down vote up
@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"), new TestingConnectorContext());
    MBeanServer mbeanServer = getPlatformMBeanServer();
    Set<ObjectName> objectNames = mbeanServer.queryNames(new ObjectName("io.prestosql.plugin.jdbc:*"), null);

    assertTrue(objectNames.containsAll(
            ImmutableSet.of(
                    new ObjectName("io.prestosql.plugin.jdbc:type=ConnectionFactory,name=test"),
                    new ObjectName("io.prestosql.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()));
    }
}
 
Example 9
Source Project: presto   Source File: TestHiveHadoop2Plugin.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testS3SecurityMappingAndHiveCachingMutuallyExclusive()
        throws IOException
{
    Path mappingConfig = Files.createTempFile(null, null);
    Plugin plugin = new HiveHadoop2Plugin();
    ConnectorFactory connectorFactory = Iterables.getOnlyElement(plugin.getConnectorFactories());

    assertThatThrownBy(() -> connectorFactory.create(
            "test",
            ImmutableMap.<String, String>builder()
                    .put("hive.s3.security-mapping.config-file", mappingConfig.toString())
                    .put("hive.cache.enabled", "true")
                    .put("hive.metastore.uri", "thrift://foo:1234")
                    .put("hive.cache.location", tempDirectory.toString())
                    .build(),
            new TestingConnectorContext())
            .shutdown()).hasMessageContaining("S3 security mapping is not compatible with Hive caching");
}
 
Example 10
Source Project: presto   Source File: TestHiveHadoop2Plugin.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testGcsAccessTokenAndHiveCachingMutuallyExclusive()
{
    Plugin plugin = new HiveHadoop2Plugin();
    ConnectorFactory connectorFactory = Iterables.getOnlyElement(plugin.getConnectorFactories());

    assertThatThrownBy(() -> connectorFactory.create(
            "test",
            ImmutableMap.<String, String>builder()
                    .put("hive.gcs.use-access-token", "true")
                    .put("hive.cache.enabled", "true")
                    .put("hive.metastore.uri", "thrift://foo:1234")
                    .put("hive.cache.location", tempDirectory.toString())
                    .build(),
            new TestingConnectorContext())
            .shutdown())
            .hasMessageContaining("Use of GCS access token is not compatible with Hive caching");
}
 
Example 11
Source Project: presto   Source File: TestHiveHadoop2Plugin.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testHdfsImpersonationAndHiveCachingMutuallyExclusive()
{
    Plugin plugin = new HiveHadoop2Plugin();
    ConnectorFactory connectorFactory = Iterables.getOnlyElement(plugin.getConnectorFactories());

    assertThatThrownBy(() -> connectorFactory.create(
            "test",
            ImmutableMap.<String, String>builder()
                    .put("hive.hdfs.impersonation.enabled", "true")
                    .put("hive.cache.enabled", "true")
                    .put("hive.metastore.uri", "thrift://foo:1234")
                    .put("hive.cache.location", tempDirectory.toString())
                    .build(),
            new TestingConnectorContext())
            .shutdown())
            .hasMessageContaining("Hdfs impersonation is not compatible with Hive caching");
}
 
Example 12
Source Project: presto   Source File: TestHiveHadoop2Plugin.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testRubixCache()
{
    Plugin plugin = new HiveHadoop2Plugin();
    ConnectorFactory connectorFactory = Iterables.getOnlyElement(plugin.getConnectorFactories());

    connectorFactory.create(
            "test",
            ImmutableMap.<String, String>builder()
                    .put("hive.cache.enabled", "true")
                    .put("hive.metastore.uri", "thrift://foo:1234")
                    .put("hive.cache.location", tempDirectory.toString())
                    .build(),
            new TestingConnectorContext())
            .shutdown();
}
 
Example 13
Source Project: presto   Source File: RaptorBenchmarkQueryRunner.java    License: Apache License 2.0 6 votes vote down vote up
public static LocalQueryRunner createLocalQueryRunner()
{
    Session session = testSessionBuilder()
            .setCatalog("raptor")
            .setSchema("benchmark")
            .build();
    LocalQueryRunner localQueryRunner = LocalQueryRunner.create(session);

    // add tpch
    localQueryRunner.createCatalog("tpch", new TpchConnectorFactory(1), ImmutableMap.of());

    // add raptor
    ConnectorFactory raptorConnectorFactory = getOnlyElement(new RaptorPlugin()
            .getConnectorFactories());
    Map<String, String> config = createRaptorConfig(TPCH_CACHE_DIR);
    localQueryRunner.createCatalog("raptor", raptorConnectorFactory, config);

    if (!localQueryRunner.tableExists(session, "orders")) {
        localQueryRunner.execute("CREATE TABLE orders AS SELECT * FROM tpch.sf1.orders");
    }
    if (!localQueryRunner.tableExists(session, "lineitem")) {
        localQueryRunner.execute("CREATE TABLE lineitem AS SELECT * FROM tpch.sf1.lineitem");
    }
    return localQueryRunner;
}
 
Example 14
Source Project: presto   Source File: TestRaptorPlugin.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testPlugin()
        throws Exception
{
    Plugin plugin = new RaptorPlugin();
    ConnectorFactory factory = getOnlyElement(plugin.getConnectorFactories());
    assertInstanceOf(factory, RaptorConnectorFactory.class);

    File tmpDir = Files.createTempDir();
    try {
        Map<String, String> config = ImmutableMap.<String, String>builder()
                .put("metadata.db.type", "h2")
                .put("metadata.db.filename", tmpDir.getAbsolutePath())
                .put("storage.data-directory", tmpDir.getAbsolutePath())
                .build();

        factory.create("test", config, new TestingConnectorContext());
    }
    finally {
        deleteRecursively(tmpDir.toPath(), ALLOW_INSECURE);
    }
}
 
Example 15
Source Project: presto   Source File: TestKinesisPlugin.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public ConnectorFactory testConnectorExists()
{
    KinesisPlugin plugin = new KinesisPlugin();

    // Create factory manually to double check everything is done right
    Iterable<ConnectorFactory> iteratable = plugin.getConnectorFactories();

    List<ConnectorFactory> factories = new ArrayList<>();
    for (ConnectorFactory connectorFactory : iteratable) {
        factories.add(connectorFactory);
    }
    assertNotNull(factories);
    assertEquals(factories.size(), 1);
    ConnectorFactory factory = factories.get(0);
    assertNotNull(factory);
    return factory;
}
 
Example 16
Source Project: presto   Source File: TestKinesisPlugin.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testSpinUp()
{
    String accessKey = "kinesis.accessKey";
    String secretKey = "kinesis.secretKey";
    ConnectorFactory factory = testConnectorExists();
    // Important: this has to be created before we setup the injector in the factory:
    assertNotNull(factory.getHandleResolver());

    Connector c = factory.create("kinesis.test-connector", ImmutableMap.<String, String>builder()
            .put("kinesis.hide-internal-columns", "false")
            .put("kinesis.access-key", TestUtils.noneToBlank(accessKey))
            .put("kinesis.secret-key", TestUtils.noneToBlank(secretKey))
            .build(), new TestingConnectorContext());
    assertNotNull(c);

    // Verify that the key objects have been created on the connector
    assertNotNull(c.getRecordSetProvider());
    assertNotNull(c.getSplitManager());
    ConnectorMetadata md = c.getMetadata(KinesisTransactionHandle.INSTANCE);
    assertNotNull(md);

    ConnectorTransactionHandle handle = c.beginTransaction(READ_COMMITTED, true);
    assertTrue(handle instanceof KinesisTransactionHandle);
}
 
Example 17
Source Project: presto   Source File: TestDruidJdbcPlugin.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateConnector()
{
    Plugin plugin = new DruidJdbcPlugin();
    ConnectorFactory factory = getOnlyElement(plugin.getConnectorFactories());
    factory.create("test", ImmutableMap.of("connection-url", "test"), new TestingConnectorContext());
}
 
Example 18
Source Project: presto   Source File: TestEventListener.java    License: Apache License 2.0 5 votes vote down vote up
@BeforeClass
private void setUp()
        throws Exception
{
    session = testSessionBuilder()
            .setSystemProperty("task_concurrency", "1")
            .setCatalog("tpch")
            .setSchema("tiny")
            .setClientInfo("{\"clientVersion\":\"testVersion\"}")
            .build();
    queryRunner = DistributedQueryRunner.builder(session).setNodeCount(1).build();
    queryRunner.installPlugin(new TpchPlugin());
    queryRunner.installPlugin(new TestingEventListenerPlugin(generatedEvents));
    queryRunner.installPlugin(new ResourceGroupManagerPlugin());
    queryRunner.createCatalog("tpch", "tpch", ImmutableMap.of("tpch.splits-per-node", Integer.toString(SPLITS_PER_NODE)));
    queryRunner.installPlugin(new Plugin()
    {
        @Override
        public Iterable<ConnectorFactory> getConnectorFactories()
        {
            MockConnectorFactory connectorFactory = MockConnectorFactory.builder()
                    .withListTables((session, s) -> ImmutableList.of(new SchemaTableName("default", "test_table")))
                    .withApplyProjection((session, handle, projections, assignments) -> {
                        throw new RuntimeException("Throw from apply projection");
                    })
                    .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);
}
 
Example 19
Source Project: presto   Source File: TestSqlServerPlugin.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateConnector()
{
    Plugin plugin = new SqlServerPlugin();
    ConnectorFactory factory = getOnlyElement(plugin.getConnectorFactories());
    factory.create("test", ImmutableMap.of("connection-url", "test"), new TestingConnectorContext());
}
 
Example 20
Source Project: presto   Source File: TestPostgreSqlPlugin.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateConnector()
{
    Plugin plugin = new PostgreSqlPlugin();
    ConnectorFactory factory = getOnlyElement(plugin.getConnectorFactories());
    factory.create("test", ImmutableMap.of("connection-url", "test"), new TestingConnectorContext());
}
 
Example 21
Source Project: presto   Source File: TestJdbcConnectorFactory.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void test()
{
    ConnectorFactory connectorFactory = new JdbcConnectorFactory("test", new TestingH2JdbcModule());

    connectorFactory.create("test", TestingH2JdbcModule.createProperties(), new TestingConnectorContext());
}
 
Example 22
Source Project: presto   Source File: CountingMockConnector.java    License: Apache License 2.0 5 votes vote down vote up
public Plugin getPlugin()
{
    return new Plugin()
    {
        @Override
        public Iterable<ConnectorFactory> getConnectorFactories()
        {
            return ImmutableList.of(getConnectorFactory());
        }
    };
}
 
Example 23
Source Project: presto   Source File: CountingMockConnector.java    License: Apache License 2.0 5 votes vote down vote up
private ConnectorFactory getConnectorFactory()
{
    MockConnectorFactory mockConnectorFactory = MockConnectorFactory.builder()
            .withListSchemaNames(connectorSession -> {
                listSchemasCallsCounter.incrementAndGet();
                return ImmutableList.of("test_schema1", "test_schema2");
            })
            .withListTables((connectorSession, schemaName) -> {
                listTablesCallsCounter.incrementAndGet();
                if (schemaName.equals("test_schema1")) {
                    return tablesTestSchema1;
                }
                if (schemaName.equals("test_schema2")) {
                    return tablesTestSchema2;
                }
                return ImmutableList.of();
            })
            .withGetColumns(schemaTableName -> {
                getColumnsCallsCounter.incrementAndGet();
                return defaultGetColumns().apply(schemaTableName);
            })
            .withListRoleGrants((connectorSession, roles, grantees, limit) -> {
                listRoleGranstCounter.incrementListRoleGrants(roles, grantees, limit);
                return roleGrants;
            })
            .build();

    return mockConnectorFactory;
}
 
Example 24
Source Project: presto   Source File: TestHiveHadoop2Plugin.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testRubixCacheWithNonExistingCacheDirectory()
{
    Plugin plugin = new HiveHadoop2Plugin();
    ConnectorFactory connectorFactory = Iterables.getOnlyElement(plugin.getConnectorFactories());

    assertThatThrownBy(() -> connectorFactory.create(
            "test",
            ImmutableMap.<String, String>builder()
                    .put("hive.cache.enabled", "true")
                    .put("hive.cache.start-server-on-coordinator", "true")
                    .put("hive.metastore.uri", "thrift://foo:1234")
                    .put("hive.cache.location", "/tmp/non/existing/directory")
                    .build(),
            new TestingConnectorContext())
            .shutdown())
            .hasRootCauseMessage("None of the cache parent directories exists");

    // cache directories should not be required when cache is not explicitly started on coordinator
    connectorFactory.create(
            "test",
            ImmutableMap.<String, String>builder()
                    .put("hive.cache.enabled", "true")
                    .put("hive.metastore.uri", "thrift://foo:1234")
                    .put("hive.cache.location", "/tmp/non/existing/directory")
                    .build(),
            new TestingConnectorContext())
            .shutdown();
}
 
Example 25
Source Project: presto   Source File: ConnectorManager.java    License: Apache License 2.0 5 votes vote down vote up
public synchronized void addConnectorFactory(ConnectorFactory connectorFactory, Supplier<ClassLoader> duplicatePluginClassLoaderFactory)
{
    requireNonNull(connectorFactory, "connectorFactory is null");
    requireNonNull(duplicatePluginClassLoaderFactory, "duplicatePluginClassLoaderFactory is null");
    checkState(!stopped.get(), "ConnectorManager is stopped");
    InternalConnectorFactory existingConnectorFactory = connectorFactories.putIfAbsent(
            connectorFactory.getName(),
            new InternalConnectorFactory(connectorFactory, duplicatePluginClassLoaderFactory));
    checkArgument(existingConnectorFactory == null, "Connector '%s' is already registered", connectorFactory.getName());
}
 
Example 26
Source Project: presto   Source File: TestMongoPlugin.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateConnector()
{
    MongoPlugin plugin = new MongoPlugin();

    ConnectorFactory factory = getOnlyElement(plugin.getConnectorFactories());
    Connector connector = factory.create("test", ImmutableMap.of("mongodb.seeds", seed), new TestingConnectorContext());

    Type type = getOnlyElement(plugin.getTypes());
    assertEquals(type, OBJECT_ID);

    connector.shutdown();
}
 
Example 27
Source Project: presto   Source File: TestThriftPlugin.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testPlugin()
{
    Plugin plugin = new ThriftPlugin();
    ConnectorFactory factory = getOnlyElement(plugin.getConnectorFactories());
    assertInstanceOf(factory, ThriftConnectorFactory.class);

    Map<String, String> config = ImmutableMap.of("presto.thrift.client.addresses", "localhost:7779");

    Connector connector = factory.create("test", config, new TestingConnectorContext());
    assertNotNull(connector);
    assertInstanceOf(connector, ThriftConnector.class);
}
 
Example 28
Source Project: presto   Source File: TestMemSqlPlugin.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateConnector()
{
    Plugin plugin = new MemSqlPlugin();
    ConnectorFactory factory = getOnlyElement(plugin.getConnectorFactories());
    factory.create("test", ImmutableMap.of("connection-url", "jdbc:mariadb://test"), new TestingConnectorContext());
}
 
Example 29
Source Project: presto   Source File: TestBigQueryPlugin.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testStartup()
{
    BigQueryPlugin plugin = new BigQueryPlugin();
    ConnectorFactory factory = getOnlyElement(plugin.getConnectorFactories());
    assertInstanceOf(factory, BigQueryConnectorFactory.class);
}
 
Example 30
Source Project: presto   Source File: TestKuduPlugin.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateConnector()
{
    Plugin plugin = new KuduPlugin();
    ConnectorFactory factory = getOnlyElement(plugin.getConnectorFactories());
    factory.create("test", ImmutableMap.of("kudu.client.master-addresses", "localhost:7051"), new TestingConnectorContext());
}