Search in sources :

Example 1 with DfsRepeatGraphTreeNode

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

the class DfsTraversal method buildDfsTree.

/**
 * Build bfs tree manager
 *
 * @param treeBuilder The tree builder
 * @param schema      The schema
 * @return The result tree managet
 */
public TreeManager buildDfsTree(TreeBuilder treeBuilder, GraphSchema schema) {
    TreeManager treeManager = treeBuilder.build(traversal);
    treeManager.optimizeTree();
    TreeNode currentNode = treeManager.getTreeLeaf();
    while (!(currentNode instanceof SourceTreeNode)) {
        if (currentNode.getNodeType() == NodeType.AGGREGATE) {
            throw new IllegalArgumentException("There's aggregate in the query and can'e be executed in bfs mode");
        }
        currentNode = UnaryTreeNode.class.cast(currentNode).getInputNode();
    }
    SourceDfsTreeNode sourceBfsTreeNode = new SourceDfsTreeNode(schema, batchSize);
    RepeatTreeNode repeatTreeNode = new RepeatTreeNode(sourceBfsTreeNode, schema, Maps.newHashMap());
    TreeNode sourceOutputNode = currentNode.getOutputNode();
    SourceDelegateNode repeatSourceTreeNode = new SourceDelegateNode(sourceBfsTreeNode, schema);
    DfsRepeatGraphTreeNode dfsRepeatGraphTreeNode = new DfsRepeatGraphTreeNode(repeatSourceTreeNode, SourceTreeNode.class.cast(currentNode), schema);
    if (null != sourceOutputNode) {
        UnaryTreeNode.class.cast(sourceOutputNode).setInputNode(dfsRepeatGraphTreeNode);
    } else {
        treeManager.setLeafNode(dfsRepeatGraphTreeNode);
    }
    TreeNode bodyLeafTreeNode = treeManager.getTreeLeaf();
    repeatTreeNode.setRepeatBodyTreeNode(bodyLeafTreeNode);
    repeatTreeNode.setEmitTreeNode(new SourceDelegateNode(bodyLeafTreeNode, schema));
    if (order) {
        OrderGlobalTreeNode orderTreeNode = new OrderGlobalTreeNode(new SourceDelegateNode(bodyLeafTreeNode, schema), schema, Lists.newArrayList(Pair.of(new SourceDelegateNode(bodyLeafTreeNode, schema), Order.asc)));
        repeatTreeNode.setDfsEmitTreeNode(orderTreeNode);
    }
    repeatTreeNode.setDfsFeedTreeNode(new DfsFinishTreeNode(new SourceDelegateNode(bodyLeafTreeNode, schema), schema, high));
    repeatTreeNode.setMaxLoopTimes(MAX_BFS_ITERATION_TIMES);
    RangeGlobalTreeNode rangeGlobalTreeNode = new RangeGlobalTreeNode(repeatTreeNode, schema, low, high);
    return new TreeManager(rangeGlobalTreeNode, schema, treeManager.getLabelManager(), treeManager.getQueryConfig());
}
Also used : SourceDfsTreeNode(com.alibaba.maxgraph.compiler.tree.source.SourceDfsTreeNode) DfsFinishTreeNode(com.alibaba.maxgraph.compiler.tree.DfsFinishTreeNode) SourceTreeNode(com.alibaba.maxgraph.compiler.tree.source.SourceTreeNode) SourceDfsTreeNode(com.alibaba.maxgraph.compiler.tree.source.SourceDfsTreeNode) DfsFinishTreeNode(com.alibaba.maxgraph.compiler.tree.DfsFinishTreeNode) RepeatTreeNode(com.alibaba.maxgraph.compiler.tree.RepeatTreeNode) OrderGlobalTreeNode(com.alibaba.maxgraph.compiler.tree.OrderGlobalTreeNode) RangeGlobalTreeNode(com.alibaba.maxgraph.compiler.tree.RangeGlobalTreeNode) UnaryTreeNode(com.alibaba.maxgraph.compiler.tree.UnaryTreeNode) DfsRepeatGraphTreeNode(com.alibaba.maxgraph.compiler.tree.DfsRepeatGraphTreeNode) TreeNode(com.alibaba.maxgraph.compiler.tree.TreeNode) SourceTreeNode(com.alibaba.maxgraph.compiler.tree.source.SourceTreeNode) RepeatTreeNode(com.alibaba.maxgraph.compiler.tree.RepeatTreeNode) TreeManager(com.alibaba.maxgraph.compiler.tree.TreeManager) SourceDelegateNode(com.alibaba.maxgraph.compiler.tree.source.SourceDelegateNode) OrderGlobalTreeNode(com.alibaba.maxgraph.compiler.tree.OrderGlobalTreeNode) DfsRepeatGraphTreeNode(com.alibaba.maxgraph.compiler.tree.DfsRepeatGraphTreeNode) UnaryTreeNode(com.alibaba.maxgraph.compiler.tree.UnaryTreeNode) RangeGlobalTreeNode(com.alibaba.maxgraph.compiler.tree.RangeGlobalTreeNode)

Aggregations

DfsFinishTreeNode (com.alibaba.maxgraph.compiler.tree.DfsFinishTreeNode)1 DfsRepeatGraphTreeNode (com.alibaba.maxgraph.compiler.tree.DfsRepeatGraphTreeNode)1 OrderGlobalTreeNode (com.alibaba.maxgraph.compiler.tree.OrderGlobalTreeNode)1 RangeGlobalTreeNode (com.alibaba.maxgraph.compiler.tree.RangeGlobalTreeNode)1 RepeatTreeNode (com.alibaba.maxgraph.compiler.tree.RepeatTreeNode)1 TreeManager (com.alibaba.maxgraph.compiler.tree.TreeManager)1 TreeNode (com.alibaba.maxgraph.compiler.tree.TreeNode)1 UnaryTreeNode (com.alibaba.maxgraph.compiler.tree.UnaryTreeNode)1 SourceDelegateNode (com.alibaba.maxgraph.compiler.tree.source.SourceDelegateNode)1 SourceDfsTreeNode (com.alibaba.maxgraph.compiler.tree.source.SourceDfsTreeNode)1 SourceTreeNode (com.alibaba.maxgraph.compiler.tree.source.SourceTreeNode)1