Search in sources :

Example 1 with Label

use of com.vaticle.typedb.core.common.parameters.Label in project grakn by graknlabs.

the class TypeGraph method getType.

public TypeVertex getType(String label, @Nullable String scope) {
    assert storage.isOpen();
    String scopedLabel = scopedLabel(label, scope);
    try {
        if (!isReadOnly) {
            multiLabelLock.readLock().lock();
            singleLabelLocks.computeIfAbsent(scopedLabel, x -> newReadWriteLock()).readLock().lock();
        }
        TypeVertex vertex = typesByLabel.get(scopedLabel);
        if (vertex != null)
            return vertex;
        IndexIID.Type index = IndexIID.Type.Label.of(label, scope);
        ByteArray iid = storage.get(index);
        if (iid != null) {
            vertex = typesByIID.computeIfAbsent(VertexIID.Type.of(iid), i -> new TypeVertexImpl.Persisted(this, i, label, scope));
            typesByLabel.putIfAbsent(scopedLabel, vertex);
        }
        return vertex;
    } finally {
        if (!isReadOnly) {
            singleLabelLocks.get(scopedLabel).readLock().unlock();
            multiLabelLock.readLock().unlock();
        }
    }
}
Also used : Pair(com.vaticle.typedb.common.collection.Pair) RuleStructureImpl(com.vaticle.typedb.core.graph.structure.impl.RuleStructureImpl) ENTITY(com.vaticle.typedb.core.graph.common.Encoding.Vertex.Type.Root.ENTITY) KeyGenerator(com.vaticle.typedb.core.graph.common.KeyGenerator) ASC(com.vaticle.typedb.core.common.iterator.sorted.SortedIterator.ASC) VertexIID(com.vaticle.typedb.core.graph.iid.VertexIID) RELATES(com.vaticle.typedb.core.graph.common.Encoding.Edge.Type.RELATES) RELATION(com.vaticle.typedb.core.graph.common.Encoding.Vertex.Type.Root.RELATION) Map(java.util.Map) TYPE_NOT_FOUND(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeRead.TYPE_NOT_FOUND) RELATION_TYPE(com.vaticle.typedb.core.graph.common.Encoding.Vertex.Type.RELATION_TYPE) ATTRIBUTE(com.vaticle.typedb.core.graph.common.Encoding.Vertex.Type.Root.ATTRIBUTE) IndexIID(com.vaticle.typedb.core.graph.iid.IndexIID) Iterators.loop(com.vaticle.typedb.core.common.iterator.Iterators.loop) ByteArray(com.vaticle.typedb.core.common.collection.ByteArray) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) FunctionalIterator(com.vaticle.typedb.core.common.iterator.FunctionalIterator) INVALID_SCHEMA_WRITE(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeGraph.INVALID_SCHEMA_WRITE) OBJECT(com.vaticle.typedb.core.graph.common.Encoding.ValueType.OBJECT) SUB(com.vaticle.typedb.core.graph.common.Encoding.Edge.Type.SUB) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) NavigableSet(java.util.NavigableSet) Pattern(com.vaticle.typeql.lang.pattern.Pattern) Forwardable(com.vaticle.typedb.core.common.iterator.sorted.SortedIterator.Forwardable) ENTITY_TYPE(com.vaticle.typedb.core.graph.common.Encoding.Vertex.Type.ENTITY_TYPE) Objects(java.util.Objects) Stream(java.util.stream.Stream) ROLE_TYPE(com.vaticle.typedb.core.graph.common.Encoding.Vertex.Type.ROLE_TYPE) TypeDBException(com.vaticle.typedb.core.common.exception.TypeDBException) Key(com.vaticle.typedb.core.graph.common.Storage.Key) Conjunction(com.vaticle.typeql.lang.pattern.Conjunction) TRANSACTION_SCHEMA_READ_VIOLATION(com.vaticle.typedb.core.common.exception.ErrorMessage.Transaction.TRANSACTION_SCHEMA_READ_VIOLATION) Iterators.link(com.vaticle.typedb.core.common.iterator.Iterators.link) KeyValue(com.vaticle.typedb.core.common.collection.KeyValue) Collections.set(com.vaticle.typedb.common.collection.Collections.set) Order(com.vaticle.typedb.core.common.iterator.sorted.SortedIterator.Order) ATTRIBUTE_TYPE(com.vaticle.typedb.core.graph.common.Encoding.Vertex.Type.ATTRIBUTE_TYPE) HashMap(java.util.HashMap) Supplier(java.util.function.Supplier) TreeSet(java.util.TreeSet) Forwardable.iterateSorted(com.vaticle.typedb.core.common.iterator.sorted.SortedIterators.Forwardable.iterateSorted) Forwardable.merge(com.vaticle.typedb.core.common.iterator.sorted.SortedIterators.Forwardable.merge) ConcurrentMap(java.util.concurrent.ConcurrentMap) HashSet(java.util.HashSet) Storage(com.vaticle.typedb.core.graph.common.Storage) THING_TYPE(com.vaticle.typedb.core.graph.common.Encoding.Vertex.Type.THING_TYPE) Type.scopedLabel(com.vaticle.typedb.core.graph.common.Encoding.Vertex.Type.scopedLabel) RuleUsage(com.vaticle.typedb.core.graph.iid.IndexIID.Type.RuleUsage) Collections.pair(com.vaticle.typedb.common.collection.Collections.pair) ROLE(com.vaticle.typedb.core.graph.common.Encoding.Vertex.Type.Root.ROLE) Math.toIntExact(java.lang.Math.toIntExact) Label(com.vaticle.typedb.core.common.parameters.Label) Encoding(com.vaticle.typedb.core.graph.common.Encoding) Nullable(javax.annotation.Nullable) PLAYS(com.vaticle.typedb.core.graph.common.Encoding.Edge.Type.PLAYS) Iterators.tree(com.vaticle.typedb.core.common.iterator.Iterators.tree) THING(com.vaticle.typedb.core.graph.common.Encoding.Vertex.Type.Root.THING) RuleStructure(com.vaticle.typedb.core.graph.structure.RuleStructure) TypeVertexImpl(com.vaticle.typedb.core.graph.vertex.impl.TypeVertexImpl) OWNS_KEY(com.vaticle.typedb.core.graph.common.Encoding.Edge.Type.OWNS_KEY) StructureIID(com.vaticle.typedb.core.graph.iid.StructureIID) ThingVariable(com.vaticle.typeql.lang.pattern.variable.ThingVariable) Iterators.iterate(com.vaticle.typedb.core.common.iterator.Iterators.iterate) OWNS(com.vaticle.typedb.core.graph.common.Encoding.Edge.Type.OWNS) TypeVertex(com.vaticle.typedb.core.graph.vertex.TypeVertex) StampedLock(java.util.concurrent.locks.StampedLock) ByteArray(com.vaticle.typedb.core.common.collection.ByteArray) IndexIID(com.vaticle.typedb.core.graph.iid.IndexIID) TypeVertex(com.vaticle.typedb.core.graph.vertex.TypeVertex)

