Skip to content

Commit

Permalink
Fix formatting + improve comments in GroupBy.{h,cpp}
Browse files Browse the repository at this point in the history
  • Loading branch information
Hannah Bast committed Jan 4, 2025
1 parent 896df47 commit bbed6e7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
22 changes: 16 additions & 6 deletions src/engine/GroupBy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,8 @@ ProtoResult GroupBy::computeResult(bool requestLaziness) {
}

if (useHashMapOptimization) {
// Helper lambda that calls `computeGroupByForHashMapOptimization` for the
// given `subresults`.
auto computeWithHashMap = [this, &metadataForUnsequentialData,
&groupByCols](auto&& subresults) {
auto doCompute = [&]<int NumCols> {
Expand All @@ -376,9 +378,10 @@ ProtoResult GroupBy::computeResult(bool requestLaziness) {
return ad_utility::callFixedSize(groupByCols.size(), doCompute);
};

// Now call `computeWithHashMap` and return the result. It expects a range
// of results, so if the result is fully materialized, we create an array
// with a single element.
if (subresult->isFullyMaterialized()) {
// `computeWithHashMap` takes a range, so we artificially create one with
// a single input.
return computeWithHashMap(
std::array{std::pair{std::cref(subresult->idTable()),
std::cref(subresult->localVocab())}});
Expand Down Expand Up @@ -1506,29 +1509,36 @@ Result GroupBy::computeGroupByForHashMapOptimization(
NUM_GROUP_COLUMNS == 0);
LocalVocab localVocab;

// Initialize aggregation data
// Initialize the data for the aggregates of the GROUP BY operation.
HashMapAggregationData<NUM_GROUP_COLUMNS> aggregationData(
getExecutionContext()->getAllocator(), aggregateAliases,
columnIndices.size());

// Process the input blocks (pairs of `IdTable` and `LocalVocab`) one after
// the other.
ad_utility::Timer lookupTimer{ad_utility::Timer::Stopped};
ad_utility::Timer aggregationTimer{ad_utility::Timer::Stopped};
for (const auto& [inputTableRef, inputLocalVocabRef] : subresults) {
// Also support `std::reference_wrapper` as the input.
const IdTable& inputTable = inputTableRef;
const LocalVocab& inputLocalVocab = inputLocalVocabRef;

// Merge the local vocab of each input block.
//
// NOTE: If the input blocks have very similar or even identical non-empty
// local vocabs, no deduplication is performed.
localVocab.mergeWith(std::span{&inputLocalVocab, 1});
// Initialize evaluation context

// Setup the `EvaluationContext` for this input block.
sparqlExpression::EvaluationContext evaluationContext(
*getExecutionContext(), _subtree->getVariableColumns(), inputTable,
getExecutionContext()->getAllocator(), localVocab, cancellationHandle_,
deadline_);

evaluationContext._groupedVariables = ad_utility::HashSet<Variable>{
_groupByVariables.begin(), _groupByVariables.end()};
evaluationContext._isPartOfGroupBy = true;

// Iterate of the rows of this input block. Process (up to)
// `GROUP_BY_HASH_MAP_BLOCK_SIZE` rows at a time.
for (size_t i = 0; i < inputTable.size();
i += GROUP_BY_HASH_MAP_BLOCK_SIZE) {
checkCancellation();
Expand Down
10 changes: 4 additions & 6 deletions src/engine/GroupBy.h
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

Expand Down Expand Up @@ -317,8 +316,7 @@ class GroupBy : public Operation {
// and subsequently calling `createResultFromHashMap`.
template <size_t NUM_GROUP_COLUMNS>
Result computeGroupByForHashMapOptimization(
std::vector<HashMapAliasInformation>& aggregateAliases,
auto subresults,
std::vector<HashMapAliasInformation>& aggregateAliases, auto subresults,
const std::vector<size_t>& columnIndices) const;

using AggregationData =
Expand Down

0 comments on commit bbed6e7

Please sign in to comment.