Search in sources :

Example 56 with EdgeLabel

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());
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) EdgeLabel(com.baidu.hugegraph.schema.EdgeLabel) SchemaManager(com.baidu.hugegraph.schema.SchemaManager) Edge(org.apache.tinkerpop.gremlin.structure.Edge) Test(org.junit.Test)

Example 57 with EdgeLabel

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());
    });
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) VertexLabel(com.baidu.hugegraph.schema.VertexLabel) EdgeLabel(com.baidu.hugegraph.schema.EdgeLabel) HugeEdge(com.baidu.hugegraph.structure.HugeEdge) RamTable(com.baidu.hugegraph.backend.store.ram.RamTable) HugeVertex(com.baidu.hugegraph.structure.HugeVertex) Test(org.junit.Test)

Example 58 with EdgeLabel

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);
}
Also used : HugeProperty(com.baidu.hugegraph.structure.HugeProperty) FakeObjects(com.baidu.hugegraph.unit.FakeObjects) VertexLabel(com.baidu.hugegraph.schema.VertexLabel) EdgeLabel(com.baidu.hugegraph.schema.EdgeLabel) HugeEdge(com.baidu.hugegraph.structure.HugeEdge) EdgeId(com.baidu.hugegraph.backend.id.EdgeId) Id(com.baidu.hugegraph.backend.id.Id) HugeVertex(com.baidu.hugegraph.structure.HugeVertex) PropertyKey(com.baidu.hugegraph.schema.PropertyKey) Date(java.util.Date) BaseUnitTest(com.baidu.hugegraph.unit.BaseUnitTest) Test(org.junit.Test)

Aggregations

EdgeLabel (com.baidu.hugegraph.schema.EdgeLabel)58 Test (org.junit.Test)22 SchemaManager (com.baidu.hugegraph.schema.SchemaManager)19 Id (com.baidu.hugegraph.backend.id.Id)16 VertexLabel (com.baidu.hugegraph.schema.VertexLabel)12 PropertyKey (com.baidu.hugegraph.schema.PropertyKey)11 HugeEdge (com.baidu.hugegraph.structure.HugeEdge)11 HugeGraph (com.baidu.hugegraph.HugeGraph)10 Edge (org.apache.tinkerpop.gremlin.structure.Edge)10 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)8 EdgeId (com.baidu.hugegraph.backend.id.EdgeId)7 HugeVertex (com.baidu.hugegraph.structure.HugeVertex)6 Timed (com.codahale.metrics.annotation.Timed)5 RolesAllowed (jakarta.annotation.security.RolesAllowed)5 Produces (jakarta.ws.rs.Produces)5 Date (java.util.Date)4 GraphTransaction (com.baidu.hugegraph.backend.tx.GraphTransaction)3 SchemaTransaction (com.baidu.hugegraph.backend.tx.SchemaTransaction)3 IndexLabel (com.baidu.hugegraph.schema.IndexLabel)3 SchemaStatus (com.baidu.hugegraph.type.define.SchemaStatus)3