Search in sources :

Example 1 with Connector

use of com.facebook.presto.spi.connector.Connector in project presto by prestodb.

the class TestAnalyzer method createTestingCatalog.

private Catalog createTestingCatalog(String catalogName, ConnectorId connectorId) {
    ConnectorId systemId = createSystemTablesConnectorId(connectorId);
    Connector connector = createTestingConnector();
    InternalNodeManager nodeManager = new InMemoryNodeManager();
    return new Catalog(catalogName, connectorId, connector, createInformationSchemaConnectorId(connectorId), new InformationSchemaConnector(catalogName, nodeManager, metadata, accessControl), systemId, new SystemConnector(systemId, nodeManager, connector.getSystemTables(), transactionId -> transactionManager.getConnectorTransaction(transactionId, connectorId)));
}
Also used : SystemConnector(com.facebook.presto.connector.system.SystemConnector) QualifiedObjectName(com.facebook.presto.metadata.QualifiedObjectName) TablePropertyManager(com.facebook.presto.metadata.TablePropertyManager) TypeManager(com.facebook.presto.spi.type.TypeManager) MetadataManager(com.facebook.presto.metadata.MetadataManager) MISSING_SCHEMA(com.facebook.presto.sql.analyzer.SemanticErrorCode.MISSING_SCHEMA) TypeRegistry(com.facebook.presto.type.TypeRegistry) APPLY_FUNCTION(com.facebook.presto.operator.scalar.ApplyFunction.APPLY_FUNCTION) MISMATCHED_COLUMN_ALIASES(com.facebook.presto.sql.analyzer.SemanticErrorCode.MISMATCHED_COLUMN_ALIASES) Test(org.testng.annotations.Test) ConnectorTransactionHandle(com.facebook.presto.spi.connector.ConnectorTransactionHandle) VIEW_IS_RECURSIVE(com.facebook.presto.sql.analyzer.SemanticErrorCode.VIEW_IS_RECURSIVE) BIGINT(com.facebook.presto.spi.type.BigintType.BIGINT) CATALOG_NOT_SPECIFIED(com.facebook.presto.sql.analyzer.SemanticErrorCode.CATALOG_NOT_SPECIFIED) NON_NUMERIC_SAMPLE_PERCENTAGE(com.facebook.presto.sql.analyzer.SemanticErrorCode.NON_NUMERIC_SAMPLE_PERCENTAGE) InternalNodeManager(com.facebook.presto.metadata.InternalNodeManager) SchemaTableName(com.facebook.presto.spi.SchemaTableName) MISMATCHED_SET_COLUMN_TYPES(com.facebook.presto.sql.analyzer.SemanticErrorCode.MISMATCHED_SET_COLUMN_TYPES) INVALID_WINDOW_FRAME(com.facebook.presto.sql.analyzer.SemanticErrorCode.INVALID_WINDOW_FRAME) TransactionBuilder.transaction(com.facebook.presto.transaction.TransactionBuilder.transaction) SCHEMA_NOT_SPECIFIED(com.facebook.presto.sql.analyzer.SemanticErrorCode.SCHEMA_NOT_SPECIFIED) ORDER_BY_MUST_BE_IN_SELECT(com.facebook.presto.sql.analyzer.SemanticErrorCode.ORDER_BY_MUST_BE_IN_SELECT) WILDCARD_WITHOUT_FROM(com.facebook.presto.sql.analyzer.SemanticErrorCode.WILDCARD_WITHOUT_FROM) ConnectorSplitManager(com.facebook.presto.spi.connector.ConnectorSplitManager) COLUMN_TYPE_UNKNOWN(com.facebook.presto.sql.analyzer.SemanticErrorCode.COLUMN_TYPE_UNKNOWN) MUST_BE_AGGREGATION_FUNCTION(com.facebook.presto.sql.analyzer.SemanticErrorCode.MUST_BE_AGGREGATION_FUNCTION) Collections.emptyList(java.util.Collections.emptyList) INVALID_SCHEMA_NAME(com.facebook.presto.sql.analyzer.SemanticErrorCode.INVALID_SCHEMA_NAME) BeforeMethod(org.testng.annotations.BeforeMethod) VARCHAR(com.facebook.presto.spi.type.VarcharType.VARCHAR) MISSING_ATTRIBUTE(com.facebook.presto.sql.analyzer.SemanticErrorCode.MISSING_ATTRIBUTE) NESTED_WINDOW(com.facebook.presto.sql.analyzer.SemanticErrorCode.NESTED_WINDOW) NOT_SUPPORTED(com.facebook.presto.sql.analyzer.SemanticErrorCode.NOT_SUPPORTED) VIEW_ANALYSIS_ERROR(com.facebook.presto.sql.analyzer.SemanticErrorCode.VIEW_ANALYSIS_ERROR) TestingMetadata(com.facebook.presto.testing.TestingMetadata) SchemaPropertyManager(com.facebook.presto.metadata.SchemaPropertyManager) String.format(java.lang.String.format) SqlParser(com.facebook.presto.sql.parser.SqlParser) AMBIGUOUS_ATTRIBUTE(com.facebook.presto.sql.analyzer.SemanticErrorCode.AMBIGUOUS_ATTRIBUTE) ColumnMetadata(com.facebook.presto.spi.ColumnMetadata) MISSING_COLUMN(com.facebook.presto.sql.analyzer.SemanticErrorCode.MISSING_COLUMN) Catalog(com.facebook.presto.metadata.Catalog) ConnectorId.createSystemTablesConnectorId(com.facebook.presto.connector.ConnectorId.createSystemTablesConnectorId) Optional(java.util.Optional) STANDALONE_LAMBDA(com.facebook.presto.sql.analyzer.SemanticErrorCode.STANDALONE_LAMBDA) ConnectorId(com.facebook.presto.connector.ConnectorId) SystemConnector(com.facebook.presto.connector.system.SystemConnector) AllowAllAccessControl(com.facebook.presto.security.AllowAllAccessControl) JsonCodec(io.airlift.json.JsonCodec) CANNOT_HAVE_AGGREGATIONS_OR_WINDOWS(com.facebook.presto.sql.analyzer.SemanticErrorCode.CANNOT_HAVE_AGGREGATIONS_OR_WINDOWS) ConnectorMetadata(com.facebook.presto.spi.connector.ConnectorMetadata) DOUBLE(com.facebook.presto.spi.type.DoubleType.DOUBLE) WINDOW_REQUIRES_OVER(com.facebook.presto.sql.analyzer.SemanticErrorCode.WINDOW_REQUIRES_OVER) DUPLICATE_RELATION(com.facebook.presto.sql.analyzer.SemanticErrorCode.DUPLICATE_RELATION) ViewDefinition(com.facebook.presto.metadata.ViewDefinition) ArrayType(com.facebook.presto.type.ArrayType) AccessControlManager(com.facebook.presto.security.AccessControlManager) TYPE_MISMATCH(com.facebook.presto.sql.analyzer.SemanticErrorCode.TYPE_MISMATCH) MULTIPLE_FIELDS_FROM_SUBQUERY(com.facebook.presto.sql.analyzer.SemanticErrorCode.MULTIPLE_FIELDS_FROM_SUBQUERY) COLUMN_NAME_NOT_SPECIFIED(com.facebook.presto.sql.analyzer.SemanticErrorCode.COLUMN_NAME_NOT_SPECIFIED) NESTED_AGGREGATION(com.facebook.presto.sql.analyzer.SemanticErrorCode.NESTED_AGGREGATION) INVALID_ORDINAL(com.facebook.presto.sql.analyzer.SemanticErrorCode.INVALID_ORDINAL) InformationSchemaConnector(com.facebook.presto.connector.informationSchema.InformationSchemaConnector) MISSING_CATALOG(com.facebook.presto.sql.analyzer.SemanticErrorCode.MISSING_CATALOG) ImmutableList(com.google.common.collect.ImmutableList) SessionPropertyManager(com.facebook.presto.metadata.SessionPropertyManager) TransactionManager(com.facebook.presto.transaction.TransactionManager) InMemoryNodeManager(com.facebook.presto.metadata.InMemoryNodeManager) INVALID_LITERAL(com.facebook.presto.sql.analyzer.SemanticErrorCode.INVALID_LITERAL) ConnectorTableMetadata(com.facebook.presto.spi.ConnectorTableMetadata) Connector(com.facebook.presto.spi.connector.Connector) Language(org.intellij.lang.annotations.Language) MISSING_TABLE(com.facebook.presto.sql.analyzer.SemanticErrorCode.MISSING_TABLE) Session(com.facebook.presto.Session) NodeLocation(com.facebook.presto.sql.tree.NodeLocation) MUST_BE_AGGREGATE_OR_GROUP_BY(com.facebook.presto.sql.analyzer.SemanticErrorCode.MUST_BE_AGGREGATE_OR_GROUP_BY) Assert.fail(org.testng.Assert.fail) TestingSession.testSessionBuilder(com.facebook.presto.testing.TestingSession.testSessionBuilder) SAMPLE_PERCENTAGE_OUT_OF_RANGE(com.facebook.presto.sql.analyzer.SemanticErrorCode.SAMPLE_PERCENTAGE_OUT_OF_RANGE) CatalogManager(com.facebook.presto.metadata.CatalogManager) VIEW_IS_STALE(com.facebook.presto.sql.analyzer.SemanticErrorCode.VIEW_IS_STALE) Consumer(java.util.function.Consumer) ConnectorId.createInformationSchemaConnectorId(com.facebook.presto.connector.ConnectorId.createInformationSchemaConnectorId) IsolationLevel(com.facebook.presto.spi.transaction.IsolationLevel) ViewColumn(com.facebook.presto.metadata.ViewDefinition.ViewColumn) DUPLICATE_COLUMN_NAME(com.facebook.presto.sql.analyzer.SemanticErrorCode.DUPLICATE_COLUMN_NAME) TransactionManager.createTestTransactionManager(com.facebook.presto.transaction.TransactionManager.createTestTransactionManager) BlockEncodingManager(com.facebook.presto.block.BlockEncodingManager) Metadata(com.facebook.presto.metadata.Metadata) AccessControl(com.facebook.presto.security.AccessControl) Statement(com.facebook.presto.sql.tree.Statement) SystemConnector(com.facebook.presto.connector.system.SystemConnector) InformationSchemaConnector(com.facebook.presto.connector.informationSchema.InformationSchemaConnector) Connector(com.facebook.presto.spi.connector.Connector) InformationSchemaConnector(com.facebook.presto.connector.informationSchema.InformationSchemaConnector) InternalNodeManager(com.facebook.presto.metadata.InternalNodeManager) Catalog(com.facebook.presto.metadata.Catalog) ConnectorId.createSystemTablesConnectorId(com.facebook.presto.connector.ConnectorId.createSystemTablesConnectorId) ConnectorId(com.facebook.presto.connector.ConnectorId) ConnectorId.createInformationSchemaConnectorId(com.facebook.presto.connector.ConnectorId.createInformationSchemaConnectorId) InMemoryNodeManager(com.facebook.presto.metadata.InMemoryNodeManager)

