Repository: apache/arrow
File: cpp/src/arrow/compute/kernels/hash_aggregate.cc (C++)

Code before:
    ARROW_ASSIGN_OR_RAISE(auto counts, counts_.Finish());
    return std::make_shared<Int64Array>(num_groups_, std::move(counts));
  }

  std::shared_ptr<DataType> out_type() const override { return int64(); }

  int64_t num_groups_ = 0;
  CountOptions options_;
  BufferBuilder counts_;
};

// ----------------------------------------------------------------------
// MinMax implementation

// XXX: Consider making these concepts complete and moving to public header.

template <typename T>
concept CBooleanConcept = std::is_same_v<T, bool>;

// XXX: Ideally we want to have std::floating_point<Float16> = true.
template <typename T>
concept CFloatingPointConcept =
    std::floating_point<T> || std::is_same_v<T, util::Float16>;

template <typename T>
concept CDecimalConcept = std::is_same_v<T, Decimal32> || std::is_same_v<T, Decimal64> ||
    std::is_same_v<T, Decimal128> || std::is_same_v<T, Decimal256>;

template <typename CType>
struct AntiExtrema {
  static constexpr CType anti_min() { return std::numeric_limits<CType>::max(); }
  static constexpr CType anti_max() { return std::numeric_limits<CType>::min(); }
};

template <CBooleanConcept CType>
struct AntiExtrema<CType> {
  static constexpr CType anti_min() { return true; }
  static constexpr CType anti_max() { return false; }
};

template <CFloatingPointConcept CType>
struct AntiExtrema<CType> {
  static constexpr CType anti_min() { return std::numeric_limits<CType>::quiet_NaN(); }
  static constexpr CType anti_max() { return std::numeric_limits<CType>::quiet_NaN(); }
};

template <CDecimalConcept CType>
struct AntiExtrema<CType> {
  static constexpr CType anti_min() { return CType::GetMaxSentinel(); }
  static constexpr CType anti_max() { return CType::GetMinSentinel(); }
};

Review comment (suggestion):
By the way, it seems `CTypeTraits<Decimal32>` et al. aren't defined, perhaps open a separate issue for that.

Code after:
    ARROW_ASSIGN_OR_RAISE(auto counts, counts_.Finish());
    return std::make_shared<Int64Array>(num_groups_, std::move(counts));
  }

  std::shared_ptr<DataType> out_type() const override { return int64(); }

  int64_t num_groups_ = 0;
  CountOptions options_;
  BufferBuilder counts_;
};

// ----------------------------------------------------------------------
// MinMax implementation

// XXX: Consider making these concepts complete and moving to public header.

template <typename T>
concept CBooleanConcept = std::same_as<T, bool>;

// XXX: Ideally we want to have std::floating_point<Float16> = true.
template <typename T>
concept CFloatingPointConcept = std::floating_point<T> || std::same_as<T, util::Float16>;

template <typename T>
concept CDecimalConcept = std::same_as<T, Decimal32> || std::same_as<T, Decimal64> ||
    std::same_as<T, Decimal128> || std::same_as<T, Decimal256>;

template <typename CType>
struct AntiExtrema {
  static constexpr CType anti_min() { return std::numeric_limits<CType>::max(); }
  static constexpr CType anti_max() { return std::numeric_limits<CType>::min(); }
};

template <CBooleanConcept CType>
struct AntiExtrema<CType> {
  static constexpr CType anti_min() { return true; }
  static constexpr CType anti_max() { return false; }
};

template <CFloatingPointConcept CType>
struct AntiExtrema<CType> {
  static constexpr CType anti_min() { return std::numeric_limits<CType>::quiet_NaN(); }
  static constexpr CType anti_max() { return std::numeric_limits<CType>::quiet_NaN(); }
};

template <CDecimalConcept CType>
struct AntiExtrema<CType> {
  static constexpr CType anti_min() { return CType::GetMaxSentinel(); }
  static constexpr CType anti_max() { return CType::GetMinSentinel(); }
};