Strabon

changeset 842:908beb56b3f4 temporals

fixing implementation for temporal constructs in postgres temporal (the respective java implementation has been completed)
author Konstantina Bereta <Konstantina.Bereta@di.uoa.gr>
date Mon Jan 07 20:50:23 2013 +0200 (2013-01-07)
parents 50e40dbb6082
children 2fbca5bcab55
files generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBSelectQuery.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/base/GeneralDBExprSupport.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/factories/GeneralDBBooleanExprFactory.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/temporal/GeneralDBSqlPeriodIntersection.java generaldb/src/main/java/org/openrdf/sail/generaldb/evaluation/GeneralDBEvaluation.java generaldb/src/main/java/org/openrdf/sail/generaldb/evaluation/GeneralDBQueryBuilder.java generaldb/src/main/java/org/openrdf/sail/generaldb/optimizers/GeneralDBSelectQueryOptimizer.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/GeneralDBSelectQuery.java	Fri Jan 04 19:38:07 2013 +0200
     1.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBSelectQuery.java	Mon Jan 07 20:50:23 2013 +0200
     1.3 @@ -49,10 +49,14 @@
     1.4  	
     1.5  	/**
     1.6  	 * XXX addition for spatial constructs in select
     1.7 +	 * cloned behaviour to apply for the temporal case, too
     1.8  	 */
     1.9  	
    1.10  	private Map<String, GeneralDBSqlExpr> spatialConstructs = new HashMap<String, GeneralDBSqlExpr>();
    1.11  	
    1.12 +	private Map<String, GeneralDBSqlExpr> temporalConstructs = new HashMap<String, GeneralDBSqlExpr>();
    1.13 +
    1.14 +	
    1.15  	//Extra addition for true spatial selections and joins in FROM clause - 07/09/2011
    1.16  	//private List<GeneralDBSqlExpr> spatialFilters = new ArrayList<GeneralDBSqlExpr>();
    1.17  	/**
    1.18 @@ -81,6 +85,14 @@
    1.19  		this.spatialConstructs = spatialConstructs;
    1.20  	}
    1.21  	
    1.22 +	public Map<String, GeneralDBSqlExpr> getTemporalConstructs() {
    1.23 +		return temporalConstructs;
    1.24 +	}
    1.25 +
    1.26 +	public void setTemporalConstructs(Map<String, GeneralDBSqlExpr> temporalConstructs) {
    1.27 +		this.temporalConstructs = temporalConstructs;
    1.28 +	}
    1.29 +	
    1.30  	//09/09/2011 XXX
    1.31  //	public List<GeneralDBSqlExpr> getSpatialFilters() {
    1.32  //		return spatialFilters;
    1.33 @@ -248,6 +260,8 @@
    1.34  		clone.from = from.clone();
    1.35  		clone.order = new ArrayList<OrderElem>(order);
    1.36  		clone.spatialConstructs = new HashMap<String, GeneralDBSqlExpr>(spatialConstructs);
    1.37 +		clone.temporalConstructs = new HashMap<String, GeneralDBSqlExpr>(temporalConstructs);
    1.38 +
    1.39  		return clone;
    1.40  	}
    1.41  
     2.1 --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/base/GeneralDBExprSupport.java	Fri Jan 04 19:38:07 2013 +0200
     2.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/base/GeneralDBExprSupport.java	Mon Jan 07 20:50:23 2013 +0200
     2.3 @@ -101,7 +101,10 @@
     2.4  import org.openrdf.sail.generaldb.algebra.temporal.GeneralDBSqlOverrightPeriod;
     2.5  import org.openrdf.sail.generaldb.algebra.temporal.GeneralDBSqlPeriodContainedBy;
     2.6  import org.openrdf.sail.generaldb.algebra.temporal.GeneralDBSqlPeriodContains;
     2.7 +import org.openrdf.sail.generaldb.algebra.temporal.GeneralDBSqlPeriodIntersection;
     2.8 +import org.openrdf.sail.generaldb.algebra.temporal.GeneralDBSqlPeriodMinus;
     2.9  import org.openrdf.sail.generaldb.algebra.temporal.GeneralDBSqlPeriodOverlaps;
    2.10 +import org.openrdf.sail.generaldb.algebra.temporal.GeneralDBSqlPeriodUnion;
    2.11  import org.openrdf.sail.generaldb.algebra.temporal.GeneralDBSqlStarts;
    2.12  import org.openrdf.sail.rdbms.exceptions.UnsupportedRdbmsOperatorException;
    2.13  /**
    2.14 @@ -365,6 +368,17 @@
    2.15  	public static GeneralDBSqlExpr below(GeneralDBSqlExpr left, GeneralDBSqlExpr right) {
    2.16  		return new GeneralDBSqlBelow(left, right);
    2.17  	}
    2.18 +	//stSPARQL Temporal Construct Functions
    2.19 +	
    2.20 +	public static GeneralDBSqlExpr periodIntersection(GeneralDBSqlExpr left, GeneralDBSqlExpr right) {
    2.21 +		return new GeneralDBSqlPeriodIntersection(left, right);
    2.22 +	}
    2.23 +	public static GeneralDBSqlExpr periodUnion(GeneralDBSqlExpr left, GeneralDBSqlExpr right) {
    2.24 +		return new GeneralDBSqlPeriodUnion(left, right);
    2.25 +	}
    2.26 +	public static GeneralDBSqlExpr periodMinus(GeneralDBSqlExpr left, GeneralDBSqlExpr right) {
    2.27 +		return new GeneralDBSqlPeriodMinus(left, right);
    2.28 +	}
    2.29  	
    2.30  	//stSparql Temporal Relation Functions
    2.31  	public static GeneralDBSqlExpr afterPeriod(GeneralDBSqlExpr left, GeneralDBSqlExpr right) {
     3.1 --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/factories/GeneralDBBooleanExprFactory.java	Fri Jan 04 19:38:07 2013 +0200
     3.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/factories/GeneralDBBooleanExprFactory.java	Mon Jan 07 20:50:23 2013 +0200
     3.3 @@ -46,6 +46,10 @@
     3.4  import org.openrdf.query.algebra.evaluation.function.spatial.stsparql.construct.UnionFunc;
     3.5  import org.openrdf.query.algebra.evaluation.function.spatial.stsparql.metric.AreaFunc;
     3.6  import org.openrdf.query.algebra.evaluation.function.spatial.stsparql.relation.RelateFunc;
     3.7 +import org.openrdf.query.algebra.evaluation.function.temporal.stsparql.construct.PeriodIntersectionFunc;
     3.8 +import org.openrdf.query.algebra.evaluation.function.temporal.stsparql.construct.PeriodMinusFunc;
     3.9 +import org.openrdf.query.algebra.evaluation.function.temporal.stsparql.construct.TemporalConstructFunc;
    3.10 +import org.openrdf.query.algebra.evaluation.function.temporal.stsparql.construct.periodUnionFunc;
    3.11  import org.openrdf.query.algebra.evaluation.function.temporal.stsparql.relation.AdjacentPeriodFunc;
    3.12  import org.openrdf.query.algebra.evaluation.function.temporal.stsparql.relation.AfterPeriodFunc;
    3.13  import org.openrdf.query.algebra.evaluation.function.temporal.stsparql.relation.BeforePeriodFunc;
    3.14 @@ -751,10 +755,48 @@
    3.15  		{
    3.16  			return temporalRelationFunction(functionCall,function);	
    3.17  		}
    3.18 +		else if(function instanceof TemporalConstructFunc) //copied behaviour to capture the temporal cases
    3.19 +		{
    3.20 +			return temporalConstructFunction(functionCall,function);
    3.21 +		}
    3.22  		
    3.23  		return null;
    3.24  	}
    3.25 +	
    3.26 +	GeneralDBSqlExpr temporalConstructFunction(FunctionCall functionCall, Function function) throws UnsupportedRdbmsOperatorException
    3.27 +	{
    3.28  
    3.29 +		GeneralDBSqlExpr leftArg = null;
    3.30 +		GeneralDBSqlExpr rightArg = null;
    3.31 +
    3.32 +		ValueExpr left = functionCall.getArgs().get(0);
    3.33 +
    3.34 +
    3.35 +		if(left instanceof FunctionCall)
    3.36 +		{
    3.37 +			leftArg = temporalFunction((FunctionCall) left);
    3.38 +		}
    3.39 +		else
    3.40 +		{
    3.41 +			leftArg = label(left);
    3.42 +		}
    3.43 +
    3.44 +		if(!( functionCall.getArgs().size()==1))
    3.45 +		{
    3.46 +			ValueExpr right = functionCall.getArgs().get(1);
    3.47 +			if(right instanceof FunctionCall)
    3.48 +			{
    3.49 +				rightArg = temporalFunction((FunctionCall) right);
    3.50 +			}
    3.51 +			else
    3.52 +			{
    3.53 +				rightArg = label(right);
    3.54 +			}
    3.55 +		}
    3.56 +
    3.57 +		return temporalConstructPicker(function, leftArg, rightArg);
    3.58 +
    3.59 +	}
    3.60  	GeneralDBSqlExpr temporalRelationFunction(FunctionCall functionCall, Function function) throws UnsupportedRdbmsOperatorException
    3.61  	{
    3.62  		ValueExpr left = functionCall.getArgs().get(0);
    3.63 @@ -940,6 +982,24 @@
    3.64  
    3.65  	}
    3.66  	
    3.67 +	GeneralDBSqlExpr temporalConstructPicker(Function function,GeneralDBSqlExpr leftArg, GeneralDBSqlExpr rightArg)
    3.68 +	{
    3.69 +		if(function instanceof PeriodIntersectionFunc)
    3.70 +		{
    3.71 +			return periodIntersection(leftArg, rightArg);
    3.72 +		}
    3.73 +		else if(function instanceof periodUnionFunc)
    3.74 +		{
    3.75 +			return periodUnion(leftArg, rightArg);
    3.76 +		}
    3.77 +		else if(function instanceof PeriodMinusFunc)
    3.78 +		{
    3.79 +			return periodMinus(leftArg, rightArg);
    3.80 +		}
    3.81 +		else
    3.82 +			return null;
    3.83 +	}
    3.84 +	
    3.85  	GeneralDBSqlExpr temporalRelationPicker(Function function,GeneralDBSqlExpr leftArg, GeneralDBSqlExpr rightArg, 
    3.86  			GeneralDBSqlExpr thirdArg)
    3.87  	{
     4.1 --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/temporal/GeneralDBSqlPeriodIntersection.java	Fri Jan 04 19:38:07 2013 +0200
     4.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/temporal/GeneralDBSqlPeriodIntersection.java	Mon Jan 07 20:50:23 2013 +0200
     4.3 @@ -45,7 +45,7 @@
     4.4  	@Override
     4.5  	public String getPostgresFunction() {
     4.6  
     4.7 -		return null;
     4.8 +		return "period_intersect";
     4.9  	}
    4.10  
    4.11  }
    4.12 \ No newline at end of file
     5.1 --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/evaluation/GeneralDBEvaluation.java	Fri Jan 04 19:38:07 2013 +0200
     5.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/evaluation/GeneralDBEvaluation.java	Mon Jan 07 20:50:23 2013 +0200
     5.3 @@ -100,6 +100,7 @@
     5.4  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlSpatialProperty;
     5.5  import org.openrdf.sail.generaldb.algebra.GeneralDBURIColumn;
     5.6  import org.openrdf.sail.generaldb.algebra.base.GeneralDBSqlExpr;
     5.7 +import org.openrdf.sail.generaldb.algebra.temporal.GeneralDBSqlTemporalConstructBinary;
     5.8  import org.openrdf.sail.generaldb.model.GeneralDBPolyhedron;
     5.9  import org.openrdf.sail.generaldb.schema.IdSequence;
    5.10  import org.openrdf.sail.generaldb.util.StSPARQLValueComparator;
    5.11 @@ -139,7 +140,7 @@
    5.12  	 * Enumeration of the possible types of the results of spatial functions.
    5.13  	 * A <tt>NULL</tt> result type is to be interpreted as error.   
    5.14  	 */ 
    5.15 -	public enum ResultType { INTEGER, STRING, BOOLEAN, WKB, DOUBLE, NULL};
    5.16 +	public enum ResultType { INTEGER, STRING, BOOLEAN, WKB, DOUBLE, PERIOD,NULL};
    5.17  
    5.18  	
    5.19  	//used to retrieve the appropriate column in the Binding Iteration
    5.20 @@ -916,6 +917,37 @@
    5.21  				}
    5.22  			}
    5.23  		}
    5.24 +		Iterator iter = qb.getTemporalConstructs().entrySet().iterator();
    5.25 +		while (iter.hasNext()) {
    5.26 +			@SuppressWarnings("rawtypes")
    5.27 +			Map.Entry pairs = (Map.Entry)iter.next();
    5.28 +			//System.out.println(pairs.getKey() + " = " + pairs.getValue());
    5.29 +
    5.30 +			//Trying to fill what's missing
    5.31 +			GeneralDBSqlExpr expr = (GeneralDBSqlExpr) pairs.getValue();
    5.32 +			locateColumnVars(expr,qb.getVars());
    5.33 +
    5.34 +			//Assuming thematic aggregates and spatial expressions won't be combined
    5.35 +			if(!this.thematicExpressions.contains(expr))
    5.36 +			{
    5.37 +				query.construct(expr);
    5.38 +				boolean increaseIndex = false;
    5.39 +
    5.40 +				GeneralDBSpatialFuncInfo info = null;
    5.41 +				
    5.42 +				ResultType type = getResultType(expr);
    5.43 +				if (type == ResultType.NULL) {
    5.44 +					throw new UnsupportedRdbmsOperatorException("No such temporal expression exists!");
    5.45 +					
    5.46 +				} else {
    5.47 +					info = new GeneralDBSpatialFuncInfo((String) pairs.getKey(), type);				
    5.48 +					
    5.49 +				}
    5.50 +
    5.51 +				constructIndexesAndNames.put(info,index++);
    5.52 +
    5.53 +			}
    5.54 +		}
    5.55  		//
    5.56  
    5.57  		for (OrderElem by : qb.getOrderElems()) {
    5.58 @@ -1053,6 +1085,11 @@
    5.59  			locateColumnVars(((GeneralDBSqlMathExpr)expr).getLeftArg(),allKnown);
    5.60  			locateColumnVars(((GeneralDBSqlMathExpr)expr).getRightArg(),allKnown);
    5.61  		}
    5.62 +		else if(expr instanceof GeneralDBSqlTemporalConstructBinary)
    5.63 +		{
    5.64 +			locateColumnVars(((GeneralDBSqlTemporalConstructBinary)expr).getLeftArg(),allKnown);
    5.65 +			locateColumnVars(((GeneralDBSqlTemporalConstructBinary)expr).getRightArg(),allKnown);
    5.66 +		}
    5.67  		else
    5.68  		{
    5.69  			//must recurse
    5.70 @@ -1085,6 +1122,7 @@
    5.71  
    5.72  	/**
    5.73  	 * Given an expression get the type of the result. 
    5.74 +	 * Extended it to take into account the temporal constructs
    5.75  	 * 
    5.76  	 * @param expr
    5.77  	 * @return
    5.78 @@ -1122,6 +1160,10 @@
    5.79  		{
    5.80  			return ResultType.DOUBLE;
    5.81  		}
    5.82 +		else if(expr instanceof GeneralDBSqlTemporalConstructBinary)
    5.83 +		{
    5.84 +			return ResultType.PERIOD;
    5.85 +		}
    5.86  		return ResultType.NULL;//SHOULD NEVER REACH THIS CASE
    5.87  	}
    5.88  }
     6.1 --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/evaluation/GeneralDBQueryBuilder.java	Fri Jan 04 19:38:07 2013 +0200
     6.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/evaluation/GeneralDBQueryBuilder.java	Mon Jan 07 20:50:23 2013 +0200
     6.3 @@ -648,6 +648,15 @@
     6.4  		else if(expr instanceof GeneralDBSqlAdjacentPeriod){
     6.5  			append((GeneralDBSqlAdjacentPeriod)expr, filter);
     6.6  		}
     6.7 +		else if(expr instanceof GeneralDBSqlPeriodIntersection){
     6.8 +			append((GeneralDBSqlPeriodIntersection)expr, filter);
     6.9 +		}
    6.10 +		else if(expr instanceof GeneralDBSqlPeriodUnion){
    6.11 +			append((GeneralDBSqlPeriodUnion)expr, filter);
    6.12 +		}
    6.13 +		else if(expr instanceof GeneralDBSqlPeriodMinus){
    6.14 +			append((GeneralDBSqlPeriodMinus)expr, filter);
    6.15 +		}
    6.16  		
    6.17  		//GeoSPARQL
    6.18  		//Simple Features
    6.19 @@ -1279,6 +1288,18 @@
    6.20  		{
    6.21  			append((GeneralDBSqlGeoSymDifference)constr, filter);
    6.22  		}
    6.23 +		else if(constr instanceof GeneralDBSqlPeriodIntersection)
    6.24 +		{
    6.25 +			append((GeneralDBSqlPeriodIntersection)constr, filter);
    6.26 +		}
    6.27 +		else if(constr instanceof GeneralDBSqlPeriodMinus)
    6.28 +		{
    6.29 +			append((GeneralDBSqlPeriodMinus)constr, filter);
    6.30 +		}
    6.31 +		else if(constr instanceof GeneralDBSqlPeriodUnion)
    6.32 +		{
    6.33 +			append((GeneralDBSqlPeriodUnion)constr, filter);
    6.34 +		}
    6.35  
    6.36  			}
    6.37  
     7.1 --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/optimizers/GeneralDBSelectQueryOptimizer.java	Fri Jan 04 19:38:07 2013 +0200
     7.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/optimizers/GeneralDBSelectQueryOptimizer.java	Mon Jan 07 20:50:23 2013 +0200
     7.3 @@ -1057,6 +1057,16 @@
     7.4  						}
     7.5  						iter.remove();
     7.6  					}
     7.7 +					else if(function instanceof TemporalConstructFunc || function instanceof TemporalRelationFunc)
     7.8 +					{
     7.9 +						try {
    7.10 +							sqlExpr= sql.getBooleanExprFactory().temporalFunction((FunctionCall)expr);
    7.11 +							reference.getTemporalConstructs().put(name, sqlExpr);
    7.12 +						} catch (UnsupportedRdbmsOperatorException e) {
    7.13 +							// TODO Auto-generated catch block
    7.14 +							e.printStackTrace();
    7.15 +						}
    7.16 +					}
    7.17  				}
    7.18  				else //Union (or Extent) is used as an aggregate function on Select Clause!
    7.19  				{
    7.20 @@ -1082,6 +1092,8 @@
    7.21  						sqlExpr = sql.getNumericExprFactory().createNumericExpr(expr);
    7.22  
    7.23  						reference.getSpatialConstructs().put(name, sqlExpr);
    7.24 +						reference.getTemporalConstructs().put(name, sqlExpr);
    7.25 +
    7.26  						iter.remove();
    7.27  					}
    7.28  				} catch (UnsupportedRdbmsOperatorException e) {
     8.1 --- a/postgis/src/main/java/org/openrdf/sail/postgis/evaluation/PostGISQueryBuilder.java	Fri Jan 04 19:38:07 2013 +0200
     8.2 +++ b/postgis/src/main/java/org/openrdf/sail/postgis/evaluation/PostGISQueryBuilder.java	Mon Jan 07 20:50:23 2013 +0200
     8.3 @@ -352,9 +352,11 @@
     8.4  		if(!(expr instanceof GeneralDBSqlSpatialMetricBinary) 
     8.5  				&&!(expr instanceof GeneralDBSqlSpatialMetricUnary)
     8.6  				&&!(expr instanceof GeneralDBSqlMathExpr)
     8.7 -				&&!(expr instanceof GeneralDBSqlSpatialProperty))
     8.8 +				&&!(expr instanceof GeneralDBSqlSpatialProperty)
     8.9 +			&&!(expr instanceof GeneralDBSqlTemporal))
    8.10  		{
    8.11  			query.select().appendFunction(ST_ASBINARY);
    8.12 +			System.out.println("appended st_asBinary!");
    8.13  		}
    8.14  		else
    8.15  		{
    8.16 @@ -1110,21 +1112,21 @@
    8.17  	protected void append(GeneralDBSqlPeriodIntersection expr, GeneralDBSqlExprBuilder filter)
    8.18  			throws UnsupportedRdbmsOperatorException
    8.19  			{
    8.20 -		//appendGeneralDBSpatialFunctionUnary(expr, filter, SpatialFunctionsPostGIS.ST_IsEmpty);
    8.21 +		appendGeneralDBTemporalFunctionBinary(expr, filter, expr.getPostgresFunction());
    8.22  			}
    8.23  	
    8.24  	@Override
    8.25  	protected void append(GeneralDBSqlPeriodMinus expr, GeneralDBSqlExprBuilder filter)
    8.26  			throws UnsupportedRdbmsOperatorException
    8.27  			{
    8.28 -		//appendGeneralDBSpatialFunctionUnary(expr, filter, SpatialFunctionsPostGIS.ST_IsEmpty);
    8.29 +		appendGeneralDBTemporalFunctionBinary(expr, filter, expr.getPostgresFunction());
    8.30  			}
    8.31  	
    8.32  	@Override
    8.33  	protected void append(GeneralDBSqlPeriodUnion expr, GeneralDBSqlExprBuilder filter)
    8.34  			throws UnsupportedRdbmsOperatorException
    8.35  			{
    8.36 -		//appendGeneralDBSpatialFunctionUnary(expr, filter, SpatialFunctionsPostGIS.ST_IsEmpty);
    8.37 +	appendGeneralDBTemporalFunctionBinary(expr, filter, expr.getPostgresFunction());
    8.38  			}
    8.39  
    8.40