You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jena.apache.org by "Claus Stadler (JIRA)" <ji...@apache.org> on 2016/04/27 15:22:14 UTC
[jira] [Created] (JENA-1170) QueryTransformLib cannot rename
varibales
Claus Stadler created JENA-1170:
-----------------------------------
Summary: QueryTransformLib cannot rename varibales
Key: JENA-1170
URL: https://issues.apache.org/jira/browse/JENA-1170
Project: Apache Jena
Issue Type: Bug
Components: ARQ
Affects Versions: Jena 3.0.1
Reporter: Claus Stadler
Renaming variables of a query - a rather basic use case when transforming queries - does not work with the snippet below due to a raised exception:
Map<Var, Node> vmap = Collections.singletonMap(Var.alloc("a"), (Node)Var.alloc("x"));
Query foo = QueryFactory.create("Select ?a { ?a ?b ?c }");
Query bar = QueryTransformOps.transform(foo, vmap);
The reason is, that the way QueryTransformOps.transformVarExprList[1] is implemented, prevents this. Also, a much nicer (unfortunately private) implementation already exists at Transformer.ApplyTransformVisitor.process[2]
I suggest to make [2] publicly accessible (e.g. as part of one of the TransformLibs or a VarExprUtils) and implement [1] based on that:
class QueryTransformOps {
private static void transformVarExprList(VarExprList varExprList, ExprTransform exprTransform)
{
VarExprList tmp = VarExprListUtils.transform(varExprList, exprTransform);
VarExprListUtils.replace(varExprList, tmp);
}
}
class VarExprListUtils {
public static void replace(VarExprList dst, VarExprList src) {
if(dst != src) {
dst.clear();
copy(dst, src);
}
}
public static void copy(VarExprList dst, VarExprList src) {
for(Var v : src.getVars()) {
Expr e = src.getExpr(v);
if(e == null) {
src.add(v);
} else {
src.add(v, e);
}
}
}
}
[1] https://github.com/apache/jena/blob/master/jena-arq/src/main/java/org/apache/jena/sparql/algebra/Transformer.java#L243
[2] https://github.com/apache/jena/blob/master/jena-arq/src/main/java/org/apache/jena/sparql/syntax/syntaxtransform/QueryTransformOps.java#L74
As a side note, it would be convenient, if the transform method also accepted a Map<Var, Var> - i.e. changing the method signature to accept a Map<Var, ? extends Node>
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)