use of com.alibaba.maxgraph.compiler.tree.TreeNodeLabelManager in project GraphScope by alibaba.
the class TreeNodeUtils method buildSubQueryPlan.
/**
* Build sub query plan from given leaf tree node
*
* @param treeNode The given leaf tree node
* @param sourceVertex The source vertex
* @param contextManager The context manager
* @param generateUseKey The flag of generated use key, it may be generated outside such as
* group
* @return The query plan of sub query
*/
public static LogicalSubQueryPlan buildSubQueryPlan(TreeNode treeNode, LogicalVertex sourceVertex, ContextManager contextManager, boolean generateUseKey) {
TreeNodeLabelManager treeNodeLabelManager = contextManager.getTreeNodeLabelManager();
VertexIdManager vertexIdManager = contextManager.getVertexIdManager();
List<TreeNode> treeNodeList = buildTreeNodeListFromLeaf(treeNode);
boolean useKeyFlag = checkNodeListUseKey(treeNodeList);
LogicalSubQueryPlan logicalSubQueryPlan = new LogicalSubQueryPlan(contextManager);
LogicalVertex currentSourceVertex = sourceVertex;
for (TreeNode currentNode : treeNodeList) {
if (currentNode instanceof AbstractUseKeyNode) {
((AbstractUseKeyNode) currentNode).enableUseKeyFlag(currentSourceVertex);
}
if (currentNode instanceof SourceDelegateNode) {
if (useKeyFlag && generateUseKey) {
LogicalVertex enterKeyVertex = new LogicalUnaryVertex(vertexIdManager.getId(), new ProcessorFunction(QueryFlowOuterClass.OperatorType.ENTER_KEY, Message.Value.newBuilder().setPayload(QueryFlowOuterClass.EnterKeyArgumentProto.newBuilder().setEnterKeyType(QueryFlowOuterClass.EnterKeyTypeProto.KEY_SELF).setUniqFlag(true).build().toByteString())), false, currentSourceVertex);
currentNode.setFinishVertex(enterKeyVertex, treeNodeLabelManager);
logicalSubQueryPlan.addLogicalVertex(currentSourceVertex);
logicalSubQueryPlan.addLogicalVertex(enterKeyVertex);
logicalSubQueryPlan.addLogicalEdge(currentSourceVertex, enterKeyVertex, new LogicalEdge());
currentSourceVertex = enterKeyVertex;
} else {
currentNode.setFinishVertex(currentSourceVertex, treeNodeLabelManager);
logicalSubQueryPlan.addLogicalVertex(currentSourceVertex);
}
}
logicalSubQueryPlan.mergeLogicalQueryPlan(currentNode.buildLogicalQueryPlan(contextManager));
}
return logicalSubQueryPlan;
}
Aggregations