Skip to content

Commit

Permalink
Clarification on remaining two TODOs
Browse files Browse the repository at this point in the history
  • Loading branch information
Hannah Bast committed Dec 14, 2024
1 parent 1b93334 commit bc03b70
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
9 changes: 7 additions & 2 deletions src/engine/Describe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ string Describe::getCacheKeyImpl() const {
// Add the names of the default graphs (from the FROM clauses) to the cache
// key, in a deterministic order.
//
// TODO: What about the FROM NAMED clauses?
// NOTE: The default and named graphs are also part of the cache key of the
// `subtree_`. However, the named graphs only determine the result for
// `subtree_` (the resouces to be described), whereas the default graphs

Check failure on line 51 in src/engine/Describe.cpp

View workflow job for this annotation

GitHub Actions / Check for spelling errors

resouces ==> resources
// also determine which triples for these resources become part of the result.
const auto& defaultGraphs = describe_.datasetClauses_.defaultGraphs_;
if (defaultGraphs.has_value()) {
std::vector<std::string> graphIdVec;
Expand Down Expand Up @@ -169,7 +172,9 @@ IdTable Describe::makeAndExecuteJoinWithFullIndex(
// Compute the result of the `join` and select the columns `?subject`,
// `?predicate`, `?object`.
//
// TODO: How can the `result` have more columns than those?
// NOTE: Typically, the join result has already those exact columns, in which
// case the `selectColumns` operation is a no-op. Note sure when this is not
// the case, but better safe than sorry.
auto result = join->getResult();
IdTable resultTable = result->idTable().clone();
ColumnIndex s = join->getVariableColumn(V{"?subject"});
Expand Down
25 changes: 16 additions & 9 deletions src/parser/sparqlParser/SparqlQleverVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,9 @@ ParsedQuery Visitor::visit(Parser::DescribeQueryContext* ctx) {
auto describeClause = parsedQuery::Describe{};
auto describedResources = visitVector(ctx->varOrIri());

std::vector<Variable> describedVariables;
// Convert the describe resources (variables or IRIs) from the format that the
// parser delivers to the one that the `Describe` struct expects.
// parser delivers to the one that the `parsedQuery::Describe` struct expects.
std::vector<Variable> describedVariables;
for (GraphTerm& resource : describedResources) {
if (std::holds_alternative<Variable>(resource)) {
const auto& variable = std::get<Variable>(resource);
Expand All @@ -300,13 +300,13 @@ ParsedQuery Visitor::visit(Parser::DescribeQueryContext* ctx) {
}
}

// Parse the FROM and FROM NAMED clauses and store them in the
// `describeClause`.
// Parse the FROM and FROM NAMED clauses.
auto datasetClauses = parsedQuery::DatasetClauses::fromClauses(
visitVector(ctx->datasetClause()));
describeClause.datasetClauses_ = datasetClauses;

// Parse the WHERE clause and handle the special case of `DESCRIBE *`.
// Parse the WHERE clause and construct a SELECT query from it. For `DESCRIBE
// *`, add each visible variable as a resource to describe.
visitWhereClause(ctx->whereClause(), parsedQuery_);
if (describedResources.empty()) {
const auto& visibleVariables =
Expand All @@ -319,10 +319,17 @@ ParsedQuery Visitor::visit(Parser::DescribeQueryContext* ctx) {
selectClause.setSelected(std::move(describedVariables));
describeClause.whereClause_ = std::move(parsedQuery_);

// Set up the actual DESCRIBE query, which is implemented as a CONSTRUCT query
// of the form `CONSTRUCT { ?subject ?predicate ?object} { ... }`. Note that
// the solution modifiers (in particular ORDER BY) are part of this query, not
// of the WHERE clause.
// Set up the final `ParsedQuery` object for the DESCRIBE query. The clause is
// a CONSTRUCT query of the form `CONSTRUCT { ?subject ?predicate ?object} {
// ... }`, with the `parsedQuery::Describe` object from above as the root
// graph pattern. The solution modifiers (in particular ORDER BY) are part of
// the CONSTRUCT query.
//
// NOTE: The dataset clauses are stored once in `parsedQuery_.datasetClauses_`
// (which pertains to the CONSTRUCT query that computes the result of the
// DESCRIBE), and once in `parsedQuery_.describeClause_.datasetClauses_`
// (which pertains to the SELECT query that computes the resources to be
// described).
parsedQuery_ = ParsedQuery{};
parsedQuery_.addSolutionModifiers(visit(ctx->solutionModifier()));
parsedQuery_._rootGraphPattern._graphPatterns.emplace_back(
Expand Down

0 comments on commit bc03b70

Please sign in to comment.