Search in sources :

Example 6 with IndexingExpr

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);
}
Also used : ArrayList(java.util.ArrayList) DBObject(com.mongodb.DBObject) IndexingExpr(org.apache.rya.indexing.IndexingExpr) Test(org.junit.Test)

Example 7 with IndexingExpr

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)));
}
Also used : Var(org.openrdf.query.algebra.Var) URIImpl(org.openrdf.model.impl.URIImpl) IndexingExpr(org.apache.rya.indexing.IndexingExpr)

Example 8 with IndexingExpr

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;
    }
}
Also used : Var(org.openrdf.query.algebra.Var) IndexingFunctionRegistry(org.apache.rya.indexing.IndexingFunctionRegistry) ArrayList(java.util.ArrayList) EventQueryNodeBuilder(org.apache.rya.indexing.geotemporal.model.EventQueryNode.EventQueryNodeBuilder) StatementPattern(org.openrdf.query.algebra.StatementPattern) FUNCTION_TYPE(org.apache.rya.indexing.IndexingFunctionRegistry.FUNCTION_TYPE) Collection(java.util.Collection) FunctionCall(org.openrdf.query.algebra.FunctionCall) IndexingExpr(org.apache.rya.indexing.IndexingExpr)

Example 9 with IndexingExpr

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);
    }
}
Also used : BasicDBObjectBuilder(com.mongodb.BasicDBObjectBuilder) MongoException(com.mongodb.MongoException) ArrayList(java.util.ArrayList) Document(org.bson.Document) BsonDocument(org.bson.BsonDocument) DBObject(com.mongodb.DBObject) DocumentConverterException(org.apache.rya.indexing.entity.storage.mongo.DocumentConverter.DocumentConverterException) GeoTemporalIndexException(org.apache.rya.indexing.geotemporal.GeoTemporalIndexException) Event(org.apache.rya.indexing.geotemporal.model.Event) IndexingExpr(org.apache.rya.indexing.IndexingExpr)

Example 10 with IndexingExpr

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();
}
Also used : StatementPattern(org.openrdf.query.algebra.StatementPattern) Var(org.openrdf.query.algebra.Var) ArrayList(java.util.ArrayList) MongoEventStorage(org.apache.rya.indexing.geotemporal.mongo.MongoEventStorage) EventStorage(org.apache.rya.indexing.geotemporal.storage.EventStorage) IndexingExpr(org.apache.rya.indexing.IndexingExpr) Test(org.junit.Test)

Aggregations

IndexingExpr (org.apache.rya.indexing.IndexingExpr)15 ArrayList (java.util.ArrayList)13 Var (org.openrdf.query.algebra.Var)12 StatementPattern (org.openrdf.query.algebra.StatementPattern)11 Test (org.junit.Test)10 DBObject (com.mongodb.DBObject)9 URIImpl (org.openrdf.model.impl.URIImpl)9 FunctionCall (org.openrdf.query.algebra.FunctionCall)9 URI (org.openrdf.model.URI)4 MongoEventStorage (org.apache.rya.indexing.geotemporal.mongo.MongoEventStorage)2 EventStorage (org.apache.rya.indexing.geotemporal.storage.EventStorage)2 BasicDBObjectBuilder (com.mongodb.BasicDBObjectBuilder)1 MongoException (com.mongodb.MongoException)1 Collection (java.util.Collection)1 RyaURI (org.apache.rya.api.domain.RyaURI)1 IndexingFunctionRegistry (org.apache.rya.indexing.IndexingFunctionRegistry)1 FUNCTION_TYPE (org.apache.rya.indexing.IndexingFunctionRegistry.FUNCTION_TYPE)1 DocumentConverterException (org.apache.rya.indexing.entity.storage.mongo.DocumentConverter.DocumentConverterException)1 GeoTemporalIndexException (org.apache.rya.indexing.geotemporal.GeoTemporalIndexException)1 Event (org.apache.rya.indexing.geotemporal.model.Event)1