Filter scope and optionals

If the proposed filter scoping rule is taken naively, there isn't a way to get 
value testing conditions into the left join conditions for optional (unlike 
the join conditions for a group).

Here's an example:

---- Data
@prefix   :         <http://example/> .

:x1 :p 1 .
:x2 :p 2 .

:x3 :q 3 .
:x3 :q 4 .
---- Data


---- Query
PREFIX :    <http://example/>

SELECT *
{
   ?x :p ?v .
   OPTIONAL
   {
     ?y :q ?w .
     FILTER(?v=2)
   }
}
---- Query


---- Results 1
---------------------
| x   | v | y   | w |
=====================
| :x2 | 2 | :x3 | 4 |
| :x2 | 2 | :x3 | 3 |
| :x1 | 1 |     |   |
---------------------

---- Results 2
-------------------
| x   | v | y | w |
===================
| :x2 | 2 |   |   |
| :x1 | 1 |   |   |
-------------------

Results 1 is what the current doc (declarative form) gets - and would be the 
same if the FILTER were part of the left outer join conditions.

Results 2 is what a purely filter-scoped-to-group gets because the optional 
part never matches because ?v is an unbound variable.


I can't see any way of getting filter into the scope of the left outer join. 
The only way I can see of rewriting this query is to use a UNION and repeat 
the fixed pattern on each side of the union, one side including the filter and 
  optional triple pattern. That query is going to give different answers and 
the app will have to post-process the results to find out what went on.

Intuitively, the scope rule needs to be modified to put the filter just 
outside the group, allowing it to be part of the left outer join, and not just 
inside the group.

Any alternatives?
How do we formalize this?

 Andy

Received on Monday, 30 October 2006 10:54:15 UTC