Search in sources :

Example 51 with Edge

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;
}
Also used : Edge(com.baidu.hugegraph.structure.graph.Edge) ComputerException(com.baidu.hugegraph.computer.core.common.exception.ComputerException)

Example 52 with Edge

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;
}
Also used : EdgeLabel(com.baidu.hugegraph.structure.schema.EdgeLabel) Edge(com.baidu.hugegraph.structure.graph.Edge)

Example 53 with Edge

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

Example 54 with Edge

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

Example 55 with Edge

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

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