aggregate functions and errors in SPARQL

This is a comment on
http://www.w3.org/TR/2013/REC-sparql11-query-20130321/

I have found it overly hard work to understand how aggregate functions behave in the face of errors.
I think there are many corner case and that the specification would benefit by explicitly calling some of them out.

Specifically a confusing issue, that is not clearly specified, is that:
- an unbound value gets excluded from a multi set
- but an error value propagates through multi set functions like ToList and Flatten


Here are some examples:


Select (Min(?x) as ?y)
{
   { BIND('2' as ?x)}
   UNION
   {}
}

gives y = 2: rationale when ?x is unbound then there is no solution and no value is passed into the aggregation and MIN(2) = 2
[This is despite the ORDER BY ordering putting unbound before 2]


Select (Min(?x) as ?y)
{
   BIND (?z+0 as ?x)
   VALUES ?z { "abc" 3 }
}

This comes to ?y = 3 by similar reasoning ("abc"+0 gives an error which leaves ?x unbound.


However, this result is changed by moving the computation (?z+0) into the select expression

Select (Min(?z+0) as ?y)
{
   VALUES ?z { "abc" 3 }
}

This comes to ?y = unbound, because the error happens during the aggregation rather than before it.

If the aggregate function is SAMPLE in these two cases then the result is the same as with MIN. Notice I think it may  not be conformant for

Select (SAMPLE(?z+0) as ?y)
{
   VALUES ?z { "abc" 3 }
}

to return ?y = 3 … this matter perhaps should be revised, since SAMPLE is meant to be cheap, but as specified all matches may need to be verified for errors.

A case I have been dealing with is CONCAT( '"', GROUP_CONCAT( REPLACE($x,'[\\\\"]','\\\\$0') ; SEPARATOR='" "' ), '"') AS $y )
(which creates a string of quoted strings with \ escaping of quotes and \)
This behaves differently if the REPLACE() operation is pushed down as a BIND in the WHERE clause: actually both behaviors are useful (as is, errors cause no result; pushing the BIND down ignores errors)

===

A suggested textual change is to add informative text with some examples like this, and to review the normative text to verify that it is clear and consistent on this matter.


Jeremy J Carroll
Principal Architect
Syapse, Inc.

Received on Thursday, 17 October 2013 15:59:21 UTC