Hi,
I discovered a bug in the Jena ARQ engine.
RDF Document:
-------------
<?xml version='1.0' encoding='UTF-8'?>
<rdf:RDF xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'
xmlns:foaf='http://xmlns.com/foaf/0.1/'
xmlns:own='http://mytests/' >
<rdf:Description rdf:about='http://mytests/a'>
<own:tv>0</own:tv>
<own:tv>1</own:tv>
<own:false>0</own:false>
<own:true>1</own:true>
</rdf:Description>
</rdf:RDF>
Query 1:
--------
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX own: <http://mytests/>
SELECT ?X1 ?Y1 ?A0 ?A1 ?B0 ?B1
WHERE
{
own:a own:true ?B0 .
OPTIONAL {
{
own:a own:true ?X1 .
own:a own:true ?Y1 .
own:a own:false ?A0 .
own:a own:true ?A1 .
own:a own:false ?B0 .
own:a own:true ?B1 .
}
UNION
{
own:a own:false ?X1 .
own:a own:false ?Y1 .
own:a own:false ?A0 .
own:a own:true ?A1 .
own:a own:false ?B0 .
own:a own:true ?B1 .
}
}
}
Query 2:
--------
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX own: <http://mytests/>
SELECT ?X1 ?Y1 ?A0 ?A1 ?B0 ?B1
WHERE
{
own:a own:true ?B0 .
OPTIONAL {
{
own:a own:tv ?X1 .
own:a own:true ?A1 .
own:a own:false ?A0 .
}
OPTIONAL {
{
own:a own:tv ?X1 .
own:a own:tv ?Y1 .
own:a own:true ?B1 .
own:a own:false ?B0 .
}
{ { own:a own:true ?Y1 . } UNION { own:a own:false ?X1 . } }
{ { own:a own:true ?X1 . } UNION { own:a own:false ?Y1 . } }
}
}
}
In both expressions, the expressions encapsulated in the inner /outer/
optional expression evaluate to the same result, namely:
-------------------------------------
| X1 | Y1 | A0 | A1 | B0 | B1 |
=====================================
| "1" | "1" | "0" | "1" | "0" | "1" |
| "0" | "0" | "0" | "1" | "0" | "1" |
-------------------------------------
In both cases, this is the expected result. When now adding the outer
OPT-expression, namely
> own:a own:true ?B0 . OPTIONAL {
> ...
> }
the first query still works fine (Result: ?B0 -> 1), whereas the
second one produces a wrong result:
-----------------------------------
| X1 | Y1 | A0 | A1 | B0 | B1 |
===================================
| "1" | | "0" | "1" | "1" | |
| "0" | | "0" | "1" | "1" | |
-----------------------------------
Also checked the query with the JRDF SPARQL implementation. This
implementation gives the same (correct) result in both cases.
Kind Regards
Michael