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 UNION: problem it ORDER BY criterion #685

Closed
tobiasschweizer opened this issue Dec 11, 2017 · 2 comments · Fixed by #692
Closed

KnarQL UNION: problem it ORDER BY criterion #685

tobiasschweizer opened this issue Dec 11, 2017 · 2 comments · Fixed by #692
Assignees
Labels
API/V2 breaking any breaking change bug something isn't working
Milestone

Comments

@tobiasschweizer
Copy link
Contributor

tobiasschweizer commented Dec 11, 2017

When I run the following KnarQL query, the triplestore crashes:

PREFIX beol: <http://0.0.0.0:3333/ontology/beol/simple/v2#>
    PREFIX knora-api: <http://api.knora.org/ontology/knora-api/simple/v2#>
    
    CONSTRUCT {
        ?letter knora-api:isMainResource true .
        
        ?letter beol:creationDate ?date .
    
        ?letter beol:hasAuthor  ?person1 .   

    } WHERE {
        {
            ?letter a knora-api:Resource .
            ?letter a beol:letter .
            
            ?letter beol:creationDate ?date .
        
            beol:creationDate knora-api:objectType knora-api:Date .
            ?date a knora-api:Date .
            
        
        } UNION {
        
            ?letter beol:hasAuthor ?person1 .
            
            beol:hasAuthor knora-api:objectType knora-api:Resource .
            
            ?person1 a beol:person .
            ?person1 a knora-api:Resource .
        } 
           
    } ORDER BY ?date

SPARQL that is executed by the triplestore:

 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#hasAuthor> ?person1 .
 ?letter <http://www.knora.org/ontology/beol#hasAuthorValue> ?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> .
 }
 GRAPH <http://www.ontotext.com/explicit> {
     ?date <http://www.knora.org/ontology/knora-base#valueHasStartJDN> ?date__valueHasStartJDN .
 }
 }
 
 GROUP BY ?letter ?date__valueHasStartJDN
 ORDER BY ASC(?date__valueHasStartJDN) ASC(?letter)
 OFFSET 0
 LIMIT 25

Problem: the pattern GRAPH <http://www.ontotext.com/explicit> { ?date <http://www.knora.org/ontology/knora-base#valueHasStartJDN> ?date__valueHasStartJDN . } is inserted after the last UNION block and ?date__valueHasStartJDN does not seem to be bound.

Solution: move the pattern to the end of the first block of the WHERE clause.

 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> .
 }
GRAPH <http://www.ontotext.com/explicit> {
     ?date <http://www.knora.org/ontology/knora-base#valueHasStartJDN> ?date__valueHasStartJDN .
 }
 } UNION {
 ?letter <http://www.knora.org/ontology/beol#hasAuthor> ?person1 .
 ?letter <http://www.knora.org/ontology/beol#hasAuthorValue> ?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 ?date__valueHasStartJDN
 ORDER BY ASC(?date__valueHasStartJDN) ASC(?letter)
 OFFSET 0
 LIMIT 25

@tobiasschweizer tobiasschweizer self-assigned this Dec 11, 2017
@tobiasschweizer tobiasschweizer added API/V2 breaking any breaking change bug something isn't working labels Dec 11, 2017
@tobiasschweizer tobiasschweizer added this to the API V2 milestone Dec 11, 2017
@tobiasschweizer
Copy link
Contributor Author

see also #642

@tobiasschweizer tobiasschweizer changed the title KnarQL: UNION KnarQL UNION: problem it ORDER BY criterion Dec 11, 2017
@tobiasschweizer
Copy link
Contributor Author

tobiasschweizer commented Dec 11, 2017

I think the KnarQL query above is actually wrong, the first part should be required. As it is now, it asks for alternative patterns.

It should be rewritten to:

PREFIX beol: <http://0.0.0.0:3333/ontology/beol/simple/v2#>
    PREFIX knora-api: <http://api.knora.org/ontology/knora-api/simple/v2#>
    
    CONSTRUCT {
        ?letter knora-api:isMainResource true .
        
        ?letter beol:creationDate ?date .
    
        ?letter beol:hasAuthor  ?person1 .   

    } WHERE {
        
            ?letter a knora-api:Resource .
            ?letter a beol:letter .
            
            ?letter beol:creationDate ?date .
        
            beol:creationDate knora-api:objectType knora-api:Date .
            ?date a knora-api:Date .
            
         OPTIONAL {
        
            ?letter beol:hasAuthor ?person1 .
            
            beol:hasAuthor knora-api:objectType knora-api:Resource .
            
            ?person1 a beol:person .
            ?person1 a knora-api:Resource .
        } 
           
    } ORDER BY ?date

Then we have the same problem as reported in #686

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 bug something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant