-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'ad-freiburg:master' into words-and-docs-file-parsing
- Loading branch information
Showing
4 changed files
with
155 additions
and
77 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 |
---|---|---|
@@ -1,8 +1,7 @@ | ||
// Copyright 2018, University of Freiburg, | ||
// Copyright 2018 - 2024, University of Freiburg | ||
// Chair of Algorithms and Data Structures. | ||
// Author: | ||
// 2018 Florian Kramer ([email protected]) | ||
// 2020- Johannes Kalmbach ([email protected]) | ||
// Authors: Florian Kramer [2018] | ||
// Johannes Kalmbach <[email protected]> | ||
|
||
#pragma once | ||
|
||
|
@@ -316,10 +315,9 @@ class GroupBy : public Operation { | |
// Create result IdTable by using a HashMap mapping groups to aggregation data | ||
// and subsequently calling `createResultFromHashMap`. | ||
template <size_t NUM_GROUP_COLUMNS> | ||
IdTable computeGroupByForHashMapOptimization( | ||
std::vector<HashMapAliasInformation>& aggregateAliases, | ||
const IdTable& subresult, const std::vector<size_t>& columnIndices, | ||
LocalVocab* localVocab) const; | ||
Result computeGroupByForHashMapOptimization( | ||
std::vector<HashMapAliasInformation>& aggregateAliases, auto subresults, | ||
const std::vector<size_t>& columnIndices) const; | ||
|
||
using AggregationData = | ||
std::variant<AvgAggregationData, CountAggregationData, MinAggregationData, | ||
|
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,50 @@ 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); | ||
|
||
// Disable optimization for following tests | ||
RuntimeParameters().set<"group-by-hash-map-enabled">(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