Skip to content

GH-2979 Allow query explanation via REST API #5312

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

odysa
Copy link

@odysa odysa commented Apr 19, 2025

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):

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

@odysa odysa force-pushed the feat/explain-api branch 2 times, most recently from 99edfc9 to 143ce8e Compare April 19, 2025 01:02
@odysa odysa force-pushed the feat/explain-api branch 4 times, most recently from c0e40c4 to 1ab08af Compare April 30, 2025 04:26
@hmottestad
Copy link
Contributor

Does this in any way allow a remote repo (HTTPRepository) to use the existing query explanation method on a query object and retrieve the explanation from the remote server?

@odysa
Copy link
Author

odysa commented May 4, 2025

Does this in any way allow a remote repo (HTTPRepository) to use the existing query explanation method on a query object and retrieve the explanation from the remote server?

@hmottestad I think answer is yes. Add a method in RDF4JProtocolSession to send request to the remote server. Just like this.

public void getRepositoryList(TupleQueryResultHandler handler) throws IOException, TupleQueryResultHandlerException,
RepositoryException, UnauthorizedException, QueryInterruptedException {
checkServerURL();
HttpGet method = applyAdditionalHeaders(new HttpGet(Protocol.getRepositoriesLocation(serverURL)));
try {
getTupleQueryResult(method, handler);
} catch (MalformedQueryException e) {
// This shouldn't happen as no queries are involved
logger.warn("Server reported unexpected malfored query error", e);
throw new RepositoryException(e.getMessage(), e);
} finally {
method.reset();
}
}

@hmottestad
Copy link
Contributor

Serialisation would be the main issue then I guess.

Let me just have a little think to see if there could be any potential issues down the line.

@odysa odysa force-pushed the feat/explain-api branch 4 times, most recently from f6d9d9b to eaddc96 Compare May 7, 2025 22:04
@odysa odysa force-pushed the feat/explain-api branch from eaddc96 to c03814d Compare May 13, 2025 03:32
@odysa odysa changed the title GH-2979 Allow query explanation via HTTPRepository / REST API GH-2979 Allow query explanation via REST API May 14, 2025
@odysa odysa requested a review from hmottestad May 14, 2025 01:46
@odysa
Copy link
Author

odysa commented May 14, 2025

@hmottestad Hey, let's only include the rest api in this PR. I will have some future work on HttpRepo and workbench to utilize this api.

@hmottestad
Copy link
Contributor

Code looks good! Thanks!

The final thing I need to do is test this locally just to see how it looks.

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

Successfully merging this pull request may close these issues.

2 participants