W3C home > Mailing lists > Public > public-rdf-dawg@w3.org > October to December 2006

Re: Filter scope and optionals

From: Steve Harris <steve.harris@garlik.com>
Date: Mon, 30 Oct 2006 15:58:35 +0000
Message-Id: <85B89B90-F076-49EE-BD53-028856D26115@garlik.com>
Cc: RDF Data Access Working Group <public-rdf-dawg@w3.org>
To: andy.seaborne@hp.com


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 GMT

This archive was generated by hypermail 2.3.1 : Tuesday, 26 March 2013 16:15:27 GMT