You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@jena.apache.org by "namedgraph (via GitHub)" <gi...@apache.org> on 2026/02/08 22:21:23 UTC
[I] VALUES clause ignored in aggregation queries when placed outside GRAPH pattern [jena]
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: issues-unsubscribe@jena.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@jena.apache.org
For additional commands, e-mail: issues-help@jena.apache.org
Re: [I] VALUES clause ignored in aggregation queries when placed outside GRAPH pattern [jena]
Posted by "namedgraph (via GitHub)" <gi...@apache.org>.
namedgraph closed issue #3739: VALUES clause ignored in aggregation queries when placed outside GRAPH pattern
URL: https://github.com/apache/jena/issues/3739
--
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: issues-unsubscribe@jena.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@jena.apache.org
For additional commands, e-mail: issues-help@jena.apache.org
Re: [I] VALUES clause ignored in aggregation queries when placed outside GRAPH pattern [jena]
Posted by "Aklakan (via GitHub)" <gi...@apache.org>.
Aklakan commented on issue #3739:
URL: https://github.com/apache/jena/issues/3739#issuecomment-3872805585
AFAIK the variables of the VALUES block need to be in-scope with the result variables.
```sparql
SELECT ?foo (COUNT(*) AS ?count) {
}
GROUP BY ?foo
VALUES ?foo { "foo" }
```
gives
```
-----------------
| foo | count |
=================
| "foo" | 1 |
-----------------
```
--
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: issues-unsubscribe@jena.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@jena.apache.org
For additional commands, e-mail: issues-help@jena.apache.org
Re: [I] VALUES clause ignored in aggregation queries when placed outside GRAPH pattern [jena]
Posted by "namedgraph (via GitHub)" <gi...@apache.org>.
namedgraph commented on issue #3739:
URL: https://github.com/apache/jena/issues/3739#issuecomment-3872918397
@Aklakan that makes sense, but why does the query 1 (same pattern, but no aggregation) return a diffetent result (count)? :)
--
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: issues-unsubscribe@jena.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@jena.apache.org
For additional commands, e-mail: issues-help@jena.apache.org
Re: [I] VALUES clause ignored in aggregation queries when placed outside GRAPH pattern [jena]
Posted by "afs (via GitHub)" <gi...@apache.org>.
afs commented on issue #3739:
URL: https://github.com/apache/jena/issues/3739#issuecomment-3873038876
As @Aklakan says - aggregation puts `?type` out of scope. In Q1 there was no intermediate step that changes scoping.
In Q2, the `VALUES` is performed after aggregation so `?type` from the query pattern as gone away, and before projection
(and you can't add the variable to the projection because that's determined by the grouping).
--
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: issues-unsubscribe@jena.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@jena.apache.org
For additional commands, e-mail: issues-help@jena.apache.org
Re: [I] VALUES clause ignored in aggregation queries when placed outside GRAPH pattern [jena]
Posted by "namedgraph (via GitHub)" <gi...@apache.org>.
namedgraph commented on issue #3739:
URL: https://github.com/apache/jena/issues/3739#issuecomment-3873303093
Thanks!
--
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: issues-unsubscribe@jena.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@jena.apache.org
For additional commands, e-mail: issues-help@jena.apache.org