- From: Axel Polleres <axel.polleres@deri.org>
- Date: Sun, 19 Sep 2010 21:24:16 +0100
- To: SPARQL Working Group <public-rdf-dawg@w3.org>
- Cc: Axel Polleres <axel.polleres@deri.org>
Some 3 draft test cases for this...
Data:
@prefix ex: <http://example.org/> .
ex:lemonade1 ex:price 3 ;
rdf:type ex:Softdrink.
ex:beer1 ex:price 3;
rdf:type ex:Beer.
ex:wine1 ex:price 3.50 ;
rdf:type ex:Wine.
ex:wine2 ex:price 4 .
rdf:type ex:Wine.
ex:wine3 ex:price "n/a";
rdf:type ex:Wine.
Queries:
sum-per-category-1:
PREFIX ex: <http://example.org/>
SELECT ?T (Sum(COLAESCE(xs:decimal(?Pr),0) AS ?P)
WHERE { ?Item rdf:type ?T; ex:price ?Pr }
GROUP BY ?T
sum-per-category-2:
PREFIX ex: <http://example.org/>
SELECT ?T (Sum(?Pr) AS ?P)
WHERE { ?Item rdf:type ?T; ex:price ?Pr
FILTER( isNumeric(?Pr) ) }
GROUP BY ?T
sum-per-category-3:
PREFIX ex: <http://example.org/>
SELECT ?T (Sum(IF(isNumeric(?Pr),?Pr,0) AS ?P)
WHERE { ?Item rdf:type ?T; ex:price ?Pr
) }
GROUP BY ?T
best,
Axel
On 19 Sep 2010, at 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
Received on Sunday, 19 September 2010 20:24:53 UTC