Hi,
It's the level at which the VALUES are being applied. They happen
after the SERVICE has returned. To see this, try pulling out the
sections of your query and use SELECT.
Starting with the sub query inside the SERVICE:
SELECT ?book (COUNT(?title) AS ?dummy)
WHERE { $book dc:title $title }
GROUP BY $book
This provides a count of "1" for all 7 book.
If you apply the VALUES here:
SELECT ?book (COUNT(?title) AS ?dummy)
WHERE { $book dc:title $title }
GROUP BY $book
VALUES ?title {
"Harry Potter and the Chamber of Secrets"
"Harry Potter and the Philosopher's Stone"
}
Then it gets restricted to a count of "1" for the two specified books.
However, when the VALUES are applied outside of the SERVICE you see
all 7 books come back. So this shows that the VALUES did not get
applied until the end of the SERVICE request. Of course, once the
SERVICE request has returned, there are no bindings for ?title, so
these values have no effect. The same can be seen if you apply VALUES
at the end of a local query:
SELECT ?book ?dummy {
SELECT ?book (COUNT(?title) AS ?dummy)
WHERE { $book dc:title $title }
GROUP BY $book
}
VALUES ?title {
"Harry Potter and the Chamber of Secrets"
"Harry Potter and the Philosopher's Stone"
}
The subquery binds ?book and ?dummy and returns, at which point the
results are merged with the bindings for ?title. Since ?title isn't in
the final result, this gets projected out, and the values have no
final effect.
Also, your final query using the "federated query without the
aggregation may have been misleading you:
CONSTRUCT { $book dc:title ?title }
WHERE {
SERVICE <http://sparql.org/books/sparql>
{ SELECT ?book ?title
WHERE { $book dc:title $title }
}
VALUES ?title {
"Harry Potter and the Chamber of Secrets"
"Harry Potter and the Philosopher's Stone"
}
}
The SERVICE section is actually returning all 7 books, including the
binding for ?title. You subsequently apply the VALUES, and this
reduces the bindings to just those 2 cases.If you remove the ?title
from the inner SELECT you see all 7 books next to each of the 2 titles
again (for a total of 14 results).
I need to look at the Federated query document more carefully, but I
was expecting that an important use case for VALUES was to help reduce
network transfers, meaning that when SERVICE blocks are sent over the
network the engine will silently append a VALUES clause to the query.
If ARQ is doing the correct thing here (and I suspect that it is),
then this makes these behind-the-scene optimizations harder since the
engine will only be able to append VALUES bindings if they only bind
variables that are being projected by the query in the subselect.
Regards,
Paul Gearon
On Fri, Jul 6, 2012 at 9:40 AM, Neubert Joachim <[email protected]> wrote:
> I try to query a current (rev 1356848) Fuseki endpoint with a list of
> VALUES and to update another one with aggregated results. It did not
> work as expected, and I could reproduce the behaviour with the standard
> books endpoint and an a (somehow contrieved) query:
>
> When I execute the following statement
>
> CONSTRUCT { $book dc:description ?dummy }
> WHERE {
> SERVICE <http://sparql.org/books/sparql>
> { SELECT ?book (COUNT(?title) AS ?dummy)
> WHERE { $book dc:title $title }
> GROUP BY $book
> }
> VALUES ?title {
> "Harry Potter and the Chamber of Secrets"
> "Harry Potter and the Philosopher's Stone"
> }
> }
>
> I'd expect two triples to be produced -
>
> <http://example.org/book/book1> dc:description 1 .
> <http://example.org/book/book2> dc:description 1 .
>
> However, I get 7 triples, for book1 - book7.
>
> A direct query against http://sparql.org/books/sparql
>
> CONSTRUCT { ?book dc:description ?dummy }
> WHERE {
> SELECT ?book (COUNT(?title) AS ?dummy)
> WHERE { $book dc:title $title }
> GROUP BY $book
> VALUES ?title {
> "Harry Potter and the Chamber of Secrets"
> "Harry Potter and the Philosopher's Stone"
> }
> }
>
> works as expected. And so does a federated query without the
> aggregation:
>
> CONSTRUCT { $book dc:title ?title }
> WHERE {
> SERVICE <http://sparql.org/books/sparql>
> { SELECT ?book ?title
> WHERE { $book dc:title $title }
> }
> VALUES ?title {
> "Harry Potter and the Chamber of Secrets"
> "Harry Potter and the Philosopher's Stone"
> }
> }
>
> Am I missing something?
>
> Cheers, Joachim