use of org.unipop.query.UniQuery in project unipop by unipop-graph.
the class RowController method search.
@SuppressWarnings("unchecked")
protected <E extends Element, R> Iterator<R> search(UniQuery query, Map<JdbcSchema<E>, Select> selects, SelectCollector<JdbcSchema<E>, Select, R> collector) {
if (bulk.size() != 0) {
contextManager.batch(bulk);
bulk.clear();
}
MetricsRunner metrics = new MetricsRunner(this, query, selects.keySet().stream().map(s -> ((ElementSchema) s)).collect(Collectors.toList()));
logger.info("mapped schemas for search, schemas: {}", selects);
if (selects.size() == 0)
return EmptyIterator.instance();
Iterator<JdbcSchema<E>> schemaIterator = selects.keySet().iterator();
Set<R> collect = selects.values().stream().map(select -> this.getContextManager().fetch(select)).flatMap(res -> collector.parse.apply(schemaIterator.next(), res).stream()).collect(Collectors.toSet());
metrics.stop((children) -> fillChildren(children, selects));
logger.info("results: {}", collect);
return collect.iterator();
}
use of org.unipop.query.UniQuery in project unipop by unipop-graph.
the class RowController method fetchProperties.
@Override
public void fetchProperties(DeferredVertexQuery uniQuery) {
SelectCollector<JdbcSchema<Vertex>, Select, Vertex> collector = new SelectCollector<>(schema -> schema.getSearch(uniQuery, schema.toPredicates(uniQuery.getPredicates())), (schema, results) -> schema.parseResults(results, uniQuery));
Map<JdbcSchema<Vertex>, Select> selects = vertexSchemas.stream().filter(schema -> this.traversalFilter.filter(schema, uniQuery.getTraversal())).collect(collector);
Iterator<Vertex> searchIterator = this.search(uniQuery, selects, collector);
Map<Object, DeferredVertex> vertexMap = uniQuery.getVertices().stream().collect(Collectors.toMap(UniElement::id, Function.identity(), (a, b) -> a));
searchIterator.forEachRemaining(newVertex -> {
DeferredVertex deferredVertex = vertexMap.get(newVertex.id());
if (deferredVertex != null) {
deferredVertex.loadProperties(newVertex);
}
});
}
use of org.unipop.query.UniQuery in project unipop by unipop-graph.
the class RestController method fetchProperties.
@Override
public void fetchProperties(DeferredVertexQuery uniQuery) {
RestCollector<RestVertexSchema, BaseRequest, Vertex> collector = new RestCollector<>(schema -> schema.getSearch(uniQuery), (schema, result) -> schema.parseResults(result, uniQuery));
Map<RestVertexSchema, BaseRequest> schemas = vertexSchemas.stream().filter(schema -> this.traversalFilter.filter(schema, uniQuery.getTraversal())).collect(collector);
Iterator<Vertex> iterator = search(uniQuery, schemas, collector);
Map<Object, DeferredVertex> vertexMap = uniQuery.getVertices().stream().collect(Collectors.toMap(UniElement::id, Function.identity(), (a, b) -> a));
iterator.forEachRemaining(newVertex -> {
DeferredVertex deferredVertex = vertexMap.get(newVertex.id());
if (deferredVertex != null)
deferredVertex.loadProperties(newVertex);
});
}
Aggregations