Search in sources :

Example 6 with RelationType

use of org.janusgraph.core.RelationType in project janusgraph by JanusGraph.

the class RelationTypeIndexWrapper method getSortKey.

@Override
public RelationType[] getSortKey() {
    StandardJanusGraphTx tx = type.tx();
    long[] ids = type.getSortKey();
    RelationType[] keys = new RelationType[ids.length];
    for (int i = 0; i < keys.length; i++) {
        keys[i] = tx.getExistingRelationType(ids[i]);
    }
    return keys;
}
Also used : StandardJanusGraphTx(org.janusgraph.graphdb.transaction.StandardJanusGraphTx) RelationType(org.janusgraph.core.RelationType) InternalRelationType(org.janusgraph.graphdb.internal.InternalRelationType)

Example 7 with RelationType

use of org.janusgraph.core.RelationType in project janusgraph by JanusGraph.

the class AbstractIndexManagementIT method testRemoveRelationIndex.

@Test
public void testRemoveRelationIndex() throws InterruptedException, BackendException, ExecutionException {
    tx.commit();
    mgmt.commit();
    // Load the "Graph of the Gods" sample data
    GraphOfTheGodsFactory.loadWithoutMixedIndex(graph, true);
    // Disable the "battlesByTime" index
    JanusGraphManagement m = graph.openManagement();
    RelationType battled = m.getRelationType("battled");
    RelationTypeIndex battlesByTime = m.getRelationIndex(battled, "battlesByTime");
    m.updateIndex(battlesByTime, SchemaAction.DISABLE_INDEX);
    m.commit();
    graph.tx().commit();
    // Block until the SchemaStatus transitions to DISABLED
    assertTrue(ManagementSystem.awaitRelationIndexStatus(graph, "battlesByTime", "battled").status(SchemaStatus.DISABLED).call().getSucceeded());
    // Remove index
    MapReduceIndexManagement mri = new MapReduceIndexManagement(graph);
    m = graph.openManagement();
    battled = m.getRelationType("battled");
    battlesByTime = m.getRelationIndex(battled, "battlesByTime");
    ScanMetrics metrics = mri.updateIndex(battlesByTime, SchemaAction.REMOVE_INDEX).get();
    assertEquals(6, metrics.getCustom(IndexRemoveJob.DELETED_RECORDS_COUNT));
}
Also used : JanusGraphManagement(org.janusgraph.core.schema.JanusGraphManagement) RelationType(org.janusgraph.core.RelationType) ScanMetrics(org.janusgraph.diskstorage.keycolumnvalue.scan.ScanMetrics) RelationTypeIndex(org.janusgraph.core.schema.RelationTypeIndex) Test(org.junit.jupiter.api.Test) JanusGraphBaseTest(org.janusgraph.graphdb.JanusGraphBaseTest)

Example 8 with RelationType

use of org.janusgraph.core.RelationType in project janusgraph by JanusGraph.

the class JanusGraphVertexDeserializer method getPropertyKeyCardinality.

private VertexProperty.Cardinality getPropertyKeyCardinality(String name) {
    RelationType rt = typeManager.getRelationType(name);
    if (null == rt || !rt.isPropertyKey())
        return VertexProperty.Cardinality.single;
    PropertyKey pk = typeManager.getExistingPropertyKey(rt.longId());
    switch(pk.cardinality()) {
        case SINGLE:
            return VertexProperty.Cardinality.single;
        case LIST:
            return VertexProperty.Cardinality.list;
        case SET:
            return VertexProperty.Cardinality.set;
        default:
            throw new IllegalStateException("Unknown cardinality " + pk.cardinality());
    }
}
Also used : RelationType(org.janusgraph.core.RelationType) InternalRelationType(org.janusgraph.graphdb.internal.InternalRelationType) PropertyKey(org.janusgraph.core.PropertyKey)

Example 9 with RelationType

use of org.janusgraph.core.RelationType in project janusgraph by JanusGraph.

the class BasicVertexCentricQueryBuilder method compileConstraints.

/**
 * Converts the constraint conditions of this query into a constraintMap which is passed as an argument.
 * If all the constraint conditions could be accounted for in the constraintMap, this method returns true, else -
 * if some constraints cannot be captured in an interval - it returns false to indicate that further in-memory
 * filtering will be necessary.
 * </p>
 * This constraint map is used in constructing the SliceQueries and query optimization since this representation
 * is easier to handle.
 *
 * @param conditions
 * @param constraintMap
 * @return
 */
