NVL, LET, COALESCE, CASE

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 09:52:48 UTC