Dmitry Zhelobanov created JENA-2288: ---------------------------------------
Summary: Counting aggregation inside SERVICE provides wrong result Key: JENA-2288 URL: https://issues.apache.org/jira/browse/JENA-2288 Project: Apache Jena Issue Type: Bug Affects Versions: Jena 4.4.0 Reporter: Dmitry Zhelobanov Here is a query which retrieves museums in the specific city: {code:java} PREFIX wd: <http://www.wikidata.org/entity/> PREFIX wdt: <http://www.wikidata.org/prop/direct/> SELECT ?wikidata_iri ?museum WHERE { VALUES (?wikidata_iri) { (<http://www.wikidata.org/entity/Q612>) } . SERVICE <https://query.wikidata.org/sparql> { { select ?wikidata_iri ?museum where { OPTIONAL { ?museum (wdt:P131)+ ?wikidata_iri ; wdt:P31/(wdt:P279)* wd:Q33506 . } } } } } {code} This query returns 3 results: |<http://www.wikidata.org/entity/Q612>|<http://www.wikidata.org/entity/Q2125281>| |<http://www.wikidata.org/entity/Q612>|<http://www.wikidata.org/entity/Q28736367>| |<http://www.wikidata.org/entity/Q612>|<http://www.wikidata.org/entity/Q67737768>| And here is a query which is supposed to count the number of the same museums in the same city: {code:java} PREFIX wd: <http://www.wikidata.org/entity/> PREFIX wdt: <http://www.wikidata.org/prop/direct/> SELECT ?wikidata_iri ?museum_count_in_city WHERE { VALUES (?wikidata_iri) { (<http://www.wikidata.org/entity/Q612>) } . SERVICE <https://query.wikidata.org/sparql> { { select ?wikidata_iri (COUNT(?museum) as ?museum_count_in_city) where { OPTIONAL { ?museum (wdt:P131)+ ?wikidata_iri ; wdt:P31/(wdt:P279)* wd:Q33506 . } } group by ?wikidata_iri } } }{code} But the count value produced by the query is wrong: |<[http://www.wikidata.org/entity/Q612]>|"201"{^}^^<[http://www.w3.org/2001/XMLSchema#integer]>{^}| It outputs *201* instead of expected *3.* -- This message was sent by Atlassian Jira (v8.20.1#820001)