Search in sources :

Example 11 with PropertyKey

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;
}
Also used : PropertyKey(com.baidu.hugegraph.structure.schema.PropertyKey)

Example 12 with PropertyKey

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());
}
Also used : RestResult(com.baidu.hugegraph.rest.RestResult) PropertyKey(com.baidu.hugegraph.structure.schema.PropertyKey) Test(org.junit.Test)

Example 13 with PropertyKey

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);
}
Also used : SchemaManager(com.baidu.hugegraph.driver.SchemaManager) PropertyKey(com.baidu.hugegraph.structure.schema.PropertyKey) Test(org.junit.Test)

Example 14 with PropertyKey

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());
}
Also used : SchemaManager(com.baidu.hugegraph.driver.SchemaManager) PropertyKey(com.baidu.hugegraph.structure.schema.PropertyKey) Test(org.junit.Test)

Example 15 with PropertyKey

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