Search in sources :

Example 21 with PropertyKey

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

the class PropertyKeyService method list.

public List<PropertyKeyEntity> list(Collection<String> names, int connId, boolean emptyAsAll) {
    HugeClient client = this.client(connId);
    List<PropertyKey> propertyKeys;
    if (CollectionUtils.isEmpty(names)) {
        if (emptyAsAll) {
            propertyKeys = client.schema().getPropertyKeys();
        } else {
            propertyKeys = new ArrayList<>();
        }
    } else {
        propertyKeys = client.schema().getPropertyKeys(new ArrayList<>(names));
    }
    List<PropertyKeyEntity> results = new ArrayList<>(propertyKeys.size());
    propertyKeys.forEach(propertyKey -> {
        results.add(convert(propertyKey));
    });
    return results;
}
Also used : HugeClient(com.baidu.hugegraph.driver.HugeClient) ArrayList(java.util.ArrayList) PropertyKey(com.baidu.hugegraph.structure.schema.PropertyKey) PropertyKeyEntity(com.baidu.hugegraph.entity.schema.PropertyKeyEntity)

Example 22 with PropertyKey

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

the class VertexLabelService method reuse.

public void reuse(ConflictDetail detail, int connId) {
    // Assume that the conflict detail is valid
    Ex.check(!detail.hasConflict(), "schema.cannot-reuse-conflict");
    HugeClient client = this.client(connId);
    List<PropertyKey> propertyKeys = this.pkService.filter(detail, client);
    if (!propertyKeys.isEmpty()) {
        try {
            this.pkService.addBatch(propertyKeys, client);
        } catch (Exception e) {
            throw new ExternalException("schema.propertykey.reuse.failed", e);
        }
    }
    List<VertexLabel> vertexLabels = this.filter(detail, client);
    // Filter propertykeys and propertyindexes
    if (!vertexLabels.isEmpty()) {
        try {
            this.addBatch(vertexLabels, client);
        } catch (Exception e) {
            this.pkService.removeBatch(propertyKeys, client);
            throw new ExternalException("schema.vertexlabel.reuse.failed", e);
        }
    }
    List<IndexLabel> indexLabels = this.piService.filter(detail, client);
    if (!indexLabels.isEmpty()) {
        try {
            this.piService.addBatch(indexLabels, client);
        } catch (Exception e) {
            this.removeBatch(vertexLabels, client);
            this.pkService.removeBatch(propertyKeys, client);
            throw new ExternalException("schema.propertyindex.reuse.failed", e);
        }
    }
}
Also used : HugeClient(com.baidu.hugegraph.driver.HugeClient) VertexLabel(com.baidu.hugegraph.structure.schema.VertexLabel) IndexLabel(com.baidu.hugegraph.structure.schema.IndexLabel) ExternalException(com.baidu.hugegraph.exception.ExternalException) PropertyKey(com.baidu.hugegraph.structure.schema.PropertyKey) ServerException(com.baidu.hugegraph.exception.ServerException) ExternalException(com.baidu.hugegraph.exception.ExternalException)

Example 23 with PropertyKey

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

the class RestResultTest method testReadPropertyKey.

@Test
public void testReadPropertyKey() {
    String json = "{" + "\"id\": 3," + "\"data_type\": \"INT\"," + "\"name\": \"id\"," + "\"cardinality\": \"SINGLE\"," + "\"properties\": []" + "}";
    Mockito.when(this.mockResponse.getStatus()).thenReturn(200);
    Mockito.when(this.mockResponse.getHeaders()).thenReturn(null);
    Mockito.when(this.mockResponse.readEntity(String.class)).thenReturn(json);
    RestResult result = new RestResult(this.mockResponse);
    Assert.assertEquals(200, result.status());
    Assert.assertNull(result.headers());
    PropertyKey propertyKey = result.readObject(PropertyKey.class);
    Assert.assertEquals("id", propertyKey.name());
    Assert.assertEquals(DataType.INT, propertyKey.dataType());
    Assert.assertEquals(Cardinality.SINGLE, propertyKey.cardinality());
    Assert.assertEquals(Collections.emptySet(), propertyKey.properties());
}
Also used : RestResult(com.baidu.hugegraph.rest.RestResult) PropertyKey(com.baidu.hugegraph.structure.schema.PropertyKey) Test(org.junit.Test)

