in vermeer/apps/worker/load_graph_bl.go [1386:1459]
func (eb *EdgesBl) GetEdges(spaceName string, graphName string, vertId string, direction string) ([]string, []string, []*pb.EdgeProperty, error) {
graph := GraphMgr.GetGraphByName(spaceName, graphName)
if graph == nil {
return []string{}, []string{}, []*pb.EdgeProperty{}, fmt.Errorf("graph %s not found", graphName)
}
shortId, ok := graph.Data.Vertex.GetVertexIndex(vertId)
if !ok {
return []string{}, []string{}, []*pb.EdgeProperty{}, fmt.Errorf("vertexId %s not found", vertId)
}
if shortId < graph.Data.VertIDStart ||
shortId >= graph.Data.VertIDStart+graph.Data.VertexCount {
return []string{}, []string{}, []*pb.EdgeProperty{}, fmt.Errorf("vertexId %s not in range", vertId)
}
getInEdges := func() ([]string, error) {
//if graph.Data.InEdges == nil {
// return []string{}, fmt.Errorf("inEdges is nil")
//}
inEdges := graph.Data.Edges.GetInEdges(shortId - graph.Data.VertIDStart)
edges := make([]string, 0, len(inEdges))
for _, s := range inEdges {
edges = append(edges, graph.Data.Vertex.GetVertex(uint32(s)).ID)
}
return edges, nil
}
getOutEdges := func() ([]string, error) {
if !graph.UseOutEdges {
return []string{}, fmt.Errorf("outEdges is nil")
}
outEdges := graph.Data.Edges.GetOutEdges(shortId - graph.Data.VertIDStart)
edges := make([]string, 0, len(outEdges))
for _, s := range outEdges {
edges = append(edges, graph.Data.Vertex.GetVertex(uint32(s)).ID)
}
return edges, nil
}
var edgeProperties []*pb.EdgeProperty
if graph != nil && graph.UseProperty {
inEdges, err := getInEdges()
if err != nil {
return []string{}, []string{}, []*pb.EdgeProperty{}, err
}
edgeProperties = make([]*pb.EdgeProperty, 0, len(inEdges))
for i, edge := range inEdges {
properties := &pb.EdgeProperty{}
properties.Edge = edge
properties.Property = make(map[string]string)
for _, ps := range graph.Data.InEdgesPropertySchema.Schema {
prop, err := graph.Data.InEdgesProperty.GetValue(ps.PropKey, shortId-graph.Data.VertIDStart, uint32(i))
if err != nil {
return []string{}, []string{}, []*pb.EdgeProperty{}, err
}
properties.Property[ps.PropKey] = prop.ToString()
}
edgeProperties = append(edgeProperties, properties)
}
}
if direction == "in" {
inEdges, err := getInEdges()
return inEdges, []string{}, edgeProperties, err
} else if direction == "out" {
outEdges, err := getOutEdges()
return []string{}, outEdges, []*pb.EdgeProperty{}, err
} else if direction == "both" {
inEdges, err := getInEdges()
outEdges, err := getOutEdges()
return inEdges, outEdges, []*pb.EdgeProperty{}, err
}
return []string{}, []string{}, []*pb.EdgeProperty{}, fmt.Errorf("direction %s not supported", direction)
}