Search in sources :

Example 11 with IndexingExpr

use of org.apache.rya.indexing.IndexingExpr in project incubator-rya by apache.

the class EventQueryNode2IT method buildNode.

private EventQueryNode buildNode(final EventStorage store, final String query) throws Exception {
    final List<IndexingExpr> geoFilters = new ArrayList<>();
    final List<IndexingExpr> temporalFilters = new ArrayList<>();
    final List<StatementPattern> sps = getSps(query);
    final List<FunctionCall> filters = getFilters(query);
    for (final FunctionCall filter : filters) {
        final URI filterURI = new URIImpl(filter.getURI());
        final Var objVar = IndexingFunctionRegistry.getResultVarFromFunctionCall(filterURI, filter.getArgs());
        final IndexingExpr expr = new IndexingExpr(filterURI, sps.get(0), extractArguments(objVar.getName(), filter));
        if (IndexingFunctionRegistry.getFunctionType(filterURI) == FUNCTION_TYPE.GEO) {
            geoFilters.add(expr);
        } else {
            temporalFilters.add(expr);
        }
    }
    final StatementPattern geoPattern = sps.get(1);
    final StatementPattern temporalPattern = sps.get(0);
    return new EventQueryNode.EventQueryNodeBuilder().setStorage(store).setGeoPattern(geoPattern).setTemporalPattern(temporalPattern).setGeoFilters(geoFilters).setTemporalFilters(temporalFilters).setUsedFilters(filters).build();
}
Also used : StatementPattern(org.openrdf.query.algebra.StatementPattern) Var(org.openrdf.query.algebra.Var) ArrayList(java.util.ArrayList) URIImpl(org.openrdf.model.impl.URIImpl) FunctionCall(org.openrdf.query.algebra.FunctionCall) URI(org.openrdf.model.URI) RyaURI(org.apache.rya.api.domain.RyaURI) IndexingExpr(org.apache.rya.indexing.IndexingExpr)

Example 12 with IndexingExpr

use of org.apache.rya.indexing.IndexingExpr in project incubator-rya by apache.

the class GeoTemporalMongoDBStorageStrategyTest method equalsInstantAfterInterval_GeoTemporalSingleGeoTwoTemporal.

@Test
public void equalsInstantAfterInterval_GeoTemporalSingleGeoTwoTemporal() throws Exception {
    final String query = "PREFIX time: <http://www.w3.org/2006/time#> \n" + "PREFIX tempo: <tag:rya-rdf.org,2015:temporal#> \n" + "PREFIX geo: <http://www.opengis.net/ont/geosparql#>" + "PREFIX geof: <http://www.opengis.net/def/function/geosparql/>" + "SELECT ?event ?time ?point ?wkt " + "WHERE { " + "  ?event time:atTime ?time . " + "  ?point geo:asWKT ?wkt . " + "  FILTER(geof:sfEquals(?wkt, \"POLYGON((-4 -3, -4 3, 2 3, 2 -3, -4 -3))\"^^geo:wktLiteral)) ." + "  FILTER(tempo:hasBeginningInterval(?time, \"[1969-12-31T19:00:00-05:00,1969-12-31T19:00:01-05:00]\")) . " + "  FILTER(tempo:afterInterval(?time, \"[1969-12-31T19:00:00-05:00,1969-12-31T19:00:01-05:00]\"))" + "}";
    final List<IndexingExpr> geoFilters = new ArrayList<>();
    final List<IndexingExpr> temporalFilters = new ArrayList<>();
    final List<StatementPattern> sps = getSps(query);
    final List<FunctionCall> filters = getFilters(query);
    for (final FunctionCall filter : filters) {
        final URI filterURI = new URIImpl(filter.getURI());
        final Var objVar = IndexingFunctionRegistry.getResultVarFromFunctionCall(filterURI, filter.getArgs());
        final IndexingExpr expr = new IndexingExpr(filterURI, sps.get(0), extractArguments(objVar.getName(), filter));
        if (IndexingFunctionRegistry.getFunctionType(filterURI) == FUNCTION_TYPE.GEO) {
            geoFilters.add(expr);
        } else {
            temporalFilters.add(expr);
        }
    }
    final DBObject actual = adapter.getFilterQuery(geoFilters, temporalFilters);
    final String expectedString = "{ " + "\"$and\" : [ { " + "\"location\" : { " + "\"coordinates\" : [ [ [ -4.0 , -3.0] , [ -4.0 , 3.0] , [ 2.0 , 3.0] , [ 2.0 , -3.0] , [ -4.0 , -3.0]]] , " + "\"type\" : \"Polygon\"" + "}" + "} , { " + "\"$and\" : [ { " + "\"instant\" : { " + "\"$gt\" : { " + "\"$date\" : \"1970-01-01T00:00:01.000Z\"" + "}" + "}" + "} , { " + "\"instant\" : { " + "\"$date\" : \"1970-01-01T00:00:00.000Z\"" + "}" + "}]" + "}]" + "}";
    final DBObject expected = (DBObject) JSON.parse(expectedString);
    assertEqualMongo(expected, actual);
}
Also used : StatementPattern(org.openrdf.query.algebra.StatementPattern) Var(org.openrdf.query.algebra.Var) ArrayList(java.util.ArrayList) URIImpl(org.openrdf.model.impl.URIImpl) FunctionCall(org.openrdf.query.algebra.FunctionCall) URI(org.openrdf.model.URI) DBObject(com.mongodb.DBObject) IndexingExpr(org.apache.rya.indexing.IndexingExpr) Test(org.junit.Test)

