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