Search in sources :

Example 71 with ConnectorId

use of com.facebook.presto.spi.ConnectorId in project presto by prestodb.

the class SqlTask method getMetadataUpdateRequests.

private MetadataUpdates getMetadataUpdateRequests(TaskHolder taskHolder) {
    ConnectorId connectorId = null;
    ImmutableList.Builder<ConnectorMetadataUpdateHandle> connectorMetadataUpdatesBuilder = ImmutableList.builder();
    if (taskHolder.getTaskExecution() != null) {
        TaskMetadataContext taskMetadataContext = taskHolder.getTaskExecution().getTaskContext().getTaskMetadataContext();
        if (!taskMetadataContext.getMetadataUpdaters().isEmpty()) {
            connectorId = taskMetadataContext.getConnectorId();
            for (ConnectorMetadataUpdater metadataUpdater : taskMetadataContext.getMetadataUpdaters()) {
                connectorMetadataUpdatesBuilder.addAll(metadataUpdater.getPendingMetadataUpdateRequests());
            }
        }
    }
    return new MetadataUpdates(connectorId, connectorMetadataUpdatesBuilder.build());
}
Also used : MetadataUpdates(com.facebook.presto.metadata.MetadataUpdates) ConnectorMetadataUpdater(com.facebook.presto.spi.connector.ConnectorMetadataUpdater) ImmutableList(com.google.common.collect.ImmutableList) ConnectorMetadataUpdateHandle(com.facebook.presto.spi.ConnectorMetadataUpdateHandle) ConnectorId(com.facebook.presto.spi.ConnectorId)

Example 72 with ConnectorId

use of com.facebook.presto.spi.ConnectorId in project presto by prestodb.

the class ApplyConnectorOptimization method buildConnectorPlanNodeContext.

private static ConnectorPlanNodeContext buildConnectorPlanNodeContext(PlanNode node, PlanNode parent, ImmutableMap.Builder<PlanNode, ConnectorPlanNodeContext> contextBuilder) {
    Set<ConnectorId> connectorIds;
    Set<Class<? extends PlanNode>> planNodeTypes;
    if (node.getSources().isEmpty()) {
        if (node instanceof TableScanNode) {
            connectorIds = ImmutableSet.of(((TableScanNode) node).getTable().getConnectorId());
            planNodeTypes = ImmutableSet.of(TableScanNode.class);
        } else {
            connectorIds = ImmutableSet.of(EMPTY_CONNECTOR_ID);
            planNodeTypes = ImmutableSet.of(node.getClass());
        }
    } else {
        connectorIds = new HashSet<>();
        planNodeTypes = new HashSet<>();
        for (PlanNode child : node.getSources()) {
            ConnectorPlanNodeContext childContext = buildConnectorPlanNodeContext(child, node, contextBuilder);
            connectorIds.addAll(childContext.getReachableConnectors());
            planNodeTypes.addAll(childContext.getReachablePlanNodeTypes());
        }
        planNodeTypes.add(node.getClass());
    }
    ConnectorPlanNodeContext connectorPlanNodeContext = new ConnectorPlanNodeContext(parent, connectorIds, planNodeTypes);
    contextBuilder.put(node, connectorPlanNodeContext);
    return connectorPlanNodeContext;
}
Also used : PlanNode(com.facebook.presto.spi.plan.PlanNode) TableScanNode(com.facebook.presto.spi.plan.TableScanNode) ConnectorId(com.facebook.presto.spi.ConnectorId)

Example 73 with ConnectorId

use of com.facebook.presto.spi.ConnectorId in project presto by prestodb.

the class ApplyConnectorOptimization method optimize.

@Override
public PlanNode optimize(PlanNode plan, Session session, TypeProvider types, PlanVariableAllocator variableAllocator, PlanNodeIdAllocator idAllocator, WarningCollector warningCollector) {
    requireNonNull(plan, "plan is null");
    requireNonNull(session, "session is null");
    requireNonNull(types, "types is null");
    requireNonNull(variableAllocator, "variableAllocator is null");
    requireNonNull(idAllocator, "idAllocator is null");
    Map<ConnectorId, Set<ConnectorPlanOptimizer>> connectorOptimizers = connectorOptimizersSupplier.get();
    if (connectorOptimizers.isEmpty()) {
        return plan;
    }
    // retrieve all the connectors
    ImmutableSet.Builder<ConnectorId> connectorIds = ImmutableSet.builder();
    getAllConnectorIds(plan, connectorIds);
    // In order to preserve the fixpoint, we will "pretend" the newly added C2 table scan is part of C1's job to maintain.
    for (ConnectorId connectorId : connectorIds.build()) {
        Set<ConnectorPlanOptimizer> optimizers = connectorOptimizers.get(connectorId);
        if (optimizers == null) {
            continue;
        }
        ImmutableMap.Builder<PlanNode, ConnectorPlanNodeContext> contextMapBuilder = ImmutableMap.builder();
        buildConnectorPlanNodeContext(plan, null, contextMapBuilder);
        Map<PlanNode, ConnectorPlanNodeContext> contextMap = contextMapBuilder.build();
        // keep track of changed nodes; the keys are original nodes and the values are the new nodes
        Map<PlanNode, PlanNode> updates = new HashMap<>();
        // process connector optimizers
        for (PlanNode node : contextMap.keySet()) {
            // For a subtree with root `node` to be a max closure, the following conditions must hold:
            // * The subtree with root `node` is a closure.
            // * `node` has no parent, or the subtree with root as `node`'s parent is not a closure.
            ConnectorPlanNodeContext context = contextMap.get(node);
            if (!context.isClosure(connectorId) || !context.getParent().isPresent() || contextMap.get(context.getParent().get()).isClosure(connectorId)) {
                continue;
            }
            PlanNode newNode = node;
            // the returned node is still a max closure (only if there is no new connector added, which does happen but ignored here)
            for (ConnectorPlanOptimizer optimizer : optimizers) {
                newNode = optimizer.optimize(newNode, session.toConnectorSession(connectorId), variableAllocator, idAllocator);
            }
            if (node != newNode) {
                // the optimizer has allocated a new PlanNode
                checkState(containsAll(ImmutableSet.copyOf(newNode.getOutputVariables()), node.getOutputVariables()), "the connector optimizer from %s returns a node that does not cover all output before optimization", connectorId);
                updates.put(node, newNode);
            }
        }
        // up to this point, we have a set of updated nodes; need to recursively update their parents
        // alter the plan with a bottom-up approach (but does not have to be strict bottom-up to guarantee the correctness of the algorithm)
        // use "original nodes" to keep track of the plan structure and "updates" to keep track of the new nodes
        Queue<PlanNode> originalNodes = new LinkedList<>(updates.keySet());
        while (!originalNodes.isEmpty()) {
            PlanNode originalNode = originalNodes.poll();
            if (!contextMap.get(originalNode).getParent().isPresent()) {
                // originalNode must be the root; update the plan
                plan = updates.get(originalNode);
                continue;
            }
            PlanNode originalParent = contextMap.get(originalNode).getParent().get();
            // need to create a new parent given the child has changed; the new parent needs to point to the new child.
            // if a node has been updated, it will occur in `updates`; otherwise, just use the original node
            ImmutableList.Builder<PlanNode> newChildren = ImmutableList.builder();
            originalParent.getSources().forEach(child -> newChildren.add(updates.getOrDefault(child, child)));
            PlanNode newParent = originalParent.replaceChildren(newChildren.build());
            // mark the new parent as updated
            updates.put(originalParent, newParent);
            // enqueue the parent node in order to recursively update its ancestors
            originalNodes.add(originalParent);
        }
    }
    return plan;
}
Also used : ConnectorPlanOptimizer(com.facebook.presto.spi.ConnectorPlanOptimizer) HashSet(java.util.HashSet) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) HashMap(java.util.HashMap) ImmutableList(com.google.common.collect.ImmutableList) ImmutableMap(com.google.common.collect.ImmutableMap) LinkedList(java.util.LinkedList) PlanNode(com.facebook.presto.spi.plan.PlanNode) ImmutableSet(com.google.common.collect.ImmutableSet) ConnectorId(com.facebook.presto.spi.ConnectorId)

Example 74 with ConnectorId

use of com.facebook.presto.spi.ConnectorId in project presto by prestodb.

the class TestCostCalculator method tableScan.

private TableScanNode tableScan(String id, List<VariableReferenceExpression> variables) {
    ImmutableMap.Builder<VariableReferenceExpression, ColumnHandle> assignments = ImmutableMap.builder();
    for (VariableReferenceExpression variable : variables) {
        assignments.put(variable, new TpchColumnHandle("orderkey", BIGINT));
    }
    TpchTableHandle tableHandle = new TpchTableHandle("orders", 1.0);
    return new TableScanNode(Optional.empty(), new PlanNodeId(id), new TableHandle(new ConnectorId("tpch"), tableHandle, TpchTransactionHandle.INSTANCE, Optional.of(new TpchTableLayoutHandle(tableHandle, TupleDomain.all()))), variables, assignments.build(), TupleDomain.all(), TupleDomain.all());
}
Also used : PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) ColumnHandle(com.facebook.presto.spi.ColumnHandle) TpchColumnHandle(com.facebook.presto.tpch.TpchColumnHandle) TableScanNode(com.facebook.presto.spi.plan.TableScanNode) TpchColumnHandle(com.facebook.presto.tpch.TpchColumnHandle) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) TpchTableHandle(com.facebook.presto.tpch.TpchTableHandle) TableHandle(com.facebook.presto.spi.TableHandle) TpchTableLayoutHandle(com.facebook.presto.tpch.TpchTableLayoutHandle) ImmutableMap(com.google.common.collect.ImmutableMap) TpchTableHandle(com.facebook.presto.tpch.TpchTableHandle) ConnectorId(com.facebook.presto.spi.ConnectorId)

Example 75 with ConnectorId

use of com.facebook.presto.spi.ConnectorId in project presto by prestodb.

the class TestSystemSplit method testSerialization.

@Test
public void testSerialization() {
    ConnectorId connectorId = new ConnectorId("testid");
    SystemTableHandle tableHandle = new SystemTableHandle(connectorId, "xyz", "foo");
    SystemSplit expected = new SystemSplit(connectorId, tableHandle, HostAddress.fromParts("127.0.0.1", 0), TupleDomain.all());
    JsonCodec<SystemSplit> codec = jsonCodec(SystemSplit.class);
    SystemSplit actual = codec.fromJson(codec.toJson(expected));
    assertEquals(actual.getConnectorId(), expected.getConnectorId());
    assertEquals(actual.getTableHandle(), expected.getTableHandle());
    assertEquals(actual.getAddresses(), expected.getAddresses());
    assertEquals(actual.getConstraint(), expected.getConstraint());
}
Also used : ConnectorId(com.facebook.presto.spi.ConnectorId) Test(org.testng.annotations.Test)

Aggregations

ConnectorId (com.facebook.presto.spi.ConnectorId)162 ConnectorMetadata (com.facebook.presto.spi.connector.ConnectorMetadata)75 TableHandle (com.facebook.presto.spi.TableHandle)33 Test (org.testng.annotations.Test)29 ConnectorSession (com.facebook.presto.spi.ConnectorSession)26 ConnectorTableHandle (com.facebook.presto.spi.ConnectorTableHandle)18 PrestoException (com.facebook.presto.spi.PrestoException)18 ConnectorTransactionHandle (com.facebook.presto.spi.connector.ConnectorTransactionHandle)18 Session (com.facebook.presto.Session)16 ImmutableList (com.google.common.collect.ImmutableList)16 QualifiedObjectName (com.facebook.presto.common.QualifiedObjectName)15 List (java.util.List)15 PlanNodeId (com.facebook.presto.spi.plan.PlanNodeId)14 Map (java.util.Map)12 Optional (java.util.Optional)12 InMemoryNodeManager (com.facebook.presto.metadata.InMemoryNodeManager)11 ConnectorOutputTableHandle (com.facebook.presto.spi.ConnectorOutputTableHandle)11 SchemaTableName (com.facebook.presto.spi.SchemaTableName)11 ImmutableMap (com.google.common.collect.ImmutableMap)11 ConnectorInsertTableHandle (com.facebook.presto.spi.ConnectorInsertTableHandle)10