Search in sources :

Example 31 with Vertex

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

Example 32 with Vertex

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

the class FileLoadTest method testCustomizedSchema.

@Test
public void testCustomizedSchema() {
    ioUtil.write("vertex_person.csv", "name,age,city", "marko,29,Beijing", "vadas,27,Hongkong", "josh,32,Beijing", "peter,35,Shanghai", "\"li,nary\",26,\"Wu,han\"");
    ioUtil.write("vertex_software.csv", GBK, "name,lang,price", "lop,java,328", "ripple,java,199");
    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("customized_schema/struct.json"), "-s", configPath("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(7, vertices.size());
    Assert.assertEquals(6, edges.size());
    boolean interestedVertex = false;
    for (Vertex vertex : vertices) {
        Assert.assertEquals(String.class, vertex.id().getClass());
        if (((String) vertex.id()).contains("li,nary")) {
            interestedVertex = true;
            Assert.assertEquals(26, vertex.property("age"));
            Assert.assertEquals("Wu,han", vertex.property("city"));
        }
    }
    Assert.assertTrue(interestedVertex);
    boolean interestedEdge = false;
    for (Edge edge : edges) {
        Assert.assertEquals(String.class, edge.sourceId().getClass());
        Assert.assertEquals(String.class, edge.targetId().getClass());
        if (((String) edge.sourceId()).contains("marko") && ((String) edge.targetId()).contains("vadas")) {
            interestedEdge = true;
            Assert.assertEquals("20160110", edge.property("date"));
            Assert.assertEquals(0.5, edge.property("weight"));
        }
    }
    Assert.assertTrue(interestedEdge);
}
Also used : Vertex(com.baidu.hugegraph.structure.graph.Vertex) Edge(com.baidu.hugegraph.structure.graph.Edge) Test(org.junit.Test)

Example 33 with Vertex

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

the class FileLoadTest method testIgnoreNullValueColumns.

@Test
public void testIgnoreNullValueColumns() {
    ioUtil.write("vertex_person.csv", "name,age,city", "marko,NULL,null", "vadas,NULL,", "josh,,null");
    String[] args = new String[] { "-f", structPath("ignore_null_value_columns/struct.json"), "-s", configPath("ignore_null_value_columns/schema.groovy"), "-g", GRAPH, "-h", SERVER, "--test-mode", "true" };
    HugeGraphLoader.main(args);
    List<Vertex> vertices = CLIENT.graph().listVertices();
    Assert.assertEquals(3, vertices.size());
    for (Vertex vertex : vertices) {
        Assert.assertNull(vertex.property("age"));
        Assert.assertNull(vertex.property("city"));
    }
}
Also used : Vertex(com.baidu.hugegraph.structure.graph.Vertex) Test(org.junit.Test)

Example 34 with Vertex

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

the class FileLoadTest method testSkipStruct.

@Test
public void testSkipStruct() {
    ioUtil.write("vertex_person.csv", "name,age,city", "marko,29,Beijing", "vadas,27,Hongkong", "josh,32,Beijing", "peter,35,Shanghai", "\"li,nary\",26,\"Wu,han\"");
    ioUtil.write("vertex_software.csv", GBK, "name,lang,price", "lop,java,328", "ripple,java,199");
    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("skip_struct/struct.json"), "-s", configPath("skip_struct/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(7, vertices.size());
    Assert.assertEquals(4, edges.size());
    for (Edge edge : edges) {
        Assert.assertEquals("created", edge.label());
    }
}
Also used : Vertex(com.baidu.hugegraph.structure.graph.Vertex) Edge(com.baidu.hugegraph.structure.graph.Edge) Test(org.junit.Test)

Example 35 with Vertex

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

the class FileLoadTest method testOrcCompressFile.

@Test
public void testOrcCompressFile() throws java.text.ParseException {
    // TODO: add test for blob and uuid
    TypeInfo typeInfo = TypeInfoUtils.getTypeInfoFromTypeString("struct<" + "name:string," + "p_boolean:boolean," + "p_byte:tinyint," + "p_int:int," + "p_long:bigint," + "p_float:float," + "p_double:double," + "p_string:string," + "p_date:date" + ">");
    Date nowDate = Date.valueOf("2019-12-09");
    ioUtil.writeOrc("vertex_person.orc", typeInfo, "marko", true, (byte) 1, 2, 3L, 4.0F, 5.0D, "marko", nowDate);
    String[] args = new String[] { "-f", structPath("orc_compress_file/struct.json"), "-s", configPath("orc_compress_file/schema.groovy"), "-g", GRAPH, "-h", SERVER, "--batch-insert-threads", "2", "--test-mode", "true" };
    HugeGraphLoader.main(args);
    List<Vertex> vertices = CLIENT.graph().listVertices();
    Assert.assertEquals(1, vertices.size());
    Vertex vertex = vertices.get(0);
    Assert.assertEquals(true, vertex.property("p_boolean"));
    Assert.assertEquals(1, vertex.property("p_byte"));
    Assert.assertEquals(2, vertex.property("p_int"));
    Assert.assertEquals(3, vertex.property("p_long"));
    Assert.assertEquals(4.0D, vertex.property("p_float"));
    Assert.assertEquals(5.0D, vertex.property("p_double"));
    Assert.assertEquals("marko", vertex.property("p_string"));
    assertDateEquals("2019-12-09 00:00:00.000", vertex.property("p_date"));
}
Also used : Vertex(com.baidu.hugegraph.structure.graph.Vertex) TypeInfo(org.apache.hadoop.hive.serde2.typeinfo.TypeInfo) Date(org.apache.hadoop.hive.common.type.Date) 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