antoniogarrote / rdfstore-js

JS RDF store with SPARQL support
MIT License
564 stars 109 forks source link

Evaluation error using OPTIONAL with FILTER #148

Open aldonline opened 7 years ago

aldonline commented 7 years ago

Query

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
select ?label ?comment from <http://dbpedia.org/ontology/> where {
    <http://dbpedia.org/ontology/Agglomeration> ?p ?o .
    optional {
        <http://dbpedia.org/ontology/Agglomeration> rdfs:label ?label .
        filter  ( (lang(?label) = "") || langmatches(lang(?label), "EN") ) 
    } .
    optional {
        <http://dbpedia.org/ontology/Agglomeration> rdfs:comment ?comment .
        filter ( (lang(?comment) = "") || langmatches(lang(?comment), "EN") )          
    } .
} limit 1

Dataset

The data I'm querying against comes from a full dump of the named graph http://dbpedia.org/ontology/ on the main dbpedia server (https://dbpedia.org/sparql).

Stack

TypeError: Cannot read property 'token' of undefined
at Object.QueryFilters.runBuiltInCall (  rdfstore/src/query_filters.js:1342:22)
at Object.QueryFilters.runFilter (  rdfstore/src/query_filters.js:395:33)
at Object.QueryFilters.runFilter (  rdfstore/src/query_filters.js:385:36)
at Object.QueryFilters.runOrFunction (  rdfstore/src/query_filters.js:895:32)
at Object.QueryFilters.runFilter (  rdfstore/src/query_filters.js:389:33)
at Object.QueryFilters.runAndFunction (  rdfstore/src/query_filters.js:931:32)
at Object.QueryFilters.runFilter (  rdfstore/src/query_filters.js:391:33)
at   rdfstore/src/query_filters.js:186:36    at   rdfstore/src/query_engine.js:556:9
at   rdfstore/src/utils.js:385:21

Explanation

The engine tries to evaluate the FILTER(...) clause even if the ?label or ?comment variables are not bound. My expectation would be for the complete OPTIONAL clause to fail if there are no bindings for the BGP. You can try the same query in Virtuoso (https://dbpedia.org/sparql) and it will work.