Example 2 with Connector

use of com.facebook.presto.spi.connector.Connector in project presto by prestodb.

the class TestTransactionManager method testTransactionWorkflow.

@Test
public void testTransactionWorkflow() {
    try (IdleCheckExecutor executor = new IdleCheckExecutor()) {
        CatalogManager catalogManager = new CatalogManager();
        TransactionManager transactionManager = InMemoryTransactionManager.create(new TransactionManagerConfig(), executor.getExecutor(), catalogManager, finishingExecutor);
        Connector c1 = new TpchConnectorFactory().create(CATALOG_NAME, ImmutableMap.of(), new TestingConnectorContext());
        registerConnector(catalogManager, transactionManager, CATALOG_NAME, CONNECTOR_ID, c1);
        TransactionId transactionId = transactionManager.beginTransaction(false);
        assertEquals(transactionManager.getAllTransactionInfos().size(), 1);
        TransactionInfo transactionInfo = transactionManager.getTransactionInfo(transactionId);
        assertFalse(transactionInfo.isAutoCommitContext());
        assertTrue(transactionInfo.getConnectorIds().isEmpty());
        assertFalse(transactionInfo.getWrittenConnectorId().isPresent());
        ConnectorMetadata metadata = transactionManager.getOptionalCatalogMetadata(transactionId, CATALOG_NAME).get().getMetadata();
        metadata.listSchemaNames(TEST_SESSION.toConnectorSession(CONNECTOR_ID));
        transactionInfo = transactionManager.getTransactionInfo(transactionId);
        assertEquals(transactionInfo.getConnectorIds(), ImmutableList.of(CONNECTOR_ID, INFORMATION_SCHEMA_ID, SYSTEM_TABLES_ID));
        assertFalse(transactionInfo.getWrittenConnectorId().isPresent());
        getFutureValue(transactionManager.asyncCommit(transactionId));
        assertTrue(transactionManager.getAllTransactionInfos().isEmpty());
    }
}
Also used : InformationSchemaConnector(com.facebook.presto.connector.informationSchema.InformationSchemaConnector) Connector(com.facebook.presto.spi.connector.Connector) SystemConnector(com.facebook.presto.connector.system.SystemConnector) TpchConnectorFactory(com.facebook.presto.tpch.TpchConnectorFactory) TestingConnectorContext(com.facebook.presto.testing.TestingConnectorContext) ConnectorMetadata(com.facebook.presto.spi.connector.ConnectorMetadata) CatalogManager(com.facebook.presto.metadata.CatalogManager) Test(org.testng.annotations.Test)

