use of com.alibaba.maxgraph.compiler.logical.LogicalVertex in project GraphScope by alibaba.
the class GroupCountTreeNode method buildLogicalQueryPlan.
@Override
public LogicalSubQueryPlan buildLogicalQueryPlan(ContextManager contextManager) {
LogicalSubQueryPlan logicalSubQueryPlan = new LogicalSubQueryPlan(contextManager);
LogicalVertex sourceVertex = getInputNode().getOutputVertex();
logicalSubQueryPlan.addLogicalVertex(sourceVertex);
LogicalVertex outputVertex;
if (null == keyTreeNode || keyTreeNode instanceof SourceDelegateNode) {
ProcessorFunction processorFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.GROUP_COUNT);
outputVertex = new LogicalUnaryVertex(contextManager.getVertexIdManager().getId(), processorFunction, false, sourceVertex);
logicalSubQueryPlan.addLogicalVertex(outputVertex);
logicalSubQueryPlan.addLogicalEdge(sourceVertex, outputVertex, new LogicalEdge());
} else {
TreeNode currentKeyNode = TreeNodeUtils.buildSingleOutputNode(keyTreeNode, schema);
if (currentKeyNode instanceof JoinZeroNode) {
((JoinZeroNode) currentKeyNode).disableJoinZero();
}
LogicalSubQueryPlan keyValuePlan = TreeNodeUtils.buildSubQueryPlan(currentKeyNode, sourceVertex, contextManager);
LogicalVertex groupValueVertex = keyValuePlan.getOutputVertex();
LogicalVertex enterKeyVertex = TreeNodeUtils.getSourceTreeNode(currentKeyNode).getOutputVertex();
logicalSubQueryPlan.mergeLogicalQueryPlan(keyValuePlan);
if (TreeNodeUtils.checkJoinSourceFlag(currentKeyNode)) {
String valueLabel = contextManager.getTreeNodeLabelManager().createSysLabelStart("val");
getUsedLabelList().add(valueLabel);
int valueLabelId = contextManager.getTreeNodeLabelManager().getLabelIndex(valueLabel);
LogicalBinaryVertex logicalBinaryVertex = new LogicalBinaryVertex(contextManager.getVertexIdManager().getId(), new ProcessorFunction(CompilerUtils.parseJoinOperatorType(currentKeyNode), Message.Value.newBuilder().setIntValue(valueLabelId)), false, enterKeyVertex, groupValueVertex);
logicalSubQueryPlan.addLogicalVertex(logicalBinaryVertex);
logicalSubQueryPlan.addLogicalEdge(enterKeyVertex, logicalBinaryVertex, new LogicalEdge());
logicalSubQueryPlan.addLogicalEdge(groupValueVertex, logicalBinaryVertex, new LogicalEdge());
ProcessorFunction selectValueFunction = TreeNodeUtils.createSelectOneFunction(valueLabel, Pop.first, contextManager.getTreeNodeLabelManager().getLabelIndexList());
LogicalVertex selectLabelVertex = new LogicalUnaryVertex(contextManager.getVertexIdManager().getId(), selectValueFunction, false, logicalBinaryVertex);
logicalSubQueryPlan.addLogicalVertex(selectLabelVertex);
logicalSubQueryPlan.addLogicalEdge(logicalBinaryVertex, selectLabelVertex, LogicalEdge.forwardEdge());
}
groupValueVertex = logicalSubQueryPlan.getOutputVertex();
ProcessorFunction processorFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.GROUP_COUNT, Message.Value.newBuilder());
outputVertex = new LogicalUnaryVertex(contextManager.getVertexIdManager().getId(), processorFunction, false, groupValueVertex);
logicalSubQueryPlan.addLogicalVertex(outputVertex);
logicalSubQueryPlan.addLogicalEdge(groupValueVertex, outputVertex, new LogicalEdge());
}
ProcessorFunction foldMapFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.FOLDMAP);
LogicalVertex foldMapVertex = new LogicalUnaryVertex(contextManager.getVertexIdManager().getId(), foldMapFunction, false, outputVertex);
logicalSubQueryPlan.addLogicalVertex(foldMapVertex);
logicalSubQueryPlan.addLogicalEdge(outputVertex, foldMapVertex, new LogicalEdge());
addUsedLabelAndRequirement(foldMapVertex, contextManager.getTreeNodeLabelManager());
setFinishVertex(foldMapVertex, contextManager.getTreeNodeLabelManager());
return logicalSubQueryPlan;
}
use of com.alibaba.maxgraph.compiler.logical.LogicalVertex in project GraphScope by alibaba.
the class CostEstimator method costQueryPlan.
/**
* This method computes the cost of an query plan.
*
* @param queryPlan The given query plan
* @param statistics The DataStatistics
* @param schema The Schema
* @return The costs of query plan
*/
public Costs costQueryPlan(LogicalQueryPlan queryPlan, DataStatistics statistics, GraphSchema schema) {
List<LogicalVertex> logicalVertexList = queryPlan.getLogicalVertexList();
Costs totalCosts = new Costs();
for (LogicalVertex logicalVertex : logicalVertexList) {
logicalVertex.computeOutputEstimates(statistics, schema);
Costs vertexCosts = costOperator(queryPlan, logicalVertex);
totalCosts.addCosts(vertexCosts);
}
return totalCosts;
}
use of com.alibaba.maxgraph.compiler.logical.LogicalVertex in project GraphScope by alibaba.
the class UnaryTreeNode method parseSingleUnaryVertex.
protected LogicalSubQueryPlan parseSingleUnaryVertex(VertexIdManager vertexIdManager, TreeNodeLabelManager labelManager, ProcessorFunction processorFunction, ContextManager contextManager, LogicalEdge logicalEdge, boolean outputFlag) {
LogicalSubQueryPlan logicalSubQueryPlan = new LogicalSubQueryPlan(contextManager);
LogicalVertex sourceVertex = getInputNode().getOutputVertex();
logicalSubQueryPlan.addLogicalVertex(sourceVertex);
LogicalUnaryVertex logicalUnaryVertex = new LogicalUnaryVertex(vertexIdManager.getId(), processorFunction, false, sourceVertex);
logicalUnaryVertex.setEarlyStopFlag(super.earlyStopArgument);
logicalSubQueryPlan.addLogicalVertex(logicalUnaryVertex);
logicalSubQueryPlan.addLogicalEdge(sourceVertex, logicalUnaryVertex, logicalEdge);
if (outputFlag) {
setFinishVertex(logicalUnaryVertex, labelManager);
addUsedLabelAndRequirement(logicalUnaryVertex, labelManager);
}
return logicalSubQueryPlan;
}
use of com.alibaba.maxgraph.compiler.logical.LogicalVertex in project GraphScope by alibaba.
the class PlanUtils method getOrderVertexList.
/**
* Get order vertex list for given plan
*
* @param plan The given plan
* @return The order vertex list
*/
public static List<LogicalVertex> getOrderVertexList(Graph<LogicalVertex, LogicalEdge> plan) {
List<LogicalVertex> logicalVertexList = Lists.newArrayList();
LinkedList<LogicalVertex> vertexQueue = Lists.newLinkedList();
vertexQueue.addAll(getSourceVertexList(plan));
while (!vertexQueue.isEmpty()) {
LogicalVertex currentVertex = vertexQueue.pop();
logicalVertexList.add(currentVertex);
List<LogicalVertex> targetVertexList = getTargetVertexList(plan, currentVertex);
for (LogicalVertex targetVertex : targetVertexList) {
List<LogicalVertex> sourceVertexList = getSourceVertexList(plan, targetVertex);
if (logicalVertexList.containsAll(sourceVertexList)) {
vertexQueue.push(targetVertex);
}
}
}
return logicalVertexList;
}
use of com.alibaba.maxgraph.compiler.logical.LogicalVertex 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);
}
Aggregations