Fwd: Re: NVL, LET, COALESCE, CASE

[forwarding with permissoin from Jacek]

-------- Original Message --------
Subject: Re: NVL, LET, COALESCE, CASE
Date: Wed, 17 Nov 2010 19:13:44 +0100
From: Jacek Gajek <jacek.s.gajek@gmail.com>
To: Lee Feigenbaum <lee@thefigtrees.net>

Hi Lee,

Thanks for a quick reply,

Sorry for the confusion, I was looking at the old version of SPARQL 1.1.
Indeed, IF, BIND and COALESCE address my comment.

However, I still cannot find a BIND keyword specs. The article
http://www.w3.org/TR/sparql11-query/ is a source for me.
NVL became optional since it can be expressed with COALESCE.

A CASE statement request remains active, because I believe that a statement

BIND(IF(e1, e2, IF(e4, e5, IF(e6, e7, IF(e8, e9, IF(e10, e11, e12))))) 
AS ?var).

qualifies as a coding horror and therefore should not be found in a
production code.
By a CASE statement I understand an equivalent for a CASE statement in SQL.

Greetings,

Jacek*

* - not "Jackek". Jacek is a polish equivalent for "Jack" and is read
like "yasek" :-)

2010/11/17 Lee Feigenbaum <lee@thefigtrees.net>:
> Hi Jackek,
>
> SPARQL 1.1 includes a COALESCE function:
>
>  COALESCE(e1, e2, e3, e4, ...) returns the value of the first expression
> which is bound and does not evaluate to an error.
>
> It also includes an IF function:
>
>  IF(e1, e2, e3) returns e2 if the effective boolean value of e1 is true, and
> returns e3 if the EBV of e1 is false.
>
> It also includes a BIND keyword:
>
>  BIND(expr AS ?var)
>
> adds a binding of ?var to the value(s) of evaluating expr for each solution
> in the current solution set.
>
> The Working Group tracks all feedback, so please let us know if this
> addresses your comment.
>
> thanks,
> Lee
>
> On 11/16/2010 5:32 PM, Jacek Gajek wrote:
>>
>> Hi,
>>
>> In my opinion, an equivalent for the NVL function is a must-have.
>>
>> NVL(?x, "abc")
>>   if bound(?x) then ?x
>>   else "abc";
>>
>> NVL(?x, ?y)
>>   if bound(?x) then ?x
>>   else ?y;
>>
>> Also, a LET statement would be useful when a projection expression is too
>> long.
>> By the way, using projections in a WHERE clause would become possible.
>> Since order of executing statements in a WHERE clause is not determined,
>> a precedence of LET statements will have to specified.
>>
>> 1. LET statements can be executed in any time. Order of execution is
>> not determined (maybe even parallelly)
>> 2. LET statements must be independent to each other (one cannot use a
>> result from another)
>> 3. Projections may be used only as return values or with the construct
>> below:
>>
>> LET ?x=..., ?y=...
>>   {
>>     //use ?x, ?y (as literals exclusively of course)
>>   }
>>
>> alternatively:
>>
>> LET ?x =... .
>> (...)
>> LET ?y = ... .
>> (...)
>> USE ?x, ?y
>> {
>>   // evaluate and use ?x, ?y.
>> }
>>
>> That
>>
>> Example: change the projection given below to take into account, that
>> ?value1, ?value2 and ?backvalue1 are all optional:
>> SELECT xsd:replace(xsd:replace(xsd:replace(?source, "%value1%",
>> ?value1), "%value2%", ?value2), "%backvalue1%", ?backvalue1) AS
>> ?answer
>> WHERE
>> { ... }
>>
>> 1. It would be _possible_ with NVL.
>> 2. It would be _elegant_ with LET.
>>
>>
>> Going further, COALESCE and CASE might be included:
>>
>> COALESCE (expression [ ,...n ] )
>>
>> is
>>
>> CASE
>>    WHEN BOUND(expression1) THEN expression1
>>    WHEN BOUND(expression2) THEN expression2
>>
>>    ELSE expressionN
>> END
>>
>> They would be projections too, so they could be used in a LET
>> statement as well as the others.
>>
>> The above are just a bunch of ideas which came to my mind after using
>> SPARQL for some time.
>> I hope you find them useful.
>>
>> Greetings,
>>
>> Jacek Gajek
>>
>>
>>
>

Received on Wednesday, 17 November 2010 18:33:31 UTC