use of org.unipop.query.predicates.PredicatesHolder 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.predicates.PredicatesHolder in project unipop by unipop-graph.
the class VertexSchema method toPredicates.
/**
* Receives a list of vertices and converts them to predicates
* @param vertices A list of vertices
* @return Predicate holder
*/
default PredicatesHolder toPredicates(List<? extends Vertex> vertices) {
if (vertices == null || vertices.size() == 0)
return PredicatesHolderFactory.abort();
HashSet<PredicatesHolder> predicates = new HashSet<>();
vertices.stream().collect(Collectors.groupingBy(Vertex::label)).forEach((label, labelVertices) -> {
HasContainer labelPredicate = new HasContainer(T.label.getAccessor(), P.eq(label));
HasContainer ids = new HasContainer(T.id.getAccessor(), P.within(labelVertices.stream().map(Vertex::id).collect(Collectors.toSet())));
PredicatesHolder labelPredicates = PredicatesHolderFactory.and(ids, labelPredicate);
PredicatesHolder toPredicates = toPredicates(labelPredicates);
predicates.add(toPredicates);
});
return PredicatesHolderFactory.or(predicates);
}
use of org.unipop.query.predicates.PredicatesHolder in project unipop by unipop-graph.
the class RestEdge method getSearch.
@Override
public BaseRequest getSearch(SearchVertexQuery query) {
int limit = query.getOrders() == null || query.getOrders().size() > 0 ? -1 : query.getLimit();
PredicatesHolder edgePredicates = this.toPredicates(query.getPredicates());
PredicatesHolder vertexPredicates = this.getVertexPredicates(query.getVertices(), query.getDirection());
PredicatesHolder predicatesHolder = PredicatesHolderFactory.and(edgePredicates, vertexPredicates);
return createSearch(predicatesHolder, limit);
}
use of org.unipop.query.predicates.PredicatesHolder in project unipop by unipop-graph.
the class DateFieldPropertySchema method getValues.
@Override
public Set<Object> getValues(PredicatesHolder predicatesHolder) {
Stream<PredicatesHolder> predicates = predicatesHolder.findKey(this.key).map(this::explodeConnective);
Map<String, Date> datePredicates = new HashMap<>();
predicates.flatMap(p -> p.getPredicates().stream()).forEach(has -> {
String biPredicate = has.getBiPredicate().toString();
Object value = has.getValue();
switch(biPredicate) {
case "eq":
datePredicates.put("eq", fromDisplay(value.toString()));
break;
case "gt":
datePredicates.put("gt", fromDisplay(value.toString()));
case "gte":
datePredicates.put("gte", fromDisplay(value.toString()));
break;
case "lt":
datePredicates.put("lt", fromDisplay(value.toString()));
break;
case "lte":
datePredicates.put("lte", fromDisplay(value.toString()));
break;
default:
throw new IllegalArgumentException("cant get value");
}
});
if (datePredicates.size() == 0)
return Collections.emptySet();
if (datePredicates.containsKey("eq"))
return Collections.singleton(toSource(datePredicates.get("eq")));
else if ((datePredicates.containsKey("gt") || datePredicates.containsKey("gte")) && (datePredicates.containsKey("lt") || datePredicates.containsKey("lte"))) {
Date from = datePredicates.containsKey("gt") ? datePredicates.get("gt") : datePredicates.get("gte");
Date to = datePredicates.containsKey("lt") ? datePredicates.get("lt") : datePredicates.get("lte");
List<Date> dates = new ArrayList<>();
long interval = this.interval;
long endTime = to.getTime();
long curTime = from.getTime();
while (curTime <= endTime) {
dates.add(new Date(curTime));
curTime += interval;
}
return dates.stream().map(this::toSource).collect(Collectors.toSet());
} else
throw new IllegalArgumentException("cant get only gt or lt value");
}
use of org.unipop.query.predicates.PredicatesHolder in project unipop by unipop-graph.
the class ConcatenateFieldPropertySchema method stringValueToPredicate.
private PredicatesHolder stringValueToPredicate(String value, HasContainer has, boolean collection) {
String[] values = value.split(delimiter);
if (values.length < schemas.size())
return PredicatesHolderFactory.abort();
Set<PredicatesHolder> predicates = new HashSet<>();
for (int i = 0; i < schemas.size(); i++) {
P predicate = has.getPredicate().clone();
final Object currentValue = values[i];
P p = new P(predicate.getBiPredicate(), collection ? Arrays.asList(currentValue) : currentValue);
PredicatesHolder predicatesHolder = schemas.get(i).toPredicates(PredicatesHolderFactory.predicate(new HasContainer(has.getKey(), p)));
predicates.add(predicatesHolder);
}
return PredicatesHolderFactory.and(predicates);
}
Aggregations