rdf4j icon indicating copy to clipboard operation
rdf4j copied to clipboard

GH-2979 Allow query explanation via REST API

Open odysa opened this issue 6 months ago • 5 comments

GitHub issue resolved: #

#2979

Briefly describe the changes proposed in this PR:

Add an additional parameter to the query endpoint. If parm explain is present, don't execute the query and return the query explaination instead.

Currently only supports Text and Json response format.

Requst to return Json

curl -G 'http://localhost:8080/rdf4j-server/repositories/testrepo' \
           --data-urlencode 'explain=Timed' \
           --data-urlencode 'query=SELECT * WHERE { ?s ?p ?o }' \
           -H 'Accept:application/json'
{
  "type" : "StatementPattern",
  "resultSizeEstimate" : 0.0,
  "resultSizeActual" : 0,
  "totalTimeActual" : 0.005417,
  "plans" : [ {
    "type" : "Var (name=s)"
  }, {
    "type" : "Var (name=p)"
  }, {
    "type" : "Var (name=o)"
  } ],
  "selfTimeActual" : 0.005417
}

Request to return plain text

curl -G 'http://localhost:8080/rdf4j-server/repositories/testrepo' \
           --data-urlencode 'explain=Timed' \
           --data-urlencode 'query=SELECT * WHERE { ?s ?p ?o }' \
           -H 'Accept: text/plain'
StatementPattern (resultSizeEstimate=0, resultSizeActual=0, totalTimeActual=0.004ms, selfTimeActual=0.004ms)
   s: Var (name=s)
   p: Var (name=p)
   o: Var (name=o)

PR Author Checklist (see the contributor guidelines for more details):

  • [x] my pull request is self-contained
  • [x] I've added tests for the changes I made
  • [x] I've applied code formatting (you can use mvn process-resources to format from the command line)
  • [x] I've squashed my commits where necessary
  • [x] every commit message starts with the issue number (GH-xxxx) followed by a meaningful description of the change

odysa avatar Apr 19 '25 00:04 odysa