Search in sources :

Example 1 with RangeGlobalTreeNode

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

the class TreeNodeUtils method optimizeSubFilterNode.

/**
 * Optimize filter node in TraversalFilterNode
 *
 * @param filterTreeNode The given filter node
 * @return The optimized filter node
 */
public static TreeNode optimizeSubFilterNode(TreeNode filterTreeNode) {
    TreeNode sourceNode = getSourceTreeNode(filterTreeNode);
    UnaryTreeNode firstNode = (UnaryTreeNode) sourceNode.getOutputNode();
    if (firstNode instanceof VertexTreeNode) {
        VertexTreeNode vertexTreeNode = (VertexTreeNode) firstNode;
        Direction direction = vertexTreeNode.getDirection();
        if (direction == Direction.OUT) {
            while (true) {
                boolean optimizeFinish = true;
                TreeNode outputNode = vertexTreeNode.getOutputNode();
                if (null == outputNode) {
                    vertexTreeNode.enableCountFlag();
                    TreeNode hasTreeNode = new HasTreeNode(vertexTreeNode, Lists.newArrayList(new HasContainer("", P.gt(0L))), vertexTreeNode.getSchema());
                    hasTreeNode.setOutputNode(null);
                    break;
                }
                if (outputNode instanceof RangeGlobalTreeNode) {
                    TreeNode rangeOutputNode = outputNode.getOutputNode();
                    vertexTreeNode.setOutputNode(rangeOutputNode);
                    if (null != rangeOutputNode) {
                        ((UnaryTreeNode) rangeOutputNode).setInputNode(vertexTreeNode);
                    }
                    optimizeFinish = false;
                } else if (outputNode instanceof CountGlobalTreeNode) {
                    vertexTreeNode.enableCountFlag();
                    TreeNode rangeOutputNode = outputNode.getOutputNode();
                    vertexTreeNode.setOutputNode(rangeOutputNode);
                    if (null != rangeOutputNode) {
                        ((UnaryTreeNode) rangeOutputNode).setInputNode(vertexTreeNode);
                    }
                    optimizeFinish = false;
                }
                if (optimizeFinish) {
                    break;
                }
            }
        }
    }
    TreeNode currentFilterNode = sourceNode;
    while (currentFilterNode.getOutputNode() != null) {
        currentFilterNode = currentFilterNode.getOutputNode();
    }
    return currentFilterNode;
}
Also used : VertexTreeNode(com.alibaba.maxgraph.compiler.tree.VertexTreeNode) HasTreeNode(com.alibaba.maxgraph.compiler.tree.HasTreeNode) 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) HasContainer(org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer) CountGlobalTreeNode(com.alibaba.maxgraph.compiler.tree.CountGlobalTreeNode) Direction(org.apache.tinkerpop.gremlin.structure.Direction) UnaryTreeNode(com.alibaba.maxgraph.compiler.tree.UnaryTreeNode) RangeGlobalTreeNode(com.alibaba.maxgraph.compiler.tree.RangeGlobalTreeNode)

Example 2 with RangeGlobalTreeNode

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

the class TreeNodeUtils method buildSingleOutputNode.

/**
 * Add limit(1) to multiple output tree node
 *
 * @param treeNode The given tree node
 * @param schema The schema
 * @return The result tree node
 */
public static TreeNode buildSingleOutputNode(TreeNode treeNode, GraphSchema schema) {
    if (null == treeNode) {
        return null;
    }
    boolean hasMultipleEachInputFlag = TreeNodeUtils.checkMultipleOutput(treeNode);
    TreeNode currentFilterTreeNode = treeNode;
    if (hasMultipleEachInputFlag) {
        currentFilterTreeNode = new RangeGlobalTreeNode(treeNode, schema, 0, 1);
    }
    return currentFilterTreeNode;
}
Also used : 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) RangeGlobalTreeNode(com.alibaba.maxgraph.compiler.tree.RangeGlobalTreeNode)

Example 3 with RangeGlobalTreeNode

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

Example 4 with RangeGlobalTreeNode

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

the class MaxGraphLimitStopStrategy method apply.

@Override
public void apply(TreeManager treeManager) {
    TreeNode currNode = treeManager.getTreeLeaf();
    boolean limitStopFlag = false;
    while (currNode instanceof UnaryTreeNode) {
        if (currNode instanceof RangeGlobalTreeNode) {
            RangeGlobalTreeNode rangeGlobalTreeNode = (RangeGlobalTreeNode) currNode;
            if (rangeGlobalTreeNode.getLow() == 0) {
                limitStopFlag = true;
            }
            break;
        }
        currNode = ((UnaryTreeNode) currNode).getInputNode();
    }
    if (limitStopFlag) {
        treeManager.getQueryConfig().addProperty(CompilerConstant.QUERY_SCHEDULE_GRANULARITY, QueryFlowOuterClass.InputBatchLevel.VerySmall.name());
        currNode.enableGlobalStop();
        TreeNode node = ((UnaryTreeNode) currNode).getInputNode();
        while (node instanceof UnaryTreeNode) {
            node.enableGlobalFilter();
            node = ((UnaryTreeNode) node).getInputNode();
        }
        node.enableGlobalFilter();
    }
}
Also used : RangeGlobalTreeNode(com.alibaba.maxgraph.compiler.tree.RangeGlobalTreeNode) UnaryTreeNode(com.alibaba.maxgraph.compiler.tree.UnaryTreeNode) TreeNode(com.alibaba.maxgraph.compiler.tree.TreeNode) UnaryTreeNode(com.alibaba.maxgraph.compiler.tree.UnaryTreeNode) RangeGlobalTreeNode(com.alibaba.maxgraph.compiler.tree.RangeGlobalTreeNode)

Aggregations

RangeGlobalTreeNode (com.alibaba.maxgraph.compiler.tree.RangeGlobalTreeNode)4 TreeNode (com.alibaba.maxgraph.compiler.tree.TreeNode)4 UnaryTreeNode (com.alibaba.maxgraph.compiler.tree.UnaryTreeNode)4 SourceTreeNode (com.alibaba.maxgraph.compiler.tree.source.SourceTreeNode)3 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 SelectOneTreeNode (com.alibaba.maxgraph.compiler.tree.SelectOneTreeNode)2 SumTreeNode (com.alibaba.maxgraph.compiler.tree.SumTreeNode)2 TokenTreeNode (com.alibaba.maxgraph.compiler.tree.TokenTreeNode)2 VertexTreeNode (com.alibaba.maxgraph.compiler.tree.VertexTreeNode)2 DfsFinishTreeNode (com.alibaba.maxgraph.compiler.tree.DfsFinishTreeNode)1 DfsRepeatGraphTreeNode (com.alibaba.maxgraph.compiler.tree.DfsRepeatGraphTreeNode)1 OrderGlobalTreeNode (com.alibaba.maxgraph.compiler.tree.OrderGlobalTreeNode)1 RepeatTreeNode (com.alibaba.maxgraph.compiler.tree.RepeatTreeNode)1 TreeManager (com.alibaba.maxgraph.compiler.tree.TreeManager)1 SourceDelegateNode (com.alibaba.maxgraph.compiler.tree.source.SourceDelegateNode)1