Strabon

changeset 46:b74d143a7ef7

Seems that SRID has been correctly retrieved without further issues caused to the query string.
Will now attempt to appropriately create the Strabon Polyhedron
author Manos Karpathiotakis <mk@di.uoa.gr>
date Tue Mar 13 18:39:36 2012 +0200 (2012-03-13)
parents 7bbf921b454d
children 59d921de8db6
files generaldb/src/main/java/org/openrdf/sail/generaldb/evaluation/GeneralDBEvaluation.java postgis/src/main/java/org/openrdf/sail/postgis/evaluation/PostGISQueryBuilder.java
line diff
     1.1 --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/evaluation/GeneralDBEvaluation.java	Mon Mar 12 14:27:44 2012 +0200
     1.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/evaluation/GeneralDBEvaluation.java	Tue Mar 13 18:39:36 2012 +0200
     1.3 @@ -169,8 +169,8 @@
     1.4  	@Override
     1.5  	public CloseableIteration<BindingSet, QueryEvaluationException> evaluate(TupleExpr expr,
     1.6  			BindingSet bindings)
     1.7 -			throws QueryEvaluationException
     1.8 -			{
     1.9 +					throws QueryEvaluationException
    1.10 +					{
    1.11  		if (expr instanceof GeneralDBSelectQuery)
    1.12  			return evaluate((GeneralDBSelectQuery)expr, bindings);
    1.13  		else if (expr instanceof Group) {
    1.14 @@ -180,11 +180,11 @@
    1.15  			return evaluate((Order)expr, bindings);
    1.16  		}
    1.17  		return super.evaluate(expr, bindings);
    1.18 -			}
    1.19 +					}
    1.20  	@Override
    1.21  	public Value evaluate(ValueExpr expr, BindingSet bindings)
    1.22 -	throws ValueExprEvaluationException, QueryEvaluationException
    1.23 -	{
    1.24 +			throws ValueExprEvaluationException, QueryEvaluationException
    1.25 +			{
    1.26  		if (expr instanceof Var) {
    1.27  			return evaluate((Var)expr, bindings);
    1.28  		}
    1.29 @@ -192,7 +192,7 @@
    1.30  			return evaluate((FunctionCall)expr, bindings);
    1.31  		}
    1.32  		return super.evaluate(expr, bindings);
    1.33 -	}
    1.34 +			}
    1.35  
    1.36  	/**
    1.37  	 * Had to use it for the cases met in group by (Union as an aggregate)
    1.38 @@ -245,7 +245,7 @@
    1.39  	@Override
    1.40  	public Value evaluate(FunctionCall fc, BindingSet bindings)
    1.41  	{
    1.42 -//		System.out.println("FunctionCall placeholder");
    1.43 +		//		System.out.println("FunctionCall placeholder");
    1.44  
    1.45  		if(fc.getParentNode() instanceof Avg)
    1.46  		{
    1.47 @@ -428,7 +428,7 @@
    1.48  				return funcResult ? BooleanLiteralImpl.TRUE : BooleanLiteralImpl.FALSE;
    1.49  			}
    1.50  			else {
    1.51 -			//Default Sesame Behavior
    1.52 +				//Default Sesame Behavior
    1.53  				List<ValueExpr> args = fc.getArgs();
    1.54  
    1.55  				Value[] argValues = new Value[args.size()];
    1.56 @@ -501,8 +501,8 @@
    1.57  
    1.58  	@Override
    1.59  	public CloseableIteration<BindingSet, QueryEvaluationException> evaluate(Group node, BindingSet bindings)
    1.60 -	throws QueryEvaluationException
    1.61 -	{
    1.62 +			throws QueryEvaluationException
    1.63 +			{
    1.64  		//		Set<String> tmp1 = node.getAggregateBindingNames();
    1.65  		//		Set<String> tmp2 = node.getAssuredBindingNames();
    1.66  		//		Set<String> tmp3 = node.getBindingNames();
    1.67 @@ -512,18 +512,18 @@
    1.68  		//			//System.out.println(node.g);
    1.69  		//		}
    1.70  		return new StSPARQLGroupIterator(this, node, bindings);
    1.71 -	}
    1.72 +			}
    1.73  
    1.74  	@Override
    1.75  	public CloseableIteration<BindingSet, QueryEvaluationException> evaluate(Order node, BindingSet bindings)
    1.76 -	throws QueryEvaluationException
    1.77 -	{
    1.78 +			throws QueryEvaluationException
    1.79 +			{
    1.80  		StSPARQLValueComparator vcmp = new StSPARQLValueComparator();
    1.81  		StSPARQLOrderComparator cmp = new StSPARQLOrderComparator(this, node, vcmp);
    1.82  		boolean reduced = isReduced(node);
    1.83  		long limit = getLimit(node);
    1.84  		return new OrderIterator(evaluate(node.getArg(), bindings), cmp, limit, reduced);
    1.85 -	}
    1.86 +			}
    1.87  
    1.88  	//Duplicated from EvaluationStrategyImpl
    1.89  	private boolean isReduced(QueryModelNode node) {
    1.90 @@ -606,11 +606,11 @@
    1.91  	//	}
    1.92  
    1.93  	protected abstract CloseableIteration<BindingSet, QueryEvaluationException> evaluate(GeneralDBSelectQuery qb, BindingSet b)
    1.94 -	throws UnsupportedRdbmsOperatorException, RdbmsQueryEvaluationException;
    1.95 +			throws UnsupportedRdbmsOperatorException, RdbmsQueryEvaluationException;
    1.96  
    1.97  	protected String toQueryString(GeneralDBSelectQuery qb, QueryBindingSet bindings, List<Object> parameters)
    1.98 -	throws RdbmsException, UnsupportedRdbmsOperatorException
    1.99 -	{
   1.100 +			throws RdbmsException, UnsupportedRdbmsOperatorException
   1.101 +			{
   1.102  		GeneralDBQueryBuilder query = factory.createQueryBuilder();
   1.103  		if (qb.isDistinct()) {
   1.104  			query.distinct();
   1.105 @@ -642,6 +642,8 @@
   1.106  						if(var.isSpatial())
   1.107  						{
   1.108  							this.geoNames.put(var.getIndex()+2,var.getName());
   1.109 +							//I am carrying SRID too! Therefore, shifting index one more position
   1.110 +							index++;
   1.111  						}
   1.112  						query.select(proj.getId());
   1.113  						query.select(proj.getStringValue());
   1.114 @@ -688,7 +690,7 @@
   1.115  			if(!this.thematicExpressions.contains(expr))
   1.116  			{
   1.117  				query.construct(expr);
   1.118 -
   1.119 +				boolean increaseIndex = false;
   1.120  
   1.121  				GeneralDBSpatialFuncInfo info = null;
   1.122  				switch(constructReturnType(expr))
   1.123 @@ -708,6 +710,7 @@
   1.124  				case 4: 
   1.125  					//WKB
   1.126  					info = new GeneralDBSpatialFuncInfo((String) pairs.getKey(), typeOfField.WKB);
   1.127 +					increaseIndex = true;
   1.128  					break;
   1.129  				case 5: 
   1.130  					//DOUBLE
   1.131 @@ -718,6 +721,12 @@
   1.132  
   1.133  				//constructIndexesAndNames.put((String) pairs.getKey(),index++);
   1.134  				constructIndexesAndNames.put(info,index++);
   1.135 +				if(increaseIndex)
   1.136 +				{
   1.137 +					//Increasing index by one more because of SRID!
   1.138 +					//However, only in the case when the result is some geometry (e.g. not for metrics)
   1.139 +					index++;
   1.140 +				}
   1.141  			}
   1.142  		}
   1.143  		//
   1.144 @@ -740,7 +749,7 @@
   1.145  			logger.debug(parameters.toString());
   1.146  		}
   1.147  		return query.toString();
   1.148 -	}
   1.149 +			}
   1.150  
   1.151  	/**
   1.152  	 * Function used to locate all ColumnVars from the select's spatial constructs so that they can later 
     2.1 --- a/postgis/src/main/java/org/openrdf/sail/postgis/evaluation/PostGISQueryBuilder.java	Mon Mar 12 14:27:44 2012 +0200
     2.2 +++ b/postgis/src/main/java/org/openrdf/sail/postgis/evaluation/PostGISQueryBuilder.java	Tue Mar 13 18:39:36 2012 +0200
     2.3 @@ -228,6 +228,9 @@
     2.4  				//
     2.5  				filter.closeBracket();
     2.6  
     2.7 +				//Adding srid field explicitly for my StrabonPolyhedron constructor later on!
     2.8 +				filter.appendComma();
     2.9 +				filter.column(alias, "srid");
    2.10  			}
    2.11  			else
    2.12  			{
    2.13 @@ -284,12 +287,12 @@
    2.14  			}
    2.15  
    2.16  	//FIXME my addition from here on
    2.17 -	
    2.18 +
    2.19  	//Issue with this function: crashes when MathExpr is present in Select but does not
    2.20  	//involve spatial variables! must escape this somehow
    2.21  	@Override
    2.22  	public GeneralDBQueryBuilder construct(GeneralDBSqlExpr expr) throws UnsupportedRdbmsOperatorException
    2.23 -			{
    2.24 +	{
    2.25  		if(!(expr instanceof GeneralDBSqlSpatialMetricBinary) 
    2.26  				&&!(expr instanceof GeneralDBSqlSpatialMetricUnary)
    2.27  				&&!(expr instanceof GeneralDBSqlMathExpr)
    2.28 @@ -309,8 +312,10 @@
    2.29  		{
    2.30  			dispatchUnarySqlOperator((UnaryGeneralDBOperator) expr, query.select);
    2.31  		}
    2.32 +		//SRID support must be explicitly added!
    2.33 +
    2.34  		return this;
    2.35 -			}
    2.36 +	}
    2.37  
    2.38  	//Spatial Relationship Functions
    2.39  	@Override
    2.40 @@ -786,7 +791,7 @@
    2.41  				{
    2.42  					appendMBB((GeneralDBLabelColumn)(expr.getArg()),filter);
    2.43  				}
    2.44 -	
    2.45 +
    2.46  				filter.closeBracket();
    2.47  			}
    2.48  			else
    2.49 @@ -797,7 +802,7 @@
    2.50  		}
    2.51  
    2.52  		filter.closeBracket();
    2.53 -	}
    2.54 +			}
    2.55  
    2.56  	@Override
    2.57  	protected void append(GeneralDBSqlGeoIsSimple expr, GeneralDBSqlExprBuilder filter)
    2.58 @@ -1016,6 +1021,8 @@
    2.59  	{
    2.60  		//In the case where no variable is present in the expression! e.g ConvexHull("POLYGON((.....))")
    2.61  		boolean sridNeeded = true;
    2.62 +		//XXX Incorporating SRID
    2.63 +		String sridExpr = null;
    2.64  		
    2.65  		filter.openBracket();
    2.66  
    2.67 @@ -1033,8 +1040,7 @@
    2.68  		}
    2.69  		else
    2.70  		{
    2.71 -			//XXX Incorporating SRID
    2.72 -			String sridExpr = null;
    2.73 +			
    2.74  			GeneralDBSqlExpr tmp = expr;
    2.75  			if(tmp instanceof GeneralDBSqlSpatialConstructBinary && tmp.getParentNode() == null)
    2.76  			{
    2.77 @@ -1175,8 +1181,14 @@
    2.78  			}
    2.79  			///
    2.80  		}
    2.81 -		//}
    2.82  		filter.closeBracket();
    2.83 +		//Used to explicitly include SRID
    2.84 +		if(expr instanceof GeneralDBSqlSpatialConstructBinary && expr.getParentNode() == null)
    2.85 +		{
    2.86 +			filter.appendComma();
    2.87 +			filter.append(sridExpr);
    2.88 +		}
    2.89 +		
    2.90  			}
    2.91  
    2.92  	//Used in all the generaldb boolean spatial functions of the form ST_Function(?GEO1) 
    2.93 @@ -1185,6 +1197,8 @@
    2.94  			{
    2.95  		//In the case where no variable is present in the expression! e.g ConvexHull("POLYGON((.....))")
    2.96  		boolean sridNeeded = true;
    2.97 +		String sridExpr = null;
    2.98 +
    2.99  		filter.openBracket();
   2.100  
   2.101  		boolean check1 = expr.getArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull");
   2.102 @@ -1207,8 +1221,7 @@
   2.103  		}
   2.104  		else
   2.105  		{
   2.106 -			//XXX Incorporating SRID
   2.107 -			String sridExpr = null;
   2.108 +
   2.109  			GeneralDBSqlExpr tmp = expr;
   2.110  
   2.111  
   2.112 @@ -1294,7 +1307,7 @@
   2.113  			}
   2.114  
   2.115  			filter.closeBracket();
   2.116 -			//SRID Support
   2.117 +//			//SRID Support
   2.118  			if(sridNeeded)
   2.119  			{
   2.120  				if(expr instanceof GeneralDBSqlSpatialConstructUnary && expr.getParentNode() == null)
   2.121 @@ -1309,7 +1322,13 @@
   2.122  		}
   2.123  
   2.124  		filter.closeBracket();
   2.125 -
   2.126 +		//Used to explicitly include SRID
   2.127 +		if(expr instanceof GeneralDBSqlSpatialConstructUnary && expr.getParentNode() == null)
   2.128 +		{
   2.129 +			filter.appendComma();
   2.130 +			filter.append(sridExpr);
   2.131 +		}
   2.132 +		
   2.133  			}
   2.134  
   2.135