Warm tip: This article is reproduced from serverfault.com, please click

Aggregate Function AVG in GraphDB

发布于 2021-01-12 09:49:47

For my project in GraphDB 9.4.1 I created a repository with owl rl (optimized).

In my data I need to query the average value of a data property. When I follow the steps according to SPARQL instruction, the result is empty. I used the following Query:

PREFIX : <http://www.BLB.de/Ontologie#>
select ?s (AVG(?TP) as ?AP) where { 
?s a :MachinestatusID .
?s :hastotalpower_Kalender ?TP.
?s <http://www.BLB.de/Ontologie#Is_switched_on_Kalender> ?K
} Group by ?s ?K 

Result:

s                                                     AP
http://www.BLB.de/Daten/Anlagenstatus/id/1  
http://www.BLB.de/Daten/Anlagenstatus/id/2  
http://www.BLB.de/Daten/Anlagenstatus/id/3  

To validate the data, I already selected the data without the aggregate function. Al ?TP are values between 0 and 5000. There is no data format specified. ?K is 1 or 0. Due to GraphDB documentation AVG function is support.

s                                           TP      K
http://www.BLB.de/Daten/Anlagenstatus/id/1  4186    1
http://www.BLB.de/Daten/Anlagenstatus/id/2  4183    1
http://www.BLB.de/Daten/Anlagenstatus/id/3  4177    1
http://www.BLB.de/Daten/Anlagenstatus/id/4  4171    1

Is there any solution to get the real average as output?

Questioner
PhilippGr
Viewed
1
PhilippGr 2021-01-12 23:09:10

The data format of ?TP needed to be casted explizitly. Modifing the average function to the following solved the problem:

(AVG(xsd:integer(?TP)) as ?AP)