rdf4j icon indicating copy to clipboard operation
rdf4j copied to clipboard

QueryStringUtil.getTupleQueryString doesnt handle inline binding expressions

Open pulquero opened this issue 3 years ago • 6 comments

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'.

pulquero avatar Sep 23 '20 11:09 pulquero

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!

hmottestad avatar Sep 24 '20 07:09 hmottestad

select (count(?o) as ?c) {?s ?p ?o} with binding o='foo'

pulquero avatar Sep 24 '20 12:09 pulquero

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));
			}
		}
.
.
.

pulquero avatar Sep 24 '20 13:09 pulquero

Related issues: #2212 and #520

abrokenjester avatar Sep 25 '20 01:09 abrokenjester

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.

hmottestad avatar Sep 26 '20 15:09 hmottestad

Tried to assign @Sanchit-Trivedi

hmottestad avatar May 15 '22 05:05 hmottestad