Github user zuyu commented on a diff in the pull request:

    https://github.com/apache/incubator-quickstep/pull/239#discussion_r112882425
  
    --- Diff: storage/ThreadPrivateCompactKeyHashTable.cpp ---
    @@ -0,0 +1,422 @@
    +/**
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + *   http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing,
    + * software distributed under the License is distributed on an
    + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    + * KIND, either express or implied.  See the License for the
    + * specific language governing permissions and limitations
    + * under the License.
    + **/
    +
    +#include "storage/ThreadPrivateCompactKeyHashTable.hpp"
    +
    +#include <algorithm>
    +#include <cstddef>
    +#include <cstdint>
    +#include <type_traits>
    +#include <vector>
    +
    +#include "expressions/aggregation/AggregationHandle.hpp"
    +#include "expressions/aggregation/AggregationID.hpp"
    +#include "storage/StorageBlob.hpp"
    +#include "storage/StorageBlockInfo.hpp"
    +#include "storage/StorageManager.hpp"
    +#include "storage/ValueAccessorMultiplexer.hpp"
    +#include "types/Type.hpp"
    +#include "types/TypeID.hpp"
    +#include "types/containers/ColumnVectorsValueAccessor.hpp"
    +#include "utility/ScopedBuffer.hpp"
    +
    +#include "glog/logging.h"
    +
    +namespace quickstep {
    +
    +namespace {
    +
    +#define CASE_KEY_SIZE(value) \
    +  case value: return functor(std::integral_constant<std::size_t, value>())
    +
    +template <typename FunctorT>
    +auto InvokeOnKeySize(const std::size_t key_size, const FunctorT &functor) {
    +  switch (key_size) {
    +    CASE_KEY_SIZE(1);
    +    CASE_KEY_SIZE(2);
    +    CASE_KEY_SIZE(3);
    +    CASE_KEY_SIZE(4);
    +    CASE_KEY_SIZE(5);
    +    CASE_KEY_SIZE(6);
    +    CASE_KEY_SIZE(7);
    +    CASE_KEY_SIZE(8);
    +    default:
    +      break;
    +  }
    +  LOG(FATAL) << "Unexpected key size: " << key_size;
    +}
    +
    +#undef CASE_KEY_SIZE
    +
    +}  // namespace
    +
    +constexpr std::size_t ThreadPrivateCompactKeyHashTable::kKeyCodeSize;
    +
    +ThreadPrivateCompactKeyHashTable::ThreadPrivateCompactKeyHashTable(
    +    const std::vector<const Type*> &key_types,
    +    const std::size_t num_entries,
    +    const std::vector<AggregationHandle*> &handles,
    +    StorageManager *storage_manager)
    +    : key_types_(key_types),
    +      handles_(handles),
    +      total_state_size_(0),
    +      num_buckets_(0),
    +      buckets_allocated_(0),
    +      storage_manager_(storage_manager) {
    +  // Cache key sizes.
    +  for (const Type *key_type : key_types) {
    +    DCHECK(!key_type->isVariableLength());
    +    DCHECK(!key_type->isNullable());
    +    key_sizes_.emplace_back(key_type->maximumByteLength());
    +  }
    +
    +  for (const AggregationHandle *handle : handles) {
    +    const std::vector<const Type*> arg_types = handle->getArgumentTypes();
    +    DCHECK_LE(arg_types.size(), 1u);
    +    DCHECK(arg_types.empty() || !arg_types.front()->isNullable());
    +
    +    // Figure out state size.
    +    std::size_t state_size = 0;
    +    switch (handle->getAggregationID()) {
    +      case AggregationID::kCount: {
    +        state_size = sizeof(std::int64_t);
    +        break;
    +      }
    +      case AggregationID::kSum: {
    +        DCHECK_EQ(1u, arg_types.size());
    +        switch (arg_types.front()->getTypeID()) {
    +          case TypeID::kInt:  // Fall through
    +          case TypeID::kLong:
    +            state_size = sizeof(std::int64_t);
    +            break;
    +          case TypeID::kFloat:  // Fall through
    +          case TypeID::kDouble:
    +            state_size = sizeof(double);
    --- End diff --
    
    FYI, for all four cases,  `state_size` is `8`.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to