Search in sources :

Example 21 with Connector

use of io.trino.spi.connector.Connector in project trino by trinodb.

the class TestThriftPlugin method testPlugin.

@Test
public void testPlugin() {
    Plugin plugin = new ThriftPlugin();
    ConnectorFactory factory = getOnlyElement(plugin.getConnectorFactories());
    assertInstanceOf(factory, ThriftConnectorFactory.class);
    Map<String, String> config = ImmutableMap.of("trino.thrift.client.addresses", "localhost:7779");
    Connector connector = factory.create("test", config, new TestingConnectorContext());
    assertNotNull(connector);
    assertInstanceOf(connector, ThriftConnector.class);
    connector.shutdown();
}
Also used : Connector(io.trino.spi.connector.Connector) ConnectorFactory(io.trino.spi.connector.ConnectorFactory) TestingConnectorContext(io.trino.testing.TestingConnectorContext) Plugin(io.trino.spi.Plugin) Test(org.testng.annotations.Test)

Example 22 with Connector

use of io.trino.spi.connector.Connector in project trino by trinodb.

the class TpchConnectorFactory method create.

@Override
public Connector create(String catalogName, Map<String, String> properties, ConnectorContext context) {
    int splitsPerNode = getSplitsPerNode(properties);
    ColumnNaming columnNaming = ColumnNaming.valueOf(properties.getOrDefault(TPCH_COLUMN_NAMING_PROPERTY, ColumnNaming.SIMPLIFIED.name()).toUpperCase(ENGLISH));
    DecimalTypeMapping decimalTypeMapping = DecimalTypeMapping.valueOf(properties.getOrDefault(TPCH_DOUBLE_TYPE_MAPPING_PROPERTY, DecimalTypeMapping.DOUBLE.name()).toUpperCase(ENGLISH));
    NodeManager nodeManager = context.getNodeManager();
    return new Connector() {

        @Override
        public ConnectorTransactionHandle beginTransaction(IsolationLevel isolationLevel, boolean readOnly, boolean autoCommit) {
            return TpchTransactionHandle.INSTANCE;
        }

        @Override
        public ConnectorMetadata getMetadata(ConnectorSession session, ConnectorTransactionHandle transaction) {
            return new TpchMetadata(columnNaming, decimalTypeMapping, predicatePushdownEnabled, partitioningEnabled, getTpchTableScanRedirectionCatalog(properties), getTpchTableScanRedirectionSchema(properties));
        }

        @Override
        public ConnectorSplitManager getSplitManager() {
            return new TpchSplitManager(nodeManager, splitsPerNode);
        }

        @Override
        public ConnectorPageSourceProvider getPageSourceProvider() {
            if (isProducePages(properties)) {
                return new TpchPageSourceProvider(getMaxRowsPerPage(properties), decimalTypeMapping);
            }
            throw new UnsupportedOperationException();
        }

        @Override
        public ConnectorRecordSetProvider getRecordSetProvider() {
            if (!isProducePages(properties)) {
                return new TpchRecordSetProvider(decimalTypeMapping);
            }
            throw new UnsupportedOperationException();
        }

        @Override
        public ConnectorNodePartitioningProvider getNodePartitioningProvider() {
            return new TpchNodePartitioningProvider(nodeManager, splitsPerNode);
        }
    };
}
Also used : Connector(io.trino.spi.connector.Connector) IsolationLevel(io.trino.spi.transaction.IsolationLevel) ConnectorTransactionHandle(io.trino.spi.connector.ConnectorTransactionHandle) NodeManager(io.trino.spi.NodeManager) ConnectorSession(io.trino.spi.connector.ConnectorSession)

Example 23 with Connector

use of io.trino.spi.connector.Connector in project trino by trinodb.

the class TpcdsConnectorFactory method create.

@Override
public Connector create(String catalogName, Map<String, String> config, ConnectorContext context) {
    int splitsPerNode = getSplitsPerNode(config);
    NodeManager nodeManager = context.getNodeManager();
    return new Connector() {

        @Override
        public ConnectorTransactionHandle beginTransaction(IsolationLevel isolationLevel, boolean readOnly, boolean autoCommit) {
            return TpcdsTransactionHandle.INSTANCE;
        }

        @Override
        public ConnectorMetadata getMetadata(ConnectorSession session, ConnectorTransactionHandle transactionHandle) {
            return new TpcdsMetadata();
        }

        @Override
        public ConnectorSplitManager getSplitManager() {
            return new TpcdsSplitManager(nodeManager, splitsPerNode, isWithNoSexism(config));
        }

        @Override
        public ConnectorRecordSetProvider getRecordSetProvider() {
            return new TpcdsRecordSetProvider();
        }

        @Override
        public ConnectorNodePartitioningProvider getNodePartitioningProvider() {
            return new TpcdsNodePartitioningProvider(nodeManager, splitsPerNode);
        }
    };
}
Also used : NodeManager(io.trino.spi.NodeManager) Connector(io.trino.spi.connector.Connector) IsolationLevel(io.trino.spi.transaction.IsolationLevel) ConnectorTransactionHandle(io.trino.spi.connector.ConnectorTransactionHandle) ConnectorSession(io.trino.spi.connector.ConnectorSession)

Aggregations

Connector (io.trino.spi.connector.Connector)23 ConnectorFactory (io.trino.spi.connector.ConnectorFactory)15 TestingConnectorContext (io.trino.testing.TestingConnectorContext)14 Test (org.testng.annotations.Test)12 NodeManager (io.trino.spi.NodeManager)6 ThreadContextClassLoader (io.trino.spi.classloader.ThreadContextClassLoader)5 ConnectorContext (io.trino.spi.connector.ConnectorContext)5 ConnectorTransactionHandle (io.trino.spi.connector.ConnectorTransactionHandle)5 Map (java.util.Map)5 Injector (com.google.inject.Injector)4 Bootstrap (io.airlift.bootstrap.Bootstrap)4 JsonModule (io.airlift.json.JsonModule)4 PageIndexerFactory (io.trino.spi.PageIndexerFactory)4 ConnectorNodePartitioningProvider (io.trino.spi.connector.ConnectorNodePartitioningProvider)4 ConnectorPageSinkProvider (io.trino.spi.connector.ConnectorPageSinkProvider)4 ConnectorPageSourceProvider (io.trino.spi.connector.ConnectorPageSourceProvider)4 ConnectorSplitManager (io.trino.spi.connector.ConnectorSplitManager)4 TableProcedureMetadata (io.trino.spi.connector.TableProcedureMetadata)4 Procedure (io.trino.spi.procedure.Procedure)4 Optional (java.util.Optional)4