Example 2 with Label

use of com.vaticle.typedb.core.common.parameters.Label in project grakn by graknlabs.

the class LogicManager method getRule.

public Rule getRule(String label) {
    Rule rule = logicCache.rule().getIfPresent(label);
    if (rule != null)
        return rule;
    RuleStructure structure = graphMgr.schema().rules().get(label);
    if (structure != null)
        return logicCache.rule().get(structure.label(), l -> Rule.of(this, structure));
    return null;
}
Also used : ConceptManager(com.vaticle.typedb.core.concept.ConceptManager) Iterators.link(com.vaticle.typedb.core.common.iterator.Iterators.link) ILLEGAL_STATE(com.vaticle.typedb.core.common.exception.ErrorMessage.Internal.ILLEGAL_STATE) TraversalEngine(com.vaticle.typedb.core.traversal.TraversalEngine) HashMap(java.util.HashMap) Map(java.util.Map) Collections.list(com.vaticle.typedb.common.collection.Collections.list) Comparator.comparing(java.util.Comparator.comparing) LinkedList(java.util.LinkedList) Label(com.vaticle.typedb.core.common.parameters.Label) Nullable(javax.annotation.Nullable) GraphManager(com.vaticle.typedb.core.graph.GraphManager) StringBuilders(com.vaticle.typedb.core.common.util.StringBuilders) TypeInference(com.vaticle.typedb.core.logic.tool.TypeInference) FunctionalIterator(com.vaticle.typedb.core.common.iterator.FunctionalIterator) RuleStructure(com.vaticle.typedb.core.graph.structure.RuleStructure) Set(java.util.Set) Pattern(com.vaticle.typeql.lang.pattern.Pattern) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) List(java.util.List) ThingVariable(com.vaticle.typeql.lang.pattern.variable.ThingVariable) RuleExporter.writeRule(com.vaticle.typedb.core.logic.LogicManager.RuleExporter.writeRule) Iterators.iterate(com.vaticle.typedb.core.common.iterator.Iterators.iterate) CONTRADICTORY_RULE_CYCLE(com.vaticle.typedb.core.common.exception.ErrorMessage.RuleWrite.CONTRADICTORY_RULE_CYCLE) TypeDBException(com.vaticle.typedb.core.common.exception.TypeDBException) Conjunction(com.vaticle.typeql.lang.pattern.Conjunction) RuleStructure(com.vaticle.typedb.core.graph.structure.RuleStructure) RuleExporter.writeRule(com.vaticle.typedb.core.logic.LogicManager.RuleExporter.writeRule)

