"Unbound" in SPARQL (was Re: [TF-LIB] COALESCE is an unhelpful choice of name)

On 15 Nov 2009, at 16:01, Andy Seaborne wrote:
> On 15/11/2009 09:51, Steve Harris wrote:
>>
>>> > What happens if all the terms are unbound? An error?
>>>
>>> I think it has to be an error and XXX(expression) without a default
>>> value is a no-op.
>>
>> It's NULL in SQL. That makes most sense I think.
>
> So we agree?  There is no NULL in SPARQL.  unbound, as a value is an  
> error.

Ah, yeah. My stores have an explicit "unbound value", so it could be  
returned from a function, but that's a hack and makes no real sense in  
SPARQL 1.0.

It's a little unfortunate because we might have to return an error  
from a MIN (etc.) over an empty multiset, which isn't ideal for some  
usecases:

data:

:alice a :Salesperson ;
        :sales [
   :date "2009-11-14" ;
   :volume 12 ;
] , [
   :date "2009-11-14" ;
   :volume 9 ;
] .
:bob a :Salesperson ;
      :sales [
   :date "2009-11-14" ;
   :volume 8 ;
] .
:carol a :Salesperson .

query:

SELECT ?x (MAX(?sales) AS ?bestDay)
WHERE {
   ?x a :Salesperson .
   OPTIONAL {
     ?x :sales [
       :volume ?sales ;
     ]
   }
}
GROUP BY ?x

results:

?x = :alice, ?bestDay = 12
?x = :bob, ?bestDay = 8
[no row for :carol because we can't return "unbound"/null from MAX(? 
sales)]

I'd be interested to know what current implementations do in this  
situation?

We could say that empty multisets aren't used by aggregate functions,  
and the result is unbound, but that messes up COUNT and SUM, and some  
user-defined aggregates. Also has strange implications for expressions  
using aggregates.

- Steve

-- 
Steve Harris, CTO, Garlik Limited
2 Sheen Road, Richmond, TW9 1AE, UK
+44(0)20 8973 2465  http://www.garlik.com/
Registered in England and Wales 535 7233 VAT # 849 0517 11
Registered office: Thames House, Portsmouth Road, Esher, Surrey, KT10  
9AD

Received on Sunday, 15 November 2009 18:12:54 UTC