qmj0923 opened a new issue, #3040:
URL: https://github.com/apache/jena/issues/3040
### Version
4.10.0
### Question
I am using the following code to transform variables in the query:
```java
package test.example;
import org.apache.jena.query.Query;
import org.apache.jena.query.QueryFactory;
import org.apache.jena.query.Syntax;
import org.apache.jena.sparql.core.Var;
import org.apache.jena.sparql.syntax.syntaxtransform.QueryTransformOps;
import java.util.HashMap;
import java.util.Map;
public class Main {
public static void main(String[] args) {
String queryString = """
PREFIX : <http://example/>
SELECT ?a WHERE {
VALUES ?a { :q }
BIND (?a AS ?b)
?a ?c ?d.
}
""";
Query query = QueryFactory.create(queryString,
Syntax.syntaxSPARQL_11);
// System.out.println(query);
Map<Var, Var> varMap = new HashMap<>();
varMap.put(Var.alloc("a"), Var.alloc("newA"));
Query newQuery = QueryTransformOps.transform(query, varMap);
System.out.println(newQuery);
}
}
```
And the output is as follows:
```
SELECT ?newA
WHERE
{ VALUES ?a { :q }
BIND(?newA AS ?b)
?newA ?c ?d
}
```
I wonder why the `?a` in the VALUES clause is not replaced with `?newA`. I
find that it relates to this code:
https://github.com/apache/jena/blob/a3983b2a6d26c5dc7d849b7d5f2f550f9d607eb3/jena-arq/src/main/java/org/apache/jena/sparql/syntax/syntaxtransform/ApplyElementTransformVisitor.java#L114-L118
In the code, `((ElementTransformSubst) transform)` calls
`ElementTransformCopyBase.transform(ElementData el)`, so the substitution never
happens. Am I right?
--
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]