Search in sources :

Example 21 with Vertex

use of com.baidu.hugegraph.structure.graph.Vertex in project incubator-hugegraph-toolchain by apache.

the class GraphService method updateVertex.

public Vertex updateVertex(int connId, VertexEntity entity) {
    HugeClient client = this.client(connId);
    GraphManager graph = client.graph();
    Vertex vertex = this.buildVertex(connId, entity);
    // TODO: client should add updateVertex() method
    return graph.addVertex(vertex);
}
Also used : Vertex(com.baidu.hugegraph.structure.graph.Vertex) HugeClient(com.baidu.hugegraph.driver.HugeClient) GraphManager(com.baidu.hugegraph.driver.GraphManager)

Example 22 with Vertex

use of com.baidu.hugegraph.structure.graph.Vertex 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 23 with Vertex

use of com.baidu.hugegraph.structure.graph.Vertex 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 24 with Vertex

use of com.baidu.hugegraph.structure.graph.Vertex in project incubator-hugegraph-toolchain by apache.

the class GraphManager method addVertex.

public Vertex addVertex(String label, Object id, Map<String, Object> properties) {
    Vertex vertex = new Vertex(label);
    vertex.id(id);
    this.attachProperties(vertex, properties);
    return this.addVertex(vertex);
}
Also used : Vertex(com.baidu.hugegraph.structure.graph.Vertex)

Example 25 with Vertex

use of com.baidu.hugegraph.structure.graph.Vertex in project incubator-hugegraph-toolchain by apache.

the class JDBCLoadTest method testCustomizedSchema.

@Test
public void testCustomizedSchema() {
    dbUtil.insert("INSERT INTO `person` VALUES " + "(1,'marko',29,'Beijing')," + "(2,'vadas',27,'HongKong')," + "(3,'josh',32,'Beijing')," + "(4,'peter',35,'Shanghai')," + "(5,'li,nary',26,'Wu,han')," + "(6,'tom',NULL,NULL);");
    dbUtil.insert("INSERT INTO `software` VALUES " + "(100,'lop','java',328.00)," + "(200,'ripple','java',199.00);");
    dbUtil.insert("INSERT INTO `knows` VALUES " + "(1,1,2,'2016-01-10',0.50)," + "(2,1,3,'2013-02-20',1.00);");
    dbUtil.insert("INSERT INTO `created` VALUES " + "(1,1,100,'2017-12-10',0.40)," + "(2,3,100,'2009-11-11',0.40)," + "(3,3,200,'2017-12-10',1.00)," + "(4,4,100,'2017-03-24',0.20);");
    String[] args = new String[] { "-f", configPath("jdbc_customized_schema/struct.json"), "-s", configPath("jdbc_customized_schema/schema.groovy"), "-g", GRAPH, "-h", SERVER, "--batch-insert-threads", "2", "--test-mode", "true" };
    HugeGraphLoader.main(args);
    List<Vertex> vertices = CLIENT.graph().listVertices();
    List<Edge> edges = CLIENT.graph().listEdges();
    Assert.assertEquals(8, vertices.size());
    Assert.assertEquals(6, edges.size());
    for (Vertex vertex : vertices) {
        Assert.assertEquals(Integer.class, vertex.id().getClass());
    }
    for (Edge edge : edges) {
        Assert.assertEquals(Integer.class, edge.sourceId().getClass());
        Assert.assertEquals(Integer.class, edge.targetId().getClass());
    }
}
Also used : Vertex(com.baidu.hugegraph.structure.graph.Vertex) Edge(com.baidu.hugegraph.structure.graph.Edge) Test(org.junit.Test)

Aggregations

Vertex (com.baidu.hugegraph.structure.graph.Vertex)165 Test (org.junit.Test)110 Edge (com.baidu.hugegraph.structure.graph.Edge)33 HugeClient (com.baidu.hugegraph.driver.HugeClient)22 ArrayList (java.util.ArrayList)21 SchemaManager (com.baidu.hugegraph.driver.SchemaManager)18 BaseClientTest (com.baidu.hugegraph.BaseClientTest)17 BeforeClass (org.junit.BeforeClass)17 GraphManager (com.baidu.hugegraph.driver.GraphManager)14 BatchVertexRequest (com.baidu.hugegraph.structure.graph.BatchVertexRequest)13 Path (com.baidu.hugegraph.structure.graph.Path)11 Result (com.baidu.hugegraph.structure.gremlin.Result)10 ResultSet (com.baidu.hugegraph.structure.gremlin.ResultSet)10 List (java.util.List)10 BaseApiTest (com.baidu.hugegraph.api.BaseApiTest)9 ImmutableList (com.google.common.collect.ImmutableList)6 ImmutableMap (com.google.common.collect.ImmutableMap)6 Map (java.util.Map)6 RestResult (com.baidu.hugegraph.rest.RestResult)5 PathsWithVertices (com.baidu.hugegraph.structure.traverser.PathsWithVertices)5