Example 3 with Label

use of com.vaticle.typedb.core.common.parameters.Label in project grakn by graknlabs.

the class TypeInference method propagateLabels.

private void propagateLabels(Conjunction conj) {
    iterate(conj.variables()).filter(v -> v.isType() && v.asType().label().isPresent()).forEachRemaining(typeVar -> {
        Label label = typeVar.asType().label().get().properLabel();
        if (label.scope().isPresent()) {
            Set<Label> labels = graphMgr.schema().resolveRoleTypeLabels(label);
            if (labels.isEmpty())
                throw TypeDBException.of(ROLE_TYPE_NOT_FOUND, label.name(), label.scope().get());
            typeVar.addInferredTypes(labels);
        } else {
            if (graphMgr.schema().getType(label) == null)
                throw TypeDBException.of(TYPE_NOT_FOUND, label);
            typeVar.addInferredTypes(label);
        }
    });
}
Also used : Pair(com.vaticle.typedb.common.collection.Pair) ILLEGAL_STATE(com.vaticle.typedb.core.common.exception.ErrorMessage.Internal.ILLEGAL_STATE) TraversalEngine(com.vaticle.typedb.core.traversal.TraversalEngine) TypeConstraint(com.vaticle.typedb.core.pattern.constraint.type.TypeConstraint) Collections.set(com.vaticle.typedb.common.collection.Collections.set) Variable(com.vaticle.typedb.core.pattern.variable.Variable) Identifier(com.vaticle.typedb.core.traversal.common.Identifier) UNSATISFIABLE_SUB_PATTERN(com.vaticle.typedb.core.common.exception.ErrorMessage.Pattern.UNSATISFIABLE_SUB_PATTERN) HashMap(java.util.HashMap) UNSATISFIABLE_PATTERN_VARIABLE_VALUE(com.vaticle.typedb.core.common.exception.ErrorMessage.Pattern.UNSATISFIABLE_PATTERN_VARIABLE_VALUE) LogicCache(com.vaticle.typedb.core.logic.LogicCache) PlaysConstraint(com.vaticle.typedb.core.pattern.constraint.type.PlaysConstraint) UNSATISFIABLE_PATTERN_VARIABLE(com.vaticle.typedb.core.common.exception.ErrorMessage.Pattern.UNSATISFIABLE_PATTERN_VARIABLE) IIDConstraint(com.vaticle.typedb.core.pattern.constraint.thing.IIDConstraint) IsConstraint(com.vaticle.typedb.core.pattern.constraint.thing.IsConstraint) ATTRIBUTE(com.vaticle.typeql.lang.common.TypeQLToken.Type.ATTRIBUTE) VertexIID(com.vaticle.typedb.core.graph.iid.VertexIID) Map(java.util.Map) ValueConstraint(com.vaticle.typedb.core.pattern.constraint.thing.ValueConstraint) RelatesConstraint(com.vaticle.typedb.core.pattern.constraint.type.RelatesConstraint) TYPE_NOT_FOUND(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeRead.TYPE_NOT_FOUND) OwnsConstraint(com.vaticle.typedb.core.pattern.constraint.type.OwnsConstraint) ValueTypeConstraint(com.vaticle.typedb.core.pattern.constraint.type.ValueTypeConstraint) GraphTraversal(com.vaticle.typedb.core.traversal.GraphTraversal) Iterators.empty(com.vaticle.typedb.core.common.iterator.Iterators.empty) Label(com.vaticle.typedb.core.common.parameters.Label) Encoding(com.vaticle.typedb.core.graph.common.Encoding) GraphManager(com.vaticle.typedb.core.graph.GraphManager) Conjunction(com.vaticle.typedb.core.pattern.Conjunction) FunctionalIterator(com.vaticle.typedb.core.common.iterator.FunctionalIterator) ThingVariable(com.vaticle.typedb.core.pattern.variable.ThingVariable) IsaConstraint(com.vaticle.typedb.core.pattern.constraint.thing.IsaConstraint) SubConstraint(com.vaticle.typedb.core.pattern.constraint.type.SubConstraint) Set(java.util.Set) RegexConstraint(com.vaticle.typedb.core.pattern.constraint.type.RegexConstraint) Disjunction(com.vaticle.typedb.core.pattern.Disjunction) HasConstraint(com.vaticle.typedb.core.pattern.constraint.thing.HasConstraint) Retrievable(com.vaticle.typedb.core.traversal.common.Identifier.Variable.Retrievable) TraversalVertex(com.vaticle.typedb.core.traversal.graph.TraversalVertex) TypeVariable(com.vaticle.typedb.core.pattern.variable.TypeVariable) RelationConstraint(com.vaticle.typedb.core.pattern.constraint.thing.RelationConstraint) Optional(java.util.Optional) Iterators.iterate(com.vaticle.typedb.core.common.iterator.Iterators.iterate) TypeDBException(com.vaticle.typedb.core.common.exception.TypeDBException) ROLE_TYPE_NOT_FOUND(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeRead.ROLE_TYPE_NOT_FOUND) TypeVertex(com.vaticle.typedb.core.graph.vertex.TypeVertex) Comparator(java.util.Comparator) Label(com.vaticle.typedb.core.common.parameters.Label)