Example 3 with Connector

use of com.facebook.presto.spi.connector.Connector in project presto by prestodb.

the class TestRedisPlugin method testStartup.

@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);
}
Also used : Connector(com.facebook.presto.spi.connector.Connector) ConnectorFactory(com.facebook.presto.spi.connector.ConnectorFactory) TestingConnectorContext(com.facebook.presto.testing.TestingConnectorContext) Test(org.testng.annotations.Test)

Example 4 with Connector

use of com.facebook.presto.spi.connector.Connector in project presto by prestodb.

the class IndexedTpchConnectorFactory method create.

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

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

        @Override
        public ConnectorMetadata getMetadata(ConnectorTransactionHandle transactionHandle) {
            return new TpchIndexMetadata(catalogName, indexedData);
        }

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

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

        @Override
        public ConnectorIndexProvider getIndexProvider() {
            return new TpchIndexProvider(indexedData);
        }

        @Override
        public Set<SystemTable> getSystemTables() {
            return ImmutableSet.of(new ExampleSystemTable());
        }

        @Override
        public ConnectorNodePartitioningProvider getNodePartitioningProvider() {
            return new TpchNodePartitioningProvider(nodeManager, splitsPerNode);
        }
    };
}
Also used : Connector(com.facebook.presto.spi.connector.Connector) IsolationLevel(com.facebook.presto.spi.transaction.IsolationLevel) ConnectorTransactionHandle(com.facebook.presto.spi.connector.ConnectorTransactionHandle) TpchSplitManager(com.facebook.presto.tpch.TpchSplitManager) NodeManager(com.facebook.presto.spi.NodeManager) TpchNodePartitioningProvider(com.facebook.presto.tpch.TpchNodePartitioningProvider) SystemTable(com.facebook.presto.spi.SystemTable) TpchRecordSetProvider(com.facebook.presto.tpch.TpchRecordSetProvider)

