use of org.janusgraph.graphdb.internal.InternalVertex in project janusgraph by JanusGraph.
the class ModificationDeserializer method parseRelation.
public static InternalRelation parseRelation(TransactionLogHeader.Modification modification, StandardJanusGraphTx tx) {
Change state = modification.state;
assert state.isProper();
long outVertexId = modification.outVertexId;
Entry relEntry = modification.relationEntry;
InternalVertex outVertex = tx.getInternalVertex(outVertexId);
// Special relation parsing, compare to {@link RelationConstructor}
RelationCache relCache = tx.getEdgeSerializer().readRelation(relEntry, false, tx);
assert relCache.direction == Direction.OUT;
InternalRelationType type = (InternalRelationType) tx.getExistingRelationType(relCache.typeId);
assert type.getBaseType() == null;
InternalRelation rel;
if (type.isPropertyKey()) {
if (state == Change.REMOVED) {
rel = new StandardVertexProperty(relCache.relationId, (PropertyKey) type, outVertex, relCache.getValue(), ElementLifeCycle.Removed);
} else {
rel = new CacheVertexProperty(relCache.relationId, (PropertyKey) type, outVertex, relCache.getValue(), relEntry);
}
} else {
assert type.isEdgeLabel();
InternalVertex otherVertex = tx.getInternalVertex(relCache.getOtherVertexId());
if (state == Change.REMOVED) {
rel = new StandardEdge(relCache.relationId, (EdgeLabel) type, outVertex, otherVertex, ElementLifeCycle.Removed);
} else {
rel = new CacheEdge(relCache.relationId, (EdgeLabel) type, outVertex, otherVertex, relEntry);
}
}
if (state == Change.REMOVED && relCache.hasProperties()) {
// copy over properties
for (LongObjectCursor<Object> entry : relCache) {
rel.setPropertyDirect(tx.getExistingPropertyKey(entry.key), entry.value);
}
}
return rel;
}
use of org.janusgraph.graphdb.internal.InternalVertex in project janusgraph by JanusGraph.
the class StandardJanusGraphTx method getVertex.
@Override
public JanusGraphVertex getVertex(long vertexId) {
verifyOpen();
if (null != config.getGroupName()) {
MetricManager.INSTANCE.getCounter(config.getGroupName(), "db", "getVertexByID").inc();
}
if (!isValidVertexId(vertexId))
return null;
// Make canonical partitioned vertex id
if (idInspector.isPartitionedVertex(vertexId))
vertexId = idManager.getCanonicalVertexId(vertexId);
final InternalVertex v = vertexCache.get(vertexId, externalVertexRetriever);
return (null == v || v.isRemoved()) ? null : v;
}
use of org.janusgraph.graphdb.internal.InternalVertex in project janusgraph by JanusGraph.
the class BasicVertexCentricQueryBuilder method executeRelations.
protected Iterable<JanusGraphRelation> executeRelations(InternalVertex vertex, BaseVertexCentricQuery baseQuery) {
if (isPartitionedVertex(vertex)) {
if (!hasAllCanonicalTypes()) {
InternalVertex[] representatives = tx.getAllRepresentatives(vertex, restrict2Partitions);
Iterable<JanusGraphRelation> merge = null;
for (InternalVertex rep : representatives) {
Iterable<JanusGraphRelation> iterable = executeIndividualRelations(rep, baseQuery);
if (merge == null) {
merge = iterable;
} else {
merge = ResultMergeSortIterator.mergeSort(merge, iterable, (Comparator) orders, false);
}
}
return ResultSetIterator.wrap(merge, baseQuery.getLimit());
} else
vertex = tx.getCanonicalVertex(vertex);
}
return executeIndividualRelations(vertex, baseQuery);
}
use of org.janusgraph.graphdb.internal.InternalVertex in project janusgraph by JanusGraph.
the class BasicVertexCentricQueryBuilder method executeVertexIds.
public VertexList executeVertexIds(InternalVertex vertex, BaseVertexCentricQuery baseQuery) {
if (isPartitionedVertex(vertex)) {
// If there is a sort order, we need to first merge the relations (and sort) and then compute vertices
if (!orders.isEmpty())
return edges2VertexIds((Iterable) executeRelations(vertex, baseQuery), vertex);
if (!hasAllCanonicalTypes()) {
InternalVertex[] representatives = tx.getAllRepresentatives(vertex, restrict2Partitions);
VertexListInternal merge = null;
for (InternalVertex rep : representatives) {
if (merge != null && merge.size() >= baseQuery.getLimit())
break;
VertexList vertexList = executeIndividualVertexIds(rep, baseQuery);
if (merge == null)
merge = (VertexListInternal) vertexList;
else
merge.addAll(vertexList);
}
if (merge != null && merge.size() > baseQuery.getLimit()) {
merge = (VertexListInternal) merge.subList(0, baseQuery.getLimit());
}
return merge;
} else
vertex = tx.getCanonicalVertex(vertex);
}
return executeIndividualVertexIds(vertex, baseQuery);
}
use of org.janusgraph.graphdb.internal.InternalVertex in project janusgraph by JanusGraph.
the class MultiVertexCentricQueryBuilder method execute.
/* ---------------------------------------------------------------
* Query Execution
* ---------------------------------------------------------------
*/
/**
* Constructs the BaseVertexCentricQuery through {@link BasicVertexCentricQueryBuilder#constructQuery(org.janusgraph.graphdb.internal.RelationCategory)}.
* If the query asks for an implicit key, the resulting map is computed and returned directly.
* If the query is empty, a map that maps each vertex to an empty list is returned.
* Otherwise, the query is executed for all vertices through the transaction which will effectively
* pre-load the return result sets into the associated {@link org.janusgraph.graphdb.vertices.CacheVertex} or
* don't do anything at all if the vertex is new (and hence no edges in the storage backend).
* After that, a map is constructed that maps each vertex to the corresponding VertexCentricQuery and wrapped
* into a QueryProcessor. Hence, upon iteration the query will be executed like any other VertexCentricQuery
* with the performance difference that the SliceQueries will have already been preloaded and not further
* calls to the storage backend are needed.
*
* @param returnType
* @return
*/
protected <Q> Map<JanusGraphVertex, Q> execute(RelationCategory returnType, ResultConstructor<Q> resultConstructor) {
Preconditions.checkArgument(!vertices.isEmpty(), "Need to add at least one vertex to query");
final Map<JanusGraphVertex, Q> result = new HashMap<>(vertices.size());
BaseVertexCentricQuery bq = super.constructQuery(returnType);
profiler.setAnnotation(QueryProfiler.MULTIQUERY_ANNOTATION, true);
profiler.setAnnotation(QueryProfiler.NUMVERTICES_ANNOTATION, vertices.size());
if (!bq.isEmpty()) {
for (BackendQueryHolder<SliceQuery> sq : bq.getQueries()) {
Set<InternalVertex> adjVertices = new HashSet<>(vertices);
for (InternalVertex v : vertices) {
if (isPartitionedVertex(v)) {
profiler.setAnnotation(QueryProfiler.PARTITIONED_VERTEX_ANNOTATION, true);
adjVertices.remove(v);
adjVertices.addAll(allRequiredRepresentatives(v));
}
}
// Overwrite with more accurate size accounting for partitioned vertices
profiler.setAnnotation(QueryProfiler.NUMVERTICES_ANNOTATION, adjVertices.size());
tx.executeMultiQuery(adjVertices, sq.getBackendQuery(), sq.getProfiler());
}
for (InternalVertex v : vertices) {
result.put(v, resultConstructor.getResult(v, bq));
}
} else {
for (JanusGraphVertex v : vertices) result.put(v, resultConstructor.emptyResult());
}
return result;
}
Aggregations