Search in sources :

Example 16 with IndexLabel

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

the class IndexLabelAPI method create.

public IndexLabel.IndexLabelWithTask create(IndexLabel indexLabel) {
    Object il = this.checkCreateOrUpdate(indexLabel);
    RestResult result = this.client.post(this.path(), il);
    return result.readObject(IndexLabel.IndexLabelWithTask.class);
}
Also used : RestResult(com.baidu.hugegraph.rest.RestResult) IndexLabel(com.baidu.hugegraph.structure.schema.IndexLabel)

Example 17 with IndexLabel

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

the class RestResultTest method testReadIndexLabel.

@Test
public void testReadIndexLabel() {
    String json = "{" + "\"id\": \"4\"," + "\"index_type\": \"SEARCH\"," + "\"base_value\": \"software\"," + "\"name\": \"softwareByPrice\"," + "\"fields\": [\"price\"]," + "\"base_type\": \"VERTEX_LABEL\"" + "}";
    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());
    IndexLabel indexLabel = result.readObject(IndexLabel.class);
    Assert.assertEquals("softwareByPrice", indexLabel.name());
    Assert.assertEquals(HugeType.VERTEX_LABEL, indexLabel.baseType());
    Assert.assertEquals("software", indexLabel.baseValue());
    Assert.assertEquals(IndexType.SEARCH, indexLabel.indexType());
    Assert.assertEquals(ImmutableList.of("price"), indexLabel.indexFields());
}
Also used : RestResult(com.baidu.hugegraph.rest.RestResult) IndexLabel(com.baidu.hugegraph.structure.schema.IndexLabel) Test(org.junit.Test)

Example 18 with IndexLabel

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

the class IndexLabelTest method testAppendIndexLabelWithUserData.

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

Example 19 with IndexLabel

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

the class IndexLabelTest method testAddIndexLabelAsync.

@Test
public void testAddIndexLabelAsync() {
    SchemaManager schema = schema();
    schema.vertexLabel("player").properties("name", "age").create();
    IndexLabel playerByName = schema.indexLabel("playerByName").onV("player").by("name").secondary().build();
    long task = schema.addIndexLabelAsync(playerByName);
    waitUntilTaskCompleted(task);
    playerByName = schema.getIndexLabel(playerByName.name());
    Assert.assertNotNull(playerByName);
}
Also used : IndexLabel(com.baidu.hugegraph.structure.schema.IndexLabel) SchemaManager(com.baidu.hugegraph.driver.SchemaManager) Test(org.junit.Test)

Example 20 with IndexLabel

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

the class IndexLabelTest method testEliminateIndexLabelWithUserData.

@Test
public void testEliminateIndexLabelWithUserData() {
    SchemaManager schema = schema();
    BaseFuncTest.initVertexLabel();
    IndexLabel personByCity = schema.indexLabel("personByCity").onV("person").by("city").secondary().userdata("type", "secondary").userdata("icon", "picture").ifNotExist().create();
    Assert.assertEquals(3, personByCity.userdata().size());
    Assert.assertEquals("secondary", personByCity.userdata().get("type"));
    Assert.assertEquals("picture", personByCity.userdata().get("icon"));
    String time = (String) personByCity.userdata().get("~create_time");
    Date createTime = DateUtil.parse(time);
    Assert.assertTrue(createTime.before(DateUtil.now()));
    personByCity = schema.indexLabel("personByCity").userdata("type", "secondary").eliminate();
    Assert.assertEquals(2, personByCity.userdata().size());
    Assert.assertEquals("picture", personByCity.userdata().get("icon"));
    time = (String) personByCity.userdata().get("~create_time");
    Assert.assertEquals(createTime, DateUtil.parse(time));
}
Also used : IndexLabel(com.baidu.hugegraph.structure.schema.IndexLabel) SchemaManager(com.baidu.hugegraph.driver.SchemaManager) Date(java.util.Date) 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