good afternoon;

> On 2017-11-04, at 12:18, Andy Seaborne <[email protected]> wrote:
> 
> Following on from the thread in October "Problem with MAX when no result 
> expected" <https://s.apache.org/03Hz> here is an investigation into SPARQL 
> Aggregation, both what the spec says and what ARQ does.
> 
> It would be interesting to get reports about other implementations for these 
> two queries:
> 
> Q1: SELECT (COUNT(*) AS ?C1) { ?s ?p ?o FILTER(false) }
> Q2: SELECT (COUNT(*) AS ?C2) { ?s ?p ?o FILTER(false) } GROUP BY ?s

http://dydra.com/jhacker/foaf/@query#q1 : 0
http://dydra.com/jhacker/foaf/@query#q2 : no result

> 
> It doesn't matter what the data is - the WHERE {} does not match anything. Or 
> use Q1,Q2 below with an empty dataset.
> 
> == tl;dr
> 
> I think that ARQ follows the spec but the spec is not what you might expect 
> from an SQL background.

i have no background implementing sql.

> 
> ==
> 
> The original question rose from the case of no matches to the WHERE clause.
> 
> * What happens when there is no GROUP BY
> * What happens when there is a GROUP BY
> 
> Q1: SELECT (COUNT(*) AS ?C1) { ?s ?p ?o }
> Q2: SELECT (COUNT(*) AS ?C2) { ?s ?p ?o } GROUP BY ?s
> 
> with no matches to the graph pattern  { ?s ?p ?o }.
> (beware below! {} are being used in different ways!)
> 
> == The SPARQL 1.1 specification
> 
> In the definition of "Group",
> https://www.w3.org/TR/sparql11-query/#defn_algGroup
> 
> If the pattern does not match, then Group(exprlist, Ω) is the empty set ∅.
> 
> ListEval(exprlist, μ) is the GROUP BY key
>  μ is a row ("solution mapping" in the spec).
> 
> ListEval(exprlist, μ) → { μ' ... } is the grouping of rows by GROUP BY. For 
> each group, there is a set of rows. It's a map from key to set of rows.
> 
> If there are no matches, so no μ, there are no entries in this map. When 
> there are no matches to the pattern "WHERE { ?s ?p ?o }", so no μ, there are 
> no entries in this map; { μ' ... } is the empty set ∅.
> 
> From here, the rest of the definitions simplify down to empty.
> 
> Aggregation(exprlist, func, scalarvals, ∅) is ∅.
> AggregateJoin(∅) = ∅.
> Flatten(∅) = ∅.
> 
> COUNT(∅) = 0 (xsd:integer zero)
> SUM(∅) = 0
> AVG, MIN, MAX, SAMPLE are errors
> GROUP_CONCAT = ""
> 
> Throughout this, it does not matter if there is a GROUP BY clause or not 
> because "Group" is the empty set ∅ in both cases.

there is a reading of the recommendation text according to which the two sets 
which are empty are not of the same kind.
in one case, the set is that over which the aggregation operations run and in 
that case, the result is 0.
in the other case it is the set of groups, in which case, there is no set of 
solutions over which to run the aggregation and therefore there is no result.

is there some way to read the text such that the empty set of groups transforms 
into an empty set of solutions?



---
james anderson | [email protected] | http://dydra.com





Reply via email to