rdf4j icon indicating copy to clipboard operation
rdf4j copied to clipboard

Allow query explanation via HTTPRepository / REST API

Open abrokenjester opened this issue 4 years ago • 8 comments

The query explain feature (see GH-2044) should be extended to allow use over HTTP. This will enable using it in the HTTPRepository as well as in any non-Java environment that communicates via the REST API.

abrokenjester avatar Apr 09 '21 04:04 abrokenjester

@hmottestad @kenwenzel Hello, I am interested in this feature and would like to contribute. If RDF4J maintainers still want this rest API, I am happy to discuss api design with you

odysa avatar Apr 07 '25 19:04 odysa

That would be very welcome from our side.

https://rdf4j.org/documentation/reference/rest-api/

Here is the API docs that we have. Did you already have an idea for how to extend it to support query explanation?

hmottestad avatar Apr 08 '25 04:04 hmottestad

Add POST Request /repositories/{repository_id}/explain

Request Body:

{
  "query": "SELECT * WHERE {?S ?O ?P}",
  "level": "Timed"
}

Response:

{
  "explain": ".........."
}

Core Logic:

try (final RepositoryConnection connection = RepositoryInterceptor.getRepositoryConnection()) {
    final Explanation explanation = connection.prepareQuery(query).explain(level);
}

Optionally, we may integrate explain into the Workbench UI to enhance user interaction.

odysa avatar Apr 08 '25 15:04 odysa

@hmottestad @kenwenzel would you prefer extending the sparql to do smth like

EXPLAIN [with limit] SPARQL

or try and do it through custom functions?

nguyenm100 avatar Apr 19 '25 11:04 nguyenm100

Neptune uses an additional HTTP Parameter: https://docs.aws.amazon.com/neptune/latest/userguide/sparql-explain-using.html

Maybe this is also something that we could do?

kenwenzel avatar Apr 20 '25 05:04 kenwenzel

@kenwenzel Good idea. If I understand correctly, we will use the existing SPARQL execution endpoints. If explain=mode is passed, it does query explanation, otherwise, execute this query.

odysa avatar Apr 27 '25 17:04 odysa

@odysa Yes, this is how I understand it, too.

kenwenzel avatar Apr 28 '25 08:04 kenwenzel

#5312 good for review

odysa avatar Apr 30 '25 14:04 odysa