use of com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan in project GraphScope by alibaba.
the class GroupTreeNode method buildLogicalQueryPlan.
@Override
public LogicalSubQueryPlan buildLogicalQueryPlan(ContextManager contextManager) {
LogicalSubQueryPlan logicalSubQueryPlan = new LogicalSubQueryPlan(contextManager);
LogicalVertex sourceVertex = getInputNode().getOutputVertex();
logicalSubQueryPlan.addLogicalVertex(sourceVertex);
QueryFlowOuterClass.EnterKeyArgumentProto enterKeyArgumentProto = null;
if (keyTreeNode == null || keyTreeNode instanceof SourceDelegateNode) {
enterKeyArgumentProto = QueryFlowOuterClass.EnterKeyArgumentProto.newBuilder().setEnterKeyType(QueryFlowOuterClass.EnterKeyTypeProto.KEY_SELF).build();
} else if (UnaryTreeNode.class.cast(keyTreeNode).getInputNode() instanceof SourceDelegateNode) {
Optional<QueryFlowOuterClass.EnterKeyArgumentProto> propLabelId = TreeNodeUtils.parseEnterKeyArgument(keyTreeNode, schema, contextManager.getTreeNodeLabelManager());
if (propLabelId.isPresent()) {
enterKeyArgumentProto = propLabelId.get();
}
}
if (null != enterKeyArgumentProto) {
// use enter key operator to generate key data
ProcessorFunction enterKeyFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.ENTER_KEY, Message.Value.newBuilder().setPayload(enterKeyArgumentProto.toByteString()));
LogicalVertex enterKeyVertex = new LogicalUnaryVertex(contextManager.getVertexIdManager().getId(), enterKeyFunction, false, sourceVertex);
enterKeyArgumentProto.getPropIdListList().forEach(v -> {
if (v < 0) {
enterKeyFunction.getUsedLabelList().add(v);
}
});
if (enterKeyArgumentProto.getPropLabelId() < 0) {
enterKeyFunction.getUsedLabelList().add(enterKeyArgumentProto.getPropLabelId());
}
logicalSubQueryPlan.addLogicalVertex(enterKeyVertex);
logicalSubQueryPlan.addLogicalEdge(sourceVertex, enterKeyVertex, new LogicalEdge());
} else {
TreeNode currentKeyNode = TreeNodeUtils.buildSingleOutputNode(keyTreeNode, schema);
LogicalSubQueryPlan keyQueryPlan = TreeNodeUtils.buildSubQueryPlan(currentKeyNode, sourceVertex, contextManager, true);
LogicalVertex keyValueVertex = keyQueryPlan.getOutputVertex();
logicalSubQueryPlan.mergeLogicalQueryPlan(keyQueryPlan);
sourceVertex = TreeNodeUtils.getSourceTreeNode(keyTreeNode).getOutputVertex();
if (sourceVertex.getProcessorFunction().getOperatorType() == QueryFlowOuterClass.OperatorType.ENTER_KEY) {
ProcessorFunction joinKeyFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.JOIN_RIGHT_VALUE_KEY);
LogicalBinaryVertex joinKeyVertex = new LogicalBinaryVertex(contextManager.getVertexIdManager().getId(), joinKeyFunction, false, sourceVertex, keyValueVertex);
logicalSubQueryPlan.addLogicalVertex(joinKeyVertex);
logicalSubQueryPlan.addLogicalEdge(sourceVertex, joinKeyVertex, new LogicalEdge());
logicalSubQueryPlan.addLogicalEdge(keyValueVertex, joinKeyVertex, new LogicalEdge());
} else {
String keyValueLabel = contextManager.getTreeNodeLabelManager().createSysLabelStart(keyValueVertex, "val");
String sourceLabel = contextManager.getTreeNodeLabelManager().createSysLabelStart(sourceVertex, "source");
ProcessorFunction selectSourceFunction = TreeNodeUtils.createSelectOneFunction(sourceLabel, Pop.first, contextManager.getTreeNodeLabelManager().getLabelIndexList());
LogicalVertex selectVertex = new LogicalUnaryVertex(contextManager.getVertexIdManager().getId(), selectSourceFunction, false, keyValueVertex);
logicalSubQueryPlan.addLogicalVertex(selectVertex);
logicalSubQueryPlan.addLogicalEdge(keyValueVertex, selectVertex, new LogicalEdge(EdgeShuffleType.FORWARD));
int keyValueLabelId = contextManager.getTreeNodeLabelManager().getLabelIndex(keyValueLabel);
ProcessorFunction enterKeyFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.ENTER_KEY, Message.Value.newBuilder().setPayload(QueryFlowOuterClass.EnterKeyArgumentProto.newBuilder().setEnterKeyType(QueryFlowOuterClass.EnterKeyTypeProto.KEY_PROP_LABEL).setUniqFlag(false).setPropLabelId(keyValueLabelId).build().toByteString()));
enterKeyFunction.getUsedLabelList().add(keyValueLabelId);
LogicalVertex enterKeyVertex = new LogicalUnaryVertex(contextManager.getVertexIdManager().getId(), enterKeyFunction, false, selectVertex);
logicalSubQueryPlan.addLogicalVertex(enterKeyVertex);
logicalSubQueryPlan.addLogicalEdge(selectVertex, enterKeyVertex, new LogicalEdge(EdgeShuffleType.FORWARD));
}
}
LogicalVertex outputVertex = logicalSubQueryPlan.getOutputVertex();
LogicalSubQueryPlan aggregateQueryPlan = TreeNodeUtils.buildSubQueryPlan(valueTreeNode, outputVertex, contextManager, false);
LogicalVertex aggregateVertex = aggregateQueryPlan.getOutputVertex();
logicalSubQueryPlan.mergeLogicalQueryPlan(aggregateQueryPlan);
// convert by key value to entry
ProcessorFunction processorFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.BYKEY_ENTRY);
LogicalVertex bykeyEntryVertex = new LogicalUnaryVertex(contextManager.getVertexIdManager().getId(), processorFunction, false, aggregateVertex);
logicalSubQueryPlan.addLogicalVertex(bykeyEntryVertex);
logicalSubQueryPlan.addLogicalEdge(aggregateVertex, bykeyEntryVertex, new LogicalEdge());
outputVertex = logicalSubQueryPlan.getOutputVertex();
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.LogicalSubQueryPlan in project GraphScope by alibaba.
the class RangeGlobalTreeNode method buildLogicalQueryPlan.
@Override
public LogicalSubQueryPlan buildLogicalQueryPlan(ContextManager contextManager) {
TreeNodeLabelManager labelManager = contextManager.getTreeNodeLabelManager();
VertexIdManager vertexIdManager = contextManager.getVertexIdManager();
LogicalSubQueryPlan logicalSubQueryPlan = new LogicalSubQueryPlan(contextManager);
LogicalVertex sourceVertex = getInputNode().getOutputVertex();
logicalSubQueryPlan.addLogicalVertex(sourceVertex);
ProcessorFunction combinerFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.COMBINER_RANGE, createArgumentBuilder().addLongValueList(0).addLongValueList(high));
LogicalUnaryVertex combinerVertex = new LogicalUnaryVertex(vertexIdManager.getId(), combinerFunction, false, sourceVertex);
combinerVertex.setEarlyStopFlag(super.earlyStopArgument);
logicalSubQueryPlan.addLogicalVertex(combinerVertex);
logicalSubQueryPlan.addLogicalEdge(sourceVertex, combinerVertex, LogicalEdge.forwardEdge());
QueryFlowOuterClass.OperatorType operatorType = getUseKeyOperator(QueryFlowOuterClass.OperatorType.RANGE);
Message.Value.Builder argumentBuilder = Message.Value.newBuilder().addLongValueList(low).addLongValueList(high);
ProcessorFunction processorFunction = new ProcessorFunction(operatorType, argumentBuilder);
LogicalUnaryVertex rangeVertex = new LogicalUnaryVertex(vertexIdManager.getId(), processorFunction, false, combinerVertex);
logicalSubQueryPlan.addLogicalVertex(rangeVertex);
logicalSubQueryPlan.addLogicalEdge(combinerVertex, rangeVertex, new LogicalEdge());
addUsedLabelAndRequirement(rangeVertex, labelManager);
setFinishVertex(rangeVertex, labelManager);
return logicalSubQueryPlan;
}
use of com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan in project GraphScope by alibaba.
the class SourceDelegateNode method buildLogicalQueryPlan.
@Override
public LogicalSubQueryPlan buildLogicalQueryPlan(ContextManager contextManager) {
LogicalSubQueryPlan logicalSubQueryPlan = new LogicalSubQueryPlan(contextManager);
logicalSubQueryPlan.addLogicalVertex(getOutputVertex());
return logicalSubQueryPlan;
}
use of com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan in project GraphScope by alibaba.
the class SourceDfsTreeNode method buildLogicalQueryPlan.
@Override
public LogicalSubQueryPlan buildLogicalQueryPlan(ContextManager contextManager) {
LogicalSubQueryPlan logicalQueryPlan = new LogicalSubQueryPlan(contextManager);
logicalQueryPlan.setDelegateSourceFlag(false);
ProcessorSourceFunction processorSourceFunction = new ProcessorSourceFunction(QueryFlowOuterClass.OperatorType.DFS_SOURCE, Message.Value.newBuilder().setLongValue(batchSize), null);
return processSourceVertex(contextManager.getVertexIdManager(), contextManager.getTreeNodeLabelManager(), logicalQueryPlan, processorSourceFunction);
}
use of com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan in project GraphScope by alibaba.
the class SourceVertexTreeNode method buildLogicalQueryPlan.
@Override
public LogicalSubQueryPlan buildLogicalQueryPlan(ContextManager contextManager) {
LogicalSubQueryPlan logicalQueryPlan = new LogicalSubQueryPlan(contextManager);
logicalQueryPlan.setDelegateSourceFlag(false);
Message.Value.Builder argumentBuilder = Message.Value.newBuilder();
processLabelArgument(argumentBuilder, true);
processIdArgument(argumentBuilder, true);
Map<String, List<Integer>> primaryKeyLabelIdList = Maps.newHashMap();
for (GraphVertex vertexType : this.schema.getVertexList()) {
List<GraphProperty> primaryKeyList = vertexType.getPrimaryKeyList();
if (null != primaryKeyList && primaryKeyList.size() == 1) {
String propertyName = primaryKeyList.get(0).getName();
List<Integer> labelIdList = primaryKeyLabelIdList.computeIfAbsent(propertyName, k -> Lists.newArrayList());
labelIdList.add(vertexType.getLabelId());
}
}
QueryFlowOuterClass.VertexPrimaryKeyListProto.Builder primaryKeyBuilder = QueryFlowOuterClass.VertexPrimaryKeyListProto.newBuilder();
for (HasContainer container : this.hasContainerList) {
String key = container.getKey();
List<Integer> labelIdList = primaryKeyLabelIdList.get(key);
if (null != labelIdList) {
for (Integer labelId : labelIdList) {
if (container.getBiPredicate() instanceof Compare && container.getBiPredicate() == Compare.eq) {
primaryKeyBuilder.addPrimaryKeys(QueryFlowOuterClass.VertexPrimaryKeyProto.newBuilder().setLabelId(labelId).setPrimaryKeyValue(container.getValue().toString()));
} else if (container.getBiPredicate() instanceof Contains && container.getBiPredicate() == Contains.within) {
for (Object val : (Collection<Object>) container.getValue()) {
primaryKeyBuilder.addPrimaryKeys(QueryFlowOuterClass.VertexPrimaryKeyProto.newBuilder().setLabelId(labelId).setPrimaryKeyValue(val.toString()));
}
}
}
}
}
argumentBuilder.setPayload(primaryKeyBuilder.build().toByteString()).setBoolFlag(isPartitionIdFlag());
ProcessorSourceFunction processorSourceFunction = new ProcessorSourceFunction(getCountOperator(QueryFlowOuterClass.OperatorType.V), argumentBuilder, rangeLimit);
VertexIdManager vertexIdManager = contextManager.getVertexIdManager();
TreeNodeLabelManager treeNodeLabelManager = contextManager.getTreeNodeLabelManager();
LogicalSourceVertex logicalSourceVertex = new LogicalSourceVertex(vertexIdManager.getId(), processorSourceFunction);
logicalSourceVertex.getBeforeRequirementList().addAll(buildBeforeRequirementList(treeNodeLabelManager));
logicalSourceVertex.getAfterRequirementList().addAll(buildAfterRequirementList(treeNodeLabelManager));
getUsedLabelList().forEach(v -> processorSourceFunction.getUsedLabelList().add(treeNodeLabelManager.getLabelIndex(v)));
logicalQueryPlan.addLogicalVertex(logicalSourceVertex);
setFinishVertex(logicalQueryPlan.getOutputVertex(), treeNodeLabelManager);
return logicalQueryPlan;
}
Aggregations