SPARQL: error selecting variables in OPTIONAL clauses
KonradHoeffner opened this issue · comments
Selecting a variable that only occurs in an optional clause results in an error such as this:
Error: Variables '?c,?src' are used in the projection result, but are not assigned.
runOperation quadstore.bundle.js:2
run quadstore.bundle.js:2
runObservable quadstore.bundle.js:2
mediate quadstore.bundle.js:2
query quadstore.bundle.js:2
sparqlStream quadstore.bundle.js:2
sparql quadstore.bundle.js:2
sparql quadstore.bundle.js:2
select sparql.ts:14
selectClasses loadGraphFromSparql.ts:51
createClassNodes loadGraphFromSparql.ts:83
createNodes loadGraphFromSparql.ts:241
loadGraphFromSparql loadGraphFromSparql.ts:261
applyParams main.ts:103
fillInitialGraph main.ts:136
default progress.ts:49
fillInitialGraph main.ts:134
fill view.ts:49
View view.ts:110
main main.ts:209
EventListener.handleEvent* main.ts:217
log.ts:61:7
level log.ts:61
applyParams main.ts:124
fillInitialGraph main.ts:136
default progress.ts:49
fillInitialGraph main.ts:134
fill view.ts:49
View view.ts:110
main main.ts:209
(Async: EventListener.handleEvent)
<anonymous> main.ts:217
Example Query
PREFIX ov: <http://open.vocab.org/terms/>
SELECT ?c
(GROUP_CONCAT(distinct(CONCAT(?l,"@",lang(?l)));separator="|") as ?l)
?src
WHERE
{
?c a owl:Class.
OPTIONAL {?c rdfs:label ?l.}
OPTIONAL {?src ov:defines ?c.}
}
The query works perfectly on a Virtuoso SPARQL endpoint.
Thank you for reporting @KonradHoeffner . This might be related to comunica/comunica#666 . Which version of quadstore
were you using?
I was using https://cdn.jsdelivr.net/gh/beautifulinteractions/node-quadstore-webpack-bundle/quadstore.bundle.js, which was using quadstore version 9.2.0-alpha.0 at the time.
Which means this happened using @comunica/actor-init-sparql^1.22.2
. @rubensworks can this be a regression on comunica/comunica#666 ? I don't think @KonradHoeffner is able to test with a different version as he ended up using a different solution based on Virtuoso but I may be able to A/B test next week or so.
Things seem to be going wrong because of the usage of GROUP_CONCAT
. Seems to be slightly different to comunica/comunica#666 though. Could you create a new issue for this?
I suspect just a very minor change will be needed here: https://github.com/comunica/comunica/blob/master/packages/actor-query-operation-project/lib/ActorQueryOperationProject.ts#L35-L40
Note to self, this also occurs for MINUS queries such as this one:
PREFIX ex: <http://www.w3.org/2009/sparql/docs/tests/data-sparql11/negation#>
SELECT * {
?animal a ex:Animal MINUS {
optional {
?animal a ?type
FILTER(?type = ex:Reptile || ?type = ex:Insect)
}
}
}
Sure!
Tracked upstream in comunica/comunica#866
Fixed, will ship with next major version (10.0.0)