Strabon

changeset 783:971584294be1 DiffDateTime

NOT WORKING: SQL query is now being formated, but datetime cannot be handled properly because it is stored in label_values with every literal
author George Garbis <ggarbis@di.uoa.gr>
date Wed Dec 05 19:22:44 2012 +0200 (2012-12-05)
parents b9cde09d417d
children ece107a3cf59
files generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBSqlDiffDateTime.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBSqlGeoDistance.java generaldb/src/main/java/org/openrdf/sail/generaldb/evaluation/GeneralDBQueryBuilder.java monetdb/src/main/java/org/openrdf/sail/monetdb/evaluation/MonetDBQueryBuilder.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/algebra/GeneralDBSqlDiffDateTime.java	Wed Dec 05 16:17:45 2012 +0200
     1.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBSqlDiffDateTime.java	Wed Dec 05 19:22:44 2012 +0200
     1.3 @@ -15,7 +15,7 @@
     1.4   * 
     1.5   */
     1.6  
     1.7 -public class GeneralDBSqlDiffDateTime extends GeneralDBSqlDateTimeMetricBinary{
     1.8 +public class GeneralDBSqlDiffDateTime extends GeneralDBSqlDateTimeMetricBinary {
     1.9  	
    1.10  	public GeneralDBSqlDiffDateTime(GeneralDBSqlExpr left, GeneralDBSqlExpr right) {
    1.11  		super(left, right);
     2.1 --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBSqlGeoDistance.java	Wed Dec 05 16:17:45 2012 +0200
     2.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBSqlGeoDistance.java	Wed Dec 05 19:22:44 2012 +0200
     2.3 @@ -9,7 +9,7 @@
     2.4  import org.openrdf.sail.generaldb.algebra.base.GeneralDBQueryModelVisitorBase;
     2.5  import org.openrdf.sail.generaldb.algebra.base.GeneralDBSqlExpr;
     2.6  
     2.7 -public class GeneralDBSqlGeoDistance extends GeneralDBSqlSpatialMetricBinary{
     2.8 +public class GeneralDBSqlGeoDistance extends GeneralDBSqlSpatialMetricBinary {
     2.9  
    2.10  	public GeneralDBSqlGeoDistance(GeneralDBSqlExpr left, GeneralDBSqlExpr right) {
    2.11  		super(left, right);
     3.1 --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/evaluation/GeneralDBQueryBuilder.java	Wed Dec 05 16:17:45 2012 +0200
     3.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/evaluation/GeneralDBQueryBuilder.java	Wed Dec 05 19:22:44 2012 +0200
     3.3 @@ -39,6 +39,7 @@
     3.4  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlContainsMBB;
     3.5  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlCoveredBy;
     3.6  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlCovers;
     3.7 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlDiffDateTime;
     3.8  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlDisjoint;
     3.9  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlEq;
    3.10  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlEqualsSpatial;
    3.11 @@ -687,7 +688,9 @@
    3.12  		else if (expr instanceof GeneralDBSqlGeoDistance) {
    3.13  			append((GeneralDBSqlGeoDistance)expr, filter);
    3.14  		}
    3.15 -
    3.16 +		else if (expr instanceof GeneralDBSqlDiffDateTime) {
    3.17 +			append((GeneralDBSqlDiffDateTime)expr, filter);
    3.18 +		}
    3.19  		/**
    3.20  		 * end of my addition
    3.21  		 */
    3.22 @@ -1106,6 +1109,15 @@
    3.23  	protected abstract void append(GeneralDBSqlGeoSymDifference expr, GeneralDBSqlExprBuilder filter)
    3.24  			throws UnsupportedRdbmsOperatorException;
    3.25  
    3.26 +	/** Addition for datetime metric functions
    3.27 +	 * 
    3.28 +	 * @author George Garbis <ggarbis@di.uoa.gr>
    3.29 +	 * 
    3.30 +	 */
    3.31 +	protected abstract void append(GeneralDBSqlDiffDateTime expr, GeneralDBSqlExprBuilder filter)
    3.32 +			throws UnsupportedRdbmsOperatorException;
    3.33 +	/***/
    3.34 +	
    3.35  	//Spatial Metric Functions
    3.36  	protected abstract void append(GeneralDBSqlGeoDistance expr, GeneralDBSqlExprBuilder filter)
    3.37  			throws UnsupportedRdbmsOperatorException;
    3.38 @@ -1215,6 +1227,18 @@
    3.39  
    3.40  			}
    3.41  
    3.42 +	/** Addition for datetime metric functions
    3.43 +	 * 
    3.44 +	 * @author George Garbis <ggarbis@di.uoa.gr>
    3.45 +	 * 
    3.46 +	 */
    3.47 +	protected void appendCastToEpoch(GeneralDBSqlExprBuilder filter)
    3.48 +	{
    3.49 +//		filter.epochCastBefore();
    3.50 +//		filter.epochCastAfter();
    3.51 +	}	
    3.52 +	/***/
    3.53 +	
    3.54  	protected void appendCastToDouble(GeneralDBSqlExprBuilder filter)
    3.55  	{
    3.56  		filter.doubleCast();
     4.1 --- a/monetdb/src/main/java/org/openrdf/sail/monetdb/evaluation/MonetDBQueryBuilder.java	Wed Dec 05 16:17:45 2012 +0200
     4.2 +++ b/monetdb/src/main/java/org/openrdf/sail/monetdb/evaluation/MonetDBQueryBuilder.java	Wed Dec 05 19:22:44 2012 +0200
     4.3 @@ -23,6 +23,7 @@
     4.4  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlContainsMBB;
     4.5  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlCoveredBy;
     4.6  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlCovers;
     4.7 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlDiffDateTime;
     4.8  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlDisjoint;
     4.9  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlEqualsSpatial;
    4.10  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlGeoArea;
    4.11 @@ -194,6 +195,15 @@
    4.12  		; 
    4.13  	}
    4.14  
    4.15 +	/** Addition for datetime metric functions
    4.16 +	 * 
    4.17 +	 * @author George Garbis <ggarbis@di.uoa.gr>
    4.18 +	 * 
    4.19 +	 */
    4.20 +	public enum DateTimeFunctionMonetDB { Difference; }
    4.21 +	/***/
    4.22 +
    4.23 +	
    4.24  	public MonetDBQueryBuilder() {
    4.25  		super();
    4.26  	}
    4.27 @@ -757,6 +767,19 @@
    4.28  		appendMonetDBSpatialFunctionBinary(expr, filter, SpatialFunctionsMonetDB.ST_SymDifference);
    4.29  			}
    4.30  
    4.31 +	/** Addition for datetime metric functions
    4.32 +	 * 
    4.33 +	 * @author George Garbis <ggarbis@di.uoa.gr>
    4.34 +	 * 
    4.35 +	 */
    4.36 +	@Override
    4.37 +	protected void append(GeneralDBSqlDiffDateTime expr, GeneralDBSqlExprBuilder filter)
    4.38 +		throws UnsupportedRdbmsOperatorException
    4.39 +	{
    4.40 +		appendGeneralDBDateTimeFunctionBinary(expr, filter, DateTimeFunctionMonetDB.Difference);
    4.41 +	}
    4.42 +	/***/
    4.43 +	
    4.44  	@Override
    4.45  	//Spatial Metric Functions
    4.46  	protected void append(GeneralDBSqlGeoDistance expr, GeneralDBSqlExprBuilder filter)
    4.47 @@ -1101,6 +1124,147 @@
    4.48  
    4.49  			}
    4.50  
    4.51 +	/** Addition for datetime metric functions
    4.52 +	 * 
    4.53 +	 * @author George Garbis <ggarbis@di.uoa.gr>
    4.54 +	 * 
    4.55 +	 */
    4.56 +	protected void appendGeneralDBDateTimeFunctionBinary(BinaryGeneralDBOperator expr, GeneralDBSqlExprBuilder filter, DateTimeFunctionMonetDB func)
    4.57 +			throws UnsupportedRdbmsOperatorException
    4.58 +	{
    4.59 +		filter.openBracket();
    4.60 +
    4.61 +		boolean check1 = expr.getLeftArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull");
    4.62 +		boolean check2 = expr.getRightArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull");
    4.63 +
    4.64 +		if(check1)
    4.65 +		{
    4.66 +			this.append((GeneralDBSqlNull)expr.getLeftArg(), filter);
    4.67 +
    4.68 +		}
    4.69 +		else if(check2)
    4.70 +		{
    4.71 +			this.append((GeneralDBSqlNull)expr.getRightArg(), filter);
    4.72 +		}
    4.73 +		else
    4.74 +		{
    4.75 +
    4.76 +			GeneralDBSqlExpr tmp = expr;
    4.77 +			if(tmp instanceof GeneralDBSqlSpatialConstructBinary && tmp.getParentNode() == null)
    4.78 +			{
    4.79 +				while(true)
    4.80 +				{
    4.81 +					GeneralDBSqlExpr child;
    4.82 +
    4.83 +					if(tmp instanceof BinaryGeneralDBOperator)
    4.84 +					{
    4.85 +						child = ((BinaryGeneralDBOperator) tmp).getLeftArg();
    4.86 +					}
    4.87 +					else //(tmp instanceof UnaryGeneralDBOperator)
    4.88 +					{
    4.89 +						child = ((UnaryGeneralDBOperator) tmp).getArg();
    4.90 +					}
    4.91 +
    4.92 +					tmp = child;
    4.93 +					if(tmp instanceof GeneralDBLabelColumn)
    4.94 +					{
    4.95 +						//Reached the innermost left var -> need to capture its SRID
    4.96 +						String alias;
    4.97 +						if (((GeneralDBLabelColumn) tmp).getRdbmsVar().isResource()) {
    4.98 +							//Predicates used in triple patterns non-existent in db
    4.99 +							alias="NULL";
   4.100 +						}
   4.101 +						else
   4.102 +						{
   4.103 +							//Reached the innermost left var -> need to capture its SRID
   4.104 +							alias = getLabelAlias(((GeneralDBLabelColumn) tmp).getRdbmsVar());
   4.105 +						}
   4.106 +						break;
   4.107 +					}
   4.108 +				}
   4.109 +			}
   4.110 +
   4.111 +			filter.openBracket();
   4.112 +
   4.113 +			if(expr.getLeftArg() instanceof GeneralDBStringValue)
   4.114 +			{
   4.115 +				GeneralDBStringValue arg = (GeneralDBStringValue) expr.getLeftArg();
   4.116 +				String raw = arg.getValue();
   4.117 +				filter.append(" "+raw+" ");
   4.118 +			}
   4.119 +			else if(expr.getLeftArg() instanceof GeneralDBDoubleValue) //case met in buffer!
   4.120 +			{
   4.121 +				append(((GeneralDBDoubleValue)expr.getLeftArg()), filter);
   4.122 +			}
   4.123 +			else if(expr.getLeftArg() instanceof GeneralDBNumericColumn) //case met in buffer!
   4.124 +			{
   4.125 +				append(((GeneralDBNumericColumn)expr.getLeftArg()), filter);
   4.126 +			}
   4.127 +			else if(expr.getLeftArg() instanceof GeneralDBURIColumn) //case met in transform!
   4.128 +			{
   4.129 +				filter.keepSRID_part1();
   4.130 +				append(((GeneralDBURIColumn)expr.getLeftArg()), filter);
   4.131 +				filter.keepSRID_part2();
   4.132 +				append(((GeneralDBURIColumn)expr.getLeftArg()), filter);
   4.133 +				filter.keepSRID_part3();
   4.134 +			}
   4.135 +			//case met in buffer when in select -> buffer(?spatial,?thematic)
   4.136 +			else if(expr.getLeftArg() instanceof GeneralDBLabelColumn && !((GeneralDBLabelColumn)expr.getLeftArg()).isSpatial())
   4.137 +			{
   4.138 +				append(((GeneralDBLabelColumn)expr.getLeftArg()),filter);
   4.139 +				appendCastToDouble(filter);
   4.140 +			}
   4.141 +			else
   4.142 +			{
   4.143 +				// Den prepei na ftasei edw
   4.144 +			}
   4.145 +						
   4.146 +			switch(func)
   4.147 +			{
   4.148 +				case Difference: filter.append(" - "); break;			
   4.149 +			}
   4.150 +			
   4.151 +			if(expr.getRightArg() instanceof GeneralDBStringValue)
   4.152 +			{
   4.153 +				GeneralDBStringValue arg = (GeneralDBStringValue) expr.getRightArg();
   4.154 +				String raw = arg.getValue();
   4.155 +				filter.append(" "+raw+" ");
   4.156 +			}
   4.157 +			else if(expr.getRightArg() instanceof GeneralDBDoubleValue) //case met in buffer!
   4.158 +			{
   4.159 +				append(((GeneralDBDoubleValue)expr.getRightArg()), filter);
   4.160 +			}
   4.161 +			else if(expr.getRightArg() instanceof GeneralDBNumericColumn) //case met in buffer!
   4.162 +			{
   4.163 +				append(((GeneralDBNumericColumn)expr.getRightArg()), filter);
   4.164 +			}
   4.165 +			else if(expr.getRightArg() instanceof GeneralDBURIColumn) //case met in transform!
   4.166 +			{
   4.167 +				filter.keepSRID_part1();
   4.168 +				append(((GeneralDBURIColumn)expr.getRightArg()), filter);
   4.169 +				filter.keepSRID_part2();
   4.170 +				append(((GeneralDBURIColumn)expr.getRightArg()), filter);
   4.171 +				filter.keepSRID_part3();
   4.172 +			}
   4.173 +			//case met in buffer when in select -> buffer(?spatial,?thematic)
   4.174 +			else if(expr.getRightArg() instanceof GeneralDBLabelColumn && !((GeneralDBLabelColumn)expr.getRightArg()).isSpatial())
   4.175 +			{
   4.176 +				append(((GeneralDBLabelColumn)expr.getRightArg()),filter);
   4.177 +				appendCastToDouble(filter);
   4.178 +			}
   4.179 +			else
   4.180 +			{
   4.181 +				// Den prepei na ftasei edw
   4.182 +			}
   4.183 +
   4.184 +
   4.185 +			filter.closeBracket();
   4.186 +		}
   4.187 +		filter.closeBracket();
   4.188 +	}
   4.189 +	
   4.190 +	/***/
   4.191 +
   4.192  
   4.193  	//Used in all the generaldb boolean spatial functions of the form ST_Function(?GEO1,?GEO2) 
   4.194  	//EXCEPT ST_Transform!!!
     5.1 --- a/postgis/src/main/java/org/openrdf/sail/postgis/evaluation/PostGISQueryBuilder.java	Wed Dec 05 16:17:45 2012 +0200
     5.2 +++ b/postgis/src/main/java/org/openrdf/sail/postgis/evaluation/PostGISQueryBuilder.java	Wed Dec 05 19:22:44 2012 +0200
     5.3 @@ -22,6 +22,7 @@
     5.4  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlContainsMBB;
     5.5  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlCoveredBy;
     5.6  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlCovers;
     5.7 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlDiffDateTime;
     5.8  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlDisjoint;
     5.9  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlEqualsSpatial;
    5.10  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlGeoArea;
    5.11 @@ -731,6 +732,19 @@
    5.12  		appendGeneralDBSpatialFunctionBinary(expr, filter, SpatialFunctionsPostGIS.ST_SymDifference);
    5.13  			}
    5.14  
    5.15 +	/** Addition for datetime metric functions
    5.16 +	 * 
    5.17 +	 * @author George Garbis <ggarbis@di.uoa.gr>
    5.18 +	 * 
    5.19 +	 */
    5.20 +	@Override
    5.21 +	protected void append(GeneralDBSqlDiffDateTime expr, GeneralDBSqlExprBuilder filter)
    5.22 +		throws UnsupportedRdbmsOperatorException
    5.23 +	{
    5.24 +		appendGeneralDBDateTimeFunctionBinary(expr, filter, DateTimeFunctionPostGIS.Difference);
    5.25 +	}
    5.26 +	/***/
    5.27 +	
    5.28  	//Spatial Metric Functions
    5.29  	@Override
    5.30  	protected void append(GeneralDBSqlGeoDistance expr, GeneralDBSqlExprBuilder filter)
    5.31 @@ -1264,7 +1278,6 @@
    5.32  	 * @author George Garbis <ggarbis@di.uoa.gr>
    5.33  	 * 
    5.34  	 */
    5.35 -	
    5.36  	protected void appendGeneralDBDateTimeFunctionBinary(BinaryGeneralDBOperator expr, GeneralDBSqlExprBuilder filter, DateTimeFunctionPostGIS func)
    5.37  			throws UnsupportedRdbmsOperatorException
    5.38  	{
    5.39 @@ -1347,8 +1360,9 @@
    5.40  			//case met in buffer when in select -> buffer(?spatial,?thematic)
    5.41  			else if(expr.getLeftArg() instanceof GeneralDBLabelColumn && !((GeneralDBLabelColumn)expr.getLeftArg()).isSpatial())
    5.42  			{
    5.43 +				filter.append(" extract(epoch from ");
    5.44  				append(((GeneralDBLabelColumn)expr.getLeftArg()),filter);
    5.45 -				appendCastToDouble(filter);
    5.46 +				filter.append("::timestamp) ");
    5.47  			}
    5.48  			else
    5.49  			{
    5.50 @@ -1385,8 +1399,10 @@
    5.51  			//case met in buffer when in select -> buffer(?spatial,?thematic)
    5.52  			else if(expr.getRightArg() instanceof GeneralDBLabelColumn && !((GeneralDBLabelColumn)expr.getRightArg()).isSpatial())
    5.53  			{
    5.54 +				filter.append(" extract(epoch from ");
    5.55  				append(((GeneralDBLabelColumn)expr.getRightArg()),filter);
    5.56 -				appendCastToDouble(filter);
    5.57 +				filter.append("::timestamp) ");
    5.58 +				
    5.59  			}
    5.60  			else
    5.61  			{
    5.62 @@ -1397,8 +1413,7 @@
    5.63  			filter.closeBracket();
    5.64  		}
    5.65  		filter.closeBracket();
    5.66 -	}
    5.67 -	
    5.68 +	}	
    5.69  	/***/
    5.70  
    5.71  	//Used in all the generaldb stsparql boolean spatial functions of the form ST_Function(?GEO1,?GEO2)