8000 [Feature] support decimal256 by stephen-shelby · Pull Request #60051 · StarRocks/starrocks · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[Feature] support decimal256 #60051

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions be/src/column/column_hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include "column/vectorized_fwd.h"
#include "storage/uint24.h"
#include "types/int256.h"

#ifdef __SSE4_2__
#include <nmmintrin.h>
Expand Down Expand Up @@ -124,12 +125,35 @@ inline uint64_t hash_128(uint64_t seed, int128_t val) {
return seed;
}

inline uint64_t hash_256(uint64_t seed, const int256_t& val) {
LOG(ERROR) << "00000000000000000000";
uint64_t parts[4];
parts[0] = static_cast<uint64_t>(val.low);
parts[1] = static_cast<uint64_t>(val.low >> 64);
parts[2] = static_cast<uint64_t>(static_cast<uint128_t>(val.high));
parts[3] = static_cast<uint64_t>(static_cast<uint128_t>(val.high) >> 64);

uint64_t hash = seed;
for (int i = 0; i < 4; ++i) {
hash_combine(hash, parts[i]);
}
return hash;
}

template <PhmapSeed seed>
struct Hash128WithSeed {
std::size_t operator()(int128_t value) const {
return phmap_mix_with_seed<sizeof(size_t), seed>()(hash_128(seed, value));
}
};

template <PhmapSeed seed>
struct Hash256WithSeed {
std::size_t operator()(const int256_t& value) const {
return phmap_mix_with_seed<sizeof(size_t), seed>()(hash_256(seed, value));
}
};

