# Federated query issue

**URL:** <https://community.stardog.com/t/federated-query-issue/1485>\
**Category:** Bug\
**Created:** [February 19, 2019, 2:53pm UTC](https://community.stardog.com/t/federated-query-issue/1485 "2019-02-19T14:53:15Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![nicky508](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/nicky508/32/102_2.png) [@nicky508](https://community.stardog.com/u/nicky508)\
**Post date:** [February 19, 2019, 2:53pm UTC](https://community.stardog.com/t/federated-query-issue/1485/1 "2019-02-19T14:53:15Z")

</div>

Dear,

We have encountered a issue within the federated queries of Stardog. We have a stardog instance on which we execute a federated query via Stardog Studio.

The Query:

> SELECT \*  
> WHERE {  
> SERVICE [https://data.pdok.nl/sparql](https://data.pdok.nl/sparql) {  
> ?vbo [http://bag.basisregistraties.overheid.nl/def/bag#identificatiecode](http://bag.basisregistraties.overheid.nl/def/bag#identificatiecode) "0758010000090558" .  
> }  
> }

When we run the query we got the following error:

> ERROR 2019-02-19 14:04:31,121 [stardog-user-1] com.complexible.stardog.protocols.http.server.StardogHttpServiceLoader:accept(235): An unexpected exception was handled by the server  
> com.stardog.stark.query.QueryExecutionFailure: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; Content is not allowed in prolog. [L1:1]  
> at com.complexible.common.rdf.query.IteratorAsTupleQueryResult.hasNext(IteratorAsTupleQueryResult.java:82) ~[stardog-utils-rdf-6.1.0.jar:?]  
> at com.stardog.stark.query.ClosingSpliterator.forEachRemaining(ClosingSpliterator.java:37) ~[stardog-stark-query-api-6.1.0.jar:?]  
> at java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:580) ~[?:1.8.0\_191]  
> at com.stardog.stark.query.io.QueryResultWriters.write(QueryResultWriters.java:142) ~[stardog-stark-query-io-6.1.0.jar:?]  
> at com.stardog.stark.query.io.QueryResultWriters.write(QueryResultWriters.java:127) ~[stardog-stark-query-io-6.1.0.jar:?]  
> at com.complexible.stardog.protocols.http.server.ProtocolUtils.writeTupleResponse(ProtocolUtils.java:579) ~[stardog-protocols-http-server-6.1.0.jar:?]  
> at com.complexible.stardog.protocols.http.server.ProtocolUtils.executeReadQuery(ProtocolUtils.java:489) ~[stardog-protocols-http-server-6.1.0.jar:?]  
> at com.complexible.stardog.protocols.http.server.ProtocolUtils.executeReadQuery(ProtocolUtils.java:474) ~[stardog-protocols-http-server-6.1.0.jar:?]  
> at com.complexible.stardog.protocols.http.server.SPARQLProtocol.executeQuery(SPARQLProtocol.java:127) ~[stardog-protocols-http-server-6.1.0.jar:?]  
> at com.complexible.stardog.protocols.http.server.SPARQLProtocol.post(SPARQLProtocol.java:91) ~[stardog-protocols-http-server-6.1.0.jar:?]  
> at com.stardog.http.server.undertow.jaxrs.ExtractRoutes.lambda$handleIt$5(ExtractRoutes.java:192) ~[stardog-protocols-http-server-6.1.0.jar:?]  
> at org.apache.shiro.subject.support.SubjectRunnable.doRun(SubjectRunnable.java:120) [shiro-core-1.2.3.jar:1.2.3]  
> at org.apache.shiro.subject.support.SubjectRunnable.run(SubjectRunnable.java:108) [shiro-core-1.2.3.jar:1.2.3]  
> at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:1.8.0\_191]  
> at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:1.8.0\_191]  
> at java.lang.Thread.run(Thread.java:748) [?:1.8.0\_191]  
> Caused by: com.complexible.stardog.plan.eval.operator.OperatorException: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; Content is not allowed in prolog. [L1:1]  
> at com.complexible.stardog.plan.eval.service.SPARQLService$SparqlServiceQuery.evaluateBatch(SPARQLService.java:131) ~[stardog-6.1.0.jar:?]  
> at com.complexible.stardog.plan.eval.service.BatchingJoinArgServiceQuery.evaluate(BatchingJoinArgServiceQuery.java:59) ~[stardog-6.1.0.jar:?]  
> at com.complexible.stardog.plan.eval.operator.impl.ServiceOperatorImpl.computeNext(ServiceOperatorImpl.java:83) ~[stardog-6.1.0.jar:?]  
> at com.complexible.stardog.plan.eval.operator.impl.ServiceOperatorImpl.computeNext(ServiceOperatorImpl.java:34) ~[stardog-6.1.0.jar:?]  
> at com.complexible.common.collect.AbstractSkippingIterator.tryToComputeNext(AbstractSkippingIterator.java:143) ~[stardog-utils-common-6.1.0.jar:?]  
> at com.complexible.common.collect.AbstractSkippingIterator.hasNext(AbstractSkippingIterator.java:130) ~[stardog-utils-common-6.1.0.jar:?]  
> at com.complexible.stardog.plan.eval.operator.impl.SingleProjectionOp.computeNext(SingleProjectionOp.java:82) ~[stardog-6.1.0.jar:?]  
> at com.complexible.stardog.plan.eval.operator.impl.SingleProjectionOp.computeNext(SingleProjectionOp.java:29) ~[stardog-6.1.0.jar:?]  
> at com.complexible.common.collect.AbstractSkippingIterator.tryToComputeNext(AbstractSkippingIterator.java:143) ~[stardog-utils-common-6.1.0.jar:?]  
> at com.complexible.common.collect.AbstractSkippingIterator.hasNext(AbstractSkippingIterator.java:130) ~[stardog-utils-common-6.1.0.jar:?]  
> at com.complexible.stardog.plan.eval.operator.util.AutoCloseOperator.computeNext(AutoCloseOperator.java:112) ~[stardog-6.1.0.jar:?]  
> at com.complexible.stardog.plan.eval.operator.util.AutoCloseOperator.computeNext(AutoCloseOperator.java:25) ~[stardog-6.1.0.jar:?]  
> at com.complexible.common.collect.AbstractSkippingIterator.tryToComputeNext(AbstractSkippingIterator.java:143) ~[stardog-utils-common-6.1.0.jar:?]  
> at com.complexible.common.collect.AbstractSkippingIterator.hasNext(AbstractSkippingIterator.java:130) ~[stardog-utils-common-6.1.0.jar:?]  
> at com.complexible.stardog.plan.eval.operator.util.OpBasedBindingSetIteration.computeNext(OpBasedBindingSetIteration.java:116) ~[stardog-6.1.0.jar:?]  
> at com.complexible.stardog.plan.eval.operator.util.OpBasedBindingSetIteration.computeNext(OpBasedBindingSetIteration.java:39) ~[stardog-6.1.0.jar:?]  
> at com.google.common.collect.AbstractIterator.tryToComputeNext(AbstractIterator.java:141) ~[guava-26.0-jre.jar:?]  
> at com.google.common.collect.AbstractIterator.hasNext(AbstractIterator.java:136) ~[guava-26.0-jre.jar:?]  
> at com.complexible.common.rdf.query.IteratorAsTupleQueryResult.hasNext(IteratorAsTupleQueryResult.java:78) ~[stardog-utils-rdf-6.1.0.jar:?]  
> ... 15 more  
> Caused by: com.stardog.stark.query.io.InvalidQueryResults: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; Content is not allowed in prolog. [L1:1]  
> at com.stardog.stark.query.io.xml.SAXErrorHandler.fatalError(SAXErrorHandler.java:71) ~[stardog-stark-query-xml-6.1.0.jar:?]  
> at org.apache.xerces.util.ErrorHandlerWrapper.fatalError(Unknown Source) ~[xercesImpl-2.11.0.jar:?]  
> at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source) ~[xercesImpl-2.11.0.jar:?]  
> at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source) ~[xercesImpl-2.11.0.jar:?]  
> at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source) ~[xercesImpl-2.11.0.jar:?]  
> at org.apache.xerces.impl.XMLScanner.reportFatalError(Unknown Source) ~[xercesImpl-2.11.0.jar:?]  
> at org.apache.xerces.impl.XMLDocumentScannerImpl$PrologDispatcher.dispatch(Unknown Source) ~[xercesImpl-2.11.0.jar:?]  
> at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source) ~[xercesImpl-2.11.0.jar:?]  
> at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source) ~[xercesImpl-2.11.0.jar:?]  
> at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source) ~[xercesImpl-2.11.0.jar:?]  
> at org.apache.xerces.parsers.XMLParser.parse(Unknown Source) ~[xercesImpl-2.11.0.jar:?]  
> at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source) ~[xercesImpl-2.11.0.jar:?]  
> at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source) ~[xercesImpl-2.11.0.jar:?]  
> at com.stardog.stark.query.io.xml.SimpleSAXParser.parse(SimpleSAXParser.java:221) ~[stardog-stark-query-xml-6.1.0.jar:?]  
> at com.stardog.stark.query.io.xml.SimpleSAXParser.parse(SimpleSAXParser.java:196) ~[stardog-stark-query-xml-6.1.0.jar:?]  
> at com.stardog.stark.query.io.xml.SPARQLXMLSelectResultParser.parse(SPARQLXMLSelectResultParser.java:78) ~[stardog-stark-query-xml-6.1.0.jar:?]  
> at com.stardog.stark.query.io.xml.SPARQLXMLSelectResultParser.parse(SPARQLXMLSelectResultParser.java:37) ~[stardog-stark-query-xml-6.1.0.jar:?]  
> at com.stardog.stark.query.io.QueryResultParsers.read(QueryResultParsers.java:307) ~[stardog-stark-query-io-6.1.0.jar:?]  
> at com.stardog.stark.query.io.QueryResultParsers.readSelect(QueryResultParsers.java:146) ~[stardog-stark-query-io-6.1.0.jar:?]  
> at com.complexible.stardog.plan.eval.service.SPARQLService$SparqlServiceQuery.evaluateBatch(SPARQLService.java:124) ~[stardog-6.1.0.jar:?]  
> at com.complexible.stardog.plan.eval.service.BatchingJoinArgServiceQuery.evaluate(BatchingJoinArgServiceQuery.java:59) ~[stardog-6.1.0.jar:?]  
> at com.complexible.stardog.plan.eval.operator.impl.ServiceOperatorImpl.computeNext(ServiceOperatorImpl.java:83) ~[stardog-6.1.0.jar:?]  
> at com.complexible.stardog.plan.eval.operator.impl.ServiceOperatorImpl.computeNext(ServiceOperatorImpl.java:34) ~[stardog-6.1.0.jar:?]  
> at com.complexible.common.collect.AbstractSkippingIterator.tryToComputeNext(AbstractSkippingIterator.java:143) ~[stardog-utils-common-6.1.0.jar:?]  
> at com.complexible.common.collect.AbstractSkippingIterator.hasNext(AbstractSkippingIterator.java:130) ~[stardog-utils-common-6.1.0.jar:?]  
> at com.complexible.stardog.plan.eval.operator.impl.SingleProjectionOp.computeNext(SingleProjectionOp.java:82) ~[stardog-6.1.0.jar:?]  
> at com.complexible.stardog.plan.eval.operator.impl.SingleProjectionOp.computeNext(SingleProjectionOp.java:29) ~[stardog-6.1.0.jar:?]  
> at com.complexible.common.collect.AbstractSkippingIterator.tryToComputeNext(AbstractSkippingIterator.java:143) ~[stardog-utils-common-6.1.0.jar:?]  
> at com.complexible.common.collect.AbstractSkippingIterator.hasNext(AbstractSkippingIterator.java:130) ~[stardog-utils-common-6.1.0.jar:?]  
> at com.complexible.stardog.plan.eval.operator.util.AutoCloseOperator.computeNext(AutoCloseOperator.java:112) ~[stardog-6.1.0.jar:?]  
> at com.complexible.stardog.plan.eval.operator.util.AutoCloseOperator.computeNext(AutoCloseOperator.java:25) ~[stardog-6.1.0.jar:?]  
> at com.complexible.common.collect.AbstractSkippingIterator.tryToComputeNext(AbstractSkippingIterator.java:143) ~[stardog-utils-common-6.1.0.jar:?]  
> at com.complexible.common.collect.AbstractSkippingIterator.hasNext(AbstractSkippingIterator.java:130) ~[stardog-utils-common-6.1.0.jar:?]  
> at com.complexible.stardog.plan.eval.operator.util.OpBasedBindingSetIteration.computeNext(OpBasedBindingSetIteration.java:116) ~[stardog-6.1.0.jar:?]  
> at com.complexible.stardog.plan.eval.operator.util.OpBasedBindingSetIteration.computeNext(OpBasedBindingSetIteration.java:39) ~[stardog-6.1.0.jar:?]  
> at com.google.common.collect.AbstractIterator.tryToComputeNext(AbstractIterator.java:141) ~[guava-26.0-jre.jar:?]  
> at com.google.common.collect.AbstractIterator.hasNext(AbstractIterator.java:136) ~[guava-26.0-jre.jar:?]  
> at com.complexible.common.rdf.query.IteratorAsTupleQueryResult.hasNext(IteratorAsTupleQueryResult.java:78) ~[stardog-utils-rdf-6.1.0.jar:?]  
> ... 15 more

Our first thought would be that stardog expects XML but does not get XML and therefore encounters a SAX error.  
With help of a proxy we extracted following curl statement from stardog to the sparql endpoint:

> curl -X GET "[https://data.pdok.nl/sparql?query=SELECT+%3Fvbo+ WHERE+{ ++%3Fvbo+\<http%3A%2F%2Fbag.basisregistraties.overheid.nl%2Fdef%2Fbag%23identificatiecode\>+"0758010000090558" }&quot](https://data.pdok.nl/sparql?query=SELECT+%3Fvbo+%0AWHERE+%7B%0A++%3Fvbo+%3Chttp%3A%2F%2Fbag.basisregistraties.overheid.nl%2Fdef%2Fbag%23identificatiecode%3E+%220758010000090558%22%0A%7D&quot); -v -H "Accept: application/sparql-results+xml;q=0.9, application/sparql-results+json;q=0.9, text/csv;q=0.8, text/tab-separated-values;q=0.8, application/x-binary-rdf-results-table;q=0.8"

The curl statement return sparql results as json, which explains why stardog gives a SAX error.

We also tried a federated on wiki data. This works fine. If we do the same exercise we find that wikidata return sparql results as a xml. It seems that stardog does not process the results right, although the accept header contains sparql results in json.

---

<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:** [February 20, 2019, 4:08pm UTC](https://community.stardog.com/t/federated-query-issue/1485/2 "2019-02-20T16:08:13Z")

</div>

You might want to check your query. I get a malformed query response. I haven't had to unencoded it yet to see what the problem might be.

---

<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:** [February 20, 2019, 4:12pm UTC](https://community.stardog.com/t/federated-query-issue/1485/3 "2019-02-20T16:12:57Z")

</div>

The url encoding was a little off. This returns results. Give it a try

`curl -X GET "https://data.pdok.nl/sparql?query=SELECT%20%3Fvbo%20WHERE%20%7B%20%3Fvbo%20%3Chttp%3A%2F%2Fbag.basisregistraties.overheid.nl%2Fdef%2Fbag%23identificatiecode%3E%20%220758010000090558%22%20%7D%0A" -v -H "Accept: application/sparql-results+xml;q=0.9, application/sparql-results+json;q=0.9, text/csv;q=0.8, text/tab-separated-values;q=0.8, application/x-binary-rdf-results-table;q=0.8"`

---

<div class="post-metadata">

**Author:** ![stephen](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/stephen/32/27_2.png) [@stephen](https://community.stardog.com/u/stephen)\
**Post date:** [February 20, 2019, 5:29pm UTC](https://community.stardog.com/t/federated-query-issue/1485/4 "2019-02-20T17:29:36Z")

</div>

It is returning JSON results, but Stardog seems to be misinterpreting them. I will investigate further and report back here when I find something

---

<div class="post-metadata">

**Author:** ![nicky508](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/nicky508/32/102_2.png) [@nicky508](https://community.stardog.com/u/nicky508)\
**Post date:** [February 21, 2019, 8:35am UTC](https://community.stardog.com/t/federated-query-issue/1485/5 "2019-02-21T08:35:55Z")

</div>

@zachary.whitley The query does work, thats not the issue.

@stephen Thats exactly what we think as well. Thanks!

---

<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:** [February 21, 2019, 4:00pm UTC](https://community.stardog.com/t/federated-query-issue/1485/6 "2019-02-21T16:00:26Z")

</div>

Well you just must be super lucky because the query you supplied returns the following for me.

```
MALFORMED QUERY: Encountered "<EOF>" at line 1, column 12.
Was expecting one of:
    "(" ...
    "{" ...
```

---

<div class="post-metadata">

**Author:** ![stephen](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/stephen/32/27_2.png) [@stephen](https://community.stardog.com/u/stephen)\
**Post date:** [February 21, 2019, 4:32pm UTC](https://community.stardog.com/t/federated-query-issue/1485/7 "2019-02-21T16:32:23Z")

</div>

@zachary.whitley it was doing that for me as well until I removed the newlines. Probably some weird invisible characters coming over from discourse or something.

---

<div class="post-metadata">

**Author:** ![nicky508](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/nicky508/32/102_2.png) [@nicky508](https://community.stardog.com/u/nicky508)\
**Post date:** [February 22, 2019, 8:44am UTC](https://community.stardog.com/t/federated-query-issue/1485/8 "2019-02-22T08:44:59Z")

</div>

@zachary.whitley Uhmm, I see. Probably some copy paste thing....

---

<div class="post-metadata">

**Author:** ![stephen](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/stephen/32/27_2.png) [@stephen](https://community.stardog.com/u/stephen)\
**Post date:** [February 26, 2019, 2:06pm UTC](https://community.stardog.com/t/federated-query-issue/1485/9 "2019-02-26T14:06:54Z")

</div>

An update: We have discovered the root cause of this issue, and it will be fixed in the upcoming 6.1.2 release.

---

<div class="post-metadata">

**Author:** ![nicky508](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/nicky508/32/102_2.png) [@nicky508](https://community.stardog.com/u/nicky508)\
**Post date:** [March 7, 2019, 10:36am UTC](https://community.stardog.com/t/federated-query-issue/1485/10 "2019-03-07T10:36:36Z")

</div>

Thanks! Stephan for your help.
