sparql - Jena ARQ returns non-empty result for AVG() if there is no matching triple pattern -
i have query uses avg() operator:
select (avg(?z) ?avg) { ?x <http://ex.com/value> ?z }
let's imagine triple store doesn't have triples matching given triple pattern, expect (at least do) query should return empty result. , virtuoso returns empty result, can use dbpedia's sparql endpoint check (execute).
but fuseki , jena arq return non-empty result: 0
. can check on sparql.org (execute).
is possible configure jena arq return empty result given query? if so, how?
we expect (at least do) query should return empty result. , virtuoso returns empty result, can use dbpedia's sparql endpoint check.
but fuseki , jena arq return non-empty result: 0. can check on sparql.org.
i don't know whether can change behavior of avg, shouldn't, because jena doing right thing here, , virtuoso (the endpoint dbpedia) doing wrong. sparql 1.1 standard defines avg return when group empty:
18.5.1.4 avg
the avg set function calculates average value expression on group. defined in terms of sum , count.
definition: avg numeric avg(multiset m)
avg(m) = "0"^^xsd:integer, where count(m) = 0
avg(m) = sum(m) / count(m), count(m) > 0
that said, can use if check whether count zero, , return undefined value in case, , average otherwise. should work endpoint, too, not arq. used values introduce variable undefined value here, use expression produce error, e.g., 1/0. (of course, danger there implementations can extend behavior of operators, it's pretty hard guarantee particular expression error.)
select (if(count(?x) = 0,?undef,avg(?x)) ?average) { values ?x { 2 3 4 } values ?undef { undef } } group ?undef
----------- | average | =========== | 3.0 | -----------
and in case there no values ?x:
select (if(count(?x) = 0,?undef,avg(?x)) ?average) { values ?x {} values ?undef { undef } } group ?undef
----------- | average | =========== | | -----------
Comments
Post a Comment