io.prestosql.spi.connector.ConnectorFactory Java Examples

The following examples show how to use io.prestosql.spi.connector.ConnectorFactory. 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 File: TestCoordinatorDynamicFiltering.java    From presto with 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 #2
Source File: TestJmxStats.java    From presto with 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 #3
Source File: TestHiveHadoop2Plugin.java    From presto with 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 #4
Source File: TestHiveHadoop2Plugin.java    From presto with 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 #5
Source File: TestHiveHadoop2Plugin.java    From presto with 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 #6
Source File: TestKinesisPlugin.java    From presto with 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 #7
Source File: TestHiveHadoop2Plugin.java    From presto with 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 #8
Source File: TestKinesisPlugin.java    From presto with 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 #9
Source File: TestMetadataManager.java    From presto with 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 #10
Source File: TestBeginQuery.java    From presto with 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 #11
Source File: TestConnectorEventListener.java    From presto with 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 #12
Source File: TestSystemConnector.java    From presto with 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 #13
Source File: RaptorBenchmarkQueryRunner.java    From presto with 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 File: TestRedisPlugin.java    From presto with 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 #15
Source File: TestRaptorPlugin.java    From presto with 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 #16
Source File: TestKafkaPlugin.java    From presto with 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 #17
Source File: TestEventListener.java    From presto with 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 #18
Source File: TestSheetsPlugin.java    From presto with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateConnector()
        throws Exception
{
    Plugin plugin = new SheetsPlugin();
    ConnectorFactory factory = getOnlyElement(plugin.getConnectorFactories());
    Builder<String, String> propertiesMap = new Builder<String, String>().put("credentials-path", getTestCredentialsPath()).put("metadata-sheet-id", TEST_METADATA_SHEET_ID);
    Connector c = factory.create(GOOGLE_SHEETS, propertiesMap.build(), new TestingConnectorContext());
    assertNotNull(c);
}
 
Example #19
Source File: TestDruidJdbcPlugin.java    From presto with 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 #20
Source File: TestSqlServerPlugin.java    From presto with 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 #21
Source File: TestPostgreSqlPlugin.java    From presto with 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 #22
Source File: CountingMockConnector.java    From presto with 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 File: TestHiveHadoop2Plugin.java    From presto with 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 #24
Source File: ConnectorManager.java    From presto with 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 #25
Source File: KinesisPlugin.java    From presto with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized Iterable<ConnectorFactory> getConnectorFactories()
{
    if (factory == null) {
        this.factory = new KinesisConnectorFactory();
    }
    return ImmutableList.of(this.factory);
}
 
Example #26
Source File: TestKuduPlugin.java    From presto with 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());
}
 
Example #27
Source File: TestMongoPlugin.java    From presto with 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 #28
Source File: TestBigQueryPlugin.java    From presto with 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 #29
Source File: TestMemSqlPlugin.java    From presto with 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 #30
Source File: TestThriftPlugin.java    From presto with 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);
}