clarification on expected behavior of GROUP BY

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):

> 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.

This states that these restrictions on the projection *only* apply to queries that involve aggregates. So, for example:

PREFIX : <http://example/>
SELECT (COUNT(?s) as ?count) ?v
{ ?s :p ?v . }
GROUP BY ?s

is syntactically invalid because ?v is not a constant, nor an aggregate expression, and it is not part of the GROUP BY.

However, 

PREFIX : <http://example/>
SELECT ?s ?v
{ ?s :p ?v . }
GROUP BY ?s

should be syntactically fine, unless I'm missing something, since there is no aggregate involved in the query.

Yet the SPARQL test suite covers this exact example as a negative syntax test:

- https://www.w3.org/2009/sparql/docs/tests/summary.html#grouping-group06
- https://www.w3.org/2009/sparql/docs/tests/summary.html#grouping-group07 <https://www.w3.org/2009/sparql/docs/tests/summary.html#grouping-group06>

So my question is: is there a relevant part of the spec or the errata that I'm overlooking, or are these two test cases in conflict with the  1.1 spec?

Jeen

Received on Sunday, 10 April 2022 01:36:34 UTC