Strabon
changeset 741:60a14eba94dd temporals
Temporal joins are now perfomed correctly. Tested with simple queries containing strdf:AfterPeriod, strdf:BeforePeriod, strdf:PeriodContains, strdf:containedByPeriod and strdf:PeriodOverlaps in the FILTER clause of the query.
line diff
1.1 --- a/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/stsparql/relation/InsideFunc.java Mon Nov 26 14:38:29 2012 +0200 1.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/stsparql/relation/InsideFunc.java Tue Nov 27 20:08:56 2012 +0200 1.3 @@ -20,6 +20,6 @@ 1.4 1.5 @Override 1.6 public String getURI() { 1.7 - return GeoConstants.inside; 1.8 + return GeoConstants.within; 1.9 } 1.10 }
2.1 --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/factories/GeneralDBBooleanExprFactory.java Mon Nov 26 14:38:29 2012 +0200 2.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/factories/GeneralDBBooleanExprFactory.java Tue Nov 27 20:08:56 2012 +0200 2.3 @@ -46,7 +46,13 @@ 2.4 import org.openrdf.query.algebra.evaluation.function.spatial.stsparql.construct.UnionFunc; 2.5 import org.openrdf.query.algebra.evaluation.function.spatial.stsparql.metric.AreaFunc; 2.6 import org.openrdf.query.algebra.evaluation.function.spatial.stsparql.relation.RelateFunc; 2.7 +import org.openrdf.query.algebra.evaluation.function.temporal.stsparql.relation.AfterPeriodFunc; 2.8 +import org.openrdf.query.algebra.evaluation.function.temporal.stsparql.relation.BeforePeriodFunc; 2.9 +import org.openrdf.query.algebra.evaluation.function.temporal.stsparql.relation.PeriodContainedByFunc; 2.10 +import org.openrdf.query.algebra.evaluation.function.temporal.stsparql.relation.PeriodContainsFunc; 2.11 import org.openrdf.query.algebra.evaluation.function.temporal.stsparql.relation.TemporalConstants; 2.12 +import org.openrdf.query.algebra.evaluation.function.temporal.stsparql.relation.TemporalRelationFunc; 2.13 +import org.openrdf.query.algebra.evaluation.function.temporal.stsparql.relation.periodOverlapsFunc; 2.14 import org.openrdf.query.algebra.helpers.QueryModelVisitorBase; 2.15 import org.openrdf.sail.generaldb.algebra.GeneralDBFalseValue; 2.16 import org.openrdf.sail.generaldb.algebra.GeneralDBRefIdColumn; 2.17 @@ -671,6 +677,35 @@ 2.18 2.19 result = spatialMetricPicker(function, leftArg, rightArg); 2.20 } 2.21 + else if(function instanceof TemporalRelationFunc) 2.22 + { 2.23 + ValueExpr left = functionCall.getArgs().get(0); 2.24 + ValueExpr right = functionCall.getArgs().get(1); 2.25 + 2.26 + 2.27 + GeneralDBSqlExpr leftArg = null; 2.28 + GeneralDBSqlExpr rightArg = null; 2.29 + GeneralDBSqlExpr thirdArg = null; 2.30 + 2.31 + if(left instanceof FunctionCall) 2.32 + { 2.33 + leftArg = temporalFunction((FunctionCall) left); 2.34 + } 2.35 + else 2.36 + { 2.37 + leftArg = label(left); 2.38 + } 2.39 + 2.40 + if(right instanceof FunctionCall) 2.41 + { 2.42 + rightArg = temporalFunction((FunctionCall) right); 2.43 + } 2.44 + else 2.45 + { 2.46 + rightArg = label(right); 2.47 + } 2.48 + result = temporalRelationPicker(function, leftArg, rightArg, thirdArg); 2.49 + } 2.50 else //default case 2.51 { 2.52 meetNode(functionCall); 2.53 @@ -699,7 +734,49 @@ 2.54 } 2.55 return null; 2.56 } 2.57 + 2.58 + public GeneralDBSqlExpr temporalFunction(FunctionCall functionCall) throws UnsupportedRdbmsOperatorException 2.59 + { 2.60 + Function function = FunctionRegistry.getInstance().get(functionCall.getURI()); 2.61 + //FIXME more cases to be added later. E.g, for the temporal construct functions and temporal metric functions 2.62 + if(function instanceof SpatialRelationshipFunc) 2.63 + { 2.64 + return temporalRelationFunction(functionCall,function); 2.65 + } 2.66 + 2.67 + return null; 2.68 + } 2.69 2.70 + GeneralDBSqlExpr temporalRelationFunction(FunctionCall functionCall, Function function) throws UnsupportedRdbmsOperatorException 2.71 + { 2.72 + ValueExpr left = functionCall.getArgs().get(0); 2.73 + ValueExpr right = functionCall.getArgs().get(1); 2.74 + 2.75 + 2.76 + GeneralDBSqlExpr leftArg = null; 2.77 + GeneralDBSqlExpr rightArg = null; 2.78 + GeneralDBSqlExpr thirdArg = null; 2.79 + 2.80 + if(left instanceof FunctionCall) 2.81 + { 2.82 + leftArg = temporalFunction((FunctionCall) left); 2.83 + } 2.84 + else 2.85 + { 2.86 + leftArg = label(left); 2.87 + } 2.88 + 2.89 + if(right instanceof FunctionCall) 2.90 + { 2.91 + rightArg = temporalFunction((FunctionCall) right); 2.92 + } 2.93 + else 2.94 + { 2.95 + rightArg = label(right); 2.96 + } 2.97 + 2.98 + return temporalRelationPicker(function, leftArg, rightArg, thirdArg); 2.99 + } 2.100 2.101 GeneralDBSqlExpr spatialRelationshipFunction(FunctionCall functionCall, Function function) throws UnsupportedRdbmsOperatorException 2.102 { 2.103 @@ -854,7 +931,36 @@ 2.104 return spatialPropertyPicker(function, expr); 2.105 2.106 } 2.107 - 2.108 + 2.109 + GeneralDBSqlExpr temporalRelationPicker(Function function,GeneralDBSqlExpr leftArg, GeneralDBSqlExpr rightArg, 2.110 + GeneralDBSqlExpr thirdArg) 2.111 + { 2.112 + if(function instanceof AfterPeriodFunc) 2.113 + { 2.114 + return afterPeriod(leftArg, rightArg); 2.115 + } 2.116 + else if(function instanceof BeforePeriodFunc) 2.117 + { 2.118 + return beforePeriod(leftArg, rightArg); 2.119 + } 2.120 + else if(function instanceof PeriodContainsFunc) 2.121 + { 2.122 + return periodContains(leftArg, rightArg); 2.123 + } 2.124 + else if(function instanceof PeriodContainedByFunc) 2.125 + { 2.126 + return periodContainedBy(leftArg, rightArg); 2.127 + } 2.128 + else if(function instanceof periodOverlapsFunc) 2.129 + { 2.130 + return periodOverlaps(leftArg, rightArg); 2.131 + } 2.132 + else 2.133 + { 2.134 + return null; 2.135 + } 2.136 + } 2.137 + 2.138 GeneralDBSqlExpr spatialRelationshipPicker(Function function,GeneralDBSqlExpr leftArg, GeneralDBSqlExpr rightArg, 2.139 GeneralDBSqlExpr thirdArg) 2.140 {
3.1 --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/evaluation/GeneralDBQueryBuilder.java Mon Nov 26 14:38:29 2012 +0200 3.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/evaluation/GeneralDBQueryBuilder.java Tue Nov 27 20:08:56 2012 +0200 3.3 @@ -1183,6 +1183,23 @@ 3.4 3.5 } 3.6 } 3.7 + 3.8 + protected void appendPeriod(GeneralDBLabelColumn var, GeneralDBSqlExprBuilder filter) 3.9 + { 3.10 + //I seriously doubt it will ever visit this case 3.11 + 3.12 + if (var.getRdbmsVar().isResource()) { 3.13 + filter.appendNull(); 3.14 + 3.15 + } 3.16 + else { 3.17 + String alias = getLabelAlias(var.getRdbmsVar()); 3.18 + 3.19 + filter.column(alias, "period"); 3.20 + 3.21 + } 3.22 + } 3.23 + 3.24 3.25 protected abstract String appendWKT(GeneralDBSqlExpr expr, GeneralDBSqlExprBuilder filter); 3.26
4.1 --- a/monetdb/src/main/java/org/openrdf/sail/monetdb/evaluation/MonetDBQueryBuilder.java Mon Nov 26 14:38:29 2012 +0200 4.2 +++ b/monetdb/src/main/java/org/openrdf/sail/monetdb/evaluation/MonetDBQueryBuilder.java Tue Nov 27 20:08:56 2012 +0200 4.3 @@ -377,6 +377,7 @@ 4.4 } 4.5 if(expr instanceof BinaryGeneralDBOperator) 4.6 { 4.7 + System.out.println("expr instanceof BinaryGeneralDBOperator"); 4.8 dispatchBinarySqlOperator((BinaryGeneralDBOperator) expr, (MonetDBSqlExprBuilder)query.select); 4.9 } 4.10 else if(expr instanceof UnaryGeneralDBOperator)
5.1 --- a/postgis/src/main/java/org/openrdf/sail/postgis/evaluation/PostGISQueryBuilder.java Mon Nov 26 14:38:29 2012 +0200 5.2 +++ b/postgis/src/main/java/org/openrdf/sail/postgis/evaluation/PostGISQueryBuilder.java Tue Nov 27 20:08:56 2012 +0200 5.3 @@ -1353,7 +1353,7 @@ 5.4 //XXX Incorporating SRID 5.5 String sridExpr = null; 5.6 5.7 - filter.openBracket(); 5.8 + //filter.openBracket(); 5.9 5.10 boolean check1 = expr.getLeftArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull"); 5.11 boolean check2 = expr.getRightArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull"); 5.12 @@ -1371,7 +1371,7 @@ 5.13 { 5.14 5.15 GeneralDBSqlExpr tmp = expr; 5.16 - if(tmp instanceof GeneralDBSqlSpatialConstructBinary && tmp.getParentNode() == null) 5.17 + if(tmp instanceof GeneralDBSqlTemporalConstructBinary && tmp.getParentNode() == null) 5.18 { 5.19 while(true) 5.20 { 5.21 @@ -1420,6 +1420,20 @@ 5.22 ///// 5.23 5.24 5.25 + 5.26 + 5.27 + 5.28 + filter.openBracket(); 5.29 + if (expr.getLeftArg() instanceof GeneralDBSqlTemporalConstructBinary) 5.30 + { 5.31 + appendConstructFunction(expr.getLeftArg(), filter); 5.32 + } 5.33 + else 5.34 + { 5.35 + appendPeriod((GeneralDBLabelColumn)(expr.getLeftArg()),filter); 5.36 + 5.37 + } 5.38 + 5.39 if(func.equals("=")|| func.equals("!=")|| func.equals("-")|| func.equals("+")|| func.equals("~")|| 5.40 func.equals("@")|| func.equals("<<")|| func.equals(">>")|| func.equals("&>")|| func.equals("&>")|| func.equals("&&")) 5.41 { 5.42 @@ -1427,12 +1441,6 @@ 5.43 5.44 } 5.45 5.46 - 5.47 - filter.openBracket(); 5.48 - if (expr.getLeftArg() instanceof GeneralDBSqlTemporalConstructBinary) 5.49 - { 5.50 - appendConstructFunction(expr.getLeftArg(), filter); 5.51 - } 5.52 //TODO:Think about adding more temporal function types (e.g., metrics, unary operators) 5.53 5.54 /*else if(expr.getLeftArg() instanceof GeneralDBSqlSpatialConstructUnary) 5.55 @@ -1448,17 +1456,21 @@ 5.56 { 5.57 appendMBB((GeneralDBLabelColumn)(expr.getLeftArg()),filter); 5.58 }*/ 5.59 - filter.appendComma(); 5.60 + //filter.appendComma(); 5.61 5.62 5.63 - filter.openBracket(); 5.64 +// //filter.openBracket(); 5.65 if (expr.getRightArg() instanceof GeneralDBSqlTemporalConstructBinary) 5.66 { 5.67 appendConstructFunction(expr.getRightArg(), filter); 5.68 } 5.69 + else 5.70 + { 5.71 + appendPeriod((GeneralDBLabelColumn)(expr.getRightArg()),filter); 5.72 + } 5.73 5.74 5.75 - filter.closeBracket(); 5.76 +// //filter.closeBracket(); 5.77 //SRID Support 5.78 if(expr instanceof GeneralDBSqlSpatialConstructBinary && expr.getParentNode() == null) 5.79 {
6.1 --- a/runtime/src/main/java/eu/earthobservatory/runtime/postgis/QueryOp.java Mon Nov 26 14:38:29 2012 +0200 6.2 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/postgis/QueryOp.java Tue Nov 27 20:08:56 2012 +0200 6.3 @@ -52,8 +52,7 @@ 6.4 strabon.query(queryString, Format.fromString(resultsFormat), strabon.getSailRepoConnection(), System.out); 6.5 6.6 } catch (Exception e) { 6.7 - logger.error("[Strabon.QueryOp] Error during execution of SPARQL query.", e); 6.8 - 6.9 + logger.error("[Strabon.QueryOp] Error during execution of SPARQL query.", e); 6.10 } finally { 6.11 if (strabon != null) { 6.12 strabon.close();