Search in sources :

Example 21 with IndexLabel

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

the class IndexLabelTest method testAddIndexLabelWithUserData.

@Test
public void testAddIndexLabelWithUserData() {
    SchemaManager schema = schema();
    BaseFuncTest.initVertexLabel();
    IndexLabel personByCity = schema.indexLabel("personByCity").onV("person").by("city").secondary().userdata("type", "secondary").ifNotExist().create();
    Assert.assertEquals(2, personByCity.userdata().size());
    Assert.assertEquals("secondary", personByCity.userdata().get("type"));
    String time = (String) personByCity.userdata().get("~create_time");
    Date createTime = DateUtil.parse(time);
    Assert.assertTrue(createTime.before(DateUtil.now()));
    IndexLabel personByAge = schema.indexLabel("personByAge").onV("person").by("age").range().userdata("type", "secondary").userdata("type", "range").ifNotExist().create();
    Assert.assertEquals(2, personByAge.userdata().size());
    Assert.assertEquals("range", personByAge.userdata().get("type"));
    time = (String) personByAge.userdata().get("~create_time");
    createTime = DateUtil.parse(time);
    Assert.assertTrue(createTime.before(DateUtil.now()));
}
Also used : IndexLabel(com.baidu.hugegraph.structure.schema.IndexLabel) SchemaManager(com.baidu.hugegraph.driver.SchemaManager) Date(java.util.Date) Test(org.junit.Test)

Example 22 with IndexLabel

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

the class IndexLabelTest method testRemoveIndexLabelAsync.

@Test
public void testRemoveIndexLabelAsync() {
    SchemaManager schema = schema();
    schema.vertexLabel("player").properties("name", "age").create();
    IndexLabel playerByName = schema.indexLabel("playerByName").onV("player").by("name").secondary().create();
    Assert.assertNotNull(playerByName);
    // Remove index label async
    schema.removeIndexLabelAsync("playerByName");
}
Also used : IndexLabel(com.baidu.hugegraph.structure.schema.IndexLabel) SchemaManager(com.baidu.hugegraph.driver.SchemaManager) Test(org.junit.Test)

Example 23 with IndexLabel

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

the class IndexLabelTest method testIndexLabel.

@Test
public void testIndexLabel() {
    IndexLabel.Builder builder = new IndexLabel.BuilderImpl("personByAge", null);
    IndexLabel indexLabel = builder.onV("person").secondary().by("age").build();
    String json = "{\"name\":\"personByAge\",\"id\":0," + "\"check_exist\":true,\"user_data\":{}," + "\"base_type\":\"VERTEX_LABEL\"," + "\"base_value\":\"person\"," + "\"index_type\":\"SECONDARY\",\"fields\":[\"age\"]," + "\"rebuild\":true}";
    Assert.assertEquals(json, JsonUtil.toJson(indexLabel));
    Assert.assertEquals(HugeType.INDEX_LABEL.string(), indexLabel.type());
}
Also used : IndexLabel(com.baidu.hugegraph.structure.schema.IndexLabel) Test(org.junit.Test)

Example 24 with IndexLabel

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

the class IndexLabelApiTest method testCreateWithIndexType.

@Test
public void testCreateWithIndexType() {
    IndexLabel indexLabel = schema().indexLabel("personByAge").onV("person").by("age").indexType(IndexType.RANGE).build();
    Assert.assertEquals("personByAge", indexLabel.name());
    Assert.assertEquals(HugeType.VERTEX_LABEL, indexLabel.baseType());
    Assert.assertEquals("person", indexLabel.baseValue());
    Assert.assertEquals(IndexType.RANGE, indexLabel.indexType());
    List<String> fields = ImmutableList.of("age");
    Assert.assertTrue(fields.size() == indexLabel.indexFields().size());
    Assert.assertTrue(fields.containsAll(indexLabel.indexFields()));
}
Also used : IndexLabel(com.baidu.hugegraph.structure.schema.IndexLabel) Test(org.junit.Test)

Example 25 with IndexLabel

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

the class IndexLabelApiTest method testCreateRangeIndexOnNotNumberProperty.

@Test
public void testCreateRangeIndexOnNotNumberProperty() {
    IndexLabel indexLabel = schema().indexLabel("personByCity").onV("person").by("city").range().build();
    Utils.assertResponseError(400, () -> {
        indexLabelAPI.create(indexLabel);
    });
}
Also used : IndexLabel(com.baidu.hugegraph.structure.schema.IndexLabel) Test(org.junit.Test)

Aggregations

IndexLabel (com.baidu.hugegraph.structure.schema.IndexLabel)56 Test (org.junit.Test)34 HugeClient (com.baidu.hugegraph.driver.HugeClient)14 SchemaManager (com.baidu.hugegraph.driver.SchemaManager)11 ArrayList (java.util.ArrayList)10 ServerException (com.baidu.hugegraph.exception.ServerException)9 ExternalException (com.baidu.hugegraph.exception.ExternalException)8 Task (com.baidu.hugegraph.structure.Task)7 VertexLabel (com.baidu.hugegraph.structure.schema.VertexLabel)7 PropertyIndex (com.baidu.hugegraph.entity.schema.PropertyIndex)6 EdgeLabel (com.baidu.hugegraph.structure.schema.EdgeLabel)6 Date (java.util.Date)6 RestResult (com.baidu.hugegraph.rest.RestResult)4 HashSet (java.util.HashSet)4 SchemaType (com.baidu.hugegraph.entity.schema.SchemaType)2 PropertyKey (com.baidu.hugegraph.structure.schema.PropertyKey)2 TasksWithPage (com.baidu.hugegraph.api.task.TasksWithPage)1 Constant (com.baidu.hugegraph.common.Constant)1 ConflictDetail (com.baidu.hugegraph.entity.schema.ConflictDetail)1 ConflictStatus (com.baidu.hugegraph.entity.schema.ConflictStatus)1