use of com.baidu.hugegraph.schema.EdgeLabel in project incubator-hugegraph by apache.
the class EdgeLabelCoreTest method testAppendEdgeLabelWithNullableKeysInAppendProperties.
@Test
public void testAppendEdgeLabelWithNullableKeysInAppendProperties() {
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").link("person", "book").create();
EdgeLabel look = schema.edgeLabel("look").properties("weight").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 testAddEdgeLabelWithUserdata.
@Test
public void testAddEdgeLabelWithUserdata() {
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 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"));
EdgeLabel write = schema.edgeLabel("write").link("person", "book").properties("time", "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"));
}
use of com.baidu.hugegraph.schema.EdgeLabel in project incubator-hugegraph by apache.
the class EdgeLabelCoreTest method testListEdgeLabels.
@Test
public void testListEdgeLabels() {
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();
EdgeLabel look = schema.edgeLabel("look").multiTimes().properties("time").link("person", "book").sortKeys("time").create();
EdgeLabel write = schema.edgeLabel("write").multiTimes().properties("time").link("author", "book").sortKeys("time").create();
List<EdgeLabel> edgeLabels = schema.getEdgeLabels();
Assert.assertEquals(2, edgeLabels.size());
Assert.assertTrue(edgeLabels.contains(look));
Assert.assertTrue(edgeLabels.contains(write));
// clear cache
params().schemaEventHub().call(Events.CACHE, "clear", null);
Assert.assertEquals(look, schema.getEdgeLabel("look"));
edgeLabels = schema.getEdgeLabels();
Assert.assertEquals(2, edgeLabels.size());
Assert.assertTrue(edgeLabels.contains(look));
Assert.assertTrue(edgeLabels.contains(write));
}
use of com.baidu.hugegraph.schema.EdgeLabel in project incubator-hugegraph by apache.
the class EdgeLabelCoreTest method testAddEdgeLabelWithDisableLabelIndex.
@Test
public void testAddEdgeLabelWithDisableLabelIndex() {
super.initPropertyKeys();
HugeGraph graph = graph();
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").enableLabelIndex(false).create();
Assert.assertEquals(false, write.enableLabelIndex());
Vertex marko = graph.addVertex(T.label, "person", "name", "marko", "age", 22);
Vertex java = graph.addVertex(T.label, "book", "name", "java in action");
Vertex hadoop = graph.addVertex(T.label, "book", "name", "hadoop mapreduce");
marko.addEdge("write", java, "time", "2016-12-12", "weight", 0.3);
marko.addEdge("write", hadoop, "time", "2014-2-28", "weight", 0.5);
graph.tx().commit();
if (!storeFeatures().supportsQueryByLabel()) {
Assert.assertThrows(NoIndexException.class, () -> {
graph.traversal().E().hasLabel("write").toList();
});
} else {
List<Edge> edges = graph.traversal().E().hasLabel("write").toList();
Assert.assertEquals(2, edges.size());
}
}
use of com.baidu.hugegraph.schema.EdgeLabel in project incubator-hugegraph by apache.
the class IndexLabelCoreTest method testAddIndexLabelOfEdge.
@Test
public void testAddIndexLabelOfEdge() {
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", "tags").create();
schema.indexLabel("authoredByContri").onE("authored").secondary().by("contribution").create();
schema.indexLabel("authoredByTags").onE("authored").secondary().by("tags").create();
EdgeLabel authored = schema.getEdgeLabel("authored");
IndexLabel authoredByContri = schema.getIndexLabel("authoredByContri");
IndexLabel authoredByTags = schema.getIndexLabel("authoredByTags");
Assert.assertNotNull(authoredByContri);
Assert.assertEquals(2, authored.indexLabels().size());
assertContainsIl(authored.indexLabels(), "authoredByContri", "authoredByTags");
Assert.assertEquals(HugeType.EDGE_LABEL, authoredByContri.baseType());
Assert.assertEquals(HugeType.EDGE_LABEL, authoredByTags.baseType());
assertELEqual("authored", authoredByContri.baseValue());
assertELEqual("authored", authoredByTags.baseValue());
Assert.assertEquals(IndexType.SECONDARY, authoredByContri.indexType());
Assert.assertEquals(IndexType.SECONDARY, authoredByTags.indexType());
}
Aggregations