-
Notifications
You must be signed in to change notification settings - Fork 65
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
3 changed files
with
60 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
// Authors: Florian Kramer ([email protected]) | ||
// Johannes Kalmbach ([email protected]) | ||
|
||
#include <engine/SpatialJoinAlgorithms.h> | ||
#include <gmock/gmock.h> | ||
|
||
#include <cstdio> | ||
|
@@ -36,6 +37,7 @@ using ::testing::Optional; | |
|
||
namespace { | ||
auto I = IntId; | ||
auto D = DoubleId; | ||
|
||
// Return a matcher that checks, whether a given `std::optional<IdTable` has a | ||
// value and that value is equal to `makeIdTableFromVector(table)`. | ||
|
@@ -747,6 +749,47 @@ TEST_F(GroupByOptimizations, correctResultForHashMapOptimization) { | |
resultWithoutOptimization->asDebugString()); | ||
} | ||
|
||
// _____________________________________________________________________________ | ||
TEST_F(GroupByOptimizations, hashMapOptimizationLazyAndMaterializedInputs) { | ||
/* Setup query: | ||
SELECT ?x (AVG(?y) as ?avg) WHERE { | ||
# explicitly defined subresult. | ||
} GROUP BY ?x | ||
*/ | ||
// Setup three unsorted input blocks. The first column will be the grouped | ||
// `?x`, and the second column the variable `?y` of which we compute the | ||
// average. | ||
auto runTest = [this](bool inputIsLazy) { | ||
std::vector<IdTable> tables; | ||
tables.push_back(makeIdTableFromVector({{3, 6}, {8, 27}, {5, 7}}, I)); | ||
tables.push_back(makeIdTableFromVector({{8, 27}, {5, 9}}, I)); | ||
tables.push_back(makeIdTableFromVector({{5, 2}, {3, 4}}, I)); | ||
// The expected averages are as follows: (3 -> 5.0), (5 -> 6.0), (8 | ||
// -> 27.0). | ||
auto subtree = ad_utility::makeExecutionTree<ValuesForTesting>( | ||
qec, std::move(tables), | ||
std::vector<std::optional<Variable>>{Variable{"?x"}, Variable{"?y"}}); | ||
auto& values = | ||
dynamic_cast<ValuesForTesting&>(*subtree->getRootOperation()); | ||
values.forceFullyMaterialized() = !inputIsLazy; | ||
|
||
SparqlExpressionPimpl avgYPimpl = makeAvgPimpl(varY); | ||
std::vector<Alias> aliasesAvgY{Alias{avgYPimpl, Variable{"?avg"}}}; | ||
|
||
// Calculate result with optimization | ||
qec->getQueryTreeCache().clearAll(); | ||
RuntimeParameters().set<"group-by-hash-map-enabled">(true); | ||
GroupBy groupBy{qec, variablesOnlyX, aliasesAvgY, std::move(subtree)}; | ||
auto result = groupBy.computeResultOnlyForTesting(); | ||
ASSERT_TRUE(result.isFullyMaterialized()); | ||
EXPECT_THAT( | ||
result.idTable(), | ||
matchesIdTableFromVector({{I(3), D(5)}, {I(5), D(6)}, {I(8), D(27)}})); | ||
}; | ||
runTest(true); | ||
runTest(false); | ||
} | ||
|
||
// _____________________________________________________________________________ | ||
TEST_F(GroupByOptimizations, correctResultForHashMapOptimizationForCountStar) { | ||
/* Setup query: | ||
|
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