Example 24 with PropertyKey

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

the class PropertyKeyTest method testOlapPropertyKey.

@Test
public void testOlapPropertyKey() {
    SchemaManager schema = schema();
    PropertyKey pagerank = schema.propertyKey("pagerank").asDouble().writeType(WriteType.OLAP_RANGE).build();
    schema.addPropertyKey(pagerank);
    schema.getPropertyKey(pagerank.name());
    schema.clearPropertyKey(pagerank);
    schema.removePropertyKey(pagerank.name());
    Utils.assertResponseError(404, () -> {
        schema.getPropertyKey(pagerank.name());
    });
    long task = schema.addPropertyKeyAsync(pagerank);
    waitUntilTaskCompleted(task);
    schema.getPropertyKey(pagerank.name());
    task = schema.clearPropertyKeyAsync(pagerank);
    waitUntilTaskCompleted(task);
    task = schema.removePropertyKeyAsync(pagerank.name());
    waitUntilTaskCompleted(task);
    Utils.assertResponseError(404, () -> {
        schema.getPropertyKey(pagerank.name());
    });
}
Also used : SchemaManager(com.baidu.hugegraph.driver.SchemaManager) PropertyKey(com.baidu.hugegraph.structure.schema.PropertyKey) Test(org.junit.Test)

Example 25 with PropertyKey

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

the class PropertyKeyTest method testEliminatePropertyKeyWithUserData.

@Test
public void testEliminatePropertyKeyWithUserData() {
    SchemaManager schema = 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"));
    String time = (String) age.userdata().get("~create_time");
    Date createTime = DateUtil.parse(time);
    Assert.assertTrue(createTime.before(DateUtil.now()));
    age = schema.propertyKey("age").userdata("max", "").eliminate();
    Assert.assertEquals(2, age.userdata().size());
    Assert.assertEquals(0, age.userdata().get("min"));
    time = (String) age.userdata().get("~create_time");
    Assert.assertEquals(createTime, DateUtil.parse(time));
}
Also used : SchemaManager(com.baidu.hugegraph.driver.SchemaManager) PropertyKey(com.baidu.hugegraph.structure.schema.PropertyKey) Date(java.util.Date) Test(org.junit.Test)

Aggregations

PropertyKey (com.baidu.hugegraph.structure.schema.PropertyKey)40 Test (org.junit.Test)27 SchemaManager (com.baidu.hugegraph.driver.SchemaManager)7 HugeClient (com.baidu.hugegraph.driver.HugeClient)6 RestResult (com.baidu.hugegraph.rest.RestResult)6 ExternalException (com.baidu.hugegraph.exception.ExternalException)4 Date (java.util.Date)4 ServerException (com.baidu.hugegraph.exception.ServerException)3 PropertyKeyEntity (com.baidu.hugegraph.entity.schema.PropertyKeyEntity)2 Vertex (com.baidu.hugegraph.structure.graph.Vertex)2 IndexLabel (com.baidu.hugegraph.structure.schema.IndexLabel)2 VertexLabel (com.baidu.hugegraph.structure.schema.VertexLabel)2 GremlinRequest (com.baidu.hugegraph.api.gremlin.GremlinRequest)1 NotSupportException (com.baidu.hugegraph.exception.NotSupportException)1 InputSource (com.baidu.hugegraph.loader.source.InputSource)1 FileSource (com.baidu.hugegraph.loader.source.file.FileSource)1 ListFormat (com.baidu.hugegraph.loader.source.file.ListFormat)1 Edge (com.baidu.hugegraph.structure.graph.Edge)1 ResultSet (com.baidu.hugegraph.structure.gremlin.ResultSet)1 EdgeLabel (com.baidu.hugegraph.structure.schema.EdgeLabel)1