- From: Birte Glimm <birte.glimm@uni-ulm.de>
- Date: Tue, 5 Jun 2012 12:13:14 +0200
- To: Andy Seaborne <andy.seaborne@epimorphics.com>
- Cc: SPARQL Working Group <public-rdf-dawg@w3.org>
On 3 June 2012 17:03, Andy Seaborne <andy.seaborne@epimorphics.com> wrote:
> Can aggregate expressions contain aggregates?
My hope/assumption was that the grammar rules this out, but looking
carefully, it seems it doesn't :-(
> This comes from a recent email [1] and while these may well not actually
> address the application goal (a subquery was meant - see thread), the SPARQL
> 1.1 Query spec does permit these unusual queries.
>
> Example:
>
> PREFIX ex: <http://example.org/meals#>
> SELECT (AVG(?mealPrice * (1.0 + MAX( ?mealTip / ?mealPrice)))
> AS ?avgCostWithBestTip)
> WHERE {
> ?description ex:mealPrice ?mealPrice .
> ?description ex:mealTip ?mealTip .
> } GROUP BY ?description
>
> i.e.an aggregate inside an aggregate: AVG(?x * MAX (?y) )
>
> One line of argument is that the expression inside the aggregate is applied
> to each row, so only row variables should be considered in-scope. The
> aggregate AVG(max(?x)+1) is violating that as max(?x) is not a per-row
> expression.
If we use this line of argument, it certainly has to be made explicit
in the spec. Otherwise it's hard to get the connection.
[snip]
> Related to this is the interaction with select expressions:
>
> SELECT (max(?x) As ?M) (avg(?M+1) AS ?A)
>
> because the select expression rules say you can use ?M inside AVG().
That also doesn't look nice.
> If we wish to forbid this, we can do it quite easily by having a parser rule
> that aggregates can't appear in expression for the aggregate, which is a
> simple static check.
+1, but we do also need to address the issue Steve mentions, i.e.,
even the use of ?M instead of ?M+1 is problematic because expressions
are evaluated only after aggregation.
BIRTE
> Andy
>
> [1] http://s.apache.org/Yy6
>
--
Jun. Prof. Dr. Birte Glimm Tel.: +49 731 50 24125
Inst. of Artificial Intelligence Secr: +49 731 50 24258
University of Ulm Fax: +49 731 50 24188
D-89069 Ulm birte.glimm@uni-ulm.de
Germany
Received on Tuesday, 5 June 2012 10:13:46 UTC