use of com.baidu.hugegraph.structure.schema.IndexLabel in project incubator-hugegraph-toolchain by apache.
the class TaskApiTest method testListAll.
@Test
public void testListAll() {
IndexLabel personByCity = schema().getIndexLabel("personByCity");
IndexLabel personByAge = schema().getIndexLabel("personByAge");
IndexLabel knowsByDate = schema().getIndexLabel("knowsByDate");
IndexLabel createdByDate = schema().getIndexLabel("createdByDate");
Set<Long> taskIds = new HashSet<>();
taskIds.add(rebuildAPI.rebuild(personByCity));
taskIds.add(rebuildAPI.rebuild(personByAge));
taskIds.add(rebuildAPI.rebuild(knowsByDate));
taskIds.add(rebuildAPI.rebuild(createdByDate));
List<Task> tasks = taskAPI.list(null, -1);
Assert.assertEquals(4, tasks.size());
Set<Long> listedTaskIds = new HashSet<>();
for (Task task : tasks) {
listedTaskIds.add(task.id());
}
Assert.assertEquals(taskIds.size(), listedTaskIds.size());
Assert.assertTrue(taskIds.containsAll(listedTaskIds));
taskIds.forEach(BaseApiTest::waitUntilTaskCompleted);
taskIds.forEach(id -> taskAPI.delete(id));
tasks = taskAPI.list(null, -1);
Assert.assertEquals(0, tasks.size());
}
use of com.baidu.hugegraph.structure.schema.IndexLabel in project incubator-hugegraph-toolchain by apache.
the class IndexLabelApiTest method testAddIndexLabelWithRebuildFalse.
@Test
public void testAddIndexLabelWithRebuildFalse() {
Vertex vertex = new Vertex("person");
vertex.property("name", "James");
vertex.property("city", "Beijing");
vertex.property("age", 19);
vertex = vertexAPI.create(vertex);
IndexLabel personByAge = schema().indexLabel("personByAge").onV("person").by("city").secondary().rebuild(false).build();
IndexLabel.IndexLabelWithTask il = indexLabelAPI.create(personByAge);
IndexLabel created = il.indexLabel();
Assert.assertEquals(personByAge.name(), created.name());
Assert.assertEquals(personByAge.baseType(), created.baseType());
Assert.assertEquals(personByAge.baseValue(), created.baseValue());
Assert.assertEquals(personByAge.indexType(), created.indexType());
Assert.assertEquals(Task.TASK_ID_NULL, il.taskId());
Map<String, Object> properties = ImmutableMap.of("city", "Beijing");
List<Vertex> vertices = vertexAPI.list("person", properties, 0, null, 10).results();
Assert.assertEquals(0, vertices.size());
long taskId = rebuildAPI.rebuild(personByAge);
waitUntilTaskCompleted(taskId);
vertices = vertexAPI.list("person", properties, 0, null, 10).results();
Assert.assertEquals(1, vertices.size());
Assert.assertEquals(vertex, vertices.get(0));
}
use of com.baidu.hugegraph.structure.schema.IndexLabel in project incubator-hugegraph-toolchain by apache.
the class IndexLabelApiTest method testGet.
@Test
public void testGet() {
IndexLabel indexLabel1 = schema().indexLabel("personByAge").onV("person").by("age").range().build();
indexLabel1 = indexLabelAPI.create(indexLabel1).indexLabel();
IndexLabel indexLabel2 = indexLabelAPI.get("personByAge");
Assert.assertEquals(indexLabel1.name(), indexLabel2.name());
Assert.assertEquals(indexLabel1.baseType(), indexLabel2.baseType());
Assert.assertEquals(indexLabel1.baseValue(), indexLabel2.baseValue());
Assert.assertEquals(indexLabel1.indexType(), indexLabel2.indexType());
Assert.assertEquals(indexLabel1.indexFields(), indexLabel2.indexFields());
}
use of com.baidu.hugegraph.structure.schema.IndexLabel in project incubator-hugegraph-toolchain by apache.
the class JobApiTest method testRebuildIndexLabel.
@Test
public void testRebuildIndexLabel() {
IndexLabel personByCity = schema().getIndexLabel("personByAge");
long taskId = rebuildAPI.rebuild(personByCity);
Task task = taskAPI.get(taskId);
Assert.assertNotNull(task);
Assert.assertEquals(taskId, task.id());
waitUntilTaskCompleted(taskId);
}
use of com.baidu.hugegraph.structure.schema.IndexLabel in project incubator-hugegraph-toolchain by apache.
the class IndexLabelAPI method checkCreateOrUpdate.
@Override
protected Object checkCreateOrUpdate(SchemaElement schemaElement) {
IndexLabel indexLabel = (IndexLabel) schemaElement;
if (indexLabel.indexType() == IndexType.SHARD) {
this.client.checkApiVersion("0.43", "shard index");
} else if (indexLabel.indexType() == IndexType.UNIQUE) {
this.client.checkApiVersion("0.44", "unique index");
}
IndexLabel il = indexLabel;
if (this.client.apiVersionLt("0.50")) {
E.checkArgument(indexLabel.userdata() == null || indexLabel.userdata().isEmpty(), "Not support userdata of index label until api " + "version 0.50");
E.checkArgument(indexLabel.rebuild(), "Not support rebuild of index label until api " + "version 0.57");
il = indexLabel.switchV49();
} else if (this.client.apiVersionLt("0.57")) {
E.checkArgument(indexLabel.rebuild(), "Not support rebuild of index label until api " + "version 0.57");
il = indexLabel.switchV56();
}
return il;
}
Aggregations