Search in sources :

Example 51 with EdgeLabel

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

the class IndexLabelCoreTest method testRebuildIndexLabelOfEdge.

@Test
public void testRebuildIndexLabelOfEdge() {
    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.edgeLabel("authored").rebuildIndex();
    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 52 with EdgeLabel

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

the class EdgeLabelCoreTest method testCreateTime.

@Test
public void testCreateTime() {
    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();
    Date createTime = (Date) look.userdata().get(Userdata.CREATE_TIME);
    Date now = DateUtil.now();
    Assert.assertFalse(createTime.after(now));
    look = schema.getEdgeLabel("look");
    createTime = (Date) look.userdata().get(Userdata.CREATE_TIME);
    Assert.assertFalse(createTime.after(now));
}
Also used : EdgeLabel(com.baidu.hugegraph.schema.EdgeLabel) SchemaManager(com.baidu.hugegraph.schema.SchemaManager) Date(java.util.Date) Test(org.junit.Test)

Example 53 with EdgeLabel

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

the class EdgeLabelCoreTest method testAppendEdgeLabelWithNullableKeysInOriginProperties.

@Test
public void testAppendEdgeLabelWithNullableKeysInOriginProperties() {
    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", "weight").link("person", "book").create();
    EdgeLabel look = schema.edgeLabel("look").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 54 with EdgeLabel

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

the class EdgeLabelCoreTest method testAddEdgeLabelWithTtl.

@Test
public void testAddEdgeLabelWithTtl() {
    super.initPropertyKeys();
    SchemaManager schema = graph().schema();
    schema.propertyKey("date").asDate().ifNotExist().create();
    schema.vertexLabel("person").properties("name", "age", "city").primaryKeys("name").nullableKeys("city").create();
    schema.vertexLabel("book").properties("name").primaryKeys("name").create();
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        schema.edgeLabel("read").link("person", "book").properties("date", "weight").ttl(-86400L).create();
    });
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        schema.edgeLabel("read").link("person", "book").properties("date", "weight").ttlStartTime("date").create();
    });
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        schema.edgeLabel("read").link("person", "book").properties("date", "weight").ttlStartTime("name").create();
    });
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        schema.edgeLabel("read").link("person", "book").properties("date", "weight").ttlStartTime("weight").create();
    });
    EdgeLabel read = schema.edgeLabel("read").link("person", "book").properties("date", "weight").ttl(86400L).create();
    Assert.assertNotNull(read);
    Assert.assertEquals("read", read.name());
    assertVLEqual("person", read.sourceLabel());
    assertVLEqual("book", read.targetLabel());
    Assert.assertEquals(2, read.properties().size());
    assertContainsPk(read.properties(), "date", "weight");
    Assert.assertEquals(0, read.sortKeys().size());
    Assert.assertEquals(Frequency.SINGLE, read.frequency());
    Assert.assertEquals(86400L, read.ttl());
    Assert.assertEquals(IdGenerator.ZERO, read.ttlStartTime());
    EdgeLabel write = schema.edgeLabel("write").link("person", "book").properties("date", "weight").ttl(86400L).ttlStartTime("date").create();
    Assert.assertNotNull(write);
    Assert.assertEquals("write", write.name());
    assertVLEqual("person", write.sourceLabel());
    assertVLEqual("book", write.targetLabel());
    Assert.assertEquals(2, write.properties().size());
    assertContainsPk(write.properties(), "date", "weight");
    Assert.assertEquals(0, write.sortKeys().size());
    Assert.assertEquals(Frequency.SINGLE, write.frequency());
    Assert.assertEquals(86400L, write.ttl());
    Assert.assertNotNull(write.ttlStartTime());
    assertContainsPk(ImmutableSet.of(write.ttlStartTime()), "date");
}
Also used : EdgeLabel(com.baidu.hugegraph.schema.EdgeLabel) SchemaManager(com.baidu.hugegraph.schema.SchemaManager) Test(org.junit.Test)

Example 55 with EdgeLabel

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

the class EdgeLabelCoreTest method testEliminateEdgeLabelWithUserdata.

@Test
public void testEliminateEdgeLabelWithUserdata() {
    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").userdata("icon", "picture2").create();
    Assert.assertEquals(3, write.userdata().size());
    Assert.assertEquals("one-to-many", write.userdata().get("multiplicity"));
    Assert.assertEquals("picture2", write.userdata().get("icon"));
    write = schema.edgeLabel("write").userdata("icon", "").eliminate();
    Assert.assertEquals(2, write.userdata().size());
    Assert.assertEquals("one-to-many", write.userdata().get("multiplicity"));
}
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