Search in sources :

Example 1 with Forwardable

use of com.vaticle.typedb.core.common.iterator.sorted.SortedIterator.Forwardable in project grakn by graknlabs.

the class GraphIterator method computeNext.

private boolean computeNext(int pos) {
    if (pos == 0)
        return false;
    ProcedureEdge<?, ?> edge = procedure.edge(pos);
    Identifier toID = edge.to().id();
    if (pos == computeNextSeekPos) {
        computeNextSeekPos = edgeCount;
    } else if (pos > computeNextSeekPos) {
        if (!edge.isClosureEdge())
            iterators.get(toID).recycle();
        if (!backTrack(pos))
            return false;
        if (edge.isClosureEdge()) {
            Vertex<?, ?> fromVertex = answer.get(edge.from().id());
            Vertex<?, ?> toVertex = answer.get(edge.to().id());
            if (isClosure(edge, fromVertex, toVertex))
                return true;
            else
                return computeNextClosure(pos);
        } else {
            Forwardable<? extends Vertex<?, ?>, Order.Asc> toIter = branch(answer.get(edge.from().id()), edge);
            iterators.put(toID, toIter);
        }
    }
    if (edge.isClosureEdge()) {
        return computeNextClosure(pos);
    } else if (iterators.get(toID).hasNext()) {
        answer.put(toID, iterators.get(toID).next());
        return true;
    } else {
        return computeNextBranch(pos);
    }
}
Also used : Order(com.vaticle.typedb.core.common.iterator.sorted.SortedIterator.Order) Vertex(com.vaticle.typedb.core.graph.vertex.Vertex) ThingVertex(com.vaticle.typedb.core.graph.vertex.ThingVertex) Identifier(com.vaticle.typedb.core.traversal.common.Identifier) Forwardable(com.vaticle.typedb.core.common.iterator.sorted.SortedIterator.Forwardable)

Example 2 with Forwardable

use of com.vaticle.typedb.core.common.iterator.sorted.SortedIterator.Forwardable 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);
}
Also used : ILLEGAL_STATE(com.vaticle.typedb.core.common.exception.ErrorMessage.Internal.ILLEGAL_STATE) KeyValue(com.vaticle.typedb.core.common.collection.KeyValue) Identifier(com.vaticle.typedb.core.traversal.common.Identifier) Order(com.vaticle.typedb.core.common.iterator.sorted.SortedIterator.Order) StructureEdge(com.vaticle.typedb.core.traversal.structure.StructureEdge) HashMap(java.util.HashMap) ASC(com.vaticle.typedb.core.common.iterator.sorted.SortedIterator.ASC) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Map(java.util.Map) AbstractFunctionalIterator(com.vaticle.typedb.core.common.iterator.AbstractFunctionalIterator) NoSuchElementException(java.util.NoSuchElementException) Label(com.vaticle.typedb.core.common.parameters.Label) GraphManager(com.vaticle.typedb.core.graph.GraphManager) RelationTraversal(com.vaticle.typedb.core.traversal.RelationTraversal) VertexMap(com.vaticle.typedb.core.traversal.common.VertexMap) FunctionalIterator(com.vaticle.typedb.core.common.iterator.FunctionalIterator) Iterator(java.util.Iterator) Set(java.util.Set) SortedIterators(com.vaticle.typedb.core.common.iterator.sorted.SortedIterators) Vertex(com.vaticle.typedb.core.graph.vertex.Vertex) Forwardable(com.vaticle.typedb.core.common.iterator.sorted.SortedIterator.Forwardable) ThingVertex(com.vaticle.typedb.core.graph.vertex.ThingVertex) List(java.util.List) Retrievable(com.vaticle.typedb.core.traversal.common.Identifier.Variable.Retrievable) ROLEPLAYER(com.vaticle.typedb.core.graph.common.Encoding.Edge.Thing.Optimised.ROLEPLAYER) Iterators.iterate(com.vaticle.typedb.core.common.iterator.Iterators.iterate) TypeDBException(com.vaticle.typedb.core.common.exception.TypeDBException) TypeVertex(com.vaticle.typedb.core.graph.vertex.TypeVertex) ThingVertex(com.vaticle.typedb.core.graph.vertex.ThingVertex) TypeVertex(com.vaticle.typedb.core.graph.vertex.TypeVertex)

