Search in sources :

Example 1 with FunctionCall

use of org.openrdf.query.algebra.FunctionCall in project incubator-rya by apache.

the class FilterRangeVisitor method meet.

@Override
public void meet(final Filter node) throws Exception {
    super.meet(node);
    final ValueExpr arg = node.getCondition();
    if (arg instanceof FunctionCall) {
        final FunctionCall fc = (FunctionCall) arg;
        if (RANGE.stringValue().equals(fc.getURI())) {
            // range(?var, start, end)
            final List<ValueExpr> valueExprs = fc.getArgs();
            if (valueExprs.size() != 3) {
                throw new QueryEvaluationException("org.apache:range must have 3 parameters: variable, start, end");
            }
            final Var var = (Var) valueExprs.get(0);
            final ValueConstant startVc = (ValueConstant) valueExprs.get(1);
            final ValueConstant endVc = (ValueConstant) valueExprs.get(2);
            final Value start = startVc.getValue();
            final Value end = endVc.getValue();
            rangeValues.put(var, new RangeValue(start, end));
            node.setCondition(new ValueConstant(BooleanLiteralImpl.TRUE));
        }
    }
}
Also used : ValueExpr(org.openrdf.query.algebra.ValueExpr) QueryEvaluationException(org.openrdf.query.QueryEvaluationException) Var(org.openrdf.query.algebra.Var) ValueConstant(org.openrdf.query.algebra.ValueConstant) Value(org.openrdf.model.Value) RangeValue(org.apache.rya.api.domain.RangeValue) FunctionCall(org.openrdf.query.algebra.FunctionCall) RangeValue(org.apache.rya.api.domain.RangeValue)

Example 2 with FunctionCall

use of org.openrdf.query.algebra.FunctionCall 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);
}
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 3 with FunctionCall

use of org.openrdf.query.algebra.FunctionCall 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);
}
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 4 with FunctionCall

use of org.openrdf.query.algebra.FunctionCall 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);
}
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 5 with FunctionCall

use of org.openrdf.query.algebra.FunctionCall in project incubator-rya by apache.

the class PeriodicQueryUtilTest method periodicNodeNotPresentTest.

@Test
public void periodicNodeNotPresentTest() throws Exception {
    List<ValueExpr> values = Arrays.asList(new Var("time"), new ValueConstant(vf.createLiteral(12.0)), new ValueConstant(vf.createLiteral(6.0)), new ValueConstant(vf.createURI(PeriodicQueryUtil.temporalNameSpace + "hours")));
    FunctionCall func = new FunctionCall("uri:func", values);
    Optional<PeriodicQueryNode> node1 = PeriodicQueryUtil.getPeriodicQueryNode(func, new Join());
    Assert.assertEquals(false, node1.isPresent());
}
Also used : ValueExpr(org.openrdf.query.algebra.ValueExpr) Var(org.openrdf.query.algebra.Var) ValueConstant(org.openrdf.query.algebra.ValueConstant) Join(org.openrdf.query.algebra.Join) FunctionCall(org.openrdf.query.algebra.FunctionCall) Test(org.junit.Test)

Aggregations

FunctionCall (org.openrdf.query.algebra.FunctionCall)14 Var (org.openrdf.query.algebra.Var)14 Test (org.junit.Test)10 ArrayList (java.util.ArrayList)9 IndexingExpr (org.apache.rya.indexing.IndexingExpr)9 StatementPattern (org.openrdf.query.algebra.StatementPattern)9 URIImpl (org.openrdf.model.impl.URIImpl)8 DBObject (com.mongodb.DBObject)7 URI (org.openrdf.model.URI)4 ValueConstant (org.openrdf.query.algebra.ValueConstant)4 ValueExpr (org.openrdf.query.algebra.ValueExpr)4 Join (org.openrdf.query.algebra.Join)3 Collection (java.util.Collection)1 RangeValue (org.apache.rya.api.domain.RangeValue)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 EventQueryNodeBuilder (org.apache.rya.indexing.geotemporal.model.EventQueryNode.EventQueryNodeBuilder)1 Value (org.openrdf.model.Value)1 QueryEvaluationException (org.openrdf.query.QueryEvaluationException)1