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));
}
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));
}
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);
}
}
}
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;
}
}
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();
}
Aggregations