# How to get pystardog to construct from a named graph with virtual transparency on

**URL:** <https://community.stardog.com/t/how-to-get-pystardog-to-construct-from-a-named-graph-with-virtual-transparency-on/2418>\
**Category:** Support\
**Created:** [May 3, 2020, 6:45pm UTC](https://community.stardog.com/t/how-to-get-pystardog-to-construct-from-a-named-graph-with-virtual-transparency-on/2418 "2020-05-03T18:45:55Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kevin\_Vanslette](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/kevin_vanslette/32/646_2.png) [@Kevin\_Vanslette](https://community.stardog.com/u/Kevin_Vanslette)\
**Post date:** [May 3, 2020, 6:45pm UTC](https://community.stardog.com/t/how-to-get-pystardog-to-construct-from-a-named-graph-with-virtual-transparency-on/2418/1 "2020-05-03T18:45:55Z")

</div>

Hi everybody,

I am using pystardog to perform a constructs (or select) on a named graph. Using Studio, the construct query returns results in about 1.5 seconds, while pystardog timesout.

Here is the form of the construct call:

```
CONSTRUCT {    
GRAPH <urn:foo> {
?s ?p ?o.
?s2 ?p2 ?o2.
}}
WHERE{
?s :predefined_predicate ?s2.
?s ?p ?o.
?s2 ?p2 ?o2.

}

```

In studio, I have the db and the named graph selected in the Workplace tab. If I did not select the named graph in the gui, and instead queried from tag:stardog:api:context:all (virtual transparency is on) with the above construct call, it also timed out.

In pystardog, I ran the above construct call through:

```
 with stardog.Admin(**conn_details) as admin:
        db= admin.database('db')

        with stardog.Connection('db', **conn_details) as conn:
            conn.begin()

            resultsconstruct=conn.graph(sparql,limit=100)

            conn.end()

```

It times out independent of the limit on the number of triples returned.

does anyone know how to solve this issue?

---

<div class="post-metadata">

**Author:** ![Kevin\_Vanslette](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/kevin_vanslette/32/646_2.png) [@Kevin\_Vanslette](https://community.stardog.com/u/Kevin_Vanslette)\
**Post date:** [May 3, 2020, 7:02pm UTC](https://community.stardog.com/t/how-to-get-pystardog-to-construct-from-a-named-graph-with-virtual-transparency-on/2418/2 "2020-05-03T19:02:40Z")

</div>

I should note that the named graph urn:foo was constructed from virtual graphs and it is not itself a virtual graph.

Further, I noted that the query plan in studio (from what I could tell) did not change when adding or removing the named graph, GRAPH urn:foo{...}, from the query in either case (context:all or the named graph foo selected in the worksheet). Changing between context:all and named graph in the worksheet did change the query plan. Context:all utilized the virtual graphs rather than being overridden by the GRAPH urn:foo call.... likely because virtual transparency is on.

---

<div class="post-metadata">

**Author:** ![zachary.whitley](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/zachary.whitley/32/94_2.png) [@zachary.whitley](https://community.stardog.com/u/zachary.whitley)\
**Post date:** [May 3, 2020, 7:07pm UTC](https://community.stardog.com/t/how-to-get-pystardog-to-construct-from-a-named-graph-with-virtual-transparency-on/2418/3 "2020-05-03T19:07:39Z")

</div>

I'm having a hard time following exactly what you did, what the expected out come was and what you result you actually got. Can you be a little more explicit about what exact queries you ran with what options. What version of Stardog are you running? Are there any errors or warnings in stardog.log?

---

<div class="post-metadata">

**Author:** ![Kevin\_Vanslette](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/kevin_vanslette/32/646_2.png) [@Kevin\_Vanslette](https://community.stardog.com/u/Kevin_Vanslette)\
**Post date:** [May 3, 2020, 7:23pm UTC](https://community.stardog.com/t/how-to-get-pystardog-to-construct-from-a-named-graph-with-virtual-transparency-on/2418/4 "2020-05-03T19:23:48Z")

</div>

Okay.... I guess I solved it...? I turned virtual transparency to false and I was able to query in pystardog without changing anything else. Is this truly the desired functionality of virtual transparency = true? Shouldn't the logic be to check if a call has been constrained to query from a particular graph rather than querying from all of the transparent virtual graphs first? If virtual transparency is on, shouldn't there be a way to override this in the sparql query?

---

<div class="post-metadata">

**Author:** ![zachary.whitley](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/zachary.whitley/32/94_2.png) [@zachary.whitley](https://community.stardog.com/u/zachary.whitley)\
**Post date:** [May 3, 2020, 7:44pm UTC](https://community.stardog.com/t/how-to-get-pystardog-to-construct-from-a-named-graph-with-virtual-transparency-on/2418/5 "2020-05-03T19:44:27Z")

</div>

> [@Kevin\_Vanslette](#):
>
> Is this truly the desired functionality of virtual transparency = true?

What exact functionality are you referring to? I'm still having difficulty following your description of the problem. It would help if you could expand on what "this" is in your question. There should be no difference between a query in Studio and a query in pystardog so I would not characterize the difference as the desired functionality of the virtual transparency feature. It's more likely a problem with either the way you're using pystardog or pystardog itself.

---

<div class="post-metadata">

**Author:** ![Kevin\_Vanslette](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/kevin_vanslette/32/646_2.png) [@Kevin\_Vanslette](https://community.stardog.com/u/Kevin_Vanslette)\
**Post date:** [May 4, 2020, 12:30pm UTC](https://community.stardog.com/t/how-to-get-pystardog-to-construct-from-a-named-graph-with-virtual-transparency-on/2418/6 "2020-05-04T12:30:46Z")

</div>

I turned virtual transparency to false and I was able to query [the named graph directly] in pystardog without changing anything else.

hope that helps!

---

<div class="post-metadata">

**Author:** ![Kevin\_Vanslette](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/kevin_vanslette/32/646_2.png) [@Kevin\_Vanslette](https://community.stardog.com/u/Kevin_Vanslette)\
**Post date:** [May 4, 2020, 3:47pm UTC](https://community.stardog.com/t/how-to-get-pystardog-to-construct-from-a-named-graph-with-virtual-transparency-on/2418/7 "2020-05-04T15:47:17Z")

</div>

Hi All,

I am continuing this post. I really need to have virtual transparency on but there is no way to change the query plan from pystardog such that pystardog queries straight from the specified named graph urn:foo instead of querying through the virtual graphs and ignoring the named graph completely. Studio has this capability because one may change the query plan with the gui:

 ![image](https://canada1.discourse-cdn.com/flex030/uploads/stardog/original/1X/da783515e71d0eeda59646a3b6fecbc8a059631d.png)

---

<div class="post-metadata">

**Author:** ![zachary.whitley](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/zachary.whitley/32/94_2.png) [@zachary.whitley](https://community.stardog.com/u/zachary.whitley)\
**Post date:** [May 4, 2020, 6:07pm UTC](https://community.stardog.com/t/how-to-get-pystardog-to-construct-from-a-named-graph-with-virtual-transparency-on/2418/8 "2020-05-04T18:07:09Z")

</div>

I think it would be more helpful if you explained what you want to do and how what you're seeing differs from what you expect. It's probably just casual use of the term query plan but Studio is changing the query which changes the query plan to match but there isn't a way to modify the query plan directly.

If I understand your question correctly I have I related question. How does virtual transparency interact with the use of FROM and FROM NAMED. My expectation would be that the use of a FROM clause overrides virtual transparency and effectively turns that feature off for that query but that's just conjecture. Have you tried including a FROM NAMED clause in your query?

I've always found the use of FROM and FROM NAMED a little confusing especially when you combine it with query.all.graphs. ex. FROM overrides the default graph. If you have just a FROM NAMED what is the default graph? empty? same as it was before? I think it's empty but I'm never confident about that answer.

---

<div class="post-metadata">

**Author:** ![PaulJackson](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/pauljackson/32/243_2.png) [@PaulJackson](https://community.stardog.com/u/PaulJackson)\
**Post date:** [May 4, 2020, 8:02pm UTC](https://community.stardog.com/t/how-to-get-pystardog-to-construct-from-a-named-graph-with-virtual-transparency-on/2418/9 "2020-05-04T20:02:57Z")

</div>

Kevin,

I am able to reproduce an issue (returning no results) using a CONSTRUCT query and two variable predicates (`?p` and ?p2) joined. If I turn on VT then I get results. If I modify the query like this:

```auto
CONSTRUCT {    
GRAPH <urn:foo> {
?s ?p ?o.
?s2 ?p2 ?o2.
}}
FROM <virtual://theVg>
WHERE{
?s :predefined_predicate ?s2.
?s ?p ?o.
?s2 ?p2 ?o2.
}

```

or

```auto
CONSTRUCT {    
GRAPH <urn:foo> {
?s ?p ?o.
?s2 ?p2 ?o2.
}}
WHERE{
    GRAPH <virtual://theVg> {
       ?s :predefined_predicate ?s2.
       ?s ?p ?o.
       ?s2 ?p2 ?o2.
    }
}

```

I also do not get results. I'm looking into a fix now.

I'm not clear on what feature is available in Studio that isn't in pystardog. The drop-down with the named graphs is equivalent to including `FROM NAMED` in your query. Are you saying you need pystardog to support that in the API?

-Paul

---

<div class="post-metadata">

**Author:** ![Kevin\_Vanslette](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/kevin_vanslette/32/646_2.png) [@Kevin\_Vanslette](https://community.stardog.com/u/Kevin_Vanslette)\
**Post date:** [May 4, 2020, 8:34pm UTC](https://community.stardog.com/t/how-to-get-pystardog-to-construct-from-a-named-graph-with-virtual-transparency-on/2418/10 "2020-05-04T20:34:51Z")

</div>

I don't know if this helps, but here is my situation:

I have a db that I created with virtual transparency on. I then used that db and some virtual graphs to hit a postgres db and constructed a named graph, urn:foo.

I would then like to perform a construct (or select) query on the named graph I created \*without instantiating the virtual graphs as they would hit the postgres db again. If i write the call

```
CONSTRUCT {    
GRAPH <urn:foo> {
?s ?p ?o.
?s2 ?p2 ?o2.
}}
WHERE{
?s :predefined_predicate ?s2.
?s ?p ?o.
?s2 ?p2 ?o2.

} 

```

and click show plan

 ![image](https://canada1.discourse-cdn.com/flex030/uploads/stardog/original/1X/a625e911aa395396f28a0f1dbd31e77642d7cfa3.png)

then there is a simple query plan that hits the named graph.

If instead I do not have urn:foo selected (i.e i put it on ...context:all) and show plan, then it involves unions of the vgs because vg transparency is on. The query plan does not change in this case if I use FROM NAMED urn:foo or GRAPH urn:foo (seemingly) anywhere in the sparql body, which seems at odds with

> [@PaulJackson](#):
>
> is equivalent to including `FROM NAMED` in your query

Do you see a similar issue?

---

<div class="post-metadata">

**Author:** ![Kevin\_Vanslette](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/kevin_vanslette/32/646_2.png) [@Kevin\_Vanslette](https://community.stardog.com/u/Kevin_Vanslette)\
**Post date:** [May 18, 2020, 6:06pm UTC](https://community.stardog.com/t/how-to-get-pystardog-to-construct-from-a-named-graph-with-virtual-transparency-on/2418/11 "2020-05-18T18:06:45Z")

</div>

Are there any updates on the above post?

Also:

> [@PaulJackson](#):
>
> I'm not clear on what feature is available in Studio that isn't in pystardog.

The feature that seemingly available in studio is to bypass the virtual graphs (while virtual transparency is on) and query a named graph directly (as could be seen from the query plan) while pystardog seems to always go through the virtual graphs when virtual transparency is on even knowing they are not needed (in my case) to query the named graph.

---

<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:** [May 18, 2020, 6:27pm UTC](https://community.stardog.com/t/how-to-get-pystardog-to-construct-from-a-named-graph-with-virtual-transparency-on/2418/12 "2020-05-18T18:27:45Z")

</div>

Paul, I think that we had an error in our query and are testing a solution now.

Will let you know....

Andrea

---

<div class="post-metadata">

**Author:** ![PaulJackson](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/pauljackson/32/243_2.png) [@PaulJackson](https://community.stardog.com/u/PaulJackson)\
**Post date:** [May 21, 2020, 1:05pm UTC](https://community.stardog.com/t/how-to-get-pystardog-to-construct-from-a-named-graph-with-virtual-transparency-on/2418/13 "2020-05-21T13:05:19Z")

</div>

Hi Kevin,

Just saw this.

The named graph `<tag:stardog:api:context:local>` can be used to prevent queries from accessing virtual graphs.

It doesn't look like pystardog exposes the option to set the dataset.  
I'm looking at `https://pystardog.readthedocs.io/en/latest/source/stardog.html#stardog.connection.Connection.select` and there should be a couple options for setting the `default-graph-uri` and `named-graph-uri`. I'll create a ticket for that.

-Paul

---

<div class="post-metadata">

**Author:** ![Kevin\_Vanslette](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/kevin_vanslette/32/646_2.png) [@Kevin\_Vanslette](https://community.stardog.com/u/Kevin_Vanslette)\
**Post date:** [May 21, 2020, 2:40pm UTC](https://community.stardog.com/t/how-to-get-pystardog-to-construct-from-a-named-graph-with-virtual-transparency-on/2418/14 "2020-05-21T14:40:27Z")

</div>

Thanks Paul, this is great.

It may make sense to add a similar ticket for connection.graph in case one is interested in constructing named subgraphs from a named graph.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex030/uploads/stardog/original/2X/e/ed66b48a616f505106a4acde3c9cee7e6da9bc67.svg) [@system](https://community.stardog.com/u/system)\
**Post date:** [June 4, 2020, 2:40pm UTC](https://community.stardog.com/t/how-to-get-pystardog-to-construct-from-a-named-graph-with-virtual-transparency-on/2418/15 "2020-06-04T14:40:32Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
