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

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 13 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,18 @@ class SparqlTripleSimple : public SparqlTripleBase<TripleComponent> {
using Base::Base;
};

class SparqlTripleSimpleWithGraph : public SparqlTripleSimple {
public:
using SparqlTripleSimple::SparqlTripleSimple;
SparqlTripleSimpleWithGraph(TripleComponent s, TripleComponent p,
TripleComponent o, std::optional<Iri> g,
AdditionalScanColumns additionalScanColumns = {})
: SparqlTripleSimple(std::move(s), std::move(p), std::move(o),
std::move(additionalScanColumns)),
g_{std::move(g)} {}
std::optional<Iri> g_;
};

// 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
65 changes: 60 additions & 5 deletions src/parser/UpdateClause.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,73 @@

#pragma once

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

struct Load {
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)} {}
};

namespace parsedQuery {
struct UpdateClause : ClauseBase {
std::vector<SparqlTripleSimple> toInsert_;
std::vector<SparqlTripleSimple> toDelete_;
std::variant<GraphUpdate, Load, Clear, Drop, Create, Add, Move, Copy> op_;

UpdateClause() = default;
UpdateClause(std::vector<SparqlTripleSimple> toInsert,
std::vector<SparqlTripleSimple> toDelete)
: toInsert_{std::move(toInsert)}, toDelete_{std::move(toDelete)} {}
explicit UpdateClause(
std::variant<GraphUpdate, Load, Clear, Drop, Create, Add, Move, Copy> op)
: op_{std::move(op)} {}
};
} // namespace parsedQuery
15 changes: 12 additions & 3 deletions src/parser/data/GraphRef.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,18 @@
#include "parser/Iri.h"

using GraphRef = TripleComponent::Iri;
struct DEFAULT {};
struct NAMED {};
struct ALL {};
struct DEFAULT {
// For testing
bool operator==(const DEFAULT&) const = default;
};
struct NAMED {
// For testing
bool operator==(const NAMED&) const = default;
};
struct ALL {
// For testing
bool operator==(const ALL&) const = default;

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

View check run for this annotation

Codecov / codecov/patch

src/parser/data/GraphRef.h#L22

Added line #L22 was not covered by tests
};

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