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 
http://www.w3.org/2009/sparql/meeting/2010-03-26#SUM
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 http://www.w3.org/2009/sparql/meeting/2010-03-26#resolution_2
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: <http://example.org/>
> PREFIX rdf:     <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
> 
> SELECT ?T (Sum(?Pr) AS ?P)
> WHERE { ?Item rdf:type ?T; ex:price ?Pr }
> GROUP BY ?T
> 
> 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.

Axel

> 

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