# HG changeset patch # User Stella Giannakopoulou # Date 1418918637 -7200 # Node ID 3776ff96efea50f3686a8272a2c3d70d9f2bf773 # Parent 47a6ec31f27c72aecdf047e7cd72368d0ffa7e09 bug #78: fixed also the case where spatial functions in SELECT did not recognize the variables that result from a BIND. For this, I changed the tuple expression, so that it evaluates in Java the spatial functions that contain such kind of variables. diff -r 47a6ec31f27c -r 3776ff96efea generaldb/src/main/java/org/openrdf/sail/generaldb/optimizers/GeneralDBSelectQueryOptimizer.java --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/optimizers/GeneralDBSelectQueryOptimizer.java Thu Dec 18 17:56:55 2014 +0200 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/optimizers/GeneralDBSelectQueryOptimizer.java Thu Dec 18 18:03:57 2014 +0200 @@ -140,6 +140,9 @@ private Group referenceGroupBy = null; + //used to keep the names used in a BIND clause + private Set namesInBind = new HashSet(); + //Counter used to enumerate expressions in having private int havingID = 1; @@ -993,8 +996,10 @@ if (expr instanceof FunctionCall) //if (expr instanceof FunctionCall && !isFuncExprGrounded(expr)) - { // if the expr is grounded we are going to evaluate it in Java - if(!evaluateInJava(expr)) + { // if the expr is grounded we are going to evaluate it in Java + //also if the function involves variables from a BIND clause + //we evaluate it in java + if(!evaluateInJava(expr) && !varInBind(expr)) { Function function = FunctionRegistry.getInstance().get(((FunctionCall) expr).getURI()); if(function instanceof SpatialPropertyFunc || function instanceof SpatialRelationshipFunc || @@ -1009,7 +1014,7 @@ iter.remove(); } } - else //Union (or Extent) is used as an aggregate function on Select Clause! + else if(!varInBind(expr)) //Union (or Extent) is used as an aggregate function on Select Clause! { //must add as aggregate if(this.referenceGroupBy != null) @@ -1019,7 +1024,10 @@ } iter.remove(); } - + //if the name of the new variable is not present in the projection + //then it results from a BIND + if(!(node.getParentNode() instanceof Projection)) + namesInBind.add(name+"?spatial"); } //Issue: MathExpr is not exclusively met in spatial cases! //Need to distinguish thematic and spatial!! @@ -1254,6 +1262,32 @@ } + /** + * + * @param expr + * @return true if the variable occurs inside a BIND clause + * false otherwise + */ + private boolean varInBind(ValueExpr expr) + { + if(expr instanceof FunctionCall) + { + for(int i = 0 ; i< ((FunctionCall) expr).getArgs().size(); i++) + { + return varInBind(((FunctionCall) expr).getArgs().get(i)); + } + return false; + } + else if(expr instanceof Var) //Var + { + if(namesInBind.contains(((Var)expr).getName())) + return true; + return false; + } + else + return false; + } + @Override public void meet(Slice node) throws RuntimeException