Search in sources :

Example 6 with TreeNodeLabelManager

use of com.alibaba.maxgraph.compiler.tree.TreeNodeLabelManager 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)

Aggregations

TreeNodeLabelManager (com.alibaba.maxgraph.compiler.tree.TreeNodeLabelManager)6 TreeNode (com.alibaba.maxgraph.compiler.tree.TreeNode)4 SourceTreeNode (com.alibaba.maxgraph.compiler.tree.source.SourceTreeNode)4 CostModelManager (com.alibaba.maxgraph.compiler.cost.CostModelManager)3 LogicalSubQueryPlan (com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan)3 VertexIdManager (com.alibaba.maxgraph.compiler.logical.VertexIdManager)3 ProcessorFunction (com.alibaba.maxgraph.compiler.logical.function.ProcessorFunction)3 Message (com.alibaba.maxgraph.Message)2 CostMappingManager (com.alibaba.maxgraph.compiler.cost.CostMappingManager)2 RowField (com.alibaba.maxgraph.compiler.cost.RowField)2 RowFieldManager (com.alibaba.maxgraph.compiler.cost.RowFieldManager)2 LogicalEdge (com.alibaba.maxgraph.compiler.logical.LogicalEdge)2 LogicalUnaryVertex (com.alibaba.maxgraph.compiler.logical.LogicalUnaryVertex)2 LogicalVertex (com.alibaba.maxgraph.compiler.logical.LogicalVertex)2 ContextManager (com.alibaba.maxgraph.compiler.optimizer.ContextManager)2 BaseTreeNode (com.alibaba.maxgraph.compiler.tree.BaseTreeNode)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