use of com.baidu.hugegraph.structure.graph.Edge in project hugegraph-computer by hugegraph.
the class MockWorkerInputManager method loadEdgeInputSplitData.
public int loadEdgeInputSplitData() {
if (this.edgeInputSplit == null) {
throw new ComputerException("Should fetch edge input split meta " + "before load");
}
if (this.edgeInputSplit.equals(InputSplit.END_SPLIT)) {
throw new ComputerException("Can't load edge input split data, " + "because it has been exhausted");
}
EdgeFetcher edgeFetcher = this.fetcher.edgeFetcher();
edgeFetcher.prepareLoadInputSplit(this.edgeInputSplit);
int count = 0;
while (edgeFetcher.hasNext()) {
Edge edge = edgeFetcher.next();
// Write edge to buffer
Assert.assertNotNull(edge);
count++;
}
return count;
}
use of com.baidu.hugegraph.structure.graph.Edge in project hugegraph-computer by hugegraph.
the class FileEdgeFetcher method buildElement.
@Override
protected List<Edge> buildElement(Line line, ElementBuilder<Edge> builder) {
List<Edge> edges = super.buildElement(line, builder);
for (Edge edge : edges) {
// generate edgeId
EdgeLabel edgeLabel = (EdgeLabel) builder.schemaLabel();
String edgeId = IdUtil.assignEdgeId(edge, edgeLabel);
edge.id(edgeId);
}
return edges;
}
use of com.baidu.hugegraph.structure.graph.Edge in project incubator-hugegraph-toolchain by apache.
the class GraphService method buildEdge.
private EdgeHolder buildEdge(int connId, EdgeEntity entity) {
HugeClient client = this.client(connId);
GraphManager graph = client.graph();
EdgeLabelEntity el = this.elService.get(entity.getLabel(), connId);
VertexLabelEntity sourceVl = this.vlService.get(el.getSourceLabel(), connId);
VertexLabelEntity targetVl = this.vlService.get(el.getTargetLabel(), connId);
Object realSourceId = this.convertVertexId(sourceVl.getIdStrategy(), entity.getSourceId());
Object realTargetId = this.convertVertexId(targetVl.getIdStrategy(), entity.getTargetId());
Vertex sourceVertex = graph.getVertex(realSourceId);
Vertex targetVertex = graph.getVertex(realTargetId);
Ex.check(el.getSourceLabel().equals(sourceVertex.label()) && el.getTargetLabel().equals(targetVertex.label()), "graph.edge.link-unmatched-vertex", entity.getLabel(), el.getSourceLabel(), el.getTargetLabel(), sourceVertex.label(), targetVertex.label());
Edge edge = new Edge(entity.getLabel());
edge.source(sourceVertex);
edge.target(targetVertex);
this.fillProperties(connId, el, edge, entity.getProperties());
return new EdgeHolder(edge, sourceVertex, targetVertex);
}
use of com.baidu.hugegraph.structure.graph.Edge in project incubator-hugegraph-toolchain by apache.
the class GremlinQueryService method buildGraphView.
private GraphView buildGraphView(TypedResult result, HugeClient client) {
List<Object> data = result.getData();
if (!result.getType().isGraph() || CollectionUtils.isEmpty(data)) {
return GraphView.EMPTY;
}
Map<Object, Vertex> vertices = new HashMap<>();
Map<String, Edge> edges = new HashMap<>();
for (Object object : data) {
if (object instanceof Vertex) {
Vertex vertex = (Vertex) object;
vertices.put(vertex.id(), vertex);
} else if (object instanceof Edge) {
Edge edge = (Edge) object;
edges.put(edge.id(), edge);
} else if (object instanceof Path) {
List<Object> elements = ((Path) object).objects();
for (Object element : elements) {
if (element instanceof Vertex) {
Vertex vertex = (Vertex) element;
vertices.put(vertex.id(), vertex);
} else if (element instanceof Edge) {
Edge edge = (Edge) element;
edges.put(edge.id(), edge);
} else {
return GraphView.EMPTY;
}
}
}
}
if (!edges.isEmpty()) {
if (vertices.isEmpty()) {
vertices = this.verticesOfEdge(result, edges, client);
} else {
// TODO: reduce the number of requests
vertices.putAll(this.verticesOfEdge(result, edges, client));
}
} else {
if (!vertices.isEmpty()) {
edges = this.edgesOfVertex(result, vertices, client);
}
}
if (!edges.isEmpty()) {
Ex.check(!vertices.isEmpty(), "gremlin.edges.linked-vertex.not-exist");
}
return new GraphView(vertices.values(), edges.values());
}
use of com.baidu.hugegraph.structure.graph.Edge in project incubator-hugegraph-toolchain by apache.
the class OltpAlgoService method buildPathGraphView.
private GraphView buildPathGraphView(Path result) {
Map<Object, Vertex> vertices = new HashMap<>();
Map<String, Edge> edges = new HashMap<>();
List<Object> elements = result.objects();
for (Object element : elements) {
if (element instanceof Vertex) {
Vertex vertex = (Vertex) element;
vertices.put(vertex.id(), vertex);
} else if (element instanceof Edge) {
Edge edge = (Edge) element;
edges.put(edge.id(), edge);
} else {
return GraphView.EMPTY;
}
}
return new GraphView(vertices.values(), new ArrayList<>());
}
Aggregations