Strabon

changeset 368:031c493dd14c

some refactorings in GeneralDBEvaluation for the type of the result of function evaluation
author Babis Nikolaou <charnik@di.uoa.gr>
date Tue Jun 26 20:46:47 2012 +0300 (2012-06-26)
parents 5bc9b08e456f
children bbc219fdeeed
files generaldb/src/main/java/org/openrdf/sail/generaldb/GeneralDBSpatialFuncInfo.java generaldb/src/main/java/org/openrdf/sail/generaldb/evaluation/GeneralDBEvaluation.java generaldb/src/main/java/org/openrdf/sail/generaldb/iteration/GeneralDBBindingIteration.java
line diff
     1.1 --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/GeneralDBSpatialFuncInfo.java	Tue Jun 26 20:27:25 2012 +0300
     1.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/GeneralDBSpatialFuncInfo.java	Tue Jun 26 20:46:47 2012 +0300
     1.3 @@ -1,47 +1,39 @@
     1.4  package org.openrdf.sail.generaldb;
     1.5  
     1.6 +import org.openrdf.sail.generaldb.evaluation.GeneralDBEvaluation.ResultType;
     1.7 +
     1.8  /**
     1.9 + * Class used to store all info needed about a spatial construct / metric / property 
    1.10 + * located in select clause. Currently storing info about the name of the field that 
    1.11 + * has to be retrieved from the Result Set, as well as the type of the spatial function.
    1.12   * 
    1.13 - * @author manolee
    1.14 - * Class used to store all info needed about a spatial construct / metric / property located in select clause
    1.15 - * Currently storing info about the name of the field that has to be retrieved from the Result Set, 
    1.16 - * as well as the type of the spatial function 
    1.17 + * @author Manos Karpathiotakis <mk@di.uoa.gr>
    1.18   */
    1.19  public class GeneralDBSpatialFuncInfo {
    1.20 -	
    1.21 -	public enum typeOfField 
    1.22 -	{
    1.23 -			Integer,
    1.24 -			Double,
    1.25 -			Boolean,
    1.26 -			String,
    1.27 -			WKB
    1.28 -			;
    1.29 -	}
    1.30 -	
    1.31 -	
    1.32  
    1.33 -	public GeneralDBSpatialFuncInfo(String fieldName, typeOfField type) {
    1.34 -		super();
    1.35 +	private String fieldName;
    1.36 +	private ResultType type;
    1.37 +
    1.38 +	public GeneralDBSpatialFuncInfo(String fieldName, ResultType type) {
    1.39  		this.fieldName = fieldName;
    1.40  		this.type = type;
    1.41  	}
    1.42 -	private String fieldName;
    1.43 -	private typeOfField type;
    1.44 +	
    1.45  	public String getFieldName() {
    1.46  		return fieldName;
    1.47  	}
    1.48 +	
    1.49  	public void setFieldName(String fieldName) {
    1.50  		this.fieldName = fieldName;
    1.51  	}
    1.52 -	public typeOfField getType() {
    1.53 +	
    1.54 +	public ResultType getType() {
    1.55  		return type;
    1.56  	}
    1.57 -	public void setType(typeOfField type) {
    1.58 +	
    1.59 +	public void setType(ResultType type) {
    1.60  		this.type = type;
    1.61  	}
    1.62 -	
    1.63 -	
    1.64  }
    1.65  
    1.66  
     2.1 --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/evaluation/GeneralDBEvaluation.java	Tue Jun 26 20:27:25 2012 +0300
     2.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/evaluation/GeneralDBEvaluation.java	Tue Jun 26 20:46:47 2012 +0300
     2.3 @@ -5,33 +5,15 @@
     2.4   */
     2.5  package org.openrdf.sail.generaldb.evaluation;
     2.6  
     2.7 -import static org.openrdf.sail.generaldb.algebra.base.GeneralDBExprSupport.geoBoundary;
     2.8 -import static org.openrdf.sail.generaldb.algebra.base.GeneralDBExprSupport.geoBuffer;
     2.9 -import static org.openrdf.sail.generaldb.algebra.base.GeneralDBExprSupport.geoConvexHull;
    2.10 -import static org.openrdf.sail.generaldb.algebra.base.GeneralDBExprSupport.geoDifference;
    2.11 -import static org.openrdf.sail.generaldb.algebra.base.GeneralDBExprSupport.geoEnvelope;
    2.12 -import static org.openrdf.sail.generaldb.algebra.base.GeneralDBExprSupport.geoIntersection;
    2.13 -import static org.openrdf.sail.generaldb.algebra.base.GeneralDBExprSupport.geoSymDifference;
    2.14 -import static org.openrdf.sail.generaldb.algebra.base.GeneralDBExprSupport.geoUnion;
    2.15 +import info.aduna.iteration.CloseableIteration;
    2.16  
    2.17 -import java.sql.Connection;
    2.18 -import java.sql.PreparedStatement;
    2.19 -import java.sql.SQLException;
    2.20  import java.util.ArrayList;
    2.21  import java.util.Collection;
    2.22  import java.util.HashMap;
    2.23  import java.util.Iterator;
    2.24  import java.util.List;
    2.25  import java.util.Map;
    2.26 -import java.util.Set;
    2.27  
    2.28 -import org.slf4j.Logger;
    2.29 -import org.slf4j.LoggerFactory;
    2.30 -
    2.31 -import info.aduna.iteration.CloseableIteration;
    2.32 -import info.aduna.iteration.EmptyIteration;
    2.33 -
    2.34 -import org.opengis.filter.spatial.Disjoint;
    2.35  import org.openrdf.model.Literal;
    2.36  import org.openrdf.model.Value;
    2.37  import org.openrdf.model.impl.BooleanLiteralImpl;
    2.38 @@ -42,8 +24,6 @@
    2.39  import org.openrdf.query.QueryEvaluationException;
    2.40  import org.openrdf.query.algebra.Avg;
    2.41  import org.openrdf.query.algebra.Distinct;
    2.42 -import org.openrdf.query.algebra.Extension;
    2.43 -import org.openrdf.query.algebra.ExtensionElem;
    2.44  import org.openrdf.query.algebra.FunctionCall;
    2.45  import org.openrdf.query.algebra.Group;
    2.46  import org.openrdf.query.algebra.GroupElem;
    2.47 @@ -52,7 +32,6 @@
    2.48  import org.openrdf.query.algebra.Reduced;
    2.49  import org.openrdf.query.algebra.Slice;
    2.50  import org.openrdf.query.algebra.TupleExpr;
    2.51 -import org.openrdf.query.algebra.ValueConstant;
    2.52  import org.openrdf.query.algebra.ValueExpr;
    2.53  import org.openrdf.query.algebra.Var;
    2.54  import org.openrdf.query.algebra.evaluation.QueryBindingSet;
    2.55 @@ -60,15 +39,8 @@
    2.56  import org.openrdf.query.algebra.evaluation.function.Function;
    2.57  import org.openrdf.query.algebra.evaluation.function.FunctionRegistry;
    2.58  import org.openrdf.query.algebra.evaluation.function.spatial.SpatialConstructFunc;
    2.59 -import org.openrdf.query.algebra.evaluation.function.spatial.SpatialPropertyFunc;
    2.60  import org.openrdf.query.algebra.evaluation.function.spatial.SpatialRelationshipFunc;
    2.61  import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPolyhedron;
    2.62 -import org.openrdf.query.algebra.evaluation.function.spatial.geosparql.nontopological.GeoSparqlBoundaryFunc;
    2.63 -import org.openrdf.query.algebra.evaluation.function.spatial.geosparql.nontopological.GeoSparqlConvexHullFunc;
    2.64 -import org.openrdf.query.algebra.evaluation.function.spatial.geosparql.nontopological.GeoSparqlEnvelopeFunc;
    2.65 -import org.openrdf.query.algebra.evaluation.function.spatial.stsparql.construct.BoundaryFunc;
    2.66 -import org.openrdf.query.algebra.evaluation.function.spatial.stsparql.construct.ConvexHullFunc;
    2.67 -import org.openrdf.query.algebra.evaluation.function.spatial.stsparql.construct.EnvelopeFunc;
    2.68  import org.openrdf.query.algebra.evaluation.function.spatial.stsparql.relation.AboveFunc;
    2.69  import org.openrdf.query.algebra.evaluation.function.spatial.stsparql.relation.AnyInteractFunc;
    2.70  import org.openrdf.query.algebra.evaluation.function.spatial.stsparql.relation.BelowFunc;
    2.71 @@ -83,13 +55,11 @@
    2.72  import org.openrdf.query.algebra.evaluation.function.spatial.stsparql.relation.RightFunc;
    2.73  import org.openrdf.query.algebra.evaluation.function.spatial.stsparql.relation.TouchFunc;
    2.74  import org.openrdf.query.algebra.evaluation.impl.EvaluationStrategyImpl;
    2.75 +import org.openrdf.query.algebra.evaluation.iterator.OrderIterator;
    2.76  import org.openrdf.query.algebra.evaluation.iterator.StSPARQLGroupIterator;
    2.77 -import org.openrdf.query.algebra.evaluation.iterator.OrderIterator;
    2.78  import org.openrdf.query.algebra.evaluation.util.JTSWrapper;
    2.79  import org.openrdf.query.algebra.evaluation.util.StSPARQLOrderComparator;
    2.80 -import org.openrdf.sail.generaldb.util.StSPARQLValueComparator;
    2.81  import org.openrdf.sail.generaldb.GeneralDBSpatialFuncInfo;
    2.82 -import org.openrdf.sail.generaldb.GeneralDBSpatialFuncInfo.typeOfField;
    2.83  import org.openrdf.sail.generaldb.GeneralDBTripleRepository;
    2.84  import org.openrdf.sail.generaldb.GeneralDBValueFactory;
    2.85  import org.openrdf.sail.generaldb.algebra.GeneralDBColumnVar;
    2.86 @@ -98,32 +68,34 @@
    2.87  import org.openrdf.sail.generaldb.algebra.GeneralDBNumericColumn;
    2.88  import org.openrdf.sail.generaldb.algebra.GeneralDBSelectProjection;
    2.89  import org.openrdf.sail.generaldb.algebra.GeneralDBSelectQuery;
    2.90 +import org.openrdf.sail.generaldb.algebra.GeneralDBSelectQuery.OrderElem;
    2.91  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlCase;
    2.92 -import org.openrdf.sail.generaldb.algebra.GeneralDBSqlDisjoint;
    2.93  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlGeoAsText;
    2.94  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlGeoDimension;
    2.95  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlGeoGeometryType;
    2.96  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlGeoIsEmpty;
    2.97  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlGeoIsSimple;
    2.98  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlGeoSrid;
    2.99 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlIsNull;
   2.100  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlMathExpr;
   2.101 -import org.openrdf.sail.generaldb.algebra.GeneralDBSqlIsNull;
   2.102  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlNot;
   2.103 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlSpatialConstructBinary;
   2.104  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlSpatialConstructUnary;
   2.105  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlSpatialMetricBinary;
   2.106  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlSpatialMetricUnary;
   2.107  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlSpatialProperty;
   2.108 -import org.openrdf.sail.generaldb.algebra.GeneralDBSelectQuery.OrderElem;
   2.109 -import org.openrdf.sail.generaldb.algebra.GeneralDBSqlSpatialConstructBinary;
   2.110  import org.openrdf.sail.generaldb.algebra.GeneralDBURIColumn;
   2.111  import org.openrdf.sail.generaldb.algebra.base.GeneralDBSqlExpr;
   2.112  import org.openrdf.sail.generaldb.model.GeneralDBPolyhedron;
   2.113 +import org.openrdf.sail.generaldb.schema.IdSequence;
   2.114 +import org.openrdf.sail.generaldb.util.StSPARQLValueComparator;
   2.115  import org.openrdf.sail.rdbms.exceptions.RdbmsException;
   2.116  import org.openrdf.sail.rdbms.exceptions.RdbmsQueryEvaluationException;
   2.117  import org.openrdf.sail.rdbms.exceptions.UnsupportedRdbmsOperatorException;
   2.118  import org.openrdf.sail.rdbms.model.RdbmsLiteral;
   2.119  import org.openrdf.sail.rdbms.model.RdbmsURI;
   2.120 -import org.openrdf.sail.generaldb.schema.IdSequence;
   2.121 +import org.slf4j.Logger;
   2.122 +import org.slf4j.LoggerFactory;
   2.123  
   2.124  import com.vividsolutions.jts.geom.Geometry;
   2.125  
   2.126 @@ -131,8 +103,7 @@
   2.127   * Extends the default strategy by accepting {@link GeneralDBSelectQuery} and evaluating
   2.128   * them on a database.
   2.129   * 
   2.130 - * @author James Leigh
   2.131 - * 
   2.132 + * @author Manos Karpathiotakis <mk@di.uoa.gr>
   2.133   */
   2.134  public abstract class GeneralDBEvaluation extends EvaluationStrategyImpl {
   2.135  
   2.136 @@ -149,6 +120,12 @@
   2.137  	protected HashMap<Integer,String> geoNames = new HashMap<Integer,String>();
   2.138  
   2.139  	protected List<GeneralDBSqlExpr> thematicExpressions = new ArrayList<GeneralDBSqlExpr>(5);
   2.140 +	
   2.141 +	/**
   2.142 +	 * Enumeration of the possible types of the results of spatial functions.
   2.143 +	 * A <tt>NULL</tt> result type is to be interpreted as error.   
   2.144 +	 */ 
   2.145 +	public enum ResultType { INTEGER, STRING, BOOLEAN, WKB, DOUBLE, NULL};
   2.146  
   2.147  	//used to retrieve the appropriate column in the Binding Iteration
   2.148  	protected HashMap<GeneralDBSpatialFuncInfo, Integer> constructIndexesAndNames = new HashMap<GeneralDBSpatialFuncInfo, Integer>();
   2.149 @@ -183,7 +160,8 @@
   2.150  			return evaluate((Order)expr, bindings);
   2.151  		}
   2.152  		return super.evaluate(expr, bindings);
   2.153 -					}
   2.154 +	}
   2.155 +	
   2.156  	@Override
   2.157  	public Value evaluate(ValueExpr expr, BindingSet bindings)
   2.158  			throws ValueExprEvaluationException, QueryEvaluationException
   2.159 @@ -750,30 +728,14 @@
   2.160  				boolean increaseIndex = false;
   2.161  
   2.162  				GeneralDBSpatialFuncInfo info = null;
   2.163 -				switch(constructReturnType(expr))
   2.164 -				{
   2.165 -				case 1:
   2.166 -					//Integer
   2.167 -					info = new GeneralDBSpatialFuncInfo((String) pairs.getKey(), typeOfField.Integer);
   2.168 -					break;
   2.169 -				case 2: 
   2.170 -					//String
   2.171 -					info = new GeneralDBSpatialFuncInfo((String) pairs.getKey(), typeOfField.String);
   2.172 -					break;
   2.173 -				case 3: 
   2.174 -					//Boolean
   2.175 -					info = new GeneralDBSpatialFuncInfo((String) pairs.getKey(), typeOfField.Boolean);
   2.176 -					break;
   2.177 -				case 4: 
   2.178 -					//WKB
   2.179 -					info = new GeneralDBSpatialFuncInfo((String) pairs.getKey(), typeOfField.WKB);
   2.180 -					increaseIndex = true;
   2.181 -					break;
   2.182 -				case 5: 
   2.183 -					//DOUBLE
   2.184 -					info = new GeneralDBSpatialFuncInfo((String) pairs.getKey(), typeOfField.Double);
   2.185 -					break;
   2.186 -				default: throw new UnsupportedRdbmsOperatorException("No such spatial expression exists!");
   2.187 +				
   2.188 +				ResultType type = getResultType(expr);
   2.189 +				if (type == ResultType.NULL) {
   2.190 +					throw new UnsupportedRdbmsOperatorException("No such spatial expression exists!");
   2.191 +					
   2.192 +				} else {
   2.193 +					info = new GeneralDBSpatialFuncInfo((String) pairs.getKey(), type);
   2.194 +					
   2.195  				}
   2.196  
   2.197  				//constructIndexesAndNames.put((String) pairs.getKey(),index++);
   2.198 @@ -801,10 +763,7 @@
   2.199  			query.offset(qb.getOffset());
   2.200  		}
   2.201  		parameters.addAll(query.getParameters());
   2.202 -//		if (logger.isDebugEnabled()) {
   2.203 -//			logger.debug(query.toString());
   2.204 -//			logger.debug(parameters.toString());
   2.205 -//		}
   2.206 +
   2.207  		return query.toString();
   2.208  	}
   2.209  
   2.210 @@ -962,38 +921,38 @@
   2.211  	 * @param expr
   2.212  	 * @return
   2.213  	 */
   2.214 -	private int constructReturnType(GeneralDBSqlExpr expr)
   2.215 +	private ResultType getResultType(GeneralDBSqlExpr expr)
   2.216  	{
   2.217  		if(expr instanceof GeneralDBSqlSpatialProperty)
   2.218  		{
   2.219  			if(expr instanceof GeneralDBSqlGeoDimension ||
   2.220  					expr instanceof GeneralDBSqlGeoSrid	)
   2.221  			{
   2.222 -				return 1; //INTEGER
   2.223 +				return ResultType.INTEGER;
   2.224  			}
   2.225  			else if(expr instanceof GeneralDBSqlGeoGeometryType ||
   2.226  					expr instanceof GeneralDBSqlGeoAsText	)
   2.227  			{
   2.228 -				return 2; //STRING
   2.229 +				return ResultType.STRING;
   2.230  			}
   2.231  			else if(expr instanceof GeneralDBSqlGeoIsSimple ||
   2.232  					expr instanceof GeneralDBSqlGeoIsEmpty	)
   2.233  			{
   2.234 -				return 3; //Boolean
   2.235 +				return ResultType.BOOLEAN;
   2.236  			}
   2.237  
   2.238  		}
   2.239  		else if(expr instanceof GeneralDBSqlSpatialConstructBinary ||
   2.240  				expr instanceof GeneralDBSqlSpatialConstructUnary)
   2.241  		{
   2.242 -			return 4; //WKB
   2.243 +			return ResultType.WKB;
   2.244  		}
   2.245  		else if(expr instanceof GeneralDBSqlSpatialMetricBinary ||
   2.246  				expr instanceof GeneralDBSqlSpatialMetricUnary ||
   2.247  				expr instanceof GeneralDBSqlMathExpr)
   2.248  		{
   2.249 -			return 5; //FLOAT
   2.250 +			return ResultType.DOUBLE;
   2.251  		}
   2.252 -		return 0;//SHOULD NEVER REACH THIS CASE
   2.253 +		return ResultType.NULL;//SHOULD NEVER REACH THIS CASE
   2.254  	}
   2.255  }
     3.1 --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/iteration/GeneralDBBindingIteration.java	Tue Jun 26 20:27:25 2012 +0300
     3.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/iteration/GeneralDBBindingIteration.java	Tue Jun 26 20:46:47 2012 +0300
     3.3 @@ -158,16 +158,16 @@
     3.4  			Value value = null;
     3.5  			switch(construct.getType())
     3.6  			{
     3.7 -			case Boolean: 
     3.8 +			case BOOLEAN: 
     3.9  				value = createBooleanGeoValueForSelectConstructs(rs, sp_ConstructIndexesAndNames.get(construct));
    3.10  				break;
    3.11 -			case Double: 
    3.12 +			case DOUBLE: 
    3.13  				value = createDoubleGeoValueForSelectConstructs(rs, sp_ConstructIndexesAndNames.get(construct));
    3.14  				break;
    3.15 -			case Integer: 
    3.16 +			case INTEGER: 
    3.17  				value = createIntegerGeoValueForSelectConstructs(rs, sp_ConstructIndexesAndNames.get(construct));
    3.18  				break;
    3.19 -			case String: 
    3.20 +			case STRING: 
    3.21  				value = createStringGeoValueForSelectConstructs(rs, sp_ConstructIndexesAndNames.get(construct));
    3.22  				break;
    3.23  			case WKB: