W3C home > Mailing lists > Public > public-sparql-dev@w3.org > October to December 2015

Re: quick sanity check question on sub-query, service and variable scoping

From: Gregory Williams <greg@evilfunhouse.com>
Date: Mon, 19 Oct 2015 11:54:50 -0700
Cc: Gary King <gwking@metabang.com>, public-sparql-dev@w3.org
Message-Id: <6E3E98F0-8F58-4BBB-8985-4568875F1DA2@evilfunhouse.com>
To: Miguel <miguel.ceriani@gmail.com>
On Oct 19, 2015, at 11:26 AM, Miguel <miguel.ceriani@gmail.com> wrote:
> Hi Gary,
> SERVICE blocks and sub-queries have different semantics relating to the variable scope.
> The variables in a sub-query are in a scope disjoint from the enclosing one, unless they are projected in the SELECT clause.
> So in the first example the variable ?time1 in the sub-query is distinct from the variable ?time1 in the main query.
> In this case you are correct, the inner ?time1 won't never be bound.
> The variables in a SERVICE blocks instead, share the same scope as the enclosing query.
> So in the second example there is only a ?time1 variable, referenced both inside and outside the SERVICE block.
> In this case ?time1 main perfectly be bound.
> Of course, if it is actually bound or not depends on the data.

I don’t think this is right. The bottom-up semantics of SERVICE (and SPARQL in general) means that the service block will be evaluated independently, and then joined with any results from the basic graph pattern that precedes it.

>> select distinct * {
>>   ?person a ex:Person .
>>   ?person ex:startTime ?time1 .
>>   service <http://example.com/foo> {
>>     ?otherPerson a ex:Person .
>>     ?otherPerson ex:startTime ?time2 .
>>     FILTER (?time2 > ?time1)
>>   }
>> }

Based on the description of “ Evaluation of a Service Pattern”[1]:

...the multiset of solution mappings corresponding to the results of executing query SELECT * WHERE Q against the service endpoint with IRI iri where Q is the serialization of P in SPARQL syntax, in case of a successful service invocation according to the SPARQL protocol...

the evaluation here is going to send the SPARQL query:

    ?otherPerson a ex:Person .
    ?otherPerson ex:startTime ?time2 .
    FILTER (?time2 > ?time1)

to the endpoint at <http://example.com/foo>. And since this query will always have ?time1 unbound at the point of evaluation, no results will be returned.


[1] http://www.w3.org/TR/2013/REC-sparql11-federated-query-20130321/#algebra_service
Received on Monday, 19 October 2015 18:55:15 UTC

This archive was generated by hypermail 2.3.1 : Monday, 19 October 2015 18:55:16 UTC