Example 13 with IndexingExpr

use of org.apache.rya.indexing.IndexingExpr in project incubator-rya by apache.

the class GeoTemporalMongoDBStorageStrategyTest method equalsInstantAfterInterval_onlyOneTemporal.

@Test
public void equalsInstantAfterInterval_onlyOneTemporal() throws Exception {
    final String query = "PREFIX time: <http://www.w3.org/2006/time#> \n" + "PREFIX tempo: <tag:rya-rdf.org,2015:temporal#> \n" + "SELECT ?event ?time " + "WHERE { " + "  ?event time:atTime ?time . " + "  FILTER(tempo:equals(?time, \"2015-12-30T12:00:00Z\")) . " + "}";
    final List<IndexingExpr> geoFilters = new ArrayList<>();
    final List<IndexingExpr> temporalFilters = new ArrayList<>();
    final List<StatementPattern> sps = getSps(query);
    final List<FunctionCall> filters = getFilters(query);
    for (final FunctionCall filter : filters) {
        // should only be one.
        final Var objVar = IndexingFunctionRegistry.getResultVarFromFunctionCall(new URIImpl(filter.getURI()), filter.getArgs());
        final IndexingExpr expr = new IndexingExpr(new URIImpl(filter.getURI()), sps.get(0), extractArguments(objVar.getName(), filter));
        temporalFilters.add(expr);
    }
    final DBObject actual = adapter.getFilterQuery(geoFilters, temporalFilters);
    final String expectedString = "{ " + "\"instant\" : {" + "\"$date\" : \"2015-12-30T12:00:00.000Z\"" + "}" + "}";
    final DBObject expected = (DBObject) JSON.parse(expectedString);
    assertEqualMongo(expected, actual);
}
Also used : StatementPattern(org.openrdf.query.algebra.StatementPattern) Var(org.openrdf.query.algebra.Var) ArrayList(java.util.ArrayList) URIImpl(org.openrdf.model.impl.URIImpl) FunctionCall(org.openrdf.query.algebra.FunctionCall) DBObject(com.mongodb.DBObject) IndexingExpr(org.apache.rya.indexing.IndexingExpr) Test(org.junit.Test)

Example 14 with IndexingExpr

use of org.apache.rya.indexing.IndexingExpr in project incubator-rya by apache.

the class GeoTemporalMongoDBStorageStrategyTest method equalsInstantAfterInterval_GeoTemporalTwoEach.

