Strabon

changeset 1297:bff210fdab24

#46: Made Intersection function an aggregate function working
with a group by
author Stella Giannakopoulou <sgian@di.uoa.gr>
date Wed Nov 27 22:09:09 2013 +0200 (2013-11-27)
parents 279edd1144df
children 83c25ed69f94
files evaluation/src/main/java/org/openrdf/query/algebra/evaluation/iterator/StSPARQLGroupIterator.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/factories/GeneralDBBooleanExprFactory.java generaldb/src/main/java/org/openrdf/sail/generaldb/optimizers/GeneralDBSelectQueryOptimizer.java
line diff
     1.1 --- a/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/iterator/StSPARQLGroupIterator.java	Mon Oct 21 20:33:38 2013 +0300
     1.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/iterator/StSPARQLGroupIterator.java	Wed Nov 27 22:09:09 2013 +0200
     1.3 @@ -449,9 +449,17 @@
     1.4  				}
     1.5  				else if(function instanceof IntersectionFunc)
     1.6  				{
     1.7 -					leftArg = (StrabonPolyhedron) evaluateConstruct(((FunctionCall) expr).getArgs().get(0),prototype);
     1.8 -					rightArg = (StrabonPolyhedron) evaluateConstruct(((FunctionCall) expr).getArgs().get(1),prototype);
     1.9 -					return StrabonPolyhedron.intersection(leftArg, rightArg);
    1.10 +					if(((FunctionCall) expr).getArgs().size()==1)
    1.11 +					{
    1.12 +						//Aggregate!!! => Value ready in spatialAggregatesResults
    1.13 +						return new StrabonPolyhedron(spatialAggregatesResult.get(expr));
    1.14 +					}
    1.15 +					else
    1.16 +					{
    1.17 +						leftArg = (StrabonPolyhedron) evaluateConstruct(((FunctionCall) expr).getArgs().get(0),prototype);
    1.18 +						rightArg = (StrabonPolyhedron) evaluateConstruct(((FunctionCall) expr).getArgs().get(1),prototype);
    1.19 +						return StrabonPolyhedron.intersection(leftArg, rightArg);
    1.20 +					}
    1.21  				}
    1.22  				else if(function instanceof DifferenceFunc)
    1.23  				{
    1.24 @@ -510,13 +518,14 @@
    1.25  			computeAggregateFunctions(fc, bindingSet);
    1.26  		}
    1.27  
    1.28 -		//Currently: Either Union OR Extent
    1.29 +		//Currently: Either Union OR Extent OR Intersection
    1.30  		private void computeAggregateFunctions(ValueExpr expr, BindingSet bindingSet)
    1.31  		{
    1.32  			if(expr instanceof FunctionCall)
    1.33  			{
    1.34  				Function function = FunctionRegistry.getInstance().get(((FunctionCall) expr).getURI());
    1.35  				boolean condition = ((!(function instanceof UnionFunc) || !(((FunctionCall) expr).getArgs().size()==1))
    1.36 +						&& (!(function instanceof IntersectionFunc) || !(((FunctionCall) expr).getArgs().size()==1))
    1.37  						&&!(function instanceof ExtentFunc));
    1.38  				if(condition)
    1.39  				{
    1.40 @@ -574,6 +583,10 @@
    1.41  						{
    1.42  							this.spatialAggregatesResult.put((FunctionCall) expr, poly.getGeometry());
    1.43  						}
    1.44 +						else if(function instanceof IntersectionFunc)
    1.45 +						{
    1.46 +							this.spatialAggregatesResult.put((FunctionCall) expr, poly.getGeometry());
    1.47 +						}
    1.48  						else if(function instanceof ExtentFunc)
    1.49  						{
    1.50  							Geometry env = poly.getGeometry().getEnvelope();
    1.51 @@ -593,6 +606,15 @@
    1.52  							united.setSRID(poly.getGeometry().getSRID());
    1.53  							this.spatialAggregatesResult.put((FunctionCall) expr, united);
    1.54  						}
    1.55 +						else if(function instanceof IntersectionFunc)
    1.56 +						{
    1.57 +							//XXX possible issue with expressions like
    1.58 +							// ?x hasGeom sth^^4326
    1.59 +							// ?x hasGeom sthElse^^2100
    1.60 +							Geometry intersection = aggr.intersection(poly.getGeometry());
    1.61 +							intersection.setSRID(poly.getGeometry().getSRID());
    1.62 +							this.spatialAggregatesResult.put((FunctionCall) expr, intersection);
    1.63 +						}
    1.64  						else if(function instanceof ExtentFunc)
    1.65  						{
    1.66  							//XXX possible issue with expressions like 
     2.1 --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/factories/GeneralDBBooleanExprFactory.java	Mon Oct 21 20:33:38 2013 +0300
     2.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/factories/GeneralDBBooleanExprFactory.java	Wed Nov 27 22:09:09 2013 +0200
     2.3 @@ -130,6 +130,7 @@
     2.4  import org.openrdf.query.algebra.evaluation.function.spatial.stsparql.construct.ConvexHullFunc;
     2.5  import org.openrdf.query.algebra.evaluation.function.spatial.stsparql.construct.EnvelopeFunc;
     2.6  import org.openrdf.query.algebra.evaluation.function.spatial.stsparql.construct.UnionFunc;
     2.7 +import org.openrdf.query.algebra.evaluation.function.spatial.stsparql.construct.IntersectionFunc;
     2.8  import org.openrdf.query.algebra.evaluation.function.spatial.stsparql.metric.AreaFunc;
     2.9  import org.openrdf.query.algebra.evaluation.function.spatial.stsparql.relation.RelateFunc;
    2.10  import org.openrdf.query.algebra.helpers.QueryModelVisitorBase;
    2.11 @@ -874,7 +875,8 @@
    2.12  				&& !(function instanceof GeoSparqlConvexHullFunc)
    2.13  				&& !(function instanceof GeoSparqlEnvelopeFunc)
    2.14  				&& !(function instanceof Centroid)
    2.15 -				&& !(function instanceof UnionFunc && functionCall.getArgs().size()==1))
    2.16 +				&& !(function instanceof UnionFunc && functionCall.getArgs().size()==1)
    2.17 +				&& !(function instanceof IntersectionFunc && functionCall.getArgs().size()==1))
    2.18  		{
    2.19  			ValueExpr right = functionCall.getArgs().get(1);
    2.20  			if(right instanceof FunctionCall)
     3.1 --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/optimizers/GeneralDBSelectQueryOptimizer.java	Mon Oct 21 20:33:38 2013 +0300
     3.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/optimizers/GeneralDBSelectQueryOptimizer.java	Wed Nov 27 22:09:09 2013 +0200
     3.3 @@ -68,6 +68,7 @@
     3.4  import org.openrdf.query.algebra.evaluation.function.spatial.SpatialRelationshipFunc;
     3.5  import org.openrdf.query.algebra.evaluation.function.spatial.stsparql.aggregate.ExtentFunc;
     3.6  import org.openrdf.query.algebra.evaluation.function.spatial.stsparql.construct.BufferFunc;
     3.7 +import org.openrdf.query.algebra.evaluation.function.spatial.stsparql.construct.IntersectionFunc;
     3.8  import org.openrdf.query.algebra.evaluation.function.spatial.stsparql.construct.TransformFunc;
     3.9  import org.openrdf.query.algebra.evaluation.function.spatial.stsparql.construct.UnionFunc;
    3.10  import org.openrdf.sail.generaldb.GeneralDBValueFactory;
    3.11 @@ -1203,7 +1204,7 @@
    3.12  
    3.13  	/**
    3.14  	 * Function used recursively to specify whether the function call present in the select clause contains an aggregate
    3.15 -	 * of the form strdf:union(?aggrValue). 
    3.16 +	 * of the form strdf:union(?aggrValue) or strdf:intersection(?aggrValue). 
    3.17  	 * @param expr 
    3.18  	 * @return true if no aggregate is present, false otherwise.
    3.19  	 */
    3.20 @@ -1212,18 +1213,20 @@
    3.21  		if(expr instanceof FunctionCall)
    3.22  		{
    3.23  			Function function = FunctionRegistry.getInstance().get(((FunctionCall) expr).getURI());
    3.24 -			if((!(function instanceof UnionFunc) || !(((FunctionCall) expr).getArgs().size()==1))&&!(function instanceof ExtentFunc))
    3.25 +			if((!(function instanceof UnionFunc) || !(((FunctionCall) expr).getArgs().size()==1))
    3.26 +					&&(!(function instanceof IntersectionFunc) || !(((FunctionCall) expr).getArgs().size()==1))
    3.27 +					&&!(function instanceof ExtentFunc))
    3.28  			{
    3.29  				//Recursively check arguments
    3.30 -				boolean unionPresent = false;
    3.31 +				boolean aggregatePresent = false;
    3.32  				for(int i = 0 ; i< ((FunctionCall) expr).getArgs().size(); i++)
    3.33  				{
    3.34  					//ValueExpr tmp = ((FunctionCall) expr).getArgs().get(i);
    3.35  					//containsAggregateUnion = containsAggregateUnion || evaluateInDB(tmp);
    3.36  					//					noUnionPresent = noUnionPresent ^ evaluateInJava(((FunctionCall) expr).getArgs().get(i));
    3.37 -					unionPresent = unionPresent || evaluateInJava(((FunctionCall) expr).getArgs().get(i));
    3.38 +					aggregatePresent = aggregatePresent || evaluateInJava(((FunctionCall) expr).getArgs().get(i));
    3.39  				}
    3.40 -				return unionPresent;
    3.41 +				return aggregatePresent;
    3.42  			}
    3.43  			else
    3.44  			{
    3.45 @@ -1738,6 +1741,7 @@
    3.46  				Function function = FunctionRegistry.getInstance().get(((FunctionCall) expr).getURI());
    3.47  				//Aggregate Function
    3.48  				if(((function instanceof UnionFunc) && (((FunctionCall) expr).getArgs().size()==1))
    3.49 +						|| ((function instanceof IntersectionFunc) && (((FunctionCall) expr).getArgs().size()==1))
    3.50  						|| (function instanceof ExtentFunc))
    3.51  				{
    3.52  					GroupElem groupElem = new GroupElem("havingCondition"+(havingID++)+"-aggregateInside-", new Avg(expr));