Skip to content
This repository has been archived by the owner on Nov 9, 2022. It is now read-only.

Allow running SPARQL and maybe SQL using execute_query #869

Open
grtjn opened this issue Jan 10, 2018 · 5 comments
Open

Allow running SPARQL and maybe SQL using execute_query #869

grtjn opened this issue Jan 10, 2018 · 5 comments

Comments

@grtjn
Copy link
Contributor

grtjn commented Jan 10, 2018

See also #821

@rhdunn
Copy link
Contributor

rhdunn commented Jan 10, 2018

I have been using:

import module namespace sem = "http://marklogic.com/semantics" at "/MarkLogic/semantics.xqy";
let $query := "$QUERY_STRING"
let $vars := ()
let $options := $OPTIONS
return try {
  let $ret     := $FUNCTION
  let $triples := for $item in $ret where $item instance of sem:triple return $item
  let $other   := for $item in $ret where not($item instance of sem:triple) return $item
  return if (count($triples) > 0) then
    let $fmt := sem:rdf-serialize($triples, "$TRIPLE_FORMAT")
    let $_ := xdmp:add-response-header("X-Content-Type", "$CONTENT_TYPE")
    return ($fmt, $other)
  else
    $ret
} catch ($e) { $e }

to run SPARQL queries in a plugin of mine, replacing $FUNCTION, etc. with string replacement logic.

@rhdunn
Copy link
Contributor

rhdunn commented Jan 10, 2018

X-Content-Type is used because setting Content-Type changes the multipart content type and breaks things. This could be removed for the roxy version. $FUNCTION is the appropriate invoke/eval function, allowing support for profiling and debugging.

@grtjn
Copy link
Contributor Author

grtjn commented Jan 10, 2018

I had in mind using /v1/graph/sparql. Would sending your code to /v1/eval provide more possibilities?

@rhdunn
Copy link
Contributor

rhdunn commented Jan 10, 2018

Using /v1/graph/sparql is probably better for roxy. I'm using eval to make use of things like better exception reporting, profiling, and debugging if available.

@grtjn
Copy link
Contributor Author

grtjn commented Jan 10, 2018

Thanks for sharing though, appreciated!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants