Search in sources :

Example 81 with VertexLabel

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

the class VertexLabelCoreTest method testAddVertexLabelWithNullableKeys.

@Test
public void testAddVertexLabelWithNullableKeys() {
    super.initPropertyKeys();
    SchemaManager schema = graph().schema();
    VertexLabel person = schema.vertexLabel("person").properties("name", "age", "city").primaryKeys("name").nullableKeys("city").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");
    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 82 with VertexLabel

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

the class VertexLabelCoreTest method testAddVertexWithDefaultIdStrategyAndNotPassedPk.

@Test
public void testAddVertexWithDefaultIdStrategyAndNotPassedPk() {
    super.initPropertyKeys();
    HugeGraph graph = graph();
    SchemaManager schema = graph.schema();
    VertexLabel person = schema.vertexLabel("person").properties("name", "age").create();
    Assert.assertEquals(IdStrategy.AUTOMATIC, person.idStrategy());
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) VertexLabel(com.baidu.hugegraph.schema.VertexLabel) SchemaManager(com.baidu.hugegraph.schema.SchemaManager) Test(org.junit.Test)

Example 83 with VertexLabel

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

the class VertexLabelCoreTest method testAddVertexWithAutomaticIdStrategyAndNotPassedPk.

@Test
public void testAddVertexWithAutomaticIdStrategyAndNotPassedPk() {
    super.initPropertyKeys();
    HugeGraph graph = graph();
    SchemaManager schema = graph.schema();
    VertexLabel person = schema.vertexLabel("person").useAutomaticId().properties("name", "age").create();
    Assert.assertEquals(IdStrategy.AUTOMATIC, person.idStrategy());
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) VertexLabel(com.baidu.hugegraph.schema.VertexLabel) SchemaManager(com.baidu.hugegraph.schema.SchemaManager) Test(org.junit.Test)

Example 84 with VertexLabel

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

the class CachedGraphTransactionTest method newVertex.

private HugeVertex newVertex(Id id) {
    HugeGraph graph = this.cache().graph();
    graph.schema().propertyKey("name").asText().checkExist(false).create();
    graph.schema().vertexLabel("person").idStrategy(IdStrategy.CUSTOMIZE_NUMBER).properties("name").nullableKeys("name").checkExist(false).create();
    VertexLabel vl = graph.vertexLabel("person");
    return new HugeVertex(graph, id, vl);
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) VertexLabel(com.baidu.hugegraph.schema.VertexLabel) HugeVertex(com.baidu.hugegraph.structure.HugeVertex)

Example 85 with VertexLabel

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

the class JsonUtilTest method testSerializeEdge.

@Test
public void testSerializeEdge() {
    FakeObjects fakeObject = new FakeObjects();
    PropertyKey name = fakeObject.newPropertyKey(IdGenerator.of(1), "name");
    PropertyKey age = fakeObject.newPropertyKey(IdGenerator.of(2), "age", DataType.INT, Cardinality.SINGLE);
    PropertyKey city = fakeObject.newPropertyKey(IdGenerator.of(3), "city");
    PropertyKey date = fakeObject.newPropertyKey(IdGenerator.of(4), "date", DataType.DATE);
    PropertyKey weight = fakeObject.newPropertyKey(IdGenerator.of(5), "weight", DataType.DOUBLE);
    VertexLabel vl = fakeObject.newVertexLabel(IdGenerator.of(1), "person", IdStrategy.CUSTOMIZE_NUMBER, name.id(), age.id(), city.id());
    EdgeLabel el = fakeObject.newEdgeLabel(IdGenerator.of(1), "knows", Frequency.SINGLE, vl.id(), vl.id(), date.id(), weight.id());
    HugeVertex source = new HugeVertex(fakeObject.graph(), IdGenerator.of(123456), vl);
    HugeVertex target = new HugeVertex(fakeObject.graph(), IdGenerator.of(987654), vl);
    Id id = EdgeId.parse("L123456>1>>L987654");
    HugeEdge edge = new HugeEdge(fakeObject.graph(), id, el);
    Whitebox.setInternalState(edge, "sourceVertex", source);
    Whitebox.setInternalState(edge, "targetVertex", target);
    Date dateValue = Utils.date("2019-03-12");
    MutableIntObjectMap<HugeProperty<?>> properties = CollectionFactory.newIntObjectMap(date.id(), new HugeEdgeProperty<>(edge, date, dateValue), weight.id(), new HugeEdgeProperty<>(edge, weight, 0.8));
    Whitebox.setInternalState(edge, "properties", properties);
    String json = JsonUtil.toJson(edge);
    Assert.assertEquals("{\"id\":\"L123456>1>>L987654\"," + "\"label\":\"knows\",\"type\":\"edge\"," + "\"outV\":123456,\"outVLabel\":\"person\"," + "\"inV\":987654,\"inVLabel\":\"person\"," + "\"properties\":{\"date\":" + "\"2019-03-12 00:00:00.000\"," + "\"weight\":0.8}}", json);
}
Also used : HugeProperty(com.baidu.hugegraph.structure.HugeProperty) FakeObjects(com.baidu.hugegraph.unit.FakeObjects) 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) BaseUnitTest(com.baidu.hugegraph.unit.BaseUnitTest) 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