Search code examples
sparqlgraphdb

Strange SPARQL behaviour in GraphDB


When trying to figure out why a certain query did not produce the expected results I came across some strange behaviour in GraphDB (10.2.1). Reproduced it with a small testset of data.

Turtle testdata

@prefix ex: <http://example.com/> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

ex:1 ex:hasDate "2022-03-01"^^xsd:date .
ex:2 ex:hasDate "2021-03-01"^^xsd:date .
ex:3 ex:hasDate "2022-08-24"^^xsd:date .

Imported this data in an empty repository, and then executed the following query:

PREFIX ex: <http://example.com/>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>

SELECT *
WHERE
{
    BIND("2022-01-01"^^xsd:date AS ?start_period)
    BIND("2022-12-31"^^xsd:date AS ?end_period)    
    ?something ex:hasDate ?date .
    FILTER (?date < ?end_period)
    FILTER (?date > ?start_period)
    {
        BIND("test" AS ?unused)       
    } UNION {
        BIND("test2" AS ?also_unused)
    }
}

Now I get the expected results:

start_period end_period something date unused also_unused
"2022-01-01"^^xsd:date 2022-12-31"^^xsd:date ex:1 "2022-03-01"^^xsd:date "test"
"2022-01-01"^^xsd:date "2022-12-31"^^xsd:date ex:3 "2022-08-24"^^xsd:date "test"
"2022-01-01"^^xsd:date "2022-12-31"^^xsd:date ex:1 "2022-03-01"^^xsd:date "test2"
"2022-01-01"^^xsd:date "2022-12-31"^^xsd:date ex:3 "2022-08-24"^^xsd:date "test2"

Now, for the strange behaviour. If you remove either one of the filters the query returns empty. But if you then also remove the complete UNION statement with the two BIND instructions, you will get a query result.

So, the combination of the UNION statement in combination with one filter seems to lead to problems.

Also, in the situation where you do not get any results, replacing SELECT * with (MIN(?date) AS ?test) will produce a result as you'd expect. So the following does produce a result:

PREFIX ex: <http://example.com/>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>

SELECT (MIN(?date) AS ?test)
WHERE
{
    BIND("2022-01-01"^^xsd:date AS ?start_period)
    BIND("2022-12-31"^^xsd:date AS ?end_period)    
    ?something ex:hasDate ?date .
    FILTER (?date > ?start_period)
    {
        BIND("test" AS ?unused)       
    } UNION {
        BIND("test2" AS ?also_unused)
    }
}

But if you use a SELECT * instead, the is no result. So, ask for the 'smallest' date produces "2022-03-01", asking for all the dates produces nothing at all. Is this a bug or am I missing something obvious here?

Rep


Solution

  • The issue you have mentioned has been fixed in a later version of GraphDB (10.3.0), which is scheduled to be released in the upcoming weeks. GraphDB also has a support mail where questions and problems like the provided, are discussed and resolved in swifter manner, in case of urgency :

    [email protected] .