0

I am working with SPARQL federated queries. I do not wish to return anything other than aggregated data from each service query. Is this possible? Currently, the query returns data from each service query, and then runs a count and group by. I tried to use subqueries, but they do not work. I am using a fuseki server.

<Edited - added sample query>

SELECT (COUNT(?var) as ?varCount)  ?var2
WHERE{      
   {          
       ?var a abc:Class;                                                       
   }    
UNION       
   {        
   SERVICE <https://sample1.org>    
       {              
       ?var a abc:Class;               
       ?var abc:var2 ?var2.                    
       }        
   }
UNION       
   {        
   SERVICE <https://sample2.org>    
       {              
       ?var a abc:Class;               
       ?var abc:var2 ?var2.                 
       }        
   }
} group by ?var2  
Kris
  • 63
  • 7
  • Please show the query example. You can put aggregates to the SERVICE clause and aggregate the partial results in the caller. – AndyS Sep 23 '21 at 20:47
  • Hi Andy, firstly, many thanks for your fast reply. I will add an example of a query above now. – Kris Sep 24 '21 at 10:10
  • Since you have DISTINCT, you can't count at the remote sites and combine locally. – AndyS Sep 24 '21 at 12:33
  • Can you give me an example of a query I could run to aggregate the data at the remote sites? The most important thing is that aggregated data does not leave the remote sites. – Kris Sep 24 '21 at 12:53
  • AndyS, I removed DISTINCT from the query. – Kris Sep 24 '21 at 15:41
  • Now you can do ` SERVICE { SELECT (COUNT(?var) as ?varCount) ?var2 { ?var a abc:Class; ?var abc:var2 ?var2. } group by ?var2 } ` and so a SUM overall `?varCount` returned from each part. Also can write as drop the UNION, do 3 calls, get ?varCount1, ?varCount2, ?varCount3 and BIND(?varCount1+?varCount2+?varCount3 AS ?varCount). – AndyS Sep 24 '21 at 16:31

0 Answers0