[ 
https://issues.apache.org/jira/browse/JENA-2342?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17577377#comment-17577377
 ] 

ASF subversion and git services commented on JENA-2342:
-------------------------------------------------------

Commit ec1d9de33e9ce0fbbd16034f182d470bb6fe8eaa in jena's branch 
refs/heads/main from Andy Seaborne
[ https://gitbox.apache.org/repos/asf?p=jena.git;h=ec1d9de33e ]

JENA-2342: Only consider group variables


> 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
>            Priority: Minor
>
> 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: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to