You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jena.apache.org by Rob Vesse <rv...@yarcdata.com> on 2013/03/22 00:48:24 UTC

Clarification on SPARQL behaviour re Aggregates and Project Expressions

A question came in from one of our developers about what he saw as a
strangeness in SPARQL behavior in ARQ.  It relates to behavior when both
aggregates and project expressions are used in the same SELECT clause e.g.

SELECT (COUNT(?s) AS ?subjects) (?subjects + 1 AS ?x)
WHERE
{
  ?s ?p ?o
}

In the current ARQ code this produces the following error:

Non-group key variable in SELECT: ?subjects in expression ( ?subjects + 1 )

Yet in past versions this was permitted by ARQ because this developer can
run this kind of query in his copy of TBC (which I am fully aware is
likely using several versions of ARQ behind the latest)

Is this the correct interpretation of the specification or not?

As I understood it aggregates apply during the GROUP BY phase and then
project expressions happen afterwards so in principal at least this query
can be represented in legal algebra.

However I think this is covered by 18.2.4 in the specification:

The syntax error arises for use of a variable as the named target of AS
(e.g. ... AS ?x) when the variable is used inside the WHERE clause of the
SELECT or if already used as the traget of AS in this SELECT expression.

So I assume ARQ is correct in its behavior and that it's just that the
fact that it works in TBC reflects a bug/earlier version of the spec in an
earlier release.

Cheers,

Rob


Re: Clarification on SPARQL behaviour re Aggregates and Project Expressions

Posted by Rob Vesse <rv...@yarcdata.com>.
Thanks for the clarification and the fix,

Rob



On 3/22/13 4:34 AM, "Andy Seaborne" <an...@apache.org> wrote:

>On 21/03/13 23:48, Rob Vesse wrote:
>> A question came in from one of our developers
>
>Do point him at the users@ list - the more, the merrier!
>
>> about what he saw as a
>> strangeness in SPARQL behavior in ARQ.  It relates to behavior when both
>> aggregates and project expressions are used in the same SELECT clause
>>e.g.
>>
>> SELECT (COUNT(?s) AS ?subjects) (?subjects + 1 AS ?x)
>> WHERE
>> {
>>    ?s ?p ?o
>> }
>>
>> In the current ARQ code this produces the following error:
>>
>> Non-group key variable in SELECT: ?subjects in expression ( ?subjects +
>>1 )
>>
>> Yet in past versions this was permitted by ARQ because this developer
>>can
>> run this kind of query in his copy of TBC (which I am fully aware is
>> likely using several versions of ARQ behind the latest)
>>
>> Is this the correct interpretation of the specification or not?
>>
>> As I understood it aggregates apply during the GROUP BY phase and then
>> project expressions happen afterwards so in principal at least this
>>query
>> can be represented in legal algebra.
>>
>> However I think this is covered by 18.2.4 in the specification:
>>
>> The syntax error arises for use of a variable as the named target of AS
>> (e.g. ... AS ?x) when the variable is used inside the WHERE clause of
>>the
>> SELECT or if already used as the traget of AS in this SELECT expression.
>>
>> So I assume ARQ is correct in its behavior and that it's just that the
>> fact that it works in TBC reflects a bug/earlier version of the spec in
>>an
>> earlier release.
>
>It's a bug in the newer ARQ.  It should work.  I suspect that the old
>version worked because checks weren't being done.  If it's an old copy
>of ARQ, it used to do less/no static checking. It became a required
>static check in SPARQL.
>
>JENA-419 ... fixed.
>
>	Andy
>


Re: Clarification on SPARQL behaviour re Aggregates and Project Expressions

Posted by Andy Seaborne <an...@apache.org>.
On 21/03/13 23:48, Rob Vesse wrote:
> A question came in from one of our developers

Do point him at the users@ list - the more, the merrier!

> about what he saw as a
> strangeness in SPARQL behavior in ARQ.  It relates to behavior when both
> aggregates and project expressions are used in the same SELECT clause e.g.
>
> SELECT (COUNT(?s) AS ?subjects) (?subjects + 1 AS ?x)
> WHERE
> {
>    ?s ?p ?o
> }
>
> In the current ARQ code this produces the following error:
>
> Non-group key variable in SELECT: ?subjects in expression ( ?subjects + 1 )
>
> Yet in past versions this was permitted by ARQ because this developer can
> run this kind of query in his copy of TBC (which I am fully aware is
> likely using several versions of ARQ behind the latest)
>
> Is this the correct interpretation of the specification or not?
>
> As I understood it aggregates apply during the GROUP BY phase and then
> project expressions happen afterwards so in principal at least this query
> can be represented in legal algebra.
>
> However I think this is covered by 18.2.4 in the specification:
>
> The syntax error arises for use of a variable as the named target of AS
> (e.g. ... AS ?x) when the variable is used inside the WHERE clause of the
> SELECT or if already used as the traget of AS in this SELECT expression.
>
> So I assume ARQ is correct in its behavior and that it's just that the
> fact that it works in TBC reflects a bug/earlier version of the spec in an
> earlier release.

It's a bug in the newer ARQ.  It should work.  I suspect that the old 
version worked because checks weren't being done.  If it's an old copy 
of ARQ, it used to do less/no static checking. It became a required 
static check in SPARQL.

JENA-419 ... fixed.

	Andy