use of com.alibaba.maxgraph.compiler.logical.function.ProcessorSourceFunction 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.function.ProcessorSourceFunction 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;
}
use of com.alibaba.maxgraph.compiler.logical.function.ProcessorSourceFunction in project GraphScope by alibaba.
the class LogicalQueryPlan method optimizeGraphVertex.
private void optimizeGraphVertex() {
List<LogicalVertex> logicalVertexList = this.getLogicalVertexList();
LogicalVertex graphVertex = null;
for (LogicalVertex logicalVertex : logicalVertexList) {
if (logicalVertex.getProcessorFunction().getOperatorType() == QueryFlowOuterClass.OperatorType.SUBGRAPH) {
graphVertex = logicalVertex;
break;
}
}
if (null != graphVertex) {
List<Pair<LogicalEdge, LogicalVertex>> graphSourceVertexList = this.getSourceEdgeVertexList(graphVertex);
List<Pair<LogicalEdge, LogicalVertex>> graphTargetVertexList = this.getTargetEdgeVertexList(graphVertex);
if (graphTargetVertexList != null && graphTargetVertexList.size() == 1) {
LogicalVertex targetVertex = graphTargetVertexList.get(0).getRight();
if (targetVertex.getProcessorFunction().getOperatorType() == QueryFlowOuterClass.OperatorType.OUTPUT_VINEYARD_VERTEX) {
return;
}
}
if (graphSourceVertexList.size() == 1) {
LogicalVertex graphSourceVertex = graphSourceVertexList.get(0).getRight();
if (graphSourceVertex.getProcessorFunction() instanceof ProcessorSourceFunction) {
ProcessorSourceFunction processorSourceFunction = ProcessorSourceFunction.class.cast(graphSourceVertex.getProcessorFunction());
processorSourceFunction.resetOperatorType(QueryFlowOuterClass.OperatorType.SUBGRAPH_SOURCE);
if (graphVertex.getProcessorFunction().getArgumentBuilder() != null) {
processorSourceFunction.getArgumentBuilder().mergeFrom(graphVertex.getProcessorFunction().getArgumentBuilder().build());
}
this.removeVertex(graphVertex);
}
}
}
}
use of com.alibaba.maxgraph.compiler.logical.function.ProcessorSourceFunction 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.function.ProcessorSourceFunction 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);
}
Aggregations