Search in sources :

Example 51 with LogicalVertex

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

the class TreeNodeUtils method buildSubQueryPlan.

/**
 * Build sub query plan from given leaf tree node
 *
 * @param treeNode The given leaf tree node
 * @param sourceVertex The source vertex
 * @param contextManager The context manager
 * @param generateUseKey The flag of generated use key, it may be generated outside such as
 *     group
 * @return The query plan of sub query
 */
public static LogicalSubQueryPlan buildSubQueryPlan(TreeNode treeNode, LogicalVertex sourceVertex, ContextManager contextManager, boolean generateUseKey) {
    TreeNodeLabelManager treeNodeLabelManager = contextManager.getTreeNodeLabelManager();
    VertexIdManager vertexIdManager = contextManager.getVertexIdManager();
    List<TreeNode> treeNodeList = buildTreeNodeListFromLeaf(treeNode);
    boolean useKeyFlag = checkNodeListUseKey(treeNodeList);
    LogicalSubQueryPlan logicalSubQueryPlan = new LogicalSubQueryPlan(contextManager);
    LogicalVertex currentSourceVertex = sourceVertex;
    for (TreeNode currentNode : treeNodeList) {
        if (currentNode instanceof AbstractUseKeyNode) {
            ((AbstractUseKeyNode) currentNode).enableUseKeyFlag(currentSourceVertex);
        }
        if (currentNode instanceof SourceDelegateNode) {
            if (useKeyFlag && generateUseKey) {
                LogicalVertex enterKeyVertex = new LogicalUnaryVertex(vertexIdManager.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, treeNodeLabelManager);
                logicalSubQueryPlan.addLogicalVertex(currentSourceVertex);
                logicalSubQueryPlan.addLogicalVertex(enterKeyVertex);
                logicalSubQueryPlan.addLogicalEdge(currentSourceVertex, enterKeyVertex, new LogicalEdge());
                currentSourceVertex = enterKeyVertex;
            } else {
                currentNode.setFinishVertex(currentSourceVertex, treeNodeLabelManager);
                logicalSubQueryPlan.addLogicalVertex(currentSourceVertex);
            }
        }
        logicalSubQueryPlan.mergeLogicalQueryPlan(currentNode.buildLogicalQueryPlan(contextManager));
    }
    return logicalSubQueryPlan;
}
Also used : TreeNodeLabelManager(com.alibaba.maxgraph.compiler.tree.TreeNodeLabelManager) 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) 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) SourceDelegateNode(com.alibaba.maxgraph.compiler.tree.source.SourceDelegateNode) VertexIdManager(com.alibaba.maxgraph.compiler.logical.VertexIdManager) LogicalSubQueryPlan(com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan) AbstractUseKeyNode(com.alibaba.maxgraph.compiler.tree.addition.AbstractUseKeyNode)

Example 52 with LogicalVertex

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

the class WherePredicateTreeNode method processFirstValueNode.

private int processFirstValueNode(ContextManager contextManager, VertexIdManager vertexIdManager, TreeNodeLabelManager labelManager, LogicalSubQueryPlan logicalSubQueryPlan, TreeNode firstRingNode) {
    LogicalVertex currentSourceVertex = logicalSubQueryPlan.getOutputVertex();
    LogicalSubQueryPlan subQueryPlan = TreeNodeUtils.buildSubQueryPlan(firstRingNode, currentSourceVertex, contextManager);
    logicalSubQueryPlan.mergeLogicalQueryPlan(subQueryPlan);
    LogicalVertex valueVertex = subQueryPlan.getOutputVertex();
    String sourceLabel = labelManager.createSysLabelStart(valueVertex, "val");
    return labelManager.getLabelIndex(sourceLabel);
}
Also used : LogicalVertex(com.alibaba.maxgraph.compiler.logical.LogicalVertex) LogicalSubQueryPlan(com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan)

Example 53 with LogicalVertex

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

the class AbstractUseKeyNode method processJoinZeroVertex.

/**
 * Process zero for sum and count vertex
 *
 * @param vertexIdManager     The vertex id manager
 * @param logicalSubQueryPlan The logical sub query plan
 * @param valueVertex         The value vertex
 * @param joinZeroFlag        The join zero flag
 * @return The output vertex after deal with join zero flag
 */
protected LogicalVertex processJoinZeroVertex(VertexIdManager vertexIdManager, LogicalSubQueryPlan logicalSubQueryPlan, LogicalVertex valueVertex, boolean joinZeroFlag) {
    LogicalVertex outputVertex = valueVertex;
    LogicalVertex leftVertex = getSourceVertex();
    if (joinZeroFlag && null != leftVertex) {
        ProcessorFunction joinZeroFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.JOIN_RIGHT_ZERO_JOIN);
        LogicalBinaryVertex logicalBinaryVertex = new LogicalBinaryVertex(vertexIdManager.getId(), joinZeroFunction, false, leftVertex, valueVertex);
        logicalSubQueryPlan.addLogicalVertex(logicalBinaryVertex);
        logicalSubQueryPlan.addLogicalEdge(valueVertex, logicalBinaryVertex, new LogicalEdge());
        outputVertex = logicalBinaryVertex;
    }
    return outputVertex;
}
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

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