Search in sources :

Example 21 with ConnectorTransactionHandle

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

the class TestTableWriterOperator method createTableWriterOperator.

private Operator createTableWriterOperator(PageSinkManager pageSinkManager, OperatorFactory statisticsAggregation, List<Type> outputTypes, Session session, TaskMetadataContext taskMetadataContext, DriverContext driverContext) {
    List<String> notNullColumnNames = new ArrayList<>(1);
    notNullColumnNames.add(null);
    TableWriterOperatorFactory factory = new TableWriterOperatorFactory(0, new PlanNodeId("test"), pageSinkManager, new ConnectorMetadataUpdaterManager(), taskMetadataContext, new CreateHandle(new OutputTableHandle(CONNECTOR_ID, new ConnectorTransactionHandle() {
    }, new ConnectorOutputTableHandle() {
    }), new SchemaTableName("testSchema", "testTable")), ImmutableList.of(0), notNullColumnNames, session, statisticsAggregation, outputTypes, TABLE_COMMIT_CONTEXT_CODEC, NO_COMMIT);
    return factory.createOperator(driverContext);
}
Also used : PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) TableWriterOperatorFactory(com.facebook.presto.operator.TableWriterOperator.TableWriterOperatorFactory) OutputTableHandle(com.facebook.presto.metadata.OutputTableHandle) ConnectorOutputTableHandle(com.facebook.presto.spi.ConnectorOutputTableHandle) ConnectorOutputTableHandle(com.facebook.presto.spi.ConnectorOutputTableHandle) CreateHandle(com.facebook.presto.execution.scheduler.ExecutionWriterTarget.CreateHandle) ArrayList(java.util.ArrayList) ConnectorTransactionHandle(com.facebook.presto.spi.connector.ConnectorTransactionHandle) ConnectorMetadataUpdaterManager(com.facebook.presto.metadata.ConnectorMetadataUpdaterManager) SchemaTableName(com.facebook.presto.spi.SchemaTableName)

Example 22 with ConnectorTransactionHandle

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

the class FunctionAssertions method compileScanFilterProject.

private static SourceOperatorFactory compileScanFilterProject(SqlFunctionProperties sqlFunctionProperties, Optional<RowExpression> filter, RowExpression projection, ExpressionCompiler compiler) {
    try {
        Supplier<CursorProcessor> cursorProcessor = compiler.compileCursorProcessor(sqlFunctionProperties, filter, ImmutableList.of(projection), SOURCE_ID);
        Supplier<PageProcessor> pageProcessor = compiler.compilePageProcessor(sqlFunctionProperties, filter, ImmutableList.of(projection));
        return new ScanFilterAndProjectOperator.ScanFilterAndProjectOperatorFactory(0, new PlanNodeId("test"), SOURCE_ID, PAGE_SOURCE_PROVIDER, cursorProcessor, pageProcessor, new TableHandle(new ConnectorId("test"), new ConnectorTableHandle() {
        }, new ConnectorTransactionHandle() {
        }, Optional.empty()), ImmutableList.of(), ImmutableList.of(projection.getType()), Optional.empty(), new DataSize(0, BYTE), 0);
    } catch (Throwable e) {
        if (e instanceof UncheckedExecutionException) {
            e = e.getCause();
        }
        throw new RuntimeException("Error compiling filter " + filter + ": " + e.getMessage(), e);
    }
}
Also used : CursorProcessor(com.facebook.presto.operator.project.CursorProcessor) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) ConnectorTransactionHandle(com.facebook.presto.spi.connector.ConnectorTransactionHandle) ConnectorTableHandle(com.facebook.presto.spi.ConnectorTableHandle) PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) PageProcessor(com.facebook.presto.operator.project.PageProcessor) DataSize(io.airlift.units.DataSize) TableHandle(com.facebook.presto.spi.TableHandle) ConnectorTableHandle(com.facebook.presto.spi.ConnectorTableHandle) ConnectorId(com.facebook.presto.spi.ConnectorId)

Example 23 with ConnectorTransactionHandle

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

the class SystemSplitManager method getSplits.

