CommentResponse:ED-1

From SPARQL Working Group
Jump to: navigation, search

Draft response to:

http://lists.w3.org/Archives/Public/public-rdf-dawg-comments/2010Feb/0006.html


Dear Emanuele,

we still owe you an official response to the you original mail. We have discussed the issue of aggregates in depth at the group's recent F2F meeting. Although the general spirit of your alternative proposal is interesting, the group will at this stage go forward with the current design for aggregates.

Note especially, that in the presence of aggregates all variables that are projected need to be either be subject to a GROUP BY clause or an aggregation:

"In aggregate queries and sub-queries only expressions which have been used as GROUP BY expressions, or aggregated expressions (i.e. expressions where all variables appear inside an aggregate function) can be projected."

That is, the following of your (slightly simplified) examples would not be allowed syntactically since ?auth and ?name are not grouped in the outer query.

PREFIX : <http://books.example/> SELECT  ?auth ?name (AVG(?numberOfBooks) AS ?averageNumberOfBooks) WHERE { ?auth :name ?name

   {
           SELECT ?auth (COUNT(?book) AS ?numberOfBooks)
           WHERE {
                   ?auth :wrote ?book .
                 }
           GROUP BY ?auth
          HAVING (?numberOfBooks > 5)

}


best regards,

Axel, on behalf of the WG

=========

I tried to understand what Emanuele wants to achieve (but withou seeing indented results tables and examples I can't really), so the following second part of the response is optional:

=========

It seems that in the query you intend to duplicate the results of the AVG aggregate for each author in that example. Such duplicate output of the aggregated values was not considered within the WG a major use case.

You could achieve the same result though joining two subqueries:

PREFIX : <http://books.example/> SELECT * WHERE{ {SELECT ?auth (SAMPLE(?name) AS ?nam ) WHERE {

       ?auth :wrote ?book .
       ?auth :name ?name .
     }
     GROUP BY ?auth
     HAVING ((COUNT(?book) > 5)

}} {SELECT (AVG(?numberOfBooks) AS ?averageNumberOfBooks) WHERE {

   {
          SELECT (COUNT(?book) AS ?numberOfBooks)
          WHERE {
                   ?auth :wrote ?book .
                 }
          GROUP BY ?auth
          HAVING (?numberOfBooks > 5)
   }

}} }