Skip to content

Commit

Permalink
few additional adaptations
Browse files Browse the repository at this point in the history
  • Loading branch information
realHannes committed Nov 11, 2024
1 parent 0992fab commit f489b24
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 44 deletions.
11 changes: 5 additions & 6 deletions src/engine/Filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,11 @@ string Filter::getDescriptor() const {
void Filter::setPrefilterExpressionForIndexScanChildren() {
const std::vector<PrefilterVariablePair>& prefilterVec =
_expression.getPrefilterExpressionForMetadata();
this->forAllDescendants(
[&prefilterVec](const QueryExecutionTree* ptr) -> void {
if (ptr) {
ptr->setPrefilterExpression(prefilterVec);
}
});
this->forAllDescendants([&prefilterVec](const QueryExecutionTree* ptr) {
if (ptr) {
ptr->setPrefilterExpression(prefilterVec);
}
});
}

// _____________________________________________________________________________
Expand Down
9 changes: 5 additions & 4 deletions src/engine/IndexScan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ VariableToColumnMap IndexScan::computeVariableToColumnMap() const {

//______________________________________________________________________________
std::vector<CompressedBlockMetadata> IndexScan::applyFilterBlockMetadata(
const std::vector<CompressedBlockMetadata>& blocks) const {
std::vector<CompressedBlockMetadata>&& blocks) const {
std::ranges::for_each(prefilters_, [&blocks](const PrefilterIndexPair& pair) {
pair.first->evaluate(blocks, pair.second);
});

Check warning on line 163 in src/engine/IndexScan.cpp

View check run for this annotation

Codecov / codecov/patch

src/engine/IndexScan.cpp#L162-L163

Added lines #L162 - L163 were not covered by tests
Expand Down Expand Up @@ -276,7 +276,7 @@ ScanSpecificationAsTripleComponent IndexScan::getScanSpecificationTc() const {

// _____________________________________________________________________________
Permutation::IdTableGenerator IndexScan::getLazyScan(
std::vector<CompressedBlockMetadata> blocks) const {
std::vector<CompressedBlockMetadata>&& blocks) const {
// If there is a LIMIT or OFFSET clause that constrains the scan
// (which can happen with an explicit subquery), we cannot use the prefiltered
// blocks, as we currently have no mechanism to include limits and offsets
Expand Down Expand Up @@ -344,7 +344,8 @@ IndexScan::lazyScanForJoinOfTwoScans(const IndexScan& s1, const IndexScan& s2) {
auto [blocks1, blocks2] = CompressedRelationReader::getBlocksForJoin(
metaBlocks1.value(), metaBlocks2.value());

std::array result{s1.getLazyScan(blocks1), s2.getLazyScan(blocks2)};
std::array result{s1.getLazyScan(std::move(blocks1)),
s2.getLazyScan(std::move(blocks2))};
result[0].details().numBlocksAll_ = metaBlocks1.value().blockMetadata_.size();
result[1].details().numBlocksAll_ = metaBlocks2.value().blockMetadata_.size();
return result;
Expand All @@ -365,7 +366,7 @@ Permutation::IdTableGenerator IndexScan::lazyScanForJoinOfColumnWithScan(
auto blocks = CompressedRelationReader::getBlocksForJoin(joinColumn,
metaBlocks1.value());

auto result = getLazyScan(blocks);
auto result = getLazyScan(std::move(blocks));
result.details().numBlocksAll_ = metaBlocks1.value().blockMetadata_.size();
return result;
}
4 changes: 2 additions & 2 deletions src/engine/IndexScan.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ class IndexScan final : public Operation {
// Filter relevant `CompressedBlockMetadata` blocks by applying the
// `PrefilterExpression`s from `prefilters_`.
std::vector<CompressedBlockMetadata> applyFilterBlockMetadata(
const std::vector<CompressedBlockMetadata>& blocks) const;
std::vector<CompressedBlockMetadata>&& blocks) const;

// Return the (lazy) `IdTable` for this `IndexScan` in chunks.
Result::Generator chunkedIndexScan() const;
Expand All @@ -157,6 +157,6 @@ class IndexScan final : public Operation {
// Helper functions for the public `getLazyScanFor...` methods and
// `chunkedIndexScan` (see above).
Permutation::IdTableGenerator getLazyScan(
std::vector<CompressedBlockMetadata> blocks) const;
std::vector<CompressedBlockMetadata>&& blocks) const;
std::optional<Permutation::MetadataAndBlocks> getMetadataForScan() const;
};
10 changes: 9 additions & 1 deletion src/engine/Operation.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,15 @@ class Operation {

// Set `PrefilterExpression`s (for `IndexScan`).
virtual void setPrefilterExpression(
const std::vector<PrefilterVariablePair>&){};
const std::vector<PrefilterVariablePair>&){
// The prefiltering procedure is implemented by applying the
// PrefilterExpressions directly on the CompressedBlockMetadata.
// This is currently done while performing the result computation for
// IndexScan.
// (1) Overwrite this method for the derived IndexScan class.
// (2) The default method for all other derived classes is implemented
// here, no PrefilterExpressions need to be set.
};

// Apply the provided void function for all descendants. The given function
// must be invocable with a `const QueryExecutionTree*` object.
Expand Down
31 changes: 15 additions & 16 deletions src/engine/sparqlExpressions/RelationalExpressions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -448,22 +448,21 @@ RelationalExpression<comp>::getPrefilterExpressionForMetadata(
};

const auto tryGetPrefilterExprVariablePairVec =
[&mirroredExpression](
const SparqlExpression* child0, const SparqlExpression* child1,
bool reversed) -> std::vector<PrefilterExprVariablePair> {
std::vector<PrefilterExprVariablePair> resVec{};
if (const auto* variable =
dynamic_cast<const VariableExpression*>(child0)) {
if (const auto* valueId = dynamic_cast<const IdExpression*>(child1)) {
resVec.emplace_back(std::make_pair(
reversed ? mirroredExpression(valueId->value())
: std::make_unique<p::RelationalExpression<comp>>(
valueId->value()),
variable->value()));
}
}
return resVec;
};
[&mirroredExpression](const SparqlExpression* child0,
const SparqlExpression* child1, bool reversed) {
std::vector<PrefilterExprVariablePair> resVec{};
if (const auto* variable =
dynamic_cast<const VariableExpression*>(child0)) {
if (const auto* valueId = dynamic_cast<const IdExpression*>(child1)) {
resVec.emplace_back(
reversed ? mirroredExpression(valueId->value())
: std::make_unique<p::RelationalExpression<comp>>(
valueId->value()),
variable->value());
}
}
return resVec;
};
// Option 1:
// RelationalExpression containing a VariableExpression as the first child
// and an IdExpression as the second child.
Expand Down
18 changes: 9 additions & 9 deletions src/engine/sparqlExpressions/StringExpressions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,23 +244,23 @@ class StrStartsExpressionImpl : public NaryExpression<NaryOperation> {
AD_CORRECTNESS_CHECK(this->N == 2);
const SparqlExpression* child0 = this->getNthChild(0).value();
const SparqlExpression* child1 = this->getNthChild(1).value();
const auto getPrefilterExprVariableVec =
[](const SparqlExpression* child0, const SparqlExpression* child1,
bool startsWithVar) -> std::vector<PrefilterExprVariablePair> {
const auto getPrefilterExprVariableVec = [](const SparqlExpression* child0,
const SparqlExpression* child1,
bool startsWithVar) {
using namespace prefilterExpressions;
std::vector<PrefilterExprVariablePair> resVec{};
if (const auto* variable =
dynamic_cast<const VariableExpression*>(child0)) {
if (const auto* valueId = dynamic_cast<const IdExpression*>(child1)) {
!startsWithVar
// make {<(>= VocabId(n)), ?var>} (Option 1)
? resVec.emplace_back(std::make_pair(
// Will return: {<(>= VocabId(n)), ?var>} (Option 1)
? resVec.emplace_back(
std::make_unique<GreaterEqualExpression>(valueId->value()),
variable->value()))
// make {<(<= VocabId(n)), ?var>} (Option 2)
: resVec.emplace_back(std::make_pair(
variable->value())
// Will return: {<(<= VocabId(n)), ?var>} (Option 2)
: resVec.emplace_back(
std::make_unique<LessEqualExpression>(valueId->value()),
variable->value()));
variable->value());
}
}
return resVec;
Expand Down
7 changes: 3 additions & 4 deletions src/index/CompressedBlockPrefiltering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ std::vector<BlockMetadata> RelationalExpression<Comparison>::evaluateImpl(
template <CompOp Comparison>
bool RelationalExpression<Comparison>::operator==(
const PrefilterExpression& other) const {
const RelationalExpression<Comparison>* otherRelational =
const auto* otherRelational =
dynamic_cast<const RelationalExpression<Comparison>*>(&other);
if (!otherRelational) {
return false;
Expand Down Expand Up @@ -333,7 +333,7 @@ std::vector<BlockMetadata> LogicalExpression<Operation>::evaluateImpl(
template <LogicalOperator Operation>
bool LogicalExpression<Operation>::operator==(
const PrefilterExpression& other) const {
const LogicalExpression<Operation>* otherlogical =
const auto* otherlogical =
dynamic_cast<const LogicalExpression<Operation>*>(&other);
if (!otherlogical) {
return false;
Expand Down Expand Up @@ -382,8 +382,7 @@ std::vector<BlockMetadata> NotExpression::evaluateImpl(

//______________________________________________________________________________
bool NotExpression::operator==(const PrefilterExpression& other) const {
const NotExpression* otherNotExpression =
dynamic_cast<const NotExpression*>(&other);
const auto* otherNotExpression = dynamic_cast<const NotExpression*>(&other);
if (!otherNotExpression) {
return false;
}
Expand Down
3 changes: 1 addition & 2 deletions src/index/Permutation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ IdTable Permutation::scan(
const auto& p = getActualPermutation(scanSpec);

return p.reader().scan(
scanSpec,
blocks.has_value() ? std::move(blocks.value()) : p.meta_.blockData(),
scanSpec, blocks.has_value() ? blocks.value() : p.meta_.blockData(),
additionalColumns, cancellationHandle,
getLocatedTriplesForPermutation(locatedTriplesSnapshot), limitOffset);
}
Expand Down

0 comments on commit f489b24

Please sign in to comment.