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

Re: Aggregate with Group By

From: Andy Seaborne <andy@apache.org>
Date: Tue, 25 Nov 2014 11:53:27 +0000
Message-ID: <54746DB7.2030301@apache.org>
To: public-sparql-dev@w3.org
On 19/11/14 17:47, Dimitrianos Savva wrote:
> Hello,
>
> What is the expected result set for the following query if we suppose
> that the graph pattern in WHERE does not match any triple;
>
> SELECT (sum(?c) as ?s)
> WHERE{
>     ?a ?b ?c .
>     FILTER (str(?a) = "something_that_not_exists")
> }
> GROUP BY ?a
>
> If I am not wrong, the same query without the GROUP BY, must return
> error (null).
>
> Regards,
> Dimis

If there is no GROUP BY, then because there is an aggregation, there is 
an implicit group of everything. See 11.  In the example, it's empty as 
the pattern has zero matches.

18.5.1:
Group(exprlist, Ω) = empty list -> empty set.

If there is a GROUP BY, then there are groups for each ?a, which is none:

18.5.1
Group(exprlist, Ω) = ?a -> empty set.

That is exprList, not the evaluation of the list which happens next ...

M(Ω) = { ListEval(exprlist, μ) | μ in Ω } = empty because no μ
Flatten(M) = empty
ToList(Flatten) = empty list

"sum" of no elements is 0 (18.5.1.3) (Card[S] = 0)

	Andy

PS ARQ in the last release gets this wrong: SUM empty was error (unset), 
and SUM DISTINCT was zero.  That's madness and will be fixed.
Received on Tuesday, 25 November 2014 11:54:01 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 6 January 2015 20:15:52 UTC