Wrong query evaluation with aggregation subquery

限于喜欢 提交于 2019-12-02 08:53:01

问题


Please refer to Factforge Endpoint to execute this query. The subquery doesn't return any results. ?myVar will be projected out to the containing query, and then joined with the triple pattern ?myVar ?p ?o.. But as there are no results from the inner select, the join should result in nothing. However, this is not the case when executing the query. Isn't this a bug?

SELECT 
?myVar ?p ?o
WHERE 
{   
  { 
    SELECT ?myVar 
        WHERE { 
            ?myVar <http://www.example.com/arbitraryNonExistent> ?xx. 
        } 
    GROUP BY ?myVar
  } 
  ?myVar ?p ?o.  
} 
LIMIT 10

回答1:


It is the expected behaviour. According to https://www.w3.org/TR/sparql11-query/#aggregateAlgebra if there is a GROUP BY:

Group(exprlist, Ω) = { ... | μ in Ω }

and we have no matches, then Ω is empty, so:

Group(exprlist, {}) = {}

The effect is that the subquery returns a single solution where ?myVar is unbound and the join with the next statement pattern matches everything for ?myVar. At the end you are getting a lot of solutions for the whole query.

There is even a W3C SPARQL conformance testcase covering the exact scenario:

  • https://www.w3.org/2009/sparql/docs/tests/data-sparql11/aggregates/agg-empty-group.rq

  • https://www.w3.org/2009/sparql/docs/tests/data-sparql11/aggregates/agg-empty-group.srx

And also an old discussion at http://answers.semanticweb.com/questions/17410/semantics-of-sparql-aggregates.



来源:https://stackoverflow.com/questions/50116255/wrong-query-evaluation-with-aggregation-subquery

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!