0

I am facing a weird problem using SPARQL. This piece of code is working fine on QConsole -

xquery version "1.0-ml";
import module namespace sem = "http://marklogic.com/semantics" at "/MarkLogic/semantics.xqy";

declare function local:forex-series (
    $from-currency-id as xs:string,
    $to-currency-id as xs:string,
    $forex-supplier-id as xs:string,
    $feed-name-id as xs:string
)
{
    let $map := map:map()
    let $series-sparql := 'PREFIX series: <http://iddn.icis.com/series/>
                    PREFIX predicates: <http://iddn.icis.com/predicates/>
                    PREFIX xmls: <http://www.w3.org/2001/XMLSchema#>

                    SELECT ?series
                    WHERE {
                      ?series predicates:to-currency $toCurrencyId ;
                              predicates:from-currency $fromCurrencyId ;
                              predicates:forex-provider $forexSupplierId ;
                              predicates:forex-feed $feedNameId ;
                    }'
    let $_ := map:put($map, "toCurrencyId", sem:iri($to-currency-id))
    let $_ := map:put($map, "fromCurrencyId", sem:iri($from-currency-id))
    let $_ := map:put($map, "forexSupplierId", sem:iri($forex-supplier-id))
    let $_ := map:put($map, "feedNameId", sem:iri($feed-name-id))
        return
            sem:query-results-serialize(sem:sparql($series-sparql, $map))
};

let $to-currency-id := "http://iddn.icis.com/ref-data/currency/10"
let $from-currency-id := "http://iddn.icis.com/ref-data/currency/18"
let $forex-supplier-id := "http://iddn.icis.com/asset/forex/xe"
let $feed-name-id := "http://iddn.icis.com/asset/forex/current"
return local:forex-series($from-currency-id, $to-currency-id, $forex-supplier-id, $feed-name-id)

But it is not working properly when added into the XQuery development code and deployed into modules. sem:sparql doesn't return anything in that case.

Is there any setting which needs to be done? Or am I missing something? Thoughts on this please!

Ankit Bhardwaj
  • 754
  • 8
  • 27
  • Does the SPARQL query itself return the expected results? – UninformedUser May 30 '16 at 05:50
  • Yes, it does. Even this code when executed from QConsole works fine. It is only behaving in unexpected manner when run with the deployed code. – Ankit Bhardwaj May 30 '16 at 06:01
  • Is the module running agains the same database you are using in query console? You can also set the triples the query is being executed against using the `$store` option that takes a list of in-nemory triple stores. – scotthenninger May 30 '16 at 13:05
  • There is some problem with the privileges. Apart from sparql and sparql update privilege, I need to add any other? – Ankit Bhardwaj May 30 '16 at 13:23

1 Answers1

1

Please keep in mind that triples are documents and follow the same security as other documents.

So, are you sure that you have the right to read the documents what include the triples?

Example: Are you using admin in the query console and a different user for the code run in other ways?

  • Thanks David, This part I also figured out that problem is because of different user. I just need know which particular privilege or role do I need to assign to the user in order to be able to use this? – Ankit Bhardwaj May 31 '16 at 06:34
  • 1
    Your user needs a role that has read permission on the triple documents. I think that is controlled via graph permissions, see also http://docs.marklogic.com/sem:graph-set-permissions.. – grtjn May 31 '16 at 07:30
  • You do not describe how your triples are stored. It also depends on how you store your triples. Unmanaged (embedded) triples mean that you at least need read rights on the document for which the triples are embedded. – David Ennis -CleverLlamas.com May 31 '16 at 08:04