use of com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan in project GraphScope by alibaba.
the class RatioEdgeVertexTreeNode method buildLogicalQueryPlan.
@Override
public LogicalSubQueryPlan buildLogicalQueryPlan(ContextManager contextManager) {
TreeNodeLabelManager labelManager = contextManager.getTreeNodeLabelManager();
VertexIdManager vertexIdManager = contextManager.getVertexIdManager();
TreeNode inputNode = this.getInputNode();
LogicalVertex inputVertex = inputNode.getOutputVertex();
TreeNode sourceNode = UnaryTreeNode.class.cast(inputNode).getInputNode();
LogicalVertex sourceVertex = sourceNode.getOutputVertex();
LogicalSubQueryPlan logicalSubQueryPlan = new LogicalSubQueryPlan(contextManager);
logicalSubQueryPlan.addLogicalVertex(inputVertex);
logicalSubQueryPlan.addLogicalVertex(sourceVertex);
ProcessorFunction countFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.COUNT);
LogicalUnaryVertex countVertex = new LogicalUnaryVertex(vertexIdManager.getId(), countFunction, false, sourceVertex);
logicalSubQueryPlan.addLogicalVertex(countVertex);
LogicalEdge countEdge = new LogicalEdge(EdgeShuffleType.SHUFFLE_BY_CONST);
countEdge.setStreamIndex(1);
logicalSubQueryPlan.addLogicalEdge(sourceVertex, countVertex, countEdge);
ProcessorFunction enterKeyFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.ENTER_KEY, Message.Value.newBuilder().setPayload(QueryFlowOuterClass.EnterKeyArgumentProto.newBuilder().setEnterKeyType(QueryFlowOuterClass.EnterKeyTypeProto.KEY_SELF).setUniqFlag(true).build().toByteString()));
LogicalVertex enterKeyVertex = new LogicalUnaryVertex(vertexIdManager.getId(), enterKeyFunction, false, sourceVertex);
logicalSubQueryPlan.addLogicalVertex(enterKeyVertex);
logicalSubQueryPlan.addLogicalEdge(sourceVertex, enterKeyVertex, new LogicalEdge(EdgeShuffleType.FORWARD));
ProcessorFunction valueFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.valueOf(direction.name() + "_V"));
LogicalUnaryVertex valueVertex = new LogicalUnaryVertex(vertexIdManager.getId(), valueFunction, false, enterKeyVertex);
logicalSubQueryPlan.addLogicalVertex(valueVertex);
LogicalEdge valueEdge = new LogicalEdge(EdgeShuffleType.SHUFFLE_BY_KEY);
logicalSubQueryPlan.addLogicalEdge(enterKeyVertex, valueVertex, valueEdge);
ProcessorFunction countByKeyFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.COUNT_BY_KEY, Message.Value.newBuilder().addIntValueList(0));
LogicalUnaryVertex countByKeyVertex = new LogicalUnaryVertex(vertexIdManager.getId(), countByKeyFunction, false, valueVertex);
logicalSubQueryPlan.addLogicalVertex(countByKeyVertex);
logicalSubQueryPlan.addLogicalEdge(valueVertex, countByKeyVertex, new LogicalEdge(EdgeShuffleType.SHUFFLE_BY_KEY));
ProcessorFunction ratioFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.JOIN_RATIO, Message.Value.newBuilder().setIntValue(CompilerUtils.parseCompareType(predicate, predicate.getBiPredicate()).getNumber()).setDoubleValue(Double.parseDouble(predicate.getValue().toString())));
LogicalBinaryVertex logicalBinaryVertex = new LogicalBinaryVertex(vertexIdManager.getId(), ratioFunction, true, countVertex, countByKeyVertex);
logicalSubQueryPlan.addLogicalVertex(logicalBinaryVertex);
logicalSubQueryPlan.addLogicalEdge(countVertex, logicalBinaryVertex, new LogicalEdge(EdgeShuffleType.BROADCAST));
logicalSubQueryPlan.addLogicalEdge(countByKeyVertex, logicalBinaryVertex, new LogicalEdge(EdgeShuffleType.FORWARD));
setFinishVertex(logicalBinaryVertex, labelManager);
addUsedLabelAndRequirement(logicalBinaryVertex, labelManager);
return logicalSubQueryPlan;
}
use of com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan in project GraphScope by alibaba.
the class RatioVertexTreeNode method buildLogicalQueryPlan.
@Override
public LogicalSubQueryPlan buildLogicalQueryPlan(ContextManager contextManager) {
TreeNodeLabelManager treeNodeLabelManager = contextManager.getTreeNodeLabelManager();
VertexIdManager vertexIdManager = contextManager.getVertexIdManager();
LogicalVertex sourceVertex = getInputNode().getOutputVertex();
LogicalSubQueryPlan logicalSubQueryPlan = new LogicalSubQueryPlan(contextManager);
logicalSubQueryPlan.addLogicalVertex(sourceVertex);
ProcessorFunction countFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.COUNT);
LogicalUnaryVertex countVertex = new LogicalUnaryVertex(vertexIdManager.getId(), countFunction, false, sourceVertex);
logicalSubQueryPlan.addLogicalVertex(countVertex);
LogicalEdge countEdge = new LogicalEdge(EdgeShuffleType.SHUFFLE_BY_CONST);
countEdge.setStreamIndex(0);
logicalSubQueryPlan.addLogicalEdge(sourceVertex, countVertex, countEdge);
ProcessorFunction enterKeyFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.ENTER_KEY, Message.Value.newBuilder().setPayload(QueryFlowOuterClass.EnterKeyArgumentProto.newBuilder().setEnterKeyType(QueryFlowOuterClass.EnterKeyTypeProto.KEY_SELF).setUniqFlag(true).build().toByteString()));
LogicalVertex enterKeyVertex = new LogicalUnaryVertex(vertexIdManager.getId(), enterKeyFunction, false, sourceVertex);
logicalSubQueryPlan.addLogicalVertex(enterKeyVertex);
LogicalEdge enterKeyEdge = new LogicalEdge(EdgeShuffleType.FORWARD);
enterKeyEdge.setStreamIndex(1);
logicalSubQueryPlan.addLogicalEdge(sourceVertex, enterKeyVertex, enterKeyEdge);
QueryFlowOuterClass.OperatorType valueOperatorType = QueryFlowOuterClass.OperatorType.valueOf(StringUtils.upperCase(direction.name()));
Message.Value.Builder argumentBuilder = Message.Value.newBuilder();
if (null != labelList) {
for (String label : labelList) {
try {
argumentBuilder.addIntValueList(schema.getElement(label).getLabelId());
} catch (Exception e) {
throw new RuntimeException("There's no edge label=>" + label);
}
}
}
ProcessorFunction valueFunction = new ProcessorFunction(valueOperatorType, argumentBuilder);
LogicalUnaryVertex valueVertex = new LogicalUnaryVertex(vertexIdManager.getId(), valueFunction, false, enterKeyVertex);
logicalSubQueryPlan.addLogicalVertex(valueVertex);
LogicalEdge valueEdge = new LogicalEdge(EdgeShuffleType.SHUFFLE_BY_KEY);
logicalSubQueryPlan.addLogicalEdge(enterKeyVertex, valueVertex, valueEdge);
ProcessorFunction countByKeyFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.COUNT_BY_KEY, Message.Value.newBuilder().addIntValueList(0));
LogicalUnaryVertex countByKeyVertex = new LogicalUnaryVertex(vertexIdManager.getId(), countByKeyFunction, false, valueVertex);
logicalSubQueryPlan.addLogicalVertex(countByKeyVertex);
logicalSubQueryPlan.addLogicalEdge(valueVertex, countByKeyVertex, new LogicalEdge(EdgeShuffleType.SHUFFLE_BY_KEY));
ProcessorFunction ratioFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.JOIN_RATIO, Message.Value.newBuilder().setIntValue(CompilerUtils.parseCompareType(predicate, predicate.getBiPredicate()).getNumber()).setDoubleValue(Double.parseDouble(predicate.getValue().toString())));
LogicalBinaryVertex logicalBinaryVertex = new LogicalBinaryVertex(vertexIdManager.getId(), ratioFunction, true, countVertex, countByKeyVertex);
logicalSubQueryPlan.addLogicalVertex(logicalBinaryVertex);
logicalSubQueryPlan.addLogicalEdge(countVertex, logicalBinaryVertex, new LogicalEdge(EdgeShuffleType.BROADCAST));
logicalSubQueryPlan.addLogicalEdge(countByKeyVertex, logicalBinaryVertex, new LogicalEdge(EdgeShuffleType.FORWARD));
setFinishVertex(logicalBinaryVertex, treeNodeLabelManager);
addUsedLabelAndRequirement(logicalBinaryVertex, treeNodeLabelManager);
return logicalSubQueryPlan;
}
use of com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan in project GraphScope by alibaba.
the class RepeatTreeNode method buildFilterResultPlan.
private LogicalVertex buildFilterResultPlan(ContextManager contextManager, VertexIdManager vertexIdManager, TreeNodeLabelManager labelManager, LogicalSubQueryPlan logicalSubQueryPlan, LogicalVertex delegateSourceVertex, TreeNode emitTreeNode) {
TreeNode currentEmitTreeNode = TreeNodeUtils.buildSingleOutputNode(emitTreeNode, schema);
LogicalSubQueryPlan untilPlan = TreeNodeUtils.buildSubQueryPlan(currentEmitTreeNode, delegateSourceVertex, contextManager);
LogicalVertex enterKeyVertex = TreeNodeUtils.getSourceTreeNode(currentEmitTreeNode).getOutputVertex();
LogicalVertex untilResultVertex = untilPlan.getOutputVertex();
logicalSubQueryPlan.mergeLogicalQueryPlan(untilPlan);
if (currentEmitTreeNode instanceof HasTreeNode && ((HasTreeNode) currentEmitTreeNode).getInputNode() instanceof SourceDelegateNode) {
return untilResultVertex;
} else {
LogicalVertex currentOutputVertex = new LogicalBinaryVertex(vertexIdManager.getId(), new ProcessorFunction(QueryFlowOuterClass.OperatorType.JOIN_DIRECT_FILTER), false, enterKeyVertex, untilResultVertex);
logicalSubQueryPlan.addLogicalVertex(currentOutputVertex);
logicalSubQueryPlan.addLogicalEdge(enterKeyVertex, currentOutputVertex, new LogicalEdge());
logicalSubQueryPlan.addLogicalEdge(untilResultVertex, currentOutputVertex, new LogicalEdge());
return currentOutputVertex;
}
}
use of com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan in project GraphScope by alibaba.
the class RepeatTreeNode 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);
List<LogicalVertex> outputVertexList = Lists.newArrayList();
LogicalVertex inputVertex = delegateSourceVertex;
ProcessorRepeatFunction processorRepeatFunction = new ProcessorRepeatFunction();
if (null != untilFirstTreeNode) {
Pair<LogicalVertex, Pair<LogicalVertex, LogicalSubQueryPlan>> untilTable = buildUntilQueryPlan(untilTreeNode, delegateSourceVertex, labelManager, contextManager, vertexIdManager);
outputVertexList.add(untilTable.getLeft());
inputVertex = untilTable.getRight().getLeft();
logicalSubQueryPlan.mergeLogicalQueryPlan(untilTable.getRight().getRight());
}
if (null != emitFirstTreeNode) {
LogicalVertex emitVertex;
if (emitFirstTreeNode instanceof SourceDelegateNode) {
emitVertex = inputVertex;
} else {
emitVertex = buildFilterResultPlan(contextManager, vertexIdManager, labelManager, logicalSubQueryPlan, inputVertex, emitFirstTreeNode);
}
outputVertexList.add(emitVertex);
processorRepeatFunction.enableEmitFlag();
}
checkArgument(null != repeatBodyTreeNode, "repeat body tree node can't be null");
processorRepeatFunction.setMaxLoopTimes(maxLoopTimes);
LogicalVertex repeatVertex = new LogicalUnaryVertex(vertexIdManager.getId(), processorRepeatFunction, false, inputVertex);
logicalSubQueryPlan.addLogicalVertex(repeatVertex);
logicalSubQueryPlan.addLogicalEdge(inputVertex, repeatVertex, new LogicalEdge());
List<LogicalVertex> leaveVertexList = Lists.newArrayList();
LogicalSubQueryPlan repeatBodyPlan = new LogicalSubQueryPlan(contextManager);
LogicalSourceDelegateVertex repeatSourceVertex = new LogicalSourceDelegateVertex(inputVertex);
repeatBodyPlan.addLogicalVertex(repeatSourceVertex);
repeatBodyPlan.mergeLogicalQueryPlan(TreeNodeUtils.buildQueryPlanWithSource(repeatBodyTreeNode, labelManager, contextManager, vertexIdManager, repeatSourceVertex));
LogicalVertex feedbackVertex = repeatBodyPlan.getOutputVertex();
if (null != untilTreeNode) {
Pair<LogicalVertex, Pair<LogicalVertex, LogicalSubQueryPlan>> untilTable = buildUntilQueryPlan(untilTreeNode, feedbackVertex, labelManager, contextManager, vertexIdManager);
feedbackVertex = untilTable.getRight().getLeft();
LogicalVertex untilVertex = untilTable.getLeft();
untilVertex.getAfterRequirementList().add(QueryFlowOuterClass.RequirementValue.newBuilder().setReqType(QueryFlowOuterClass.RequirementType.KEY_DEL));
leaveVertexList.add(untilVertex);
repeatBodyPlan.mergeLogicalQueryPlan(untilTable.getRight().getRight());
}
if (null != emitTreeNode) {
LogicalVertex emitVertex;
if (emitTreeNode instanceof SourceDelegateNode) {
emitVertex = feedbackVertex;
} else {
emitVertex = buildFilterResultPlan(contextManager, vertexIdManager, labelManager, repeatBodyPlan, feedbackVertex, emitTreeNode);
}
if (null != dfsEmitTreeNode) {
repeatBodyPlan.mergeLogicalQueryPlan(TreeNodeUtils.buildQueryPlanWithSource(dfsEmitTreeNode, labelManager, contextManager, vertexIdManager, emitVertex));
emitVertex = repeatBodyPlan.getOutputVertex();
}
leaveVertexList.add(emitVertex);
processorRepeatFunction.enableEmitFlag();
}
if (null != dfsFeedTreeNode) {
dfsFeedTreeNode.setRepeatSourceVertex(repeatBodyPlan.getTargetVertex(repeatSourceVertex));
LogicalSubQueryPlan dfsQueryPlan = TreeNodeUtils.buildQueryPlanWithSource(dfsFeedTreeNode, labelManager, contextManager, vertexIdManager, feedbackVertex);
feedbackVertex = dfsQueryPlan.getOutputVertex();
repeatBodyPlan.mergeLogicalQueryPlan(dfsQueryPlan);
}
processorRepeatFunction.setEnterVertex(repeatBodyPlan.getTargetVertex(repeatSourceVertex));
processorRepeatFunction.setFeedbackVertex(feedbackVertex);
processorRepeatFunction.setRepeatPlan(repeatBodyPlan);
if (!leaveVertexList.isEmpty()) {
if (leaveVertexList.size() == 1) {
processorRepeatFunction.setLeaveVertex(leaveVertexList.get(0));
} else {
LogicalVertex unionLeaveVertex = unionVertexList(vertexIdManager, repeatBodyPlan, leaveVertexList);
processorRepeatFunction.setLeaveVertex(unionLeaveVertex);
}
}
LogicalVertex outputVertex = repeatVertex;
if (!outputVertexList.isEmpty()) {
List<LogicalVertex> outputUnionVertexList = Lists.newArrayList(outputVertexList);
outputUnionVertexList.add(repeatVertex);
outputVertex = unionVertexList(vertexIdManager, logicalSubQueryPlan, outputUnionVertexList);
}
addUsedLabelAndRequirement(outputVertex, labelManager);
setFinishVertex(outputVertex, labelManager);
return logicalSubQueryPlan;
}
use of com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan in project GraphScope by alibaba.
the class RepeatTreeNode method buildUntilQueryPlan.
/**
* Build until query plan with given tree node
*
* @param untilTreeNode The given until tree node
* @param inputVertex The input vertex of until
* @return The table of result. The first one is until vertex, the second one is feedback vertex and the third one is result plan
*/
private Pair<LogicalVertex, Pair<LogicalVertex, LogicalSubQueryPlan>> buildUntilQueryPlan(TreeNode untilTreeNode, LogicalVertex inputVertex, TreeNodeLabelManager treeNodeLabelManager, ContextManager contextManager, VertexIdManager vertexIdManager) {
LogicalSubQueryPlan logicalSubQueryPlan = new LogicalSubQueryPlan(contextManager);
LogicalVertex untilVertex = null, feedbackVertex = null;
if (untilTreeNode instanceof NotTreeNode) {
NotTreeNode notTreeNode = NotTreeNode.class.cast(untilTreeNode);
TreeNode notFilterNode = notTreeNode.getNotTreeNode();
TreeNode currentUntilNode = TreeNodeUtils.buildSingleOutputNode(notFilterNode, schema);
LogicalSubQueryPlan untilPlan = TreeNodeUtils.buildSubQueryPlanWithKey(currentUntilNode, inputVertex, treeNodeLabelManager, contextManager, vertexIdManager);
LogicalVertex enterKeyVertex = TreeNodeUtils.getSourceTreeNode(currentUntilNode).getOutputVertex();
logicalSubQueryPlan.mergeLogicalQueryPlan(untilPlan);
LogicalVertex feedbackKeyVertex = untilPlan.getOutputVertex();
feedbackVertex = new LogicalUnaryVertex(vertexIdManager.getId(), new ProcessorFunction(QueryFlowOuterClass.OperatorType.KEY_MESSAGE), true, feedbackKeyVertex);
logicalSubQueryPlan.addLogicalVertex(feedbackVertex);
logicalSubQueryPlan.addLogicalEdge(feedbackKeyVertex, feedbackVertex, new LogicalEdge(EdgeShuffleType.FORWARD));
untilVertex = new LogicalBinaryVertex(vertexIdManager.getId(), new ProcessorFunction(QueryFlowOuterClass.OperatorType.JOIN_DIRECT_FILTER_NEGATE), false, enterKeyVertex, feedbackKeyVertex);
logicalSubQueryPlan.addLogicalVertex(untilVertex);
logicalSubQueryPlan.addLogicalEdge(enterKeyVertex, untilVertex, new LogicalEdge());
logicalSubQueryPlan.addLogicalEdge(feedbackKeyVertex, untilVertex, new LogicalEdge());
} else {
TreeNode currentUntilNode = TreeNodeUtils.buildSingleOutputNode(untilTreeNode, schema);
LogicalSubQueryPlan untilPlan = TreeNodeUtils.buildSubQueryPlanWithKey(currentUntilNode, inputVertex, treeNodeLabelManager, contextManager, vertexIdManager);
LogicalVertex enterKeyVertex = TreeNodeUtils.getSourceTreeNode(currentUntilNode).getOutputVertex();
LogicalVertex untilOutputVertex = untilPlan.getOutputVertex();
logicalSubQueryPlan.mergeLogicalQueryPlan(untilPlan);
feedbackVertex = new LogicalBinaryVertex(vertexIdManager.getId(), new ProcessorFunction(QueryFlowOuterClass.OperatorType.JOIN_DIRECT_FILTER_NEGATE), false, enterKeyVertex, untilOutputVertex);
logicalSubQueryPlan.addLogicalVertex(feedbackVertex);
logicalSubQueryPlan.addLogicalEdge(enterKeyVertex, feedbackVertex, new LogicalEdge());
logicalSubQueryPlan.addLogicalEdge(untilOutputVertex, feedbackVertex, new LogicalEdge());
untilVertex = new LogicalUnaryVertex(vertexIdManager.getId(), new ProcessorFunction(QueryFlowOuterClass.OperatorType.KEY_MESSAGE), true, untilOutputVertex);
logicalSubQueryPlan.addLogicalVertex(untilVertex);
logicalSubQueryPlan.addLogicalEdge(untilOutputVertex, untilVertex, new LogicalEdge(EdgeShuffleType.FORWARD));
}
return Pair.of(untilVertex, Pair.of(feedbackVertex, logicalSubQueryPlan));
}
Aggregations