Search in sources :

Example 6 with TypeVertex

use of com.vaticle.typedb.core.graph.vertex.TypeVertex in project grakn by graknlabs.

the class TypeAdjacencyImpl method put.

@Override
public TypeEdge put(Encoding.Edge.Type encoding, TypeVertex adjacent) {
    assert !owner.isDeleted();
    TypeVertex from = isOut() ? owner : adjacent;
    TypeVertex to = isOut() ? adjacent : owner;
    TypeEdgeImpl edge = new TypeEdgeImpl.Buffered(encoding, from, to);
    edges.computeIfAbsent(encoding, e -> new ConcurrentSkipListSet<>()).add(getView(edge));
    if (isOut())
        ((TypeAdjacencyImpl<?>) to.ins()).putNonRecursive(edge);
    else
        ((TypeAdjacencyImpl<?>) from.outs()).putNonRecursive(edge);
    owner.setModified();
    return edge;
}
Also used : EdgeViewIID(com.vaticle.typedb.core.graph.iid.EdgeViewIID) ConcurrentSet(com.vaticle.typedb.common.collection.ConcurrentSet) KeyValue(com.vaticle.typedb.core.common.collection.KeyValue) TypeEdge(com.vaticle.typedb.core.graph.edge.TypeEdge) Predicate(java.util.function.Predicate) Order(com.vaticle.typedb.core.common.iterator.sorted.SortedIterator.Order) InfixIID(com.vaticle.typedb.core.graph.iid.InfixIID) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Forwardable(com.vaticle.typedb.core.common.iterator.sorted.SortedIterator.Forwardable) ASC(com.vaticle.typedb.core.common.iterator.sorted.SortedIterator.ASC) Forwardable.iterateSorted(com.vaticle.typedb.core.common.iterator.sorted.SortedIterators.Forwardable.iterateSorted) InEdgeIteratorImpl(com.vaticle.typedb.core.graph.adjacency.impl.TypeEdgeIterator.InEdgeIteratorImpl) ConcurrentMap(java.util.concurrent.ConcurrentMap) OutEdgeIteratorImpl(com.vaticle.typedb.core.graph.adjacency.impl.TypeEdgeIterator.OutEdgeIteratorImpl) Forwardable.emptySorted(com.vaticle.typedb.core.common.iterator.sorted.SortedIterators.Forwardable.emptySorted) ConcurrentSkipListSet(java.util.concurrent.ConcurrentSkipListSet) VertexIID(com.vaticle.typedb.core.graph.iid.VertexIID) TypeAdjacency(com.vaticle.typedb.core.graph.adjacency.TypeAdjacency) Optional(java.util.Optional) TypeEdgeImpl(com.vaticle.typedb.core.graph.edge.impl.TypeEdgeImpl) Key(com.vaticle.typedb.core.graph.common.Storage.Key) TypeVertex(com.vaticle.typedb.core.graph.vertex.TypeVertex) ByteArray(com.vaticle.typedb.core.common.collection.ByteArray) Encoding(com.vaticle.typedb.core.graph.common.Encoding) ConcurrentSkipListSet(java.util.concurrent.ConcurrentSkipListSet) TypeVertex(com.vaticle.typedb.core.graph.vertex.TypeVertex) TypeEdgeImpl(com.vaticle.typedb.core.graph.edge.impl.TypeEdgeImpl)

Example 7 with TypeVertex

use of com.vaticle.typedb.core.graph.vertex.TypeVertex 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 8 with TypeVertex

use of com.vaticle.typedb.core.graph.vertex.TypeVertex in project grakn by graknlabs.

the class EncodingTest method expectedAttributeIID.

private ByteArray expectedAttributeIID(GraphManager graphMgr, Label attributeTypeLabel, long attributeValue) {
    TypeVertex type = graphMgr.schema().getType(attributeTypeLabel);
    assertTrue(type.isAttributeType());
    return ByteArray.join(ATTRIBUTE.prefix().bytes(), type.iid().bytes(), Encoding.ValueType.LONG.bytes(), encodeLongAsSorted(attributeValue));
}
Also used : TypeVertex(com.vaticle.typedb.core.graph.vertex.TypeVertex)

Example 9 with TypeVertex

use of com.vaticle.typedb.core.graph.vertex.TypeVertex in project grakn by graknlabs.

the class EncodingTest method expectedAttributeIID.

private ByteArray expectedAttributeIID(GraphManager graphMgr, Label attributeTypeLabel, String attributeValue) {
    TypeVertex type = graphMgr.schema().getType(attributeTypeLabel);
    assertTrue(type.isAttributeType());
    try {
        return ByteArray.join(ATTRIBUTE.prefix().bytes(), type.iid().bytes(), Encoding.ValueType.STRING.bytes(), encodeStringAsSorted(attributeValue, STRING_ENCODING));
    } catch (TypeDBCheckedException e) {
        throw TypeDBException.of(e);
    }
}
Also used : TypeDBCheckedException(com.vaticle.typedb.core.common.exception.TypeDBCheckedException) TypeVertex(com.vaticle.typedb.core.graph.vertex.TypeVertex)

Example 10 with TypeVertex

use of com.vaticle.typedb.core.graph.vertex.TypeVertex in project grakn by graknlabs.

the class RelationTypeImpl method getRelates.

