Modified Aggregation unit test. Ran clang-format.
Project: http://git-wip-us.apache.org/repos/asf/incubator-quickstep/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-quickstep/commit/c123bd49 Tree: http://git-wip-us.apache.org/repos/asf/incubator-quickstep/tree/c123bd49 Diff: http://git-wip-us.apache.org/repos/asf/incubator-quickstep/diff/c123bd49 Branch: refs/heads/quickstep-28-29 Commit: c123bd494fd98428a488d349b9ecb2114092a33f Parents: 3606000 Author: rathijit <rathi...@node-2.aggregation-pr.quickstep-pg0.wisc.cloudlab.us> Authored: Sun Aug 21 05:33:40 2016 -0500 Committer: Harshad Deshmukh <hbdeshm...@apache.org> Committed: Tue Sep 20 12:56:07 2016 -0500 ---------------------------------------------------------------------- .../aggregation/AggregationConcreteHandle.cpp | 15 +- .../aggregation/AggregationConcreteHandle.hpp | 153 +- expressions/aggregation/AggregationHandle.hpp | 48 +- .../aggregation/AggregationHandleAvg.cpp | 96 +- .../aggregation/AggregationHandleAvg.hpp | 130 +- .../aggregation/AggregationHandleCount.cpp | 150 +- .../aggregation/AggregationHandleCount.hpp | 118 +- .../aggregation/AggregationHandleDistinct.hpp | 28 +- .../aggregation/AggregationHandleMax.cpp | 71 +- .../aggregation/AggregationHandleMax.hpp | 98 +- .../aggregation/AggregationHandleMin.cpp | 73 +- .../aggregation/AggregationHandleMin.hpp | 101 +- .../aggregation/AggregationHandleSum.cpp | 87 +- .../aggregation/AggregationHandleSum.hpp | 113 +- expressions/aggregation/CMakeLists.txt | 85 +- .../tests/AggregationHandleAvg_unittest.cpp | 255 +-- .../tests/AggregationHandleCount_unittest.cpp | 311 ++-- .../tests/AggregationHandleMax_unittest.cpp | 382 +++-- .../tests/AggregationHandleMin_unittest.cpp | 378 +++-- .../tests/AggregationHandleSum_unittest.cpp | 291 ++-- storage/AggregationOperationState.cpp | 263 ++-- storage/AggregationOperationState.hpp | 42 +- storage/FastHashTable.hpp | 1461 +++++++++--------- storage/FastSeparateChainingHashTable.hpp | 1171 ++++++++------ storage/HashTableBase.hpp | 20 +- 25 files changed, 3281 insertions(+), 2659 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/c123bd49/expressions/aggregation/AggregationConcreteHandle.cpp ---------------------------------------------------------------------- diff --git a/expressions/aggregation/AggregationConcreteHandle.cpp b/expressions/aggregation/AggregationConcreteHandle.cpp index ac5148b..ae677d9 100644 --- a/expressions/aggregation/AggregationConcreteHandle.cpp +++ b/expressions/aggregation/AggregationConcreteHandle.cpp @@ -23,8 +23,8 @@ #include <vector> #include "catalog/CatalogTypedefs.hpp" -#include "storage/HashTable.hpp" #include "storage/FastHashTable.hpp" +#include "storage/HashTable.hpp" #include "storage/HashTableFactory.hpp" namespace quickstep { @@ -52,24 +52,19 @@ void AggregationConcreteHandle::insertValueAccessorIntoDistinctifyHashTable( AggregationStateHashTableBase *distinctify_hash_table) const { // If the key-value pair is already there, we don't need to update the value, // which should always be "true". I.e. the value is just a placeholder. - // const auto noop_upserter = [](const auto &accessor, const bool *value) -> void {}; AggregationStateFastHashTable *hash_table = static_cast<AggregationStateFastHashTable *>(distinctify_hash_table); if (key_ids.size() == 1) { std::vector<std::vector<attribute_id>> args; args.emplace_back(key_ids); - hash_table->upsertValueAccessorFast(args, - accessor, - key_ids[0], - true /* check_for_null_keys */); + hash_table->upsertValueAccessorFast( + args, accessor, key_ids[0], true /* check_for_null_keys */); } else { std::vector<std::vector<attribute_id>> empty_args; empty_args.resize(1); - hash_table->upsertValueAccessorCompositeKeyFast(empty_args, - accessor, - key_ids, - true /* check_for_null_keys */); + hash_table->upsertValueAccessorCompositeKeyFast( + empty_args, accessor, key_ids, true /* check_for_null_keys */); } } http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/c123bd49/expressions/aggregation/AggregationConcreteHandle.hpp ---------------------------------------------------------------------- diff --git a/expressions/aggregation/AggregationConcreteHandle.hpp b/expressions/aggregation/AggregationConcreteHandle.hpp index 5b47e93..ac37bae 100644 --- a/expressions/aggregation/AggregationConcreteHandle.hpp +++ b/expressions/aggregation/AggregationConcreteHandle.hpp @@ -21,18 +21,18 @@ #define QUICKSTEP_EXPRESSIONS_AGGREGATION_AGGREGATION_CONCRETE_HANDLE_HPP_ #include <cstddef> -#include <vector> #include <utility> +#include <vector> #include "catalog/CatalogTypedefs.hpp" #include "expressions/aggregation/AggregationHandle.hpp" -#include "storage/HashTable.hpp" #include "storage/FastHashTable.hpp" +#include "storage/HashTable.hpp" #include "storage/HashTableBase.hpp" +#include "threading/SpinMutex.hpp" #include "types/TypedValue.hpp" #include "types/containers/ColumnVector.hpp" #include "utility/Macros.hpp" -#include "threading/SpinMutex.hpp" #include "glog/logging.h" @@ -61,7 +61,8 @@ class HashTableStateUpserterFast { * table. The corresponding state (for the same key) in the destination * hash table will be upserted. **/ - HashTableStateUpserterFast(const HandleT &handle, const uint8_t *source_state) + HashTableStateUpserterFast(const HandleT &handle, + const std::uint8_t *source_state) : handle_(handle), source_state_(source_state) {} /** @@ -70,13 +71,13 @@ class HashTableStateUpserterFast { * @param destination_state The aggregation state in the aggregation hash * table that is being upserted. **/ - void operator()(uint8_t *destination_state) { + void operator()(std::uint8_t *destination_state) { handle_.mergeStatesFast(source_state_, destination_state); } private: const HandleT &handle_; - const uint8_t *source_state_; + const std::uint8_t *source_state_; DISALLOW_COPY_AND_ASSIGN(HashTableStateUpserterFast); }; @@ -108,13 +109,15 @@ class AggregationConcreteHandle : public AggregationHandle { */ AggregationStateHashTableBase* createDistinctifyHashTable( const HashTableImplType hash_table_impl, - const std::vector<const Type*> &key_types, + const std::vector<const Type *> &key_types, const std::size_t estimated_num_distinct_keys, StorageManager *storage_manager) const override; /** - * @brief Implementaion for AggregationHandle::insertValueAccessorIntoDistinctifyHashTable() - * that inserts the GROUP BY expressions and aggregation arguments together + * @brief Implementaion for + * AggregationHandle::insertValueAccessorIntoDistinctifyHashTable() + * that inserts the GROUP BY expressions and aggregation arguments + * together * as keys into the distinctify hash table. */ void insertValueAccessorIntoDistinctifyHashTable( @@ -123,23 +126,19 @@ class AggregationConcreteHandle : public AggregationHandle { AggregationStateHashTableBase *distinctify_hash_table) const override; protected: - AggregationConcreteHandle() { - } + AggregationConcreteHandle() {} - template <typename HandleT, - typename StateT> + template <typename HandleT, typename StateT> StateT* aggregateOnDistinctifyHashTableForSingleUnaryHelperFast( const AggregationStateHashTableBase &distinctify_hash_table) const; - template <typename HandleT, - typename HashTableT> + template <typename HandleT, typename HashTableT> void aggregateOnDistinctifyHashTableForGroupByUnaryHelperFast( const AggregationStateHashTableBase &distinctify_hash_table, AggregationStateHashTableBase *hash_table, - int index) const; + std::size_t index) const; - template <typename HandleT, - typename HashTableT> + template <typename HandleT, typename HashTableT> ColumnVector* finalizeHashTableHelperFast( const Type &result_type, const AggregationStateHashTableBase &hash_table, @@ -151,11 +150,13 @@ class AggregationConcreteHandle : public AggregationHandle { const AggregationStateHashTableBase &hash_table, const std::vector<TypedValue> &group_key, int index) const { - const std::uint8_t *group_state - = static_cast<const HashTableT&>(hash_table).getSingleCompositeKey(group_key, index); + const std::uint8_t *group_state = + static_cast<const HashTableT &>(hash_table) + .getSingleCompositeKey(group_key, index); DCHECK(group_state != nullptr) << "Could not find entry for specified group_key in HashTable"; - return static_cast<const HandleT*>(this)->finalizeHashTableEntryFast(group_state); + return static_cast<const HandleT *>(this)->finalizeHashTableEntryFast( + group_state); } template <typename HandleT, typename HashTableT> @@ -177,24 +178,26 @@ class AggregationConcreteHandle : public AggregationHandle { template <typename HandleT, typename ColumnVectorT> class HashTableAggregateFinalizer { public: - HashTableAggregateFinalizer(const HandleT &handle, - std::vector<std::vector<TypedValue>> *group_by_keys, - ColumnVectorT *output_column_vector) + HashTableAggregateFinalizer( + const HandleT &handle, + std::vector<std::vector<TypedValue>> *group_by_keys, + ColumnVectorT *output_column_vector) : handle_(handle), group_by_keys_(group_by_keys), - output_column_vector_(output_column_vector) { - } + output_column_vector_(output_column_vector) {} inline void operator()(const std::vector<TypedValue> &group_by_key, const AggregationState &group_state) { group_by_keys_->emplace_back(group_by_key); - output_column_vector_->appendTypedValue(handle_.finalizeHashTableEntry(group_state)); + output_column_vector_->appendTypedValue( + handle_.finalizeHashTableEntry(group_state)); } inline void operator()(const std::vector<TypedValue> &group_by_key, const unsigned char *byte_ptr) { group_by_keys_->emplace_back(group_by_key); - output_column_vector_->appendTypedValue(handle_.finalizeHashTableEntryFast(byte_ptr)); + output_column_vector_->appendTypedValue( + handle_.finalizeHashTableEntryFast(byte_ptr)); } private: @@ -208,47 +211,51 @@ class HashTableAggregateFinalizer { // ---------------------------------------------------------------------------- // Implementations of templated methods follow: -template <typename HandleT, - typename StateT> -StateT* AggregationConcreteHandle::aggregateOnDistinctifyHashTableForSingleUnaryHelperFast( - const AggregationStateHashTableBase &distinctify_hash_table) const { - const HandleT& handle = static_cast<const HandleT&>(*this); - StateT *state = static_cast<StateT*>(createInitialState()); +template <typename HandleT, typename StateT> +StateT* AggregationConcreteHandle:: + aggregateOnDistinctifyHashTableForSingleUnaryHelperFast( + const AggregationStateHashTableBase &distinctify_hash_table) const { + const HandleT &handle = static_cast<const HandleT &>(*this); + StateT *state = static_cast<StateT *>(createInitialState()); // A lambda function which will be called on each key from the distinctify // hash table. - const auto aggregate_functor = [&handle, &state](const TypedValue &key, - const std::uint8_t &dumb_placeholder) { + const auto aggregate_functor = [&handle, &state]( + const TypedValue &key, const std::uint8_t &dumb_placeholder) { // For each (unary) key in the distinctify hash table, aggregate the key // into "state". handle.iterateUnaryInl(state, key); }; const AggregationStateFastHashTable &hash_table = - static_cast<const AggregationStateFastHashTable &>(distinctify_hash_table); - // Invoke the lambda function "aggregate_functor" on each key from the distinctify + static_cast<const AggregationStateFastHashTable &>( + distinctify_hash_table); + // Invoke the lambda function "aggregate_functor" on each key from the + // distinctify // hash table. hash_table.forEach(&aggregate_functor); return state; } -template <typename HandleT, - typename HashTableT> -void AggregationConcreteHandle::aggregateOnDistinctifyHashTableForGroupByUnaryHelperFast( - const AggregationStateHashTableBase &distinctify_hash_table, - AggregationStateHashTableBase *aggregation_hash_table, - int index) const { - const HandleT& handle = static_cast<const HandleT&>(*this); - HashTableT *target_hash_table = static_cast<HashTableT*>(aggregation_hash_table); +template <typename HandleT, typename HashTableT> +void AggregationConcreteHandle:: + aggregateOnDistinctifyHashTableForGroupByUnaryHelperFast( + const AggregationStateHashTableBase &distinctify_hash_table, + AggregationStateHashTableBase *aggregation_hash_table, + std::size_t index) const { + const HandleT &handle = static_cast<const HandleT &>(*this); + HashTableT *target_hash_table = + static_cast<HashTableT *>(aggregation_hash_table); // A lambda function which will be called on each key-value pair from the // distinctify hash table. const auto aggregate_functor = [&handle, &target_hash_table, &index]( - std::vector<TypedValue> &key, - const bool &dumb_placeholder) { - // For each (composite) key vector in the distinctify hash table with size N. - // The first N-1 entries are GROUP BY columns and the last entry is the argument + std::vector<TypedValue> &key, const bool &dumb_placeholder) { + // For each (composite) key vector in the distinctify hash table with size + // N. + // The first N-1 entries are GROUP BY columns and the last entry is the + // argument // to be aggregated on. const TypedValue argument(std::move(key.back())); key.pop_back(); @@ -263,59 +270,55 @@ void AggregationConcreteHandle::aggregateOnDistinctifyHashTableForGroupByUnaryHe }; const HashTableT &source_hash_table = - static_cast<const HashTableT&>(distinctify_hash_table); + static_cast<const HashTableT &>(distinctify_hash_table); // Invoke the lambda function "aggregate_functor" on each composite key vector // from the distinctify hash table. source_hash_table.forEachCompositeKeyFast(&aggregate_functor); } -template <typename HandleT, - typename HashTableT> +template <typename HandleT, typename HashTableT> ColumnVector* AggregationConcreteHandle::finalizeHashTableHelperFast( const Type &result_type, const AggregationStateHashTableBase &hash_table, std::vector<std::vector<TypedValue>> *group_by_keys, int index) const { - const HandleT &handle = static_cast<const HandleT&>(*this); - const HashTableT &hash_table_concrete = static_cast<const HashTableT&>(hash_table); + const HandleT &handle = static_cast<const HandleT &>(*this); + const HashTableT &hash_table_concrete = + static_cast<const HashTableT &>(hash_table); if (group_by_keys->empty()) { if (NativeColumnVector::UsableForType(result_type)) { - NativeColumnVector *result = new NativeColumnVector(result_type, - hash_table_concrete.numEntries()); + NativeColumnVector *result = + new NativeColumnVector(result_type, hash_table_concrete.numEntries()); HashTableAggregateFinalizer<HandleT, NativeColumnVector> finalizer( - handle, - group_by_keys, - result); + handle, group_by_keys, result); hash_table_concrete.forEachCompositeKeyFast(&finalizer, index); return result; } else { - IndirectColumnVector *result = new IndirectColumnVector(result_type, - hash_table_concrete.numEntries()); + IndirectColumnVector *result = new IndirectColumnVector( + result_type, hash_table_concrete.numEntries()); HashTableAggregateFinalizer<HandleT, IndirectColumnVector> finalizer( - handle, - group_by_keys, - result); + handle, group_by_keys, result); hash_table_concrete.forEachCompositeKeyFast(&finalizer, index); return result; } } else { if (NativeColumnVector::UsableForType(result_type)) { - NativeColumnVector *result = new NativeColumnVector(result_type, - group_by_keys->size()); + NativeColumnVector *result = + new NativeColumnVector(result_type, group_by_keys->size()); for (const std::vector<TypedValue> &group_by_key : *group_by_keys) { - result->appendTypedValue(finalizeGroupInHashTableFast<HandleT, HashTableT>(hash_table, - group_by_key, - index)); + result->appendTypedValue( + finalizeGroupInHashTableFast<HandleT, HashTableT>( + hash_table, group_by_key, index)); } return result; } else { - IndirectColumnVector *result = new IndirectColumnVector(result_type, - hash_table_concrete.numEntries()); + IndirectColumnVector *result = new IndirectColumnVector( + result_type, hash_table_concrete.numEntries()); for (const std::vector<TypedValue> &group_by_key : *group_by_keys) { - result->appendTypedValue(finalizeGroupInHashTableFast<HandleT, HashTableT>(hash_table, - group_by_key, - index)); + result->appendTypedValue( + finalizeGroupInHashTableFast<HandleT, HashTableT>( + hash_table, group_by_key, index)); } return result; } http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/c123bd49/expressions/aggregation/AggregationHandle.hpp ---------------------------------------------------------------------- diff --git a/expressions/aggregation/AggregationHandle.hpp b/expressions/aggregation/AggregationHandle.hpp index 01e3d20..d2cee6d 100644 --- a/expressions/aggregation/AggregationHandle.hpp +++ b/expressions/aggregation/AggregationHandle.hpp @@ -40,7 +40,6 @@ class ValueAccessor; * @{ */ - /** * @brief Abstract base class for aggregation state. **/ @@ -107,8 +106,7 @@ class AggregationHandle { * @brief Virtual destructor. * **/ - virtual ~AggregationHandle() { - } + virtual ~AggregationHandle() {} /** * @brief Create an initial "blank" state for this aggregation. @@ -136,7 +134,7 @@ class AggregationHandle { **/ virtual AggregationStateHashTableBase* createGroupByHashTable( const HashTableImplType hash_table_impl, - const std::vector<const Type*> &group_by_types, + const std::vector<const Type *> &group_by_types, const std::size_t estimated_num_groups, StorageManager *storage_manager) const = 0; @@ -167,7 +165,8 @@ class AggregationHandle { * for deleting the returned AggregationState. **/ virtual AggregationState* accumulateColumnVectors( - const std::vector<std::unique_ptr<ColumnVector>> &column_vectors) const = 0; + const std::vector<std::unique_ptr<ColumnVector>> &column_vectors) + const = 0; #ifdef QUICKSTEP_ENABLE_VECTOR_COPY_ELISION_SELECTION /** @@ -269,7 +268,8 @@ class AggregationHandle { int index) const = 0; /** - * @brief Create a new HashTable for the distinctify step for DISTINCT aggregation. + * @brief Create a new HashTable for the distinctify step for DISTINCT + * aggregation. * * Distinctify is the first step for DISTINCT aggregation. This step inserts * the GROUP BY expression values and aggregation arguments together as keys @@ -282,7 +282,8 @@ class AggregationHandle { * we simply treat it as a special GROUP BY case that the GROUP BY expression * vector is empty. * - * @param hash_table_impl The choice of which concrete HashTable implementation + * @param hash_table_impl The choice of which concrete HashTable + * implementation * to use. * @param key_types The types of the GROUP BY expressions together with the * types of the aggregation arguments. @@ -292,14 +293,15 @@ class AggregationHandle { * This is an estimate only, and the HashTable will be resized if it * becomes over-full. * @param storage_manager The StorageManager to use to create the HashTable. - * A StorageBlob will be allocated to serve as the HashTable's in-memory + * A StorageBlob will be allocated to serve as the HashTable's + * in-memory * storage. * @return A new HashTable instance with the appropriate state type for this * aggregate as the ValueT. */ virtual AggregationStateHashTableBase* createDistinctifyHashTable( const HashTableImplType hash_table_impl, - const std::vector<const Type*> &key_types, + const std::vector<const Type *> &key_types, const std::size_t estimated_num_distinct_keys, StorageManager *storage_manager) const = 0; @@ -307,11 +309,13 @@ class AggregationHandle { * @brief Inserts the GROUP BY expressions and aggregation arguments together * as keys into the distinctify hash table. * - * @param accessor The ValueAccessor that will be iterated over to read tuples. + * @param accessor The ValueAccessor that will be iterated over to read + * tuples. * @param key_ids The attribute_ids of the GROUP BY expressions in accessor * together with the attribute_ids of the arguments to this aggregate * in accessor, in order. - * @param distinctify_hash_table The HashTable to store the GROUP BY expressions + * @param distinctify_hash_table The HashTable to store the GROUP BY + * expressions * and the aggregation arguments together as hash table keys and a bool * constant \c true as hash table value (So the hash table actually * serves as a hash set). This should have been created by calling @@ -340,7 +344,8 @@ class AggregationHandle { * @brief Perform GROUP BY aggregation on the keys from the distinctify hash * table and upserts states into the aggregation hash table. * - * @param distinctify_hash_table Hash table which stores the GROUP BY expression + * @param distinctify_hash_table Hash table which stores the GROUP BY + * expression * values and aggregation arguments together as hash table keys. * @param aggregation_hash_table The HashTable to upsert AggregationStates in. * This should have been created by calling createGroupByHashTable() on @@ -349,18 +354,19 @@ class AggregationHandle { virtual void aggregateOnDistinctifyHashTableForGroupBy( const AggregationStateHashTableBase &distinctify_hash_table, AggregationStateHashTableBase *aggregation_hash_table, - int index) const = 0; + std::size_t index) const = 0; - virtual size_t getPayloadSize() const {return 1;} - virtual void iterateInlFast(const std::vector<TypedValue> &arguments, uint8_t *byte_ptr) const {} - virtual void mergeStatesFast(const uint8_t *src, uint8_t *dst) const {} - virtual void initPayload(uint8_t *byte_ptr) const {} - virtual void BlockUpdate() {} - virtual void AllowUpdate() {} + virtual std::size_t getPayloadSize() const { return 1; } + virtual void updateState(const std::vector<TypedValue> &arguments, + std::uint8_t *byte_ptr) const {} + virtual void mergeStatesFast(const std::uint8_t *src, + std::uint8_t *dst) const {} + virtual void initPayload(std::uint8_t *byte_ptr) const {} + virtual void blockUpdate() {} + virtual void allowUpdate() {} protected: - AggregationHandle() { - } + AggregationHandle() {} private: DISALLOW_COPY_AND_ASSIGN(AggregationHandle); http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/c123bd49/expressions/aggregation/AggregationHandleAvg.cpp ---------------------------------------------------------------------- diff --git a/expressions/aggregation/AggregationHandleAvg.cpp b/expressions/aggregation/AggregationHandleAvg.cpp index b27888f..2481092 100644 --- a/expressions/aggregation/AggregationHandleAvg.cpp +++ b/expressions/aggregation/AggregationHandleAvg.cpp @@ -42,7 +42,7 @@ namespace quickstep { class StorageManager; AggregationHandleAvg::AggregationHandleAvg(const Type &type) - : argument_type_(type), block_update(false) { + : argument_type_(type), block_update_(false) { // We sum Int as Long and Float as Double so that we have more headroom when // adding many values. TypeID type_precision_id; @@ -76,26 +76,24 @@ AggregationHandleAvg::AggregationHandleAvg(const Type &type) // Divide operator for dividing sum by count to get final average. divide_operator_.reset( BinaryOperationFactory::GetBinaryOperation(BinaryOperationID::kDivide) - .makeUncheckedBinaryOperatorForTypes(sum_type, TypeFactory::GetType(kDouble))); + .makeUncheckedBinaryOperatorForTypes(sum_type, + TypeFactory::GetType(kDouble))); // Result is nullable, because AVG() over 0 values (or all NULL values) is // NULL. - result_type_ - = &(BinaryOperationFactory::GetBinaryOperation(BinaryOperationID::kDivide) - .resultTypeForArgumentTypes(sum_type, TypeFactory::GetType(kDouble)) - ->getNullableVersion()); + result_type_ = + &(BinaryOperationFactory::GetBinaryOperation(BinaryOperationID::kDivide) + .resultTypeForArgumentTypes(sum_type, TypeFactory::GetType(kDouble)) + ->getNullableVersion()); } AggregationStateHashTableBase* AggregationHandleAvg::createGroupByHashTable( const HashTableImplType hash_table_impl, - const std::vector<const Type*> &group_by_types, + const std::vector<const Type *> &group_by_types, const std::size_t estimated_num_groups, StorageManager *storage_manager) const { return AggregationStateHashTableFactory<AggregationStateAvg>::CreateResizable( - hash_table_impl, - group_by_types, - estimated_num_groups, - storage_manager); + hash_table_impl, group_by_types, estimated_num_groups, storage_manager); } AggregationState* AggregationHandleAvg::accumulateColumnVectors( @@ -105,9 +103,8 @@ AggregationState* AggregationHandleAvg::accumulateColumnVectors( AggregationStateAvg *state = new AggregationStateAvg(blank_state_); std::size_t count = 0; - state->sum_ = fast_add_operator_->accumulateColumnVector(state->sum_, - *column_vectors.front(), - &count); + state->sum_ = fast_add_operator_->accumulateColumnVector( + state->sum_, *column_vectors.front(), &count); state->count_ = count; return state; } @@ -121,10 +118,8 @@ AggregationState* AggregationHandleAvg::accumulateValueAccessor( AggregationStateAvg *state = new AggregationStateAvg(blank_state_); std::size_t count = 0; - state->sum_ = fast_add_operator_->accumulateValueAccessor(state->sum_, - accessor, - accessor_ids.front(), - &count); + state->sum_ = fast_add_operator_->accumulateValueAccessor( + state->sum_, accessor, accessor_ids.front(), &count); state->count_ = count; return state; } @@ -139,40 +134,44 @@ void AggregationHandleAvg::aggregateValueAccessorIntoHashTable( << "Got wrong number of arguments for AVG: " << argument_ids.size(); } -void AggregationHandleAvg::mergeStates( - const AggregationState &source, - AggregationState *destination) const { - const AggregationStateAvg &avg_source = static_cast<const AggregationStateAvg&>(source); - AggregationStateAvg *avg_destination = static_cast<AggregationStateAvg*>(destination); +void AggregationHandleAvg::mergeStates(const AggregationState &source, + AggregationState *destination) const { + const AggregationStateAvg &avg_source = + static_cast<const AggregationStateAvg &>(source); + AggregationStateAvg *avg_destination = + static_cast<AggregationStateAvg *>(destination); SpinMutexLock lock(avg_destination->mutex_); avg_destination->count_ += avg_source.count_; - avg_destination->sum_ = merge_add_operator_->applyToTypedValues(avg_destination->sum_, - avg_source.sum_); + avg_destination->sum_ = merge_add_operator_->applyToTypedValues( + avg_destination->sum_, avg_source.sum_); } -void AggregationHandleAvg::mergeStatesFast( - const uint8_t *source, - uint8_t *destination) const { - const TypedValue *src_sum_ptr = reinterpret_cast<const TypedValue *>(source + blank_state_.sum_offset); - const std::int64_t *src_count_ptr = reinterpret_cast<const std::int64_t *>(source + blank_state_.count_offset); - TypedValue *dst_sum_ptr = reinterpret_cast<TypedValue *>(destination+blank_state_.sum_offset); - std::int64_t *dst_count_ptr = reinterpret_cast<std::int64_t *>(destination + blank_state_.count_offset); - (*dst_count_ptr) += (*src_count_ptr); - *dst_sum_ptr = merge_add_operator_->applyToTypedValues(*dst_sum_ptr, *src_sum_ptr); +void AggregationHandleAvg::mergeStatesFast(const std::uint8_t *source, + std::uint8_t *destination) const { + const TypedValue *src_sum_ptr = + reinterpret_cast<const TypedValue *>(source + blank_state_.sum_offset_); + const std::int64_t *src_count_ptr = reinterpret_cast<const std::int64_t *>( + source + blank_state_.count_offset_); + TypedValue *dst_sum_ptr = + reinterpret_cast<TypedValue *>(destination + blank_state_.sum_offset_); + std::int64_t *dst_count_ptr = reinterpret_cast<std::int64_t *>( + destination + blank_state_.count_offset_); + (*dst_count_ptr) += (*src_count_ptr); + *dst_sum_ptr = + merge_add_operator_->applyToTypedValues(*dst_sum_ptr, *src_sum_ptr); } - - TypedValue AggregationHandleAvg::finalize(const AggregationState &state) const { - const AggregationStateAvg &agg_state = static_cast<const AggregationStateAvg&>(state); + const AggregationStateAvg &agg_state = + static_cast<const AggregationStateAvg &>(state); if (agg_state.count_ == 0) { // AVG() over no values is NULL. return result_type_->makeNullValue(); } else { // Divide sum by count to get final average. - return divide_operator_->applyToTypedValues(agg_state.sum_, - TypedValue(static_cast<double>(agg_state.count_))); + return divide_operator_->applyToTypedValues( + agg_state.sum_, TypedValue(static_cast<double>(agg_state.count_))); } } @@ -181,31 +180,26 @@ ColumnVector* AggregationHandleAvg::finalizeHashTable( std::vector<std::vector<TypedValue>> *group_by_keys, int index) const { return finalizeHashTableHelperFast<AggregationHandleAvg, - AggregationStateFastHashTable>( - *result_type_, - hash_table, - group_by_keys, - index); + AggregationStateFastHashTable>( + *result_type_, hash_table, group_by_keys, index); } -AggregationState* AggregationHandleAvg::aggregateOnDistinctifyHashTableForSingle( +AggregationState* +AggregationHandleAvg::aggregateOnDistinctifyHashTableForSingle( const AggregationStateHashTableBase &distinctify_hash_table) const { return aggregateOnDistinctifyHashTableForSingleUnaryHelperFast< AggregationHandleAvg, - AggregationStateAvg>( - distinctify_hash_table); + AggregationStateAvg>(distinctify_hash_table); } void AggregationHandleAvg::aggregateOnDistinctifyHashTableForGroupBy( const AggregationStateHashTableBase &distinctify_hash_table, AggregationStateHashTableBase *aggregation_hash_table, - int index) const { + std::size_t index) const { aggregateOnDistinctifyHashTableForGroupByUnaryHelperFast< AggregationHandleAvg, AggregationStateFastHashTable>( - distinctify_hash_table, - aggregation_hash_table, - index); + distinctify_hash_table, aggregation_hash_table, index); } } // namespace quickstep http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/c123bd49/expressions/aggregation/AggregationHandleAvg.hpp ---------------------------------------------------------------------- diff --git a/expressions/aggregation/AggregationHandleAvg.hpp b/expressions/aggregation/AggregationHandleAvg.hpp index d134620..3e49213 100644 --- a/expressions/aggregation/AggregationHandleAvg.hpp +++ b/expressions/aggregation/AggregationHandleAvg.hpp @@ -28,8 +28,8 @@ #include "catalog/CatalogTypedefs.hpp" #include "expressions/aggregation/AggregationConcreteHandle.hpp" #include "expressions/aggregation/AggregationHandle.hpp" -#include "storage/HashTableBase.hpp" #include "storage/FastHashTable.hpp" +#include "storage/HashTableBase.hpp" #include "threading/SpinMutex.hpp" #include "types/Type.hpp" #include "types/TypedValue.hpp" @@ -59,30 +59,36 @@ class AggregationStateAvg : public AggregationState { AggregationStateAvg(const AggregationStateAvg &orig) : sum_(orig.sum_), count_(orig.count_), - sum_offset(orig.sum_offset), - count_offset(orig.count_offset), - mutex_offset(orig.mutex_offset) { - } + sum_offset_(orig.sum_offset_), + count_offset_(orig.count_offset_), + mutex_offset_(orig.mutex_offset_) {} /** * @brief Destructor. */ ~AggregationStateAvg() override {} - size_t getPayloadSize() const { - size_t p1 = reinterpret_cast<size_t>(&sum_); - size_t p2 = reinterpret_cast<size_t>(&mutex_); - return (p2-p1); + std::size_t getPayloadSize() const { + std::size_t p1 = reinterpret_cast<std::size_t>(&sum_); + std::size_t p2 = reinterpret_cast<std::size_t>(&mutex_); + return (p2 - p1); + } + + const std::uint8_t *getPayloadAddress() const { + return reinterpret_cast<const uint8_t *>(&sum_); } private: friend class AggregationHandleAvg; AggregationStateAvg() - : sum_(0), count_(0), sum_offset(0), - count_offset(reinterpret_cast<uint8_t *>(&count_)-reinterpret_cast<uint8_t *>(&sum_)), - mutex_offset(reinterpret_cast<uint8_t *>(&mutex_)-reinterpret_cast<uint8_t *>(&sum_)) { - } + : sum_(0), + count_(0), + sum_offset_(0), + count_offset_(reinterpret_cast<std::uint8_t *>(&count_) - + reinterpret_cast<std::uint8_t *>(&sum_)), + mutex_offset_(reinterpret_cast<std::uint8_t *>(&mutex_) - + reinterpret_cast<std::uint8_t *>(&sum_)) {} // TODO(shoban): We might want to specialize sum_ and count_ to use atomics // for int types similar to in AggregationStateCount. @@ -90,7 +96,7 @@ class AggregationStateAvg : public AggregationState { std::int64_t count_; SpinMutex mutex_; - int sum_offset, count_offset, mutex_offset; + int sum_offset_, count_offset_, mutex_offset_; }; /** @@ -98,8 +104,7 @@ class AggregationStateAvg : public AggregationState { **/ class AggregationHandleAvg : public AggregationConcreteHandle { public: - ~AggregationHandleAvg() override { - } + ~AggregationHandleAvg() override {} AggregationState* createInitialState() const override { return new AggregationStateAvg(blank_state_); @@ -107,14 +112,15 @@ class AggregationHandleAvg : public AggregationConcreteHandle { AggregationStateHashTableBase* createGroupByHashTable( const HashTableImplType hash_table_impl, - const std::vector<const Type*> &group_by_types, + const std::vector<const Type *> &group_by_types, const std::size_t estimated_num_groups, StorageManager *storage_manager) const override; /** * @brief Iterate method with average aggregation state. **/ - inline void iterateUnaryInl(AggregationStateAvg *state, const TypedValue &value) const { + inline void iterateUnaryInl(AggregationStateAvg *state, + const TypedValue &value) const { DCHECK(value.isPlausibleInstanceOf(argument_type_.getSignature())); if (value.isNull()) return; @@ -123,37 +129,41 @@ class AggregationHandleAvg : public AggregationConcreteHandle { ++state->count_; } - inline void iterateUnaryInlFast(const TypedValue &value, uint8_t *byte_ptr) const { + inline void iterateUnaryInlFast(const TypedValue &value, + std::uint8_t *byte_ptr) const { DCHECK(value.isPlausibleInstanceOf(argument_type_.getSignature())); if (value.isNull()) return; - TypedValue *sum_ptr = reinterpret_cast<TypedValue *>(byte_ptr + blank_state_.sum_offset); - std::int64_t *count_ptr = reinterpret_cast<std::int64_t *>(byte_ptr + blank_state_.count_offset); + TypedValue *sum_ptr = + reinterpret_cast<TypedValue *>(byte_ptr + blank_state_.sum_offset_); + std::int64_t *count_ptr = + reinterpret_cast<std::int64_t *>(byte_ptr + blank_state_.count_offset_); *sum_ptr = fast_add_operator_->applyToTypedValues(*sum_ptr, value); ++(*count_ptr); } - inline void iterateInlFast(const std::vector<TypedValue> &arguments, uint8_t *byte_ptr) const override { - if (block_update) return; - iterateUnaryInlFast(arguments.front(), byte_ptr); + inline void updateState(const std::vector<TypedValue> &arguments, + std::uint8_t *byte_ptr) const override { + if (!block_update_) { + iterateUnaryInlFast(arguments.front(), byte_ptr); + } } - void BlockUpdate() override { - block_update = true; - } + void blockUpdate() override { block_update_ = true; } - void AllowUpdate() override { - block_update = false; - } + void allowUpdate() override { block_update_ = false; } - void initPayload(uint8_t *byte_ptr) const override { - TypedValue *sum_ptr = reinterpret_cast<TypedValue *>(byte_ptr + blank_state_.sum_offset); - std::int64_t *count_ptr = reinterpret_cast<std::int64_t *>(byte_ptr + blank_state_.count_offset); + void initPayload(std::uint8_t *byte_ptr) const override { + TypedValue *sum_ptr = + reinterpret_cast<TypedValue *>(byte_ptr + blank_state_.sum_offset_); + std::int64_t *count_ptr = + reinterpret_cast<std::int64_t *>(byte_ptr + blank_state_.count_offset_); *sum_ptr = blank_state_.sum_; *count_ptr = blank_state_.count_; } AggregationState* accumulateColumnVectors( - const std::vector<std::unique_ptr<ColumnVector>> &column_vectors) const override; + const std::vector<std::unique_ptr<ColumnVector>> &column_vectors) + const override; #ifdef QUICKSTEP_ENABLE_VECTOR_COPY_ELISION_SELECTION AggregationState* accumulateValueAccessor( @@ -170,33 +180,32 @@ class AggregationHandleAvg : public AggregationConcreteHandle { void mergeStates(const AggregationState &source, AggregationState *destination) const override; - void mergeStatesFast(const uint8_t *source, - uint8_t *destination) const override; + void mergeStatesFast(const std::uint8_t *source, + std::uint8_t *destination) const override; TypedValue finalize(const AggregationState &state) const override; - inline TypedValue finalizeHashTableEntry(const AggregationState &state) const { - const AggregationStateAvg &agg_state = static_cast<const AggregationStateAvg&>(state); + inline TypedValue finalizeHashTableEntry( + const AggregationState &state) const { + const AggregationStateAvg &agg_state = + static_cast<const AggregationStateAvg &>(state); // TODO(chasseur): Could improve performance further if we made a special // version of finalizeHashTable() that collects all the sums into one // ColumnVector and all the counts into another and then applies // '*divide_operator_' to them in bulk. - return divide_operator_->applyToTypedValues(agg_state.sum_, - TypedValue(static_cast<double>(agg_state.count_))); + return divide_operator_->applyToTypedValues( + agg_state.sum_, TypedValue(static_cast<double>(agg_state.count_))); } - inline TypedValue finalizeHashTableEntryFast(const uint8_t *byte_ptr) const { -// const AggregationStateAvg &agg_state = static_cast<const AggregationStateAvg&>(state); - // TODO(chasseur): Could improve performance further if we made a special - // version of finalizeHashTable() that collects all the sums into one - // ColumnVector and all the counts into another and then applies - // '*divide_operator_' to them in bulk. - - uint8_t *value_ptr = const_cast<uint8_t*>(byte_ptr); - TypedValue *sum_ptr = reinterpret_cast<TypedValue *>(value_ptr + blank_state_.sum_offset); - std::int64_t *count_ptr = reinterpret_cast<std::int64_t *>(value_ptr + blank_state_.count_offset); - return divide_operator_->applyToTypedValues(*sum_ptr, - TypedValue(static_cast<double>(*count_ptr))); + inline TypedValue finalizeHashTableEntryFast( + const std::uint8_t *byte_ptr) const { + std::uint8_t *value_ptr = const_cast<std::uint8_t *>(byte_ptr); + TypedValue *sum_ptr = + reinterpret_cast<TypedValue *>(value_ptr + blank_state_.sum_offset_); + std::int64_t *count_ptr = reinterpret_cast<std::int64_t *>( + value_ptr + blank_state_.count_offset_); + return divide_operator_->applyToTypedValues( + *sum_ptr, TypedValue(static_cast<double>(*count_ptr))); } ColumnVector* finalizeHashTable( @@ -205,23 +214,26 @@ class AggregationHandleAvg : public AggregationConcreteHandle { int index) const override; /** - * @brief Implementation of AggregationHandle::aggregateOnDistinctifyHashTableForSingle() + * @brief Implementation of + * AggregationHandle::aggregateOnDistinctifyHashTableForSingle() * for AVG aggregation. */ AggregationState* aggregateOnDistinctifyHashTableForSingle( - const AggregationStateHashTableBase &distinctify_hash_table) const override; + const AggregationStateHashTableBase &distinctify_hash_table) + const override; /** - * @brief Implementation of AggregationHandle::aggregateOnDistinctifyHashTableForGroupBy() + * @brief Implementation of + * AggregationHandle::aggregateOnDistinctifyHashTableForGroupBy() * for AVG aggregation. */ void aggregateOnDistinctifyHashTableForGroupBy( const AggregationStateHashTableBase &distinctify_hash_table, AggregationStateHashTableBase *aggregation_hash_table, - int index) const override; + std::size_t index) const override; - size_t getPayloadSize() const override { - return blank_state_.getPayloadSize(); + std::size_t getPayloadSize() const override { + return blank_state_.getPayloadSize(); } private: @@ -241,7 +253,7 @@ class AggregationHandleAvg : public AggregationConcreteHandle { std::unique_ptr<UncheckedBinaryOperator> merge_add_operator_; std::unique_ptr<UncheckedBinaryOperator> divide_operator_; - bool block_update; + bool block_update_; DISALLOW_COPY_AND_ASSIGN(AggregationHandleAvg); }; http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/c123bd49/expressions/aggregation/AggregationHandleCount.cpp ---------------------------------------------------------------------- diff --git a/expressions/aggregation/AggregationHandleCount.cpp b/expressions/aggregation/AggregationHandleCount.cpp index aff3c28..d690f71 100644 --- a/expressions/aggregation/AggregationHandleCount.cpp +++ b/expressions/aggregation/AggregationHandleCount.cpp @@ -49,48 +49,50 @@ class ValueAccessor; template <bool count_star, bool nullable_type> AggregationStateHashTableBase* - AggregationHandleCount<count_star, nullable_type>::createGroupByHashTable( - const HashTableImplType hash_table_impl, - const std::vector<const Type*> &group_by_types, - const std::size_t estimated_num_groups, - StorageManager *storage_manager) const { - return AggregationStateHashTableFactory<AggregationStateCount>::CreateResizable( - hash_table_impl, - group_by_types, - estimated_num_groups, - storage_manager); +AggregationHandleCount<count_star, nullable_type>::createGroupByHashTable( + const HashTableImplType hash_table_impl, + const std::vector<const Type *> &group_by_types, + const std::size_t estimated_num_groups, + StorageManager *storage_manager) const { + return AggregationStateHashTableFactory< + AggregationStateCount>::CreateResizable(hash_table_impl, + group_by_types, + estimated_num_groups, + storage_manager); } template <bool count_star, bool nullable_type> AggregationState* - AggregationHandleCount<count_star, nullable_type>::accumulateColumnVectors( - const std::vector<std::unique_ptr<ColumnVector>> &column_vectors) const { +AggregationHandleCount<count_star, nullable_type>::accumulateColumnVectors( + const std::vector<std::unique_ptr<ColumnVector>> &column_vectors) const { DCHECK(!count_star) << "Called non-nullary accumulation method on an AggregationHandleCount " << "set up for nullary COUNT(*)"; DCHECK_EQ(1u, column_vectors.size()) - << "Got wrong number of ColumnVectors for COUNT: " << column_vectors.size(); + << "Got wrong number of ColumnVectors for COUNT: " + << column_vectors.size(); std::size_t count = 0; InvokeOnColumnVector( *column_vectors.front(), [&](const auto &column_vector) -> void { // NOLINT(build/c++11) - if (nullable_type) { - // TODO(shoban): Iterating over the ColumnVector is a rather slow way to - // do this. We should look at extending the ColumnVector interface to do - // a quick count of the non-null values (i.e. the length minus the - // population count of the null bitmap). We should do something similar - // for ValueAccessor too. - for (std::size_t pos = 0; - pos < column_vector.size(); - ++pos) { - count += !column_vector.getTypedValue(pos).isNull(); - } - } else { - count = column_vector.size(); - } - }); + if (nullable_type) { + // TODO(shoban): Iterating over the ColumnVector is a rather slow way + // to + // do this. We should look at extending the ColumnVector interface to + // do + // a quick count of the non-null values (i.e. the length minus the + // population count of the null bitmap). We should do something + // similar + // for ValueAccessor too. + for (std::size_t pos = 0; pos < column_vector.size(); ++pos) { + count += !column_vector.getTypedValue(pos).isNull(); + } + } else { + count = column_vector.size(); + } + }); return new AggregationStateCount(count); } @@ -98,9 +100,9 @@ AggregationState* #ifdef QUICKSTEP_ENABLE_VECTOR_COPY_ELISION_SELECTION template <bool count_star, bool nullable_type> AggregationState* - AggregationHandleCount<count_star, nullable_type>::accumulateValueAccessor( - ValueAccessor *accessor, - const std::vector<attribute_id> &accessor_ids) const { +AggregationHandleCount<count_star, nullable_type>::accumulateValueAccessor( + ValueAccessor *accessor, + const std::vector<attribute_id> &accessor_ids) const { DCHECK(!count_star) << "Called non-nullary accumulation method on an AggregationHandleCount " << "set up for nullary COUNT(*)"; @@ -113,28 +115,30 @@ AggregationState* InvokeOnValueAccessorMaybeTupleIdSequenceAdapter( accessor, [&accessor_id, &count](auto *accessor) -> void { // NOLINT(build/c++11) - if (nullable_type) { - while (accessor->next()) { - count += !accessor->getTypedValue(accessor_id).isNull(); - } - } else { - count = accessor->getNumTuples(); - } - }); + if (nullable_type) { + while (accessor->next()) { + count += !accessor->getTypedValue(accessor_id).isNull(); + } + } else { + count = accessor->getNumTuples(); + } + }); return new AggregationStateCount(count); } #endif template <bool count_star, bool nullable_type> - void AggregationHandleCount<count_star, nullable_type>::aggregateValueAccessorIntoHashTable( +void AggregationHandleCount<count_star, nullable_type>:: + aggregateValueAccessorIntoHashTable( ValueAccessor *accessor, const std::vector<attribute_id> &argument_ids, const std::vector<attribute_id> &group_by_key_ids, AggregationStateHashTableBase *hash_table) const { if (count_star) { DCHECK_EQ(0u, argument_ids.size()) - << "Got wrong number of arguments for COUNT(*): " << argument_ids.size(); + << "Got wrong number of arguments for COUNT(*): " + << argument_ids.size(); } else { DCHECK_EQ(1u, argument_ids.size()) << "Got wrong number of arguments for COUNT: " << argument_ids.size(); @@ -142,62 +146,60 @@ template <bool count_star, bool nullable_type> } template <bool count_star, bool nullable_type> - void AggregationHandleCount<count_star, nullable_type>::mergeStates( - const AggregationState &source, - AggregationState *destination) const { - const AggregationStateCount &count_source = static_cast<const AggregationStateCount&>(source); - AggregationStateCount *count_destination = static_cast<AggregationStateCount*>(destination); - - count_destination->count_.fetch_add(count_source.count_.load(std::memory_order_relaxed), - std::memory_order_relaxed); +void AggregationHandleCount<count_star, nullable_type>::mergeStates( + const AggregationState &source, AggregationState *destination) const { + const AggregationStateCount &count_source = + static_cast<const AggregationStateCount &>(source); + AggregationStateCount *count_destination = + static_cast<AggregationStateCount *>(destination); + + count_destination->count_.fetch_add( + count_source.count_.load(std::memory_order_relaxed), + std::memory_order_relaxed); } template <bool count_star, bool nullable_type> void AggregationHandleCount<count_star, nullable_type>::mergeStatesFast( - const uint8_t *source, - uint8_t *destination) const { - const std::int64_t *src_count_ptr = reinterpret_cast<const std::int64_t *>(source); - std::int64_t *dst_count_ptr = reinterpret_cast<std::int64_t *>(destination); - (*dst_count_ptr) += (*src_count_ptr); + const std::uint8_t *source, std::uint8_t *destination) const { + const std::int64_t *src_count_ptr = + reinterpret_cast<const std::int64_t *>(source); + std::int64_t *dst_count_ptr = reinterpret_cast<std::int64_t *>(destination); + (*dst_count_ptr) += (*src_count_ptr); } template <bool count_star, bool nullable_type> - ColumnVector* AggregationHandleCount<count_star, nullable_type>::finalizeHashTable( - const AggregationStateHashTableBase &hash_table, - std::vector<std::vector<TypedValue>> *group_by_keys, - int index) const { - return finalizeHashTableHelperFast<AggregationHandleCount<count_star, nullable_type>, - AggregationStateFastHashTable>( - TypeFactory::GetType(kLong), - hash_table, - group_by_keys, - index); +ColumnVector* +AggregationHandleCount<count_star, nullable_type>::finalizeHashTable( + const AggregationStateHashTableBase &hash_table, + std::vector<std::vector<TypedValue>> *group_by_keys, + int index) const { + return finalizeHashTableHelperFast< + AggregationHandleCount<count_star, nullable_type>, + AggregationStateFastHashTable>( + TypeFactory::GetType(kLong), hash_table, group_by_keys, index); } template <bool count_star, bool nullable_type> -AggregationState* AggregationHandleCount<count_star, nullable_type> - ::aggregateOnDistinctifyHashTableForSingle( +AggregationState* AggregationHandleCount<count_star, nullable_type>:: + aggregateOnDistinctifyHashTableForSingle( const AggregationStateHashTableBase &distinctify_hash_table) const { DCHECK_EQ(count_star, false); return aggregateOnDistinctifyHashTableForSingleUnaryHelperFast< AggregationHandleCount<count_star, nullable_type>, - AggregationStateCount>( - distinctify_hash_table); + AggregationStateCount>(distinctify_hash_table); } template <bool count_star, bool nullable_type> -void AggregationHandleCount<count_star, nullable_type> - ::aggregateOnDistinctifyHashTableForGroupBy( +void AggregationHandleCount<count_star, nullable_type>:: + aggregateOnDistinctifyHashTableForGroupBy( const AggregationStateHashTableBase &distinctify_hash_table, AggregationStateHashTableBase *aggregation_hash_table, - int index) const { + std::size_t index) const { DCHECK_EQ(count_star, false); aggregateOnDistinctifyHashTableForGroupByUnaryHelperFast< AggregationHandleCount<count_star, nullable_type>, AggregationStateFastHashTable>( - distinctify_hash_table, - aggregation_hash_table, - index); + distinctify_hash_table, aggregation_hash_table, index); } // Explicitly instantiate and compile in the different versions of http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/c123bd49/expressions/aggregation/AggregationHandleCount.hpp ---------------------------------------------------------------------- diff --git a/expressions/aggregation/AggregationHandleCount.hpp b/expressions/aggregation/AggregationHandleCount.hpp index 2beb0e2..2c6d717 100644 --- a/expressions/aggregation/AggregationHandleCount.hpp +++ b/expressions/aggregation/AggregationHandleCount.hpp @@ -29,8 +29,8 @@ #include "catalog/CatalogTypedefs.hpp" #include "expressions/aggregation/AggregationConcreteHandle.hpp" #include "expressions/aggregation/AggregationHandle.hpp" -#include "storage/HashTableBase.hpp" #include "storage/FastHashTable.hpp" +#include "storage/HashTableBase.hpp" #include "types/TypedValue.hpp" #include "utility/Macros.hpp" @@ -41,7 +41,8 @@ class StorageManager; class Type; class ValueAccessor; -template <bool, bool> class AggregationHandleCount; +template <bool, bool> +class AggregationHandleCount; /** \addtogroup Expressions * @{ @@ -63,8 +64,10 @@ class AggregationStateCount : public AggregationState { */ ~AggregationStateCount() override {} - size_t getPayloadSize() const { - return sizeof(count_); + std::size_t getPayloadSize() const { return sizeof(count_); } + + const std::uint8_t* getPayloadAddress() const { + return reinterpret_cast<const uint8_t *>(&count_); } private: @@ -73,13 +76,10 @@ class AggregationStateCount : public AggregationState { friend class AggregationHandleCount<true, false>; friend class AggregationHandleCount<true, true>; - AggregationStateCount() - : count_(0) { - } + AggregationStateCount() : count_(0) {} explicit AggregationStateCount(const std::int64_t initial_count) - : count_(initial_count) { - } + : count_(initial_count) {} std::atomic<std::int64_t> count_; }; @@ -96,16 +96,15 @@ class AggregationStateCount : public AggregationState { template <bool count_star, bool nullable_type> class AggregationHandleCount : public AggregationConcreteHandle { public: - ~AggregationHandleCount() override { - } + ~AggregationHandleCount() override {} AggregationState* createInitialState() const override { return new AggregationStateCount(); } - AggregationStateHashTableBase* createGroupByHashTable( + AggregationStateHashTableBase *createGroupByHashTable( const HashTableImplType hash_table_impl, - const std::vector<const Type*> &group_by_types, + const std::vector<const Type *> &group_by_types, const std::size_t estimated_num_groups, StorageManager *storage_manager) const override; @@ -113,54 +112,56 @@ class AggregationHandleCount : public AggregationConcreteHandle { state->count_.fetch_add(1, std::memory_order_relaxed); } - inline void iterateNullaryInlFast(uint8_t *byte_ptr) const { - std::int64_t *count_ptr = reinterpret_cast<std::int64_t *>(byte_ptr); - (*count_ptr)++; + inline void iterateNullaryInlFast(std::uint8_t *byte_ptr) const { + std::int64_t *count_ptr = reinterpret_cast<std::int64_t *>(byte_ptr); + (*count_ptr)++; } /** * @brief Iterate with count aggregation state. */ - inline void iterateUnaryInl(AggregationStateCount *state, const TypedValue &value) const { + inline void iterateUnaryInl(AggregationStateCount *state, + const TypedValue &value) const { if ((!nullable_type) || (!value.isNull())) { state->count_.fetch_add(1, std::memory_order_relaxed); } } - inline void iterateUnaryInlFast(const TypedValue &value, uint8_t *byte_ptr) const { + inline void iterateUnaryInlFast(const TypedValue &value, + std::uint8_t *byte_ptr) const { if ((!nullable_type) || (!value.isNull())) { std::int64_t *count_ptr = reinterpret_cast<std::int64_t *>(byte_ptr); (*count_ptr)++; } } - inline void iterateInlFast(const std::vector<TypedValue> &arguments, uint8_t *byte_ptr) const override { - if (block_update) return; - if (arguments.size()) - iterateUnaryInlFast(arguments.front(), byte_ptr); - else - iterateNullaryInlFast(byte_ptr); + inline void updateState(const std::vector<TypedValue> &arguments, + std::uint8_t *byte_ptr) const override { + if (!block_update_) { + if (arguments.size()) + iterateUnaryInlFast(arguments.front(), byte_ptr); + else + iterateNullaryInlFast(byte_ptr); + } } - void BlockUpdate() override { - block_update = true; - } + void blockUpdate() override { block_update_ = true; } - void AllowUpdate() override { - block_update = false; - } + void allowUpdate() override { block_update_ = false; } - void initPayload(uint8_t *byte_ptr) const override { - std::int64_t *count_ptr = reinterpret_cast<std::int64_t *>(byte_ptr); - *count_ptr = 0; + void initPayload(std::uint8_t *byte_ptr) const override { + std::int64_t *count_ptr = reinterpret_cast<std::int64_t *>(byte_ptr); + *count_ptr = 0; } - AggregationState* accumulateNullary(const std::size_t num_tuples) const override { + AggregationState* accumulateNullary( + const std::size_t num_tuples) const override { return new AggregationStateCount(num_tuples); } AggregationState* accumulateColumnVectors( - const std::vector<std::unique_ptr<ColumnVector>> &column_vectors) const override; + const std::vector<std::unique_ptr<ColumnVector>> &column_vectors) + const override; #ifdef QUICKSTEP_ENABLE_VECTOR_COPY_ELISION_SELECTION AggregationState* accumulateValueAccessor( @@ -177,25 +178,26 @@ class AggregationHandleCount : public AggregationConcreteHandle { void mergeStates(const AggregationState &source, AggregationState *destination) const override; - void mergeStatesFast(const uint8_t *source, - uint8_t *destination) const override; + void mergeStatesFast(const std::uint8_t *source, + std::uint8_t *destination) const override; TypedValue finalize(const AggregationState &state) const override { - return TypedValue(static_cast<const AggregationStateCount&>(state).count_.load(std::memory_order_relaxed)); + return TypedValue( + static_cast<const AggregationStateCount &>(state).count_.load( + std::memory_order_relaxed)); } - inline TypedValue finalizeHashTableEntry(const AggregationState &state) const { - return TypedValue(static_cast<const AggregationStateCount&>(state).count_.load(std::memory_order_relaxed)); + inline TypedValue finalizeHashTableEntry( + const AggregationState &state) const { + return TypedValue( + static_cast<const AggregationStateCount &>(state).count_.load( + std::memory_order_relaxed)); } - inline TypedValue finalizeHashTableEntryFast(const uint8_t *byte_ptr) const { -// const AggregationStateAvg &agg_state = static_cast<const AggregationStateAvg&>(state); - // TODO(chasseur): Could improve performance further if we made a special - // version of finalizeHashTable() that collects all the sums into one - // ColumnVector and all the counts into another and then applies - // '*divide_operator_' to them in bulk. - - const std::int64_t *count_ptr = reinterpret_cast<const std::int64_t *>(byte_ptr); + inline TypedValue finalizeHashTableEntryFast( + const std::uint8_t *byte_ptr) const { + const std::int64_t *count_ptr = + reinterpret_cast<const std::int64_t *>(byte_ptr); return TypedValue(*count_ptr); } @@ -205,24 +207,25 @@ class AggregationHandleCount : public AggregationConcreteHandle { int index) const override; /** - * @brief Implementation of AggregationHandle::aggregateOnDistinctifyHashTableForSingle() + * @brief Implementation of + * AggregationHandle::aggregateOnDistinctifyHashTableForSingle() * for SUM aggregation. */ AggregationState* aggregateOnDistinctifyHashTableForSingle( - const AggregationStateHashTableBase &distinctify_hash_table) const override; + const AggregationStateHashTableBase &distinctify_hash_table) + const override; /** - * @brief Implementation of AggregationHandle::aggregateOnDistinctifyHashTableForGroupBy() + * @brief Implementation of + * AggregationHandle::aggregateOnDistinctifyHashTableForGroupBy() * for SUM aggregation. */ void aggregateOnDistinctifyHashTableForGroupBy( const AggregationStateHashTableBase &distinctify_hash_table, AggregationStateHashTableBase *aggregation_hash_table, - int index) const override; + std::size_t index) const override; - size_t getPayloadSize() const override { - return sizeof(std::int64_t); - } + std::size_t getPayloadSize() const override { return sizeof(std::int64_t); } private: friend class AggregateFunctionCount; @@ -230,10 +233,9 @@ class AggregationHandleCount : public AggregationConcreteHandle { /** * @brief Constructor. **/ - AggregationHandleCount() : block_update(false) { - } + AggregationHandleCount() : block_update_(false) {} - bool block_update; + bool block_update_; DISALLOW_COPY_AND_ASSIGN(AggregationHandleCount); }; http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/c123bd49/expressions/aggregation/AggregationHandleDistinct.hpp ---------------------------------------------------------------------- diff --git a/expressions/aggregation/AggregationHandleDistinct.hpp b/expressions/aggregation/AggregationHandleDistinct.hpp index 978319b..838bfdd 100644 --- a/expressions/aggregation/AggregationHandleDistinct.hpp +++ b/expressions/aggregation/AggregationHandleDistinct.hpp @@ -49,27 +49,32 @@ class AggregationHandleDistinct : public AggregationConcreteHandle { /** * @brief Constructor. **/ - AggregationHandleDistinct() { - } + AggregationHandleDistinct() {} AggregationState* createInitialState() const override { - LOG(FATAL) << "AggregationHandleDistinct does not support createInitialState()."; + LOG(FATAL) + << "AggregationHandleDistinct does not support createInitialState()."; } - AggregationState* accumulateNullary(const std::size_t num_tuples) const override { - LOG(FATAL) << "AggregationHandleDistinct does not support accumulateNullary()."; + AggregationState* accumulateNullary( + const std::size_t num_tuples) const override { + LOG(FATAL) + << "AggregationHandleDistinct does not support accumulateNullary()."; } AggregationState* accumulateColumnVectors( - const std::vector<std::unique_ptr<ColumnVector>> &column_vectors) const override { - LOG(FATAL) << "AggregationHandleDistinct does not support accumulateColumnVectors()."; + const std::vector<std::unique_ptr<ColumnVector>> &column_vectors) + const override { + LOG(FATAL) << "AggregationHandleDistinct does not support " + "accumulateColumnVectors()."; } #ifdef QUICKSTEP_ENABLE_VECTOR_COPY_ELISION_SELECTION AggregationState* accumulateValueAccessor( ValueAccessor *accessor, const std::vector<attribute_id> &accessor_ids) const override { - LOG(FATAL) << "AggregationHandleDistinct does not support accumulateValueAccessor()."; + LOG(FATAL) << "AggregationHandleDistinct does not support " + "accumulateValueAccessor()."; } #endif @@ -83,7 +88,8 @@ class AggregationHandleDistinct : public AggregationConcreteHandle { } AggregationState* aggregateOnDistinctifyHashTableForSingle( - const AggregationStateHashTableBase &distinctify_hash_table) const override { + const AggregationStateHashTableBase &distinctify_hash_table) + const override { LOG(FATAL) << "AggregationHandleDistinct does not support " << "aggregateOnDistinctifyHashTableForSingle()."; } @@ -91,14 +97,14 @@ class AggregationHandleDistinct : public AggregationConcreteHandle { void aggregateOnDistinctifyHashTableForGroupBy( const AggregationStateHashTableBase &distinctify_hash_table, AggregationStateHashTableBase *groupby_hash_table, - int index) const override { + std::size_t index) const override { LOG(FATAL) << "AggregationHandleDistinct does not support " << "aggregateOnDistinctifyHashTableForGroupBy()."; } AggregationStateHashTableBase* createGroupByHashTable( const HashTableImplType hash_table_impl, - const std::vector<const Type*> &group_by_types, + const std::vector<const Type *> &group_by_types, const std::size_t estimated_num_groups, StorageManager *storage_manager) const override; http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/c123bd49/expressions/aggregation/AggregationHandleMax.cpp ---------------------------------------------------------------------- diff --git a/expressions/aggregation/AggregationHandleMax.cpp b/expressions/aggregation/AggregationHandleMax.cpp index ec3e671..c2d571b 100644 --- a/expressions/aggregation/AggregationHandleMax.cpp +++ b/expressions/aggregation/AggregationHandleMax.cpp @@ -39,22 +39,19 @@ namespace quickstep { class StorageManager; AggregationHandleMax::AggregationHandleMax(const Type &type) - : type_(type), block_update(false) { - fast_comparator_.reset(ComparisonFactory::GetComparison(ComparisonID::kGreater) - .makeUncheckedComparatorForTypes(type, - type.getNonNullableVersion())); + : type_(type), block_update_(false) { + fast_comparator_.reset( + ComparisonFactory::GetComparison(ComparisonID::kGreater) + .makeUncheckedComparatorForTypes(type, type.getNonNullableVersion())); } AggregationStateHashTableBase* AggregationHandleMax::createGroupByHashTable( const HashTableImplType hash_table_impl, - const std::vector<const Type*> &group_by_types, + const std::vector<const Type *> &group_by_types, const std::size_t estimated_num_groups, StorageManager *storage_manager) const { return AggregationStateHashTableFactory<AggregationStateMax>::CreateResizable( - hash_table_impl, - group_by_types, - estimated_num_groups, - storage_manager); + hash_table_impl, group_by_types, estimated_num_groups, storage_manager); } AggregationState* AggregationHandleMax::accumulateColumnVectors( @@ -62,9 +59,8 @@ AggregationState* AggregationHandleMax::accumulateColumnVectors( DCHECK_EQ(1u, column_vectors.size()) << "Got wrong number of ColumnVectors for MAX: " << column_vectors.size(); - return new AggregationStateMax( - fast_comparator_->accumulateColumnVector(type_.getNullableVersion().makeNullValue(), - *column_vectors.front())); + return new AggregationStateMax(fast_comparator_->accumulateColumnVector( + type_.getNullableVersion().makeNullValue(), *column_vectors.front())); } #ifdef QUICKSTEP_ENABLE_VECTOR_COPY_ELISION_SELECTION @@ -74,10 +70,10 @@ AggregationState* AggregationHandleMax::accumulateValueAccessor( DCHECK_EQ(1u, accessor_ids.size()) << "Got wrong number of attributes for MAX: " << accessor_ids.size(); - return new AggregationStateMax( - fast_comparator_->accumulateValueAccessor(type_.getNullableVersion().makeNullValue(), - accessor, - accessor_ids.front())); + return new AggregationStateMax(fast_comparator_->accumulateValueAccessor( + type_.getNullableVersion().makeNullValue(), + accessor, + accessor_ids.front())); } #endif // QUICKSTEP_ENABLE_VECTOR_COPY_ELISION_SELECTION @@ -90,24 +86,24 @@ void AggregationHandleMax::aggregateValueAccessorIntoHashTable( << "Got wrong number of arguments for MAX: " << argument_ids.size(); } -void AggregationHandleMax::mergeStates( - const AggregationState &source, - AggregationState *destination) const { - const AggregationStateMax &max_source = static_cast<const AggregationStateMax&>(source); - AggregationStateMax *max_destination = static_cast<AggregationStateMax*>(destination); +void AggregationHandleMax::mergeStates(const AggregationState &source, + AggregationState *destination) const { + const AggregationStateMax &max_source = + static_cast<const AggregationStateMax &>(source); + AggregationStateMax *max_destination = + static_cast<AggregationStateMax *>(destination); if (!max_source.max_.isNull()) { compareAndUpdate(max_destination, max_source.max_); } } -void AggregationHandleMax::mergeStatesFast( - const std::uint8_t *source, - std::uint8_t *destination) const { - const TypedValue *src_max_ptr = reinterpret_cast<const TypedValue *>(source); - TypedValue *dst_max_ptr = reinterpret_cast<TypedValue *>(destination); - if (!(src_max_ptr->isNull())) { - compareAndUpdateFast(dst_max_ptr, *src_max_ptr); +void AggregationHandleMax::mergeStatesFast(const std::uint8_t *source, + std::uint8_t *destination) const { + const TypedValue *src_max_ptr = reinterpret_cast<const TypedValue *>(source); + TypedValue *dst_max_ptr = reinterpret_cast<TypedValue *>(destination); + if (!(src_max_ptr->isNull())) { + compareAndUpdateFast(dst_max_ptr, *src_max_ptr); } } @@ -116,31 +112,26 @@ ColumnVector* AggregationHandleMax::finalizeHashTable( std::vector<std::vector<TypedValue>> *group_by_keys, int index) const { return finalizeHashTableHelperFast<AggregationHandleMax, - AggregationStateFastHashTable>( - type_.getNullableVersion(), - hash_table, - group_by_keys, - index); + AggregationStateFastHashTable>( + type_.getNullableVersion(), hash_table, group_by_keys, index); } -AggregationState* AggregationHandleMax::aggregateOnDistinctifyHashTableForSingle( +AggregationState* +AggregationHandleMax::aggregateOnDistinctifyHashTableForSingle( const AggregationStateHashTableBase &distinctify_hash_table) const { return aggregateOnDistinctifyHashTableForSingleUnaryHelperFast< AggregationHandleMax, - AggregationStateMax>( - distinctify_hash_table); + AggregationStateMax>(distinctify_hash_table); } void AggregationHandleMax::aggregateOnDistinctifyHashTableForGroupBy( const AggregationStateHashTableBase &distinctify_hash_table, AggregationStateHashTableBase *aggregation_hash_table, - int index) const { + std::size_t index) const { aggregateOnDistinctifyHashTableForGroupByUnaryHelperFast< AggregationHandleMax, AggregationStateFastHashTable>( - distinctify_hash_table, - aggregation_hash_table, - index); + distinctify_hash_table, aggregation_hash_table, index); } } // namespace quickstep http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/c123bd49/expressions/aggregation/AggregationHandleMax.hpp ---------------------------------------------------------------------- diff --git a/expressions/aggregation/AggregationHandleMax.hpp b/expressions/aggregation/AggregationHandleMax.hpp index c1a3a36..de173c9 100644 --- a/expressions/aggregation/AggregationHandleMax.hpp +++ b/expressions/aggregation/AggregationHandleMax.hpp @@ -28,8 +28,8 @@ #include "catalog/CatalogTypedefs.hpp" #include "expressions/aggregation/AggregationConcreteHandle.hpp" #include "expressions/aggregation/AggregationHandle.hpp" -#include "storage/HashTableBase.hpp" #include "storage/FastHashTable.hpp" +#include "storage/HashTableBase.hpp" #include "threading/SpinMutex.hpp" #include "types/Type.hpp" #include "types/TypedValue.hpp" @@ -56,25 +56,24 @@ class AggregationStateMax : public AggregationState { /** * @brief Copy constructor (ignores mutex). */ - AggregationStateMax(const AggregationStateMax &orig) - : max_(orig.max_) { - } + AggregationStateMax(const AggregationStateMax &orig) : max_(orig.max_) {} /** * @brief Destructor. */ - ~AggregationStateMax() override {}; + ~AggregationStateMax() override{}; + + const std::uint8_t* getPayloadAddress() const { + return reinterpret_cast<const uint8_t *>(&max_); + } private: friend class AggregationHandleMax; explicit AggregationStateMax(const Type &type) - : max_(type.getNullableVersion().makeNullValue()) { - } + : max_(type.getNullableVersion().makeNullValue()) {} - explicit AggregationStateMax(TypedValue &&value) - : max_(std::move(value)) { - } + explicit AggregationStateMax(TypedValue &&value) : max_(std::move(value)) {} TypedValue max_; SpinMutex mutex_; @@ -85,8 +84,7 @@ class AggregationStateMax : public AggregationState { **/ class AggregationHandleMax : public AggregationConcreteHandle { public: - ~AggregationHandleMax() override { - } + ~AggregationHandleMax() override {} AggregationState* createInitialState() const override { return new AggregationStateMax(type_); @@ -94,45 +92,46 @@ class AggregationHandleMax : public AggregationConcreteHandle { AggregationStateHashTableBase* createGroupByHashTable( const HashTableImplType hash_table_impl, - const std::vector<const Type*> &group_by_types, + const std::vector<const Type *> &group_by_types, const std::size_t estimated_num_groups, StorageManager *storage_manager) const override; /** * @brief Iterate with max aggregation state. */ - inline void iterateUnaryInl(AggregationStateMax *state, const TypedValue &value) const { + inline void iterateUnaryInl(AggregationStateMax *state, + const TypedValue &value) const { DCHECK(value.isPlausibleInstanceOf(type_.getSignature())); - compareAndUpdate(static_cast<AggregationStateMax*>(state), value); + compareAndUpdate(static_cast<AggregationStateMax *>(state), value); } - inline void iterateUnaryInlFast(const TypedValue &value, std::uint8_t *byte_ptr) const { + inline void iterateUnaryInlFast(const TypedValue &value, + std::uint8_t *byte_ptr) const { DCHECK(value.isPlausibleInstanceOf(type_.getSignature())); TypedValue *max_ptr = reinterpret_cast<TypedValue *>(byte_ptr); compareAndUpdateFast(max_ptr, value); } - inline void iterateInlFast(const std::vector<TypedValue> &arguments, uint8_t *byte_ptr) const override { - if (block_update) return; - iterateUnaryInlFast(arguments.front(), byte_ptr); + inline void updateState(const std::vector<TypedValue> &arguments, + std::uint8_t *byte_ptr) const override { + if (!block_update_) { + iterateUnaryInlFast(arguments.front(), byte_ptr); + } } - void BlockUpdate() override { - block_update = true; - } + void blockUpdate() override { block_update_ = true; } - void AllowUpdate() override { - block_update = false; - } + void allowUpdate() override { block_update_ = false; } - void initPayload(uint8_t *byte_ptr) const override { + void initPayload(std::uint8_t *byte_ptr) const override { TypedValue *max_ptr = reinterpret_cast<TypedValue *>(byte_ptr); TypedValue t1 = (type_.getNullableVersion().makeNullValue()); *max_ptr = t1; } AggregationState* accumulateColumnVectors( - const std::vector<std::unique_ptr<ColumnVector>> &column_vectors) const override; + const std::vector<std::unique_ptr<ColumnVector>> &column_vectors) + const override; #ifdef QUICKSTEP_ENABLE_VECTOR_COPY_ELISION_SELECTION AggregationState* accumulateValueAccessor( @@ -150,17 +149,19 @@ class AggregationHandleMax : public AggregationConcreteHandle { AggregationState *destination) const override; void mergeStatesFast(const std::uint8_t *source, - std::uint8_t *destination) const override; + std::uint8_t *destination) const override; TypedValue finalize(const AggregationState &state) const override { - return TypedValue(static_cast<const AggregationStateMax&>(state).max_); + return TypedValue(static_cast<const AggregationStateMax &>(state).max_); } - inline TypedValue finalizeHashTableEntry(const AggregationState &state) const { - return TypedValue(static_cast<const AggregationStateMax&>(state).max_); + inline TypedValue finalizeHashTableEntry( + const AggregationState &state) const { + return TypedValue(static_cast<const AggregationStateMax &>(state).max_); } - inline TypedValue finalizeHashTableEntryFast(const std::uint8_t *byte_ptr) const { + inline TypedValue finalizeHashTableEntryFast( + const std::uint8_t *byte_ptr) const { const TypedValue *max_ptr = reinterpret_cast<const TypedValue *>(byte_ptr); return TypedValue(*max_ptr); } @@ -171,25 +172,25 @@ class AggregationHandleMax : public AggregationConcreteHandle { int index) const override; /** - * @brief Implementation of AggregationHandle::aggregateOnDistinctifyHashTableForSingle() + * @brief Implementation of + * AggregationHandle::aggregateOnDistinctifyHashTableForSingle() * for MAX aggregation. */ AggregationState* aggregateOnDistinctifyHashTableForSingle( - const AggregationStateHashTableBase &distinctify_hash_table) const override; - + const AggregationStateHashTableBase &distinctify_hash_table) + const override; /** - * @brief Implementation of AggregationHandle::aggregateOnDistinctifyHashTableForGroupBy() + * @brief Implementation of + * AggregationHandle::aggregateOnDistinctifyHashTableForGroupBy() * for MAX aggregation. */ void aggregateOnDistinctifyHashTableForGroupBy( const AggregationStateHashTableBase &distinctify_hash_table, AggregationStateHashTableBase *aggregation_hash_table, - int index) const override; + std::size_t index) const override; - size_t getPayloadSize() const override { - return sizeof(TypedValue); - } + std::size_t getPayloadSize() const override { return sizeof(TypedValue); } private: friend class AggregateFunctionMax; @@ -202,24 +203,29 @@ class AggregationHandleMax : public AggregationConcreteHandle { explicit AggregationHandleMax(const Type &type); /** - * @brief compare the value with max_ and update it if the value is larger than + * @brief compare the value with max_ and update it if the value is larger + *than * current maximum. NULLs are ignored. * * @param value A TypedValue to compare **/ - inline void compareAndUpdate(AggregationStateMax *state, const TypedValue &value) const { + inline void compareAndUpdate(AggregationStateMax *state, + const TypedValue &value) const { // TODO(chasseur): Avoid null-checks when aggregating a non-nullable Type. if (value.isNull()) return; SpinMutexLock lock(state->mutex_); - if (state->max_.isNull() || fast_comparator_->compareTypedValues(value, state->max_)) { + if (state->max_.isNull() || + fast_comparator_->compareTypedValues(value, state->max_)) { state->max_ = value; } } - inline void compareAndUpdateFast(TypedValue *max_ptr, const TypedValue &value) const { + inline void compareAndUpdateFast(TypedValue *max_ptr, + const TypedValue &value) const { if (value.isNull()) return; - if (max_ptr->isNull() || fast_comparator_->compareTypedValues(value, *max_ptr)) { + if (max_ptr->isNull() || + fast_comparator_->compareTypedValues(value, *max_ptr)) { *max_ptr = value; } } @@ -227,7 +233,7 @@ class AggregationHandleMax : public AggregationConcreteHandle { const Type &type_; std::unique_ptr<UncheckedComparator> fast_comparator_; - bool block_update; + bool block_update_; DISALLOW_COPY_AND_ASSIGN(AggregationHandleMax); }; http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/c123bd49/expressions/aggregation/AggregationHandleMin.cpp ---------------------------------------------------------------------- diff --git a/expressions/aggregation/AggregationHandleMin.cpp b/expressions/aggregation/AggregationHandleMin.cpp index cc714a5..a07f299 100644 --- a/expressions/aggregation/AggregationHandleMin.cpp +++ b/expressions/aggregation/AggregationHandleMin.cpp @@ -39,22 +39,19 @@ namespace quickstep { class StorageManager; AggregationHandleMin::AggregationHandleMin(const Type &type) - : type_(type), block_update(false) { - fast_comparator_.reset(ComparisonFactory::GetComparison(ComparisonID::kLess) - .makeUncheckedComparatorForTypes(type, - type.getNonNullableVersion())); + : type_(type), block_update_(false) { + fast_comparator_.reset( + ComparisonFactory::GetComparison(ComparisonID::kLess) + .makeUncheckedComparatorForTypes(type, type.getNonNullableVersion())); } AggregationStateHashTableBase* AggregationHandleMin::createGroupByHashTable( const HashTableImplType hash_table_impl, - const std::vector<const Type*> &group_by_types, + const std::vector<const Type *> &group_by_types, const std::size_t estimated_num_groups, StorageManager *storage_manager) const { return AggregationStateHashTableFactory<AggregationStateMin>::CreateResizable( - hash_table_impl, - group_by_types, - estimated_num_groups, - storage_manager); + hash_table_impl, group_by_types, estimated_num_groups, storage_manager); } AggregationState* AggregationHandleMin::accumulateColumnVectors( @@ -62,9 +59,8 @@ AggregationState* AggregationHandleMin::accumulateColumnVectors( DCHECK_EQ(1u, column_vectors.size()) << "Got wrong number of ColumnVectors for MIN: " << column_vectors.size(); - return new AggregationStateMin( - fast_comparator_->accumulateColumnVector(type_.getNullableVersion().makeNullValue(), - *column_vectors.front())); + return new AggregationStateMin(fast_comparator_->accumulateColumnVector( + type_.getNullableVersion().makeNullValue(), *column_vectors.front())); } #ifdef QUICKSTEP_ENABLE_VECTOR_COPY_ELISION_SELECTION @@ -74,10 +70,10 @@ AggregationState* AggregationHandleMin::accumulateValueAccessor( DCHECK_EQ(1u, accessor_ids.size()) << "Got wrong number of attributes for MIN: " << accessor_ids.size(); - return new AggregationStateMin( - fast_comparator_->accumulateValueAccessor(type_.getNullableVersion().makeNullValue(), - accessor, - accessor_ids.front())); + return new AggregationStateMin(fast_comparator_->accumulateValueAccessor( + type_.getNullableVersion().makeNullValue(), + accessor, + accessor_ids.front())); } #endif // QUICKSTEP_ENABLE_VECTOR_COPY_ELISION_SELECTION @@ -90,26 +86,26 @@ void AggregationHandleMin::aggregateValueAccessorIntoHashTable( << "Got wrong number of arguments for MIN: " << argument_ids.size(); } -void AggregationHandleMin::mergeStates( - const AggregationState &source, - AggregationState *destination) const { - const AggregationStateMin &min_source = static_cast<const AggregationStateMin&>(source); - AggregationStateMin *min_destination = static_cast<AggregationStateMin*>(destination); +void AggregationHandleMin::mergeStates(const AggregationState &source, + AggregationState *destination) const { + const AggregationStateMin &min_source = + static_cast<const AggregationStateMin &>(source); + AggregationStateMin *min_destination = + static_cast<AggregationStateMin *>(destination); if (!min_source.min_.isNull()) { compareAndUpdate(min_destination, min_source.min_); } } -void AggregationHandleMin::mergeStatesFast( - const std::uint8_t *source, - std::uint8_t *destination) const { - const TypedValue *src_min_ptr = reinterpret_cast<const TypedValue *>(source); - TypedValue *dst_min_ptr = reinterpret_cast<TypedValue *>(destination); +void AggregationHandleMin::mergeStatesFast(const std::uint8_t *source, + std::uint8_t *destination) const { + const TypedValue *src_min_ptr = reinterpret_cast<const TypedValue *>(source); + TypedValue *dst_min_ptr = reinterpret_cast<TypedValue *>(destination); - if (!(src_min_ptr->isNull())) { - compareAndUpdateFast(dst_min_ptr, *src_min_ptr); - } + if (!(src_min_ptr->isNull())) { + compareAndUpdateFast(dst_min_ptr, *src_min_ptr); + } } ColumnVector* AggregationHandleMin::finalizeHashTable( @@ -117,31 +113,26 @@ ColumnVector* AggregationHandleMin::finalizeHashTable( std::vector<std::vector<TypedValue>> *group_by_keys, int index) const { return finalizeHashTableHelperFast<AggregationHandleMin, - AggregationStateFastHashTable>( - type_.getNonNullableVersion(), - hash_table, - group_by_keys, - index); + AggregationStateFastHashTable>( + type_.getNonNullableVersion(), hash_table, group_by_keys, index); } -AggregationState* AggregationHandleMin::aggregateOnDistinctifyHashTableForSingle( +AggregationState* +AggregationHandleMin::aggregateOnDistinctifyHashTableForSingle( const AggregationStateHashTableBase &distinctify_hash_table) const { return aggregateOnDistinctifyHashTableForSingleUnaryHelperFast< AggregationHandleMin, - AggregationStateMin>( - distinctify_hash_table); + AggregationStateMin>(distinctify_hash_table); } void AggregationHandleMin::aggregateOnDistinctifyHashTableForGroupBy( const AggregationStateHashTableBase &distinctify_hash_table, AggregationStateHashTableBase *aggregation_hash_table, - int index) const { + std::size_t index) const { aggregateOnDistinctifyHashTableForGroupByUnaryHelperFast< AggregationHandleMin, AggregationStateFastHashTable>( - distinctify_hash_table, - aggregation_hash_table, - index); + distinctify_hash_table, aggregation_hash_table, index); } } // namespace quickstep