- From: Andy Seaborne <andy@apache.org>
- Date: Fri, 29 Jan 2016 21:46:49 +0000
- To: public-sparql-dev@w3.org
On 29/01/16 18:47, Jörn Hees wrote: > Hi, > > over at RDFLib we got a bug report [1] that our SPARQL engine produces weird results for an aggregate query over result sets with undefined variables like this: > What was RDFLib producing? > SELECT ?x (SAMPLE(?y) as ?ys) (SAMPLE(?z) as ?zs) WHERE { > VALUES (?x ?y ?z) { > (2 6 UNDEF) > (2 UNDEF 10) > > (3 UNDEF 15) > (3 9 UNDEF) > > (5 UNDEF 25) > } > } > GROUP BY ?x > > Intuitively my understanding is that this should produce a result set like this: > > VALUES (?x ?ys ?zs) { > (2 6 10) > (3 9 15) > (5 UNDEF 25) > } > > I fixed this in [2], but there seems to be confusion what the correct solution is (not only between the RDFLib devs): > - Virtuoso returns the above [1] > - Jena returns { (2 UNDEF UNDEF) (3 UNDEF UNDEF) (5 UNDEF 25) } [2] > > So what's the correct answer? Hi, Both are right, though the Virtuoso one is pragmatically more useful in this specific case. There is no one "right" in general when SAMPLE is involved. Aggregation calculation retains errors and ?z of UNDEF is an error. SAMPLE picks any value from the choices, and at that point, errors are "values". See ListEval. """ Note that, although the result of a ListEval can be an error, and errors may be used to group, solutions containing error values are removed at projection time. """ then M(Ω) = { ListEval(exprlist, μ) | μ in Ω } Sample(M) = v, where v in Flatten(M) It's what makes SUM(?x) be undef when some ?x in group is not summable or defined. COUNT is special - it removed errors before counting. Andy > > Cheers, > Jörn > > > PS: The relevant sections seem to be [3], [4] and [5], but to me don't seem explicit enough to answer the above. > PPS: I also couldn't find any tests in [6] for the above. > > > [1]: https://github.com/RDFLib/rdflib/issues/563 > [2]: https://github.com/RDFLib/rdflib/pull/567 > [3]: https://www.w3.org/TR/sparql11-query/#defn_aggSample > [4]: https://www.w3.org/TR/sparql11-query/#aggregateExample2 > [5]: https://www.w3.org/TR/sparql11-query/#aggregateAlgebra > [6]: https://www.w3.org/2009/sparql/docs/tests/ > >
Received on Friday, 29 January 2016 21:47:19 UTC