use of com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan in project GraphScope by alibaba.
the class TreeNodeUtils method buildSubQueryPlanWithKey.
/**
* @param treeNode The given tree node
* @param sourceVertex The source vertex
* @param treeNodeLabelManager The given label manager
* @param contextManager The context manager
* @param vertexIdManager The vertex id manager
* @return The sub query with enter key vertex
*/
public static LogicalSubQueryPlan buildSubQueryPlanWithKey(TreeNode treeNode, LogicalVertex sourceVertex, TreeNodeLabelManager treeNodeLabelManager, ContextManager contextManager, VertexIdManager vertexIdManager) {
List<TreeNode> treeNodeList = buildTreeNodeListFromLeaf(treeNode);
LogicalSubQueryPlan logicalSubQueryPlan = new LogicalSubQueryPlan(contextManager);
LogicalVertex currentSourceVertex = sourceVertex;
for (TreeNode currentNode : treeNodeList) {
if (currentNode instanceof AbstractUseKeyNode) {
((AbstractUseKeyNode) currentNode).enableUseKeyFlag(currentSourceVertex);
}
if (currentNode instanceof SourceDelegateNode) {
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;
}
logicalSubQueryPlan.mergeLogicalQueryPlan(currentNode.buildLogicalQueryPlan(contextManager));
}
return logicalSubQueryPlan;
}
use of com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan in project GraphScope by alibaba.
the class TreeNodeUtils method buildQueryPlan.
/**
* Build query plan from given leaf tree node
*
* @param treeNode The given leaf tree node
* @param treeNodeLabelManager The tree node label manager
* @param contextManager The context manager
* @param vertexIdManager The vertex id manager
* @return The query plan of sub query
*/
public static LogicalSubQueryPlan buildQueryPlan(TreeNode treeNode, TreeNodeLabelManager treeNodeLabelManager, ContextManager contextManager, VertexIdManager vertexIdManager) {
List<TreeNode> treeNodeList = buildTreeNodeListFromLeaf(treeNode);
LogicalSubQueryPlan logicalSubQueryPlan = new LogicalSubQueryPlan(contextManager);
for (TreeNode currentNode : treeNodeList) {
logicalSubQueryPlan.mergeLogicalQueryPlan(currentNode.buildLogicalQueryPlan(contextManager));
}
return logicalSubQueryPlan;
}
use of com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan in project GraphScope by alibaba.
the class TreeNodeUtils method buildFilterTreeNode.
/**
* Build logical plan with filter tree node and output the input value
*/
public static LogicalVertex buildFilterTreeNode(TreeNode treeNode, ContextManager contextManager, LogicalQueryPlan logicalQueryPlan, LogicalVertex sourceVertex, GraphSchema schema) {
TreeNodeLabelManager labelManager = contextManager.getTreeNodeLabelManager();
VertexIdManager vertexIdManager = contextManager.getVertexIdManager();
TreeNode filterTreeNode = TreeNodeUtils.optimizeSubFilterNode(treeNode);
UnaryTreeNode unaryTreeNode = UnaryTreeNode.class.cast(filterTreeNode);
LogicalVertex outputVertex;
if (unaryTreeNode.getInputNode() instanceof SourceTreeNode && (unaryTreeNode instanceof SelectOneTreeNode || unaryTreeNode instanceof PropertyNode)) {
// optimize traversal filter to filter operator
int propId;
if (unaryTreeNode instanceof SelectOneTreeNode) {
propId = labelManager.getLabelIndex(SelectOneTreeNode.class.cast(unaryTreeNode).getSelectLabel());
} else {
propId = SchemaUtils.getPropId(PropertyNode.class.cast(unaryTreeNode).getPropKeyList().iterator().next(), schema);
}
Message.LogicalCompare logicalCompare = Message.LogicalCompare.newBuilder().setCompare(Message.CompareType.EXIST).setPropId(propId).build();
ProcessorFilterFunction processorFunction = new ProcessorFilterFunction(QueryFlowOuterClass.OperatorType.HAS);
if (propId < 0) {
processorFunction.getUsedLabelList().add(propId);
}
processorFunction.getLogicalCompareList().add(logicalCompare);
outputVertex = new LogicalUnaryVertex(vertexIdManager.getId(), processorFunction, false, sourceVertex);
logicalQueryPlan.addLogicalVertex(outputVertex);
logicalQueryPlan.addLogicalEdge(sourceVertex, outputVertex, new LogicalEdge());
} else {
TreeNode currentFilterTreeNode = TreeNodeUtils.buildSingleOutputNode(filterTreeNode, schema);
// build filter plan, and use join direct filter vertex to filter left stream
LogicalSubQueryPlan filterPlan = TreeNodeUtils.buildSubQueryPlan(currentFilterTreeNode, sourceVertex, contextManager);
TreeNode filterSourceNode = TreeNodeUtils.getSourceTreeNode(currentFilterTreeNode);
sourceVertex = filterSourceNode.getOutputVertex();
LogicalVertex rightVertex = filterPlan.getOutputVertex();
logicalQueryPlan.mergeLogicalQueryPlan(filterPlan);
if (TreeNodeUtils.checkJoinSourceFlag(currentFilterTreeNode)) {
LogicalBinaryVertex filterJoinVertex = new LogicalBinaryVertex(vertexIdManager.getId(), new ProcessorFunction(QueryFlowOuterClass.OperatorType.JOIN_DIRECT_FILTER), false, sourceVertex, rightVertex);
logicalQueryPlan.addLogicalVertex(filterJoinVertex);
logicalQueryPlan.addLogicalEdge(sourceVertex, filterJoinVertex, new LogicalEdge());
logicalQueryPlan.addLogicalEdge(rightVertex, filterJoinVertex, new LogicalEdge());
outputVertex = filterJoinVertex;
} else if (TreeNodeUtils.checkSelectFlag(currentFilterTreeNode)) {
String inputLabel = labelManager.createSysLabelStart(sourceVertex, "input");
ProcessorFunction selectFunction = createSelectOneFunction(inputLabel, Pop.last, labelManager.getLabelIndexList());
LogicalUnaryVertex selectVertex = new LogicalUnaryVertex(vertexIdManager.getId(), selectFunction, false, rightVertex);
logicalQueryPlan.addLogicalVertex(selectVertex);
logicalQueryPlan.addLogicalEdge(rightVertex, selectVertex, new LogicalEdge());
outputVertex = logicalQueryPlan.getOutputVertex();
} else {
outputVertex = logicalQueryPlan.getOutputVertex();
}
}
return outputVertex;
}
use of com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan in project GraphScope by alibaba.
the class UnionTreeNode method buildLogicalQueryPlan.
@Override
public LogicalSubQueryPlan buildLogicalQueryPlan(ContextManager contextManager) {
TreeNodeLabelManager labelManager = contextManager.getTreeNodeLabelManager();
VertexIdManager vertexIdManager = contextManager.getVertexIdManager();
if (unionTreeNodeList.isEmpty()) {
throw new IllegalArgumentException("union tree node list is empty");
} else {
LogicalSubQueryPlan logicalSubQueryPlan = new LogicalSubQueryPlan(contextManager);
LogicalVertex delegateSourceVertex = getInputNode().getOutputVertex();
logicalSubQueryPlan.addLogicalVertex(delegateSourceVertex);
LogicalVertex unionVertex = null;
for (TreeNode treeNode : unionTreeNodeList) {
LogicalSubQueryPlan unionPlan = TreeNodeUtils.buildQueryPlan(treeNode, labelManager, contextManager, vertexIdManager);
LogicalVertex currentUnionVertex = unionPlan.getOutputVertex();
logicalSubQueryPlan.mergeLogicalQueryPlan(unionPlan);
if (null == unionVertex) {
unionVertex = currentUnionVertex;
} else {
LogicalBinaryVertex binaryVertex = new LogicalBinaryVertex(vertexIdManager.getId(), new ProcessorFunction(QueryFlowOuterClass.OperatorType.UNION), false, unionVertex, currentUnionVertex);
logicalSubQueryPlan.addLogicalVertex(binaryVertex);
logicalSubQueryPlan.addLogicalEdge(unionVertex, binaryVertex, new LogicalEdge(EdgeShuffleType.FORWARD));
logicalSubQueryPlan.addLogicalEdge(currentUnionVertex, binaryVertex, new LogicalEdge(EdgeShuffleType.FORWARD));
unionVertex = binaryVertex;
}
}
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 WherePredicateTreeNode method processSecondValueNode.
private int processSecondValueNode(ContextManager contextManager, VertexIdManager vertexIdManager, TreeNodeLabelManager labelManager, LogicalSubQueryPlan logicalSubQueryPlan, TreeNode secondRingNode) {
LogicalVertex valueVertex = logicalSubQueryPlan.getOutputVertex();
LogicalSubQueryPlan targetSubQueryPlan = TreeNodeUtils.buildSubQueryPlan(secondRingNode, valueVertex, contextManager);
logicalSubQueryPlan.mergeLogicalQueryPlan(targetSubQueryPlan);
LogicalVertex targetValueVertex = targetSubQueryPlan.getOutputVertex();
String targetLabel = labelManager.createSysLabelStart(targetValueVertex, "val");
return labelManager.getLabelIndex(targetLabel);
}
Aggregations