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

Re: example query on aggregates in SPARQL/Query Section 2

From: Birte Glimm <birte.glimm@comlab.ox.ac.uk>
Date: Thu, 5 Nov 2009 22:39:47 +0000
Message-ID: <492f2b0b0911051439p44f4f79oec686cb9195a99f@mail.gmail.com>
To: Axel Polleres <axel.polleres@deri.org>
Cc: SPARQL Working Group <public-rdf-dawg@w3.org>
2009/11/5 Axel Polleres <axel.polleres@deri.org>:
> Sorry guys, I mainly got confused with the example.
> There's nothing wrong with the issue, but I still think that the example
> query is laying a trap,
> as users might assume that this also works if there are several authors from
> the same org for the same book.

Do you mean because the price of the book is counted more than once
then? Other than that it should be possible. At least that's what I
think, but that is transferring my SQL knoweldge to SPARQL, so I might
be wrong. To be sure, I'll give an example and hope I got the right
answer...

Example data (same prefix):
:aff1 :affiliates :auth1 .
:aff1 :affiliates :auth2 .
:auth1 :writesBook :book1 .
:auth2 :writesBook :book1 .
:book1 :price 20 .

same query:
PREFIX  <http://books.example/>
SELECT SUM(?lprice) AS ?totalPrice
WHERE {
 ?org :affiliates ?auth .
 ?auth :writesBook ?book .
 ?book :price ?lprice
}
GROUP BY ?org
HAVING (SUM(?lprice) > 10)

Would give:
totalprice
------------
20

because before grouping I have
?org ?auth    ?book  ?lprice
:aff1  :auth1  :book1  10
:aff1  :auth2  :book1  10
then I group by ?org, summing over ?lprice, which is ok since ?auth
and ?book are not in the select clause.

Birte

> Axel
>
> On 5 Nov 2009, at 09:58, Axel Polleres wrote:
>
>> Just browsing over the example again and rethinking our discussion
>> regarding implicit grouping...
>>
>> PREFIX  <http://books.example/>
>> SELECT SUM(?lprice) AS ?totalPrice
>> WHERE {
>>  ?org :affiliates ?auth .
>>  ?auth :writesBook ?book .
>>  ?book :price ?lprice
>> }
>> GROUP BY ?org
>> HAVING (SUM(?lprice) > 10)
>>
>>
>> has ungrouped variables book, auth...Looking at our resolution, I honestly
>> don't get my head around the semantics here:
>>
>> "Consensus on prohibiting projecting variables/functions on variables that
>> are not included in the group by clause. Details are pending discussion of
>> ISSUE-41."
>>
>> That doesn't seem to cover this case, where there are ungrouped variables
>> that *don't* appear in projections or scalar functions.
>> Obviously, that query doesn't becomes weird if there are more than one
>> authors from the same org, or if there are several prices for the same book.
>>
>> Opinions to resolve?
>>
>> best,
>> Axel
>>
>
>
>



-- 
Dr. Birte Glimm, Room 306
Computing Laboratory
Parks Road
Oxford
OX1 3QD
United Kingdom
+44 (0)1865 283529
Received on Thursday, 5 November 2009 22:40:28 GMT

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