Strabon
changeset 1445:49589da36a24
#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.
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.
author | Stella Giannakopoulou <sgian@di.uoa.gr> |
---|---|
date | Thu Dec 04 13:08:24 2014 +0200 (2014-12-04) |
parents | ebb6f2f3a12b |
children | 51f12bbf8cda |
files | evaluation/src/main/java/org/openrdf/query/algebra/evaluation/iterator/StSPARQLFilterIterator.java generaldb/src/main/java/org/openrdf/sail/generaldb/evaluation/GeneralDBEvaluation.java |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/iterator/StSPARQLFilterIterator.java Thu Dec 04 13:08:24 2014 +0200 1.3 @@ -0,0 +1,77 @@ 1.4 +/* 1.5 + * Copyright Aduna (http://www.aduna-software.com/) (c) 1997-2007. 1.6 + * 1.7 + * Licensed under the Aduna BSD-style license. 1.8 + */ 1.9 +package org.openrdf.query.algebra.evaluation.iterator; 1.10 + 1.11 +import java.util.Set; 1.12 + 1.13 +import info.aduna.iteration.CloseableIteration; 1.14 +import info.aduna.iteration.FilterIteration; 1.15 + 1.16 +import org.openrdf.query.BindingSet; 1.17 +import org.openrdf.query.QueryEvaluationException; 1.18 +import org.openrdf.query.algebra.Filter; 1.19 +import org.openrdf.query.algebra.SubQueryValueOperator; 1.20 +import org.openrdf.query.algebra.evaluation.EvaluationStrategy; 1.21 +import org.openrdf.query.algebra.evaluation.QueryBindingSet; 1.22 +import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException; 1.23 + 1.24 +public class StSPARQLFilterIterator extends FilterIteration<BindingSet, QueryEvaluationException> { 1.25 + 1.26 + /*-----------* 1.27 + * Constants * 1.28 + *-----------*/ 1.29 + 1.30 + private final Filter filter; 1.31 + 1.32 + private final EvaluationStrategy strategy; 1.33 + 1.34 + /*addition for spatial constructs in filter 1.35 + * 1.36 + */ 1.37 + private final Set<String> scopeBindingNames; 1.38 + 1.39 + /*--------------* 1.40 + * Constructors * 1.41 + *--------------*/ 1.42 + 1.43 + public StSPARQLFilterIterator(Filter filter, CloseableIteration<BindingSet, QueryEvaluationException> iter, 1.44 + Set<String> spatialConstructs, EvaluationStrategy strategy) 1.45 + throws QueryEvaluationException 1.46 + { 1.47 + super(iter); 1.48 + this.filter = filter; 1.49 + this.strategy = strategy; 1.50 + this.scopeBindingNames = filter.getBindingNames(); 1.51 + this.scopeBindingNames.addAll(spatialConstructs); 1.52 + } 1.53 + 1.54 + /*---------* 1.55 + * Methods * 1.56 + *---------*/ 1.57 + 1.58 + @Override 1.59 + protected boolean accept(BindingSet bindings) 1.60 + throws QueryEvaluationException 1.61 + { 1.62 + try { 1.63 + // Limit the bindings to the ones that are in scope for this filter 1.64 + QueryBindingSet scopeBindings = new QueryBindingSet(bindings); 1.65 + 1.66 + // FIXME J1 scopeBindingNames should include bindings from superquery if the filter 1.67 + // is part of a subquery. This is a workaround: we should fix the settings of scopeBindingNames, 1.68 + // rather than skipping the limiting of bindings. 1.69 + if (!(filter.getParentNode() instanceof SubQueryValueOperator)) { 1.70 + scopeBindings.retainAll(scopeBindingNames); 1.71 + } 1.72 + 1.73 + return strategy.isTrue(filter.getCondition(), scopeBindings); 1.74 + } 1.75 + catch (ValueExprEvaluationException e) { 1.76 + // failed to evaluate condition 1.77 + return false; 1.78 + } 1.79 + } 1.80 +}
2.1 --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/evaluation/GeneralDBEvaluation.java Thu Oct 30 15:54:10 2014 +0200 2.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/evaluation/GeneralDBEvaluation.java Thu Dec 04 13:08:24 2014 +0200 2.3 @@ -14,9 +14,11 @@ 2.4 import java.util.ArrayList; 2.5 import java.util.Collection; 2.6 import java.util.HashMap; 2.7 +import java.util.HashSet; 2.8 import java.util.Iterator; 2.9 import java.util.List; 2.10 import java.util.Map; 2.11 +import java.util.Set; 2.12 2.13 import org.openrdf.model.Literal; 2.14 import org.openrdf.model.Value; 2.15 @@ -30,6 +32,7 @@ 2.16 import org.openrdf.query.QueryEvaluationException; 2.17 import org.openrdf.query.algebra.Avg; 2.18 import org.openrdf.query.algebra.Distinct; 2.19 +import org.openrdf.query.algebra.Filter; 2.20 import org.openrdf.query.algebra.FunctionCall; 2.21 import org.openrdf.query.algebra.Group; 2.22 import org.openrdf.query.algebra.GroupElem; 2.23 @@ -83,7 +86,9 @@ 2.24 import org.openrdf.query.algebra.evaluation.function.spatial.stsparql.relation.mbb.MbbIntersectsFunc; 2.25 import org.openrdf.query.algebra.evaluation.function.spatial.stsparql.relation.mbb.MbbWithinFunc; 2.26 import org.openrdf.query.algebra.evaluation.impl.EvaluationStrategyImpl; 2.27 +import org.openrdf.query.algebra.evaluation.iterator.FilterIterator; 2.28 import org.openrdf.query.algebra.evaluation.iterator.OrderIterator; 2.29 +import org.openrdf.query.algebra.evaluation.iterator.StSPARQLFilterIterator; 2.30 import org.openrdf.query.algebra.evaluation.iterator.StSPARQLGroupIterator; 2.31 import org.openrdf.query.algebra.evaluation.util.JTSWrapper; 2.32 import org.openrdf.query.algebra.evaluation.util.StSPARQLOrderComparator; 2.33 @@ -513,6 +518,23 @@ 2.34 } 2.35 } 2.36 2.37 + /*Evaluation of Filter*/ 2.38 + public CloseableIteration<BindingSet, QueryEvaluationException> evaluate(Filter filter, BindingSet bindings) 2.39 + throws QueryEvaluationException 2.40 + { 2.41 + CloseableIteration<BindingSet, QueryEvaluationException> result; 2.42 + result = this.evaluate(filter.getArg(), bindings); 2.43 + 2.44 + Set <String> spatialConstructs = new HashSet<String>(); 2.45 + for(GeneralDBSpatialFuncInfo construct : constructIndexesAndNames.keySet()) { 2.46 + spatialConstructs.add(construct.getFieldName()); 2.47 + } 2.48 + //add the spatial constructs to the scope of the FILTER (case of a BIND clause 2.49 + //that contains a spatial construct) 2.50 + result = new StSPARQLFilterIterator(filter, result, spatialConstructs, this); 2.51 + return result; 2.52 + } 2.53 + 2.54 /** 2.55 * @param leftResult 2.56 * @param rightResult