use of org.apache.tinkerpop.gremlin.structure.Direction in project titan by thinkaurelius.
the class IndexRemoveJob method getQueries.
@Override
public List<SliceQuery> getQueries() {
if (isGlobalGraphIndex()) {
//Everything
return ImmutableList.of(new SliceQuery(BufferUtil.zeroBuffer(1), BufferUtil.oneBuffer(128)));
} else {
RelationTypeIndexWrapper wrapper = (RelationTypeIndexWrapper) index;
InternalRelationType wrappedType = wrapper.getWrappedType();
Direction direction = null;
for (Direction dir : Direction.values()) if (wrappedType.isUnidirected(dir))
direction = dir;
assert direction != null;
StandardTitanTx tx = (StandardTitanTx) graph.get().buildTransaction().readOnly().start();
try {
QueryContainer qc = new QueryContainer(tx);
qc.addQuery().type(wrappedType).direction(direction).relations();
return qc.getSliceQueries();
} finally {
tx.rollback();
}
}
}
use of org.apache.tinkerpop.gremlin.structure.Direction in project titan by thinkaurelius.
the class EdgeSerializer method writeRelation.
public StaticArrayEntry writeRelation(InternalRelation relation, InternalRelationType type, int position, TypeInspector tx) {
assert type == relation.getType() || type.getBaseType().equals(relation.getType());
Direction dir = EdgeDirection.fromPosition(position);
Preconditions.checkArgument(type.isUnidirected(Direction.BOTH) || type.isUnidirected(dir));
long typeid = type.longId();
DirectionID dirID = getDirID(dir, relation.isProperty() ? RelationCategory.PROPERTY : RelationCategory.EDGE);
DataOutput out = serializer.getDataOutput(DEFAULT_CAPACITY);
int valuePosition;
IDHandler.writeRelationType(out, typeid, dirID, type.isInvisibleType());
Multiplicity multiplicity = type.multiplicity();
long[] sortKey = type.getSortKey();
assert !multiplicity.isConstrained() || sortKey.length == 0 : type.name();
int keyStartPos = out.getPosition();
if (!multiplicity.isConstrained()) {
writeInlineTypes(sortKey, relation, out, tx, InlineType.KEY);
}
int keyEndPos = out.getPosition();
long relationId = relation.longId();
//How multiplicity is handled for edges and properties is slightly different
if (relation.isEdge()) {
long otherVertexId = relation.getVertex((position + 1) % 2).longId();
if (multiplicity.isConstrained()) {
if (multiplicity.isUnique(dir)) {
valuePosition = out.getPosition();
VariableLong.writePositive(out, otherVertexId);
} else {
VariableLong.writePositiveBackward(out, otherVertexId);
valuePosition = out.getPosition();
}
VariableLong.writePositive(out, relationId);
} else {
VariableLong.writePositiveBackward(out, otherVertexId);
VariableLong.writePositiveBackward(out, relationId);
valuePosition = out.getPosition();
}
} else {
assert relation.isProperty();
Preconditions.checkArgument(relation.isProperty());
Object value = ((TitanVertexProperty) relation).value();
Preconditions.checkNotNull(value);
PropertyKey key = (PropertyKey) type;
assert key.dataType().isInstance(value);
if (multiplicity.isConstrained()) {
if (multiplicity.isUnique(dir)) {
//Cardinality=SINGLE
valuePosition = out.getPosition();
writePropertyValue(out, key, value);
} else {
//Cardinality=SET
writePropertyValue(out, key, value);
valuePosition = out.getPosition();
}
VariableLong.writePositive(out, relationId);
} else {
assert multiplicity.getCardinality() == Cardinality.LIST;
VariableLong.writePositiveBackward(out, relationId);
valuePosition = out.getPosition();
writePropertyValue(out, key, value);
}
}
//Write signature
long[] signature = type.getSignature();
writeInlineTypes(signature, relation, out, tx, InlineType.SIGNATURE);
//Write remaining properties
LongSet writtenTypes = new LongHashSet(sortKey.length + signature.length);
if (sortKey.length > 0 || signature.length > 0) {
for (long id : sortKey) writtenTypes.add(id);
for (long id : signature) writtenTypes.add(id);
}
LongArrayList remainingTypes = new LongArrayList(8);
for (PropertyKey t : relation.getPropertyKeysDirect()) {
if (!(t instanceof ImplicitKey) && !writtenTypes.contains(t.longId())) {
remainingTypes.add(t.longId());
}
}
//Sort types before writing to ensure that value is always written the same way
long[] remaining = remainingTypes.toArray();
Arrays.sort(remaining);
for (long tid : remaining) {
PropertyKey t = tx.getExistingPropertyKey(tid);
writeInline(out, t, relation.getValueDirect(t), InlineType.NORMAL);
}
assert valuePosition > 0;
StaticArrayEntry entry = new StaticArrayEntry(type.getSortOrder() == Order.DESC ? out.getStaticBufferFlipBytes(keyStartPos, keyEndPos) : out.getStaticBuffer(), valuePosition);
return entry;
}
use of org.apache.tinkerpop.gremlin.structure.Direction in project janusgraph by JanusGraph.
the class RelationIdentifier method findRelation.
JanusGraphRelation findRelation(JanusGraphTransaction tx) {
JanusGraphVertex v = ((StandardJanusGraphTx) tx).getInternalVertex(outVertexId);
if (v == null || v.isRemoved())
return null;
JanusGraphVertex typeVertex = tx.getVertex(typeId);
if (typeVertex == null)
return null;
if (!(typeVertex instanceof RelationType))
throw new IllegalArgumentException("Invalid RelationIdentifier: typeID does not reference a type");
RelationType type = (RelationType) typeVertex;
Iterable<? extends JanusGraphRelation> relations;
if (((RelationType) typeVertex).isEdgeLabel()) {
Direction dir = Direction.OUT;
JanusGraphVertex other = ((StandardJanusGraphTx) tx).getInternalVertex(inVertexId);
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;
}
relations = ((VertexCentricQueryBuilder) v.query()).noPartitionRestriction().types((EdgeLabel) type).direction(dir).adjacent(other).edges();
} else {
relations = ((VertexCentricQueryBuilder) v.query()).noPartitionRestriction().types((PropertyKey) type).properties();
}
for (JanusGraphRelation r : relations) {
// Find current or previous relation
if (r.longId() == relationId || ((r instanceof StandardRelation) && ((StandardRelation) r).getPreviousID() == relationId))
return r;
}
return null;
}
use of org.apache.tinkerpop.gremlin.structure.Direction in project atlas by apache.
the class AtlasJanusVertex method getEdges.
@Override
public Iterable<AtlasEdge<AtlasJanusVertex, AtlasJanusEdge>> getEdges(AtlasEdgeDirection in) {
Direction d = AtlasJanusObjectFactory.createDirection(in);
Iterator<Edge> edges = getWrappedElement().edges(d);
return graph.wrapEdges(edges);
}
use of org.apache.tinkerpop.gremlin.structure.Direction in project atlas by apache.
the class AtlasJanusVertex method getEdges.
@Override
public Iterable<AtlasEdge<AtlasJanusVertex, AtlasJanusEdge>> getEdges(AtlasEdgeDirection dir, String edgeLabel) {
Direction d = AtlasJanusObjectFactory.createDirection(dir);
Iterator<Edge> edges = getWrappedElement().edges(d, edgeLabel);
return graph.wrapEdges(edges);
}
Aggregations