use of org.apache.rya.indexing.IndexingExpr in project incubator-rya by apache.
the class EventQueryNode method toString.
@Override
public String toString() {
final StringBuilder sb = new StringBuilder();
sb.append("Geo Pattern: " + geoPattern.toString());
sb.append("\n--Geo Filters--\n");
for (final IndexingExpr filter : geoFilters) {
sb.append(filter.toString());
sb.append("\n");
}
sb.append("\n-------------------\n");
sb.append("Temporal Pattern: " + temporalPattern.toString());
sb.append("\n--Temporal Filters--\n");
for (final IndexingExpr filter : temporalFilters) {
sb.append(filter.toString());
sb.append("\n");
}
return sb.toString();
}
use of org.apache.rya.indexing.IndexingExpr in project incubator-rya by apache.
the class EventQueryNode2IT method constructor_differentSubjects.
@Test(expected = IllegalStateException.class)
public void constructor_differentSubjects() throws Exception {
final Var geoSubj = new Var("point");
final Var geoPred = new Var("-const-http://www.opengis.net/ont/geosparql#asWKT", ValueFactoryImpl.getInstance().createURI("http://www.opengis.net/ont/geosparql#asWKT"));
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();
}
use of org.apache.rya.indexing.IndexingExpr in project incubator-rya by apache.
the class GeoTemporalMongoDBStorageStrategyTest method equalsInstantAfterInterval_onlyOneGeo.
@Test
public void equalsInstantAfterInterval_onlyOneGeo() throws Exception {
final String query = "PREFIX geo: <http://www.opengis.net/ont/geosparql#>" + "PREFIX geof: <http://www.opengis.net/def/function/geosparql/>" + "SELECT ?point ?wkt " + "WHERE { " + " ?point geo:asWKT ?wkt . " + " FILTER(geof:sfWithin(?wkt, \"POLYGON((-3 -2, -3 2, 1 2, 1 -2, -3 -2))\"^^geo:wktLiteral)) " + "}";
final List<IndexingExpr> geoFilters = 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));
geoFilters.add(expr);
}
final List<IndexingExpr> temporalFilters = new ArrayList<>();
final DBObject actual = adapter.getFilterQuery(geoFilters, temporalFilters);
final String expectedString = "{ " + "\"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\"" + "}" + "}" + "}" + "}";
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 GeoTemporalMongoDBStorageStrategyTest method equalsInstantAfterInterval_onlyGeos.
@Test
public void equalsInstantAfterInterval_onlyGeos() throws Exception {
/*
* TODO: change filter functions for coverage
*/
final String query = "PREFIX geo: <http://www.opengis.net/ont/geosparql#>" + "PREFIX geof: <http://www.opengis.net/def/function/geosparql/>" + "SELECT ?point ?wkt " + "WHERE { " + " ?point geo:asWKT ?wkt . " + " FILTER(geof:sfIntersects(?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)) " + "}";
final List<IndexingExpr> geoFilters = 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));
geoFilters.add(expr);
}
final List<IndexingExpr> temporalFilters = new ArrayList<>();
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\"" + "}" + "} , { " + "\"location\" : { " + "\"$geoIntersects\" : {" + " \"$geometry\" : {" + " \"coordinates\" : [ [ [ -3.0 , -2.0] , [ -3.0 , 2.0] , [ 1.0 , 2.0] , [ 1.0 , -2.0] , [ -3.0 , -2.0]]] ," + " \"type\" : \"Polygon\"" + "}" + "}" + "}" + "}]}";
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 GeoTemporalMongoDBStorageStrategyTest method equalsInstantAfterInterval_GeoTemporalOneEach.
@Test
public void equalsInstantAfterInterval_GeoTemporalOneEach() 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(tempo:after(?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) {
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\" : { " + "\"$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\"" + "}" + "}" + "}" + "} , { " + "\"instant\" : { " + "\"$gt\" : { " + "\"$date\" : \"2015-12-30T12:00:00.000Z\"" + "}" + "}" + "}]" + "}";
final DBObject expected = (DBObject) JSON.parse(expectedString);
assertEqualMongo(expected, actual);
}
Aggregations