namedgraph opened a new issue, #3739:
URL: https://github.com/apache/jena/issues/3739

   ### Version
   
   4.7.0
   
   ### Question
   
     When a `VALUES` clause is placed after the `WHERE` clause in a `COUNT` 
aggregation query, it appears to be completely ignored. However, the same 
`VALUES` placement works correctly for non-aggregation queries.
   
   Not sure if this is a bug or some SPARQL edge case?
   
     ### Test Results
   
     | Query Type              | VALUES Placement | Expected | Actual |
     |-------------------------|------------------|----------|--------|
     | SELECT (no aggregation) | Outside GRAPH    | 3        | 3 ✓    |
     | SELECT COUNT            | Outside GRAPH    | 3        | 5 ✗    |
     | SELECT COUNT            | Inside GRAPH     | 3        | 3 ✓    |
   
     ### Minimal Reproducible Example
   
     **Test dataset** (`test-data.trig`):
     ```turtle
     @prefix ex: <http://example.org/> .
     @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
   
     <http://example.org/graph1> {
         ex:subject1 rdf:type ex:TypeA ; ex:property "value1" .
         ex:subject2 rdf:type ex:TypeA ; ex:property "value2" .
         ex:subject3 rdf:type ex:TypeA ; ex:property "value3" .
   
         ex:subject4 rdf:type ex:TypeB ; ex:property "value4" .
         ex:subject5 rdf:type ex:TypeB ; ex:property "value5" .
     }
     ```
   
     Dataset contains: 3 subjects of `TypeA`, 2 subjects of `TypeB` (5 total)
   
     **Query 1** - SELECT without aggregation, VALUES outside GRAPH (**returns 
3, correct**):
     ```sparql
     PREFIX ex: <http://example.org/>
     PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
   
     SELECT DISTINCT ?s ?type
     WHERE {
       GRAPH ?g {
         ?s rdf:type ?type ;
            ex:property ?o .
       }
     }
     VALUES ?type { ex:TypeA }
     ```
   
     **Query 2** - COUNT with VALUES outside GRAPH (**returns 5, incorrect - 
should be 3**):
     ```sparql
     PREFIX ex: <http://example.org/>
     PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
   
     SELECT DISTINCT (COUNT(DISTINCT ?s) AS ?count)
     WHERE {
       GRAPH ?g {
         ?s rdf:type ?type ;
            ex:property ?o .
       }
     }
     VALUES ?type { ex:TypeA }
     ```
   
     **Query 3** - COUNT with VALUES inside GRAPH (**returns 3, correct**):
     ```sparql
     PREFIX ex: <http://example.org/>
     PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
   
     SELECT DISTINCT (COUNT(DISTINCT ?s) AS ?count)
     WHERE {
       GRAPH ?g {
         ?s rdf:type ?type ;
            ex:property ?o .
         VALUES ?type { ex:TypeA }
       }
     }
     ```
   
   Query 2 returns 5 (the total count across ALL types), suggesting the 
`VALUES` clause is being evaluated after aggregation or ignored entirely when 
placed outside the `GRAPH` pattern in aggregation queries.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to