rdf4j
rdf4j copied to clipboard
QueryStringUtil.getTupleQueryString doesnt handle inline binding expressions
The handling of binding substitution fails for queries of the form select (func(?x) as ?y)
. For a binding x=foo the output is select (func('foo' as ?x) as ?y)
when it should be select (func('foo') as ?y)
. The current code only works for select ?x ?y ?z
type queries. Regex needs to be modified to ignore patterns that are preceeded by 'as'.
I think I understand what this is about, but could you make a small example for us so we can make a test. That would help us a lot!
select (count(?o) as ?c) {?s ?p ?o} with binding o='foo'
Example fix:
.
.
. for (String name : bindings.getBindingNames()) {
String replacement = QueryStringUtil.valueToString(bindings.getValue(name));
if (replacement != null) {
String pattern = "[\\?\\$]" + name + "(?!\\s?\\))(?=\\W)";
select = select.replaceAll(pattern, "(" + Matcher.quoteReplacement(replacement) + " as ?" + name + ")");
pattern = "[\\?\\$]" + name + "(?=\\s?\\)\\W)";
select = select.replaceAll(pattern, Matcher.quoteReplacement(replacement));
pattern = "[\\?\\$]" + name + "(?=\\W)";
where = where.replaceAll(pattern, Matcher.quoteReplacement(replacement));
}
}
.
.
.
Related issues: #2212 and #520
This should be a decent first issue for hacktoberfest. Just write a couple of tests and try out the fix from @pulquero . It's a good patch for the time being.
Tried to assign @Sanchit-Trivedi