Search in sources :

Example 41 with SchemaManager

use of com.baidu.hugegraph.driver.SchemaManager in project incubator-hugegraph-toolchain by apache.

the class PropertyKeyTest method testEliminatePropertyKeyWithUserData.

@Test
public void testEliminatePropertyKeyWithUserData() {
    SchemaManager schema = schema();
    PropertyKey age = schema.propertyKey("age").userdata("min", 0).userdata("max", 100).create();
    Assert.assertEquals(3, age.userdata().size());
    Assert.assertEquals(0, age.userdata().get("min"));
    Assert.assertEquals(100, age.userdata().get("max"));
    String time = (String) age.userdata().get("~create_time");
    Date createTime = DateUtil.parse(time);
    Assert.assertTrue(createTime.before(DateUtil.now()));
    age = schema.propertyKey("age").userdata("max", "").eliminate();
    Assert.assertEquals(2, age.userdata().size());
    Assert.assertEquals(0, age.userdata().get("min"));
    time = (String) age.userdata().get("~create_time");
    Assert.assertEquals(createTime, DateUtil.parse(time));
}
Also used : SchemaManager(com.baidu.hugegraph.driver.SchemaManager) PropertyKey(com.baidu.hugegraph.structure.schema.PropertyKey) Date(java.util.Date) Test(org.junit.Test)

Example 42 with SchemaManager

use of com.baidu.hugegraph.driver.SchemaManager in project incubator-hugegraph-toolchain by apache.

the class PropertyKeyTest method testAddPropertyKeyWithUserData.

@Test
public void testAddPropertyKeyWithUserData() {
    SchemaManager schema = schema();
    PropertyKey age = schema.propertyKey("age").userdata("min", 0).userdata("max", 100).create();
    Assert.assertEquals(3, age.userdata().size());
    Assert.assertEquals(0, age.userdata().get("min"));
    Assert.assertEquals(100, age.userdata().get("max"));
    String time = (String) age.userdata().get("~create_time");
    Date createTime = DateUtil.parse(time);
    Assert.assertTrue(createTime.before(DateUtil.now()));
    PropertyKey id = schema.propertyKey("id").userdata("length", 15).userdata("length", 18).create();
    // The same key user data will be overwritten
    Assert.assertEquals(2, id.userdata().size());
    Assert.assertEquals(18, id.userdata().get("length"));
    time = (String) id.userdata().get("~create_time");
    createTime = DateUtil.parse(time);
    Assert.assertTrue(createTime.before(DateUtil.now()));
    PropertyKey sex = schema.propertyKey("sex").userdata("range", ImmutableList.of("male", "female")).create();
    Assert.assertEquals(2, sex.userdata().size());
    Assert.assertEquals(ImmutableList.of("male", "female"), sex.userdata().get("range"));
    time = (String) sex.userdata().get("~create_time");
    createTime = DateUtil.parse(time);
    Assert.assertTrue(createTime.before(DateUtil.now()));
}
Also used : SchemaManager(com.baidu.hugegraph.driver.SchemaManager) PropertyKey(com.baidu.hugegraph.structure.schema.PropertyKey) Date(java.util.Date) Test(org.junit.Test)

Example 43 with SchemaManager

use of com.baidu.hugegraph.driver.SchemaManager in project incubator-hugegraph-toolchain by apache.

the class EdgeTest method testQueryByPagingAndFiltering.

@Test
public void testQueryByPagingAndFiltering() {
    SchemaManager schema = schema();
    schema.propertyKey("no").asText().create();
    schema.propertyKey("location").asText().create();
    schema.propertyKey("callType").asText().create();
    schema.propertyKey("calltime").asDate().create();
    schema.propertyKey("duration").asInt().create();
    schema.vertexLabel("phone").properties("no").primaryKeys("no").enableLabelIndex(false).create();
    schema.edgeLabel("call").multiTimes().properties("location", "callType", "duration", "calltime").sourceLabel("phone").targetLabel("phone").sortKeys("location", "callType", "duration", "calltime").create();
    Vertex v1 = graph().addVertex(T.label, "phone", "no", "13812345678");
    Vertex v2 = graph().addVertex(T.label, "phone", "no", "13866668888");
    Vertex v10086 = graph().addVertex(T.label, "phone", "no", "10086");
    v1.addEdge("call", v2, "location", "Beijing", "callType", "work", "duration", 3, "calltime", "2017-5-1 23:00:00");
    v1.addEdge("call", v2, "location", "Beijing", "callType", "work", "duration", 3, "calltime", "2017-5-2 12:00:01");
    v1.addEdge("call", v2, "location", "Beijing", "callType", "work", "duration", 3, "calltime", "2017-5-3 12:08:02");
    v1.addEdge("call", v2, "location", "Beijing", "callType", "work", "duration", 8, "calltime", "2017-5-3 22:22:03");
    v1.addEdge("call", v2, "location", "Beijing", "callType", "fun", "duration", 10, "calltime", "2017-5-4 20:33:04");
    v1.addEdge("call", v10086, "location", "Nanjing", "callType", "work", "duration", 12, "calltime", "2017-5-2 15:30:05");
    v1.addEdge("call", v10086, "location", "Nanjing", "callType", "work", "duration", 14, "calltime", "2017-5-3 14:56:06");
    v2.addEdge("call", v10086, "location", "Nanjing", "callType", "fun", "duration", 15, "calltime", "2017-5-3 17:28:07");
    ResultSet resultSet = gremlin().gremlin("g.V(vid).outE('call')" + ".has('location', 'Beijing')" + ".has('callType', 'work')" + ".has('duration', 3)" + ".has('calltime', " + "P.between('2017-5-2', " + "'2017-5-4'))" + ".toList()").binding("vid", v1.id()).execute();
    Iterator<Result> results = resultSet.iterator();
    Assert.assertEquals(2, Iterators.size(results));
    Assert.assertThrows(ServerException.class, () -> {
        // no location
        gremlin().gremlin("g.V(vid).outE('call').has('callType', 'work')" + ".has('duration', 3).has('calltime', " + "P.between('2017-5-2', '2017-5-4'))" + ".has('~page', '')").binding("vid", v1.id()).execute();
    }, e -> {
        Assert.assertContains("Can't query by paging and filtering", e.getMessage());
    });
}
Also used : Vertex(com.baidu.hugegraph.structure.graph.Vertex) ResultSet(com.baidu.hugegraph.structure.gremlin.ResultSet) SchemaManager(com.baidu.hugegraph.driver.SchemaManager) Result(com.baidu.hugegraph.structure.gremlin.Result) Test(org.junit.Test) BaseClientTest(com.baidu.hugegraph.BaseClientTest)

