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: Thu, 12 Nov 2009 15:47:54 +0000
Cc: RDF Data Access Working Group <public-rdf-dawg@w3.org>
Message-Id: <BA340C9C-F622-4085-BFAC-C21BE0DD895C@garlik.com>
To: Andy Seaborne <andy.seaborne@talis.com>
On 11 Nov 2009, at 10:46, Andy Seaborne wrote:
> On 10/11/2009 18:47, Steve Harris wrote:
>>
>>> 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 .
>> }
>
> Thanks - I'd missed that.

To be clear, it's just my recollection of what we discussed, I don't  
think anything specific was in the minutes.

> However, it does not quite follow the semantics of "+" because it  
> changes the datatype:
>
> SUM(?x | ?x{1,2,3} ) ==> "6"^^xsd:integer
>
> but
>
> SUM(COALESCE(xsd:double(?x), 0) | ?x{1,2,3} ) => "6"^^xsd:double
>
> Using xsd:integer does not work e.g. 1, 1.5, 3 !=> "5.5"^^xsd:decimal

So, in 4store, if I do:

PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
SELECT (xsd:double(1) + xsd:double(2)) AS sum
WHERE {}

I get "3"^^<http://www.w3.org/2001/XMLSchema#double>, so that looks  
consistent with + to me.

I'm not claiming that 4store is a perfect implementation of the spec  
(it's not!), but that looks consistent with SPARQL 1.0's + to me.

Or did you mean the COALESCE(xsd:double(?x), 0) bit? I guess I should  
have written COALESCE(xsd:double(?x), 0e1), or xsd:double(COALESCE(?x,  
0)).

> I don't see how to write a MIN that works using COALESCE because  
> there is no natural value that plays the role zero did (e.g. MIN  
> over strings mixed with non-strings).
>
> MIN(IF(datatype(?x)=xsd:String, ?x, ???))
>
> And xsd:integers are arbitrary length so the COALESCE idiom is hard  
> for MIN (either definition).
>
>
> If SUM follows +, does MIN follow < or ORDER BY?

http://www.w3.org/2009/sparql/wiki/F2F2_Issue_Discussions says MIN/MAX  
follows ORDER BY.

- 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 Thursday, 12 November 2009 15:48:32 GMT

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