使用 COUNT 和 ORDER 的 SPARQL 查询返回奇怪的结果

发布于 2024-10-29 02:18:07 字数 1393 浏览 4 评论 0原文

以下查询对存储中的所有三元组进行计数

SELECT count(*) where { ?s ?p <http://dbpedia.org/resource/Cat> }

并返回预期结果

http://dbpedia.org/sparql?default-graph-uri=http://dbpedia.org&query=select+count(*)+{ +%3Fs+%3Fp+%3Chttp://dbpedia.org/resource/Cat%3E+}+&debug=on&timeout=&format=text/html&save=display&fname=

但是,当我第一次尝试时不小心留在了 ORDER BY 语句中,例如,

select count(*) { ?s ?p <http://dbpedia.org/resource/Cat> } order by ?s

然后我得到一个很长的结果列表

http://dbpedia.org/sparql?default-graph-uri=http: //dbpedia.org&query=select+count(*)+{+%3Fs+%3Fp+%3Chttp://dbpedia.org/resource/Cat%3E+}+order+by+%3Fs&debug=on&timeout=& ;format=text/html&save=display&fname=

谁能解释为什么会出现这个结果以及它意味着什么?这可能是 Virtuoso SPARQL 实现的一个错误吗?

The following query counts all triples in a store

SELECT count(*) where { ?s ?p <http://dbpedia.org/resource/Cat> }

And returns the expected results

http://dbpedia.org/sparql?default-graph-uri=http://dbpedia.org&query=select+count(*)+{+%3Fs+%3Fp+%3Chttp://dbpedia.org/resource/Cat%3E+}+&debug=on&timeout=&format=text/html&save=display&fname=

However, when I first tried it I accidentally left in an ORDER BY statement, e.g.,

select count(*) { ?s ?p <http://dbpedia.org/resource/Cat> } order by ?s

Then I get a very long list of results

http://dbpedia.org/sparql?default-graph-uri=http://dbpedia.org&query=select+count(*)+{+%3Fs+%3Fp+%3Chttp://dbpedia.org/resource/Cat%3E+}+order+by+%3Fs&debug=on&timeout=&format=text/html&save=display&fname=

Can anyone explain why this result happens and what it means? Is it maybe a bug with the Virtuoso SPARQL implementation?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

只怪假的太真实 2024-11-05 02:18:07

如果您在不同的商店(即在
http://api.talis.com/stores/bbc-backstage/services/sparql (它不运行 virtuoso)

第一个查询有效......

SELECT (count(?s) as ?c)
WHERE {
?s ?p <http://purl.org/ontology/po/Version> .
}

而第二个

SELECT (count(?s) as ?c)
WHERE {
?s ?p <http://purl.org/ontology/po/Version> .
} order by ?s

......给出了相同的结果。

实际上计数 + 排序在这里没有多大意义,因为 ?s 没有被选择检索。但正如你所说,你无意中尝试了它......它看起来确实像一个错误。

我的建议是向 virtuoso 用户邮件列表发送电子邮件以通知此问题。

It does look like a bug, if you run the same type of queries on a different store, i.e on
http://api.talis.com/stores/bbc-backstage/services/sparql (which doesn't run virtuoso)

This first query works ...

SELECT (count(?s) as ?c)
WHERE {
?s ?p <http://purl.org/ontology/po/Version> .
}

and the second ...

SELECT (count(?s) as ?c)
WHERE {
?s ?p <http://purl.org/ontology/po/Version> .
} order by ?s

... gives the same result.

Actually counting + ordering doesn't make much sense here because ?s is not selected to be retrieved. But as you said, you tried it accidentally and ... it does look like a bug.

My recommendation is to send an email to the virtuoso-user mailing list to notify about this issue.

酷到爆炸 2024-11-05 02:18:07

我们(= OpenLink)在这里遇到了麻烦。这个 ORDER BY ?s 在形式上是查询中的一个错误:没有分组的聚合意味着“对所有内容进行聚合”,在查询的输出端不应该有聚合之外的变量。然而,现在不会报告此错误:违反此规则的情况如此之多,以至于 SQL 编译器会进行自动分组,并且我们的 SPARQL-to-SQL 预处理器也会在可能的情况下忽略此错误。

我们可能会保持当前的行为不变。如果添加“严格”编译模式,在这种情况下将会触发错误报告。

We (= OpenLink) are in trouble here. This ORDER BY ?s is formally a bug in the query: an aggregate without grouping means "aggregate on everything", there should be no variables outside aggregates at the output end of the query. However this error is not reported now: violations of this rule are so numerous that SQL compiler makes an auto-grouping and our SPARQL-to-SQL preprocessor also ignores this error if possible.

We will probably keep the current behaviour as is. If a "strict" compilation mode is added it will trigger the error reporting in cases like this.

べ映画 2024-11-05 02:18:07

这可能是 Virtuoso 的一个错误,它似乎将带有聚合和 ORDER BY 子句的查询视为具有隐式 GROUP BY 子句。除了 DBPedia 端点之外,我在其他 Virtuoso 端点上也注意到了这一点。

IMO 这是一个错误,您应该按照 msalvadores 的建议将其报告给 Virutoso 用户邮件列表

This may be a bug with Virtuoso, it seems to treat queries with aggregates and an ORDER BY clause as having an implicit GROUP BY clause. I've noticed this on other Virtuoso endpoints besides the DBPedia one.

IMO this is a bug and you should report it to the Virutoso users mailing list as msalvadores suggests

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文