Hi, I have a SPARQL query (QUERY #1) which does this:
prefix e: <http://example.com/schema#> prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> select distinct (?r as ?e) (count(?s) as ?v) where { ?s rdf:type e:CS . ?s e:r ?r . ?r rdfs:label ?n } group by ?r order by ?r It gets parsed find by ARQ and this is the algebra structure: 1 (base <http://example/base/> 2 (prefix ((rdfs: <http://www.w3.org/2000/01/rdf-schema#>) 3 (e: <http://example.com/schema#>) 4 (rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>)) 5 (distinct 6 (project (?e ?v) 7 (order (?r) 8 (extend ((?e ?r) (?v ?.0)) 9 (group (?r) ((?.0 (count ?s))) 10 (bgp 11 (triple ?s rdf:type e:CS) 12 (triple ?s e:r ?r) 13 (triple ?r rdfs:label ?n) 14 )))))))) Now, I add (?n as ?l) to the select distinct (QUERY #2): prefix e: <http://example.com/schema#> prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> select distinct (?r as ?e) (?n as ?l) (count(?s) as ?v) where { ?s rdf:type e:CS . ?s e:r ?r . ?r rdfs:label ?n } group by ?r order by ?r And I have this syntax error: "Non-group key variable in SELECT: ?n in expression ?n" So, I tried this (QUERY #3): prefix e: <http://example.com/schema#> prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> select distinct (?r as ?e) (?n as ?l) (count(?s) as ?v) where { ?s rdf:type e:CS . ?s e:r ?r . ?r rdfs:label ?n } group by ?r ?n order by ?r And, indeed it does solve the problem. Algebra structure is: 1 (base <http://example/base/> 2 (prefix ((rdfs: <http://www.w3.org/2000/01/rdf-schema#>) 3 (e: <http://example.com/schema#>) 4 (rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>)) 5 (distinct 6 (project (?e ?l ?v) 7 (order (?r) 8 (extend ((?e ?r) (?l ?n) (?v ?.0)) 9 (group (?r ?n) ((?.0 (count ?s))) 10 (bgp 11 (triple ?s rdf:type e:CS) 12 (triple ?s e:r ?r) 13 (triple ?r rdfs:label ?n) 14 )))))))) Is QUERY #2 invalid or it is showing a problem with ARQ's query parser? I am happy with QUERY #3, however, I would like to learn and understand. I did try to go thorough the current SPARQL 1.1 Query Language spec, but I did not find a place which would help me to understand. Thank you, Paolo
