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;
}
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));
}
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());
}
}
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;
}
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();
}
Aggregations