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 "exists" function not working with "bind if" #693

Open
Kevin-Darty opened this issue Nov 7, 2017 · 9 comments
Open

Sparql "exists" function not working with "bind if" #693

Kevin-Darty opened this issue Nov 7, 2017 · 9 comments

Comments

@Kevin-Darty
Copy link

My Virtuoso is (virtuoso-t -h):

Virtuoso Open Source Edition (Column Store) (multi threaded)
Version 7.2.4.2.3217-pthreads as of Jun  3 2016
Compiled for Linux (x86_64-pc-linux-gnu)

The Sparql function exists is working fine, but not when combined with (bind if(...)).
The query:

PREFIX dbo: <http://dbpedia.org/property/>
SELECT  ?uri  ?popEstimate ?existsPopEstim ?usedExPop
WHERE {
	?uri  a <http://dbpedia.org/ontology/Place>.
	
	{?uri rdfs:label "France"@fr}
	UNION {?uri rdfs:label "Brésil"@fr}
	UNION {?uri rdfs:label "Amérique"@fr}
	
	OPTIONAL {?uri dbo:populationEstimate ?popEstimate .}	
	BIND (exists{?uri dbo:populationEstimate ?popEstimate} AS ?existsPopEstim )
	BIND (IF(?existsPopEstim , "ok", "no") AS ?usedExPop)
}
LIMIT 100

The result:

uri                                  | popEstimate | existsPopEstim | usedExPop
-------------------------------------+-------------+----------------+----------
http://dbpedia.org/resource/France   |             | 0              | ok
http://dbpedia.org/resource/Brazil   | 201032714   | 1              | ok
http://dbpedia.org/resource/Americas |             | 0              | ok 

(see https://stackoverflow.com/q/47161296/6833025)

@HughWilliams
Copy link
Collaborator

This issue has been reported to development to look into ...

@kidehen
Copy link

kidehen commented Nov 7, 2017

@niwizard ,

Copy of what I posted to Stackoverflow:

I notice that you are experiencing this problem via Version 7.2.4.2.3217-pthreads as of Jun 3 2016. Here's what happens with the more recent 7.2.x and 8.0 releases via live example links:

  • DBpedia -- running 7.2.x (2017 release)
  • URIBurner -- running 8.0 (2018 release), but doesn't have
    complete DBpedia dataset loaded.

That said, I can recreate your problem via our LOD Cloud Cache instance. Thus, I suggest:

  1. Upgrade on your part to one of the 2017 releases used in my examples above
  2. We revisit our Cluster Edition which is running behind the LOD Cloud instance that I used to recreate your problem.

@Kevin-Darty
Copy link
Author

The problem is the same with a unique BIND:

BIND (IF(exists{?uri dbo:populationEstimate ?popEstimate} , "ok", "no") AS ?usedExPop)

@kidehen
Copy link

kidehen commented Nov 8, 2017

@niwizard -- share a link to a live example on DBpedia (for instance) so that I can reply with a potential workaround etc..

@kidehen
Copy link

kidehen commented Nov 8, 2017

@niwizard,

This is a datatype issue. Basically SQL Null datatype rearing its head.

  1. This Query Result filters out Nulls

  2. This Query Shows the Null effect

  3. This Query Results Page shows the problem

That said, given --

SELECT  ?uri  ?pop ?existsPop ?usedExPop
WHERE {
	?uri  a <http://dbpedia.org/ontology/Place>.
	
	{?uri rdfs:label "France"@en}
	UNION {?uri rdfs:label "Brazil"@en}
	UNION {?uri rdfs:label "Raging River"@en}
	

	OPTIONAL {?uri dbo:populationTotal ?pop .}	
        BIND (xsd:boolean(exists{?uri dbo:populationTotal ?pop}) AS ?existsPop)
	BIND (IF(xsd:boolean(?existsPop), "ok", "no") AS ?usedExPop)
        FILTER (?pop > 0)
}
LIMIT 1000

-- we should be able to consider coercing ?existsPop to be xsd:boolean rather than requiring the explicit casting heuristics above. EXISTs should return xsd:boolean in this context.

@Kevin-Darty
Copy link
Author

OK so you casted the exists result into xsd:boolean, thus ?existsPop is giving true or false the right way.
But ?usedExPop is still returning "ok" with:

 BIND (xsd:boolean(exists{?uri dbo:populationTotal ?pop}) AS ?existsPop)
 BIND (IF(xsd:boolean(?existsPop), "ok", "no") AS ?usedExPop)

@kidehen
Copy link

kidehen commented Nov 8, 2017

@niwizard,

Yes, as per:

SELECT  ?uri  ?pop ?existsPop ?usedExPop xsd:boolean(?usedExPop) as ?usedExPop2
WHERE {
	?uri  a `<http://dbpedia.org/ontology/Place>`.
	
	{?uri rdfs:label "France"@en}
	UNION {?uri rdfs:label "Brazil"@en}
	UNION {?uri rdfs:label "Raging River"@en}
	

	OPTIONAL {?uri dbo:populationTotal ?pop .}	
        BIND (xsd:boolean(exists{?uri dbo:populationTotal ?pop}) AS ?existsPop)
	BIND (IF(xsd:boolean(?existsPop) = "true"^^xsd:boolean, "ok", "no") AS ?usedExPop)
        # FILTER (?pop > 0)
}
LIMIT 1000

Which shows the problem re. bug to be fixed as per this query results page.

@IvanMikhailov
Copy link
Contributor

I have progress with debugging, but I don't have the fix yet.

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

No branches or pull requests

4 participants