nkaralis opened a new issue, #3879: URL: https://github.com/apache/jena/issues/3879
### Version 6.0.0 ### Question Hello. I would like to ask some questions about the handling of unaggregated variables. <br> For the examples provided below, I have used Jena v6.0.0 (Fuseki and ARQ) and the following graph. ``` <http://www.example.org/s2> <http://www.example.org/p1> <http://www.example.org/o3>. <http://www.example.org/s2> <http://www.example.org/p2> "test literal". <http://www.example.org/s2> <http://www.example.org/p2> <http://www.example.org/o2>. <http://www.example.org/s1> <http://www.example.org/p1> <http://www.example.org/o1>. <http://www.example.org/s3> <http://www.example.org/p1> <http://www.example.org/o5>. <http://www.example.org/s3> <http://www.example.org/p2> <http://www.example.org/o6>. ``` In the paragraph [11.4](https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#aggregateRestrictions) of the specification, it is stated that "In a query level which uses aggregates, only expressions consisting of aggregates and constants may be projected, with one exception. When GROUP BY is given with one or more simple expressions consisting of just a variable, those variables may be projected from the level." Based on the above statement, the queries <br> Q1. `SELECT ?s (COUNT(?o) AS ?c) WHERE { ?s ?p ?o }` and <br> Q2. `SELECT (?s AS ?s2) (COUNT(?o) AS ?c) WHERE { ?s ?p ?o }` <br> raise the errors "Non-group key variable in SELECT: ?s" and "Non-group key variable in SELECT: ?s in expression ?s", respectively. <br> However, in the paragraph [18.2.4.1](https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#sparqlGroupAggregate), the provided algorithm does not follow the statement of paragraph 11.4, as it replaces an unaggregated `V` variable with `SAMPLE(V)` **First question**: Which statement should be followed? **Second question**: Based on the algorithm of paragraph 18.2.4.1, should Q2 be rejected? **Third question**: Why does the algorithm treat `(?X AS VAR)` and `?X` differently? **Fourth question**: When it comes to the cases of `ORDER BY(X)` and `HAVING(X)`, shouldn't the queries Q3 and Q4 (provided below) return the same results? <br> Q3. `SELECT ?s (COUNT(DISTINCT ?o) AS ?c) WHERE { ?s ?p ?o } GROUP BY ?s HAVING(ISIRI(?p))` (empty result set) <br> Q4. `SELECT ?s (COUNT(DISTINCT ?o) AS ?c) WHERE { ?s ?p ?o } GROUP BY ?s HAVING(ISIRI(SAMPLE(?p)))` (explicit `SAMPLE`, three solutions) ---- I also have a few questions about the variables appearing in `GROUP BY`. In the table provided in paragraph [18.2.1](https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#variableScope) of the specification, it is stated that `V` is in-scope given an expression `GROUP BY (expr AS v)`. **Fifth Question**: Should the query Q5 (provided below) throw a syntax error? <br> Q5. `SELECT (COUNT(DISTINCT ?o) AS ?c) WHERE { ?s ?p ?o } GROUP BY (1 AS ?c) # empty result set` **Sixth Question**: Since the GROUP BY is processed before the SELECT clause, is ?c always assigned the UNDEF value in the Group in Q6 (provided below)?<br> Q6. `SELECT (COUNT(DISTINCT ?o) AS ?c) WHERE { ?s ?p ?o } GROUP BY ?c # one solution` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
