use of com.baidu.hugegraph.structure.graph.Edge in project incubator-hugegraph-toolchain by apache.
the class CommonTraverserApiTest method testScanEdgeInPaging.
@Test
public void testScanEdgeInPaging() {
List<Shard> shards = edgesAPI.shards(1 * 1024 * 1024);
List<Edge> edges = new LinkedList<>();
for (Shard shard : shards) {
String page = "";
while (page != null) {
Edges results = edgesAPI.scan(shard, page, DEFAULT_PAGE_LIMIT);
edges.addAll(ImmutableList.copyOf(results.results()));
page = results.page();
}
}
Assert.assertEquals(6, edges.size());
}
use of com.baidu.hugegraph.structure.graph.Edge in project incubator-hugegraph-toolchain by apache.
the class CommonTraverserApiTest method testScanEdge.
@Test
public void testScanEdge() {
List<Shard> shards = edgesAPI.shards(1 * 1024 * 1024);
List<Edge> edges = new LinkedList<>();
for (Shard shard : shards) {
Edges results = edgesAPI.scan(shard, null, 0L);
Assert.assertNull(results.page());
edges.addAll(ImmutableList.copyOf(results.results()));
}
Assert.assertEquals(6, edges.size());
}
use of com.baidu.hugegraph.structure.graph.Edge in project incubator-hugegraph-toolchain by apache.
the class GraphService method addEdge.
public GraphView addEdge(int connId, EdgeEntity entity) {
HugeClient client = this.client(connId);
GraphManager graph = client.graph();
EdgeHolder edgeHolder = this.buildEdge(connId, entity);
Edge edge = graph.addEdge(edgeHolder.edge);
Vertex source = edgeHolder.source;
Vertex target = edgeHolder.target;
return GraphView.builder().vertices(ImmutableSet.of(source, target)).edges(ImmutableSet.of(edge)).build();
}
use of com.baidu.hugegraph.structure.graph.Edge in project incubator-hugegraph-toolchain by apache.
the class EdgeBuilder method build.
@Override
public List<Edge> build(String[] names, Object[] values) {
if (this.vertexIdsIndex == null || !Arrays.equals(this.lastNames, names)) {
this.vertexIdsIndex = this.extractVertexIdsIndex(names);
}
this.lastNames = names;
EdgeKVPairs kvPairs = this.newEdgeKVPairs();
kvPairs.source.extractFromEdge(names, values, this.vertexIdsIndex.sourceIndexes);
kvPairs.target.extractFromEdge(names, values, this.vertexIdsIndex.targetIndexes);
kvPairs.extractProperties(names, values);
List<Vertex> sources = kvPairs.source.buildVertices(false);
List<Vertex> targets = kvPairs.target.buildVertices(false);
if (sources.isEmpty() || targets.isEmpty()) {
return ImmutableList.of();
}
E.checkArgument(sources.size() == 1 || targets.size() == 1 || sources.size() == targets.size(), "The elements number of source and target must be: " + "1 to n, n to 1, n to n");
int size = Math.max(sources.size(), targets.size());
List<Edge> edges = new ArrayList<>(size);
for (int i = 0; i < size; i++) {
Vertex source = i < sources.size() ? sources.get(i) : sources.get(0);
Vertex target = i < targets.size() ? targets.get(i) : targets.get(0);
Edge edge = new Edge(this.mapping.label());
edge.source(source);
edge.target(target);
// Add properties
this.addProperties(edge, kvPairs.properties);
this.checkNonNullableKeys(edge);
edges.add(edge);
}
return edges;
}
use of com.baidu.hugegraph.structure.graph.Edge in project incubator-hugegraph-toolchain by apache.
the class BackupManager method backupEdgeShard.
private void backupEdgeShard(Shard shard) {
String desc = String.format("backing up edges[shard %s]", shard);
Edges edges = null;
String page = this.initPage();
TraverserManager g = client.traverser();
do {
try {
String p = page;
if (page == null) {
edges = retry(() -> g.edges(shard), desc);
} else {
edges = retry(() -> g.edges(shard, p), desc);
}
} catch (ToolsException e) {
this.exceptionHandler(e, HugeType.EDGE, shard);
}
if (edges == null) {
return;
}
List<Edge> edgeList = edges.results();
if (edgeList == null || edgeList.isEmpty()) {
return;
}
long count = this.backup(HugeType.EDGE, suffix.get(), edgeList);
this.edgeCounter.getAndAdd(count);
Printer.printInBackward(this.edgeCounter.get());
} while ((page = edges.page()) != null);
}
Aggregations