Ah ok I see what the problem is
If your query contains a GROUP BY then you can only project grouped by
variables (or apply an aggregate over a non-grouped variable)
Since you are grouping on the result of an expression rather than a
variable you can't also do that in the SELECT clause directly because
the ?date variable is not in scope there because it isn't used as a
group key.
To get the behaviour you want you can use the SAMPLE aggregate which
picks one value for that variable from all the solutions in the group e.g.
SELECT (<bif:year>(SAMPLE(?date)) AS ?year) (<bif:month>(SAMPLE(?date)) AS
?month)
(count(distinct ?document) AS ?documents)
{
?document a :Document;
:documentDateOfCreation ?date;
:documentType ?docType.
FILTER ( ?docType = "exam results"^^xsd:string )
}
group by (<bif:year>(?date)) (<bif:month>(?date))
I tested this and the above query will parse ok with ARQ (at least with
2.9.0)
Rob
On 3/22/12 12:13 PM, Diogo FC Patrao wrote:
Hello Robert,
Thanks for the tip, but it's still complaining
Non-group key variable in SELECT: ?date in expression<bif:year>(?date)
I even tried with an extra couple of parenthesis, but no luck.
--
diogo patrĂ£o
On Thu, Mar 22, 2012 at 3:57 PM, Robert Vesse<[email protected]> wrote:
Generally speaking to be valid SPARQL syntax any expressions either in
the project clause or in GROUP BY/ORDER BY/FILTER etc should be properly
bracketed and aliased (for project expressions) e.g.
SELECT (<bif:year>(?date) AS ?year) (<bif:month>(?date) AS ?month)
(count(distinct ?document) AS ?documents)
{
?document a :Document;
:documentDateOfCreation ?date;
:documentType ?docType.
FILTER ( ?docType = "exam results"^^xsd:string )
}
group by (<bif:year>(?date)) (<bif:month>(?date))
Try the above and see if that works
Rob Vesse -- YarcData.com -- A Division of Cray Inc
Software Engineer, Bay Area
m: 925.960.3941 | o: 925.264.4729 | @: [email protected] | Skype:
rvesse
6210 Stoneridge Mall Rd | Suite 120 | Pleasanton CA, 94588
On Mar 22, 2012, at 11:43 AM, Diogo FC Patrao wrote:
SELECT<bif:year>(?date)<bif:month>(?date) count(distinct ?document)
{
?document a :Document;
:documentDateOfCreation ?date;
:documentType ?docType.
FILTER ( ?docType = "exam results"^^xsd:string )
}
group by<bif:year>(?date)<bif:month>(?date)