use of com.vaticle.typedb.core.common.iterator.sorted.SortedIterator.ASC in project grakn by graknlabs.
the class RocksIteratorTest method attributesRetrievedAscending.
@Test
public void attributesRetrievedAscending() {
List<String> strings = new ArrayList<>();
for (int i = 0; i < 10_000; i++) {
strings.add(UUID.randomUUID().toString());
}
try (TypeDB.Transaction transaction = session.transaction(WRITE)) {
AttributeType.String stringValueType = transaction.concepts().getAttributeType("string-value").asString();
for (String string : strings) {
stringValueType.put(string);
}
transaction.commit();
}
// test ascending order
strings.sort(Comparator.naturalOrder());
try (CoreTransaction transaction = session.transaction(READ)) {
Storage.Data storage = transaction.graphMgr.data().storage();
AttributeType.String stringValueType = transaction.concepts().getAttributeType("string-value").asString();
VertexIID.Type iid = ((AttributeTypeImpl) stringValueType).vertex.iid();
Storage.Key.Prefix<VertexIID.Thing> iteratePrefix = VertexIID.Thing.Attribute.String.prefix(iid);
List<String> values = storage.iterate(iteratePrefix, ASC).map(kv -> kv.key().asAttribute().asString().value()).toList();
assertEquals(strings, values);
}
// test descending order
strings.sort(Comparator.reverseOrder());
try (CoreTransaction transaction = session.transaction(READ)) {
Storage.Data storage = transaction.graphMgr.data().storage();
AttributeType.String stringValueType = transaction.concepts().getAttributeType("string-value").asString();
VertexIID.Type iid = ((AttributeTypeImpl) stringValueType).vertex.iid();
Storage.Key.Prefix<VertexIID.Thing> iteratePrefix = VertexIID.Thing.Attribute.String.prefix(iid);
List<String> values = storage.iterate(iteratePrefix, DESC).map(kv -> kv.key().asAttribute().asString().value()).toList();
assertEquals(strings, values);
}
}
use of com.vaticle.typedb.core.common.iterator.sorted.SortedIterator.ASC in project grakn by graknlabs.
the class RelationIterator method createIterator.
private Forwardable<ThingVertex, Order.Asc> createIterator(int pos) {
StructureEdge<?, ?> edge = edges.get(pos);
ThingVertex player = answer.get(edge.to().id().asVariable().asRetrievable()).asThing();
return SortedIterators.Forwardable.merge(iterate(edge.asNative().asRolePlayer().types()).map(roleLabel -> {
TypeVertex roleVertex = graphMgr.schema().getType(roleLabel);
return player.ins().edge(ROLEPLAYER, roleVertex).fromAndOptimised().filter(relRole -> relationTypes.contains(relRole.key().type().properLabel()));
}), ASC).filter(relRole -> !scoped.contains(relRole.value())).mapSorted(relRole -> {
scoped.record(pos, relRole.value());
return relRole.key();
}, relation -> new KeyValue<>(relation, null), ASC);
}
use of com.vaticle.typedb.core.common.iterator.sorted.SortedIterator.ASC in project grakn by graknlabs.
the class ThingTypeImpl method ownsAttribute.
private void ownsAttribute(AttributeTypeImpl attributeType) {
validateIsNotDeleted();
Forwardable<AttributeType, Order.Asc> owns = getSupertypes().filter(t -> !t.equals(this)).mergeMap(ThingType::getOwns, ASC);
if (owns.findFirst(attributeType).isPresent()) {
throw exception(TypeDBException.of(OWNS_ATT_NOT_AVAILABLE, attributeType.getLabel()));
}
TypeVertex attVertex = attributeType.vertex;
TypeEdge keyEdge;
if ((keyEdge = vertex.outs().edge(OWNS_KEY, attVertex)) != null)
keyEdge.delete();
vertex.outs().put(OWNS, attVertex);
}
Aggregations