use of org.openrdf.query.algebra.evaluation.iterator.CollectionIteration in project blueprints by tinkerpop.
the class GraphSailConnection method getContextIDsInternal.
// note: iterates over all statements
public CloseableIteration<? extends Resource, SailException> getContextIDsInternal() throws SailException {
Set<Resource> contexts = new HashSet<Resource>();
CloseableIteration<? extends Statement, SailException> iter = getStatementsInternal(null, null, null, false);
try {
while (iter.hasNext()) {
Resource context = iter.next().getContext();
// match the behavior of Sesame stores, which do not include the null context
if (null != context) {
contexts.add(context);
}
}
} finally {
iter.close();
}
return new CollectionIteration<Resource, SailException>(contexts);
}
use of org.openrdf.query.algebra.evaluation.iterator.CollectionIteration in project incubator-rya by apache.
the class EventQueryNode method evaluate.
@Override
public CloseableIteration<BindingSet, QueryEvaluationException> evaluate(final BindingSet bindings) throws QueryEvaluationException {
final List<BindingSet> list = new ArrayList<>();
try {
final Collection<Event> searchEvents;
final String subj;
// if the provided binding set has the subject already, set it to the constant subject.
if (!subjectConstant.isPresent() && bindings.hasBinding(subjectVar.get())) {
subjectConstant = Optional.of(bindings.getValue(subjectVar.get()).stringValue());
} else if (bindings.size() != 0) {
list.add(bindings);
}
// If the subject needs to be filled in, check if the subject variable is in the binding set.
if (subjectConstant.isPresent()) {
// if it is, fetch that value and then fetch the entity for the subject.
subj = subjectConstant.get();
searchEvents = eventStore.search(Optional.of(new RyaURI(subj)), Optional.of(geoFilters), Optional.of(temporalFilters));
} else {
searchEvents = eventStore.search(Optional.empty(), Optional.of(geoFilters), Optional.of(temporalFilters));
}
for (final Event event : searchEvents) {
final MapBindingSet resultSet = new MapBindingSet();
if (event.getGeometry().isPresent()) {
final Geometry geo = event.getGeometry().get();
final Value geoValue = ValueFactoryImpl.getInstance().createLiteral(geo.toText());
final Var geoObj = geoPattern.getObjectVar();
resultSet.addBinding(geoObj.getName(), geoValue);
}
final Value temporalValue;
if (event.isInstant() && event.getInstant().isPresent()) {
final Optional<TemporalInstant> opt = event.getInstant();
DateTime dt = opt.get().getAsDateTime();
dt = dt.toDateTime(DateTimeZone.UTC);
final String str = dt.toString(TemporalInstantRfc3339.FORMATTER);
temporalValue = ValueFactoryImpl.getInstance().createLiteral(str);
} else if (event.getInterval().isPresent()) {
temporalValue = ValueFactoryImpl.getInstance().createLiteral(event.getInterval().get().getAsPair());
} else {
temporalValue = null;
}
if (temporalValue != null) {
final Var temporalObj = temporalPattern.getObjectVar();
resultSet.addBinding(temporalObj.getName(), temporalValue);
}
list.add(resultSet);
}
} catch (final ObjectStorageException e) {
throw new QueryEvaluationException("Failed to evaluate the binding set", e);
}
return new CollectionIteration<>(list);
}
Aggregations