@Override
public ConnectorSplitSource getSplits(ConnectorTransactionHandle transactionHandle, ConnectorSession session, ConnectorTableLayoutHandle layout, SplitSchedulingContext splitSchedulingContext) {
    SystemTableLayoutHandle layoutHandle = (SystemTableLayoutHandle) layout;
    SystemTableHandle tableHandle = layoutHandle.getTable();
    TupleDomain<ColumnHandle> constraint = layoutHandle.getConstraint();
    SystemTable systemTable = tables.getSystemTable(session, tableHandle.getSchemaTableName()).orElseThrow(() -> new PrestoException(NOT_FOUND, format("Table %s not found", tableHandle.getSchemaTableName())));
    Distribution tableDistributionMode = systemTable.getDistribution();
    if (tableDistributionMode == SINGLE_COORDINATOR) {
        HostAddress address = nodeManager.getCurrentNode().getHostAndPort();
        ConnectorSplit split = new SystemSplit(tableHandle.getConnectorId(), tableHandle, address, constraint);
        return new FixedSplitSource(ImmutableList.of(split));
    }
    ImmutableList.Builder<ConnectorSplit> splits = ImmutableList.builder();
    ImmutableSet.Builder<InternalNode> nodes = ImmutableSet.builder();
    if (tableDistributionMode == ALL_COORDINATORS) {
        nodes.addAll(nodeManager.getCoordinators());
    } else if (tableDistributionMode == ALL_NODES) {
        nodes.addAll(nodeManager.getNodes(ACTIVE).stream().filter(node -> !node.isResourceManager()).collect(toImmutableSet()));
    }
    Set<InternalNode> nodeSet = nodes.build();
    for (InternalNode node : nodeSet) {
        splits.add(new SystemSplit(tableHandle.getConnectorId(), tableHandle, node.getHostAndPort(), constraint));
    }
    return new FixedSplitSource(splits.build());
}
Also used : ALL_COORDINATORS(com.facebook.presto.spi.SystemTable.Distribution.ALL_COORDINATORS) ConnectorSplitSource(com.facebook.presto.spi.ConnectorSplitSource) NOT_FOUND(com.facebook.presto.spi.StandardErrorCode.NOT_FOUND) ConnectorTableLayoutHandle(com.facebook.presto.spi.ConnectorTableLayoutHandle) SINGLE_COORDINATOR(com.facebook.presto.spi.SystemTable.Distribution.SINGLE_COORDINATOR) PrestoException(com.facebook.presto.spi.PrestoException) ConnectorTransactionHandle(com.facebook.presto.spi.connector.ConnectorTransactionHandle) ACTIVE(com.facebook.presto.spi.NodeState.ACTIVE) InternalNodeManager(com.facebook.presto.metadata.InternalNodeManager) ImmutableList(com.google.common.collect.ImmutableList) Objects.requireNonNull(java.util.Objects.requireNonNull) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) SystemTable(com.facebook.presto.spi.SystemTable) ConnectorSplitManager(com.facebook.presto.spi.connector.ConnectorSplitManager) ImmutableSet(com.google.common.collect.ImmutableSet) ALL_NODES(com.facebook.presto.spi.SystemTable.Distribution.ALL_NODES) HostAddress(com.facebook.presto.spi.HostAddress) Set(java.util.Set) FixedSplitSource(com.facebook.presto.spi.FixedSplitSource) TupleDomain(com.facebook.presto.common.predicate.TupleDomain) String.format(java.lang.String.format) InternalNode(com.facebook.presto.metadata.InternalNode) ConnectorSession(com.facebook.presto.spi.ConnectorSession) ConnectorSplit(com.facebook.presto.spi.ConnectorSplit) ColumnHandle(com.facebook.presto.spi.ColumnHandle) Distribution(com.facebook.presto.spi.SystemTable.Distribution) ColumnHandle(com.facebook.presto.spi.ColumnHandle) ImmutableList(com.google.common.collect.ImmutableList) PrestoException(com.facebook.presto.spi.PrestoException) HostAddress(com.facebook.presto.spi.HostAddress) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) ImmutableSet(com.google.common.collect.ImmutableSet) FixedSplitSource(com.facebook.presto.spi.FixedSplitSource) Distribution(com.facebook.presto.spi.SystemTable.Distribution) SystemTable(com.facebook.presto.spi.SystemTable) InternalNode(com.facebook.presto.metadata.InternalNode) ConnectorSplit(com.facebook.presto.spi.ConnectorSplit)

Example 24 with ConnectorTransactionHandle

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

the class TestLocalExchange method testCreatePartitionFunction.