private boolean compileConstraints(And<JanusGraphRelation> conditions, Map<RelationType, Interval> constraintMap) {
    boolean isFitted = true;
    for (Condition<JanusGraphRelation> condition : conditions.getChildren()) {
        RelationType type = null;
        Interval newInterval = null;
        if (condition instanceof Or) {
            Map.Entry<RelationType, Collection> orEqual = QueryUtil.extractOrCondition((Or) condition);
            if (orEqual != null) {
                type = orEqual.getKey();
                newInterval = new PointInterval(orEqual.getValue());
            }
        } else if (condition instanceof PredicateCondition) {
            PredicateCondition<RelationType, JanusGraphRelation> atom = (PredicateCondition) condition;
            type = atom.getKey();
            Interval interval = constraintMap.get(type);
            newInterval = intersectConstraints(interval, type, atom.getPredicate(), atom.getValue());
        }
        if (newInterval != null) {
            constraintMap.put(type, newInterval);
        } else
            isFitted = false;
    }
    if (adjacentVertex != null) {
        if (adjacentVertex.hasId()) {
            constraintMap.put(ImplicitKey.ADJACENT_ID, new PointInterval(adjacentVertex.longId()));
        } else
            isFitted = false;
    }
    return isFitted;
}
Also used : PredicateCondition(org.janusgraph.graphdb.query.condition.PredicateCondition) JanusGraphRelation(org.janusgraph.core.JanusGraphRelation) Or(org.janusgraph.graphdb.query.condition.Or) PointInterval(org.janusgraph.util.datastructures.PointInterval) SystemRelationType(org.janusgraph.graphdb.types.system.SystemRelationType) RelationType(org.janusgraph.core.RelationType) InternalRelationType(org.janusgraph.graphdb.internal.InternalRelationType) Collection(java.util.Collection) Map(java.util.Map) HashMap(java.util.HashMap) PointInterval(org.janusgraph.util.datastructures.PointInterval) Interval(org.janusgraph.util.datastructures.Interval) RangeInterval(org.janusgraph.util.datastructures.RangeInterval)

Example 10 with RelationType

use of org.janusgraph.core.RelationType in project janusgraph by JanusGraph.

the class RelationIdentifierUtils method findEdgeRelations.

public static Iterable<? extends JanusGraphRelation> findEdgeRelations(JanusGraphVertex v, RelationType type, RelationIdentifier rId, JanusGraphTransaction tx) {
    Direction dir = Direction.OUT;
    JanusGraphVertex other = ((StandardJanusGraphTx) tx).getInternalVertex(rId.getInVertexId());
    if (other == null || other.isRemoved())
        return null;
    if (((StandardJanusGraphTx) tx).isPartitionedVertex(v) && !((StandardJanusGraphTx) tx).isPartitionedVertex(other)) {
        // Swap for likely better performance
        JanusGraphVertex tmp = other;
        other = v;
        v = tmp;
        dir = Direction.IN;
    }
    VertexCentricQueryBuilder query = ((VertexCentricQueryBuilder) v.query()).noPartitionRestriction().types(type).direction(dir).adjacent(other);
    RelationType internalVertex = ((StandardJanusGraphTx) tx).getExistingRelationType(type.longId());
    if (((InternalRelationType) internalVertex).getConsistencyModifier() != ConsistencyModifier.FORK) {
        query.has(ImplicitKey.JANUSGRAPHID.name(), rId.getRelationId());
    }
    return query.edges();
}
Also used : JanusGraphVertex(org.janusgraph.core.JanusGraphVertex) StandardJanusGraphTx(org.janusgraph.graphdb.transaction.StandardJanusGraphTx) RelationType(org.janusgraph.core.RelationType) InternalRelationType(org.janusgraph.graphdb.internal.InternalRelationType) VertexCentricQueryBuilder(org.janusgraph.graphdb.query.vertex.VertexCentricQueryBuilder) Direction(org.apache.tinkerpop.gremlin.structure.Direction)

Aggregations

RelationType (org.janusgraph.core.RelationType)30 InternalRelationType (org.janusgraph.graphdb.internal.InternalRelationType)22 PropertyKey (org.janusgraph.core.PropertyKey)10 JanusGraphRelation (org.janusgraph.core.JanusGraphRelation)6 JanusGraphIndex (org.janusgraph.core.schema.JanusGraphIndex)6 RelationTypeIndex (org.janusgraph.core.schema.RelationTypeIndex)6 StandardJanusGraphTx (org.janusgraph.graphdb.transaction.StandardJanusGraphTx)6 Map (java.util.Map)5 Direction (org.apache.tinkerpop.gremlin.structure.Direction)5 JanusGraphVertex (org.janusgraph.core.JanusGraphVertex)4 SystemRelationType (org.janusgraph.graphdb.types.system.SystemRelationType)4 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 EdgeLabel (org.janusgraph.core.EdgeLabel)3 VertexLabel (org.janusgraph.core.VertexLabel)3 PredicateCondition (org.janusgraph.graphdb.query.condition.PredicateCondition)3 ImplicitKey (org.janusgraph.graphdb.types.system.ImplicitKey)3 Preconditions (com.google.common.base.Preconditions)2 Collection (java.util.Collection)2 List (java.util.List)2