# BIND of a variable with CONCATs

**URL:** <https://community.stardog.com/t/bind-of-a-variable-with-concats/1153>\
**Category:** Bug\
**Created:** [July 24, 2018, 2:33am UTC](https://community.stardog.com/t/bind-of-a-variable-with-concats/1153 "2018-07-24T02:33:52Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![arwesterinen](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/arwesterinen/32/40_2.png) [@arwesterinen](https://community.stardog.com/u/arwesterinen)\
**Post date:** [July 24, 2018, 2:33am UTC](https://community.stardog.com/t/bind-of-a-variable-with-concats/1153/1 "2018-07-24T02:33:52Z")

</div>

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

```auto
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):

```auto
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

---

<div class="post-metadata">

**Author:** ![jess](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/jess/32/10_2.png) [@jess](https://community.stardog.com/u/jess)\
**Post date:** [July 24, 2018, 2:47am UTC](https://community.stardog.com/t/bind-of-a-variable-with-concats/1153/2 "2018-07-24T02:47:32Z")

</div>

Hi Andrea,

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

Jess

---

<div class="post-metadata">

**Author:** ![arwesterinen](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/arwesterinen/32/40_2.png) [@arwesterinen](https://community.stardog.com/u/arwesterinen)\
**Post date:** [July 24, 2018, 3:30am UTC](https://community.stardog.com/t/bind-of-a-variable-with-concats/1153/3 "2018-07-24T03:30:33Z")

</div>

The Query Plan:

```auto
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.

---

<div class="post-metadata">

**Author:** ![pavel](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/pavel/32/18_2.png) [@pavel](https://community.stardog.com/u/pavel)\
**Post date:** [July 24, 2018, 7:42am UTC](https://community.stardog.com/t/bind-of-a-variable-with-concats/1153/4 "2018-07-24T07:42:25Z")

</div>

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):

```auto
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

---

<div class="post-metadata">

**Author:** ![arwesterinen](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/arwesterinen/32/40_2.png) [@arwesterinen](https://community.stardog.com/u/arwesterinen)\
**Post date:** [July 24, 2018, 1:24pm UTC](https://community.stardog.com/t/bind-of-a-variable-with-concats/1153/5 "2018-07-24T13:24:21Z")

</div>

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

Thanks.  
Andrea