@Test
public void testCreatePartitionFunction() {
    int partitionCount = 10;
    PartitioningProviderManager partitioningProviderManager = new PartitioningProviderManager();
    partitioningProviderManager.addPartitioningProvider(new ConnectorId("prism"), new ConnectorNodePartitioningProvider() {

        @Override
        public ConnectorBucketNodeMap getBucketNodeMap(ConnectorTransactionHandle transactionHandle, ConnectorSession session, ConnectorPartitioningHandle partitioningHandle, List<Node> sortedNodes) {
            return createBucketNodeMap(Stream.generate(() -> sortedNodes).flatMap(List::stream).limit(10).collect(toImmutableList()), SOFT_AFFINITY);
        }

        @Override
        public ToIntFunction<ConnectorSplit> getSplitBucketFunction(ConnectorTransactionHandle transactionHandle, ConnectorSession session, ConnectorPartitioningHandle partitioningHandle) {
            return null;
        }

        @Override
        public BucketFunction getBucketFunction(ConnectorTransactionHandle transactionHandle, ConnectorSession session, ConnectorPartitioningHandle partitioningHandle, List<Type> partitionChannelTypes, int bucketCount) {
            return (Page page, int position) -> partitionCount;
        }

        @Override
        public int getBucketCount(ConnectorTransactionHandle transactionHandle, ConnectorSession session, ConnectorPartitioningHandle partitioningHandle) {
            return 10;
        }
    });
    PartitioningHandle partitioningHandle = new PartitioningHandle(Optional.of(new ConnectorId("prism")), Optional.of(new ConnectorTransactionHandle() {

        @Override
        public int hashCode() {
            return super.hashCode();
        }

        @Override
        public boolean equals(Object obj) {
            return super.equals(obj);
        }
    }), new ConnectorPartitioningHandle() {

        @Override
        public boolean isSingleNode() {
            return false;
        }

        @Override
        public boolean isCoordinatorOnly() {
            return false;
        }
    });
    PartitionFunction partitionFunction = createPartitionFunction(partitioningProviderManager, session, partitioningHandle, 600, ImmutableList.of(), false);
    assertEquals(partitionFunction.getPartitionCount(), partitionCount);
}
Also used : LocalExchange.createPartitionFunction(com.facebook.presto.operator.exchange.LocalExchange.createPartitionFunction) PartitionFunction(com.facebook.presto.operator.PartitionFunction) PartitioningProviderManager(com.facebook.presto.sql.planner.PartitioningProviderManager) Node(com.facebook.presto.spi.Node) ConnectorTransactionHandle(com.facebook.presto.spi.connector.ConnectorTransactionHandle) Page(com.facebook.presto.common.Page) Type(com.facebook.presto.common.type.Type) ConnectorPartitioningHandle(com.facebook.presto.spi.connector.ConnectorPartitioningHandle) ConnectorNodePartitioningProvider(com.facebook.presto.spi.connector.ConnectorNodePartitioningProvider) ConnectorBucketNodeMap(com.facebook.presto.spi.connector.ConnectorBucketNodeMap) ConnectorSession(com.facebook.presto.spi.ConnectorSession) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) ToIntFunction(java.util.function.ToIntFunction) ConnectorPartitioningHandle(com.facebook.presto.spi.connector.ConnectorPartitioningHandle) PartitioningHandle(com.facebook.presto.sql.planner.PartitioningHandle) BucketFunction(com.facebook.presto.spi.BucketFunction) ConnectorId(com.facebook.presto.spi.ConnectorId) Test(org.testng.annotations.Test)

Example 25 with ConnectorTransactionHandle

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

the class MetadataManager method getLayout.

@Override
public TableLayout getLayout(Session session, TableLayoutHandle handle) {
    ConnectorId connectorId = handle.getConnectorId();
    CatalogMetadata catalogMetadata = getCatalogMetadata(session, connectorId);
    ConnectorMetadata metadata = catalogMetadata.getMetadataFor(connectorId);
    ConnectorTransactionHandle transaction = catalogMetadata.getTransactionHandleFor(connectorId);
    return fromConnectorLayout(connectorId, transaction, metadata.getTableLayout(session.toConnectorSession(connectorId), handle.getConnectorHandle()));
}
Also used : ConnectorTransactionHandle(com.facebook.presto.spi.connector.ConnectorTransactionHandle) ConnectorMetadata(com.facebook.presto.spi.connector.ConnectorMetadata) ConnectorId(com.facebook.presto.connector.ConnectorId)

Aggregations

ConnectorTransactionHandle (com.facebook.presto.spi.connector.ConnectorTransactionHandle)40 ConnectorSession (com.facebook.presto.spi.ConnectorSession)18 ColumnHandle (com.facebook.presto.spi.ColumnHandle)13 ConnectorId (com.facebook.presto.spi.ConnectorId)12 ConnectorSplit (com.facebook.presto.spi.ConnectorSplit)12 List (java.util.List)12 Objects.requireNonNull (java.util.Objects.requireNonNull)12 ImmutableList (com.google.common.collect.ImmutableList)11 ConnectorMetadata (com.facebook.presto.spi.connector.ConnectorMetadata)10 Inject (javax.inject.Inject)9 ConnectorTableHandle (com.facebook.presto.spi.ConnectorTableHandle)8 Optional (java.util.Optional)8 ConnectorTableLayoutHandle (com.facebook.presto.spi.ConnectorTableLayoutHandle)7 SchemaTableName (com.facebook.presto.spi.SchemaTableName)7 ImmutableMap (com.google.common.collect.ImmutableMap)7 TupleDomain (com.facebook.presto.common.predicate.TupleDomain)6 Type (com.facebook.presto.common.type.Type)6 Map (java.util.Map)5 ConnectorTableMetadata (com.facebook.presto.spi.ConnectorTableMetadata)4 NodeManager (com.facebook.presto.spi.NodeManager)4