BIND of a variable with CONCATs

The following query returns valid results (lots of them). So, I know that ?relatedIRI and ?relatedText have values.

PREFIX event: <http://example.com/ontology/odps/Event#>
PREFIX general: <http://example.com/ontology/odps/GeneralConcepts#>
SELECT ?s ?relatedIRI ?relatedText
FROM <http://graph.example.com>
FROM <http://ontology.example.com>
where {
     { #pragma group.join
    ?s a ?type . ?type rdfs:subClassOf* event:Event } 
     ?s event:has_active_actor ?relatedIRI .
     ?relatedIRI ?p1 ?relatedText .
     FILTER ( ?p1 IN ( rdfs:label, general:canonical_label ) ) .
}

But, this query returns no results (and no errors):

PREFIX event: <http://example.com/ontology/odps/Event#>
PREFIX general: <http://example.com/ontology/odps/GeneralConcepts#>
SELECT ?o
FROM <http://graph.example.com>
FROM <http://ontology.example.com>
where {
     { #pragma group.join
    ?s a ?type . ?type rdfs:subClassOf* event:Event } 
     ?s event:has_active_actor ?relatedIRI .
     ?relatedIRI ?p1 ?relatedText .
     FILTER ( ?p1 IN ( rdfs:label, general:canonical_label ) ) .
     BIND ( CONCAT(?relatedIRI,CONCAT("$$",?relatedText)) as ?o )
}

My real use case is a CONSTRUCT statement with ?o (which also CONSTRUCTS nothing) … but the query suffices to show the problem.

Thanks for looking at this.

Andrea

Hi Andrea,

Can you provide the query plan for the query which is not returning results?

Jess

The Query Plan:

prefix event: <http://example.com/ontology/odps/Event#>
prefix general: <http://example.com/ontology/odps/GeneralConcepts#>

From <http://ontology.example.com>
From <http://graph.example.com>
Projection(?o) [#2]
`─ HashJoin(?p1) [#2]
   +─ Bind(CONCAT(?relatedIRI, CONCAT("$$", ?relatedText)) AS ?o) [#3]
   │  `─ MergeJoin(?relatedIRI) [#3]
   │     +─ Sort(?relatedIRI) [#1]
   │     │  `─ MergeJoin(?s) [#1]
   │     │     +─ Sort(?s) [#69]
   │     │     │  `─ MergeJoin(?type) [#69]
   │     │     │     +─ Sort(?type) [#214]
   │     │     │     │  `─ PropertyPath(event:Event -> ?type, minLength=0) [#214]
   │     │     │     │     `─ Scan[POSC](?type, <http://www.w3.org/2000/01/rdf-schema#subClassOf>, event:Event) [#107]
   │     │     │     `─ Scan[POSC](?s, <http://www.w3.org/1999/02/22-rdf-syntax-ns#type>, ?type) [#3.6M]
   │     │     `─ Scan[PSOC](?s, event:has_active_actor, ?relatedIRI) [#102K]
   │     `─ Scan[SPOC](?relatedIRI, ?p1, ?relatedText) [#20.1M]
   `─ VALUES (?p1) {
      +─ ( <http://www.w3.org/2000/01/rdf-schema#label> )
      `─ ( general:canonical_label )
      }

Andrea

PS. The same CONSTRUCT did execute successfully on another repo.

Hi Andrea,

I suspect the problem here is that CONCAT accepts string literals as arguments whereas in your case ?relatedIRI is bound to IRIs. You may add str(...) around it to fix it.

However, if this is the problem, Stardog should return lots of empty bindings for ?o instead of the empty set.

By the way, looking at the plan I’m thinking the following variation of the query could be generally more efficient (we’ll look into improving the optimizer in this regard):

PREFIX event: <http://example.com/ontology/odps/Event#>
PREFIX general: <http://example.com/ontology/odps/GeneralConcepts#>
SELECT ?o
FROM <http://graph.example.com>
FROM <http://ontology.example.com>
where {
     { #pragma group.join
    ?s a ?type . ?type rdfs:subClassOf* event:Event } 
     ?s event:has_active_actor ?relatedIRI .
     { ?relatedIRI rdfs:label ?relatedText } UNION { ?relatedIRI general:canonical_label ?relatedText }
     BIND ( CONCAT(STR(?relatedIRI), CONCAT("$$", STR(?relatedText))) as ?o )
}

Let us know if it helps,

Pavel

The str(?relatedXxx) did the trick. My fault (something so obvious).

Thanks.
Andrea