use of com.alibaba.maxgraph.compiler.api.schema.GraphEdge in project GraphScope by alibaba.
the class ConnectComponetsVertexProgramTreeNode method createOperatorArgument.
private Message.Value.Builder createOperatorArgument() {
Message.Value.Builder valueBuilder = Message.Value.newBuilder();
Message.ProgramCCArg.Builder ccArgumentBuilder = Message.ProgramCCArg.newBuilder();
String clusterProperty = ReflectionUtils.getFieldValue(ConnectedComponentVertexProgramStep.class, step, "clusterProperty");
PureTraversal<Vertex, Edge> edgeTraversal = ReflectionUtils.getFieldValue(ConnectedComponentVertexProgramStep.class, step, "edgeTraversal");
Parameters parameters = ReflectionUtils.getFieldValue(ConnectedComponentVertexProgramStep.class, step, "parameters");
if (parameters.contains(TIMES)) {
ArrayList<Object> times = (ArrayList<Object>) parameters.remove(TIMES);
ccArgumentBuilder.setLoopLimit((int) times.get(0));
} else {
ccArgumentBuilder.setLoopLimit(20);
}
if (clusterProperty.equals(ConnectedComponentVertexProgram.COMPONENT)) {
clusterProperty = COMPONENT;
}
ccArgumentBuilder.setPropertyCcId(SchemaUtils.getPropId(clusterProperty, schema));
List<Step> edgeTraversalSteps = edgeTraversal.getPure().getSteps();
VertexStep vstep = (VertexStep) edgeTraversalSteps.get(0);
for (String edgeLabel : vstep.getEdgeLabels()) {
GraphEdge edgeType = (GraphEdge) schema.getElement(edgeLabel);
ccArgumentBuilder.addEdgeLabels(edgeType.getLabelId());
}
if (Direction.BOTH.equals(vstep.getDirection())) {
ccArgumentBuilder.setDirection(Message.EdgeDirection.DIR_NONE);
} else if (Direction.IN.equals(vstep.getDirection())) {
ccArgumentBuilder.setDirection(Message.EdgeDirection.DIR_IN);
} else if (Direction.OUT.equals(vstep.getDirection())) {
ccArgumentBuilder.setDirection(Message.EdgeDirection.DIR_OUT);
} else {
checkArgument(false, "direction must be in/out/both for shortest path");
}
for (int i = 1; i < edgeTraversalSteps.size(); ++i) {
Step hasStep = edgeTraversalSteps.get(i);
if (hasStep instanceof HasStep) {
HasContainer hasContainer = (HasContainer) ((HasStep) hasStep).getHasContainers().get(0);
Object value = hasContainer.getPredicate().getValue();
GraphEdge edgeType = (GraphEdge) schema.getElement(value.toString());
ccArgumentBuilder.addEdgeLabels(edgeType.getLabelId());
}
}
valueBuilder.setPayload(ccArgumentBuilder.build().toByteString());
return valueBuilder;
}
use of com.alibaba.maxgraph.compiler.api.schema.GraphEdge 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.api.schema.GraphEdge in project GraphScope by alibaba.
the class LpaVertexProgramTreeNode method createOperatorArgument.
private Message.Value.Builder createOperatorArgument() {
Message.Value.Builder valueBuilder = Message.Value.newBuilder();
Message.ProgramLPAArg.Builder argBuilder = Message.ProgramLPAArg.newBuilder();
Traversal.Admin<Vertex, Edge> edgeTraversal = step.getLocalChildren().get(0);
List<Step> steps = edgeTraversal.getSteps();
// supports with(PageRank.edges,outE('knows'))
VertexStep vstep = (VertexStep) steps.get(0);
String[] labels = vstep.getEdgeLabels();
for (String edgeLabel : labels) {
GraphEdge edgeType = (GraphEdge) schema.getElement(edgeLabel);
argBuilder.addEdgeLabels(edgeType.getLabelId());
}
if (Direction.BOTH.equals(vstep.getDirection())) {
argBuilder.setDirection(Message.EdgeDirection.DIR_NONE);
} else if (Direction.IN.equals(vstep.getDirection())) {
argBuilder.setDirection(Message.EdgeDirection.DIR_IN);
} else if (Direction.OUT.equals(vstep.getDirection())) {
argBuilder.setDirection(Message.EdgeDirection.DIR_OUT);
} else {
checkArgument(false, "direction must be in/out/both for lpa");
}
for (int i = 1; i < steps.size(); ++i) {
Step step = steps.get(i);
if (step instanceof HasStep) {
HasContainer hasContainer = (HasContainer) ((HasStep) step).getHasContainers().get(0);
Object value = hasContainer.getPredicate().getValue();
GraphEdge edgeType = (GraphEdge) schema.getElement(value.toString());
argBuilder.addEdgeLabels(edgeType.getLabelId());
}
}
argBuilder.setSeedLabel(SchemaUtils.getPropId(step.getLabel(), schema));
argBuilder.setTargetLabel(SchemaUtils.getPropId(step.getProperty(), schema));
checkArgument(step.getMaxIterations() > 0, "iteration must > 0 for LPA");
argBuilder.setIteration(step.getMaxIterations());
valueBuilder.setPayload(argBuilder.build().toByteString());
return valueBuilder;
}
use of com.alibaba.maxgraph.compiler.api.schema.GraphEdge in project GraphScope by alibaba.
the class GraphSchemaMapper method parseFromSchema.
public static GraphSchemaMapper parseFromSchema(GraphSchema schema) {
GraphSchemaMapper schemaMapper = new GraphSchemaMapper();
schemaMapper.version = schema.getVersion();
schemaMapper.types = Lists.newArrayList();
for (GraphVertex graphVertex : schema.getVertexList()) {
schemaMapper.types.add(VertexTypeMapper.parseFromVertexType(graphVertex));
}
for (GraphEdge graphEdge : schema.getEdgeList()) {
schemaMapper.types.add(EdgeTypeMapper.parseFromEdgeType(graphEdge));
}
return schemaMapper;
}
use of com.alibaba.maxgraph.compiler.api.schema.GraphEdge in project GraphScope by alibaba.
the class CostDataStatistics method getOutERatio.
/**
* Compute outE scale ratio with start vertex label list and edge list
*
* @param input The given start vertex label list
* @param edgeList The given edge label list
* @return The result ratio
*/
public NodeStatistics getOutERatio(NodeStatistics input, Set<String> edgeList) {
GraphSchema schema = schemaFetcher.getSchemaSnapshotPair().getLeft();
NodeStatistics nodeStatistics = new NodeStatistics(schema);
Map<String, Double> inputVertexCountList = input.getVertexCountList();
for (String edgeLabel : edgeList) {
try {
GraphEdge edge = (GraphEdge) schema.getElement(edgeLabel);
List<EdgeRelation> relationList = edge.getRelationList();
if (relationList.size() > 0) {
double avgRelationRatio = 1.0 / edge.getRelationList().size();
relationList.stream().filter(v -> inputVertexCountList.containsKey(v.getSource().getLabel())).forEach(v -> {
double sourceVertexCount = inputVertexCountList.getOrDefault(v.getSource().getLabel(), INIT_VERTEX_COUNT);
double currEdgeCount = (this.edgeCountList.getOrDefault(edge.getLabel(), INIT_EDGE_COUNT) * avgRelationRatio / this.vertexCountList.getOrDefault(v.getSource().getLabel(), INIT_VERTEX_COUNT)) * sourceVertexCount;
nodeStatistics.addEdgeCount(edgeLabel, currEdgeCount);
});
}
} catch (Exception ignored) {
}
}
return nodeStatistics;
}
Aggregations