Search in sources :

Example 46 with LogicalVertex

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

the class GroupCountTreeNode method buildLogicalQueryPlan.

@Override
public LogicalSubQueryPlan buildLogicalQueryPlan(ContextManager contextManager) {
    LogicalSubQueryPlan logicalSubQueryPlan = new LogicalSubQueryPlan(contextManager);
    LogicalVertex sourceVertex = getInputNode().getOutputVertex();
    logicalSubQueryPlan.addLogicalVertex(sourceVertex);
    LogicalVertex outputVertex;
    if (null == keyTreeNode || keyTreeNode instanceof SourceDelegateNode) {
        ProcessorFunction processorFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.GROUP_COUNT);
        outputVertex = new LogicalUnaryVertex(contextManager.getVertexIdManager().getId(), processorFunction, false, sourceVertex);
        logicalSubQueryPlan.addLogicalVertex(outputVertex);
        logicalSubQueryPlan.addLogicalEdge(sourceVertex, outputVertex, new LogicalEdge());
    } else {
        TreeNode currentKeyNode = TreeNodeUtils.buildSingleOutputNode(keyTreeNode, schema);
        if (currentKeyNode instanceof JoinZeroNode) {
            ((JoinZeroNode) currentKeyNode).disableJoinZero();
        }
        LogicalSubQueryPlan keyValuePlan = TreeNodeUtils.buildSubQueryPlan(currentKeyNode, sourceVertex, contextManager);
        LogicalVertex groupValueVertex = keyValuePlan.getOutputVertex();
        LogicalVertex enterKeyVertex = TreeNodeUtils.getSourceTreeNode(currentKeyNode).getOutputVertex();
        logicalSubQueryPlan.mergeLogicalQueryPlan(keyValuePlan);
        if (TreeNodeUtils.checkJoinSourceFlag(currentKeyNode)) {
            String valueLabel = contextManager.getTreeNodeLabelManager().createSysLabelStart("val");
            getUsedLabelList().add(valueLabel);
            int valueLabelId = contextManager.getTreeNodeLabelManager().getLabelIndex(valueLabel);
            LogicalBinaryVertex logicalBinaryVertex = new LogicalBinaryVertex(contextManager.getVertexIdManager().getId(), new ProcessorFunction(CompilerUtils.parseJoinOperatorType(currentKeyNode), Message.Value.newBuilder().setIntValue(valueLabelId)), false, enterKeyVertex, groupValueVertex);
            logicalSubQueryPlan.addLogicalVertex(logicalBinaryVertex);
            logicalSubQueryPlan.addLogicalEdge(enterKeyVertex, logicalBinaryVertex, new LogicalEdge());
            logicalSubQueryPlan.addLogicalEdge(groupValueVertex, logicalBinaryVertex, new LogicalEdge());
            ProcessorFunction selectValueFunction = TreeNodeUtils.createSelectOneFunction(valueLabel, Pop.first, contextManager.getTreeNodeLabelManager().getLabelIndexList());
            LogicalVertex selectLabelVertex = new LogicalUnaryVertex(contextManager.getVertexIdManager().getId(), selectValueFunction, false, logicalBinaryVertex);
            logicalSubQueryPlan.addLogicalVertex(selectLabelVertex);
            logicalSubQueryPlan.addLogicalEdge(logicalBinaryVertex, selectLabelVertex, LogicalEdge.forwardEdge());
        }
        groupValueVertex = logicalSubQueryPlan.getOutputVertex();
        ProcessorFunction processorFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.GROUP_COUNT, Message.Value.newBuilder());
        outputVertex = new LogicalUnaryVertex(contextManager.getVertexIdManager().getId(), processorFunction, false, groupValueVertex);
        logicalSubQueryPlan.addLogicalVertex(outputVertex);
        logicalSubQueryPlan.addLogicalEdge(groupValueVertex, outputVertex, new LogicalEdge());
    }
    ProcessorFunction foldMapFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.FOLDMAP);
    LogicalVertex foldMapVertex = new LogicalUnaryVertex(contextManager.getVertexIdManager().getId(), foldMapFunction, false, outputVertex);
    logicalSubQueryPlan.addLogicalVertex(foldMapVertex);
    logicalSubQueryPlan.addLogicalEdge(outputVertex, foldMapVertex, new LogicalEdge());
    addUsedLabelAndRequirement(foldMapVertex, contextManager.getTreeNodeLabelManager());
    setFinishVertex(foldMapVertex, contextManager.getTreeNodeLabelManager());
    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) JoinZeroNode(com.alibaba.maxgraph.compiler.tree.addition.JoinZeroNode) SourceDelegateNode(com.alibaba.maxgraph.compiler.tree.source.SourceDelegateNode) LogicalBinaryVertex(com.alibaba.maxgraph.compiler.logical.LogicalBinaryVertex) LogicalSubQueryPlan(com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan)