template <typename T>
struct HashTypeTraits {
using HashFunc = StdHashWithSeed<T, PhmapSeed2>;
Expand All @@ -139,13 +163,20 @@ struct HashTypeTraits<int128_t> {
using HashFunc = Hash128WithSeed<PhmapSeed2>;
};

template <>
struct HashTypeTraits<int256_t> {
using HashFunc = Hash256WithSeed<PhmapSeed2>;
};

template <LogicalType LT, PhmapSeed seed>
struct PhmapDefaultHashFunc {
std::size_t operator()(const RunTimeCppType<LT>& value) const {
static_assert(is_supported(), "unsupported logical type");

if constexpr (lt_is_largeint<LT> || lt_is_decimal128<LT>) {
return Hash128WithSeed<seed>()(value);
} else if constexpr (lt_is_decimal256<LT>) {
return Hash256WithSeed<seed>()(value);
} else if constexpr (lt_is_fixedlength<LT>) {
return StdHashWithSeed<RunTimeCppType<LT>, seed>()(value);
} else if constexpr (lt_is_string<LT> || lt_is_binary<LT>) {
Expand Down
3 changes: 2 additions & 1 deletion be/src/column/field.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,13 @@ class Field {
: Field(id, name, get_type_info(type, precision, scale), STORAGE_AGGREGATE_NONE, nullptr, 0, false,
nullable) {}

// Non-key field of any type except for DECIMAL32, DECIMAL64, DECIMAL128, and ARRAY
// Non-key field of any type except for DECIMAL32, DECIMAL64, DECIMAL128, DECIMAL256, and ARRAY
Field(ColumnId id, std::string_view name, LogicalType type, bool nullable)
: Field(id, name, type, -1, -1, nullable) {
DCHECK(type != TYPE_DECIMAL32);
DCHECK(type != TYPE_DECIMAL64);
DCHECK(type != TYPE_DECIMAL128);
DCHECK(type != TYPE_DECIMAL256);
DCHECK(type != TYPE_ARRAY);
}

Expand Down
2 changes: 2 additions & 0 deletions be/src/column/fixed_length_column_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,8 @@ std::string FixedLengthColumnBase<T>::get_name() const {
return "timestamp";
} else if constexpr (IsInt128<T>) {
return "int128";
} else if constexpr (IsInt256<T>) {
return "int256";
} else if constexpr (std::is_floating_point_v<T>) {
return "float-" + std::to_string(sizeof(T));
} else {
Expand Down
8 changes: 7 additions & 1 deletion be/src/column/type_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ constexpr bool IsInt128 = false;
template <>
inline constexpr bool IsInt128<int128_t> = true;

template <typename T>
constexpr bool IsInt256 = false;
template <>
inline constexpr bool IsInt256<int256_t> = true;

template <typename T>
constexpr bool IsSlice = false;
template <>
Expand All @@ -54,7 +59,8 @@ template <>
inline constexpr bool IsDateTime<DateValue> = true;

template <typename T>
using is_starrocks_arithmetic = std::integral_constant<bool, std::is_arithmetic_v<T> || IsDecimal<T>>;
using is_starrocks_arithmetic =
std::integral_constant<bool, std::is_arithmetic_v<T> || IsDecimal<T> || std::is_same_v<T, int256_t>>;

// If isArithmeticLT is true, means this type support +,-,*,/
template <LogicalType logical_type>
Expand Down
2 changes: 2 additions & 0 deletions be/src/exec/aggregate/agg_hash_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ using Int64AggHashMap = phmap::flat_hash_map<int64_t, AggDataPtr, StdHashWithSee
template <PhmapSeed seed>
using Int128AggHashMap = phmap::flat_hash_map<int128_t, AggDataPtr, Hash128WithSeed<seed>>;
template <PhmapSeed seed>
using Int256AggHashMap = phmap::flat_hash_map<int256_t, AggDataPtr, Hash256WithSeed<seed>>;
template <PhmapSeed seed>
using DateAggHashMap = phmap::flat_hash_map<DateValue, AggDataPtr, StdHashWithSeed<DateValue, seed>>;
template <PhmapSeed seed>
using TimeStampAggHashMap = phmap::flat_hash_map<TimestampValue, AggDataPtr, StdHashWithSeed<TimestampValue, seed>>;
Expand Down
2 changes: 2 additions & 0 deletions be/src/exec/aggregate/agg_hash_set.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ using Int64AggHashSet = phmap::flat_hash_set<int64_t, StdHashWithSeed<int64_t, s
template <PhmapSeed seed>
using Int128AggHashSet = phmap::flat_hash_set<int128_t, Hash128WithSeed<seed>>;
template <PhmapSeed seed>
using Int256AggHashSet = phmap::flat_hash_set<int256_t, Hash256WithSeed<seed>>;
template <PhmapSeed seed>
using DateAggHashSet = phmap::flat_hash_set<DateValue, StdHashWithSeed<DateValue, seed>>;
template <PhmapSeed seed>
using TimeStampAggHashSet = phmap::flat_hash_set<TimestampValue, StdHashWithSeed<TimestampValue, seed>>;
Expand Down
9 changes: 9 additions & 0 deletions be/src/exec/aggregate/agg_hash_variant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ DEFINE_MAP_TYPE(AggHashMapVariant::Type::phase1_int128, Int128AggHashMapWithOneN
DEFINE_MAP_TYPE(AggHashMapVariant::Type::phase1_decimal32, Decimal32AggHashMapWithOneNumberKey<PhmapSeed1>);
DEFINE_MAP_TYPE(AggHashMapVariant::Type::phase1_decimal64, Decimal64AggHashMapWithOneNumberKey<PhmapSeed1>);
DEFINE_MAP_TYPE(AggHashMapVariant::Type::phase1_decimal128, Decimal128AggHashMapWithOneNumberKey<PhmapSeed1>);
DEFINE_MAP_TYPE(AggHashMapVariant::Type::phase1_decimal256, Decimal256AggHashMapWithOneNumberKey<PhmapSeed1>);
DEFINE_MAP_TYPE(AggHashMapVariant::Type::phase1_date, DateAggHashMapWithOneNumberKey<PhmapSeed1>);
DEFINE_MAP_TYPE(AggHashMapVariant::Type::phase1_timestamp, TimeStampAggHashMapWithOneNumberKey<PhmapSeed1>);
DEFINE_MAP_TYPE(AggHashMapVariant::Type::phase1_string, OneStringAggHashMap<PhmapSeed1>);
Expand All @@ -52,6 +53,7 @@ DEFINE_MAP_TYPE(AggHashMapVariant::Type::phase1_null_int128, NullInt128AggHashMa
DEFINE_MAP_TYPE(AggHashMapVariant::Type::phase1_null_decimal32, NullDecimal32AggHashMapWithOneNumberKey<PhmapSeed1>);
DEFINE_MAP_TYPE(AggHashMapVariant::Type::phase1_null_decimal64, NullDecimal64AggHashMapWithOneNumberKey<PhmapSeed1>);
DEFINE_MAP_TYPE(AggHashMapVariant::Type::phase1_null_decimal128, NullDecimal128AggHashMapWithOneNumberKey<PhmapSeed1>);
DEFINE_MAP_TYPE(AggHashMapVariant::Type::phase1_null_decimal256, NullDecimal256AggHashMapWithOneNumberKey<PhmapSeed1>);
DEFINE_MAP_TYPE(AggHashMapVariant::Type::phase1_null_date, NullDateAggHashMapWithOneNumberKey<PhmapSeed1>);
DEFINE_MAP_TYPE(AggHashMapVariant::Type::phase1_null_timestamp, NullTimeStampAggHashMapWithOneNumberKey<PhmapSeed1>);
DEFINE_MAP_TYPE(AggHashMapVariant::Type::phase1_null_string, NullOneStringAggHashMap<PhmapSeed1>);
Expand All @@ -72,6 +74,7 @@ DEFINE_MAP_TYPE(AggHashMapVariant::Type::phase2_int128, Int128AggHashMapWithOneN
DEFINE_MAP_TYPE(AggHashMapVariant::Type::phase2_decimal32, Decimal32AggHashMapWithOneNumberKey<PhmapSeed2>);
DEFINE_MAP_TYPE(AggHashMapVariant::Type::phase2_decimal64, Decimal64AggHashMapWithOneNumberKey<PhmapSeed2>);
DEFINE_MAP_TYPE(AggHashMapVariant::Type::phase2_decimal128, Decimal128AggHashMapWithOneNumberKey<PhmapSeed2>);
DEFINE_MAP_TYPE(AggHashMapVariant::Type::phase2_decimal256, Decimal256AggHashMapWithOneNumberKey<PhmapSeed2>);
DEFINE_MAP_TYPE(AggHashMapVariant::Type::phase2_date, DateAggHashMapWithOneNumberKey<PhmapSeed2>);
DEFINE_MAP_TYPE(AggHashMapVariant::Type::phase2_timestamp, TimeStampAggHashMapWithOneNumberKey<PhmapSeed2>);
DEFINE_MAP_TYPE(AggHashMapVariant::Type::phase2_string, OneStringAggHashMap<PhmapSeed2>);
Expand All @@ -84,6 +87,7 @@ DEFINE_MAP_TYPE(AggHashMapVariant::Type::phase2_null_int128, NullInt128AggHashMa
DEFINE_MAP_TYPE(AggHashMapVariant::Type::phase2_null_decimal32, NullDecimal32AggHashMapWithOneNumberKey<PhmapSeed2>);
DEFINE_MAP_TYPE(AggHashMapVariant::Type::phase2_null_decimal64, NullDecimal64AggHashMapWithOneNumberKey<PhmapSeed2>);
DEFINE_MAP_TYPE(AggHashMapVariant::Type::phase2_null_decimal128, NullDecimal128AggHashMapWithOneNumberKey<PhmapSeed2>);
DEFINE_MAP_TYPE(AggHashMapVariant::Type::phase2_null_decimal256, NullDecimal256AggHashMapWithOneNumberKey<PhmapSeed2>);
DEFINE_MAP_TYPE(AggHashMapVariant::Type::phase2_null_date, NullDateAggHashMapWithOneNumberKey<PhmapSeed2>);
DEFINE_MAP_TYPE(AggHashMapVariant::Type::phase2_null_timestamp, NullTimeStampAggHashMapWithOneNumberKey<PhmapSeed2>);
DEFINE_MAP_TYPE(AggHashMapVariant::Type::phase2_null_string, NullOneStringAggHashMap<PhmapSeed2>);
Expand Down Expand Up @@ -114,6 +118,7 @@ DEFINE_SET_TYPE(AggHashSetVariant::Type::phase1_int128, Int128AggHashSetOfOneNum
DEFINE_SET_TYPE(AggHashSetVariant::Type::phase1_decimal32, Decimal32AggHashSetOfOneNumberKey<PhmapSeed1>);
DEFINE_SET_TYPE(AggHashSetVariant::Type::phase1_decimal64, Decimal64AggHashSetOfOneNumberKey<PhmapSeed1>);
DEFINE_SET_TYPE(AggHashSetVariant::Type::phase1_decimal128, Decimal128AggHashSetOfOneNumberKey<PhmapSeed1>);
DEFINE_SET_TYPE(AggHashSetVariant::Type::phase1_decimal256, Decimal256AggHashSetOfOneNumberKey<PhmapSeed1>);
DEFINE_SET_TYPE(AggHashSetVariant::Type::phase1_date, DateAggHashSetOfOneNumberKey<PhmapSeed1>);
DEFINE_SET_TYPE(AggHashSetVariant::Type::phase1_timestamp, TimeStampAggHashSetOfOneNumberKey<PhmapSeed1>);
DEFINE_SET_TYPE(AggHashSetVariant::Type::phase1_string, OneStringAggHashSet<PhmapSeed1>);
Expand All @@ -126,6 +131,7 @@ DEFINE_SET_TYPE(AggHashSetVariant::Type::phase1_null_int128, NullInt128AggHashSe
DEFINE_SET_TYPE(AggHashSetVariant::Type::phase1_null_decimal32, NullDecimal32AggHashSetOfOneNumberKey<PhmapSeed1>);
DEFINE_SET_TYPE(AggHashSetVariant::Type::phase1_null_decimal64, NullDecimal64AggHashSetOfOneNumberKey<PhmapSeed1>);
DEFINE_SET_TYPE(AggHashSetVariant::Type::phase1_null_decimal128, NullDecimal128AggHashSetOfOneNumberKey<PhmapSeed1>);
DEFINE_SET_TYPE(AggHashSetVariant::Type::phase1_null_decimal256, NullDecimal256AggHashSetOfOneNumberKey<PhmapSeed1>);
DEFINE_SET_TYPE(AggHashSetVariant::Type::phase1_null_date, NullDateAggHashSetOfOneNumberKey<PhmapSeed1>);
DEFINE_SET_TYPE(AggHashSetVariant::Type::phase1_null_timestamp, NullTimeStampAggHashSetOfOneNumberKey<PhmapSeed1>);
DEFINE_SET_TYPE(AggHashSetVariant::Type::phase1_null_string, NullOneStringAggHashSet<PhmapSeed1>);
Expand All @@ -144,6 +150,7 @@ DEFINE_SET_TYPE(AggHashSetVariant::Type::phase2_int128, Int128AggHashSetOfOneNum
DEFINE_SET_TYPE(AggHashSetVariant::Type::phase2_decimal32, Decimal32AggHashSetOfOneNumberKey<PhmapSeed2>);
DEFINE_SET_TYPE(AggHashSetVariant::Type::phase2_decimal64, Decimal64AggHashSetOfOneNumberKey<PhmapSeed2>);
DEFINE_SET_TYPE(AggHashSetVariant::Type::phase2_decimal128, Decimal128AggHashSetOfOneNumberKey<PhmapSeed2>);
DEFINE_SET_TYPE(AggHashSetVariant::Type::phase2_decimal256, Decimal256AggHashSetOfOneNumberKey<PhmapSeed2>);
DEFINE_SET_TYPE(AggHashSetVariant::Type::phase2_date, DateAggHashSetOfOneNumberKey<PhmapSeed2>);
DEFINE_SET_TYPE(AggHashSetVariant::Type::phase2_timestamp, TimeStampAggHashSetOfOneNumberKey<PhmapSeed2>);
DEFINE_SET_TYPE(AggHashSetVariant::Type::phase2_string, OneStringAggHashSet<PhmapSeed2>);
Expand All @@ -156,6 +163,7 @@ DEFINE_SET_TYPE(AggHashSetVariant::Type::phase2_null_int128, NullInt128AggHashSe
DEFINE_SET_TYPE(AggHashSetVariant::Type::phase2_null_decimal32, NullDecimal32AggHashSetOfOneNumberKey<PhmapSeed2>);
DEFINE_SET_TYPE(AggHashSetVariant::Type::phase2_null_decimal64, NullDecimal64AggHashSetOfOneNumberKey<PhmapSeed2>);
DEFINE_SET_TYPE(AggHashSetVariant::Type::phase2_null_decimal128, NullDecimal128AggHashSetOfOneNumberKey<PhmapSeed2>);
DEFINE_SET_TYPE(AggHashSetVariant::Type::phase2_null_decimal256, NullDecimal256AggHashSetOfOneNumberKey<PhmapSeed2>);
DEFINE_SET_TYPE(AggHashSetVariant::Type::phase2_null_date, NullDateAggHashSetOfOneNumberKey<PhmapSeed2>);
DEFINE_SET_TYPE(AggHashSetVariant::Type::phase2_null_timestamp, NullTimeStampAggHashSetOfOneNumberKey<PhmapSeed2>);
DEFINE_SET_TYPE(AggHashSetVariant::Type::phase2_null_string, NullOneStringAggHashSet<PhmapSeed2>);
Expand Down Expand Up @@ -370,6 +378,7 @@ HashVariantResolver<HashVariantType>::HashVariantResolver() {
ADD_VARIANT_PHASE1_TYPE(TYPE_DATE, date);
ADD_VARIANT_PHASE1_TYPE(TYPE_DATETIME, timestamp);
ADD_VARIANT_PHASE1_TYPE(TYPE_DECIMAL128, decimal128);
ADD_VARIANT_PHASE1_TYPE(TYPE_DECIMAL256, decimal256);
ADD_VARIANT_PHASE1_TYPE(TYPE_LARGEINT, int128);
ADD_VARIANT_PHASE1_TYPE(TYPE_CHAR, string);
ADD_VARIANT_PHASE1_TYPE(TYPE_VARCHAR, string);
Expand Down
Loading
Loading
0