Re: clarification on expected behavior of GROUP BY

On Apr 9, 2022, at 6:35 PM, Jeen Broekstra <jeen@fastmail.com> wrote:
> 
> hi all,
> 
> I recently had cause to revisit the expected behavior of SPARQL parsers when processing queries that involve a GROUP BY clause, and have managed to confuse myself a little as to what the intent is in the spec. In particular, I'm trying to establish when a parser should flag an error for an expression in the projection that is not present in the GROUP BY clause.
> 
> The relevant part in the SPARQL 1.1 spec is section 11.4 (https://www.w3.org/TR/sparql11-query/#aggregateRestrictions <https://www.w3.org/TR/sparql11-query/#aggregateRestrictions>):
> 
>> In a query level which uses aggregates, only expressions consisting of aggregates and constants may be projected, with one exception. When GROUP BY is given with one or more simple expressions consisting of just a variable, those variables may be projected from the level.

The wording here does seem problematic. I think the intention is not so much the use of “aggregates,” but in the use of the aggregation mechanism in general. I would consider this to be determined in the first two (out of three) `if` cases in the pseudo-code given in section 18.2.4.1:

If Q contains GROUP BY exprlist
   Let G := Group(exprlist, P)
Else If Q contains an aggregate in SELECT, HAVING, ORDER BY
   Let G := Group((1), P)
Else
   skip the rest of the aggregate step
   End

So I think that "only expressions consisting of aggregates and constants may be projected, with one exception” should apply in either of the cases:

* there is a GROUP BY clause
* there is use of aggregates in SELECT, HAVING, or ORDER BY clauses

Sounds like a good thing to clarify in the errata.


.greg

Received on Sunday, 10 April 2022 04:28:42 UTC