Example 47 with LogicalVertex

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

the class CostEstimator method costQueryPlan.

/**
 * This method computes the cost of an query plan.
 *
 * @param queryPlan  The given query plan
 * @param statistics The DataStatistics
 * @param schema     The Schema
 * @return The costs of query plan
 */
public Costs costQueryPlan(LogicalQueryPlan queryPlan, DataStatistics statistics, GraphSchema schema) {
    List<LogicalVertex> logicalVertexList = queryPlan.getLogicalVertexList();
    Costs totalCosts = new Costs();
    for (LogicalVertex logicalVertex : logicalVertexList) {
        logicalVertex.computeOutputEstimates(statistics, schema);
        Costs vertexCosts = costOperator(queryPlan, logicalVertex);
        totalCosts.addCosts(vertexCosts);
    }
    return totalCosts;
}
Also used : LogicalVertex(com.alibaba.maxgraph.compiler.logical.LogicalVertex)

Example 48 with LogicalVertex

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

the class UnaryTreeNode method parseSingleUnaryVertex.

protected LogicalSubQueryPlan parseSingleUnaryVertex(VertexIdManager vertexIdManager, TreeNodeLabelManager labelManager, ProcessorFunction processorFunction, ContextManager contextManager, LogicalEdge logicalEdge, boolean outputFlag) {
    LogicalSubQueryPlan logicalSubQueryPlan = new LogicalSubQueryPlan(contextManager);
    LogicalVertex sourceVertex = getInputNode().getOutputVertex();
    logicalSubQueryPlan.addLogicalVertex(sourceVertex);
    LogicalUnaryVertex logicalUnaryVertex = new LogicalUnaryVertex(vertexIdManager.getId(), processorFunction, false, sourceVertex);
    logicalUnaryVertex.setEarlyStopFlag(super.earlyStopArgument);
    logicalSubQueryPlan.addLogicalVertex(logicalUnaryVertex);
    logicalSubQueryPlan.addLogicalEdge(sourceVertex, logicalUnaryVertex, logicalEdge);
    if (outputFlag) {
        setFinishVertex(logicalUnaryVertex, labelManager);
        addUsedLabelAndRequirement(logicalUnaryVertex, labelManager);
    }
    return logicalSubQueryPlan;
}
Also used : LogicalUnaryVertex(com.alibaba.maxgraph.compiler.logical.LogicalUnaryVertex) LogicalVertex(com.alibaba.maxgraph.compiler.logical.LogicalVertex) LogicalSubQueryPlan(com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan)

Example 49 with LogicalVertex

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

the class PlanUtils method getOrderVertexList.

/**
 * Get order vertex list for given plan
 *
 * @param plan The given plan
 * @return The order vertex list
 */
public static List<LogicalVertex> getOrderVertexList(Graph<LogicalVertex, LogicalEdge> plan) {
    List<LogicalVertex> logicalVertexList = Lists.newArrayList();
    LinkedList<LogicalVertex> vertexQueue = Lists.newLinkedList();
    vertexQueue.addAll(getSourceVertexList(plan));
    while (!vertexQueue.isEmpty()) {
        LogicalVertex currentVertex = vertexQueue.pop();
        logicalVertexList.add(currentVertex);
        List<LogicalVertex> targetVertexList = getTargetVertexList(plan, currentVertex);
        for (LogicalVertex targetVertex : targetVertexList) {
            List<LogicalVertex> sourceVertexList = getSourceVertexList(plan, targetVertex);
            if (logicalVertexList.containsAll(sourceVertexList)) {
                vertexQueue.push(targetVertex);
            }
        }
    }
    return logicalVertexList;
}
Also used : LogicalVertex(com.alibaba.maxgraph.compiler.logical.LogicalVertex)

Example 50 with LogicalVertex

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

the class TreeNodeUtils method buildSubQueryWithLabel.

/**
 * Build sub query plan, and save the result of sub plan to given label id
 *
 * @param treeNode The given tree node
 * @param sourceVertex The given source vertex
 * @param contextManager The given context manager
 * @return The result query plan and label id
 */
