Strabon
changeset 857:46d0edd3790c temporals
temporal functions period_start and period_end are now fully implemented using postgres temporal. Also added the following:
During the binding iteration phase of the query evaluation, periods with the same starting and ending points are converted into instants serialized
as xsd:dateTime values. Also, instants represented using the timestampz format are also converted into xsd:dateTime values at this level.
During the binding iteration phase of the query evaluation, periods with the same starting and ending points are converted into instants serialized
as xsd:dateTime values. Also, instants represented using the timestampz format are also converted into xsd:dateTime values at this level.
line diff
1.1 --- a/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/StrabonInstant.java Wed Jan 09 20:40:19 2013 +0200 1.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/StrabonInstant.java Fri Jan 11 17:37:01 2013 +0200 1.3 @@ -13,7 +13,9 @@ 1.4 import java.text.SimpleDateFormat; 1.5 import java.util.GregorianCalendar; 1.6 1.7 +import org.openrdf.model.Literal; 1.8 import org.openrdf.model.URI; 1.9 +import org.openrdf.model.impl.LiteralImpl; 1.10 import org.openrdf.model.impl.URIImpl; 1.11 import org.openrdf.query.algebra.evaluation.function.temporal.stsparql.relation.TemporalConstants; 1.12 1.13 @@ -98,5 +100,10 @@ 1.14 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-DD'T'HH:mm:ss"); 1.15 return sdf.format(this.value.getTime()).toString(); 1.16 } 1.17 + 1.18 + public Literal export2Literal() 1.19 + { 1.20 + return new LiteralImpl(this.stringValue(), this.datatype); 1.21 + } 1.22 1.23 }
2.1 --- a/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/StrabonPeriod.java Wed Jan 09 20:40:19 2013 +0200 2.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/StrabonPeriod.java Fri Jan 11 17:37:01 2013 +0200 2.3 @@ -20,8 +20,10 @@ 2.4 2.5 import net.sf.jtemporal.Period; 2.6 2.7 +import org.openrdf.model.Literal; 2.8 import org.openrdf.model.URI; 2.9 import org.openrdf.model.Value; 2.10 +import org.openrdf.model.impl.LiteralImpl; 2.11 import org.openrdf.model.impl.URIImpl; 2.12 import org.openrdf.query.algebra.evaluation.function.temporal.stsparql.relation.TemporalConstants; 2.13 2.14 @@ -254,4 +256,10 @@ 2.15 return A.getPeriod().succeeds((StrabonInstant)B); 2.16 } 2.17 2.18 + public Literal export2Literal() 2.19 + { 2.20 + //if(this.getStart() != this.getEnd()) 2.21 + return new LiteralImpl(this.stringValue(), this.datatype); 2.22 + } 2.23 + 2.24 }
3.1 --- a/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/StrabonTemporalElement.java Wed Jan 09 20:40:19 2013 +0200 3.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/StrabonTemporalElement.java Fri Jan 11 17:37:01 2013 +0200 3.3 @@ -9,6 +9,7 @@ 3.4 */ 3.5 package org.openrdf.query.algebra.evaluation.function.spatial; 3.6 3.7 +import org.openrdf.model.Literal; 3.8 import org.openrdf.model.URI; 3.9 import org.openrdf.model.Value; 3.10 import org.openrdf.model.impl.URIImpl; 3.11 @@ -29,7 +30,6 @@ 3.12 3.13 abstract public String stringValue(); 3.14 abstract public void setDatatype(URI datatype); 3.15 - 3.16 - 3.17 + abstract public Literal export2Literal(); 3.18 3.19 }
4.1 --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/evaluation/GeneralDBEvaluation.java Wed Jan 09 20:40:19 2013 +0200 4.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/evaluation/GeneralDBEvaluation.java Fri Jan 11 17:37:01 2013 +0200 4.3 @@ -141,7 +141,7 @@ 4.4 * Enumeration of the possible types of the results of spatial functions. 4.5 * A <tt>NULL</tt> result type is to be interpreted as error. 4.6 */ 4.7 - public enum ResultType { INTEGER, STRING, BOOLEAN, WKB, DOUBLE, PERIOD,NULL}; 4.8 + public enum ResultType { INTEGER, STRING, BOOLEAN, WKB, DOUBLE, PERIOD,INSTANT, NULL}; 4.9 4.10 4.11 //used to retrieve the appropriate column in the Binding Iteration 4.12 @@ -548,7 +548,7 @@ 4.13 return StrabonPeriod.union(rightArg, leftArg); 4.14 4.15 } 4.16 - else if(function.getURI().equals(TemporalConstants.periodIntersection)) 4.17 + /*else if(function.getURI().equals(TemporalConstants.periodIntersection)) 4.18 { 4.19 4.20 StrabonTemporalElement rightArg= null; 4.21 @@ -570,9 +570,8 @@ 4.22 { 4.23 rightArg = StrabonInstant.read(right.toString()); 4.24 } 4.25 - 4.26 return StrabonPeriod.intersection(rightArg, leftArg); 4.27 - } 4.28 + }*/ 4.29 else if(function.getURI().equals(TemporalConstants.minusPeriod)) 4.30 { //this functions takes only periods as arguments 4.31 if(!right.toString().contains(",") || !left.toString().contains(",")) 4.32 @@ -907,7 +906,6 @@ 4.33 } 4.34 4.35 } 4.36 - 4.37 //constructIndexesAndNames.put((String) pairs.getKey(),index++); 4.38 constructIndexesAndNames.put(info,index++); 4.39 if(increaseIndex) 4.40 @@ -1170,7 +1168,7 @@ 4.41 } 4.42 else if(expr instanceof GeneralDBSqlTemporalConstructUnary) 4.43 { 4.44 - return ResultType.PERIOD; 4.45 + return ResultType.INSTANT; 4.46 } 4.47 System.out.println("NOT SUPPORTED OPERATOR!!!"); 4.48 return ResultType.NULL;//SHOULD NEVER REACH THIS CASE
5.1 --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/iteration/GeneralDBBindingIteration.java Wed Jan 09 20:40:19 2013 +0200 5.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/iteration/GeneralDBBindingIteration.java Fri Jan 11 17:37:01 2013 +0200 5.3 @@ -8,13 +8,22 @@ 5.4 import java.sql.PreparedStatement; 5.5 import java.sql.ResultSet; 5.6 import java.sql.SQLException; 5.7 +import java.text.ParseException; 5.8 +import java.text.SimpleDateFormat; 5.9 +import java.util.Calendar; 5.10 import java.util.Collection; 5.11 +import java.util.GregorianCalendar; 5.12 import java.util.HashMap; 5.13 5.14 + 5.15 import org.openrdf.model.Value; 5.16 +import org.openrdf.model.impl.URIImpl; 5.17 import org.openrdf.query.BindingSet; 5.18 import org.openrdf.query.QueryEvaluationException; 5.19 import org.openrdf.query.algebra.evaluation.QueryBindingSet; 5.20 +import org.openrdf.query.algebra.evaluation.function.spatial.StrabonInstant; 5.21 +import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPeriod; 5.22 +import org.openrdf.query.algebra.evaluation.function.temporal.stsparql.relation.TemporalConstants; 5.23 import org.openrdf.sail.generaldb.GeneralDBSpatialFuncInfo; 5.24 import org.openrdf.sail.generaldb.GeneralDBValueFactory; 5.25 import org.openrdf.sail.generaldb.algebra.GeneralDBColumnVar; 5.26 @@ -180,6 +189,13 @@ 5.27 case WKB: 5.28 value = createBinaryGeoValueForSelectConstructs(rs, sp_ConstructIndexesAndNames.get(construct)); 5.29 break; 5.30 + case PERIOD: 5.31 + value = createPeriodValueForSelectConstructs(rs, sp_ConstructIndexesAndNames.get(construct)); 5.32 + break; 5.33 + case INSTANT: 5.34 + value = createPeriodValueForSelectConstructs(rs, sp_ConstructIndexesAndNames.get(construct)); 5.35 + break; 5.36 + 5.37 5.38 } 5.39 //Value value = createGeoValueForSelectConstructs(rs, sp_ConstructIndexesAndNames.get(construct)); 5.40 @@ -244,6 +260,45 @@ 5.41 return vf.asRdbmsLiteral(vf.createLiteral(potentialMetric)); 5.42 5.43 } 5.44 + 5.45 + protected RdbmsValue createPeriodValueForSelectConstructs(ResultSet rs, int index) 5.46 + throws SQLException 5.47 + { 5.48 + String datatype = null; 5.49 + String label = rs.getString(index + 1); 5.50 + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-DD'T'HH:mm:ss"); 5.51 + SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-DD HH:mm:ss"); 5.52 + 5.53 + if(label.contains(",")) //period representation 5.54 + { 5.55 + String start = label.substring(label.indexOf('[')+1,label.indexOf(',')); 5.56 + String end = label.substring(label.indexOf(',')+1,label.indexOf(')') ); 5.57 + 5.58 + if(start.equals(end)) 5.59 + { 5.60 + datatype = TemporalConstants.INSTANT; 5.61 + label = end; 5.62 + } 5.63 + else 5.64 + { 5.65 + datatype = TemporalConstants.PERIOD; 5.66 + } 5.67 + } 5.68 + else 5.69 + { 5.70 + label = label.replace(" ", "T"); 5.71 + datatype = TemporalConstants.INSTANT; 5.72 + } 5.73 + return vf.asRdbmsLiteral(vf.createLiteral(label,new URIImpl("<"+datatype+">"))); 5.74 + } 5.75 + protected RdbmsValue createInstantValueForSelectConstructs(ResultSet rs, int index) 5.76 + throws SQLException 5.77 + { 5.78 + String instant = rs.getString(index + 1); 5.79 + 5.80 + return vf.asRdbmsLiteral(vf.createLiteral(instant, new URIImpl(TemporalConstants.INSTANT))); 5.81 + 5.82 + } 5.83 5.84 protected RdbmsValue createIntegerGeoValueForSelectConstructs(ResultSet rs, int index) 5.85 throws SQLException
6.1 --- a/postgis/src/main/java/org/openrdf/sail/postgis/evaluation/PostGISQueryBuilder.java Wed Jan 09 20:40:19 2013 +0200 6.2 +++ b/postgis/src/main/java/org/openrdf/sail/postgis/evaluation/PostGISQueryBuilder.java Fri Jan 11 17:37:01 2013 +0200 6.3 @@ -362,7 +362,7 @@ 6.4 6.5 query.select().appendFunction(ST_ASBINARY); 6.6 } 6.7 - else if(expr instanceof GeneralDBSqlTemporalConstructUnary || expr instanceof GeneralDBSqlTemporalConstructBinary) 6.8 + else if( expr instanceof GeneralDBSqlTemporalConstructBinary) 6.9 { 6.10 isTemporalConstruct = true; 6.11 query.select().append(CSTRING_TO_TEXT);
7.1 --- a/postgis/src/main/java/org/openrdf/sail/postgis/iteration/PostGISBindingIteration.java Wed Jan 09 20:40:19 2013 +0200 7.2 +++ b/postgis/src/main/java/org/openrdf/sail/postgis/iteration/PostGISBindingIteration.java Fri Jan 11 17:37:01 2013 +0200 7.3 @@ -114,6 +114,10 @@ 7.4 return vf.createLiteral(label, datatype); 7.5 7.6 } 7.7 + else 7.8 + { 7.9 + System.out.println("createTemporalValue: THIS IS NOT A LITERAL!!!!!"); 7.10 + } 7.11 return createResource(rs, index); 7.12 } 7.13