Search in sources :

Example 11 with LogicalBinaryVertex

use of com.alibaba.maxgraph.compiler.logical.LogicalBinaryVertex in project GraphScope by alibaba.

the class CostEstimator method costOperator.

/**
 * This method computes the cost of an operator. The cost is composed of cost for input shipping,
 * locally processing an input, and running the operator.
 * <p>
 * It requires at least that all inputs are set and have a proper ship strategy set,
 * which is not equal to <tt>NONE</tt>.
 *
 * @param queryPlan The given query plan
 * @param vertex    The node to compute the costs for.
 */
private Costs costOperator(LogicalQueryPlan queryPlan, LogicalVertex vertex) {
    Costs costs = new Costs();
    if (vertex instanceof LogicalSourceVertex) {
        if (vertex instanceof LogicalSourceDelegateVertex) {
            LogicalSourceDelegateVertex logicalSourceDelegateVertex = LogicalSourceDelegateVertex.class.cast(vertex);
            LogicalVertex delegateVertex = logicalSourceDelegateVertex.getDelegateVertex();
            costs.setCpuCost(delegateVertex.getEstimatedNumRecords());
            costs.setNetworkCost(delegateVertex.getEstimatedOutputSize());
        } else {
            costs.setCpuCost(vertex.getEstimatedNumRecords());
            costs.setNetworkCost(0);
        }
    } else if (vertex instanceof LogicalUnaryVertex) {
        LogicalUnaryVertex unaryVertex = LogicalUnaryVertex.class.cast(vertex);
        LogicalVertex inputVertex = unaryVertex.getInputVertex();
        LogicalEdge logicalEdge = queryPlan.getLogicalEdge(inputVertex, unaryVertex);
        if (null != logicalEdge && logicalEdge.getShuffleType() != EdgeShuffleType.FORWARD) {
            costs.setNetworkCost(inputVertex.getEstimatedOutputSize());
        } else {
            costs.setNetworkCost(0);
        }
        costs.setCpuCost(inputVertex.getEstimatedNumRecords() * getOperatorFactor(vertex.getProcessorFunction()));
    } else {
        LogicalBinaryVertex logicalBinaryVertex = LogicalBinaryVertex.class.cast(vertex);
        LogicalVertex leftVertex = logicalBinaryVertex.getLeftInput();
        double networkCost = 0;
        if (queryPlan.getLogicalEdge(leftVertex, logicalBinaryVertex).getShuffleType() != EdgeShuffleType.FORWARD) {
            networkCost += leftVertex.getEstimatedOutputSize();
        }
        LogicalVertex rightVertex = logicalBinaryVertex.getRightInput();
        if (queryPlan.getLogicalEdge(rightVertex, logicalBinaryVertex).getShuffleType() != EdgeShuffleType.FORWARD) {
            networkCost += rightVertex.getEstimatedOutputSize();
        }
        costs.setNetworkCost(networkCost);
        costs.setCpuCost(leftVertex.getEstimatedNumRecords() * 2 + rightVertex.getEstimatedNumRecords());
    }
    return costs;
}
Also used : LogicalSourceVertex(com.alibaba.maxgraph.compiler.logical.LogicalSourceVertex) LogicalUnaryVertex(com.alibaba.maxgraph.compiler.logical.LogicalUnaryVertex) LogicalVertex(com.alibaba.maxgraph.compiler.logical.LogicalVertex) LogicalSourceDelegateVertex(com.alibaba.maxgraph.compiler.logical.LogicalSourceDelegateVertex) LogicalEdge(com.alibaba.maxgraph.compiler.logical.LogicalEdge) LogicalBinaryVertex(com.alibaba.maxgraph.compiler.logical.LogicalBinaryVertex)

Example 12 with LogicalBinaryVertex

use of com.alibaba.maxgraph.compiler.logical.LogicalBinaryVertex in project GraphScope by alibaba.

the class RatioEdgeVertexTreeNode method buildLogicalQueryPlan.

