use of com.baidu.hugegraph.structure.schema.PropertyKey in project incubator-hugegraph-toolchain by apache.
the class PropertyKeyAPI method checkCreateOrUpdate.
@Override
protected Object checkCreateOrUpdate(SchemaElement schemaElement) {
PropertyKey propertyKey = (PropertyKey) schemaElement;
Object pkey = propertyKey;
if (this.client.apiVersionLt("0.47")) {
E.checkArgument(propertyKey.aggregateType().isNone(), "Not support aggregate property until " + "api version 0.47");
pkey = propertyKey.switchV46();
} else if (this.client.apiVersionLt("0.59")) {
E.checkArgument(propertyKey.writeType() == WriteType.OLTP, "Not support olap property key until " + "api version 0.59");
pkey = propertyKey.switchV58();
}
return pkey;
}
use of com.baidu.hugegraph.structure.schema.PropertyKey in project incubator-hugegraph-toolchain by apache.
the class RestResultTest method testReadPropertyKeys.
@Test
public void testReadPropertyKeys() {
String json = "{\"propertykeys\": [" + "{" + "\"id\": 3," + "\"data_type\": \"TEXT\"," + "\"name\": \"id\"," + "\"cardinality\": \"SINGLE\"," + "\"properties\": []" + "}," + "{\"id\": 4," + "\"data_type\": \"FLOAT\"," + "\"name\": \"date\"," + "\"cardinality\": \"SET\"," + "\"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());
List<PropertyKey> propertyKeys = result.readList("propertykeys", PropertyKey.class);
Assert.assertEquals(2, propertyKeys.size());
PropertyKey propertyKey1 = propertyKeys.get(0);
PropertyKey propertyKey2 = propertyKeys.get(1);
Assert.assertEquals("id", propertyKey1.name());
Assert.assertEquals(DataType.TEXT, propertyKey1.dataType());
Assert.assertEquals(Cardinality.SINGLE, propertyKey1.cardinality());
Assert.assertEquals(Collections.emptySet(), propertyKey1.properties());
Assert.assertEquals("date", propertyKey2.name());
Assert.assertEquals(DataType.FLOAT, propertyKey2.dataType());
Assert.assertEquals(Cardinality.SET, propertyKey2.cardinality());
Assert.assertEquals(Collections.emptySet(), propertyKey2.properties());
}
use of com.baidu.hugegraph.structure.schema.PropertyKey in project incubator-hugegraph-toolchain by apache.
the class PropertyKeyTest method testListByNames.
@Test
public void testListByNames() {
SchemaManager schema = schema();
PropertyKey age = schema.propertyKey("age").create();
PropertyKey id = schema.propertyKey("id").create();
List<PropertyKey> propertyKeys;
propertyKeys = schema.getPropertyKeys(ImmutableList.of("age"));
Assert.assertEquals(1, propertyKeys.size());
assertContains(propertyKeys, age);
propertyKeys = schema.getPropertyKeys(ImmutableList.of("id"));
Assert.assertEquals(1, propertyKeys.size());
assertContains(propertyKeys, id);
propertyKeys = schema.getPropertyKeys(ImmutableList.of("age", "id"));
Assert.assertEquals(2, propertyKeys.size());
assertContains(propertyKeys, age);
assertContains(propertyKeys, id);
}
use of com.baidu.hugegraph.structure.schema.PropertyKey in project incubator-hugegraph-toolchain by apache.
the class PropertyKeyTest method testResetPropertyKeyId.
@Test
public void testResetPropertyKeyId() {
SchemaManager schema = schema();
PropertyKey age = schema.propertyKey("age").userdata("min", 0).userdata("max", 100).create();
Assert.assertTrue(age.id() > 0);
age.resetId();
Assert.assertEquals(0L, age.id());
}
use of com.baidu.hugegraph.structure.schema.PropertyKey in project incubator-hugegraph-toolchain by apache.
the class PropertyKeyTest method testAppendPropertyKeyWithUserData.
@Test
public void testAppendPropertyKeyWithUserData() {
SchemaManager schema = schema();
PropertyKey age = schema.propertyKey("age").userdata("min", 0).create();
Assert.assertEquals(2, age.userdata().size());
Assert.assertEquals(0, age.userdata().get("min"));
String time = (String) age.userdata().get("~create_time");
Date createTime = DateUtil.parse(time);
Assert.assertTrue(createTime.before(DateUtil.now()));
age = schema.propertyKey("age").userdata("min", 1).userdata("max", 100).append();
Assert.assertEquals(3, age.userdata().size());
Assert.assertEquals(1, age.userdata().get("min"));
Assert.assertEquals(100, age.userdata().get("max"));
time = (String) age.userdata().get("~create_time");
Assert.assertEquals(createTime, DateUtil.parse(time));
}
Aggregations