public static Pair<LogicalQueryPlan, Integer> buildSubQueryWithLabel(TreeNode treeNode, LogicalVertex sourceVertex, ContextManager contextManager) {
    boolean joinFlag = checkJoinSourceFlag(treeNode);
    List<TreeNode> treeNodeList = buildTreeNodeListFromLeaf(treeNode);
    LogicalQueryPlan queryPlan = new LogicalQueryPlan(contextManager);
    LogicalVertex originalVertex = null;
    LogicalVertex currentSourceVertex = sourceVertex;
    for (TreeNode currentNode : treeNodeList) {
        if (currentNode instanceof SourceDelegateNode) {
            queryPlan.addLogicalVertex(sourceVertex);
            if (joinFlag) {
                LogicalVertex enterKeyVertex = new LogicalUnaryVertex(contextManager.getVertexIdManager().getId(), new ProcessorFunction(QueryFlowOuterClass.OperatorType.ENTER_KEY, Message.Value.newBuilder().setPayload(QueryFlowOuterClass.EnterKeyArgumentProto.newBuilder().setEnterKeyType(QueryFlowOuterClass.EnterKeyTypeProto.KEY_SELF).setUniqFlag(true).build().toByteString())), false, currentSourceVertex);
                currentNode.setFinishVertex(enterKeyVertex, contextManager.getTreeNodeLabelManager());
                queryPlan.addLogicalVertex(enterKeyVertex);
                queryPlan.addLogicalEdge(sourceVertex, enterKeyVertex, new LogicalEdge());
                currentSourceVertex = enterKeyVertex;
                originalVertex = enterKeyVertex;
            } else {
                currentNode.setFinishVertex(sourceVertex, contextManager.getTreeNodeLabelManager());
                originalVertex = sourceVertex;
            }
        } else {
            queryPlan.mergeLogicalQueryPlan(currentNode.buildLogicalQueryPlan(contextManager));
        }
    }
    checkNotNull(originalVertex, "original vertex can't be null");
    LogicalVertex valueVertex = queryPlan.getOutputVertex();
    String valueLabel = contextManager.getTreeNodeLabelManager().createSysLabelStart("val");
    int valueLabelId = contextManager.getTreeNodeLabelManager().getLabelIndex(valueLabel);
    if (joinFlag) {
        LogicalVertex joinVertex;
        if (treeNode instanceof CountGlobalTreeNode || treeNode instanceof SumTreeNode) {
            joinVertex = new LogicalBinaryVertex(contextManager.getVertexIdManager().getId(), new ProcessorFunction(QueryFlowOuterClass.OperatorType.JOIN_COUNT_LABEL, Message.Value.newBuilder().setIntValue(valueLabelId)), false, originalVertex, valueVertex);
        } else {
            joinVertex = new LogicalBinaryVertex(contextManager.getVertexIdManager().getId(), new ProcessorFunction(QueryFlowOuterClass.OperatorType.JOIN_LABEL, Message.Value.newBuilder().setIntValue(valueLabelId)), false, originalVertex, valueVertex);
        }
        queryPlan.addLogicalVertex(joinVertex);
        queryPlan.addLogicalEdge(originalVertex, joinVertex, LogicalEdge.shuffleByKey(0));
        queryPlan.addLogicalEdge(valueVertex, joinVertex, LogicalEdge.forwardEdge());
    } else {
        LogicalVertex originalOutputVertex = queryPlan.getTargetVertex(originalVertex);
        String originalLabel = contextManager.getTreeNodeLabelManager().createBeforeSysLabelStart(originalOutputVertex, "original");
        ProcessorFunction selectFunction = createSelectOneFunction(originalLabel, Pop.first, contextManager.getTreeNodeLabelManager().getLabelIndexList());
        LogicalVertex selectVertex = new LogicalUnaryVertex(contextManager.getVertexIdManager().getId(), selectFunction, valueVertex);
        selectVertex.getBeforeRequirementList().add(QueryFlowOuterClass.RequirementValue.newBuilder().setReqType(QueryFlowOuterClass.RequirementType.LABEL_START).setReqArgument(Message.Value.newBuilder().addIntValueList(valueLabelId)));
        queryPlan.addLogicalVertex(selectVertex);
        queryPlan.addLogicalEdge(valueVertex, selectVertex, LogicalEdge.forwardEdge());
    }
    return Pair.of(queryPlan, valueLabelId);
}
Also used : LogicalUnaryVertex(com.alibaba.maxgraph.compiler.logical.LogicalUnaryVertex) ProcessorFunction(com.alibaba.maxgraph.compiler.logical.function.ProcessorFunction) LogicalEdge(com.alibaba.maxgraph.compiler.logical.LogicalEdge) SourceDelegateNode(com.alibaba.maxgraph.compiler.tree.source.SourceDelegateNode) CountGlobalTreeNode(com.alibaba.maxgraph.compiler.tree.CountGlobalTreeNode) LogicalBinaryVertex(com.alibaba.maxgraph.compiler.logical.LogicalBinaryVertex) LogicalVertex(com.alibaba.maxgraph.compiler.logical.LogicalVertex) SourceTreeNode(com.alibaba.maxgraph.compiler.tree.source.SourceTreeNode) VertexTreeNode(com.alibaba.maxgraph.compiler.tree.VertexTreeNode) MaxTreeNode(com.alibaba.maxgraph.compiler.tree.MaxTreeNode) RangeGlobalTreeNode(com.alibaba.maxgraph.compiler.tree.RangeGlobalTreeNode) FoldTreeNode(com.alibaba.maxgraph.compiler.tree.FoldTreeNode) TreeNode(com.alibaba.maxgraph.compiler.tree.TreeNode) TokenTreeNode(com.alibaba.maxgraph.compiler.tree.TokenTreeNode) MinTreeNode(com.alibaba.maxgraph.compiler.tree.MinTreeNode) CountGlobalTreeNode(com.alibaba.maxgraph.compiler.tree.CountGlobalTreeNode) HasTreeNode(com.alibaba.maxgraph.compiler.tree.HasTreeNode) SelectOneTreeNode(com.alibaba.maxgraph.compiler.tree.SelectOneTreeNode) PropertyMapTreeNode(com.alibaba.maxgraph.compiler.tree.PropertyMapTreeNode) SumTreeNode(com.alibaba.maxgraph.compiler.tree.SumTreeNode) UnaryTreeNode(com.alibaba.maxgraph.compiler.tree.UnaryTreeNode) LogicalQueryPlan(com.alibaba.maxgraph.compiler.logical.LogicalQueryPlan) SumTreeNode(com.alibaba.maxgraph.compiler.tree.SumTreeNode)