@Override
public LogicalSubQueryPlan buildLogicalQueryPlan(ContextManager contextManager) {
    TreeNodeLabelManager labelManager = contextManager.getTreeNodeLabelManager();
    VertexIdManager vertexIdManager = contextManager.getVertexIdManager();
    TreeNode inputNode = this.getInputNode();
    LogicalVertex inputVertex = inputNode.getOutputVertex();
    TreeNode sourceNode = UnaryTreeNode.class.cast(inputNode).getInputNode();
    LogicalVertex sourceVertex = sourceNode.getOutputVertex();
    LogicalSubQueryPlan logicalSubQueryPlan = new LogicalSubQueryPlan(contextManager);
    logicalSubQueryPlan.addLogicalVertex(inputVertex);
    logicalSubQueryPlan.addLogicalVertex(sourceVertex);
    ProcessorFunction countFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.COUNT);
    LogicalUnaryVertex countVertex = new LogicalUnaryVertex(vertexIdManager.getId(), countFunction, false, sourceVertex);
    logicalSubQueryPlan.addLogicalVertex(countVertex);
    LogicalEdge countEdge = new LogicalEdge(EdgeShuffleType.SHUFFLE_BY_CONST);
    countEdge.setStreamIndex(1);
    logicalSubQueryPlan.addLogicalEdge(sourceVertex, countVertex, countEdge);
    ProcessorFunction enterKeyFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.ENTER_KEY, Message.Value.newBuilder().setPayload(QueryFlowOuterClass.EnterKeyArgumentProto.newBuilder().setEnterKeyType(QueryFlowOuterClass.EnterKeyTypeProto.KEY_SELF).setUniqFlag(true).build().toByteString()));
    LogicalVertex enterKeyVertex = new LogicalUnaryVertex(vertexIdManager.getId(), enterKeyFunction, false, sourceVertex);
    logicalSubQueryPlan.addLogicalVertex(enterKeyVertex);
    logicalSubQueryPlan.addLogicalEdge(sourceVertex, enterKeyVertex, new LogicalEdge(EdgeShuffleType.FORWARD));
    ProcessorFunction valueFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.valueOf(direction.name() + "_V"));
    LogicalUnaryVertex valueVertex = new LogicalUnaryVertex(vertexIdManager.getId(), valueFunction, false, enterKeyVertex);
    logicalSubQueryPlan.addLogicalVertex(valueVertex);
    LogicalEdge valueEdge = new LogicalEdge(EdgeShuffleType.SHUFFLE_BY_KEY);
    logicalSubQueryPlan.addLogicalEdge(enterKeyVertex, valueVertex, valueEdge);
    ProcessorFunction countByKeyFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.COUNT_BY_KEY, Message.Value.newBuilder().addIntValueList(0));
    LogicalUnaryVertex countByKeyVertex = new LogicalUnaryVertex(vertexIdManager.getId(), countByKeyFunction, false, valueVertex);
    logicalSubQueryPlan.addLogicalVertex(countByKeyVertex);
    logicalSubQueryPlan.addLogicalEdge(valueVertex, countByKeyVertex, new LogicalEdge(EdgeShuffleType.SHUFFLE_BY_KEY));
    ProcessorFunction ratioFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.JOIN_RATIO, Message.Value.newBuilder().setIntValue(CompilerUtils.parseCompareType(predicate, predicate.getBiPredicate()).getNumber()).setDoubleValue(Double.parseDouble(predicate.getValue().toString())));
    LogicalBinaryVertex logicalBinaryVertex = new LogicalBinaryVertex(vertexIdManager.getId(), ratioFunction, true, countVertex, countByKeyVertex);
    logicalSubQueryPlan.addLogicalVertex(logicalBinaryVertex);
    logicalSubQueryPlan.addLogicalEdge(countVertex, logicalBinaryVertex, new LogicalEdge(EdgeShuffleType.BROADCAST));
    logicalSubQueryPlan.addLogicalEdge(countByKeyVertex, logicalBinaryVertex, new LogicalEdge(EdgeShuffleType.FORWARD));
    setFinishVertex(logicalBinaryVertex, labelManager);
    addUsedLabelAndRequirement(logicalBinaryVertex, labelManager);
    return logicalSubQueryPlan;
}
Also used : LogicalUnaryVertex(com.alibaba.maxgraph.compiler.logical.LogicalUnaryVertex) LogicalVertex(com.alibaba.maxgraph.compiler.logical.LogicalVertex) ProcessorFunction(com.alibaba.maxgraph.compiler.logical.function.ProcessorFunction) LogicalEdge(com.alibaba.maxgraph.compiler.logical.LogicalEdge) VertexIdManager(com.alibaba.maxgraph.compiler.logical.VertexIdManager) LogicalBinaryVertex(com.alibaba.maxgraph.compiler.logical.LogicalBinaryVertex) LogicalSubQueryPlan(com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan)

