use of com.baidu.hugegraph.structure.schema.IndexLabel in project incubator-hugegraph-toolchain by apache.
the class IndexLabelApiTest method testCreate.
@Test
public void testCreate() {
IndexLabel indexLabel = indexLabelAPI.create(fillIndexLabel.apply("personByAge")).indexLabel();
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()));
}
use of com.baidu.hugegraph.structure.schema.IndexLabel in project incubator-hugegraph-toolchain by apache.
the class IndexLabelApiTest method testAddIndexLabelWithUserData.
@Test
public void testAddIndexLabelWithUserData() {
IndexLabel personByAge = schema().indexLabel("personByAge").onV("person").by("age").range().userdata("min", 0).userdata("max", 100).build();
personByAge = indexLabelAPI.create(personByAge).indexLabel();
Assert.assertEquals(3, personByAge.userdata().size());
Assert.assertEquals(0, personByAge.userdata().get("min"));
Assert.assertEquals(100, personByAge.userdata().get("max"));
String time = (String) personByAge.userdata().get("~create_time");
Date createTime = DateUtil.parse(time);
Assert.assertTrue(createTime.before(DateUtil.now()));
IndexLabel personByCity = schema().indexLabel("personByCity").onV("person").by("city").secondary().userdata("length", 15).userdata("length", 18).build();
personByCity = indexLabelAPI.create(personByCity).indexLabel();
// The same key user data will be overwritten
Assert.assertEquals(2, personByCity.userdata().size());
Assert.assertEquals(18, personByCity.userdata().get("length"));
time = (String) personByCity.userdata().get("~create_time");
createTime = DateUtil.parse(time);
Assert.assertTrue(createTime.before(DateUtil.now()));
IndexLabel bookByName = schema().indexLabel("bookByName").onV("book").by("name").secondary().userdata("option", ImmutableList.of("xx", "yy")).build();
bookByName = indexLabelAPI.create(bookByName).indexLabel();
Assert.assertEquals(2, bookByName.userdata().size());
Assert.assertEquals(ImmutableList.of("xx", "yy"), bookByName.userdata().get("option"));
time = (String) bookByName.userdata().get("~create_time");
createTime = DateUtil.parse(time);
Assert.assertTrue(createTime.before(DateUtil.now()));
}
use of com.baidu.hugegraph.structure.schema.IndexLabel in project incubator-hugegraph-toolchain by apache.
the class IndexLabelApiTest method testAddIndexLabelWithUserDataWithApiVersion49.
@Test
public void testAddIndexLabelWithUserDataWithApiVersion49() {
VersionUtil.Version originApiVersion = client().apiVersion();
VersionUtil.Version apiVersion = VersionUtil.Version.of("0.49");
client().apiVersion(apiVersion);
IndexLabel personByAge = schema().indexLabel("personByAge").onV("person").by("age").range().build();
personByAge = indexLabelAPI.create(personByAge).indexLabel();
Assert.assertEquals(1, personByAge.userdata().size());
IndexLabel personByAge1 = schema().indexLabel("personByAge1").onV("person").by("age").range().userdata("min", 0).userdata("max", 100).build();
Assert.assertThrows(IllegalArgumentException.class, () -> {
indexLabelAPI.create(personByAge1).indexLabel();
}, (e) -> {
String msg = "Not support userdata of index label until api " + "version 0.50";
Assert.assertContains(msg, e.getMessage());
});
IndexLabel personByAge2 = schema().indexLabel("personByAge2").onV("person").by("age").userdata("min", 0).build();
Assert.assertThrows(NotSupportException.class, () -> {
indexLabelAPI.append(personByAge2);
}, (e) -> {
Assert.assertContains("action append on index label", e.getMessage());
});
IndexLabel personByAge3 = schema().indexLabel("personByAge3").onV("person").by("age").userdata("min", 0).build();
Assert.assertThrows(NotSupportException.class, () -> {
indexLabelAPI.eliminate(personByAge3);
}, (e) -> {
Assert.assertContains("action eliminate on index label", e.getMessage());
});
client().apiVersion(originApiVersion);
}
use of com.baidu.hugegraph.structure.schema.IndexLabel in project incubator-hugegraph-toolchain by apache.
the class PropertyIndexService method checkConflict.
public ConflictStatus checkConflict(PropertyIndex entity, int connId) {
HugeClient client = this.client(connId);
String name = entity.getName();
IndexLabel newIndexLabel = convert(entity, client);
IndexLabel oldIndexLabel = convert(this.get(name, connId), client);
if (oldIndexLabel == null) {
return ConflictStatus.PASSED;
} else if (isEqual(newIndexLabel, oldIndexLabel)) {
return ConflictStatus.EXISTED;
} else {
return ConflictStatus.DUPNAME;
}
}
use of com.baidu.hugegraph.structure.schema.IndexLabel in project incubator-hugegraph-toolchain by apache.
the class PropertyIndexService method list.
public List<PropertyIndex> list(Collection<String> names, int connId, boolean emptyAsAll) {
HugeClient client = this.client(connId);
List<IndexLabel> indexLabels;
if (CollectionUtils.isEmpty(names)) {
if (emptyAsAll) {
indexLabels = client.schema().getIndexLabels();
} else {
indexLabels = new ArrayList<>();
}
} else {
indexLabels = client.schema().getIndexLabels(new ArrayList<>(names));
}
List<PropertyIndex> results = new ArrayList<>(indexLabels.size());
indexLabels.forEach(indexLabel -> {
results.add(convert(indexLabel));
});
return results;
}
Aggregations