You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@jena.apache.org by "Jakub Galgonek (Jira)" <ji...@apache.org> on 2022/08/05 12:05:00 UTC
[jira] [Created] (JENA-2342) SPARQL query comparing "count(distinct ?v)" values is evaluated incorrectly
Jakub Galgonek created JENA-2342:
------------------------------------
Summary: SPARQL query comparing "count(distinct ?v)" values is evaluated incorrectly
Key: JENA-2342
URL: https://issues.apache.org/jira/browse/JENA-2342
Project: Apache Jena
Issue Type: Bug
Components: SPARQL
Affects Versions: Jena 4.5.0
Reporter: Jakub Galgonek
I encountered the following issue while testing the neXtProt database in Jena.
If the query –
{code:sql}
select ?id where {
values (?id ?v1 ?v2) { ('A' 'B' 'C') }
} group by ?id having (count(distinct ?v1) = count(distinct ?v2))
{code}
– is submitted, then the empty result is returned. However, the result –
{code:java}
( ?id = "A" ){code}
– should by returned.
On the other hand, the query –
{code:sql}
select ?id where {
{select ?id (count(distinct ?v1) as ?c1) (count(distinct ?v2) as ?c2) {
values (?id ?v1 ?v2) { ('A' 'B' 'C') }
} group by ?id}
filter (?c1 = ?c2)
}
{code}
– returns the result as expected.
The following code can be used to reproduce the issue:
{code:java}
import org.apache.jena.query.QueryExecution;
import org.apache.jena.query.QueryExecutionFactory;
import org.apache.jena.query.ResultSet;
import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.ModelFactory;
public class Test {
static String query1 = "select ?id where { values (?id ?v1 ?v2) { ('A' 'B' 'C') } } group by ?id having (count(distinct ?v1) = count(distinct ?v2))";
static String query2 = "select ?id where { {select ?id (count(distinct ?v1) as ?c1) (count(distinct ?v2) as ?c2) { values (?id ?v1 ?v2) { ('A' 'B' 'C') } } group by ?id} filter (?c1 = ?c2) }";
public static void main(String[] args) {
evaluate("Query1:", query1);
evaluate("Query2:", query2);
}
public static void evaluate(String name, String query) {
Model model = ModelFactory.createDefaultModel();
QueryExecution qexec = QueryExecutionFactory.create(query, model);
ResultSet results = qexec.execSelect();
System.out.println(name);
while(results.hasNext())
System.out.println(results.nextSolution());
}
}
{code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: jira-unsubscribe@jena.apache.org
For additional commands, e-mail: jira-help@jena.apache.org