Aggregations

TypeDBException (com.vaticle.typedb.core.common.exception.TypeDBException)3 FunctionalIterator (com.vaticle.typedb.core.common.iterator.FunctionalIterator)3 Iterators.iterate (com.vaticle.typedb.core.common.iterator.Iterators.iterate)3 Label (com.vaticle.typedb.core.common.parameters.Label)3 Collections.set (com.vaticle.typedb.common.collection.Collections.set)2 Pair (com.vaticle.typedb.common.collection.Pair)2 ILLEGAL_STATE (com.vaticle.typedb.core.common.exception.ErrorMessage.Internal.ILLEGAL_STATE)2 TYPE_NOT_FOUND (com.vaticle.typedb.core.common.exception.ErrorMessage.TypeRead.TYPE_NOT_FOUND)2 Iterators.link (com.vaticle.typedb.core.common.iterator.Iterators.link)2 GraphManager (com.vaticle.typedb.core.graph.GraphManager)2 Encoding (com.vaticle.typedb.core.graph.common.Encoding)2 RuleStructure (com.vaticle.typedb.core.graph.structure.RuleStructure)2 Conjunction (com.vaticle.typeql.lang.pattern.Conjunction)2 Pattern (com.vaticle.typeql.lang.pattern.Pattern)2 ThingVariable (com.vaticle.typeql.lang.pattern.variable.ThingVariable)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Objects (java.util.Objects)2 Set (java.util.Set)2 Nullable (javax.annotation.Nullable)2