Example 3 with Forwardable

use of com.vaticle.typedb.core.common.iterator.sorted.SortedIterator.Forwardable 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);
}
Also used : TypeEdge(com.vaticle.typedb.core.graph.edge.TypeEdge) INVALID_UNDEFINE_NONEXISTENT_OWNS(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.INVALID_UNDEFINE_NONEXISTENT_OWNS) RelationImpl(com.vaticle.typedb.core.concept.thing.impl.RelationImpl) ASC(com.vaticle.typedb.core.common.iterator.sorted.SortedIterator.ASC) ThingType(com.vaticle.typedb.core.concept.type.ThingType) Iterators.loop(com.vaticle.typedb.core.common.iterator.Iterators.loop) OWNS_KEY_PRECONDITION_UNIQUENESS(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.OWNS_KEY_PRECONDITION_UNIQUENESS) FunctionalIterator(com.vaticle.typedb.core.common.iterator.FunctionalIterator) OWNS_KEY_PRECONDITION_NO_INSTANCES(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.OWNS_KEY_PRECONDITION_NO_INSTANCES) OWNS_KEY_VALUE_TYPE(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.OWNS_KEY_VALUE_TYPE) SUB(com.vaticle.typedb.core.graph.common.Encoding.Edge.Type.SUB) EntityImpl(com.vaticle.typedb.core.concept.thing.impl.EntityImpl) INVALID_UNDEFINE_NONEXISTENT_PLAYS(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.INVALID_UNDEFINE_NONEXISTENT_PLAYS) Forwardable(com.vaticle.typedb.core.common.iterator.sorted.SortedIterator.Forwardable) INVALID_UNDEFINE_PLAYS_HAS_INSTANCES(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.INVALID_UNDEFINE_PLAYS_HAS_INSTANCES) ThingVertex(com.vaticle.typedb.core.graph.vertex.ThingVertex) Objects(java.util.Objects) List(java.util.List) ThingImpl(com.vaticle.typedb.core.concept.thing.impl.ThingImpl) TypeDBException(com.vaticle.typedb.core.common.exception.TypeDBException) PLAYS_ROLE_NOT_AVAILABLE(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.PLAYS_ROLE_NOT_AVAILABLE) OVERRIDDEN_NOT_SUPERTYPE(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.OVERRIDDEN_NOT_SUPERTYPE) Iterators.link(com.vaticle.typedb.core.common.iterator.Iterators.link) INVALID_UNDEFINE_INHERITED_OWNS(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.INVALID_UNDEFINE_INHERITED_OWNS) Order(com.vaticle.typedb.core.common.iterator.sorted.SortedIterator.Order) Function(java.util.function.Function) Forwardable.iterateSorted(com.vaticle.typedb.core.common.iterator.sorted.SortedIterators.Forwardable.iterateSorted) INVALID_UNDEFINE_OWNS_HAS_INSTANCES(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.INVALID_UNDEFINE_OWNS_HAS_INSTANCES) OWNS_ABSTRACT_ATT_TYPE(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.OWNS_ABSTRACT_ATT_TYPE) Forwardable.emptySorted(com.vaticle.typedb.core.common.iterator.sorted.SortedIterators.Forwardable.emptySorted) OWNS_ATT_NOT_AVAILABLE(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.OWNS_ATT_NOT_AVAILABLE) OWS_KEY_PRECONDITION_OWNERSHIP_KEY_TOO_MANY(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.OWS_KEY_PRECONDITION_OWNERSHIP_KEY_TOO_MANY) TYPE_HAS_SUBTYPES(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.TYPE_HAS_SUBTYPES) INVALID_UNDEFINE_INHERITED_PLAYS(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.INVALID_UNDEFINE_INHERITED_PLAYS) TYPE_HAS_INSTANCES_DELETE(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.TYPE_HAS_INSTANCES_DELETE) Encoding(com.vaticle.typedb.core.graph.common.Encoding) Nullable(javax.annotation.Nullable) PLAYS(com.vaticle.typedb.core.graph.common.Encoding.Edge.Type.PLAYS) GraphManager(com.vaticle.typedb.core.graph.GraphManager) UNRECOGNISED_VALUE(com.vaticle.typedb.core.common.exception.ErrorMessage.Internal.UNRECOGNISED_VALUE) OWS_KEY_PRECONDITION_OWNERSHIP_KEY_MISSING(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.OWS_KEY_PRECONDITION_OWNERSHIP_KEY_MISSING) Iterators(com.vaticle.typedb.core.common.iterator.Iterators) OWNS_KEY(com.vaticle.typedb.core.graph.common.Encoding.Edge.Type.OWNS_KEY) AttributeImpl(com.vaticle.typedb.core.concept.thing.impl.AttributeImpl) RoleType(com.vaticle.typedb.core.concept.type.RoleType) OWNS_KEY_NOT_AVAILABLE(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.OWNS_KEY_NOT_AVAILABLE) Attribute(com.vaticle.typedb.core.concept.thing.Attribute) Iterators.compareSize(com.vaticle.typedb.core.common.iterator.Iterators.compareSize) PLAYS_ABSTRACT_ROLE_TYPE(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.PLAYS_ABSTRACT_ROLE_TYPE) ROOT_TYPE_MUTATION(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.ROOT_TYPE_MUTATION) OWNS(com.vaticle.typedb.core.graph.common.Encoding.Edge.Type.OWNS) AttributeType(com.vaticle.typedb.core.concept.type.AttributeType) TypeVertex(com.vaticle.typedb.core.graph.vertex.TypeVertex) Collections(java.util.Collections) TYPE_HAS_INSTANCES_SET_ABSTRACT(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.TYPE_HAS_INSTANCES_SET_ABSTRACT) Type(com.vaticle.typedb.core.concept.type.Type) OVERRIDE_NOT_AVAILABLE(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.OVERRIDE_NOT_AVAILABLE) TypeEdge(com.vaticle.typedb.core.graph.edge.TypeEdge) AttributeType(com.vaticle.typedb.core.concept.type.AttributeType) ThingType(com.vaticle.typedb.core.concept.type.ThingType) TypeVertex(com.vaticle.typedb.core.graph.vertex.TypeVertex)

