Search in sources :

Example 1 with HasTreeNode

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

Aggregations

CountGlobalTreeNode (com.alibaba.maxgraph.compiler.tree.CountGlobalTreeNode)1 FoldTreeNode (com.alibaba.maxgraph.compiler.tree.FoldTreeNode)1 HasTreeNode (com.alibaba.maxgraph.compiler.tree.HasTreeNode)1 MaxTreeNode (com.alibaba.maxgraph.compiler.tree.MaxTreeNode)1 MinTreeNode (com.alibaba.maxgraph.compiler.tree.MinTreeNode)1 PropertyMapTreeNode (com.alibaba.maxgraph.compiler.tree.PropertyMapTreeNode)1 RangeGlobalTreeNode (com.alibaba.maxgraph.compiler.tree.RangeGlobalTreeNode)1 SelectOneTreeNode (com.alibaba.maxgraph.compiler.tree.SelectOneTreeNode)1 SumTreeNode (com.alibaba.maxgraph.compiler.tree.SumTreeNode)1 TokenTreeNode (com.alibaba.maxgraph.compiler.tree.TokenTreeNode)1 TreeNode (com.alibaba.maxgraph.compiler.tree.TreeNode)1 UnaryTreeNode (com.alibaba.maxgraph.compiler.tree.UnaryTreeNode)1 VertexTreeNode (com.alibaba.maxgraph.compiler.tree.VertexTreeNode)1 SourceTreeNode (com.alibaba.maxgraph.compiler.tree.source.SourceTreeNode)1 HasContainer (org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer)1 Direction (org.apache.tinkerpop.gremlin.structure.Direction)1