Search in sources :

Example 11 with EdgeLabel

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

the class PersonalRankTraverser method getStartDirection.

private Directions getStartDirection(Id source, String label) {
    // NOTE: The outer layer needs to ensure that the vertex Id is valid
    HugeVertex vertex = (HugeVertex) graph().vertices(source).next();
    VertexLabel vertexLabel = vertex.schemaLabel();
    EdgeLabel edgeLabel = this.graph().edgeLabel(label);
    Id sourceLabel = edgeLabel.sourceLabel();
    Id targetLabel = edgeLabel.targetLabel();
    E.checkArgument(edgeLabel.linkWithLabel(vertexLabel.id()), "The vertex '%s' doesn't link with edge label '%s'", source, label);
    E.checkArgument(!sourceLabel.equals(targetLabel), "The edge label for personal rank must " + "link different vertex labels");
    if (sourceLabel.equals(vertexLabel.id())) {
        return Directions.OUT;
    } else {
        assert targetLabel.equals(vertexLabel.id());
        return Directions.IN;
    }
}
Also used : VertexLabel(com.baidu.hugegraph.schema.VertexLabel) EdgeLabel(com.baidu.hugegraph.schema.EdgeLabel) Id(com.baidu.hugegraph.backend.id.Id) HugeVertex(com.baidu.hugegraph.structure.HugeVertex)

Example 12 with EdgeLabel

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

the class MultiGraphsTest method testCopySchemaWithMultiGraphs.

@Test
public void testCopySchemaWithMultiGraphs() {
    List<HugeGraph> graphs = openGraphs("schema_g1", "schema_g2");
    for (HugeGraph graph : graphs) {
        graph.initBackend();
    }
    HugeGraph g1 = graphs.get(0);
    g1.serverStarted(IdGenerator.of("server-g2"), NodeRole.MASTER);
    HugeGraph g2 = graphs.get(1);
    g2.serverStarted(IdGenerator.of("server-g3"), NodeRole.MASTER);
    SchemaManager schema = g1.schema();
    schema.propertyKey("id").asInt().create();
    schema.propertyKey("name").asText().create();
    schema.propertyKey("age").asInt().valueSingle().create();
    schema.propertyKey("city").asText().create();
    schema.propertyKey("weight").asDouble().valueList().create();
    schema.propertyKey("born").asDate().ifNotExist().create();
    schema.propertyKey("time").asDate().ifNotExist().create();
    schema.vertexLabel("person").properties("id", "name", "age", "city", "weight", "born").primaryKeys("id").create();
    schema.vertexLabel("person2").properties("id", "name", "age", "city").primaryKeys("id").create();
    schema.edgeLabel("friend").sourceLabel("person").targetLabel("person").properties("time").create();
    schema.indexLabel("personByName").onV("person").secondary().by("name").create();
    schema.indexLabel("personByCity").onV("person").search().by("city").create();
    schema.indexLabel("personByAge").onV("person").range().by("age").create();
    schema.indexLabel("friendByTime").onE("friend").range().by("time").create();
    Assert.assertFalse(g2.existsPropertyKey("id"));
    Assert.assertFalse(g2.existsPropertyKey("name"));
    Assert.assertFalse(g2.existsPropertyKey("age"));
    Assert.assertFalse(g2.existsPropertyKey("city"));
    Assert.assertFalse(g2.existsPropertyKey("weight"));
    Assert.assertFalse(g2.existsPropertyKey("born"));
    Assert.assertFalse(g2.existsPropertyKey("time"));
    Assert.assertFalse(g2.existsVertexLabel("person"));
    Assert.assertFalse(g2.existsVertexLabel("person2"));
    Assert.assertFalse(g2.existsEdgeLabel("friend"));
    Assert.assertFalse(g2.existsIndexLabel("personByName"));
    Assert.assertFalse(g2.existsIndexLabel("personByCity"));
    Assert.assertFalse(g2.existsIndexLabel("personByAge"));
    Assert.assertFalse(g2.existsIndexLabel("friendByTime"));
    // Copy schema from g1 to g2
    g2.schema().copyFrom(g1.schema());
    Assert.assertTrue(g2.existsPropertyKey("id"));
    Assert.assertTrue(g2.existsPropertyKey("name"));
    Assert.assertTrue(g2.existsPropertyKey("age"));
    Assert.assertTrue(g2.existsPropertyKey("city"));
    Assert.assertTrue(g2.existsPropertyKey("weight"));
    Assert.assertTrue(g2.existsPropertyKey("born"));
    Assert.assertTrue(g2.existsPropertyKey("time"));
    Assert.assertTrue(g2.existsVertexLabel("person"));
    Assert.assertTrue(g2.existsVertexLabel("person2"));
    Assert.assertTrue(g2.existsEdgeLabel("friend"));
    Assert.assertTrue(g2.existsIndexLabel("personByName"));
    Assert.assertTrue(g2.existsIndexLabel("personByCity"));
    Assert.assertTrue(g2.existsIndexLabel("personByAge"));
    Assert.assertTrue(g2.existsIndexLabel("friendByTime"));
    for (PropertyKey copied : g2.schema().getPropertyKeys()) {
        PropertyKey origin = g1.schema().getPropertyKey(copied.name());
        Assert.assertTrue(origin.hasSameContent(copied));
    }
    for (VertexLabel copied : schema.getVertexLabels()) {
        VertexLabel origin = g1.schema().getVertexLabel(copied.name());
        Assert.assertTrue(origin.hasSameContent(copied));
    }
    for (EdgeLabel copied : schema.getEdgeLabels()) {
        EdgeLabel origin = g1.schema().getEdgeLabel(copied.name());
        Assert.assertTrue(origin.hasSameContent(copied));
    }
    for (IndexLabel copied : schema.getIndexLabels()) {
        IndexLabel origin = g1.schema().getIndexLabel(copied.name());
        Assert.assertTrue(origin.hasSameContent(copied));
    }
    // Copy schema again from g1 to g2 (ignore identical content)
    g2.schema().copyFrom(g1.schema());
    for (PropertyKey copied : g2.schema().getPropertyKeys()) {
        PropertyKey origin = g1.schema().getPropertyKey(copied.name());
        Assert.assertTrue(origin.hasSameContent(copied));
    }
    for (VertexLabel copied : schema.getVertexLabels()) {
        VertexLabel origin = g1.schema().getVertexLabel(copied.name());
        Assert.assertTrue(origin.hasSameContent(copied));
    }
    for (EdgeLabel copied : schema.getEdgeLabels()) {
        EdgeLabel origin = g1.schema().getEdgeLabel(copied.name());
        Assert.assertTrue(origin.hasSameContent(copied));
    }
    for (IndexLabel copied : schema.getIndexLabels()) {
        IndexLabel origin = g1.schema().getIndexLabel(copied.name());
        Assert.assertTrue(origin.hasSameContent(copied));
    }
    for (HugeGraph graph : graphs) {
        graph.clearBackend();
    }
    destroyGraphs(graphs);
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) VertexLabel(com.baidu.hugegraph.schema.VertexLabel) IndexLabel(com.baidu.hugegraph.schema.IndexLabel) EdgeLabel(com.baidu.hugegraph.schema.EdgeLabel) SchemaManager(com.baidu.hugegraph.schema.SchemaManager) PropertyKey(com.baidu.hugegraph.schema.PropertyKey) Test(org.junit.Test)

