use of com.alibaba.maxgraph.compiler.tree.source.SourceDelegateNode in project GraphScope by alibaba.
the class TreeNodeUtils method buildQueryPlanWithSource.
/**
* Build query plan from given leaf tree node
*
* @param treeNode The given leaf tree node
* @param treeNodeLabelManager The tree node label manager
* @param contextManager The context manager
* @param vertexIdManager The vertex id manager
* @return The query plan of sub query
*/
public static LogicalSubQueryPlan buildQueryPlanWithSource(TreeNode treeNode, TreeNodeLabelManager treeNodeLabelManager, ContextManager contextManager, VertexIdManager vertexIdManager, LogicalVertex sourceVertex) {
List<TreeNode> treeNodeList = buildTreeNodeListFromLeaf(treeNode);
LogicalSubQueryPlan logicalSubQueryPlan = new LogicalSubQueryPlan(contextManager);
for (TreeNode currentNode : treeNodeList) {
if (currentNode instanceof SourceDelegateNode) {
currentNode.setFinishVertex(sourceVertex, treeNodeLabelManager);
}
logicalSubQueryPlan.mergeLogicalQueryPlan(currentNode.buildLogicalQueryPlan(contextManager));
}
return logicalSubQueryPlan;
}
use of com.alibaba.maxgraph.compiler.tree.source.SourceDelegateNode in project GraphScope by alibaba.
the class TreeNodeUtils method buildSubQueryWithLabel.
/**
* Build sub query plan, and save the result of sub plan to given label id
*
* @param treeNode The given tree node
* @param sourceVertex The given source vertex
* @param contextManager The given context manager
* @return The result query plan and label id
*/
public static Pair<LogicalQueryPlan, Integer> buildSubQueryWithLabel(TreeNode treeNode, LogicalVertex sourceVertex, ContextManager contextManager) {
boolean joinFlag = checkJoinSourceFlag(treeNode);
List<TreeNode> treeNodeList = buildTreeNodeListFromLeaf(treeNode);
LogicalQueryPlan queryPlan = new LogicalQueryPlan(contextManager);
LogicalVertex originalVertex = null;
LogicalVertex currentSourceVertex = sourceVertex;
for (TreeNode currentNode : treeNodeList) {
if (currentNode instanceof SourceDelegateNode) {
queryPlan.addLogicalVertex(sourceVertex);
if (joinFlag) {
LogicalVertex enterKeyVertex = new LogicalUnaryVertex(contextManager.getVertexIdManager().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, contextManager.getTreeNodeLabelManager());
queryPlan.addLogicalVertex(enterKeyVertex);
queryPlan.addLogicalEdge(sourceVertex, enterKeyVertex, new LogicalEdge());
currentSourceVertex = enterKeyVertex;
originalVertex = enterKeyVertex;
} else {
currentNode.setFinishVertex(sourceVertex, contextManager.getTreeNodeLabelManager());
originalVertex = sourceVertex;
}
} else {
queryPlan.mergeLogicalQueryPlan(currentNode.buildLogicalQueryPlan(contextManager));
}
}
checkNotNull(originalVertex, "original vertex can't be null");
LogicalVertex valueVertex = queryPlan.getOutputVertex();
String valueLabel = contextManager.getTreeNodeLabelManager().createSysLabelStart("val");
int valueLabelId = contextManager.getTreeNodeLabelManager().getLabelIndex(valueLabel);
if (joinFlag) {
LogicalVertex joinVertex;
if (treeNode instanceof CountGlobalTreeNode || treeNode instanceof SumTreeNode) {
joinVertex = new LogicalBinaryVertex(contextManager.getVertexIdManager().getId(), new ProcessorFunction(QueryFlowOuterClass.OperatorType.JOIN_COUNT_LABEL, Message.Value.newBuilder().setIntValue(valueLabelId)), false, originalVertex, valueVertex);
} else {
joinVertex = new LogicalBinaryVertex(contextManager.getVertexIdManager().getId(), new ProcessorFunction(QueryFlowOuterClass.OperatorType.JOIN_LABEL, Message.Value.newBuilder().setIntValue(valueLabelId)), false, originalVertex, valueVertex);
}
queryPlan.addLogicalVertex(joinVertex);
queryPlan.addLogicalEdge(originalVertex, joinVertex, LogicalEdge.shuffleByKey(0));
queryPlan.addLogicalEdge(valueVertex, joinVertex, LogicalEdge.forwardEdge());
} else {
LogicalVertex originalOutputVertex = queryPlan.getTargetVertex(originalVertex);
String originalLabel = contextManager.getTreeNodeLabelManager().createBeforeSysLabelStart(originalOutputVertex, "original");
ProcessorFunction selectFunction = createSelectOneFunction(originalLabel, Pop.first, contextManager.getTreeNodeLabelManager().getLabelIndexList());
LogicalVertex selectVertex = new LogicalUnaryVertex(contextManager.getVertexIdManager().getId(), selectFunction, valueVertex);
selectVertex.getBeforeRequirementList().add(QueryFlowOuterClass.RequirementValue.newBuilder().setReqType(QueryFlowOuterClass.RequirementType.LABEL_START).setReqArgument(Message.Value.newBuilder().addIntValueList(valueLabelId)));
queryPlan.addLogicalVertex(selectVertex);
queryPlan.addLogicalEdge(valueVertex, selectVertex, LogicalEdge.forwardEdge());
}
return Pair.of(queryPlan, valueLabelId);
}
use of com.alibaba.maxgraph.compiler.tree.source.SourceDelegateNode 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