Strabon

changeset 1396:63037c4974c5

Fixed bug #71
author Babis Nikolaou <charnik@di.uoa.gr>
date Fri Sep 19 02:45:20 2014 +0300 (2014-09-19)
parents 85a06bbfd1b8
children 42f26a9fe609
files generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBSelectQuery.java generaldb/src/main/java/org/openrdf/sail/generaldb/evaluation/GeneralDBEvaluation.java generaldb/src/main/java/org/openrdf/sail/generaldb/optimizers/GeneralDBSelectQueryOptimizer.java generaldb/src/main/java/org/openrdf/sail/generaldb/optimizers/GeneralDBValueJoinOptimizer.java postgis/src/main/java/org/openrdf/sail/postgis/iteration/PostGISBindingIteration.java
line diff
     1.1 --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBSelectQuery.java	Thu Sep 18 19:50:53 2014 +0300
     1.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBSelectQuery.java	Fri Sep 19 02:45:20 2014 +0300
     1.3 @@ -50,7 +50,6 @@
     1.4  	/**
     1.5  	 * XXX addition for spatial constructs in select
     1.6  	 */
     1.7 -	
     1.8  	private Map<String, GeneralDBSqlExpr> spatialConstructs = new HashMap<String, GeneralDBSqlExpr>();
     1.9  	
    1.10  	//Extra addition for true spatial selections and joins in FROM clause - 07/09/2011
     2.1 --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/evaluation/GeneralDBEvaluation.java	Thu Sep 18 19:50:53 2014 +0300
     2.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/evaluation/GeneralDBEvaluation.java	Fri Sep 19 02:45:20 2014 +0300
     2.3 @@ -835,8 +835,6 @@
     2.4  			}
     2.5  		}
     2.6  
     2.7 -
     2.8 -
     2.9  		//XXX Attention: Will try to add projections in select for the constructs
    2.10  		Iterator it = qb.getSpatialConstructs().entrySet().iterator();
    2.11  		while (it.hasNext()) {
     3.1 --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/optimizers/GeneralDBSelectQueryOptimizer.java	Thu Sep 18 19:50:53 2014 +0300
     3.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/optimizers/GeneralDBSelectQueryOptimizer.java	Fri Sep 19 02:45:20 2014 +0300
     3.3 @@ -104,8 +104,7 @@
     3.4  /**
     3.5   * Rewrites the core algebra model with a relation optimised model, using SQL.
     3.6   * 
     3.7 - * @author James Leigh
     3.8 - * 
     3.9 + * @author Manos Karpathiotakis <mk@di.uoa.gr.
    3.10   */
    3.11  public class GeneralDBSelectQueryOptimizer extends GeneralDBQueryModelVisitorBase<RuntimeException> 
    3.12  //implements QueryOptimizer //removed it consciously
    3.13 @@ -142,9 +141,6 @@
    3.14  
    3.15  	//Counter used to enumerate expressions in having
    3.16  	private int havingID = 1;
    3.17 -	/**
    3.18 -	 * 
    3.19 -	 */
    3.20  
    3.21  	private static final String ALIAS = "t";
    3.22  
    3.23 @@ -198,9 +194,8 @@
    3.24  			}
    3.25  
    3.26  	@Override
    3.27 -	public void meet(Union node)
    3.28 -			throws RuntimeException
    3.29 -			{
    3.30 +	public void meet(Union node) throws RuntimeException
    3.31 +	{
    3.32  		super.meet(node);
    3.33  		TupleExpr l = node.getLeftArg();
    3.34  		TupleExpr r = node.getRightArg();
    3.35 @@ -220,7 +215,7 @@
    3.36  		mergeSelectClause(query, right);
    3.37  		addProjectionsFromUnion(query, union);
    3.38  		node.replaceWith(query);
    3.39 -			}
    3.40 +	}
    3.41  
    3.42  	/**
    3.43  	 * This happens when both sides of the union have the same variable name with
    3.44 @@ -443,22 +438,21 @@
    3.45  				proj.setVar(var);
    3.46  				proj.setId(new GeneralDBRefIdColumn(var));
    3.47  
    3.48 -
    3.49  				if(geoNames.contains(var.getName()))
    3.50  				{
    3.51  					proj.setStringValue(new GeneralDBLabelColumn(var));
    3.52  					//13/09/2011 my addition in order to create a spatial join in the meet(Filter) call that will follow
    3.53  					previousAlias = var;
    3.54 +					
    3.55 +					// add the corresponding datatype (see {@link GeneralDBValueJoinOptimizer.GeneralDBLabelColumn})
    3.56 +					proj.setDatatype(new GeneralDBDatatypeColumn(var));
    3.57  				}
    3.58  				else
    3.59  				{
    3.60 -
    3.61 -
    3.62  					proj.setStringValue(coalesce(new GeneralDBURIColumn(var), new GeneralDBBNodeColumn(var), new GeneralDBLabelColumn(var),
    3.63  							new GeneralDBLongLabelColumn(var), new GeneralDBLongURIColumn(var)));
    3.64  					proj.setDatatype(new GeneralDBDatatypeColumn(var));
    3.65  					proj.setLanguage(new GeneralDBLanguageColumn(var));
    3.66 -
    3.67  				}
    3.68  				query.addSqlSelectVar(proj);
    3.69  			}
    3.70 @@ -486,8 +480,6 @@
    3.71  			from.addFilter(in);
    3.72  		}
    3.73  		sp.replaceWith(query);
    3.74 -
    3.75 -
    3.76  	}
    3.77  
    3.78  	@Override
     4.1 --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/optimizers/GeneralDBValueJoinOptimizer.java	Thu Sep 18 19:50:53 2014 +0300
     4.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/optimizers/GeneralDBValueJoinOptimizer.java	Fri Sep 19 02:45:20 2014 +0300
     4.3 @@ -42,6 +42,8 @@
     4.4  /**
     4.5   * Adds LEFT JOINs to the query for value tables.
     4.6   * 
     4.7 + * @author Charalampos Nikolaou <charnik@di.uoa.gr>
     4.8 + * @author Manos Karpathiotakis <mk@di.uoa.gr>
     4.9   * @author James Leigh
    4.10   * 
    4.11   */
    4.12 @@ -89,11 +91,6 @@
    4.13  		return geo_values_occurences;
    4.14  	}
    4.15  
    4.16 -
    4.17 -	/**
    4.18 -	 * 
    4.19 -	 */
    4.20 -
    4.21  	public void setUriTable(URITable uris) {
    4.22  		this.uris = uris;
    4.23  	}
    4.24 @@ -116,30 +113,27 @@
    4.25  	}
    4.26  
    4.27  	@Override
    4.28 -	public void meetFromItem(GeneralDBFromItem node)
    4.29 -			throws RuntimeException
    4.30 -			{
    4.31 +	public void meetFromItem(GeneralDBFromItem node) throws RuntimeException
    4.32 +	{
    4.33  		GeneralDBFromItem top = parent;
    4.34  		parent = join;
    4.35  		join = node;
    4.36  		super.meetFromItem(node);
    4.37  		join = parent;
    4.38  		parent = top;
    4.39 -			}
    4.40 +	}
    4.41  
    4.42  	@Override
    4.43 -	public void meet(GeneralDBUnionItem node)
    4.44 -			throws RuntimeException
    4.45 -			{
    4.46 +	public void meet(GeneralDBUnionItem node) throws RuntimeException
    4.47 +	{
    4.48  		stack.add(node);
    4.49  		super.meet(node);
    4.50  		stack.remove(stack.size() - 1);
    4.51 -			}
    4.52 +	}
    4.53  
    4.54  	@Override
    4.55 -	public void meet(GeneralDBSelectQuery node)
    4.56 -			throws RuntimeException
    4.57 -			{
    4.58 +	public void meet(GeneralDBSelectQuery node) throws RuntimeException
    4.59 +	{
    4.60  		query = node;
    4.61  		parent = node.getFrom();
    4.62  		join = node.getFrom();
    4.63 @@ -147,12 +141,11 @@
    4.64  		join = null;
    4.65  		parent = null;
    4.66  		query = null;
    4.67 -			}
    4.68 +	}
    4.69  
    4.70  	@Override
    4.71 -	public void meet(GeneralDBHashColumn node)
    4.72 -			throws RuntimeException
    4.73 -			{
    4.74 +	public void meet(GeneralDBHashColumn node) throws RuntimeException
    4.75 +	{
    4.76  		if (hashes == null || hashes.getName() == null) {
    4.77  			super.meet(node);
    4.78  		}
    4.79 @@ -162,22 +155,20 @@
    4.80  			String tableName = hashes.getName();
    4.81  			join(var, alias, tableName, false);
    4.82  		}
    4.83 -			}
    4.84 +	}
    4.85  
    4.86  	@Override
    4.87 -	public void meet(GeneralDBBNodeColumn node)
    4.88 -			throws RuntimeException
    4.89 -			{
    4.90 +	public void meet(GeneralDBBNodeColumn node) throws RuntimeException
    4.91 +	{
    4.92  		GeneralDBColumnVar var = node.getRdbmsVar();
    4.93  		String alias = "b" + getDBName(var);
    4.94  		String tableName = bnodes.getName();
    4.95  		join(var, alias, tableName);
    4.96 -			}
    4.97 +	}
    4.98  
    4.99  	@Override
   4.100 -	public void meet(GeneralDBDatatypeColumn node)
   4.101 -			throws RuntimeException
   4.102 -			{
   4.103 +	public void meet(GeneralDBDatatypeColumn node) throws RuntimeException
   4.104 +	{
   4.105  		GeneralDBColumnVar var = node.getRdbmsVar();
   4.106  		//XXX If spatial, I don't want this action to take place
   4.107  		if(!var.isSpatial())
   4.108 @@ -186,12 +177,11 @@
   4.109  			String tableName = literals.getDatatypeTable().getName();
   4.110  			join(var, alias, tableName);
   4.111  		}
   4.112 -			}
   4.113 +	}
   4.114  
   4.115  	@Override
   4.116 -	public void meet(GeneralDBDateTimeColumn node)
   4.117 -			throws RuntimeException
   4.118 -			{
   4.119 +	public void meet(GeneralDBDateTimeColumn node) throws RuntimeException
   4.120 +	{
   4.121  		GeneralDBColumnVar var = node.getRdbmsVar();
   4.122  		String alias = "t" + getDBName(var);
   4.123  		String tableName = literals.getDateTimeTable().getName();
   4.124 @@ -206,15 +196,14 @@
   4.125  		 * -> Reverting this in GeneralDBSqlJoinBuilder. The join actually 
   4.126  		 * executed will be LEFT after all
   4.127  		 */
   4.128 -		join(var, alias, tableName,false);
   4.129 -			}
   4.130 +		join(var, alias, tableName, false);
   4.131 +	}
   4.132  
   4.133  
   4.134  	//Careful! Changes at the alias' name can cause great problems in the query plan!
   4.135  	@Override
   4.136 -	public void meet(GeneralDBLabelColumn node)
   4.137 -			throws RuntimeException
   4.138 -			{
   4.139 +	public void meet(GeneralDBLabelColumn node) throws RuntimeException
   4.140 +	{
   4.141  		GeneralDBColumnVar var = node.getRdbmsVar();
   4.142  		//
   4.143  		String alias = "l" + getDBName(var);
   4.144 @@ -228,16 +217,32 @@
   4.145  		}
   4.146  		else
   4.147  		{
   4.148 -			//FIXME temporary try
   4.149 -			//String alias = ""+getDBName(var).subSequence(1, getDBName(var).length());
   4.150 -			tableName = "geo_values";
   4.151  			//I don't need a left join in this case! Substituting with inner join!
   4.152 -			//join(var, alias, tableName);
   4.153 -			join(var,alias,tableName,false);
   4.154 -
   4.155 +			join(var, alias, "geo_values", false);
   4.156 +	
   4.157 +			// check whether we are going to project to a geometry value
   4.158 +			// and if so, add a join with datatype_values, so that we retrieve
   4.159 +			// the datatype of the geometry as well (see bug #71)
   4.160 +			if (query.getProjections().contains(var)) {
   4.161 +				//System.out.println("We will project on a geometry: " + var);
   4.162 +				
   4.163 +				String dtAlias = "d" + getDBName(var);
   4.164 +				if (!isJoined(dtAlias)) { // if this is the first time we do this
   4.165 +					// carry also the datatype of the geometry
   4.166 +					GeneralDBFromItem valueJoin = valueJoin(dtAlias,
   4.167 +															literals.getDatatypeTable().getName(), 
   4.168 +															var, 
   4.169 +															false);
   4.170 +					
   4.171 +					// we should add the join to the parent, because geo_values might
   4.172 +					// be joining through another table (e.g., asWKT)
   4.173 +					parent.addJoin(valueJoin);
   4.174 +					
   4.175 +				}
   4.176 +			}
   4.177  		}
   4.178  
   4.179 -			}
   4.180 +	}
   4.181  
   4.182  	@Override
   4.183  	public void meet(GeneralDBLongLabelColumn node)
   4.184 @@ -280,14 +285,13 @@
   4.185  			}
   4.186  
   4.187  	@Override
   4.188 -	public void meet(GeneralDBURIColumn node)
   4.189 -			throws RuntimeException
   4.190 -			{
   4.191 +	public void meet(GeneralDBURIColumn node) throws RuntimeException
   4.192 +	{
   4.193  		GeneralDBColumnVar var = node.getRdbmsVar();
   4.194  		String alias = "u" + getDBName(var);
   4.195  		String tableName = uris.getShortTableName();
   4.196  		join(var, alias, tableName);
   4.197 -			}
   4.198 +	}
   4.199  
   4.200  	private CharSequence getDBName(GeneralDBColumnVar var) {
   4.201  		String name = var.getName();
   4.202 @@ -340,7 +344,6 @@
   4.203  			else {
   4.204  				parent.addJoinBefore(valueJoin, join);
   4.205  			}
   4.206 -
   4.207  		}
   4.208  	}
   4.209  
     5.1 --- a/postgis/src/main/java/org/openrdf/sail/postgis/iteration/PostGISBindingIteration.java	Thu Sep 18 19:50:53 2014 +0300
     5.2 +++ b/postgis/src/main/java/org/openrdf/sail/postgis/iteration/PostGISBindingIteration.java	Fri Sep 19 02:45:20 2014 +0300
     5.3 @@ -38,8 +38,8 @@
     5.4  		{
     5.5  			byte[] label = rs.getBytes(index + 1);
     5.6  			int srid = rs.getInt(index + 2);
     5.7 -			return vf.getRdbmsPolyhedron(id, GeoConstants.default_WKT_datatype, label, srid);
     5.8 -
     5.9 +			String datatype = rs.getString(index + 3);
    5.10 +			return vf.getRdbmsPolyhedron(id, datatype, label, srid);
    5.11  		}
    5.12  
    5.13  		return createResource(rs, index);