# Odd result with short form construct query

**URL:** <https://community.stardog.com/t/odd-result-with-short-form-construct-query/1224>\
**Category:** Support\
**Created:** [August 13, 2018, 10:01pm UTC](https://community.stardog.com/t/odd-result-with-short-form-construct-query/1224 "2018-08-13T22:01:29Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![bkm](https://avatars.discourse-cdn.com/v4/letter/b/ecccb3/32.png) [@bkm](https://community.stardog.com/u/bkm)\
**Post date:** [August 13, 2018, 10:01pm UTC](https://community.stardog.com/t/odd-result-with-short-form-construct-query/1224/1 "2018-08-13T22:01:29Z")

</div>

Hi,  
I don’t know if this is a bug or if I just don’t properly understand how to use CONSTRUCT queries. I have a database that includes these triples (among many others)

```auto
<http://stjohns.edu/fullclinicaltrial/NCT01661400> <http://stjohns.edu/fullclinicaltrial/hasNCT> "NCT01661400" .
<http://stjohns.edu/fullclinicaltrial/NCT01661400> <http://stjohns.edu/fullclinicaltrial/hasPrimaryOutcome> <http://stjohns.edu/fullclinicaltrial/NCT01661400PrimaryOutcome1> .
<http://stjohns.edu/fullclinicaltrial/NCT01661400> <http://stjohns.edu/fullclinicaltrial/hasPrimaryOutcome> <http://stjohns.edu/fullclinicaltrial/NCT01661400PrimaryOutcome2> .
<http://stjohns.edu/fullclinicaltrial/NCT01661400> <http://stjohns.edu/fullclinicaltrial/hasSecondaryOutcome> <http://stjohns.edu/fullclinicaltrial/NCT01661400SecondaryOutcome1> .
<http://stjohns.edu/fullclinicaltrial/NCT01661400> <http://stjohns.edu/fullclinicaltrial/hasSecondaryOutcome> <http://stjohns.edu/fullclinicaltrial/NCT01661400SecondaryOutcome2> .

```

When I run this query

```auto
construct where {
                  ?t fct:hasNCT "NCT01661400". 
                  ?t fct:hasPrimaryOutcome ?pout.       
                  ?t fct:hasSecondaryOutcome ?sout.
}

```

I get this odd result

```auto
<http://stjohns.edu/fullclinicaltrial/NCT01661400> <http://stjohns.edu/fullclinicaltrial/hasNCT> "NCT01661400" .
<http://stjohns.edu/fullclinicaltrial/NCT01661400> <http://stjohns.edu/fullclinicaltrial/hasPrimaryOutcome> <http://stjohns.edu/fullclinicaltrial/NCT01661400PrimaryOutcome1> .
<http://stjohns.edu/fullclinicaltrial/NCT01661400> <http://stjohns.edu/fullclinicaltrial/hasSecondaryOutcome> <http://stjohns.edu/fullclinicaltrial/NCT01661400SecondaryOutcome1> .
<http://stjohns.edu/fullclinicaltrial/NCT01661400> <http://stjohns.edu/fullclinicaltrial/hasPrimaryOutcome> <http://stjohns.edu/fullclinicaltrial/NCT01661400PrimaryOutcome2> .
<http://stjohns.edu/fullclinicaltrial/NCT01661400> <http://stjohns.edu/fullclinicaltrial/hasPrimaryOutcome> <http://stjohns.edu/fullclinicaltrial/NCT01661400PrimaryOutcome1> .
<http://stjohns.edu/fullclinicaltrial/NCT01661400> <http://stjohns.edu/fullclinicaltrial/hasSecondaryOutcome> <http://stjohns.edu/fullclinicaltrial/NCT01661400SecondaryOutcome2> .
<http://stjohns.edu/fullclinicaltrial/NCT01661400> <http://stjohns.edu/fullclinicaltrial/hasPrimaryOutcome> <http://stjohns.edu/fullclinicaltrial/NCT01661400PrimaryOutcome2> .

```

PrimaryOutcome1 and 2 are listed twice.

If I run this query

```auto
construct {
                ?t fct:hasPrimaryOutcome ?pout.       
                ?t fct:hasSecondaryOutcome ?sout.}
where {
                ?t fct:hasNCT "NCT01661400". 
                ?t fct:hasPrimaryOutcome ?pout.       
                ?t fct:hasSecondaryOutcome ?sout.
}

```

then I get

```auto
<http://stjohns.edu/fullclinicaltrial/NCT01661400> <http://stjohns.edu/fullclinicaltrial/hasSecondaryOutcome> <http://stjohns.edu/fullclinicaltrial/NCT01661400SecondaryOutcome1> .
<http://stjohns.edu/fullclinicaltrial/NCT01661400> <http://stjohns.edu/fullclinicaltrial/hasPrimaryOutcome> <http://stjohns.edu/fullclinicaltrial/NCT01661400PrimaryOutcome2> .
<http://stjohns.edu/fullclinicaltrial/NCT01661400> <http://stjohns.edu/fullclinicaltrial/hasSecondaryOutcome> <http://stjohns.edu/fullclinicaltrial/NCT01661400SecondaryOutcome2> .

```

with no repetition, which is what I expect given the data.

What am I doing wrong?

---

<div class="post-metadata">

**Author:** ![lorenz\_b](https://avatars.discourse-cdn.com/v4/letter/l/d78d45/32.png) [@lorenz\_b](https://community.stardog.com/u/lorenz_b)\
**Post date:** [August 14, 2018, 7:27am UTC](https://community.stardog.com/t/odd-result-with-short-form-construct-query/1224/2 "2018-08-14T07:27:47Z")

</div>

You’re doing nothing wrong. Given that the result of a `CONSTRUCT` query is in fact an RDF graph resp. a set of RDF triples, it’s simply a bug to get duplicate triples as result.

---

<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:** [August 14, 2018, 7:38am UTC](https://community.stardog.com/t/odd-result-with-short-form-construct-query/1224/3 "2018-08-14T07:38:58Z")

</div>

In fact, CONSTRUCT in SPARQL does _not_ guarantee that there will be no duplicate triples in the result (in spite of RDF being defined as a set of triples). This is fairly counterintuitive and caused some pretty lengthy discussions on W3C mailing lists during the original standardization process. Please see here:

[https://lists.w3.org/Archives/Public/public-rdf-dawg/2007OctDec/0030.html](https://lists.w3.org/Archives/Public/public-rdf-dawg/2007OctDec/0030.html)

Stardog applies a kind of a `REDUCED` filter to prune out some duplicates but there're no guarantees either. We have an open ticket #5681 to substantially improve it.

We'll also look at this example specifically to make sure there's no separate bug. However, in general, an application cannot assume that CONSTRUCT result sets are duplicate-free.

Cheers,  
Pavel

---

<div class="post-metadata">

**Author:** ![bkm](https://avatars.discourse-cdn.com/v4/letter/b/ecccb3/32.png) [@bkm](https://community.stardog.com/u/bkm)\
**Post date:** [August 14, 2018, 7:42pm UTC](https://community.stardog.com/t/odd-result-with-short-form-construct-query/1224/4 "2018-08-14T19:42:55Z")

</div>

OK, interesting. I am new to Sparql so I did not realize this is an issue. I am using the short form mainly because the query specifies a large graph (my examples pruned out most of it) and is really ugly if I have to include it both in the construct clause and the where clause. Thanks

---

<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:** [August 16, 2018, 7:54am UTC](https://community.stardog.com/t/odd-result-with-short-form-construct-query/1224/5 "2018-08-16T07:54:11Z")

</div>

Hi Bonnie,

Which version of Stardog do you use? I get the same results (with duplicates) for both versions of the query using 5.3.3.

I don’t have an explanation why PrimaryOutcome1 isn’t returned for you for your 2nd query, looks like differences in the data.

Thanks,  
Pavel

---

<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:** [August 30, 2018, 7:54am UTC](https://community.stardog.com/t/odd-result-with-short-form-construct-query/1224/6 "2018-08-30T07:54:16Z")

</div>

Closed on August 30, 2018, 7:54am UTC

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