You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Tim Harsch <ha...@yahoo.com> on 2011/05/06 20:10:26 UTC

variables after projected variables

Hi,
I wrote a query like this and sent it through Fuseki 0.1.0.  It came back with 
results for "?n0 ?n1 ?nc" and dropped the other variables.

SELECT ?n0 ?n1 (COUNT(*) as ?nc) ?n2 ?n3 ?n4 ?n5 ?n6 
WHERE { 
...
} GROUP BY ?n0 ?n1

Its probably by design, but its confusing to me because in analogous SQL I 
believe the behavior would be to calculate the ?nc result but return all rows, 
its just that the aggregrate count would be the same for any row where ?n0 or 
?n1 has been previously returned.

Does the SPARQL spec define the behavior here, or is up to implementors?

Thanks,
Tim

Re: variables after projected variables

Posted by Andy Seaborne <an...@epimorphics.com>.

On 06/05/11 19:21, Damian Steer wrote:
>
>
> Sent from my iPhone
>
> On 6 May 2011, at 19:10, Tim Harsch<ha...@yahoo.com>  wrote:
>
>> Hi,
>> I wrote a query like this and sent it through Fuseki 0.1.0.  It came back with
>> results for "?n0 ?n1 ?nc" and dropped the other variables.
>>
>> SELECT ?n0 ?n1 (COUNT(*) as ?nc) ?n2 ?n3 ?n4 ?n5 ?n6
>> WHERE {
>> ...
>> } GROUP BY ?n0 ?n1
>>
>> Its probably by design, but its confusing to me because in analogous SQL I
>> believe the behavior would be to calculate the ?nc result but return all rows,
>> its just that the aggregrate count would be the same for any row where ?n0 or
>> ?n1 has been previously returned.
>>
>> Does the SPARQL spec define the behavior here, or is up to implementors?
>>
>> Thanks,
>> Tim
>
> Sparql spec defines it that way.
>
> Damian

Yep.

After the GROUP BY only  ?n0 ?n1 and ?nc are in-scope.
?n2 ?n3 ?n4 ?n5 ?n6 are fresh variables (different from anything in {})

What your SQL experience tells you depends on the SQL system.  It ranges 
from "works" (MySQL - and deterministically) to illegal (Oracle).

(SAMPLE(?n2) AS ?n2a) etc
would get one value of the group out per (?n0 ?n1) group.  SAMPLE is an 
aggregate like COUNT that chooses at random within the group.  In ARQ, 
that means the first it comes across and SAMPLE(DISTINCT ?n0) the last 
(for no particularly logical reason).

By spec, ?n2 etc are out of scope in SQL as well.  MySQL is "different" 
(groups are effectively sorted and not scoped).

	Andy

Re: variables after projected variables

Posted by Damian Steer <d....@bristol.ac.uk>.

Sent from my iPhone

On 6 May 2011, at 19:10, Tim Harsch <ha...@yahoo.com> wrote:

> Hi,
> I wrote a query like this and sent it through Fuseki 0.1.0.  It came back with 
> results for "?n0 ?n1 ?nc" and dropped the other variables.
> 
> SELECT ?n0 ?n1 (COUNT(*) as ?nc) ?n2 ?n3 ?n4 ?n5 ?n6 
> WHERE { 
> ...
> } GROUP BY ?n0 ?n1
> 
> Its probably by design, but its confusing to me because in analogous SQL I 
> believe the behavior would be to calculate the ?nc result but return all rows, 
> its just that the aggregrate count would be the same for any row where ?n0 or 
> ?n1 has been previously returned.
> 
> Does the SPARQL spec define the behavior here, or is up to implementors?
> 
> Thanks,
> Tim

Sparql spec defines it that way.

Damian