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

Re: Semantics of SUM

From: Steve Harris <steve.harris@garlik.com>
Date: Tue, 10 Nov 2009 18:47:34 +0000
Cc: RDF Data Access Working Group <public-rdf-dawg@w3.org>
Message-Id: <54599FC8-D4CF-4B3D-B392-B7E17A7556F5@garlik.com>
To: Andy Seaborne <andy.seaborne@talis.com>
On 10 Nov 2009, at 18:25, Andy Seaborne wrote:
> On 10/11/2009 17:57, Steve Harris wrote:
>>> > Consensus that SUM/AVG should use same semantics as +
>>>
>>> Clarification: errors not in a group means that what would be
>>>
>>> 1 + error + 2 => 3
>>>
>>> which is not the same as +
>>
>> Yep, which I think is why they are in the group, and why COALESCE is
>> important.
>
> I don't see that COALESCE helps because there isn't an intermediate  
> variable representing the sum so far.

I think the idea was something like:

SELECT SUM(COALESCE(xsd:double(?x), 0))
WHERE {
   <x> <value> ?x .
}

That parallels what you do in SQL:

 > SELECT * FROM C;
+------+
| val  |
+------+
| 1    |
| 2    |
| 5    |
| 23   |
| NULL |
+------+

 > SELECT SUM(COALESCE(val, 100)) FROM C;
+-------------------------+
| SUM(COALESCE(val, 100)) |
+-------------------------+
|                     131 |
+-------------------------+

- Steve

-- 
Steve Harris, CTO, Garlik Limited
2 Sheen Road, Richmond, TW9 1AE, UK
+44(0)20 8973 2465  http://www.garlik.com/
Registered in England and Wales 535 7233 VAT # 849 0517 11
Registered office: Thames House, Portsmouth Road, Esher, Surrey, KT10  
9AD
Received on Tuesday, 10 November 2009 18:48:09 GMT

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