use of com.alibaba.maxgraph.compiler.tree.DfsFinishTreeNode 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());
}
Aggregations