jacoscaz / quadstore

A LevelDB-backed graph database for JS runtimes (Node.js, Deno, browsers, ...) supporting SPARQL queries and the RDF/JS interface.

Home Page:https://github.com/jacoscaz/quadstore

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

(can be reproduced here: http://query.linkeddatafragments.org/#datasources=https%3A%2F%2Fwww.rubensworks.net%2F&query=PREFIX%20ov%3A%20%3Chttp%3A%2F%2Fopen.vocab.org%2Fterms%2F%3E%0A%20%20SELECT%20%3Fc%0A%20%20(GROUP_CONCAT(distinct(CONCAT(%3Fl%2C%22%40%22%2Clang(%3Fl)))%3Bseparator%3D%22%7C%22)%20as%20%3Fl)%0A%20%20%3Fsrc%0A%20%20%0A%20%20WHERE%0A%20%20%7B%0A%20%20%20%20%3Fc%20a%20owl%3AClass.%0A%20%20%20%20%3Fc%20rdfs%3Alabel%20%3Fl.%0A%20%20%20%20%3Fsrc%20ov%3Adefines%20%3Fc.%0A%20%20%7D)

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)
    }
  }
}

Fixed, will ship with next major version (10.0.0)