Example 13 with LogicalBinaryVertex

use of com.alibaba.maxgraph.compiler.logical.LogicalBinaryVertex in project GraphScope by alibaba.

the class RatioVertexTreeNode method buildLogicalQueryPlan.

@Override
public LogicalSubQueryPlan buildLogicalQueryPlan(ContextManager contextManager) {
    TreeNodeLabelManager treeNodeLabelManager = contextManager.getTreeNodeLabelManager();
    VertexIdManager vertexIdManager = contextManager.getVertexIdManager();
    LogicalVertex sourceVertex = getInputNode().getOutputVertex();
    LogicalSubQueryPlan logicalSubQueryPlan = new LogicalSubQueryPlan(contextManager);
    logicalSubQueryPlan.addLogicalVertex(sourceVertex);
    ProcessorFunction countFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.COUNT);
    LogicalUnaryVertex countVertex = new LogicalUnaryVertex(vertexIdManager.getId(), countFunction, false, sourceVertex);
    logicalSubQueryPlan.addLogicalVertex(countVertex);
    LogicalEdge countEdge = new LogicalEdge(EdgeShuffleType.SHUFFLE_BY_CONST);
    countEdge.setStreamIndex(0);
    logicalSubQueryPlan.addLogicalEdge(sourceVertex, countVertex, countEdge);
    ProcessorFunction enterKeyFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.ENTER_KEY, Message.Value.newBuilder().setPayload(QueryFlowOuterClass.EnterKeyArgumentProto.newBuilder().setEnterKeyType(QueryFlowOuterClass.EnterKeyTypeProto.KEY_SELF).setUniqFlag(true).build().toByteString()));
    LogicalVertex enterKeyVertex = new LogicalUnaryVertex(vertexIdManager.getId(), enterKeyFunction, false, sourceVertex);
    logicalSubQueryPlan.addLogicalVertex(enterKeyVertex);
    LogicalEdge enterKeyEdge = new LogicalEdge(EdgeShuffleType.FORWARD);
    enterKeyEdge.setStreamIndex(1);
    logicalSubQueryPlan.addLogicalEdge(sourceVertex, enterKeyVertex, enterKeyEdge);
    QueryFlowOuterClass.OperatorType valueOperatorType = QueryFlowOuterClass.OperatorType.valueOf(StringUtils.upperCase(direction.name()));
    Message.Value.Builder argumentBuilder = Message.Value.newBuilder();
    if (null != labelList) {
        for (String label : labelList) {
            try {
                argumentBuilder.addIntValueList(schema.getElement(label).getLabelId());
            } catch (Exception e) {
                throw new RuntimeException("There's no edge label=>" + label);
            }
        }
    }
    ProcessorFunction valueFunction = new ProcessorFunction(valueOperatorType, argumentBuilder);
    LogicalUnaryVertex valueVertex = new LogicalUnaryVertex(vertexIdManager.getId(), valueFunction, false, enterKeyVertex);
    logicalSubQueryPlan.addLogicalVertex(valueVertex);
    LogicalEdge valueEdge = new LogicalEdge(EdgeShuffleType.SHUFFLE_BY_KEY);
    logicalSubQueryPlan.addLogicalEdge(enterKeyVertex, valueVertex, valueEdge);
    ProcessorFunction countByKeyFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.COUNT_BY_KEY, Message.Value.newBuilder().addIntValueList(0));
    LogicalUnaryVertex countByKeyVertex = new LogicalUnaryVertex(vertexIdManager.getId(), countByKeyFunction, false, valueVertex);
    logicalSubQueryPlan.addLogicalVertex(countByKeyVertex);
    logicalSubQueryPlan.addLogicalEdge(valueVertex, countByKeyVertex, new LogicalEdge(EdgeShuffleType.SHUFFLE_BY_KEY));
    ProcessorFunction ratioFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.JOIN_RATIO, Message.Value.newBuilder().setIntValue(CompilerUtils.parseCompareType(predicate, predicate.getBiPredicate()).getNumber()).setDoubleValue(Double.parseDouble(predicate.getValue().toString())));
    LogicalBinaryVertex logicalBinaryVertex = new LogicalBinaryVertex(vertexIdManager.getId(), ratioFunction, true, countVertex, countByKeyVertex);
    logicalSubQueryPlan.addLogicalVertex(logicalBinaryVertex);
    logicalSubQueryPlan.addLogicalEdge(countVertex, logicalBinaryVertex, new LogicalEdge(EdgeShuffleType.BROADCAST));
    logicalSubQueryPlan.addLogicalEdge(countByKeyVertex, logicalBinaryVertex, new LogicalEdge(EdgeShuffleType.FORWARD));
    setFinishVertex(logicalBinaryVertex, treeNodeLabelManager);
    addUsedLabelAndRequirement(logicalBinaryVertex, treeNodeLabelManager);
    return logicalSubQueryPlan;
}
Also used : LogicalUnaryVertex(com.alibaba.maxgraph.compiler.logical.LogicalUnaryVertex) ProcessorFunction(com.alibaba.maxgraph.compiler.logical.function.ProcessorFunction) LogicalEdge(com.alibaba.maxgraph.compiler.logical.LogicalEdge) QueryFlowOuterClass(com.alibaba.maxgraph.QueryFlowOuterClass) LogicalBinaryVertex(com.alibaba.maxgraph.compiler.logical.LogicalBinaryVertex) LogicalVertex(com.alibaba.maxgraph.compiler.logical.LogicalVertex) VertexIdManager(com.alibaba.maxgraph.compiler.logical.VertexIdManager) LogicalSubQueryPlan(com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan)

Example 14 with LogicalBinaryVertex

use of com.alibaba.maxgraph.compiler.logical.LogicalBinaryVertex in project GraphScope by alibaba.

the class RepeatTreeNode method buildFilterResultPlan.

private LogicalVertex buildFilterResultPlan(ContextManager contextManager, VertexIdManager vertexIdManager, TreeNodeLabelManager labelManager, LogicalSubQueryPlan logicalSubQueryPlan, LogicalVertex delegateSourceVertex, TreeNode emitTreeNode) {
    TreeNode currentEmitTreeNode = TreeNodeUtils.buildSingleOutputNode(emitTreeNode, schema);
    LogicalSubQueryPlan untilPlan = TreeNodeUtils.buildSubQueryPlan(currentEmitTreeNode, delegateSourceVertex, contextManager);
    LogicalVertex enterKeyVertex = TreeNodeUtils.getSourceTreeNode(currentEmitTreeNode).getOutputVertex();
    LogicalVertex untilResultVertex = untilPlan.getOutputVertex();
    logicalSubQueryPlan.mergeLogicalQueryPlan(untilPlan);
    if (currentEmitTreeNode instanceof HasTreeNode && ((HasTreeNode) currentEmitTreeNode).getInputNode() instanceof SourceDelegateNode) {
        return untilResultVertex;
    } else {
        LogicalVertex currentOutputVertex = new LogicalBinaryVertex(vertexIdManager.getId(), new ProcessorFunction(QueryFlowOuterClass.OperatorType.JOIN_DIRECT_FILTER), false, enterKeyVertex, untilResultVertex);
        logicalSubQueryPlan.addLogicalVertex(currentOutputVertex);
        logicalSubQueryPlan.addLogicalEdge(enterKeyVertex, currentOutputVertex, new LogicalEdge());
        logicalSubQueryPlan.addLogicalEdge(untilResultVertex, currentOutputVertex, new LogicalEdge());
        return currentOutputVertex;
    }
}
Also used : LogicalVertex(com.alibaba.maxgraph.compiler.logical.LogicalVertex) ProcessorFunction(com.alibaba.maxgraph.compiler.logical.function.ProcessorFunction) LogicalEdge(com.alibaba.maxgraph.compiler.logical.LogicalEdge) SourceTreeNode(com.alibaba.maxgraph.compiler.tree.source.SourceTreeNode) SourceDelegateNode(com.alibaba.maxgraph.compiler.tree.source.SourceDelegateNode) LogicalBinaryVertex(com.alibaba.maxgraph.compiler.logical.LogicalBinaryVertex) LogicalSubQueryPlan(com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan)

