CommentResponse:DB-11

From SPARQL Working Group
Jump to: navigation, search

David,

Section 10.1 "BIND: Assigning to Variables" says it ends the current basic graph pattern. Section 18.2.2.5 "Translate Graph Patterns" defines how it maps the "extend" operator in the SPARQL algebra. It is then within a group graph pattern. The purpose of bind is to set a variable based on the current basic graph pattern, not the whole query.

Evaluation of a group graph pattern in SPARQL happens by evaluating each of the separate elements of the group and then combining them with JOIN. While it can be tempting to top-to-bottom, that is not how query evaluation is defined (from SPARQL 1.0).

The query document isn't a complete tutorial for SPARQL (that would be a much larger task). The formal sections give a precise definition and section 18.2.2.5 covers how the BIND syntax maps to the extend operator and how it interacts with the syntax group, becoming a "join" to be evaluated.

> For example, I'd like to use the same variable ?limit bound to the
> constant 10 in multiple GRAPH clauses like this:
> 
>   SELECT *
>   WHERE { 
>     GRAPH ... { 
>       FILTER( ?n <= ?limit )
>     } 
>     GRAPH ... { 
>       FILTER( ?n <= ?limit )
>     } 
>     GRAPH ... { 
>       FILTER( ?n <= ?limit )
>     } 
> 
>   }
> 
> But where should I put the BIND statement to achieve this?

You may be able to achieve the effect by placing the FILTER further out:

SELECT *
WHERE { 
  { SELECT * # including ?n
    { 
      GRAPH ... { }
      GRAPH ... { }
      GRAPH ... { }
    } 
  }
  FILTER( ?n <= ?limit )
}


We would be grateful if you would acknowledge that your comment has been answered by sending a reply to this mailing list.

Andy (on behalf of the SPARQL WG)