use of com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan 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;
}
use of com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan in project GraphScope by alibaba.
the class SourceCreateGraphTreeNode method buildLogicalQueryPlan.
@Override
public LogicalSubQueryPlan buildLogicalQueryPlan(ContextManager contextManager) {
LogicalSubQueryPlan logicalQueryPlan = new LogicalSubQueryPlan(contextManager);
logicalQueryPlan.setDelegateSourceFlag(false);
String graphType = configuration.getString(QUERY_CREATE_GRAPH_TYPE, null);
if (StringUtils.isEmpty(graphType)) {
throw new IllegalArgumentException("Graph type must be setted by g.createGraph(graphName).with('graphType'," + " '...')");
}
QueryFlowOuterClass.CreateGraphTypeProto createGraphType = QueryFlowOuterClass.CreateGraphTypeProto.valueOf(StringUtils.upperCase(graphType));
if (createGraphType == QueryFlowOuterClass.CreateGraphTypeProto.VINEYARD) {
QueryFlowOuterClass.RuntimeGraphSchemaProto schemaProto = CompilerUtils.buildRuntimeGraphSchema(schema);
ProcessorSourceFunction createGraphFunction = new ProcessorSourceFunction(QueryFlowOuterClass.OperatorType.GRAPH_VINEYARD_BUILDER, Message.Value.newBuilder().setStrValue(graphName).setPayload(schemaProto.toByteString()), null);
LogicalSourceVertex logicalSourceVertex = new LogicalSourceVertex(contextManager.getVertexIdManager().getId(), createGraphFunction);
logicalQueryPlan.addLogicalVertex(logicalSourceVertex);
ProcessorFunction streamFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.GRAPH_VINEYARD_STREAM, Message.Value.newBuilder().setStrValue(graphName));
LogicalUnaryVertex vineyardStreamVertex = new LogicalUnaryVertex(contextManager.getVertexIdManager().getId(), streamFunction, logicalSourceVertex);
logicalQueryPlan.addLogicalVertex(vineyardStreamVertex);
logicalQueryPlan.addLogicalEdge(logicalSourceVertex, vineyardStreamVertex, LogicalEdge.shuffleConstant());
setFinishVertex(logicalQueryPlan.getOutputVertex(), contextManager.getTreeNodeLabelManager());
return logicalQueryPlan;
} else {
throw new IllegalArgumentException("Only support create vineyard graph yet");
}
}
use of com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan in project GraphScope by alibaba.
the class SourceEdgeTreeNode method buildLogicalQueryPlan.
@Override
public LogicalSubQueryPlan buildLogicalQueryPlan(ContextManager contextManager) {
LogicalSubQueryPlan logicalQueryPlan = new LogicalSubQueryPlan(contextManager);
logicalQueryPlan.setDelegateSourceFlag(false);
Message.Value.Builder argumentBuilder = Message.Value.newBuilder().setBoolValue(true);
processLabelArgument(argumentBuilder, false);
processIdArgument(argumentBuilder, false);
ProcessorSourceFunction processorSourceFunction = new ProcessorSourceFunction(getCountOperator(QueryFlowOuterClass.OperatorType.E), argumentBuilder, rangeLimit);
return processSourceVertex(contextManager.getVertexIdManager(), contextManager.getTreeNodeLabelManager(), logicalQueryPlan, processorSourceFunction);
}
use of com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan in project GraphScope by alibaba.
the class WherePredicateTreeNode method processFirstValueNode.
private int processFirstValueNode(ContextManager contextManager, VertexIdManager vertexIdManager, TreeNodeLabelManager labelManager, LogicalSubQueryPlan logicalSubQueryPlan, TreeNode firstRingNode) {
LogicalVertex currentSourceVertex = logicalSubQueryPlan.getOutputVertex();
LogicalSubQueryPlan subQueryPlan = TreeNodeUtils.buildSubQueryPlan(firstRingNode, currentSourceVertex, contextManager);
logicalSubQueryPlan.mergeLogicalQueryPlan(subQueryPlan);
LogicalVertex valueVertex = subQueryPlan.getOutputVertex();
String sourceLabel = labelManager.createSysLabelStart(valueVertex, "val");
return labelManager.getLabelIndex(sourceLabel);
}
Aggregations