use of org.unipop.query.search.SearchQuery in project unipop by unipop-graph.
the class UniGraph method query.
private <E extends Element, C extends Comparable> Iterator<E> query(Class<E> returnType, Object[] ids) {
PredicatesHolder idPredicate = createIdPredicate(ids, returnType);
SearchQuery<E> uniQuery = new SearchQuery<>(returnType, idPredicate, -1, null, null, null, null);
return queryControllers.stream().<E>flatMap(controller -> ConversionUtils.asStream(controller.search(uniQuery))).iterator();
}
use of org.unipop.query.search.SearchQuery in project unipop by unipop-graph.
the class AbstractRowSchema method getSearch.
@Override
public Select getSearch(SearchQuery<E> query, PredicatesHolder predicatesHolder) {
if (predicatesHolder.isAborted()) {
return null;
}
Condition conditions = new JdbcPredicatesTranslator().translate(predicatesHolder);
int finalLimit = query.getLimit() < 0 ? Integer.MAX_VALUE : query.getLimit();
SelectConditionStep<Record> where = createSqlQuery(query.getPropertyKeys()).where(conditions);
List<Pair<String, Order>> orders = query.getOrders();
if (orders != null) {
List<SortField<Object>> orderValues = orders.stream().filter(order -> !order.getValue1().equals(Order.shuffle)).filter(order -> getFieldByPropertyKey(order.getValue0()) != null).map(order -> order.getValue1().equals(Order.incr) ? field(getFieldByPropertyKey(order.getValue0())).asc() : field(getFieldByPropertyKey(order.getValue0())).desc()).collect(Collectors.toList());
if (orderValues.size() > 0)
return where.orderBy(orderValues).limit(finalLimit);
}
return where.limit(finalLimit);
}
use of org.unipop.query.search.SearchQuery in project unipop by unipop-graph.
the class VirtualController method search.
@Override
public <E extends Element> Iterator<E> search(SearchQuery<E> uniQuery) {
if (uniQuery.getReturnType() != Vertex.class)
return EmptyIterator.instance();
PredicatesHolder predicates = uniQuery.getPredicates();
List<? extends VirtualVertexSchema> filteredSchemas = vertexSchemas.stream().filter(schema -> !schema.toPredicates(predicates).getClause().equals(PredicatesHolder.Clause.Abort)).collect(Collectors.toList());
Optional<HasContainer> ids = predicates.getPredicates().stream().filter(has -> has.getKey().equals(T.id.getAccessor())).findFirst();
Optional<HasContainer> labels = predicates.getPredicates().stream().filter(has -> has.getKey().equals(T.label.getAccessor())).findFirst();
if (!ids.isPresent() || !labels.isPresent()) {
return EmptyIterator.instance();
}
ArrayList<Map<String, Object>> elements = new ArrayList<>();
Object idObject = ids.get().getValue();
Collection<Object> idsCol = idObject instanceof Collection ? ((Collection) idObject) : Collections.singleton(idObject);
Object labelObject = labels.get().getValue();
Collection<Object> labelCol = labelObject instanceof Collection ? ((Collection) labelObject) : Collections.singleton(labelObject);
idsCol.forEach(id -> labelCol.forEach(label -> elements.add(createElement(id, label.toString()))));
return (Iterator<E>) elements.stream().flatMap(fields -> filteredSchemas.stream().flatMap(schema -> Stream.of(schema.createElement(fields)))).filter(v -> v != null).iterator();
}
Aggregations