Example 5 with Connector

use of com.facebook.presto.spi.connector.Connector in project presto by prestodb.

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());
    NodeManager nodeManager = context.getNodeManager();
    return new Connector() {

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

        @Override
        public ConnectorMetadata getMetadata(ConnectorTransactionHandle transaction) {
            return new TpchMetadata(catalogName, columnNaming, predicatePushdownEnabled, isPartitioningEnabled(properties));
        }

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

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

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

Aggregations

Connector (com.facebook.presto.spi.connector.Connector)19 TestingConnectorContext (com.facebook.presto.testing.TestingConnectorContext)11 Test (org.testng.annotations.Test)9 InformationSchemaConnector (com.facebook.presto.connector.informationSchema.InformationSchemaConnector)8 SystemConnector (com.facebook.presto.connector.system.SystemConnector)8 ConnectorFactory (com.facebook.presto.spi.connector.ConnectorFactory)7 CatalogManager (com.facebook.presto.metadata.CatalogManager)6 ConnectorTransactionHandle (com.facebook.presto.spi.connector.ConnectorTransactionHandle)6 ConnectorMetadata (com.facebook.presto.spi.connector.ConnectorMetadata)5 Catalog (com.facebook.presto.metadata.Catalog)4 IsolationLevel (com.facebook.presto.spi.transaction.IsolationLevel)4 TpchConnectorFactory (com.facebook.presto.tpch.TpchConnectorFactory)4 InMemoryNodeManager (com.facebook.presto.metadata.InMemoryNodeManager)3 InternalNodeManager (com.facebook.presto.metadata.InternalNodeManager)3 MetadataManager (com.facebook.presto.metadata.MetadataManager)3 AccessControlManager (com.facebook.presto.security.AccessControlManager)3 NodeManager (com.facebook.presto.spi.NodeManager)3 Session (com.facebook.presto.Session)2 ConnectorId (com.facebook.presto.spi.ConnectorId)2 ConnectorId.createInformationSchemaConnectorId (com.facebook.presto.spi.ConnectorId.createInformationSchemaConnectorId)2