Re: ungrouped variables used in projections - Further implications?

On 25/08/10 13:33, Axel Polleres wrote:
> In total, addressing 1) and 2) my current understanding is that we should change:
>
> "In aggregate queries and sub-queries variables that appear in the query
> pattern, but are not grouped by cannot be projected nor used in project
> expressions. In order to project arbitrary expressions the SAMPLE
> aggregate may be used."
>
> -->
>
> "In aggregate queries and sub-queries variables *or expressions* that appear in the query
> pattern, but are not grouped by cannot be projected, nor be used in project
> expressions *(except within aggregations)*, *nor be used in HAVING clauses*.
> In order to project arbitrary expressions the SAMPLE aggregate may be used."
>
> The formulation gets a bit heavier, but at least it seems clearer.

Refining this:

We need to forbid the *use* of ungrouped variables in the *specific 
SELECT* expression where the GROUP occurs.  Otherwise:

1/ Use elsewhere in the query should be unaffected otherwise

SELECT *
{
    { SELECT ?x { ?x ?p ?o } GROUP BY ?x }
    ?o <p> 123 .
}

is illegal (it's a completely different ?o in the second use) which 
makes building queries by composition a nuisance.

2/ It's the undefined value of a non-key variable that's the issue 
because there isn't a clear value to give it.

Introduction of an alias name is OK: this is being clear about the "use 
in expressions"(1/(1-?o) AS ?o1)

  SELECT (count(*) AS ?p) { ?s ?p ?o } GROUP BY ?s

in extremis:

  SELECT (SAMPLE(?p) AS ?p) { ?s ?p ?o } GROUP BY ?s


Personally, I'd be happy with forbidding the use variables of grouping 
expressions:

  SELECT (1/(1-?o) AS ?o1) { ?s ?p ?o } GROUP BY (1/(1-?o)) # Forbiddable
  SELECT ?o WHERE { ?s ?p ?o } GROUP BY (1/(1-?o)) # Forbiddable

[[
In aggregate queries and sub-queries, variables that appear in the query 
pattern, but are not used to group the pattern, cannot be projected nor 
used in expressions in SELECT clause nor used in the expression of a 
HAVING clause of this query or sub-query unless they are part of an 
aggregate.

They may be used as alias names.

In order to project arbitrary expressions the SAMPLE aggregate may be used.
]]

By saying "expressions" the use as alias names comes for free but it's 
clearer to say so.

	Andy

Received on Wednesday, 25 August 2010 15:38:33 UTC