Search in sources :

Example 71 with VertexLabel

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

the class VertexLabelCoreTest method testAppendVertexLabelWithUserdata.

@Test
public void testAppendVertexLabelWithUserdata() {
    super.initPropertyKeys();
    SchemaManager schema = graph().schema();
    VertexLabel player = schema.vertexLabel("player").properties("name").userdata("super_vl", "person").create();
    Assert.assertEquals(2, player.userdata().size());
    Assert.assertEquals("person", player.userdata().get("super_vl"));
    player = schema.vertexLabel("player").userdata("icon", "picture1").append();
    Assert.assertEquals(3, player.userdata().size());
    Assert.assertEquals("person", player.userdata().get("super_vl"));
    Assert.assertEquals("picture1", player.userdata().get("icon"));
}
Also used : VertexLabel(com.baidu.hugegraph.schema.VertexLabel) SchemaManager(com.baidu.hugegraph.schema.SchemaManager) Test(org.junit.Test)

Example 72 with VertexLabel

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

the class VertexLabelCoreTest method testCreateTime.

@Test
public void testCreateTime() {
    super.initPropertyKeys();
    SchemaManager schema = graph().schema();
    VertexLabel person = schema.vertexLabel("person").properties("name", "age", "city").primaryKeys("name").create();
    Date createTime = (Date) person.userdata().get(Userdata.CREATE_TIME);
    Date now = DateUtil.now();
    Assert.assertFalse(createTime.after(now));
    person = schema.getVertexLabel("person");
    createTime = (Date) person.userdata().get(Userdata.CREATE_TIME);
    Assert.assertFalse(createTime.after(now));
}
Also used : VertexLabel(com.baidu.hugegraph.schema.VertexLabel) SchemaManager(com.baidu.hugegraph.schema.SchemaManager) Date(java.util.Date) Test(org.junit.Test)

Example 73 with VertexLabel

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

the class VertexLabelCoreTest method testAppendVertexLabelWithNullableKeysInOriginProperties.

@Test
public void testAppendVertexLabelWithNullableKeysInOriginProperties() {
    super.initPropertyKeys();
    SchemaManager schema = graph().schema();
    schema.vertexLabel("person").properties("name", "age", "city").primaryKeys("name").nullableKeys("age").create();
    VertexLabel person = schema.vertexLabel("person").nullableKeys("city").append();
    Assert.assertNotNull(person);
    Assert.assertEquals("person", person.name());
    Assert.assertEquals(3, person.properties().size());
    assertContainsPk(person.properties(), "name", "age", "city");
    Assert.assertEquals(1, person.primaryKeys().size());
    assertContainsPk(person.primaryKeys(), "name");
    Assert.assertEquals(2, person.nullableKeys().size());
    assertContainsPk(person.nullableKeys(), "age", "city");
}
Also used : VertexLabel(com.baidu.hugegraph.schema.VertexLabel) SchemaManager(com.baidu.hugegraph.schema.SchemaManager) Test(org.junit.Test)

Example 74 with VertexLabel

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

the class VertexLabelCoreTest method testAddVertexLabelWithEnableLabelIndex.

@Test
public void testAddVertexLabelWithEnableLabelIndex() {
    super.initPropertyKeys();
    SchemaManager schema = graph().schema();
    VertexLabel person = schema.vertexLabel("person").properties("name", "age", "city").primaryKeys("name").nullableKeys("city").enableLabelIndex(true).create();
    Assert.assertEquals(true, person.enableLabelIndex());
    graph().addVertex(T.label, "person", "name", "marko", "age", 18);
    graph().addVertex(T.label, "person", "name", "josh", "age", 20);
    graph().tx().commit();
    List<Vertex> persons = graph().traversal().V().hasLabel("person").toList();
    Assert.assertEquals(2, persons.size());
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) VertexLabel(com.baidu.hugegraph.schema.VertexLabel) SchemaManager(com.baidu.hugegraph.schema.SchemaManager) Test(org.junit.Test)

Example 75 with VertexLabel

use of com.baidu.hugegraph.schema.VertexLabel 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)

Aggregations

VertexLabel (com.baidu.hugegraph.schema.VertexLabel)86 Test (org.junit.Test)35 SchemaManager (com.baidu.hugegraph.schema.SchemaManager)27 Id (com.baidu.hugegraph.backend.id.Id)23 PropertyKey (com.baidu.hugegraph.schema.PropertyKey)20 HugeGraph (com.baidu.hugegraph.HugeGraph)19 HugeVertex (com.baidu.hugegraph.structure.HugeVertex)19 EdgeId (com.baidu.hugegraph.backend.id.EdgeId)12 EdgeLabel (com.baidu.hugegraph.schema.EdgeLabel)12 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)11 FakeObjects (com.baidu.hugegraph.unit.FakeObjects)7 ConditionQuery (com.baidu.hugegraph.backend.query.ConditionQuery)6 BaseUnitTest (com.baidu.hugegraph.unit.BaseUnitTest)5 Timed (com.codahale.metrics.annotation.Timed)5 RolesAllowed (jakarta.annotation.security.RolesAllowed)5 Produces (jakarta.ws.rs.Produces)5 Watched (com.baidu.hugegraph.perf.PerfUtil.Watched)4 IndexLabel (com.baidu.hugegraph.schema.IndexLabel)4 HugeEdge (com.baidu.hugegraph.structure.HugeEdge)4 Date (java.util.Date)4