Search in sources :

Example 6 with Edge

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

the class GraphManager method addEdges.

public List<Edge> addEdges(List<Edge> edges, boolean checkVertex) {
    for (Edge edge : edges) {
        edge.sourceId();
        edge.targetId();
    }
    List<String> ids = this.edgeAPI.create(edges, checkVertex);
    for (int i = 0; i < edges.size(); i++) {
        Edge edge = edges.get(i);
        edge.id(ids.get(i));
        this.attachManager(edge);
    }
    return edges;
}
Also used : Edge(com.baidu.hugegraph.structure.graph.Edge)

Example 7 with Edge

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

the class GraphManager method addEdge.

public Edge addEdge(Object sourceId, String label, Object targetId, Object... properties) {
    Edge edge = new Edge(label);
    edge.sourceId(sourceId);
    edge.targetId(targetId);
    this.attachProperties(edge, properties);
    return this.addEdge(edge);
}
Also used : Edge(com.baidu.hugegraph.structure.graph.Edge)

Example 8 with Edge

use of com.baidu.hugegraph.structure.graph.Edge 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)

Example 9 with Edge

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

the class FileLoadTest method testSingleInsertEdgeWithCheckVertexFalse.

@Test
public void testSingleInsertEdgeWithCheckVertexFalse() {
    // The source and target vertex doesn't exist
    ioUtil.write("edge_knows.csv", "source_name,target_name,date,weight", "marko,vadas,20160110,0.5", "marko,josh,20130220,1.0");
    ioUtil.write("edge_created.csv", "source_name,target_name,date,weight", "marko,lop,20171210,0.4", "josh,lop,20091111,0.4", "josh,ripple,20171210,1.0", "peter,lop,20170324,0.2");
    String[] args = new String[] { "-f", structPath("single_insert_edge_with_check_vertex_false/struct.json"), "-s", configPath("single_insert_edge_with_check_vertex_false/schema.groovy"), "-g", GRAPH, "-h", SERVER, "--check-vertex", "false", "--batch-insert-threads", "2", "--test-mode", "true" };
    HugeGraphLoader.main(args);
    List<Vertex> vertices = CLIENT.graph().listVertices();
    List<Edge> edges = CLIENT.graph().listEdges();
    Assert.assertEquals(0, vertices.size());
    Assert.assertEquals(6, edges.size());
    edges.forEach(edge -> {
        Assert.assertThrows(ServerException.class, () -> {
            CLIENT.graph().getVertex(edge.sourceId());
        }, e -> {
            ServerException se = (ServerException) e;
            Assert.assertTrue(se.exception().contains("NotFoundException"));
        });
        Assert.assertThrows(ServerException.class, () -> {
            CLIENT.graph().getVertex(edge.targetId());
        }, e -> {
            ServerException se = (ServerException) e;
            Assert.assertTrue(se.exception().contains("NotFoundException"));
        });
    });
}
Also used : Vertex(com.baidu.hugegraph.structure.graph.Vertex) ServerException(com.baidu.hugegraph.exception.ServerException) Edge(com.baidu.hugegraph.structure.graph.Edge) Test(org.junit.Test)

Example 10 with Edge

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

the class FileLoadTest method testNumberAndDatePrimaryKeysEncoded.

@Test
public void testNumberAndDatePrimaryKeysEncoded() throws java.text.ParseException {
    ioUtil.write("vertex_person.csv", "id,name,age,city", "100,marko,29,Beijing");
    ioUtil.write("vertex_software.csv", "date,name,lang,price", "2000-02-01,lop,java,328");
    ioUtil.write("edge_created.csv", "source_id,target_date,date,weight", "100,2000-02-01,2017-12-10,0.4");
    String[] args = new String[] { "-f", structPath("number_and_date_pks_encoded/struct.json"), "-s", configPath("number_and_date_pks_encoded/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(2, vertices.size());
    Assert.assertEquals(1, edges.size());
    Vertex v1 = CLIENT.graph().listVertices("person").get(0);
    Vertex v2 = CLIENT.graph().listVertices("software").get(0);
    Edge e = edges.get(0);
    String v1Id = String.format("%s:%s", 1, LongEncoding.encodeNumber(100));
    java.util.Date date = DateUtil.parse("2000-02-01", "yyyy-MM-dd");
    String v2Id = String.format("%s:%s", 2, LongEncoding.encodeNumber(date));
    String eId = String.format("S1:%s>1>>S2:%s", LongEncoding.encodeNumber(100), LongEncoding.encodeNumber(date));
    Assert.assertEquals(v1Id, v1.id());
    Assert.assertEquals(v2Id, v2.id());
    Assert.assertEquals(eId, e.id());
}
Also used : Vertex(com.baidu.hugegraph.structure.graph.Vertex) Edge(com.baidu.hugegraph.structure.graph.Edge) Test(org.junit.Test)

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