-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Johannes Kalmbach <[email protected]>
- Loading branch information
Showing
10 changed files
with
80 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,15 +2,15 @@ | |
// Chair of Algorithms and Data Structures. | ||
// Author: Johannes Kalmbach <[email protected]> | ||
|
||
#include "engine/ExistsScan.h" | ||
#include "engine/ExistsJoin.h" | ||
|
||
#include "engine/QueryPlanner.h" | ||
#include "engine/sparqlExpressions/ExistsExpression.h" | ||
#include "engine/sparqlExpressions/SparqlExpression.h" | ||
#include "util/JoinAlgorithms/JoinAlgorithms.h" | ||
|
||
// _____________________________________________________________________________ | ||
ExistsScan::ExistsScan(QueryExecutionContext* qec, | ||
ExistsJoin::ExistsJoin(QueryExecutionContext* qec, | ||
std::shared_ptr<QueryExecutionTree> left, | ||
std::shared_ptr<QueryExecutionTree> right, | ||
Variable existsVariable) | ||
|
@@ -24,16 +24,16 @@ ExistsScan::ExistsScan(QueryExecutionContext* qec, | |
} | ||
|
||
// _____________________________________________________________________________ | ||
string ExistsScan::getCacheKeyImpl() const { | ||
string ExistsJoin::getCacheKeyImpl() const { | ||
return absl::StrCat("EXISTS SCAN left: ", left_->getCacheKey(), | ||
" right: ", right_->getCacheKey()); | ||
} | ||
|
||
// _____________________________________________________________________________ | ||
string ExistsScan::getDescriptor() const { return "EXISTS scan"; } | ||
string ExistsJoin::getDescriptor() const { return "EXISTS scan"; } | ||
|
||
// ____________________________________________________________________________ | ||
VariableToColumnMap ExistsScan::computeVariableToColumnMap() const { | ||
VariableToColumnMap ExistsJoin::computeVariableToColumnMap() const { | ||
auto res = left_->getVariableColumns(); | ||
AD_CONTRACT_CHECK( | ||
!res.contains(existsVariable_), | ||
|
@@ -43,18 +43,18 @@ VariableToColumnMap ExistsScan::computeVariableToColumnMap() const { | |
} | ||
|
||
// ____________________________________________________________________________ | ||
size_t ExistsScan::getResultWidth() const { | ||
size_t ExistsJoin::getResultWidth() const { | ||
// We add one column to the input. | ||
return left_->getResultWidth() + 1; | ||
} | ||
|
||
// ____________________________________________________________________________ | ||
vector<ColumnIndex> ExistsScan::resultSortedOn() const { | ||
vector<ColumnIndex> ExistsJoin::resultSortedOn() const { | ||
return left_->resultSortedOn(); | ||
} | ||
|
||
// ____________________________________________________________________________ | ||
float ExistsScan::getMultiplicity(size_t col) { | ||
float ExistsJoin::getMultiplicity(size_t col) { | ||
if (col < getResultWidth() - 1) { | ||
return left_->getMultiplicity(col); | ||
} | ||
|
@@ -64,18 +64,18 @@ float ExistsScan::getMultiplicity(size_t col) { | |
} | ||
|
||
// ____________________________________________________________________________ | ||
uint64_t ExistsScan::getSizeEstimateBeforeLimit() { | ||
uint64_t ExistsJoin::getSizeEstimateBeforeLimit() { | ||
return left_->getSizeEstimate(); | ||
} | ||
|
||
// ____________________________________________________________________________ | ||
size_t ExistsScan::getCostEstimate() { | ||
size_t ExistsJoin::getCostEstimate() { | ||
return left_->getCostEstimate() + right_->getCostEstimate() + | ||
left_->getSizeEstimate() + right_->getSizeEstimate(); | ||
} | ||
|
||
// ____________________________________________________________________________ | ||
ProtoResult ExistsScan::computeResult([[maybe_unused]] bool requestLaziness) { | ||
ProtoResult ExistsJoin::computeResult([[maybe_unused]] bool requestLaziness) { | ||
auto leftRes = left_->getResult(); | ||
auto rightRes = right_->getResult(); | ||
const auto& left = leftRes->idTable(); | ||
|
@@ -139,7 +139,7 @@ ProtoResult ExistsScan::computeResult([[maybe_unused]] bool requestLaziness) { | |
} | ||
|
||
// _____________________________________________________________________________ | ||
std::shared_ptr<QueryExecutionTree> ExistsScan::addExistsScansToSubtree( | ||
std::shared_ptr<QueryExecutionTree> ExistsJoin::addExistsScansToSubtree( | ||
const sparqlExpression::SparqlExpressionPimpl& expression, | ||
std::shared_ptr<QueryExecutionTree> subtree, QueryExecutionContext* qec, | ||
const ad_utility::SharedCancellationHandle& cancellationHandle) { | ||
|
@@ -158,7 +158,7 @@ std::shared_ptr<QueryExecutionTree> ExistsScan::addExistsScansToSubtree( | |
auto pq = exists.argument(); | ||
auto tree = | ||
std::make_shared<QueryExecutionTree>(qp.createExecutionTree(pq)); | ||
subtree = ad_utility::makeExecutionTree<ExistsScan>( | ||
subtree = ad_utility::makeExecutionTree<ExistsJoin>( | ||
qec, std::move(subtree), std::move(tree), exists.variable()); | ||
} | ||
return subtree; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
// Julian Mundhahs <[email protected]> | ||
// Hannah Bast <[email protected]> | ||
|
||
#include <engine/sparqlExpressions/ExistsExpression.h> | ||
#include <gtest/gtest.h> | ||
|
||
#include <iostream> | ||
|
@@ -14,6 +15,7 @@ | |
#include "./SparqlExpressionTestHelpers.h" | ||
#include "./util/GTestHelpers.h" | ||
#include "./util/TripleComponentTestHelpers.h" | ||
#include "QueryPlannerTestHelpers.h" | ||
#include "SparqlAntlrParserTestHelpers.h" | ||
#include "engine/sparqlExpressions/CountStarExpression.h" | ||
#include "engine/sparqlExpressions/GroupConcatExpression.h" | ||
|
@@ -1860,6 +1862,43 @@ TEST(SparqlParser, binaryStringExpressions) { | |
expectBuiltInCall("STRBEFORE(?x, ?y)", makeMatcher(&makeStrBeforeExpression)); | ||
} | ||
|
||
// Matchers for EXISTS and NOT EXISTS functions. | ||
namespace existsTestHelpers { | ||
using namespace sparqlExpression; | ||
using namespace ::testing; | ||
|
||
// Match an EXISTS function | ||
auto existsMatcher(Matcher<const ParsedQuery&> pattern) { | ||
return Pointee(WhenDynamicCastTo<const ExistsExpression&>( | ||
AD_PROPERTY(ExistsExpression, argument, pattern))); | ||
} | ||
// Match a NOT EXISTS function | ||
auto notExistsMatcher(Matcher<const ParsedQuery&> pattern) { | ||
return builtInCallTestHelpers::matchNaryWithChildrenMatchers( | ||
&makeUnaryNegateExpression, existsMatcher(pattern)); | ||
} | ||
} // namespace existsTestHelpers | ||
|
||
// _____________________________________________________________________________ | ||
TEST(SparqlParser, Exists) { | ||
using namespace existsTestHelpers; | ||
auto expectBuiltInCall = ExpectCompleteParse<&Parser::builtInCall>{}; | ||
// A matcher that matches the query `SELECT * { ?x <bar> ?foo}`, where the | ||
// FROM and FROM NAMED clauses can still be specified via arguments. | ||
using Graphs = ScanSpecificationAsTripleComponent::Graphs; | ||
auto selectABarFooMatcher = [](Graphs defaultGraphs = std::nullopt, | ||
Graphs namedGraphs = std::nullopt) { | ||
return testing::AllOf(m::SelectQuery( | ||
m::AsteriskSelect(), | ||
m::GraphPattern(m::Triples({{Var{"?a"}, "<bar>", Var{"?foo"}}})), | ||
defaultGraphs, namedGraphs)); | ||
}; | ||
expectBuiltInCall("EXISTS {?a <bar> ?foo}", | ||
existsMatcher(selectABarFooMatcher())); | ||
expectBuiltInCall("NOT EXISTS {?a <bar> ?foo}", | ||
notExistsMatcher(selectABarFooMatcher())); | ||
} | ||
|
||
namespace aggregateTestHelpers { | ||
using namespace sparqlExpression; | ||
|
||
|