Search in sources :

Example 36 with PropertyKey

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

the class PropertyKeyCoreTest method testAddPropertyKeyWithUserdata.

@Test
public void testAddPropertyKeyWithUserdata() {
    SchemaManager schema = graph().schema();
    PropertyKey age = schema.propertyKey("age").userdata("min", 0).userdata("max", 100).create();
    Assert.assertEquals(3, age.userdata().size());
    Assert.assertEquals(0, age.userdata().get("min"));
    Assert.assertEquals(100, age.userdata().get("max"));
    PropertyKey id = schema.propertyKey("id").userdata("length", 15).userdata("length", 18).create();
    // The same key user data will be overwritten
    Assert.assertEquals(2, id.userdata().size());
    Assert.assertEquals(18, id.userdata().get("length"));
    PropertyKey sex = schema.propertyKey("sex").userdata("range", ImmutableList.of("male", "female")).create();
    Assert.assertEquals(2, sex.userdata().size());
    Assert.assertEquals(ImmutableList.of("male", "female"), sex.userdata().get("range"));
}
Also used : SchemaManager(com.baidu.hugegraph.schema.SchemaManager) PropertyKey(com.baidu.hugegraph.schema.PropertyKey) Test(org.junit.Test)

Example 37 with PropertyKey

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

the class PropertyKeyCoreTest method testAddPropertyKey.

@Test
public void testAddPropertyKey() {
    SchemaManager schema = graph().schema();
    PropertyKey id = schema.propertyKey("id").asText().valueSingle().create();
    Assert.assertEquals("id", id.name());
    Assert.assertEquals(DataType.TEXT, id.dataType());
    Assert.assertEquals(Cardinality.SINGLE, id.cardinality());
}
Also used : SchemaManager(com.baidu.hugegraph.schema.SchemaManager) PropertyKey(com.baidu.hugegraph.schema.PropertyKey) Test(org.junit.Test)

Example 38 with PropertyKey

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

the class PropertyKeyCoreTest method testEliminatePropertyKeyWithUserdata.

@Test
public void testEliminatePropertyKeyWithUserdata() {
    SchemaManager schema = graph().schema();
    PropertyKey age = schema.propertyKey("age").userdata("min", 0).userdata("max", 100).create();
    Assert.assertEquals(3, age.userdata().size());
    Assert.assertEquals(0, age.userdata().get("min"));
    Assert.assertEquals(100, age.userdata().get("max"));
    age = schema.propertyKey("age").userdata("max", "").eliminate();
    Assert.assertEquals(2, age.userdata().size());
    Assert.assertEquals(0, age.userdata().get("min"));
}
Also used : SchemaManager(com.baidu.hugegraph.schema.SchemaManager) PropertyKey(com.baidu.hugegraph.schema.PropertyKey) Test(org.junit.Test)

Example 39 with PropertyKey

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

the class EdgeAPI method getEdgeId.

private Id getEdgeId(HugeGraph g, JsonEdge newEdge) {
    String sortKeys = "";
    Id labelId = g.edgeLabel(newEdge.label).id();
    List<Id> sortKeyIds = g.edgeLabel(labelId).sortKeys();
    if (!sortKeyIds.isEmpty()) {
        List<Object> sortKeyValues = new ArrayList<>(sortKeyIds.size());
        sortKeyIds.forEach(skId -> {
            PropertyKey pk = g.propertyKey(skId);
            String sortKey = pk.name();
            Object sortKeyValue = newEdge.properties.get(sortKey);
            E.checkArgument(sortKeyValue != null, "The value of sort key '%s' can't be null", sortKey);
            sortKeyValue = pk.validValueOrThrow(sortKeyValue);
            sortKeyValues.add(sortKeyValue);
        });
        sortKeys = ConditionQuery.concatValues(sortKeyValues);
    }
    EdgeId edgeId = new EdgeId(HugeVertex.getIdValue(newEdge.source), Directions.OUT, labelId, sortKeys, HugeVertex.getIdValue(newEdge.target));
    if (newEdge.id != null) {
        E.checkArgument(edgeId.asString().equals(newEdge.id), "The ids are different between server and " + "request body ('%s' != '%s'). And note the sort " + "key values should either be null or equal to " + "the origin value when specified edge id", edgeId, newEdge.id);
    }
    return edgeId;
}
Also used : EdgeId(com.baidu.hugegraph.backend.id.EdgeId) ArrayList(java.util.ArrayList) Id(com.baidu.hugegraph.backend.id.Id) EdgeId(com.baidu.hugegraph.backend.id.EdgeId) PropertyKey(com.baidu.hugegraph.schema.PropertyKey)

