- From: Seaborne, Andy <andy.seaborne@hp.com>
- Date: Tue, 25 Aug 2009 19:54:22 +0000
- To: "public-sparql-dev@w3.org" <public-sparql-dev@w3.org>
> -----Original Message----- > From: public-sparql-dev-request@w3.org [mailto:public-sparql-dev- > request@w3.org] On Behalf Of Lee Feigenbaum > Sent: 25 August 2009 14:02 > To: Toby Inkster > Cc: public-sparql-dev@w3.org > Subject: Re: SPARQL Query Problem - perhaps solvable in 1.1? > > Toby Inkster wrote: > > A very simple solution, which would solve the ordering problem (and also > > greatly simplify the filter) would be for SPARQL to borrow the COALESCE > > function from SQL. For those not familiar with COALESCE, it takes a > > variable number of arguments, and returns the first of those arguments > > which is not null. (In the SPARQL case, it would be the first which is > > bound.) > > > > That would make my filter as simple as: > > > > FILTER (inRange(COALESCE(?date1,?date2,?date3,?date4))) > > > > And my sorting as easy as: > > > > ORDER BY (COALESCE(?date1,?date2,?date3,?date4)) > > > > I should also mention that implementations are, of course, free to > extend SPARQL with arbitrary functions, which could include COALESCE. > > Lee > An operation like COALESCE isn't a true function because it does not operate on the values of it's arguments. Like BOUND(?x), it sees arguments as give before evaluation (or can catch the eval error if you prefer), and COALESCE should choose the first legal value. ?x unbound ?y = 9 e.g. COALESCE(?x, ?y, 1/0) is presumably 9 and not an error due to the 1/0 or unbound ?x SPARQL already has some special forms that behave not as functions in the presence of errors, including unbound variables. bound(?var), || and && as they behave differently from pure functions. Personally, I'd like to see the forms COALESCE and/or some kind of IF added to SPARQL if time permits because they occur sometimes in natural usage and even when not strictly necessary as language features the alternative can be verbosely painful. But time is the critical factor - we don't have a long time in this round and resources are limited. [When translating multiple OPTIONALs when the OPTIONALs share a variable like ?date not in the initial pattern, then Jena/SDB generates SQL using SQL COALESCE.] Andy
Received on Tuesday, 25 August 2009 19:55:22 UTC