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

Parse all SPARQL Update Requests #1574

Merged
merged 13 commits into from
Oct 26, 2024
16 changes: 16 additions & 0 deletions src/parser/SparqlTriple.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#pragma once

#include <utility>
#include <vector>

#include "PropertyPath.h"
Expand Down Expand Up @@ -53,6 +54,21 @@ class SparqlTripleSimple : public SparqlTripleBase<TripleComponent> {
using Base::Base;
};

class SparqlTripleSimpleWithGraph : public SparqlTripleSimple {
public:
using Graph = std::variant<std::monostate, Iri, Variable>;

SparqlTripleSimpleWithGraph(TripleComponent s, TripleComponent p,
TripleComponent o, Graph g,
AdditionalScanColumns additionalScanColumns = {})
: SparqlTripleSimple(std::move(s), std::move(p), std::move(o),
std::move(additionalScanColumns)),
g_{std::move(g)} {}
Graph g_;

bool operator==(const SparqlTripleSimpleWithGraph&) const = default;
};

// A triple where the predicate is a `PropertyPath` (which technically still
// might be a variable or fixed entity in the current implementation).
class SparqlTriple : public SparqlTripleBase<PropertyPath> {
Expand Down
69 changes: 64 additions & 5 deletions src/parser/UpdateClause.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,77 @@

#pragma once

#include "parser/Iri.h"
#include "parser/SelectClause.h"
#include "parser/SparqlTriple.h"
#include "parser/data/GraphRef.h"
#include "parser/data/Types.h"

namespace updateClause {
struct Load {
Qup42 marked this conversation as resolved.
Show resolved Hide resolved
bool silent_;
ad_utility::triple_component::Iri source_;
std::optional<GraphRef> target_;
};

struct Clear {
bool silent_;
GraphRefAll target_;
};

struct Drop {
bool silent_;
GraphRefAll target_;
};

struct Create {
bool silent_;
GraphRef target_;
};

struct Add {
bool silent_;
GraphOrDefault source_;
GraphOrDefault target_;
};

struct Move {
bool silent_;
GraphOrDefault source_;
GraphOrDefault target_;
};

struct Copy {
bool silent_;
GraphOrDefault source_;
GraphOrDefault target_;
};

// A Graph Update is an Update operation that inserts or deletes some triples.
// These triples can contain variables that are bound the result of the
// ParsedQueries GraphPattern. This used for `INSERT DATA`, `DELETE DATA`,
// `DELETE WHERE {...}` and `DELETE/INSERT {..} WHERE {...}`.
struct GraphUpdate {
std::vector<SparqlTripleSimpleWithGraph> toInsert_;
std::vector<SparqlTripleSimpleWithGraph> toDelete_;
std::optional<ad_utility::triple_component::Iri> with_;

GraphUpdate() = default;
GraphUpdate(std::vector<SparqlTripleSimpleWithGraph> toInsert,
std::vector<SparqlTripleSimpleWithGraph> toDelete)
: toInsert_{std::move(toInsert)}, toDelete_{std::move(toDelete)} {}
};

// All the available update operations.
using Operation =
std::variant<GraphUpdate, Load, Clear, Drop, Create, Add, Move, Copy>;
} // namespace updateClause

namespace parsedQuery {
struct UpdateClause : ClauseBase {
std::vector<SparqlTripleSimple> toInsert_;
std::vector<SparqlTripleSimple> toDelete_;
updateClause::Operation op_;

UpdateClause() = default;
UpdateClause(std::vector<SparqlTripleSimple> toInsert,
std::vector<SparqlTripleSimple> toDelete)
: toInsert_{std::move(toInsert)}, toDelete_{std::move(toDelete)} {}
explicit UpdateClause(updateClause::Operation op) : op_{std::move(op)} {}
};
} // namespace parsedQuery
20 changes: 17 additions & 3 deletions src/parser/data/GraphRef.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,23 @@
#include "parser/Iri.h"

using GraphRef = TripleComponent::Iri;
struct DEFAULT {};
struct NAMED {};
struct ALL {};
// Denotes the target graph for an operation. Here the target is the default
// graph.
struct DEFAULT {
// For testing
bool operator==(const DEFAULT&) const = default;
};
// Denotes the target graphs for an operation. Here the target are all named
// graphs.
struct NAMED {
// For testing
bool operator==(const NAMED&) const = default;
Qup42 marked this conversation as resolved.
Show resolved Hide resolved
};
// Denotes the target graphs for an operation. Here the target are all graphs.
struct ALL {
// For testing
bool operator==(const ALL&) const = default;

Check warning on line 27 in src/parser/data/GraphRef.h

View check run for this annotation

Codecov / codecov/patch

src/parser/data/GraphRef.h#L27

Added line #L27 was not covered by tests
};

using GraphRefAll = std::variant<GraphRef, DEFAULT, NAMED, ALL>;
using GraphOrDefault = std::variant<GraphRef, DEFAULT>;
Loading
Loading