use of com.baidu.hugegraph.schema.EdgeLabel in project incubator-hugegraph by apache.
the class IndexLabelCoreTest method testRebuildIndexLabelOfEdge.
@Test
public void testRebuildIndexLabelOfEdge() {
super.initPropertyKeys();
SchemaManager schema = graph().schema();
schema.vertexLabel("author").properties("id", "name").primaryKeys("id").create();
schema.vertexLabel("book").properties("name").primaryKeys("name").create();
schema.edgeLabel("authored").singleTime().link("author", "book").properties("contribution").create();
Vertex james = graph().addVertex(T.label, "author", "id", 1, "name", "James Gosling");
Vertex java1 = graph().addVertex(T.label, "book", "name", "java-1");
schema.indexLabel("authoredByContri").onE("authored").secondary().by("contribution").create();
EdgeLabel authored = schema.getEdgeLabel("authored");
Assert.assertEquals(1, authored.indexLabels().size());
assertContainsIl(authored.indexLabels(), "authoredByContri");
james.addEdge("authored", java1, "contribution", "test");
graph().tx().commit();
Edge edge = graph().traversal().E().hasLabel("authored").has("contribution", "test").next();
Assert.assertNotNull(edge);
schema.edgeLabel("authored").rebuildIndex();
Assert.assertEquals(1, authored.indexLabels().size());
assertContainsIl(authored.indexLabels(), "authoredByContri");
edge = graph().traversal().E().hasLabel("authored").has("contribution", "test").next();
Assert.assertNotNull(edge);
}
use of com.baidu.hugegraph.schema.EdgeLabel in project incubator-hugegraph by apache.
the class EdgeLabelCoreTest method testCreateTime.
@Test
public void testCreateTime() {
super.initPropertyKeys();
SchemaManager schema = graph().schema();
schema.vertexLabel("person").properties("name", "age", "city").primaryKeys("name").create();
schema.vertexLabel("book").properties("id", "name").primaryKeys("id").create();
EdgeLabel look = schema.edgeLabel("look").multiTimes().properties("time").link("person", "book").sortKeys("time").create();
Date createTime = (Date) look.userdata().get(Userdata.CREATE_TIME);
Date now = DateUtil.now();
Assert.assertFalse(createTime.after(now));
look = schema.getEdgeLabel("look");
createTime = (Date) look.userdata().get(Userdata.CREATE_TIME);
Assert.assertFalse(createTime.after(now));
}
use of com.baidu.hugegraph.schema.EdgeLabel in project incubator-hugegraph by apache.
the class EdgeLabelCoreTest method testAppendEdgeLabelWithNullableKeysInOriginProperties.
@Test
public void testAppendEdgeLabelWithNullableKeysInOriginProperties() {
super.initPropertyKeys();
SchemaManager schema = graph().schema();
schema.vertexLabel("person").properties("name", "age", "city").primaryKeys("name").create();
schema.vertexLabel("author").properties("id", "name").primaryKeys("id").create();
schema.vertexLabel("book").properties("id", "name").primaryKeys("id").create();
schema.edgeLabel("look").properties("time", "weight").link("person", "book").create();
EdgeLabel look = schema.edgeLabel("look").nullableKeys("weight").append();
Assert.assertNotNull(look);
Assert.assertEquals("look", look.name());
assertVLEqual("person", look.sourceLabel());
assertVLEqual("book", look.targetLabel());
Assert.assertEquals(2, look.properties().size());
assertContainsPk(look.properties(), "time", "weight");
Assert.assertEquals(1, look.nullableKeys().size());
assertContainsPk(look.nullableKeys(), "weight");
}
use of com.baidu.hugegraph.schema.EdgeLabel in project incubator-hugegraph by apache.
the class EdgeLabelCoreTest method testAddEdgeLabelWithTtl.
@Test
public void testAddEdgeLabelWithTtl() {
super.initPropertyKeys();
SchemaManager schema = graph().schema();
schema.propertyKey("date").asDate().ifNotExist().create();
schema.vertexLabel("person").properties("name", "age", "city").primaryKeys("name").nullableKeys("city").create();
schema.vertexLabel("book").properties("name").primaryKeys("name").create();
Assert.assertThrows(IllegalArgumentException.class, () -> {
schema.edgeLabel("read").link("person", "book").properties("date", "weight").ttl(-86400L).create();
});
Assert.assertThrows(IllegalArgumentException.class, () -> {
schema.edgeLabel("read").link("person", "book").properties("date", "weight").ttlStartTime("date").create();
});
Assert.assertThrows(IllegalArgumentException.class, () -> {
schema.edgeLabel("read").link("person", "book").properties("date", "weight").ttlStartTime("name").create();
});
Assert.assertThrows(IllegalArgumentException.class, () -> {
schema.edgeLabel("read").link("person", "book").properties("date", "weight").ttlStartTime("weight").create();
});
EdgeLabel read = schema.edgeLabel("read").link("person", "book").properties("date", "weight").ttl(86400L).create();
Assert.assertNotNull(read);
Assert.assertEquals("read", read.name());
assertVLEqual("person", read.sourceLabel());
assertVLEqual("book", read.targetLabel());
Assert.assertEquals(2, read.properties().size());
assertContainsPk(read.properties(), "date", "weight");
Assert.assertEquals(0, read.sortKeys().size());
Assert.assertEquals(Frequency.SINGLE, read.frequency());
Assert.assertEquals(86400L, read.ttl());
Assert.assertEquals(IdGenerator.ZERO, read.ttlStartTime());
EdgeLabel write = schema.edgeLabel("write").link("person", "book").properties("date", "weight").ttl(86400L).ttlStartTime("date").create();
Assert.assertNotNull(write);
Assert.assertEquals("write", write.name());
assertVLEqual("person", write.sourceLabel());
assertVLEqual("book", write.targetLabel());
Assert.assertEquals(2, write.properties().size());
assertContainsPk(write.properties(), "date", "weight");
Assert.assertEquals(0, write.sortKeys().size());
Assert.assertEquals(Frequency.SINGLE, write.frequency());
Assert.assertEquals(86400L, write.ttl());
Assert.assertNotNull(write.ttlStartTime());
assertContainsPk(ImmutableSet.of(write.ttlStartTime()), "date");
}
use of com.baidu.hugegraph.schema.EdgeLabel in project incubator-hugegraph by apache.
the class EdgeLabelCoreTest method testEliminateEdgeLabelWithUserdata.
@Test
public void testEliminateEdgeLabelWithUserdata() {
super.initPropertyKeys();
SchemaManager schema = graph().schema();
schema.vertexLabel("person").properties("name", "age", "city").primaryKeys("name").nullableKeys("city").create();
schema.vertexLabel("book").properties("name").primaryKeys("name").create();
EdgeLabel write = schema.edgeLabel("write").link("person", "book").properties("time", "weight").userdata("multiplicity", "one-to-many").userdata("icon", "picture2").create();
Assert.assertEquals(3, write.userdata().size());
Assert.assertEquals("one-to-many", write.userdata().get("multiplicity"));
Assert.assertEquals("picture2", write.userdata().get("icon"));
write = schema.edgeLabel("write").userdata("icon", "").eliminate();
Assert.assertEquals(2, write.userdata().size());
Assert.assertEquals("one-to-many", write.userdata().get("multiplicity"));
}
Aggregations