use of org.apache.rya.indexing.IndexingExpr in project incubator-rya by apache.
the class GeoTemporalMongoDBStorageStrategyTest method emptyFilters_test.
@Test
public void emptyFilters_test() throws Exception {
final List<IndexingExpr> geoFilters = new ArrayList<>();
final List<IndexingExpr> temporalFilters = new ArrayList<>();
final DBObject actual = adapter.getFilterQuery(geoFilters, temporalFilters);
final String expectedString = "{ }";
final DBObject expected = (DBObject) JSON.parse(expectedString);
assertEqualMongo(expected, actual);
}
use of org.apache.rya.indexing.IndexingExpr in project incubator-rya by apache.
the class GeoTemporalIndexSetProvider method addFilter.
private void addFilter(final FunctionCall call) {
filterURI = new URIImpl(call.getURI());
final Var objVar = IndexingFunctionRegistry.getResultVarFromFunctionCall(filterURI, call.getArgs());
filterMap.put(objVar, new IndexingExpr(filterURI, objectPatterns.get(objVar), GeoParseUtils.extractArguments(objVar.getName(), call)));
}
use of org.apache.rya.indexing.IndexingExpr in project incubator-rya by apache.
the class GeoTemporalIndexSetProvider method getGeoTemporalNode.
private EventQueryNode getGeoTemporalNode(final Var subj) {
final Collection<StatementPattern> patterns = patternMap.get(subj);
final Collection<FunctionCall> usedFilters = new ArrayList<>();
Optional<StatementPattern> geoPattern = Optional.empty();
Optional<StatementPattern> temporalPattern = Optional.empty();
Optional<Collection<IndexingExpr>> geoFilters = Optional.empty();
Optional<Collection<IndexingExpr>> temporalFilters = Optional.empty();
// should only be 2 patterns.
for (final StatementPattern sp : patterns) {
final Var obj = sp.getObjectVar();
if (filterMap.containsKey(obj)) {
final Collection<IndexingExpr> filters = filterMap.get(obj);
final IndexingFunctionRegistry.FUNCTION_TYPE type = ensureSameType(filters);
if (type != null && type == FUNCTION_TYPE.GEO) {
geoPattern = Optional.of(sp);
geoFilters = Optional.of(filters);
usedFilters.addAll(matchedFilters.get(obj));
} else if (type != null && type == FUNCTION_TYPE.TEMPORAL) {
temporalPattern = Optional.of(sp);
temporalFilters = Optional.of(filters);
usedFilters.addAll(matchedFilters.get(obj));
} else {
return null;
}
} else {
return null;
}
}
if (geoFilters.isPresent() && temporalFilters.isPresent() && geoPattern.isPresent() && temporalPattern.isPresent()) {
return new EventQueryNodeBuilder().setStorage(eventStorage).setGeoPattern(geoPattern.get()).setTemporalPattern(temporalPattern.get()).setGeoFilters(geoFilters.get()).setTemporalFilters(temporalFilters.get()).setUsedFilters(usedFilters).build();
} else {
return null;
}
}
use of org.apache.rya.indexing.IndexingExpr in project incubator-rya by apache.
the class MongoEventStorage method search.
@Override
public Collection<Event> search(final Optional<RyaURI> subject, final Optional<Collection<IndexingExpr>> geoFilters, final Optional<Collection<IndexingExpr>> temporalFilters) throws EventStorageException {
requireNonNull(subject);
try {
final Collection<IndexingExpr> geos = (geoFilters.isPresent() ? geoFilters.get() : new ArrayList<>());
final Collection<IndexingExpr> tempos = (temporalFilters.isPresent() ? temporalFilters.get() : new ArrayList<>());
final DBObject filterObj = queryAdapter.getFilterQuery(geos, tempos);
final BasicDBObjectBuilder builder = BasicDBObjectBuilder.start(filterObj.toMap());
if (subject.isPresent()) {
builder.append(EventDocumentConverter.SUBJECT, subject.get().getData());
}
final MongoCursor<Document> results = mongo.getDatabase(ryaInstanceName).getCollection(COLLECTION_NAME).find(BsonDocument.parse(builder.get().toString())).iterator();
final List<Event> events = new ArrayList<>();
while (results.hasNext()) {
events.add(EVENT_CONVERTER.fromDocument(results.next()));
}
return events;
} catch (final MongoException | DocumentConverterException | GeoTemporalIndexException e) {
throw new EventStorageException("Could not get the Event.", e);
}
}
use of org.apache.rya.indexing.IndexingExpr in project incubator-rya by apache.
the class EventQueryNode2IT method constructor_variablePredicate.
@Test(expected = IllegalStateException.class)
public void constructor_variablePredicate() throws Exception {
// A pattern that has a variable for its predicate.
final Var geoSubj = new Var("point");
final Var geoPred = new Var("geo");
final Var geoObj = new Var("wkt");
final StatementPattern geoSP = new StatementPattern(geoSubj, geoPred, geoObj);
final Var timeSubj = new Var("time");
final Var timePred = new Var("-const-http://www.w3.org/2006/time#inXSDDateTime", ValueFactoryImpl.getInstance().createURI("-const-http://www.w3.org/2006/time#inXSDDateTime"));
final Var timeObj = new Var("time");
final StatementPattern timeSP = new StatementPattern(timeSubj, timePred, timeObj);
// This will fail.
new EventQueryNode.EventQueryNodeBuilder().setStorage(mock(EventStorage.class)).setGeoPattern(geoSP).setTemporalPattern(timeSP).setGeoFilters(new ArrayList<IndexingExpr>()).setTemporalFilters(new ArrayList<IndexingExpr>()).setUsedFilters(new ArrayList<>()).build();
}
Aggregations