Search in sources :

Example 46 with EdgeLabel

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");
}
Also used : EdgeLabel(com.baidu.hugegraph.schema.EdgeLabel) SchemaManager(com.baidu.hugegraph.schema.SchemaManager) Test(org.junit.Test)

Example 47 with EdgeLabel

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"));
}
Also used : EdgeLabel(com.baidu.hugegraph.schema.EdgeLabel) SchemaManager(com.baidu.hugegraph.schema.SchemaManager) Test(org.junit.Test)

Example 48 with EdgeLabel

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

Example 49 with EdgeLabel

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

Example 50 with EdgeLabel

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());
}
Also used : IndexLabel(com.baidu.hugegraph.schema.IndexLabel) 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