Example 40 with PropertyKey

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

the class VertexAPI method update.

@PUT
@Timed(name = "single-update")
@Path("{id}")
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON_WITH_CHARSET)
@RolesAllowed({ "admin", "$owner=$graph $action=vertex_write" })
public String update(@Context GraphManager manager, @PathParam("graph") String graph, @PathParam("id") String idValue, @QueryParam("action") String action, JsonVertex jsonVertex) {
    LOG.debug("Graph [{}] update vertex: {}", graph, jsonVertex);
    checkUpdatingBody(jsonVertex);
    Id id = checkAndParseVertexId(idValue);
    // Parse action param
    boolean append = checkAndParseAction(action);
    HugeGraph g = graph(manager, graph);
    HugeVertex vertex = (HugeVertex) g.vertex(id);
    VertexLabel vertexLabel = vertex.schemaLabel();
    for (String key : jsonVertex.properties.keySet()) {
        PropertyKey pkey = g.propertyKey(key);
        E.checkArgument(vertexLabel.properties().contains(pkey.id()), "Can't update property for vertex '%s' because " + "there is no property key '%s' in its vertex label", id, key);
    }
    commit(g, () -> updateProperties(vertex, jsonVertex, append));
    return manager.serializer(g).writeVertex(vertex);
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) VertexLabel(com.baidu.hugegraph.schema.VertexLabel) Id(com.baidu.hugegraph.backend.id.Id) HugeVertex(com.baidu.hugegraph.structure.HugeVertex) PropertyKey(com.baidu.hugegraph.schema.PropertyKey) Path(jakarta.ws.rs.Path) RolesAllowed(jakarta.annotation.security.RolesAllowed) Consumes(jakarta.ws.rs.Consumes) Produces(jakarta.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) PUT(jakarta.ws.rs.PUT)

Aggregations

PropertyKey (com.baidu.hugegraph.schema.PropertyKey)94 Id (com.baidu.hugegraph.backend.id.Id)31 Test (org.junit.Test)24 VertexLabel (com.baidu.hugegraph.schema.VertexLabel)20 SchemaManager (com.baidu.hugegraph.schema.SchemaManager)15 HugeGraph (com.baidu.hugegraph.HugeGraph)13 EdgeLabel (com.baidu.hugegraph.schema.EdgeLabel)11 EdgeId (com.baidu.hugegraph.backend.id.EdgeId)9 HugeVertex (com.baidu.hugegraph.structure.HugeVertex)9 BaseUnitTest (com.baidu.hugegraph.unit.BaseUnitTest)9 ConditionQuery (com.baidu.hugegraph.backend.query.ConditionQuery)7 FakeObjects (com.baidu.hugegraph.unit.FakeObjects)7 Watched (com.baidu.hugegraph.perf.PerfUtil.Watched)6 HugeEdge (com.baidu.hugegraph.structure.HugeEdge)6 DataType (com.baidu.hugegraph.type.define.DataType)6 Map (java.util.Map)6 IndexLabel (com.baidu.hugegraph.schema.IndexLabel)5 Timed (com.codahale.metrics.annotation.Timed)5 RolesAllowed (jakarta.annotation.security.RolesAllowed)5 Collection (java.util.Collection)5