use of org.unipop.query.StepDescriptor in project unipop by unipop-graph.
the class UniGraphVertexStep method process.
@Override
protected Iterator<Traverser.Admin<E>> process(List<Traverser.Admin<Vertex>> traversers) {
Map<Object, List<Traverser<Vertex>>> idToTraverser = new HashMap<>(traversers.size());
List<Vertex> vertices = new ArrayList<>(traversers.size());
traversers.forEach(traverser -> {
Vertex vertex = traverser.get();
List<Traverser<Vertex>> traverserList = idToTraverser.get(vertex.id());
if (traverserList == null) {
traverserList = new ArrayList<>(1);
idToTraverser.put(vertex.id(), traverserList);
}
traverserList.add(traverser);
vertices.add(vertex);
});
SearchVertexQuery vertexQuery;
if (!returnsVertex)
vertexQuery = new SearchVertexQuery(Edge.class, vertices, direction, predicates, limit, propertyKeys, orders, stepDescriptor, traversal);
else
vertexQuery = new SearchVertexQuery(Edge.class, vertices, direction, predicates, -1, propertyKeys, null, stepDescriptor, traversal);
logger.debug("Executing query: ", vertexQuery);
Iterator<Traverser.Admin<E>> traversersIterator = controllers.stream().<Iterator<Edge>>map(controller -> controller.search(vertexQuery)).<Edge>flatMap(ConversionUtils::asStream).<Traverser.Admin<E>>flatMap(edge -> toTraversers(edge, idToTraverser)).iterator();
if (!this.returnsVertex || (propertyKeys != null && propertyKeys.size() == 0))
return traversersIterator;
return getTraversersWithProperties(traversersIterator);
}
use of org.unipop.query.StepDescriptor in project unipop by unipop-graph.
the class UniGraphEdgeOtherVertexStep method process.
@Override
protected Iterator<Traverser.Admin<Vertex>> process(List<Traverser.Admin<Edge>> traversers) {
List<Traverser.Admin<Vertex>> vertices = new ArrayList<>();
traversers.forEach(traverser -> {
final List<Object> objects = traverser.path().objects();
if (objects.get(objects.size() - 2) instanceof Vertex) {
Vertex vertex = ElementHelper.areEqual((Vertex) objects.get(objects.size() - 2), traverser.get().outVertex()) ? traverser.get().inVertex() : traverser.get().outVertex();
vertices.add(traverser.split(vertex, this));
}
});
if (propertyKeys == null || propertyKeys.size() > 0) {
List<DeferredVertex> v = vertices.stream().map(Attachable::get).filter(vertex -> vertex instanceof DeferredVertex).map(vertex -> ((DeferredVertex) vertex)).filter(DeferredVertex::isDeferred).collect(Collectors.toList());
if (v.size() > 0) {
DeferredVertexQuery query = new DeferredVertexQuery(v, propertyKeys, orders, stepDescriptor, traversal);
deferredVertexControllers.forEach(deferredVertexController -> deferredVertexController.fetchProperties(query));
}
}
return vertices.iterator();
}
Aggregations