Skip to content

Commit

Permalink
Undo extraction of SparqlTripleSimple
Browse files Browse the repository at this point in the history
To avoid duplication this change will only be in #1354
  • Loading branch information
Qup42 committed May 22, 2024
1 parent 3dfcaab commit 7640db8
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 81 deletions.
3 changes: 1 addition & 2 deletions src/parser/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ add_library(parser
GraphPattern.cpp data/Variable.cpp
Iri.cpp
Literal.cpp
LiteralOrIri.cpp
Triples.h)
LiteralOrIri.cpp)
qlever_target_link_libraries(parser sparqlParser parserData sparqlExpressions rdfEscaping re2::re2 util engine)

67 changes: 67 additions & 0 deletions src/parser/ParsedQuery.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,75 @@ class SparqlPrefix {
bool operator==(const SparqlPrefix&) const = default;
};

inline bool isVariable(const string& elem) { return elem.starts_with("?"); }
inline bool isVariable(const TripleComponent& elem) {
return elem.isVariable();
}

inline bool isVariable(const PropertyPath& elem) {
return elem._operation == PropertyPath::Operation::IRI &&
isVariable(elem._iri);
}

std::ostream& operator<<(std::ostream& out, const PropertyPath& p);

// Data container for parsed triples from the where clause.
// It is templated on the predicate type, see the instantiations below.
template <typename Predicate>
class SparqlTripleBase {
public:
using AdditionalScanColumns = std::vector<std::pair<ColumnIndex, Variable>>;
SparqlTripleBase(TripleComponent s, Predicate p, TripleComponent o,
AdditionalScanColumns additionalScanColumns = {})
: s_(std::move(s)),
p_(std::move(p)),
o_(std::move(o)),
additionalScanColumns_(std::move(additionalScanColumns)) {}

bool operator==(const SparqlTripleBase& other) const = default;
TripleComponent s_;
Predicate p_;
TripleComponent o_;
// The additional columns (e.g. patterns) that are to be attached when
// performing an index scan using this triple.
// TODO<joka921> On this level we should not store `ColumnIndex`, but the
// special predicate IRIs that are to be attached here.
std::vector<std::pair<ColumnIndex, Variable>> additionalScanColumns_;
};

// A triple where the predicate is a `TripleComponent`, so a fixed entity or a
// variable, but not a property path.
class SparqlTripleSimple : public SparqlTripleBase<TripleComponent> {
using Base = SparqlTripleBase<TripleComponent>;
using Base::Base;
};

// 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> {
public:
using Base = SparqlTripleBase<PropertyPath>;
using Base::Base;

// ___________________________________________________________________________
SparqlTriple(TripleComponent s, const std::string& p_iri, TripleComponent o)
: Base{std::move(s), PropertyPath::fromIri(p_iri), std::move(o)} {}

// ___________________________________________________________________________
[[nodiscard]] string asString() const;

// Convert to a simple triple. Fails with an exception if the predicate
// actually is a property path.
SparqlTripleSimple getSimple() const {
AD_CONTRACT_CHECK(p_.isIri());
TripleComponent p =
isVariable(p_._iri)
? TripleComponent{Variable{p_._iri}}
: TripleComponent(TripleComponent::Iri::fromIriref(p_._iri));
return {s_, p, o_, additionalScanColumns_};
}
};

// Forward declaration
namespace parsedQuery {
struct GraphPatternOperation;
Expand Down
79 changes: 0 additions & 79 deletions src/parser/Triples.h

This file was deleted.

0 comments on commit 7640db8

Please sign in to comment.