Re: isNumeric

On 20 Sep 2010, at 10:26, Andy Seaborne wrote:
> On 19/09/10 21:13, Axel Polleres wrote:
> > Hi all,
> >
> > Don't we need something like a function isNumeric to test for a numeric argument?
> > Seems to be handy, useful for instance for numeric aggregates, or no?
> >
> > It seems COALESCE together with a cast would work as well, but
> > something like
> >    SUM(IF(isNumeric(?X), ?X, 0))
> > looks better - at least to me - than:
> >      SUM(COALESCE(xs:double(?X) , 0))
> >
> > Opinions?
> >
> > Axel
> I believe we eventually agreed that sum() would skip any evaluation
> errors of the summation as being more consistent in style for SPARQL.

Hmmm, I read up in the F2F minutes
and couldn't find it there... according to the current definition SUM just delegates to op:numeric-add
which would error on non-numeric values, wouldn't it?

Note that Resolution
doesn't cover that, since the argument passed is not an error, but just 
the wrong datatype.

We might have that resolved otherwise somewhere, but frankly I can't find that.

> It
> makes it more consistent since you can always do:
> sum(?X+0)

> to make the check happen before the aggregate is called.

What does that change? if X is a string, then ?X + 0 gives an error, doesn't it?
(at least it did when I tried it with XQuery)

> We do not
> define any situation that causes a runtime evaluation error in SPARQL
> (systems may issue warnings or reject the query, of course).

I thought we throw away the whole row, i.e. leave ?P undbound for
(Sum(?Pr) AS ?P) if the flattened op:numeric-add returns an error, at least 
that's how I'd read the current text for  Definition: Extend along with the default behavior of 
op:numeric-add . At least, we'd need to throw away non-numerics along with Flatten, or something like that, yes?

> PREFIX ex: <>
> PREFIX rdf:     <>
> SELECT ?T (Sum(?Pr) AS ?P)
> WHERE { ?Item rdf:type ?T; ex:price ?Pr }
> We may want isNumeric, but it's not required here.
>         Andy
> PS The data and queries have several syntax errors.

thanks, will fix before proposing to test suite.



Received on Monday, 20 September 2010 08:56:33 UTC