@Test
public void equalsInstantAfterInterval_GeoTemporalTwoEach() throws Exception {
    final String query = "PREFIX time: <http://www.w3.org/2006/time#> \n" + "PREFIX tempo: <tag:rya-rdf.org,2015:temporal#> \n" + "PREFIX geo: <http://www.opengis.net/ont/geosparql#>" + "PREFIX geof: <http://www.opengis.net/def/function/geosparql/>" + "SELECT ?event ?time ?point ?wkt " + "WHERE { " + "  ?event time:atTime ?time . " + "  ?point geo:asWKT ?wkt . " + "  FILTER(geof:sfWithin(?wkt, \"POLYGON((-3 -2, -3 2, 1 2, 1 -2, -3 -2))\"^^geo:wktLiteral)) " + "  FILTER(geof:sfEquals(?wkt, \"POLYGON((-4 -3, -4 3, 2 3, 2 -3, -4 -3))\"^^geo:wktLiteral)) " + "  FILTER(tempo:hasEndInterval(?time, \"[1969-12-31T19:00:00-05:00,1969-12-31T19:00:01-05:00]\")) . " + "  FILTER(tempo:beforeInterval(?time, \"[1969-12-31T19:00:00-05:00,1969-12-31T19:00:01-05:00]\")) . " + "}";
    final List<IndexingExpr> geoFilters = new ArrayList<>();
    final List<IndexingExpr> temporalFilters = new ArrayList<>();
    final List<StatementPattern> sps = getSps(query);
    final List<FunctionCall> filters = getFilters(query);
    for (final FunctionCall filter : filters) {
        final URI filterURI = new URIImpl(filter.getURI());
        final Var objVar = IndexingFunctionRegistry.getResultVarFromFunctionCall(filterURI, filter.getArgs());
        final IndexingExpr expr = new IndexingExpr(filterURI, sps.get(0), extractArguments(objVar.getName(), filter));
        if (IndexingFunctionRegistry.getFunctionType(filterURI) == FUNCTION_TYPE.GEO) {
            geoFilters.add(expr);
        } else {
            temporalFilters.add(expr);
        }
    }
    final DBObject actual = adapter.getFilterQuery(geoFilters, temporalFilters);
    final String expectedString = "{ " + "\"$and\" : [ { " + "\"$and\" : [ { " + "\"location\" : { " + "\"coordinates\" : [ [ [ -4.0 , -3.0] , [ -4.0 , 3.0] , [ 2.0 , 3.0] , [ 2.0 , -3.0] , [ -4.0 , -3.0]]] , " + "\"type\" : \"Polygon\"" + "}" + "} , { " + "\"location\" : { " + "\"$geoWithin\" : { " + "\"$geometry\" : { " + "\"coordinates\" : [ [ [ -3.0 , -2.0] , [ -3.0 , 2.0] , [ 1.0 , 2.0] , [ 1.0 , -2.0] , [ -3.0 , -2.0]]] , " + "\"type\" : \"Polygon\"" + "}" + "}" + "}" + "}]" + "} , { " + "\"$and\" : [ { " + "\"instant\" : { " + "\"$lt\" : { " + "\"$date\" : \"1970-01-01T00:00:00.000Z\"" + "}" + "}" + "} , { " + "\"instant\" : { " + "\"$date\" : \"1970-01-01T00:00:01.000Z\"" + "}" + "}]" + "}]" + "}";
    final DBObject expected = (DBObject) JSON.parse(expectedString);
    assertEqualMongo(expected, actual);
}
Also used : StatementPattern(org.openrdf.query.algebra.StatementPattern) Var(org.openrdf.query.algebra.Var) ArrayList(java.util.ArrayList) URIImpl(org.openrdf.model.impl.URIImpl) FunctionCall(org.openrdf.query.algebra.FunctionCall) URI(org.openrdf.model.URI) DBObject(com.mongodb.DBObject) IndexingExpr(org.apache.rya.indexing.IndexingExpr) Test(org.junit.Test)

Example 15 with IndexingExpr

use of org.apache.rya.indexing.IndexingExpr in project incubator-rya by apache.

the class GeoTemporalMongoDBStorageStrategyTest method equalsInstantAfterInterval_onlyTemporal.

@Test
public void equalsInstantAfterInterval_onlyTemporal() throws Exception {
    final String query = "PREFIX time: <http://www.w3.org/2006/time#> \n" + "PREFIX tempo: <tag:rya-rdf.org,2015:temporal#> \n" + "SELECT ?event ?time " + "WHERE { " + "  ?event time:atTime ?time . " + "  FILTER(tempo:before(?time, \"2015-12-30T12:00:00Z\")) . " + "  FILTER(tempo:insideInterval(?time, \"[1969-12-31T19:00:00-05:00,1969-12-31T19:00:01-05:00]\")) . " + "}";
    final List<IndexingExpr> geoFilters = new ArrayList<>();
    final List<IndexingExpr> temporalFilters = new ArrayList<>();
    final List<StatementPattern> sps = getSps(query);
    final List<FunctionCall> filters = getFilters(query);
    for (final FunctionCall filter : filters) {
        final Var objVar = IndexingFunctionRegistry.getResultVarFromFunctionCall(new URIImpl(filter.getURI()), filter.getArgs());
        final IndexingExpr expr = new IndexingExpr(new URIImpl(filter.getURI()), sps.get(0), extractArguments(objVar.getName(), filter));
        temporalFilters.add(expr);
    }
    final DBObject actual = adapter.getFilterQuery(geoFilters, temporalFilters);
    final String expectedString = "{ " + "\"$and\" : [{" + "\"instant\" : {" + "\"$gt\" : {" + "\"$date\" : \"1970-01-01T00:00:00.000Z\"" + "}," + "\"$lt\" : {" + "\"$date\" : \"1970-01-01T00:00:01.000Z\"" + "}," + "}}, {" + "\"instant\" : {" + "\"$lt\" : {" + "\"$date\" : \"2015-12-30T12:00:00.000Z\"" + "}" + "}" + "}]" + "}";
    final DBObject expected = (DBObject) JSON.parse(expectedString);
    assertEqualMongo(expected, actual);
}
Also used : StatementPattern(org.openrdf.query.algebra.StatementPattern) Var(org.openrdf.query.algebra.Var) ArrayList(java.util.ArrayList) URIImpl(org.openrdf.model.impl.URIImpl) FunctionCall(org.openrdf.query.algebra.FunctionCall) DBObject(com.mongodb.DBObject) 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