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;
}
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);
}
}
}
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());
}
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());
});
}
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));
}
Aggregations