Aggregations

Forwardable (com.vaticle.typedb.core.common.iterator.sorted.SortedIterator.Forwardable)3 Order (com.vaticle.typedb.core.common.iterator.sorted.SortedIterator.Order)3 TypeDBException (com.vaticle.typedb.core.common.exception.TypeDBException)2 FunctionalIterator (com.vaticle.typedb.core.common.iterator.FunctionalIterator)2 ASC (com.vaticle.typedb.core.common.iterator.sorted.SortedIterator.ASC)2 ThingVertex (com.vaticle.typedb.core.graph.vertex.ThingVertex)2 Vertex (com.vaticle.typedb.core.graph.vertex.Vertex)2 Identifier (com.vaticle.typedb.core.traversal.common.Identifier)2 KeyValue (com.vaticle.typedb.core.common.collection.KeyValue)1 ILLEGAL_STATE (com.vaticle.typedb.core.common.exception.ErrorMessage.Internal.ILLEGAL_STATE)1 UNRECOGNISED_VALUE (com.vaticle.typedb.core.common.exception.ErrorMessage.Internal.UNRECOGNISED_VALUE)1 INVALID_UNDEFINE_INHERITED_OWNS (com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.INVALID_UNDEFINE_INHERITED_OWNS)1 INVALID_UNDEFINE_INHERITED_PLAYS (com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.INVALID_UNDEFINE_INHERITED_PLAYS)1 INVALID_UNDEFINE_NONEXISTENT_OWNS (com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.INVALID_UNDEFINE_NONEXISTENT_OWNS)1 INVALID_UNDEFINE_NONEXISTENT_PLAYS (com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.INVALID_UNDEFINE_NONEXISTENT_PLAYS)1 INVALID_UNDEFINE_OWNS_HAS_INSTANCES (com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.INVALID_UNDEFINE_OWNS_HAS_INSTANCES)1 INVALID_UNDEFINE_PLAYS_HAS_INSTANCES (com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.INVALID_UNDEFINE_PLAYS_HAS_INSTANCES)1 OVERRIDDEN_NOT_SUPERTYPE (com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.OVERRIDDEN_NOT_SUPERTYPE)1 OVERRIDE_NOT_AVAILABLE (com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.OVERRIDE_NOT_AVAILABLE)1 OWNS_ABSTRACT_ATT_TYPE (com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.OWNS_ABSTRACT_ATT_TYPE)1