Example 44 with SchemaManager

use of com.baidu.hugegraph.driver.SchemaManager in project incubator-hugegraph-toolchain by apache.

the class EdgeLabelTest method testAddEdgeLabelWithUserData.

@Test
public void testAddEdgeLabelWithUserData() {
    SchemaManager schema = schema();
    EdgeLabel father = schema.edgeLabel("father").link("person", "person").properties("weight").userdata("multiplicity", "one-to-many").create();
    Assert.assertEquals(2, father.userdata().size());
    Assert.assertEquals("one-to-many", father.userdata().get("multiplicity"));
    String time = (String) father.userdata().get("~create_time");
    Date createTime = DateUtil.parse(time);
    Assert.assertTrue(createTime.before(DateUtil.now()));
    EdgeLabel write = schema.edgeLabel("write").link("person", "book").properties("date", "weight").userdata("multiplicity", "one-to-many").userdata("multiplicity", "many-to-many").create();
    // The same key user data will be overwritten
    Assert.assertEquals(2, write.userdata().size());
    Assert.assertEquals("many-to-many", write.userdata().get("multiplicity"));
    time = (String) write.userdata().get("~create_time");
    createTime = DateUtil.parse(time);
    Assert.assertTrue(createTime.before(DateUtil.now()));
}
Also used : EdgeLabel(com.baidu.hugegraph.structure.schema.EdgeLabel) SchemaManager(com.baidu.hugegraph.driver.SchemaManager) Date(java.util.Date) Test(org.junit.Test)

Example 45 with SchemaManager

use of com.baidu.hugegraph.driver.SchemaManager in project incubator-hugegraph-toolchain by apache.

the class EdgeLabelTest method testRemoveEdgeLabelSync.

@Test
public void testRemoveEdgeLabelSync() {
    SchemaManager schema = schema();
    EdgeLabel write = schema.edgeLabel("write").link("person", "book").properties("date", "weight").userdata("multiplicity", "one-to-many").userdata("icon", "picture2").create();
    Assert.assertNotNull(write);
    // Remove edge label sync
    schema.removeEdgeLabel("write");
    write = schema.edgeLabel("write").link("person", "book").properties("date", "weight").userdata("multiplicity", "one-to-many").userdata("icon", "picture2").create();
    Assert.assertNotNull(write);
    // Remove edge label sync with timeout
    schema.removeEdgeLabel("write", 10);
}
Also used : EdgeLabel(com.baidu.hugegraph.structure.schema.EdgeLabel) SchemaManager(com.baidu.hugegraph.driver.SchemaManager) Test(org.junit.Test)

Aggregations

SchemaManager (com.baidu.hugegraph.driver.SchemaManager)61 Test (org.junit.Test)39 Vertex (com.baidu.hugegraph.structure.graph.Vertex)18 Date (java.util.Date)14 GraphManager (com.baidu.hugegraph.driver.GraphManager)11 IndexLabel (com.baidu.hugegraph.structure.schema.IndexLabel)11 EdgeLabel (com.baidu.hugegraph.structure.schema.EdgeLabel)9 HugeClient (com.baidu.hugegraph.driver.HugeClient)8 BeforeClass (org.junit.BeforeClass)8 PropertyKey (com.baidu.hugegraph.structure.schema.PropertyKey)7 VertexLabel (com.baidu.hugegraph.structure.schema.VertexLabel)6 Edge (com.baidu.hugegraph.structure.graph.Edge)4 ArrayList (java.util.ArrayList)3 PropertyIndex (com.baidu.hugegraph.entity.schema.PropertyIndex)2 Task (com.baidu.hugegraph.structure.Task)2 Result (com.baidu.hugegraph.structure.gremlin.Result)2 ResultSet (com.baidu.hugegraph.structure.gremlin.ResultSet)2 BaseClientTest (com.baidu.hugegraph.BaseClientTest)1 GremlinManager (com.baidu.hugegraph.driver.GremlinManager)1 LoadOptions (com.baidu.hugegraph.loader.executor.LoadOptions)1