Aggregations

LogicalVertex (com.alibaba.maxgraph.compiler.logical.LogicalVertex)53 LogicalSubQueryPlan (com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan)41 ProcessorFunction (com.alibaba.maxgraph.compiler.logical.function.ProcessorFunction)38 LogicalEdge (com.alibaba.maxgraph.compiler.logical.LogicalEdge)34 LogicalUnaryVertex (com.alibaba.maxgraph.compiler.logical.LogicalUnaryVertex)29 LogicalBinaryVertex (com.alibaba.maxgraph.compiler.logical.LogicalBinaryVertex)20 VertexIdManager (com.alibaba.maxgraph.compiler.logical.VertexIdManager)18 QueryFlowOuterClass (com.alibaba.maxgraph.QueryFlowOuterClass)13 SourceDelegateNode (com.alibaba.maxgraph.compiler.tree.source.SourceDelegateNode)11 LogicalQueryPlan (com.alibaba.maxgraph.compiler.logical.LogicalQueryPlan)9 SourceTreeNode (com.alibaba.maxgraph.compiler.tree.source.SourceTreeNode)9 Message (com.alibaba.maxgraph.Message)6 LogicalSourceDelegateVertex (com.alibaba.maxgraph.compiler.logical.LogicalSourceDelegateVertex)4 CountGlobalTreeNode (com.alibaba.maxgraph.compiler.tree.CountGlobalTreeNode)4 FoldTreeNode (com.alibaba.maxgraph.compiler.tree.FoldTreeNode)4 HasTreeNode (com.alibaba.maxgraph.compiler.tree.HasTreeNode)4 MaxTreeNode (com.alibaba.maxgraph.compiler.tree.MaxTreeNode)4 MinTreeNode (com.alibaba.maxgraph.compiler.tree.MinTreeNode)4 PropertyMapTreeNode (com.alibaba.maxgraph.compiler.tree.PropertyMapTreeNode)4 RangeGlobalTreeNode (com.alibaba.maxgraph.compiler.tree.RangeGlobalTreeNode)4