Search code examples
sparqlgraphdbrdf4j

GraphDB or RDF4J bug? BOUND() yields wrong value


There seems to be a problem with the BOUND() function either in Ontotext GraphDB or in RDF4J SPARQL evaluation. The latter is less likely as I cannot reproduce the bug with an in-memory SAIL.

Versions: Graphdb Free 9.4.1 (and some earlier versions: confirmed in 9.4.0, suspected in 9.3.3, probably earlier than that, too).

To reproduce:

  • Install a new 9.4.1 free GraphDB under Windows 10
  • Create a repository with default configuration, except for: SHACL validation enabled, no inference (did not systematically test other configurations, I suspect that all are affected)

Import the test data below into the default graph:

@prefix ex: <http:example.com/vocab#> .
@prefix : <http:example.com/test#> .

:buildingA a ex:Building ;
    ex:height 100;
    ex:floors 30 .

:buildingB a ex:Building ;
    ex:height 80 .

Execute this query:

select ?type (bound(?type) as ?test)
where {
    ?s a ?type .
}

Result:

?type    ?test
<http:example.com/vocab#Building>    "false"^^<http://www.w3.org/2001/XMLSchema#boolean>
<http:example.com/vocab#Building>    "false"^^<http://www.w3.org/2001/XMLSchema#boolean>

Clearly, ?test should be true in both solutions.

I tried a number of variations of the sparql query such as binding ?test in the where clause and play around with the graph patterns - the result is always the same.

If there is a workaround to this issue, I'd be grateful to hear it.


Solution

  • As @damyan-ognyanov notes, and I have verified this: simplest workaround is to introduce an arbitrary unused var in the projection, e.g.

    select ?type (bound(?type) as ?test) ?fictive_var where { ...
    

    Note: this workaround only works for uses of bound() in the projection, not if used in a bind( ) function in the where clause.