Example 15 with LogicalBinaryVertex

use of com.alibaba.maxgraph.compiler.logical.LogicalBinaryVertex in project GraphScope by alibaba.

the class RepeatTreeNode method unionVertexList.

private LogicalVertex unionVertexList(VertexIdManager vertexIdManager, LogicalSubQueryPlan repeatBodyPlan, List<LogicalVertex> leaveVertexList) {
    LogicalVertex unionVertex = leaveVertexList.get(0);
    for (int i = 1; i < leaveVertexList.size(); i++) {
        LogicalVertex currentUnionVertex = new LogicalBinaryVertex(vertexIdManager.getId(), new ProcessorFunction(QueryFlowOuterClass.OperatorType.UNION), false, unionVertex, leaveVertexList.get(i));
        repeatBodyPlan.addLogicalVertex(currentUnionVertex);
        repeatBodyPlan.addLogicalEdge(unionVertex, currentUnionVertex, new LogicalEdge(EdgeShuffleType.FORWARD));
        repeatBodyPlan.addLogicalEdge(leaveVertexList.get(i), currentUnionVertex, new LogicalEdge(EdgeShuffleType.FORWARD));
        unionVertex = currentUnionVertex;
    }
    return unionVertex;
}
Also used : LogicalVertex(com.alibaba.maxgraph.compiler.logical.LogicalVertex) ProcessorFunction(com.alibaba.maxgraph.compiler.logical.function.ProcessorFunction) LogicalEdge(com.alibaba.maxgraph.compiler.logical.LogicalEdge) LogicalBinaryVertex(com.alibaba.maxgraph.compiler.logical.LogicalBinaryVertex)

Aggregations

LogicalBinaryVertex (com.alibaba.maxgraph.compiler.logical.LogicalBinaryVertex)20 LogicalVertex (com.alibaba.maxgraph.compiler.logical.LogicalVertex)20 LogicalEdge (com.alibaba.maxgraph.compiler.logical.LogicalEdge)19 ProcessorFunction (com.alibaba.maxgraph.compiler.logical.function.ProcessorFunction)18 LogicalSubQueryPlan (com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan)15 LogicalUnaryVertex (com.alibaba.maxgraph.compiler.logical.LogicalUnaryVertex)12 VertexIdManager (com.alibaba.maxgraph.compiler.logical.VertexIdManager)6 SourceTreeNode (com.alibaba.maxgraph.compiler.tree.source.SourceTreeNode)6 QueryFlowOuterClass (com.alibaba.maxgraph.QueryFlowOuterClass)5 LogicalQueryPlan (com.alibaba.maxgraph.compiler.logical.LogicalQueryPlan)5 Message (com.alibaba.maxgraph.Message)4 SourceDelegateNode (com.alibaba.maxgraph.compiler.tree.source.SourceDelegateNode)4 JoinZeroNode (com.alibaba.maxgraph.compiler.tree.addition.JoinZeroNode)3 LogicalSourceDelegateVertex (com.alibaba.maxgraph.compiler.logical.LogicalSourceDelegateVertex)2 LogicalSourceVertex (com.alibaba.maxgraph.compiler.logical.LogicalSourceVertex)2 ProcessorFilterFunction (com.alibaba.maxgraph.compiler.logical.function.ProcessorFilterFunction)2 CountGlobalTreeNode (com.alibaba.maxgraph.compiler.tree.CountGlobalTreeNode)2 FoldTreeNode (com.alibaba.maxgraph.compiler.tree.FoldTreeNode)2 HasTreeNode (com.alibaba.maxgraph.compiler.tree.HasTreeNode)2 MaxTreeNode (com.alibaba.maxgraph.compiler.tree.MaxTreeNode)2