Search in sources :

Example 1 with AbstractUseKeyNode

use of com.alibaba.maxgraph.compiler.tree.addition.AbstractUseKeyNode in project GraphScope by alibaba.

the class TreeNodeUtils method buildSubQueryPlanWithKey.

/**
 * @param treeNode The given tree node
 * @param sourceVertex The source vertex
 * @param treeNodeLabelManager The given label manager
 * @param contextManager The context manager
 * @param vertexIdManager The vertex id manager
 * @return The sub query with enter key vertex
 */
public static LogicalSubQueryPlan buildSubQueryPlanWithKey(TreeNode treeNode, LogicalVertex sourceVertex, TreeNodeLabelManager treeNodeLabelManager, ContextManager contextManager, VertexIdManager vertexIdManager) {
    List<TreeNode> treeNodeList = buildTreeNodeListFromLeaf(treeNode);
    LogicalSubQueryPlan logicalSubQueryPlan = new LogicalSubQueryPlan(contextManager);
    LogicalVertex currentSourceVertex = sourceVertex;
    for (TreeNode currentNode : treeNodeList) {
        if (currentNode instanceof AbstractUseKeyNode) {
            ((AbstractUseKeyNode) currentNode).enableUseKeyFlag(currentSourceVertex);
        }
        if (currentNode instanceof SourceDelegateNode) {
            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;
        }
        logicalSubQueryPlan.mergeLogicalQueryPlan(currentNode.buildLogicalQueryPlan(contextManager));
    }
    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) 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) LogicalSubQueryPlan(com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan) AbstractUseKeyNode(com.alibaba.maxgraph.compiler.tree.addition.AbstractUseKeyNode)

Example 2 with AbstractUseKeyNode

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

LogicalEdge (com.alibaba.maxgraph.compiler.logical.LogicalEdge)2 LogicalSubQueryPlan (com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan)2 LogicalUnaryVertex (com.alibaba.maxgraph.compiler.logical.LogicalUnaryVertex)2 LogicalVertex (com.alibaba.maxgraph.compiler.logical.LogicalVertex)2 ProcessorFunction (com.alibaba.maxgraph.compiler.logical.function.ProcessorFunction)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 MinTreeNode (com.alibaba.maxgraph.compiler.tree.MinTreeNode)2 PropertyMapTreeNode (com.alibaba.maxgraph.compiler.tree.PropertyMapTreeNode)2 RangeGlobalTreeNode (com.alibaba.maxgraph.compiler.tree.RangeGlobalTreeNode)2 SelectOneTreeNode (com.alibaba.maxgraph.compiler.tree.SelectOneTreeNode)2 SumTreeNode (com.alibaba.maxgraph.compiler.tree.SumTreeNode)2 TokenTreeNode (com.alibaba.maxgraph.compiler.tree.TokenTreeNode)2 TreeNode (com.alibaba.maxgraph.compiler.tree.TreeNode)2 UnaryTreeNode (com.alibaba.maxgraph.compiler.tree.UnaryTreeNode)2 VertexTreeNode (com.alibaba.maxgraph.compiler.tree.VertexTreeNode)2 AbstractUseKeyNode (com.alibaba.maxgraph.compiler.tree.addition.AbstractUseKeyNode)2 SourceDelegateNode (com.alibaba.maxgraph.compiler.tree.source.SourceDelegateNode)2