Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HAVING and ORDER BY broken on COUNT() columns #247

Closed
niklas88 opened this issue May 13, 2019 · 0 comments · Fixed by #248
Closed

HAVING and ORDER BY broken on COUNT() columns #247

niklas88 opened this issue May 13, 2019 · 0 comments · Fixed by #248
Assignees
Labels
bug very important very important issue with priority

Comments

@niklas88
Copy link
Member

This issue was found by @hannahbast with the HAVING clause of the following average height by profession query:

PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX psv: <http://www.wikidata.org/prop/statement/value/>
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?occupation ?gender (AVG(?height) AS ?average_height) (COUNT(?height) AS ?count) WHERE {
  ?x wdt:P31 wd:Q5 .
  ?x p:P2048 ?statement .
  ?x wdt:P21 ?gender_id .
  ?gender_id rdfs:label ?gender .
  FILTER langMatches(lang(?gender), "en") .
  ?statement psv:P2048 ?value .
  ?value wikibase:quantityNormalized ?quantity .
  ?quantity wikibase:quantityUnit wd:Q11573 .
  ?quantity wikibase:quantityAmount ?height .
  ?x wdt:P106 ?occupation_id .
  ?occupation_id rdfs:label ?occupation .
  FILTER langMatches(lang(?occupation), "en") .
  FILTER (?height < 3)
}
GROUP BY ?occupation ?gender
HAVING (?count > 100)
ORDER BY DESC(?average_height)

It turns out this also affects ORDER BY, but works fine when the GROUP BY is implemented by CountAvailablePredicates.

A simple reproducer on the scientists collection is as follows

SELECT ?place (COUNT(?person) AS ?count) WHERE {
   ?person <is-a> <Person> .
   ?person <Place_of_birth> ?place
}
GROUP BY ?place
HAVING (?count > 5)
ORDER BY ASC(?count)

Where both the HAVING and the ORDER BY are broken on current master

@niklas88 niklas88 self-assigned this May 13, 2019
@niklas88 niklas88 added very important very important issue with priority bug labels May 13, 2019
niklas88 added a commit that referenced this issue May 15, 2019
Fix ORDER BY and FILTER on COUNT() columns #247
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug very important very important issue with priority
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant