Re: Filter scope and optionals

On 30 Oct 2006, at 10:54, Seaborne, Andy wrote:

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

My expectation when reading SPARQL queries is that ?vars will have  
whole-query scope, that might just be SQL bias, but it can't be that  
uncommon.

If FILTER() has the scope of its containing-containing block then  
that will do surprising (to my mind) things when you have eg.

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

- Steve

Received on Monday, 30 October 2006 15:59:27 UTC