use of org.unipop.jdbc.schemas.jdbc.JdbcSchema 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.jdbc.schemas.jdbc.JdbcSchema 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.jdbc.schemas.jdbc.JdbcSchema in project unipop by unipop-graph.
the class JdbcSourceProvider method init.
@Override
public Set<UniQueryController> init(UniGraph graph, JSONObject configuration, TraversalFilter traversalFilter) throws Exception {
this.contextManager = new ContextManager(configuration);
this.graph = graph;
Set<JdbcSchema> schemas = Sets.newHashSet();
getList(configuration, "vertices").forEach(vertexJson -> schemas.add(createVertexSchema(vertexJson)));
getList(configuration, "edges").forEach(edgeJson -> schemas.add(createEdgeSchema(edgeJson)));
return createControllers(schemas, traversalFilter);
}
Aggregations