Closed MJRinne closed 10 years ago
As unintuitive as the current behavior looks to me, it may actually be according to specifications, i.e. a feature. Have to work on documenting and potentially close this one.
Actually, the example is not a valid query:
11.4 Aggregate Projection Restrictions
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.
Using the SPARQL built-in aggregate to calculate average prevents another variable value in the same SELECT-clause from updating.
Steps leading to the error:
1) Query (issue7.rq):
PREFIX : http://instans.org/ SELECT ?value (avg(?value) AS ?avg) WHERE { :data :value ?value }
2) Data (issue7.ttl):
@prefix : http://instans.org/ . :data :value 1 . :data :value 2 . :data :value 3 .
3) Command line: $ instans -r issue7.rq -t issue7.ttl
What happens:
The following output is produced:
value,avg 1,1.0 1,1.5 1,2.0
What was expected to happen:
The ?value-variable should have been updated with each step like this:
value,avg 1,1.0 2,1.5 3,2.0
The same error can be observed also when ?value is replaced with a variable, which is not related to the calculation of the aggregate.
When the average calculation is removed from the query: SELECT ?value WHERE { :data :value ?value }
The output is as expected:
value 1 2 3