use of com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan in project GraphScope by alibaba.
the class DfsFinishTreeNode method buildLogicalQueryPlan.
@Override
public LogicalSubQueryPlan buildLogicalQueryPlan(ContextManager contextManager) {
LogicalSubQueryPlan logicalSubQueryPlan = new LogicalSubQueryPlan(contextManager);
LogicalVertex delegateSourceVertex = getInputNode().getOutputVertex();
logicalSubQueryPlan.addLogicalVertex(delegateSourceVertex);
LogicalVertex countVertex = new LogicalUnaryVertex(contextManager.getVertexIdManager().getId(), new ProcessorFunction(QueryFlowOuterClass.OperatorType.COUNT), false, delegateSourceVertex);
logicalSubQueryPlan.addLogicalVertex(countVertex);
logicalSubQueryPlan.addLogicalEdge(delegateSourceVertex, countVertex, new LogicalEdge());
Message.Value.Builder argument = Message.Value.newBuilder().setLongValue(maxRecordCount);
LogicalVertex dfsFinishVertex = new LogicalBinaryVertex(contextManager.getVertexIdManager().getId(), new ProcessorFunction(QueryFlowOuterClass.OperatorType.DFS_FINISH_JOIN, argument), true, repeatSourceVertex, countVertex);
logicalSubQueryPlan.addLogicalVertex(dfsFinishVertex);
logicalSubQueryPlan.addLogicalEdge(countVertex, dfsFinishVertex, new LogicalEdge(EdgeShuffleType.SHUFFLE_BY_CONST));
return logicalSubQueryPlan;
}
use of com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan in project GraphScope by alibaba.
the class SelectTreeNode method buildLogicalQueryPlan.
@Override
public LogicalSubQueryPlan buildLogicalQueryPlan(ContextManager contextManager) {
TreeNodeLabelManager labelManager = contextManager.getTreeNodeLabelManager();
VertexIdManager vertexIdManager = contextManager.getVertexIdManager();
Set<String> labelStartList = (Set<String>) this.beforeRequirementList.get(QueryFlowOuterClass.RequirementType.LABEL_START);
if (!traversalTreeNodeList.isEmpty() && null != labelStartList && !labelStartList.isEmpty()) {
for (int i = 0; i < selectKeyList.size(); i++) {
String selectKey = selectKeyList.get(i);
TreeNode selectTreeNode = traversalTreeNodeList.get(i % traversalTreeNodeList.size());
if (!(selectTreeNode instanceof SourceDelegateNode)) {
labelStartList.remove(selectKey);
}
}
}
if (null == labelStartList || labelStartList.isEmpty()) {
this.beforeRequirementList.remove(QueryFlowOuterClass.RequirementType.LABEL_START);
}
if (!contextManager.getCostModelManager().hasBestPath()) {
Map<String, Integer> labelIndexList = labelManager.getLabelIndexList();
if (traversalTreeNodeList.isEmpty()) {
Set<String> selectKeySet = Sets.newHashSet();
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());
List<Integer> selectKeyIdList = Lists.newArrayList();
for (String selectKey : selectKeyList) {
if (selectKeySet.contains(selectKey)) {
continue;
}
selectKeySet.add(selectKey);
if (!labelIndexList.containsKey(selectKey)) {
argumentBuilder.setBoolValue(false);
break;
}
selectKeyIdList.add(labelIndexList.get(selectKey));
}
argumentBuilder.addAllIntValueList(selectKeyIdList).addAllStrValueList(selectKeyIdList.stream().map(v -> labelManager.getLabelName(v)).collect(Collectors.toList()));
ProcessorFunction processorFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.SELECT, argumentBuilder);
return parseSingleUnaryVertex(vertexIdManager, labelManager, processorFunction, contextManager);
} else {
LogicalSubQueryPlan logicalSubQueryPlan = parseJoinQueryPlan(contextManager, vertexIdManager, labelManager, labelIndexList);
LogicalVertex outputVertex = logicalSubQueryPlan.getOutputVertex();
addUsedLabelAndRequirement(outputVertex, labelManager);
setFinishVertex(outputVertex, labelManager);
return logicalSubQueryPlan;
}
} else {
Map<String, Integer> labelIndexList = labelManager.getLabelIndexList();
Set<String> selectKeySet = Sets.newHashSet();
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());
List<Integer> selectKeyIdList = Lists.newArrayList();
for (String selectKey : selectKeyList) {
if (selectKeySet.contains(selectKey)) {
continue;
}
selectKeySet.add(selectKey);
if (!labelIndexList.containsKey(selectKey)) {
argumentBuilder.setBoolValue(false);
break;
}
selectKeyIdList.add(labelIndexList.get(selectKey));
}
argumentBuilder.addAllIntValueList(selectKeyIdList).addAllStrValueList(selectKeyIdList.stream().map(v -> contextManager.getTreeNodeLabelManager().getLabelName(v)).collect(Collectors.toList()));
ProcessorFunction processorFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.SELECT, argumentBuilder);
return parseSingleUnaryVertex(contextManager.getVertexIdManager(), contextManager.getTreeNodeLabelManager(), processorFunction, contextManager);
}
}
use of com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan in project GraphScope by alibaba.
the class SubgraphTreeNode method buildLogicalQueryPlan.
@Override
public LogicalSubQueryPlan buildLogicalQueryPlan(ContextManager contextManager) {
TreeNodeLabelManager treeNodeLabelManager = contextManager.getTreeNodeLabelManager();
VertexIdManager vertexIdManager = contextManager.getVertexIdManager();
LogicalSubQueryPlan logicalSubQueryPlan = new LogicalSubQueryPlan(contextManager);
LogicalVertex sourceDelegateVertex = getInputNode().getOutputVertex();
logicalSubQueryPlan.addLogicalVertex(sourceDelegateVertex);
List<Integer> edgeLabelList = Lists.newArrayList();
if (sourceDelegateVertex.getProcessorFunction().getOperatorType() == QueryFlowOuterClass.OperatorType.E) {
Message.Value.Builder argumentBuilder = sourceDelegateVertex.getProcessorFunction().getArgumentBuilder();
edgeLabelList.addAll(argumentBuilder.getIntValueListList());
}
Set<Integer> sourceVertexList = Sets.newHashSet();
Set<Integer> targetVertexList = Sets.newHashSet();
Message.SubgraphVertexList.Builder subgraphBuilder = Message.SubgraphVertexList.newBuilder();
for (Integer edgeLabel : edgeLabelList) {
GraphEdge edgeType = (GraphEdge) schema.getElement(edgeLabel);
for (EdgeRelation relationShip : edgeType.getRelationList()) {
sourceVertexList.add(relationShip.getSource().getLabelId());
targetVertexList.add(relationShip.getTarget().getLabelId());
}
}
if (sourceVertexList.isEmpty()) {
schema.getVertexList().forEach(v -> {
sourceVertexList.add(v.getLabelId());
targetVertexList.add(v.getLabelId());
});
}
subgraphBuilder.addAllSourceVertexList(sourceVertexList).addAllTargetVertexList(targetVertexList);
ProcessorFunction processorFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.SUBGRAPH, Message.Value.newBuilder().setBoolFlag(this.vertexFlag).setPayload(subgraphBuilder.build().toByteString()));
LogicalVertex graphVertex = new LogicalUnaryVertex(vertexIdManager.getId(), processorFunction, false, sourceDelegateVertex);
logicalSubQueryPlan.addLogicalVertex(graphVertex);
logicalSubQueryPlan.addLogicalEdge(sourceDelegateVertex, graphVertex, new LogicalEdge());
setFinishVertex(graphVertex, treeNodeLabelManager);
addUsedLabelAndRequirement(graphVertex, treeNodeLabelManager);
return logicalSubQueryPlan;
}
use of com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan in project GraphScope by alibaba.
the class SumTreeNode method buildLogicalQueryPlan.
@Override
public LogicalSubQueryPlan buildLogicalQueryPlan(ContextManager contextManager) {
TreeNodeLabelManager labelManager = contextManager.getTreeNodeLabelManager();
VertexIdManager vertexIdManager = contextManager.getVertexIdManager();
QueryFlowOuterClass.OperatorType operatorType = getUseKeyOperator(QueryFlowOuterClass.OperatorType.SUM);
LogicalSubQueryPlan logicalSubQueryPlan = new LogicalSubQueryPlan(contextManager);
LogicalVertex sourceVertex = getInputNode().getOutputVertex();
logicalSubQueryPlan.addLogicalVertex(sourceVertex);
ValueValueType valueValueType = ValueValueType.class.cast(getInputNode().getOutputValueType());
ProcessorFunction combinerSumFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.COMBINER_SUM, Message.Value.newBuilder().setValueType(valueValueType.getDataType()));
LogicalVertex combinerSumVertex = new LogicalUnaryVertex(vertexIdManager.getId(), combinerSumFunction, isPropLocalFlag(), sourceVertex);
logicalSubQueryPlan.addLogicalVertex(combinerSumVertex);
logicalSubQueryPlan.addLogicalEdge(sourceVertex, combinerSumVertex, LogicalEdge.forwardEdge());
ProcessorFunction sumFunction = new ProcessorFunction(operatorType, Message.Value.newBuilder().setValueType(valueValueType.getDataType()));
LogicalVertex sumVertex = new LogicalUnaryVertex(vertexIdManager.getId(), sumFunction, isPropLocalFlag(), combinerSumVertex);
logicalSubQueryPlan.addLogicalVertex(sumVertex);
logicalSubQueryPlan.addLogicalEdge(combinerSumVertex, sumVertex, new LogicalEdge());
LogicalVertex outputVertex = processJoinZeroVertex(vertexIdManager, logicalSubQueryPlan, sumVertex, isJoinZeroFlag());
setFinishVertex(outputVertex, labelManager);
return logicalSubQueryPlan;
}
use of com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan in project GraphScope by alibaba.
the class TraversalFilterTreeNode method buildLogicalQueryPlan.
@Override
public LogicalSubQueryPlan buildLogicalQueryPlan(ContextManager contextManager) {
TreeNodeLabelManager labelManager = contextManager.getTreeNodeLabelManager();
VertexIdManager vertexIdManager = contextManager.getVertexIdManager();
if (filterTreeNode instanceof SourceTreeNode) {
throw new IllegalArgumentException();
} else {
LogicalVertex sourceVertex = getInputNode().getOutputVertex();
LogicalSubQueryPlan logicalSubQueryPlan = new LogicalSubQueryPlan(contextManager);
logicalSubQueryPlan.addLogicalVertex(sourceVertex);
LogicalVertex outputVertex = TreeNodeUtils.buildFilterTreeNode(this.filterTreeNode, contextManager, logicalSubQueryPlan, sourceVertex, schema);
addUsedLabelAndRequirement(outputVertex, labelManager);
setFinishVertex(outputVertex, labelManager);
return logicalSubQueryPlan;
}
}
Aggregations