Semantics of SUM

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.

If it's the same as + and also the error (I presume as an unbound) is in 
the collection of over which to SUM then one error cause the whole thing 
to be an error, which is not where we got to last time.

I suggest that the SUM is over things that "+" works on but if there is 
a non-addable item, it is simply skipped.

SUM(?x | ?x/{1,unbound,3}) is 4.

which makes AVG = SUM/COUNT for COUNT > 0.

How does COALESCE help?

SUM(?x | ?x/{1,"2",3}) is error or 4?  How is the error handled (we 
don't have errors at the moment - if one branch of a UNION has an error 
of this kind, is the whole thing an error?  What happened to streaming!)

SUM(xsd:integer(?x) | ?x/{1,"2",3}) is 6.

	Andy

Received on Tuesday, 10 November 2009 18:25:29 UTC