Example 13 with EdgeLabel

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

the class IndexLabelCoreTest method testRemoveIndexLabelOfEdge.

@Test
public void testRemoveIndexLabelOfEdge() {
    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.indexLabel("authoredByContri").remove();
    Assert.assertThrows(NotFoundException.class, () -> {
        schema.getIndexLabel("authoredByContri");
    });
    /*
         * Should not expect that schemalabel previously constructed can be
         * dynamically modified with index label operation
         */
    authored = schema.getEdgeLabel("authored");
    Assert.assertEquals(0, authored.indexLabels().size());
    Assert.assertThrows(NoIndexException.class, () -> {
        graph().traversal().E().hasLabel("authored").has("contribution", "test").next();
    });
}
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 14 with EdgeLabel

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

the class IndexLabelCoreTest method testRebuildIndexLabelOfEdgeLabel.

@Test
public void testRebuildIndexLabelOfEdgeLabel() {
    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.indexLabel("authoredByContri").rebuild();
    Assert.assertEquals(1, authored.indexLabels().size());
    assertContainsIl(authored.indexLabels(), "authoredByContri");
    edge = graph().traversal().E().hasLabel("authored").has("contribution", "test").next();
    Assert.assertNotNull(edge);
}
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 15 with EdgeLabel

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

the class EdgeLabelCoreTest method testAppendEdgeLabelWithUserdata.

@Test
public void testAppendEdgeLabelWithUserdata() {
    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").create();
    // The same key user data will be overwritten
    Assert.assertEquals(2, write.userdata().size());
    Assert.assertEquals("one-to-many", write.userdata().get("multiplicity"));
    write = schema.edgeLabel("write").userdata("icon", "picture2").append();
    Assert.assertEquals(3, write.userdata().size());
    Assert.assertEquals("one-to-many", write.userdata().get("multiplicity"));
    Assert.assertEquals("picture2", write.userdata().get("icon"));
}
Also used : EdgeLabel(com.baidu.hugegraph.schema.EdgeLabel) SchemaManager(com.baidu.hugegraph.schema.SchemaManager) 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