use of com.baidu.hugegraph.schema.EdgeLabel in project incubator-hugegraph by apache.
the class EdgeLabelCoreTest method testAddEdgeLabelWithEnableLabelIndex.
@Test
public void testAddEdgeLabelWithEnableLabelIndex() {
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").enableLabelIndex(true).create();
Assert.assertEquals(true, 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();
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 RamTableTest method testAddInvalidVertexOrEdge.
@Test
public void testAddInvalidVertexOrEdge() {
HugeGraph graph = this.graph();
VertexLabel vl3 = graph.vertexLabel("vl3");
EdgeLabel el3 = graph.edgeLabel("el3");
VertexLabel vl2 = graph.vertexLabel("vl2");
EdgeLabel el2 = graph.edgeLabel("el2");
RamTable table = new RamTable(graph, VERTEX_SIZE, EDGE_SIZE);
HugeVertex ownerVertex = new HugeVertex(graph, IdGenerator.of(1), vl3);
HugeEdge edge1 = HugeEdge.constructEdge(ownerVertex, true, el3, "marko", IdGenerator.of(2));
Assert.assertThrows(HugeException.class, () -> {
table.addEdge(true, edge1);
}, e -> {
Assert.assertContains("Only edge label without sortkey is " + "supported by ramtable, but got 'el3(id=3)'", e.getMessage());
});
HugeVertex v1 = new HugeVertex(graph, IdGenerator.of("s1"), vl2);
HugeEdge edge2 = HugeEdge.constructEdge(v1, true, el2, "marko", IdGenerator.of("s2"));
Assert.assertThrows(HugeException.class, () -> {
table.addEdge(true, edge2);
}, e -> {
Assert.assertContains("Only number id is supported by ramtable, " + "but got string id 's1'", e.getMessage());
});
HugeVertex v2 = new HugeVertex(graph, IdGenerator.of(2), vl2);
HugeEdge edge3 = HugeEdge.constructEdge(v2, true, el2, "marko", IdGenerator.of("s2"));
Assert.assertThrows(HugeException.class, () -> {
table.addEdge(true, edge3);
}, e -> {
Assert.assertContains("Only number id is supported by ramtable, " + "but got string id 's2'", e.getMessage());
});
}
use of com.baidu.hugegraph.schema.EdgeLabel in project incubator-hugegraph by apache.
the class JsonUtilTest method testSerializeEdge.
@Test
public void testSerializeEdge() {
FakeObjects fakeObject = new FakeObjects();
PropertyKey name = fakeObject.newPropertyKey(IdGenerator.of(1), "name");
PropertyKey age = fakeObject.newPropertyKey(IdGenerator.of(2), "age", DataType.INT, Cardinality.SINGLE);
PropertyKey city = fakeObject.newPropertyKey(IdGenerator.of(3), "city");
PropertyKey date = fakeObject.newPropertyKey(IdGenerator.of(4), "date", DataType.DATE);
PropertyKey weight = fakeObject.newPropertyKey(IdGenerator.of(5), "weight", DataType.DOUBLE);
VertexLabel vl = fakeObject.newVertexLabel(IdGenerator.of(1), "person", IdStrategy.CUSTOMIZE_NUMBER, name.id(), age.id(), city.id());
EdgeLabel el = fakeObject.newEdgeLabel(IdGenerator.of(1), "knows", Frequency.SINGLE, vl.id(), vl.id(), date.id(), weight.id());
HugeVertex source = new HugeVertex(fakeObject.graph(), IdGenerator.of(123456), vl);
HugeVertex target = new HugeVertex(fakeObject.graph(), IdGenerator.of(987654), vl);
Id id = EdgeId.parse("L123456>1>>L987654");
HugeEdge edge = new HugeEdge(fakeObject.graph(), id, el);
Whitebox.setInternalState(edge, "sourceVertex", source);
Whitebox.setInternalState(edge, "targetVertex", target);
Date dateValue = Utils.date("2019-03-12");
MutableIntObjectMap<HugeProperty<?>> properties = CollectionFactory.newIntObjectMap(date.id(), new HugeEdgeProperty<>(edge, date, dateValue), weight.id(), new HugeEdgeProperty<>(edge, weight, 0.8));
Whitebox.setInternalState(edge, "properties", properties);
String json = JsonUtil.toJson(edge);
Assert.assertEquals("{\"id\":\"L123456>1>>L987654\"," + "\"label\":\"knows\",\"type\":\"edge\"," + "\"outV\":123456,\"outVLabel\":\"person\"," + "\"inV\":987654,\"inVLabel\":\"person\"," + "\"properties\":{\"date\":" + "\"2019-03-12 00:00:00.000\"," + "\"weight\":0.8}}", json);
}
Aggregations