Reduced query (not meaningful):
SELECT ?x WITH {
SELECT ?x (COUNT(*) AS ?count) WHERE {
?x a schema:Dataset.
}
GROUP BY ?x
HAVING(?count > 0)
} AS %x WHERE {
INCLUDE %x.
}(link)
java.lang.IllegalArgumentException: Non-aggregate variable in select expression: x
If you remove the HAVING clause, the query is accepted.
Phrased as a non-named subquery, this works without problems:
SELECT ?x WHERE {
{
SELECT ?x (COUNT(*) AS ?count) WHERE {
?x a schema:Dataset.
}
GROUP BY ?x
HAVING(?count > 0)
}
}(link)
It seems the subquery has to specify a triple to trigger the bug; I was unable to reproduce it with a VALUES clause instead. (The triple can also be ?x ?y ?z to make the query completely independent of the database, but then you’ll want a LIMIT on the subquery.)
Here’s the original query where I found the bug:
# works with most citations
# runtime: 25-45 s
SELECT ?work ?workLabel ?count WITH {
SELECT ?work (COUNT(*) AS ?count) WHERE {
?work wdt:P2860 [].
}
GROUP BY ?work
HAVING(?count > 100)
ORDER BY DESC(?count)
LIMIT 100
} AS %works WHERE {
INCLUDE %works.
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
ORDER BY DESC(?count)(link)
This is probably an upstream issue, but BlazeGraph’s Jira seems to be down right now and I don’t have an account there anyways.