Search in sources :

Example 1 with Edge

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());
}
Also used : Shard(com.baidu.hugegraph.structure.graph.Shard) Edge(com.baidu.hugegraph.structure.graph.Edge) Edges(com.baidu.hugegraph.structure.graph.Edges) LinkedList(java.util.LinkedList) Test(org.junit.Test) BaseApiTest(com.baidu.hugegraph.api.BaseApiTest)

Example 2 with Edge

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());
}
Also used : Shard(com.baidu.hugegraph.structure.graph.Shard) Edge(com.baidu.hugegraph.structure.graph.Edge) Edges(com.baidu.hugegraph.structure.graph.Edges) LinkedList(java.util.LinkedList) Test(org.junit.Test) BaseApiTest(com.baidu.hugegraph.api.BaseApiTest)

Example 3 with Edge

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();
}
Also used : Vertex(com.baidu.hugegraph.structure.graph.Vertex) HugeClient(com.baidu.hugegraph.driver.HugeClient) GraphManager(com.baidu.hugegraph.driver.GraphManager) Edge(com.baidu.hugegraph.structure.graph.Edge)

Example 4 with Edge

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;
}
Also used : Vertex(com.baidu.hugegraph.structure.graph.Vertex) ArrayList(java.util.ArrayList) Edge(com.baidu.hugegraph.structure.graph.Edge)

Example 5 with Edge

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);
}
Also used : ToolsException(com.baidu.hugegraph.exception.ToolsException) Edges(com.baidu.hugegraph.structure.graph.Edges) Edge(com.baidu.hugegraph.structure.graph.Edge) TraverserManager(com.baidu.hugegraph.driver.TraverserManager)

Aggregations

Edge (com.baidu.hugegraph.structure.graph.Edge)103 Test (org.junit.Test)73 Vertex (com.baidu.hugegraph.structure.graph.Vertex)33 ArrayList (java.util.ArrayList)22 BaseClientTest (com.baidu.hugegraph.BaseClientTest)20 BatchEdgeRequest (com.baidu.hugegraph.structure.graph.BatchEdgeRequest)12 HugeClient (com.baidu.hugegraph.driver.HugeClient)10 Path (com.baidu.hugegraph.structure.graph.Path)9 Result (com.baidu.hugegraph.structure.gremlin.Result)8 ResultSet (com.baidu.hugegraph.structure.gremlin.ResultSet)7 RestResult (com.baidu.hugegraph.rest.RestResult)5 VertexLabel (com.baidu.hugegraph.structure.schema.VertexLabel)5 GraphManager (com.baidu.hugegraph.driver.GraphManager)4 SchemaManager (com.baidu.hugegraph.driver.SchemaManager)4 GraphView (com.baidu.hugegraph.entity.query.GraphView)4 Edges (com.baidu.hugegraph.structure.graph.Edges)4 Date (java.util.Date)4 HashMap (java.util.HashMap)4 GremlinResult (com.baidu.hugegraph.entity.query.GremlinResult)3 TypedResult (com.baidu.hugegraph.entity.query.TypedResult)3