Re: Filter-scope-1 test

Steve Harris wrote:
> I've a question regarding the filter-scope-1 test, I would have  
> expected the results below, which would be equivalent to FILTER(0)  
> after http://www.w3.org/TR/rdf-sparql-query/
> ยง 6.2, but instead I see something equivalent to if the OPTIONAL  
> block were missing entirely.
> 
> I can't find anything in the spec which suggests that evaluating a  
> FILTER() expression with out of scope variables should cause the  
> entire enclosing block to be disregarded. Though, I may have just  
> missed it.
> 
> I'm also not sure I like this scoping rule, it rules out some  
> potentially useful query forms, like:
> 
> SELECT *
> WHERE {
>    ?person :department ?dept .
>    OPTIONAL {
>      ?person :project ?proj .
>      FILTER(?dept = :technology)
>    }
> }

This is not the same case as the next example because of teh extra {} below: 
This is:

(leftjoin
   (BGP [triple ?person :department ?dept])
   (BGP [triple ?person :project ?proj])
   (= ?dept <http://example/technology>))

?dept is in scope because it becomes part of the left join condition.

?person :project ?proj is included when (?dept = :technology).

> 
> Data:
> 
> @prefix : <http://example/> .
> 
> :x :p 1 .
> :x :p 2 .
> :x :p 3 .
> :x :p 4 .
> 
> :x :q 1 .
> :x :q 2 .
> :x :q 3 .
> 
> Query:
> 
> PREFIX :    <http://example/>
> SELECT *
> {
>      :x :p ?v .
>      { :x :q ?w
>        OPTIONAL {  :x :p ?v2 FILTER(?v = 1) }
>      }
> }

Because of the extra {} this is a different structure to the first example:

(join
   (BGP [triple :x :p ?v])
   (leftjoin
     (BGP [triple :x :q ?w])
     (BGP [triple :x :p ?v2])
     (= ?v 1))
)


> 
> What I would expect: (excuse the use of NULL)

I'm having difficulty at this point : Could you explain why you expect 48 
(4*3*4) results all of which have ?v2 null?  Even old style, that wouldn't 
happen (i.e. get 4 matches when ?v = 1 and one otherwise).

It seems to have include { :x :p ?v2 } matches multiple times even when ?v != 
1  And for whatever evaluation we have, why is ?v2 null when ?v = 1?


In evaluation terms, the extra nesting given by the {} introduce a JOIN.

  :x :p ?v .

is one part and

{ :x :q ?w
       OPTIONAL {  :x :p ?v2 FILTER(?v = 1) }
}

the other part.

If you remove the {}

PREFIX :    <http://example/>
SELECT *
{
      :x :p ?v .
      :x :q ?w
        OPTIONAL {  :x :p ?v2 FILTER(?v = 1) }
}

the solutions are :

--------------
| v | w | v2 |
==============
| 4 | 3 |    |
| 4 | 2 |    |
| 4 | 1 |    |
| 3 | 3 |    |
| 3 | 2 |    |
| 3 | 1 |    |
| 2 | 3 |    |
| 2 | 2 |    |
| 2 | 1 |    |
| 1 | 3 | 4  |
| 1 | 3 | 3  |
| 1 | 3 | 2  |
| 1 | 3 | 1  |
| 1 | 2 | 4  |
| 1 | 2 | 3  |
| 1 | 2 | 2  |
| 1 | 2 | 1  |
| 1 | 1 | 4  |
| 1 | 1 | 3  |
| 1 | 1 | 2  |
| 1 | 1 | 1  |
--------------

> 
> ?v	?w	?v2	
> 1	1	NULL	
> 1	1	NULL	
> 1	1	NULL	
> 1	1	NULL	
> 1	3	NULL	
> 1	3	NULL	
> 1	3	NULL	
> 1	3	NULL	
> 1	2	NULL	
> 1	2	NULL	
> 1	2	NULL	
> 1	2	NULL	
> 3	1	NULL	
> 3	1	NULL	
> 3	1	NULL	
> 3	1	NULL	
> 3	3	NULL	
> 3	3	NULL	
> 3	3	NULL	
> 3	3	NULL	
> 3	2	NULL	
> 3	2	NULL	
> 3	2	NULL	
> 3	2	NULL	
> 2	1	NULL	
> 2	1	NULL	
> 2	1	NULL	
> 2	1	NULL	
> 2	3	NULL	
> 2	3	NULL	
> 2	3	NULL	
> 2	3	NULL	
> 2	2	NULL	
> 2	2	NULL	
> 2	2	NULL	
> 2	2	NULL	
> 4	1	NULL	
> 4	1	NULL	
> 4	1	NULL	
> 4	1	NULL	
> 4	3	NULL	
> 4	3	NULL	
> 4	3	NULL	
> 4	3	NULL	
> 4	2	NULL	
> 4	2	NULL	
> 4	2	NULL	
> 4	2	NULL	

	Andy

-- 
Hewlett-Packard Limited
Registered Office: Cain Road, Bracknell, Berks RG12 1HN
Registered No: 690597 England

Received on Wednesday, 27 June 2007 16:53:10 UTC