Search in sources :

Example 16 with EdgeLabel

use of com.baidu.hugegraph.schema.EdgeLabel in project incubator-hugegraph by apache.

the class EdgeLabelCoreTest method testAddEdgeLabelWithoutProperty.

@Test
public void testAddEdgeLabelWithoutProperty() {
    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").singleTime().link("person", "book").create();
    Assert.assertNotNull(look);
    Assert.assertEquals("look", look.name());
    assertVLEqual("person", look.sourceLabel());
    assertVLEqual("book", look.targetLabel());
    Assert.assertEquals(0, look.properties().size());
    Assert.assertEquals(0, look.sortKeys().size());
    Assert.assertEquals(Frequency.SINGLE, look.frequency());
}
Also used : EdgeLabel(com.baidu.hugegraph.schema.EdgeLabel) SchemaManager(com.baidu.hugegraph.schema.SchemaManager) Test(org.junit.Test)

Example 17 with EdgeLabel

use of com.baidu.hugegraph.schema.EdgeLabel in project incubator-hugegraph by apache.

the class EdgeLabelCoreTest method testAddEdgeLabelWithNullableKeys.

@Test
public void testAddEdgeLabelWithNullableKeys() {
    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").properties("time", "weight").nullableKeys("weight").link("person", "book").create();
    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");
}
Also used : EdgeLabel(com.baidu.hugegraph.schema.EdgeLabel) SchemaManager(com.baidu.hugegraph.schema.SchemaManager) Test(org.junit.Test)

Example 18 with EdgeLabel

use of com.baidu.hugegraph.schema.EdgeLabel in project incubator-hugegraph by apache.

the class EdgeLabelCoreTest method testAddEdgeLabel.

@Test
public void testAddEdgeLabel() {
    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();
    Assert.assertNotNull(look);
    Assert.assertEquals("look", look.name());
    assertVLEqual("person", look.sourceLabel());
    assertVLEqual("book", look.targetLabel());
    Assert.assertEquals(1, look.properties().size());
    assertContainsPk(look.properties(), "time");
    Assert.assertEquals(1, look.sortKeys().size());
    assertContainsPk(look.sortKeys(), "time");
    Assert.assertEquals(Frequency.MULTIPLE, look.frequency());
}
Also used : EdgeLabel(com.baidu.hugegraph.schema.EdgeLabel) SchemaManager(com.baidu.hugegraph.schema.SchemaManager) Test(org.junit.Test)

Example 19 with EdgeLabel

use of com.baidu.hugegraph.schema.EdgeLabel in project incubator-hugegraph by apache.

the class EdgeLabelCoreTest method testAddEdgeLabelWithoutFrequency.

@Test
public void testAddEdgeLabelWithoutFrequency() {
    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").properties("time").link("person", "book").create();
    Assert.assertNotNull(look);
    Assert.assertEquals("look", look.name());
    assertVLEqual("person", look.sourceLabel());
    assertVLEqual("book", look.targetLabel());
    Assert.assertEquals(1, look.properties().size());
    assertContainsPk(look.properties(), "time");
    Assert.assertEquals(0, look.sortKeys().size());
    Assert.assertEquals(Frequency.SINGLE, look.frequency());
}
Also used : EdgeLabel(com.baidu.hugegraph.schema.EdgeLabel) SchemaManager(com.baidu.hugegraph.schema.SchemaManager) Test(org.junit.Test)

Example 20 with EdgeLabel

use of com.baidu.hugegraph.schema.EdgeLabel in project incubator-hugegraph by apache.

the class EdgeLabelAPI method list.

@GET
@Timed
@Produces(APPLICATION_JSON_WITH_CHARSET)
@RolesAllowed({ "admin", "$owner=$graph $action=edge_label_read" })
public String list(@Context GraphManager manager, @PathParam("graph") String graph, @QueryParam("names") List<String> names) {
    boolean listAll = CollectionUtils.isEmpty(names);
    if (listAll) {
        LOG.debug("Graph [{}] list edge labels", graph);
    } else {
        LOG.debug("Graph [{}] get edge labels by names {}", graph, names);
    }
    HugeGraph g = graph(manager, graph);
    List<EdgeLabel> labels;
    if (listAll) {
        labels = g.schema().getEdgeLabels();
    } else {
        labels = new ArrayList<>(names.size());
        for (String name : names) {
            labels.add(g.schema().getEdgeLabel(name));
        }
    }
    return manager.serializer(g).writeEdgeLabels(labels);
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) EdgeLabel(com.baidu.hugegraph.schema.EdgeLabel) RolesAllowed(jakarta.annotation.security.RolesAllowed) Produces(jakarta.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) GET(jakarta.ws.rs.GET)

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