Re: aggregate functions and errors in SPARQL

Hi Jeremy,

Your previous message, 
http://lists.w3.org/Archives/Public/public-sparql-dev/2013OctDec/0001 , 
is already recorded in the errata:

http://www.w3.org/2013/sparql-errata#errata-query-6

Theer is something in your example, not aggregate related, that might be 
getting in the way as well.


On 17/10/13 16:58, Jeremy J Carroll wrote:
> 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

Not an aggregate issue per se.

Aggregate do introduce the concept of an error marker - it's a "virtual 
term" and it vanishes before results get out.

> - but an error value propagates through multi set functions like ToList and Flatten

The latter is unclear as described in
http://lists.w3.org/Archives/Public/public-sparql-dev/2013OctDec/0005.html

For MIN, the effect is the same, but not for MAX.

> 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

Clarification - "then there is no solution"

{
   { BIND('2' as ?x)} UNION {}
}

has two solutions, one from each branch of the UNION.

{} has a solution of one row, no columns (the join identity).


Group(exprlist, Ω) = { ListEval(exprlist, μ) → { μ' | μ' in Ω, 
ListEval(exprlist, μ) = ListEval(exprlist, μ') } | μ in Ω }


ListEval(?x, {}) is error and is retained:
[[
ListEval retains errors resulting from the evaluation of the list elements.
]]

so ListEval gives two items: {?x='2'}, {}



----------------------------------------------

In
http://lists.w3.org/Archives/Public/public-sparql-dev/2013OctDec/0005.html

I described two possible reading I know of: in the MIX case they both 
result in error, and hence ?y is unbound.

One way is that ToList does nor handle errors and so is an error to call 
it with an error on the multiset of solutions.  The other way is to pass 
it theough like aterm, in which case MIN is seeing errors.

MAX is affected by the two different readings; by the first reading it 
is error, by the second, 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.

Did you mean:

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

in your example.

Otherwise ?z is unbound in the BIND at the point of execution.

> 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 }
> }

That's more like the reorder pattern.

 Andy

> 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 Saturday, 19 October 2013 17:13:14 UTC