Search in sources :

Example 6 with FunctionCall

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

the class PeriodicQueryUtilTest method periodicNodeFractionalDurationTest.

@Test
public void periodicNodeFractionalDurationTest() throws Exception {
    List<ValueExpr> values = Arrays.asList(new Var("time"), new ValueConstant(vf.createLiteral(1)), new ValueConstant(vf.createLiteral(.5)), new ValueConstant(vf.createURI(PeriodicQueryUtil.temporalNameSpace + "hours")));
    FunctionCall func = new FunctionCall(PeriodicQueryUtil.PeriodicQueryURI, values);
    Optional<PeriodicQueryNode> node1 = PeriodicQueryUtil.getPeriodicQueryNode(func, new Join());
    Assert.assertEquals(true, node1.isPresent());
    double window = 1 * 60 * 60 * 1000;
    double period = .5 * 3600 * 1000;
    PeriodicQueryNode node2 = new PeriodicQueryNode((long) window, (long) period, TimeUnit.MILLISECONDS, "time", new Join());
    Assert.assertEquals(true, periodicNodesEqualIgnoreArg(node1.get(), node2));
}
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)

Example 7 with FunctionCall

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

the class PeriodicQueryUtilTest method periodicNodePresentTest.

@Test
public void periodicNodePresentTest() 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(PeriodicQueryUtil.PeriodicQueryURI, values);
    Optional<PeriodicQueryNode> node1 = PeriodicQueryUtil.getPeriodicQueryNode(func, new Join());
    Assert.assertEquals(true, node1.isPresent());
    PeriodicQueryNode node2 = new PeriodicQueryNode(12 * 60 * 60 * 1000L, 6 * 3600 * 1000L, TimeUnit.MILLISECONDS, "time", new Join());
    Assert.assertEquals(true, periodicNodesEqualIgnoreArg(node1.get(), node2));
}
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)

Example 8 with FunctionCall

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

the class GeoTemporalIndexSetProvider method discoverPatterns.

private void discoverPatterns(final StatementPattern pattern, final List<QueryModelNode> unmatched) {
    final Var subj = pattern.getSubjectVar();
    final Var objVar = pattern.getObjectVar();
    patternMap.put(subj, pattern);
    objectPatterns.put(objVar, pattern);
    // check for existing filters.
    if (unmatchedFilters.containsKey(objVar)) {
        final Collection<FunctionCall> calls = unmatchedFilters.removeAll(objVar);
        for (final FunctionCall call : calls) {
            addFilter(call);
            matchedFilters.put(objVar, call);
        }
    }
}
Also used : Var(org.openrdf.query.algebra.Var) FunctionCall(org.openrdf.query.algebra.FunctionCall)

Example 9 with FunctionCall

use of org.openrdf.query.algebra.FunctionCall 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 10 with FunctionCall

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

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