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;
}
Aggregations