Re: Semantics of SPARQL 1.1 aggregates

On 23/09/13 14:22, Esko Nuutila wrote:
> Hi,
>
> I am trying to understand the semantics of aggregates. However, the
> explanation in 'SPARQL 1.1 Query Language. W3C Recommendation 21 March
> 2013' (especially in Section 18.2.4.1 Grouping and Aggregation), is
> confusing. Could someone explain either in plain English or in a more
> formal way than in SPARQL specification, how aggregates are supposed to
> work?

18.2.4.1 is the transformation from syntax to algebra.

The evaluation is in "18.5.1 Aggregate Algebra"

>
> Some specific questions:
>
> 1) In Step: Aggregates, which variables are referred in
>
> 'For each variable V appearing outside of an aggregate'

In the SELECT clause, where aggregation occurs, expression can be made 
from aggregates and from variables used in the GROUP BY (i.e. they are 
fixed varues for each group).


SELECT ?x {
...
}
GROUP BY ?x

These are treated as pseudo-aggregates by applying the SAMPLE aggregate 
to them.  That is the identity aggregate operation.

After translation to the algebra, all expressions in a SELECT with GROUP 
are aggregates.

>
> 2) Are arbitrary expressions allowed as actual parameters in aggregate
> calls? Is AVG(?x/10) legal? What about nested aggregates, e.g., in the
> following, somewhat strange query:
>
> PREFIX :<http://example.org/#>
>
> SELECT ?w (MAX(?w/(AVG(?h/100)*AVG(?h/100))) as ?m) {
>         ?p :weigth ?w ; :height ?h .
> } GROUP BY ?w

Syntactically, yes, because aggregrates can appear anywhere that a 
function or expression can (it stops an explosion of grammar rules that 
woudl results if ther were two expression grammars for aggregate-allowed 
and aggregate-not-allowed expressions).  Also, aggregates can be URIs: 
my:aggregate(?x) which are syntactcially identical to a custom function 
call.

But it's not legal as an evaluation. It should say that aggregates 
aren't allowed inside aggregate experssions.

MAX(MAX(?x)) is meaningless because each evaluation of the expression of 
the outer MAX, once per element in the group then finding the maximum 
(see 18.5.1, "Group" operator), depends on the value of the inner MAX 
for the whole group.

This should be more clearly stated in the spec.

	Andy

>
>
> /Esko
> --
> Esko Nuutila
> Aalto University School of Science and Technology
> Department of Computer Science and Engineering
> P.O.Box 15400 (T-building, Konemiehentie 2, room B218)
> FI-00076 AALTO, FINLAND
> tel. +358 50 5750278 <tel:%2B358%2050%205750278> mailto:
> esko.nuutila@aalto.fi <mailto:esko.nuutila@aalto.fi>
>

Received on Friday, 4 October 2013 08:18:38 UTC