Skip to content

Commit

Permalink
Allow ; after update request with a single operation (#1750)
Browse files Browse the repository at this point in the history
QLever does not yet support update requests with more than one operation, e.g., `DELETE DATA { <pi> <value> 3.14 }; INSERT DATA { <pi> <value> 3.1459 }`. Due to an oversight, the current implementation also did not support single operations followed by a semicolon, e.g., `DELETE DATA { <pi> <value> 3.14 };`. These are now supported. Fixes #1747

NOTE: Support for multiple operations in a single update request will be added soon.
  • Loading branch information
Qup42 authored Feb 1, 2025
1 parent f2562fe commit 50c1f0a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
6 changes: 4 additions & 2 deletions src/parser/sparqlParser/SparqlQleverVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -438,15 +438,17 @@ std::optional<Values> Visitor::visit(Parser::ValuesClauseContext* ctx) {
return visitOptional(ctx->dataBlock());
}

// ____________________________________________________________________________________
// ____________________________________________________________________________
ParsedQuery Visitor::visit(Parser::UpdateContext* ctx) {
// The prologue (BASE and PREFIX declarations) only affects the internal
// state of the visitor.
visit(ctx->prologue());

auto update = visit(ctx->update1());

if (ctx->update()) {
// More than one operation in a single update request is not yet supported,
// but a semicolon after a single update is allowed.
if (ctx->update() && !ctx->update()->getText().empty()) {
parsedQuery_ = ParsedQuery{};
reportNotSupported(ctx->update(), "Multiple updates in one query are");
}
Expand Down
25 changes: 21 additions & 4 deletions test/SparqlAntlrParserTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2050,10 +2050,12 @@ TEST(SparqlParser, QuadData) {
TEST(SparqlParser, Update) {
auto expectUpdate_ = ExpectCompleteParse<&Parser::update>{defaultPrefixMap};
// Automatically test all updates for their `_originalString`.
auto expectUpdate = [&expectUpdate_](const std::string& query,
auto&& expected) {
expectUpdate_(query,
testing::AllOf(expected, m::pq::OriginalString(query)));
auto expectUpdate = [&expectUpdate_](
const std::string& query, auto&& expected,
ad_utility::source_location l =
ad_utility::source_location::current()) {
expectUpdate_(query, testing::AllOf(expected, m::pq::OriginalString(query)),
l);
};
auto expectUpdateFails = ExpectParseFails<&Parser::update>{};
auto Iri = [](std::string_view stringWithBrackets) {
Expand Down Expand Up @@ -2185,6 +2187,21 @@ TEST(SparqlParser, Update) {
expectUpdate("COPY DEFAULT TO GRAPH <foo>",
m::UpdateClause(m::Copy(false, DEFAULT{}, Iri("<foo>")),
m::GraphPattern()));
const auto simpleInsertMatcher = m::UpdateClause(
m::GraphUpdate({}, {{Iri("<a>"), Iri("<b>"), Iri("<c>"), noGraph}},
std::nullopt),
m::GraphPattern());
expectUpdate("INSERT DATA { <a> <b> <c> }", simpleInsertMatcher);
expectUpdate("INSERT DATA { <a> <b> <c> };", simpleInsertMatcher);
const auto multipleUpdatesError = testing::HasSubstr(
"Not supported: Multiple updates in one query are "
"currently not supported by QLever");
expectUpdateFails("INSERT DATA { <a> <b> <c> }; PREFIX foo: <foo>",
multipleUpdatesError);
expectUpdateFails("INSERT DATA { <a> <b> <c> }; BASE <bar>",
multipleUpdatesError);
expectUpdateFails("INSERT DATA { <a> <b> <c> }; INSERT DATA { <d> <e> <f> }",
multipleUpdatesError);
}

TEST(SparqlParser, QueryOrUpdate) {
Expand Down

0 comments on commit 50c1f0a

Please sign in to comment.