Search in sources :

Example 11 with VertexLabel

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

the class VertexLabelCoreTest method testAddVertexLabel.

@Test
public void testAddVertexLabel() {
    super.initPropertyKeys();
    SchemaManager schema = graph().schema();
    VertexLabel person = schema.vertexLabel("person").properties("name", "age", "city").primaryKeys("name").create();
    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");
}
Also used : VertexLabel(com.baidu.hugegraph.schema.VertexLabel) SchemaManager(com.baidu.hugegraph.schema.SchemaManager) Test(org.junit.Test)

Example 12 with VertexLabel

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

the class VertexLabelCoreTest method testAppendVertexLabelWithNullableKeysInAppendProperties.

@Test
public void testAppendVertexLabelWithNullableKeysInAppendProperties() {
    super.initPropertyKeys();
    SchemaManager schema = graph().schema();
    schema.vertexLabel("person").properties("name", "age").primaryKeys("name").create();
    VertexLabel person = schema.vertexLabel("person").properties("city").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(1, person.nullableKeys().size());
    assertContainsPk(person.nullableKeys(), "city");
}
Also used : VertexLabel(com.baidu.hugegraph.schema.VertexLabel) SchemaManager(com.baidu.hugegraph.schema.SchemaManager) Test(org.junit.Test)

Example 13 with VertexLabel

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

the class VertexLabelCoreTest method testEliminateVertexLabelWithUserdata.

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

Example 14 with VertexLabel

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

the class FakeObjects method newVertexLabel.

public VertexLabel newVertexLabel(Id id, String name, IdStrategy idStrategy, Id... properties) {
    VertexLabel schema = new VertexLabel(this.graph, id, name);
    schema.idStrategy(idStrategy);
    schema.properties(properties);
    Mockito.when(this.graph.vertexLabel(id)).thenReturn(schema);
    Mockito.when(this.graph.vertexLabelOrNone(id)).thenReturn(schema);
    return schema;
}
Also used : VertexLabel(com.baidu.hugegraph.schema.VertexLabel)

Example 15 with VertexLabel

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

the class FakeObjects method newEdge.

public HugeEdge newEdge(long sourceVertexId, long targetVertexId) {
    PropertyKey name = this.newPropertyKey(IdGenerator.of(1), "name");
    PropertyKey age = this.newPropertyKey(IdGenerator.of(2), "age", DataType.INT, Cardinality.SINGLE);
    PropertyKey city = this.newPropertyKey(IdGenerator.of(3), "city");
    PropertyKey date = this.newPropertyKey(IdGenerator.of(4), "date", DataType.DATE);
    PropertyKey weight = this.newPropertyKey(IdGenerator.of(5), "weight", DataType.DOUBLE);
    VertexLabel vl = this.newVertexLabel(IdGenerator.of(1), "person", IdStrategy.CUSTOMIZE_NUMBER, name.id(), age.id(), city.id());
    EdgeLabel el = this.newEdgeLabel(IdGenerator.of(1), "knows", Frequency.SINGLE, vl.id(), vl.id(), date.id(), weight.id());
    HugeVertex source = new HugeVertex(this.graph(), IdGenerator.of(sourceVertexId), vl);
    source.addProperty(name, "tom");
    source.addProperty(age, 18);
    source.addProperty(city, "Beijing");
    HugeVertex target = new HugeVertex(this.graph(), IdGenerator.of(targetVertexId), vl);
    target.addProperty(name, "cat");
    target.addProperty(age, 20);
    target.addProperty(city, "Shanghai");
    Id id = EdgeId.parse("L123456>1>>L987654");
    HugeEdge edge = new HugeEdge(this.graph(), id, el);
    Whitebox.setInternalState(edge, "sourceVertex", source);
    Whitebox.setInternalState(edge, "targetVertex", target);
    edge.assignId();
    edge.addProperty(date, new Date());
    edge.addProperty(weight, 0.75);
    return edge;
}
Also used : VertexLabel(com.baidu.hugegraph.schema.VertexLabel) EdgeLabel(com.baidu.hugegraph.schema.EdgeLabel) HugeEdge(com.baidu.hugegraph.structure.HugeEdge) EdgeId(com.baidu.hugegraph.backend.id.EdgeId) Id(com.baidu.hugegraph.backend.id.Id) HugeVertex(com.baidu.hugegraph.structure.HugeVertex) PropertyKey(com.baidu.hugegraph.schema.PropertyKey) Date(java.util.Date)

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