/**
 * Get the role type with a given {@code roleLabel} related by this relation type.
 *
 * First, look up the role type by the given label and it's scope: the relation label.
 * If the role type vertex do not exist, then call {@code role()} to get the inherited role types,
 * and see if the any of them has the {@code roleLabel} of interest.
 *
 * @param roleLabel the label of the role
 * @return the role type related in this relation
 */
@Override
public RoleTypeImpl getRelates(String roleLabel) {
    Optional<RoleTypeImpl> roleType;
    TypeVertex roleTypeVertex = graphMgr.schema().getType(roleLabel, vertex.label());
    if (roleTypeVertex != null) {
        return RoleTypeImpl.of(graphMgr, roleTypeVertex);
    } else if ((roleType = getRelates().filter(role -> role.getLabel().name().equals(roleLabel)).first()).isPresent()) {
        return roleType.get();
    } else
        return null;
}
Also used : TYPE_ROOT_MISMATCH(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeRead.TYPE_ROOT_MISMATCH) TypeEdge(com.vaticle.typedb.core.graph.edge.TypeEdge) RELATION_RELATES_ROLE_FROM_SUPERTYPE(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.RELATION_RELATES_ROLE_FROM_SUPERTYPE) Order(com.vaticle.typedb.core.common.iterator.sorted.SortedIterator.Order) RelationImpl(com.vaticle.typedb.core.concept.thing.impl.RelationImpl) RelationType(com.vaticle.typedb.core.concept.type.RelationType) ASC(com.vaticle.typedb.core.common.iterator.sorted.SortedIterator.ASC) Forwardable.iterateSorted(com.vaticle.typedb.core.common.iterator.sorted.SortedIterators.Forwardable.iterateSorted) RELATION_NO_ROLE(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.RELATION_NO_ROLE) RELATION_ABSTRACT_ROLE(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.RELATION_ABSTRACT_ROLE) RELATES(com.vaticle.typedb.core.graph.common.Encoding.Edge.Type.RELATES) RELATION(com.vaticle.typedb.core.graph.common.Encoding.Vertex.Type.Root.RELATION) ROLE(com.vaticle.typedb.core.graph.common.Encoding.Vertex.Type.Root.ROLE) RELATION_RELATES_ROLE_NOT_AVAILABLE(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.RELATION_RELATES_ROLE_NOT_AVAILABLE) RELATION_TYPE(com.vaticle.typedb.core.graph.common.Encoding.Vertex.Type.RELATION_TYPE) GraphManager(com.vaticle.typedb.core.graph.GraphManager) FunctionalIterator(com.vaticle.typedb.core.common.iterator.FunctionalIterator) Forwardable(com.vaticle.typedb.core.common.iterator.sorted.SortedIterator.Forwardable) RoleType(com.vaticle.typedb.core.concept.type.RoleType) ThingVertex(com.vaticle.typedb.core.graph.vertex.ThingVertex) Objects(java.util.Objects) List(java.util.List) Relation(com.vaticle.typedb.core.concept.thing.Relation) ROOT_TYPE_MUTATION(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.ROOT_TYPE_MUTATION) Optional(java.util.Optional) TypeDBException(com.vaticle.typedb.core.common.exception.TypeDBException) AttributeType(com.vaticle.typedb.core.concept.type.AttributeType) TypeVertex(com.vaticle.typedb.core.graph.vertex.TypeVertex) 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) TypeVertex(com.vaticle.typedb.core.graph.vertex.TypeVertex)

Aggregations

TypeVertex (com.vaticle.typedb.core.graph.vertex.TypeVertex)15 TypeDBException (com.vaticle.typedb.core.common.exception.TypeDBException)7 ASC (com.vaticle.typedb.core.common.iterator.sorted.SortedIterator.ASC)7 Forwardable (com.vaticle.typedb.core.common.iterator.sorted.SortedIterator.Forwardable)7 Order (com.vaticle.typedb.core.common.iterator.sorted.SortedIterator.Order)7 TypeEdge (com.vaticle.typedb.core.graph.edge.TypeEdge)7 FunctionalIterator (com.vaticle.typedb.core.common.iterator.FunctionalIterator)6 Forwardable.iterateSorted (com.vaticle.typedb.core.common.iterator.sorted.SortedIterators.Forwardable.iterateSorted)6 List (java.util.List)6 GraphManager (com.vaticle.typedb.core.graph.GraphManager)5 ThingVertex (com.vaticle.typedb.core.graph.vertex.ThingVertex)5 Objects (java.util.Objects)5 KeyValue (com.vaticle.typedb.core.common.collection.KeyValue)4 Encoding (com.vaticle.typedb.core.graph.common.Encoding)4 ByteArray (com.vaticle.typedb.core.common.collection.ByteArray)3 ROOT_TYPE_MUTATION (com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.ROOT_TYPE_MUTATION)3 TYPE_HAS_INSTANCES_SET_ABSTRACT (com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.TYPE_HAS_INSTANCES_SET_ABSTRACT)3 Iterators.iterate (com.vaticle.typedb.core.common.iterator.Iterators.iterate)3 Label (com.vaticle.typedb.core.common.parameters.Label)3 RelationImpl (com.vaticle.typedb.core.concept.thing.impl.RelationImpl)3