# HG changeset patch # User Stella Giannakopoulou # Date 1417691304 -7200 # Node ID 49589da36a24c65429670102db4e932fda64ba45 # Parent ebb6f2f3a12bf36307ac0c6ceb9663a78a183974 #78 fixed. The problem was that when a spatial construct was assigned to a variable using a BIND clause it was not visible to a FILTER. For this, I added the spatial constructs to the variables that are in scope during the evaluation of the FILTER by extending the FilterIterator. diff -r ebb6f2f3a12b -r 49589da36a24 evaluation/src/main/java/org/openrdf/query/algebra/evaluation/iterator/StSPARQLFilterIterator.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/iterator/StSPARQLFilterIterator.java Thu Dec 04 13:08:24 2014 +0200 @@ -0,0 +1,77 @@ +/* + * Copyright Aduna (http://www.aduna-software.com/) (c) 1997-2007. + * + * Licensed under the Aduna BSD-style license. + */ +package org.openrdf.query.algebra.evaluation.iterator; + +import java.util.Set; + +import info.aduna.iteration.CloseableIteration; +import info.aduna.iteration.FilterIteration; + +import org.openrdf.query.BindingSet; +import org.openrdf.query.QueryEvaluationException; +import org.openrdf.query.algebra.Filter; +import org.openrdf.query.algebra.SubQueryValueOperator; +import org.openrdf.query.algebra.evaluation.EvaluationStrategy; +import org.openrdf.query.algebra.evaluation.QueryBindingSet; +import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException; + +public class StSPARQLFilterIterator extends FilterIteration { + + /*-----------* + * Constants * + *-----------*/ + + private final Filter filter; + + private final EvaluationStrategy strategy; + + /*addition for spatial constructs in filter + * + */ + private final Set scopeBindingNames; + + /*--------------* + * Constructors * + *--------------*/ + + public StSPARQLFilterIterator(Filter filter, CloseableIteration iter, + Set spatialConstructs, EvaluationStrategy strategy) + throws QueryEvaluationException + { + super(iter); + this.filter = filter; + this.strategy = strategy; + this.scopeBindingNames = filter.getBindingNames(); + this.scopeBindingNames.addAll(spatialConstructs); + } + + /*---------* + * Methods * + *---------*/ + + @Override + protected boolean accept(BindingSet bindings) + throws QueryEvaluationException + { + try { + // Limit the bindings to the ones that are in scope for this filter + QueryBindingSet scopeBindings = new QueryBindingSet(bindings); + + // FIXME J1 scopeBindingNames should include bindings from superquery if the filter + // is part of a subquery. This is a workaround: we should fix the settings of scopeBindingNames, + // rather than skipping the limiting of bindings. + if (!(filter.getParentNode() instanceof SubQueryValueOperator)) { + scopeBindings.retainAll(scopeBindingNames); + } + + return strategy.isTrue(filter.getCondition(), scopeBindings); + } + catch (ValueExprEvaluationException e) { + // failed to evaluate condition + return false; + } + } +} diff -r ebb6f2f3a12b -r 49589da36a24 generaldb/src/main/java/org/openrdf/sail/generaldb/evaluation/GeneralDBEvaluation.java --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/evaluation/GeneralDBEvaluation.java Thu Oct 30 15:54:10 2014 +0200 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/evaluation/GeneralDBEvaluation.java Thu Dec 04 13:08:24 2014 +0200 @@ -14,9 +14,11 @@ import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; +import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Set; import org.openrdf.model.Literal; import org.openrdf.model.Value; @@ -30,6 +32,7 @@ import org.openrdf.query.QueryEvaluationException; import org.openrdf.query.algebra.Avg; import org.openrdf.query.algebra.Distinct; +import org.openrdf.query.algebra.Filter; import org.openrdf.query.algebra.FunctionCall; import org.openrdf.query.algebra.Group; import org.openrdf.query.algebra.GroupElem; @@ -83,7 +86,9 @@ import org.openrdf.query.algebra.evaluation.function.spatial.stsparql.relation.mbb.MbbIntersectsFunc; import org.openrdf.query.algebra.evaluation.function.spatial.stsparql.relation.mbb.MbbWithinFunc; import org.openrdf.query.algebra.evaluation.impl.EvaluationStrategyImpl; +import org.openrdf.query.algebra.evaluation.iterator.FilterIterator; import org.openrdf.query.algebra.evaluation.iterator.OrderIterator; +import org.openrdf.query.algebra.evaluation.iterator.StSPARQLFilterIterator; import org.openrdf.query.algebra.evaluation.iterator.StSPARQLGroupIterator; import org.openrdf.query.algebra.evaluation.util.JTSWrapper; import org.openrdf.query.algebra.evaluation.util.StSPARQLOrderComparator; @@ -513,6 +518,23 @@ } } + /*Evaluation of Filter*/ + public CloseableIteration evaluate(Filter filter, BindingSet bindings) + throws QueryEvaluationException + { + CloseableIteration result; + result = this.evaluate(filter.getArg(), bindings); + + Set spatialConstructs = new HashSet(); + for(GeneralDBSpatialFuncInfo construct : constructIndexesAndNames.keySet()) { + spatialConstructs.add(construct.getFieldName()); + } + //add the spatial constructs to the scope of the FILTER (case of a BIND clause + //that contains a spatial construct) + result = new StSPARQLFilterIterator(filter, result, spatialConstructs, this); + return result; + } + /** * @param leftResult * @param rightResult