Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SPARQL: error selecting variables in OPTIONAL clauses #142

Closed
KonradHoeffner opened this issue Oct 13, 2021 · 7 comments
Closed

SPARQL: error selecting variables in OPTIONAL clauses #142

KonradHoeffner opened this issue Oct 13, 2021 · 7 comments
Labels

Comments

@KonradHoeffner
Copy link

KonradHoeffner commented Oct 13, 2021

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.

@jacoscaz
Copy link
Owner

Thank you for reporting @KonradHoeffner . This might be related to comunica/comunica#666 . Which version of quadstore were you using?

@KonradHoeffner
Copy link
Author

KonradHoeffner commented Oct 19, 2021

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.

@jacoscaz
Copy link
Owner

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.

@rubensworks
Copy link

rubensworks commented Oct 20, 2021

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

@jacoscaz
Copy link
Owner

Sure!

@jacoscaz
Copy link
Owner

Tracked upstream in comunica/comunica#866

@jacoscaz jacoscaz changed the title Error selecting variables in OPTIONAL clauses SPARQL: error selecting variables in OPTIONAL clauses Oct 20, 2021
@jacoscaz jacoscaz added the bug label Oct 20, 2021
@jacoscaz
Copy link
Owner

Fixed, will ship with next major version (10.0.0)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants