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

KnarQL: handling of statements in OPTIONAL and UNION #686

Closed
tobiasschweizer opened this issue Dec 11, 2017 · 0 comments · Fixed by #688
Closed

KnarQL: handling of statements in OPTIONAL and UNION #686

tobiasschweizer opened this issue Dec 11, 2017 · 0 comments · Fixed by #688
Assignees
Labels
API/V2 breaking any breaking change enhancement improve existing code or new feature
Milestone

Comments

@tobiasschweizer
Copy link
Contributor

tobiasschweizer commented Dec 11, 2017

The current design expects all statements to be contained in the results (one or more matches).

The use of OPTIONAL and UNION, however, introduces statements that may match. This means that cannot be expected to be present in the results.

Consider the following SPARQL query with a UNION:

 SELECT DISTINCT ?letter (GROUP_CONCAT(?person1; SEPARATOR='') AS ?person1Concat) (GROUP_CONCAT(?date; SEPARATOR='') AS ?dateConcat) (GROUP_CONCAT(?person1__LinkValue; SEPARATOR='') AS ?person1__LinkValueConcat)
 WHERE {
 {
 ?letter <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.knora.org/ontology/knora-base#Resource> .
 GRAPH <http://www.ontotext.com/explicit> {
     ?letter <http://www.knora.org/ontology/knora-base#isDeleted> "false"^^<http://www.w3.org/2001/XMLSchema#boolean> .
 }
 ?letter <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.knora.org/ontology/beol#letter> .
 ?letter <http://www.knora.org/ontology/beol#creationDate> ?date .
 GRAPH <http://www.ontotext.com/explicit> {
     ?date <http://www.knora.org/ontology/knora-base#isDeleted> "false"^^<http://www.w3.org/2001/XMLSchema#boolean> .
 }
 } UNION {
 ?letter <http://www.knora.org/ontology/beol#mentionsPerson> ?person1 .
 ?letter <http://www.knora.org/ontology/beol#mentionsPersonValue> ?person1__LinkValue .
 GRAPH <http://www.ontotext.com/explicit> {
     ?person1__LinkValue <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.knora.org/ontology/knora-base#LinkValue> .
 }
 GRAPH <http://www.ontotext.com/explicit> {
     ?person1__LinkValue <http://www.knora.org/ontology/knora-base#isDeleted> "false"^^<http://www.w3.org/2001/XMLSchema#boolean> .
 }
 GRAPH <http://www.ontotext.com/explicit> {
     ?person1__LinkValue <http://www.w3.org/1999/02/22-rdf-syntax-ns#subject> ?letter .
 }
 GRAPH <http://www.ontotext.com/explicit> {
     ?person1__LinkValue <http://www.w3.org/1999/02/22-rdf-syntax-ns#object> ?person1 .
 }
 ?person1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.knora.org/ontology/knora-base#Resource> .
 GRAPH <http://www.ontotext.com/explicit> {
     ?person1 <http://www.knora.org/ontology/knora-base#isDeleted> "false"^^<http://www.w3.org/2001/XMLSchema#boolean> .
 }
 ?person1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.knora.org/ontology/beol#person> .
 }
 }
 
 GROUP BY ?letter
 ORDER BY ASC(?letter)
 OFFSET 0
 LIMIT 25

It returns the following results (SPARQL web console):

sparql_results

In Knora, empty results are filtered out:

debugger

Since all the variables (keys) are expected to be present in result (a map), Knora throws an exception (ErrorHandlingMap): Status Code: 500 {"status":4,"error":"org.knora.webapi.InconsistentTriplestoreDataException: No value found for SPARQL query variable 'person1Concat' in query result row"}

Proposed solution:

Statements inside an OPTIONAL or a UNION may be present in the results, but they cannot be expected to be there. In scala, we have to check for the key using get and only access it if it is not None.

@tobiasschweizer tobiasschweizer self-assigned this Dec 11, 2017
@tobiasschweizer tobiasschweizer added API/V2 breaking any breaking change enhancement improve existing code or new feature labels Dec 11, 2017
@tobiasschweizer tobiasschweizer added this to the API V2 milestone Dec 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API/V2 breaking any breaking change enhancement improve existing code or new feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant