Skip to content
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

Proof of concept for SPARQL UPDATE #916

Open
wants to merge 30 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
9a08db4
First steps towards prototype for UPDATE
Mar 15, 2023
4bfc02e
New version with a first proper test
Mar 17, 2023
aec6370
Triple location code is now correct and well tested
Mar 18, 2023
9680383
Merge remote-tracking branch 'origin/master' into update-proof-of-con…
Mar 18, 2023
606f412
Insert and delete work properly now
Mar 19, 2023
d2d99e0
Make clang-format happy
Mar 19, 2023
4017177
Try to make the more pedantic native build happy
Mar 19, 2023
b4a81df
The permutations now have access to the delta triples
Mar 21, 2023
4d22469
Better names and own class `LocatedTriple`
Mar 21, 2023
f9506a8
Merge remote-tracking branch 'origin/master' into update-proof-of-con…
Mar 21, 2023
04861ce
Refactor code and first try to merge delta triples
Mar 31, 2023
0dbd01e
Merge remote-tracking branch 'origin/master' into update-proof-of-con…
Mar 31, 2023
82911e7
Merge remote-tracking branch 'origin/master' into update-proof-of-con…
Apr 1, 2023
10c74f0
Method `mergeTriples` with good unit tests
Apr 1, 2023
fa49a33
Consider delta triples for index scans with two variables
Apr 2, 2023
15eaf48
Delta triples merged for both scan types now
Apr 3, 2023
38ca1fd
Delta triples now considered for all blocks
Apr 4, 2023
ad743bb
Merge remote-tracking branch 'origin/master' into update-proof-of-con…
Apr 5, 2023
7a36a9d
Resolve conflict that git silently merged in the last commit
Apr 6, 2023
b10ec84
Merge remote-tracking branch 'origin/master' into update-proof-of-con…
Apr 6, 2023
3afe571
Address bug pointed out by SonarCloud
Apr 8, 2023
2f4b105
Revert "Address bug pointed out by SonarCloud"
Apr 11, 2023
48578d3
Merge remote-tracking branch 'origin/master' into update-proof-of-con…
Apr 17, 2023
3906826
Merge branch 'master' into update-proof-of-concept
May 24, 2023
ad1163c
Make it compile again
Jun 8, 2023
ebd075c
Merge remote-tracking branch 'origin/master' into update-proof-of-con…
Jun 8, 2023
8cd5186
Merge remote-tracking branch 'origin/master' into update-proof-of-con…
Jun 8, 2023
b881717
Fix test with help of Johannes
Jun 9, 2023
e88c293
Latest submodules
Jun 9, 2023
8910f61
Some clean up before splitting off a first smaller PR
Jun 9, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
# Build directory
# Build directories
build/
debug/
cmake-build*

# Debugger history file
.gdb_history

# End-to-End data
e2e_data/*
# Compiled Object files
Expand Down
57 changes: 56 additions & 1 deletion src/engine/Server.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2011 - 2022, University of Freiburg
// Copyright 2011 - 2023, University of Freiburg
// Chair of Algorithms and Data Structures
// Authors: Björn Buchhold <[email protected]>
// Johannes Kalmbach <[email protected]>
Expand All @@ -13,6 +13,7 @@

#include "engine/ExportQueryExecutionTrees.h"
#include "engine/QueryPlanner.h"
#include "parser/TurtleParser.h"
#include "util/BoostHelpers/AsyncWaitForFuture.h"
#include "util/OnDestructionDontThrowDuringStackUnwinding.h"

Expand Down Expand Up @@ -310,11 +311,63 @@ Awaitable<void> Server::process(
logCommand(cmd, "clear cache completely (including unpinned elements)");
cache_.clearAll();
response = createJsonResponse(composeCacheStatsJson(), request);
} else if (auto cmd = checkParameter("cmd", "clear-delta-triples")) {
logCommand(cmd, "clear delta triples");
index_.deltaTriples().clear();
response = createJsonResponse(composeStatsJson(), request);
} else if (auto cmd = checkParameter("cmd", "get-settings")) {
logCommand(cmd, "get server settings");
response = createJsonResponse(RuntimeParameters().toMap(), request);
}

// Insert or delete triples.
//
// TODO: This is a preliminary interface for testing. Eventually, this should
// be included in our SPARQL grammer (where the line `updateUnit : update;` at
// the beginning is currently commented out).
//
// TODO: For testing purposes, allow insertions and deletions without access
// token. Eventually, this should be restricted, of course, which can be
// easily done by adding the argument `accessTokenOk` to each of the calls for
// `checkParameter`.
{
bool insertDetected = false;
bool deleteDetected = false;
std::optional<std::string> parameterValue;
if ((parameterValue = checkParameter("insert", std::nullopt))) {
LOG(INFO) << "INSERT: " << parameterValue.value() << std::endl;
insertDetected = true;
} else if ((parameterValue = checkParameter("delete", std::nullopt))) {
LOG(INFO) << "DELETE: " << parameterValue.value() << std::endl;
deleteDetected = true;
}
if (insertDetected || deleteDetected) {
AD_CORRECTNESS_CHECK(parameterValue.has_value());
const std::string& input = parameterValue.value();
TurtleStringParser<Tokenizer> parser;
parser.parseUtf8String(input);
if (parser.getTriples().size() == 0) {
throw std::runtime_error("Triple could not be parsed");
} else if (parser.getTriples().size() > 1) {
throw std::runtime_error("Only one triple per call please");
}
TurtleTriple turtleTriple = parser.getTriples()[0];
if (insertDetected) {
index_.deltaTriples().insertTriple(std::move(turtleTriple));
response =
createOkResponse(absl::StrCat("INSERT operation for triple \"",
input, "\" processed\n"),
request, ad_utility::MediaType::textPlain);
} else {
index_.deltaTriples().deleteTriple(std::move(turtleTriple));
response =
createOkResponse(absl::StrCat("DELETE operation for triple \"",
input, "\" processed\n"),
request, ad_utility::MediaType::textPlain);
}
}
}

// Ping with or without messsage.
if (urlPathAndParameters._path == "/ping") {
if (auto msg = checkParameter("msg", std::nullopt)) {
Expand Down Expand Up @@ -455,6 +508,8 @@ json Server::composeStatsJson() const {
result["num-text-records"] = index_.getNofTextRecords();
result["num-word-occurrences"] = index_.getNofWordPostings();
result["num-entity-occurrences"] = index_.getNofEntityPostings();
result["num-delta-triples-inserted"] = index_.deltaTriples().numInserted();
result["num-delta-triples-deleted"] = index_.deltaTriples().numDeleted();
return result;
}

Expand Down
1 change: 1 addition & 0 deletions src/engine/Server.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "engine/QueryExecutionContext.h"
#include "engine/QueryExecutionTree.h"
#include "engine/SortPerformanceEstimator.h"
#include "index/DeltaTriples.h"
#include "index/Index.h"
#include "nlohmann/json.hpp"
#include "parser/ParseException.h"
Expand Down
6 changes: 3 additions & 3 deletions src/global/Id.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
#include <cstdint>
#include <limits>

#include "../util/Exception.h"
#include "./IndexTypes.h"
#include "./ValueId.h"
#include "global/IndexTypes.h"
#include "global/ValueId.h"
#include "util/Exception.h"

using Id = ValueId;
typedef uint16_t Score;
Expand Down
18 changes: 18 additions & 0 deletions src/global/IdTriple.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright 2023, University of Freiburg
// Chair of Algorithms and Data Structures
// Authors: Hannah Bast <[email protected]>

#pragma once

#include <array>

#include "global/Id.h"

// Should we have an own class for this? We need this at several places.
using IdTriple = std::array<Id, 3>;

// Hash value for such triple.
template <typename H>
H AbslHashValue(H h, const IdTriple& triple) {
return H::combine(std::move(h), triple[0], triple[1], triple[2]);
}
4 changes: 2 additions & 2 deletions src/global/ValueId.h
Original file line number Diff line number Diff line change
Expand Up @@ -282,10 +282,10 @@ class ValueId {
/// This operator is only for debugging and testing. It returns a
/// human-readable representation.
friend std::ostream& operator<<(std::ostream& ostr, const ValueId& id) {
ostr << toString(id.getDatatype()) << ':';
ostr << toString(id.getDatatype())[0] << ':';
auto visitor = [&ostr]<typename T>(T&& value) {
if constexpr (ad_utility::isSimilar<T, ValueId::UndefinedType>) {
ostr << "Undefined";
ostr << "xx";
} else if constexpr (ad_utility::isSimilar<T, double> ||
ad_utility::isSimilar<T, int64_t>) {
ostr << std::to_string(value);
Expand Down
2 changes: 2 additions & 0 deletions src/index/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ add_library(index
VocabularyOnDisk.h VocabularyOnDisk.cpp
IndexMetaData.h IndexMetaDataImpl.h
MetaDataHandler.h
LocatedTriples.h LocatedTriples.cpp
DeltaTriples.h DeltaTriples.cpp
StxxlSortFunctors.h
TextMetaData.cpp TextMetaData.h
DocsDB.cpp DocsDB.h
Expand Down
Loading