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));
}
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()));
}
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());
});
}
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()));
}
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);
}
Aggregations