W3C home > Mailing lists > Public > public-sparql-dev@w3.org > January to March 2016

BIND behaviour and GroupGraphPatterns

From: Jörn Hees <j_hees@cs.uni-kl.de>
Date: Thu, 17 Mar 2016 11:16:44 +0100
Message-Id: <B1D87D40-E4ED-4CA6-900E-CE984382940C@cs.uni-kl.de>
To: public-sparql-dev@w3.org
Hi,

i have a question about the "intended scope" of BIND...

Trying to fix an issue in the RDFLib SPARQL processor [1], i came up with what i thought was a minimal breaking test [2] like this:

This works (correctly binds ?z in RDFLib):
select * {
 ?s ?p ?o .
 bind(?o as ?z)
}

This doesn't:
select * {
 ?s ?p ?o .
 { bind(?o as ?z) }
}

(At this time, my expectation was that the latter should also bind ?z. Later, I found out that jena disagrees (see appendix).)

So i went down in our implementation and fixed the behaviour, making my tests for [1] pass.

To my surprise the fix caused another test to fail, namely bind07 [3] from the SPARQL 1.1 test cases:

SELECT ?s ?p ?o ?z {
 ?s ?p ?o .
 { BIND(?o+1 AS ?z) } UNION { BIND(?o+2 AS ?z) }
}

The test asserts that ?z is unbound.
I guess that the intention of that test was to make sure ?z isn't bound to different values.

What i find weird about this is that it's inconsistent with other ways to bind ?z to different things which are allowed:

SELECT ?s ?p ?o ?z {
 ?s ?p ?o .
 { ?s ?p ?z } UNION { ?z ?p ?o }
}


So my questions are:
- Is [3] correct? What is the motivation?
- Should ?z be bound in this: select * { ?s ?p ?o .  { bind(?o as ?z) } }  ?


Cheers,
Jörn

[1]: https://github.com/RDFLib/rdflib/issues/580
[2]: https://github.com/RDFLib/rdflib/pull/601
[3]: https://www.w3.org/2009/sparql/docs/tests/data-sparql11/bind/bind07.rq



Appendix: some tests in jena on the commandline


This works as expected:
$ sparql --data=https://www.w3.org/2009/sparql/docs/tests/data-sparql11/bind/data.ttl --query=<(echo '
select * {
 ?s ?p ?o .
 bind(?o as ?z)
}
')
------------------------------------------------------------
| s                       | p                      | o | z |
============================================================
| <http://example.org/s1> | <http://example.org/p> | 1 | 1 |
| <http://example.org/s4> | <http://example.org/p> | 4 | 4 |
| <http://example.org/s3> | <http://example.org/p> | 3 | 3 |
| <http://example.org/s2> | <http://example.org/p> | 2 | 2 |
------------------------------------------------------------


This doesn't:
$ sparql --data=https://www.w3.org/2009/sparql/docs/tests/data-sparql11/bind/data.ttl --query=<(echo '
select * {
 ?s ?p ?o .
 { bind(?o as ?z) }
}
')
------------------------------------------------------------
| s                       | p                      | o | z |
============================================================
| <http://example.org/s1> | <http://example.org/p> | 1 |   |
| <http://example.org/s4> | <http://example.org/p> | 4 |   |
| <http://example.org/s3> | <http://example.org/p> | 3 |   |
| <http://example.org/s2> | <http://example.org/p> | 2 |   |
------------------------------------------------------------


Test [3]:
$ sparql --data=https://www.w3.org/2009/sparql/docs/tests/data-sparql11/bind/data.ttl --query=https://www.w3.org/2009/sparql/docs/tests/data-sparql11/bind/bind07.rq
--------------------
| s   | p  | o | z |
====================
| :s1 | :p | 1 |   |
| :s4 | :p | 4 |   |
| :s3 | :p | 3 |   |
| :s2 | :p | 2 |   |
| :s1 | :p | 1 |   |
| :s4 | :p | 4 |   |
| :s3 | :p | 3 |   |
| :s2 | :p | 2 |   |
--------------------


This binds ?z:
$ sparql --data=https://www.w3.org/2009/sparql/docs/tests/data-sparql11/bind/data.ttl --query=<(echo '
select * {
 ?s ?p ?o .
 {{ ?s ?p ?z } UNION { ?z ?p ?o }}
}
')
----------------------------------------------------------------------------------
| s                       | p                      | o | z                       |
==================================================================================
| <http://example.org/s1> | <http://example.org/p> | 1 | 1                       |
| <http://example.org/s1> | <http://example.org/p> | 1 | <http://example.org/s1> |
| <http://example.org/s4> | <http://example.org/p> | 4 | 4                       |
| <http://example.org/s4> | <http://example.org/p> | 4 | <http://example.org/s4> |
| <http://example.org/s3> | <http://example.org/p> | 3 | 3                       |
| <http://example.org/s3> | <http://example.org/p> | 3 | <http://example.org/s3> |
| <http://example.org/s2> | <http://example.org/p> | 2 | 2                       |
| <http://example.org/s2> | <http://example.org/p> | 2 | <http://example.org/s2> |
----------------------------------------------------------------------------------
Received on Thursday, 17 March 2016 10:16:56 UTC

This archive was generated by hypermail 2.3.1 : Thursday, 17 March 2016 10:16:57 UTC