Count distinct query
Opened this issue · 0 comments
koslambrou commented
The following SPARQL query allows to fetch the number of distinct subjects in the database:
SELECT (COUNT(DISTINCT ?s) as ?count) WHERE {
?s ?p ?o .
}
However, there's doesn't seem to be a way to translate that query in HSparql.
An equivalent way would be to translate it as a sub query such as:
SELECT (COUNT(?s) as ?count) WHERE {
SELECT DISTINCT ?s WHERE {
?s ?p ?o .
}
}
Which can be translated to HSparql as:
countSubjsQuery :: Query SelectQuery
countSubjsQuery = do
s <- var
p <- var
o <- var
subQuery_ $ do
triple_ s p o
distinct_
selectVars [s]
c <- var
select [count r `as` c]
Possible enhancement in order to use the distinct
function with the count
function to produce a SPARQL query similar to the first one ?