Aklakan commented on issue #3040:
URL: https://github.com/apache/jena/issues/3040#issuecomment-2690151251

   Regarding
   ```sparql
   VALUES ?a { :q }
   BIND(?newA AS ?b)
   ```
   With latest Jena, you can no longer re-bind variables in the Jena 
implementation which is consistent with the [SPARQL 1.1 Spec Section 
10](https://www.w3.org/TR/sparql11-query/#assignment).
   
   Also, the ElementTransform code has undergone several fixes in the meantime.
   
   In your case, QueryTransformOps.transform by now refuses to rename the 
variable because it rejects the scoping.
   
   ```java
           String queryString = """
               PREFIX : <http://example/>
   
               SELECT ?a WHERE {
                   VALUES ?a { :q }
               }
           """;
           Map<Var, Var> varMap = new HashMap<>();
           varMap.put(Var.alloc("a"), Var.alloc("newA"));
           Query newQuery = QueryTransformOps.replaceVars(query, varMap);
           System.out.println(newQuery);
   ```
   gives
   ```
   Exception in thread "main" 
org.apache.jena.sparql.syntax.syntaxtransform.QueryScopeException: Can not use 
?a in this query
        at 
org.apache.jena.sparql.syntax.syntaxtransform.QuerySyntaxSubstituteScope.reject(QuerySyntaxSubstituteScope.java:68)
        at 
org.apache.jena.sparql.syntax.syntaxtransform.QuerySyntaxSubstituteScope.checkAssignment(QuerySyntaxSubstituteScope.java:64)
   ```
   
   @afs should this be the case?
   
   
   What does work, is going through the algebra:
   
   ```java
           String queryString = """
               PREFIX : <http://example/>
   
               SELECT ?a WHERE {
                   VALUES ?a { :q }
               }
           """;
           Map<Var, Var> varMap = new HashMap<>();
           varMap.put(Var.alloc("a"), Var.alloc("newA"));
   
           Query query = QueryFactory.create(queryString, 
Syntax.syntaxSPARQL_11);
           Op op = Algebra.compile(query);
           Op newOp = NodeTransformLib.transform(new 
NodeTransformSubst(varMap), op);
           Query newQuery = OpAsQuery.asQuery(newOp);
           System.out.println(newQuery);
   ```
   
   Output:
   ```
   SELECT  ?newA
   WHERE
     { VALUES ?newA { <http://example/q> } }
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to