use of com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan in project GraphScope by alibaba.
the class SelectOneTreeNode method buildLogicalQueryPlan.
@Override
public LogicalSubQueryPlan buildLogicalQueryPlan(ContextManager contextManager) {
TreeNodeLabelManager labelManager = contextManager.getTreeNodeLabelManager();
VertexIdManager vertexIdManager = contextManager.getVertexIdManager();
Map<String, Integer> labelIndexList = labelManager.getLabelIndexList();
ProcessorFunction selectOneFunction = TreeNodeUtils.createSelectOneFunction(selectLabel, pop, labelIndexList);
LogicalSubQueryPlan logicalSubQueryPlan = parseSingleUnaryVertex(vertexIdManager, labelManager, selectOneFunction, contextManager, LogicalEdge.shuffleByKey(0), null == traversalTreeNode);
if (null != traversalTreeNode && !contextManager.getCostModelManager().processFieldValue(selectLabel)) {
LogicalSubQueryPlan traversalValuePlan = TreeNodeUtils.buildSubQueryPlan(traversalTreeNode, logicalSubQueryPlan.getOutputVertex(), contextManager);
logicalSubQueryPlan.mergeLogicalQueryPlan(traversalValuePlan);
LogicalVertex outputVertex = logicalSubQueryPlan.getOutputVertex();
addUsedLabelAndRequirement(outputVertex, labelManager);
setFinishVertex(outputVertex, labelManager);
}
return logicalSubQueryPlan;
}
use of com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan in project GraphScope by alibaba.
the class SelectTreeNode method parseJoinQueryPlan.
private LogicalSubQueryPlan parseJoinQueryPlan(ContextManager contextManager, VertexIdManager vertexIdManager, TreeNodeLabelManager labelManager, Map<String, Integer> labelIndexList) {
LogicalSubQueryPlan logicalSubQueryPlan = new LogicalSubQueryPlan(contextManager);
LogicalVertex delegateSourceVertex = getInputNode().getOutputVertex();
logicalSubQueryPlan.addLogicalVertex(delegateSourceVertex);
Set<String> selectKeySet = Sets.newHashSet();
List<Integer> keyIdList = Lists.newArrayList();
List<Integer> valueIdList = Lists.newArrayList();
for (int i = 0; i < selectKeyList.size(); i++) {
String selectKey = selectKeyList.get(i);
if (selectKeySet.contains(selectKey)) {
continue;
}
selectKeySet.add(selectKey);
TreeNode traversalTreeNode = traversalTreeNodeList.get(i % traversalTreeNodeList.size());
int labelIndex = labelIndexList.get(selectKey);
keyIdList.add(labelIndex);
valueIdList.add(labelIndexList.get(selectKey));
if (!(traversalTreeNode instanceof SourceDelegateNode)) {
TreeNode currentTraversalNode = TreeNodeUtils.buildSingleOutputNode(traversalTreeNode, schema);
LogicalVertex outputVertex = logicalSubQueryPlan.getOutputVertex();
LogicalSubQueryPlan traversalPlan = TreeNodeUtils.buildSubQueryPlan(currentTraversalNode, outputVertex, contextManager);
List<LogicalVertex> resultVertexList = traversalPlan.getLogicalVertexList();
if (resultVertexList.size() == 2) {
LogicalVertex fieldValueVertex = resultVertexList.get(1);
ProcessorLabelValueFunction labelValueFunction = new ProcessorLabelValueFunction(labelIndex, fieldValueVertex);
labelValueFunction.setRequireLabelFlag(true);
LogicalVertex labelValueVertex = new LogicalUnaryVertex(vertexIdManager.getId(), labelValueFunction, outputVertex);
logicalSubQueryPlan.addLogicalVertex(labelValueVertex);
logicalSubQueryPlan.addLogicalEdge(outputVertex, labelValueVertex, LogicalEdge.shuffleByKey(labelIndex));
} else {
LogicalVertex fieldValueVertex = traversalPlan.getOutputVertex();
fieldValueVertex.getAfterRequirementList().add(QueryFlowOuterClass.RequirementValue.newBuilder().setReqType(QueryFlowOuterClass.RequirementType.LABEL_START).setReqArgument(Message.Value.newBuilder().addIntValueList(labelIndex)));
logicalSubQueryPlan.mergeLogicalQueryPlan(traversalPlan);
LogicalVertex outputKeyVertex = new LogicalUnaryVertex(vertexIdManager.getId(), new ProcessorFunction(QueryFlowOuterClass.OperatorType.KEY_MESSAGE), fieldValueVertex);
logicalSubQueryPlan.addLogicalVertex(outputKeyVertex);
logicalSubQueryPlan.addLogicalEdge(fieldValueVertex, outputKeyVertex, LogicalEdge.forwardEdge());
}
}
}
LogicalVertex selectInputVertex = logicalSubQueryPlan.getOutputVertex();
Message.Value.Builder argumentBuilder = Message.Value.newBuilder().setBoolValue(true).setIntValue(pop == null ? Message.PopType.POP_EMPTY.getNumber() : Message.PopType.valueOf(StringUtils.upperCase(pop.name())).getNumber()).addAllIntValueList(valueIdList).addAllStrValueList(keyIdList.stream().map(labelManager::getLabelName).collect(Collectors.toList()));
ProcessorFunction processorFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.SELECT, argumentBuilder);
processorFunction.getUsedLabelList().addAll(valueIdList);
LogicalVertex selectVertex = new LogicalUnaryVertex(vertexIdManager.getId(), processorFunction, false, selectInputVertex);
logicalSubQueryPlan.addLogicalVertex(selectVertex);
logicalSubQueryPlan.addLogicalEdge(selectInputVertex, selectVertex, new LogicalEdge(EdgeShuffleType.FORWARD));
return logicalSubQueryPlan;
}
use of com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan in project GraphScope by alibaba.
the class StoreTreeNode method buildLogicalQueryPlan.
@Override
public LogicalSubQueryPlan buildLogicalQueryPlan(ContextManager contextManager) {
TreeNodeLabelManager treeNodeLabelManager = contextManager.getTreeNodeLabelManager();
VertexIdManager vertexIdManager = contextManager.getVertexIdManager();
LogicalVertex storeVertex;
LogicalSubQueryPlan logicalSubQueryPlan;
if (null == storeTreeNode) {
ProcessorFunction processorFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.FOLD_STORE);
logicalSubQueryPlan = parseSingleUnaryVertex(vertexIdManager, treeNodeLabelManager, processorFunction, contextManager);
storeVertex = logicalSubQueryPlan.getOutputVertex();
} else {
logicalSubQueryPlan = new LogicalSubQueryPlan(contextManager);
LogicalVertex sourceVertex = getInputNode().getOutputVertex();
logicalSubQueryPlan.addLogicalVertex(sourceVertex);
LogicalSubQueryPlan storeQueryPlan = TreeNodeUtils.buildQueryPlanWithSource(storeTreeNode, treeNodeLabelManager, contextManager, vertexIdManager, sourceVertex);
logicalSubQueryPlan.mergeLogicalQueryPlan(storeQueryPlan);
LogicalVertex valueVertex = logicalSubQueryPlan.getOutputVertex();
ProcessorFunction processorFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.FOLD_STORE);
LogicalVertex foldVertex = new LogicalUnaryVertex(vertexIdManager.getId(), processorFunction, false, valueVertex);
logicalSubQueryPlan.addLogicalVertex(foldVertex);
logicalSubQueryPlan.addLogicalEdge(valueVertex, foldVertex, new LogicalEdge(EdgeShuffleType.SHUFFLE_BY_CONST));
storeVertex = logicalSubQueryPlan.getOutputVertex();
}
storeVertex.enableStoreFlag();
setFinishVertex(getInputNode().getOutputVertex(), treeNodeLabelManager);
contextManager.addStoreVertex(sideEffectKey, storeVertex);
return logicalSubQueryPlan;
}
use of com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan in project GraphScope by alibaba.
the class TraversalMapTreeNode method buildLogicalQueryPlan.
@Override
public LogicalSubQueryPlan buildLogicalQueryPlan(ContextManager contextManager) {
TreeNodeLabelManager labelManager = contextManager.getTreeNodeLabelManager();
VertexIdManager vertexIdManager = contextManager.getVertexIdManager();
LogicalSubQueryPlan logicalSubQueryPlan = new LogicalSubQueryPlan(contextManager);
LogicalVertex delegateSourceVertex = getInputNode().getOutputVertex();
logicalSubQueryPlan.addLogicalVertex(delegateSourceVertex);
TreeNode currTraversalNode = TreeNodeUtils.buildSingleOutputNode(traversalNode, schema);
LogicalSubQueryPlan traversalPlan = TreeNodeUtils.buildQueryPlanWithSource(currTraversalNode, labelManager, contextManager, vertexIdManager, delegateSourceVertex);
logicalSubQueryPlan.mergeLogicalQueryPlan(traversalPlan);
LogicalVertex outputVertex = logicalSubQueryPlan.getOutputVertex();
addUsedLabelAndRequirement(outputVertex, labelManager);
setFinishVertex(outputVertex, labelManager);
return logicalSubQueryPlan;
}
use of com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan in project GraphScope by alibaba.
the class AndTreeNode method buildLogicalQueryPlan.
@Override
public LogicalSubQueryPlan buildLogicalQueryPlan(ContextManager contextManager) {
LogicalSubQueryPlan logicalSubQueryPlan = new LogicalSubQueryPlan(contextManager);
LogicalVertex delegateSourceVertex = getInputNode().getOutputVertex();
logicalSubQueryPlan.addLogicalVertex(delegateSourceVertex);
LogicalVertex filterVertex = delegateSourceVertex;
for (TreeNode andTreeNode : andTreeNodeList) {
LogicalQueryPlan logicalQueryPlan = new LogicalQueryPlan(contextManager);
logicalQueryPlan.addLogicalVertex(filterVertex);
filterVertex = TreeNodeUtils.buildFilterTreeNode(andTreeNode, contextManager, logicalQueryPlan, filterVertex, schema);
logicalSubQueryPlan.mergeLogicalQueryPlan(logicalQueryPlan);
}
LogicalVertex outputVertex = logicalSubQueryPlan.getOutputVertex();
addUsedLabelAndRequirement(outputVertex, contextManager.getTreeNodeLabelManager());
setFinishVertex(outputVertex, contextManager.getTreeNodeLabelManager());
return logicalSubQueryPlan;
}
Aggregations