Skip to content
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
4 changes: 4 additions & 0 deletions clickhouse/columns/decimal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ Int128 ColumnDecimal::At(size_t i) const {
}
}

Int128 ColumnDecimal::operator[](size_t i) const {
return At(i);
}

std::string ColumnDecimal::StringAt(size_t i) const {
auto scale = GetScale();

Expand Down
6 changes: 3 additions & 3 deletions clickhouse/columns/decimal.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ class ColumnDecimal : public Column {

ColumnDecimal(size_t precision, size_t scale);

void Append(const Int128& value);
CH_ABSEIL_BIGNUM_DEPRECATED void Append(const Int128& value);
void Append(const std::string& value);

Int128 At(size_t i) const;
inline auto operator[](size_t i) const { return At(i); }
CH_ABSEIL_BIGNUM_DEPRECATED Int128 At(size_t i) const;
CH_ABSEIL_BIGNUM_DEPRECATED Int128 operator[](size_t i) const;

// Returns string representation of the decimal value
std::string StringAt(size_t i) const;
Expand Down
45 changes: 45 additions & 0 deletions clickhouse/columns/numeric.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ const T& ColumnVector<T>::At(size_t n) const {
return data_.at(n);
}

template <typename T>
const T& ColumnVector<T>::operator [] (size_t n) const {
return data_.at(n);
}

template <typename T>
void ColumnVector<T>::Append(ColumnRef column) {
if (auto col = column->As<ColumnVector<T>>()) {
Expand Down Expand Up @@ -108,6 +113,46 @@ ItemView ColumnVector<T>::GetItem(size_t index) const {
return ItemView{type_->GetCode(), data_[index]};
}

template <>
void ColumnVector<Int128>::Append(const Int128& value) {
data_.push_back(value);
}

template <>
const Int128& ColumnVector<Int128>::At(size_t n) const {
return data_.at(n);
}

template <>
const Int128& ColumnVector<Int128>::operator [] (size_t n) const {
return data_.at(n);
}

template <>
std::vector<Int128>& ColumnVector<Int128>::GetWritableData() {
return data_;
}

template <>
void ColumnVector<UInt128>::Append(const UInt128& value) {
data_.push_back(value);
}

template <>
const UInt128& ColumnVector<UInt128>::At(size_t n) const {
return data_.at(n);
}

template <>
const UInt128& ColumnVector<UInt128>::operator [] (size_t n) const {
return data_.at(n);
}

template <>
std::vector<UInt128>& ColumnVector<UInt128>::GetWritableData() {
return data_;
}

template class ColumnVector<int8_t>;
template class ColumnVector<int16_t>;
template class ColumnVector<int32_t>;
Expand Down
20 changes: 19 additions & 1 deletion clickhouse/columns/numeric.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class ColumnVector : public Column {
const T& At(size_t n) const;

/// Returns element at given row number.
inline const T& operator [] (size_t n) const { return At(n); }
const T& operator [] (size_t n) const;

void Erase(size_t pos, size_t count = 1);

Expand Down Expand Up @@ -80,4 +80,22 @@ using ColumnInt128 = ColumnVector<Int128>;
using ColumnFloat32 = ColumnVector<float>;
using ColumnFloat64 = ColumnVector<double>;

template <>
CH_ABSEIL_BIGNUM_DEPRECATED void ColumnVector<Int128>::Append(const Int128& value);
template <>
CH_ABSEIL_BIGNUM_DEPRECATED const Int128& ColumnVector<Int128>::At(size_t n) const;
template <>
CH_ABSEIL_BIGNUM_DEPRECATED const Int128& ColumnVector<Int128>::operator [] (size_t n) const;
template <>
CH_ABSEIL_BIGNUM_DEPRECATED std::vector<Int128>& ColumnVector<Int128>::GetWritableData();

template <>
CH_ABSEIL_BIGNUM_DEPRECATED void ColumnVector<UInt128>::Append(const UInt128& value);
template <>
CH_ABSEIL_BIGNUM_DEPRECATED const UInt128& ColumnVector<UInt128>::At(size_t n) const;
template <>
CH_ABSEIL_BIGNUM_DEPRECATED const UInt128& ColumnVector<UInt128>::operator [] (size_t n) const;
template <>
CH_ABSEIL_BIGNUM_DEPRECATED std::vector<UInt128>& ColumnVector<UInt128>::GetWritableData();

}
27 changes: 17 additions & 10 deletions clickhouse/types/bignum.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
#include <string>
#include <string_view>

#if CH_USE_ABSEIL_FOR_BIGNUM
#define CH_ABSEIL_BIGNUM_DEPRECATED \
[[deprecated("clickhouse-cpp Abseil-backed Int128/UInt128 APIs are deprecated and will be removed soon; configure with -DCH_USE_ABSEIL_FOR_BIGNUM=OFF to use the non-Abseil implementation.")]]
#else
#define CH_ABSEIL_BIGNUM_DEPRECATED
#endif


#if defined(__SIZEOF_INT128__)
#define CH_CPP_HAS_INT128 1
Expand Down Expand Up @@ -157,36 +164,36 @@ namespace clickhouse {
class Bignum {
public:

static Int128 StringToInt128(std::string_view str);
static UInt128 StringToUInt128(std::string_view str);
CH_ABSEIL_BIGNUM_DEPRECATED static Int128 StringToInt128(std::string_view str);
CH_ABSEIL_BIGNUM_DEPRECATED static UInt128 StringToUInt128(std::string_view str);

static std::string Int128ToString(const Int128 x);
static std::string UInt128ToString(const UInt128 x);
CH_ABSEIL_BIGNUM_DEPRECATED static std::string Int128ToString(const Int128 x);
CH_ABSEIL_BIGNUM_DEPRECATED static std::string UInt128ToString(const UInt128 x);


#if CH_USE_ABSEIL_FOR_BIGNUM

static inline Int128 MakeInt128(int64_t hi, uint64_t lo) {
CH_ABSEIL_BIGNUM_DEPRECATED static inline Int128 MakeInt128(int64_t hi, uint64_t lo) {
return absl::MakeInt128(hi, lo);
}

static inline UInt128 MakeUInt128(uint64_t hi, uint64_t lo) {
CH_ABSEIL_BIGNUM_DEPRECATED static inline UInt128 MakeUInt128(uint64_t hi, uint64_t lo) {
return absl::MakeUint128(hi, lo);
}

static inline uint64_t Int128Low64(Int128 v) {
CH_ABSEIL_BIGNUM_DEPRECATED static inline uint64_t Int128Low64(Int128 v) {
return absl::Int128Low64(v);
}

static inline int64_t Int128High64(Int128 v) {
CH_ABSEIL_BIGNUM_DEPRECATED static inline int64_t Int128High64(Int128 v) {
return absl::Int128High64(v);
}

static inline uint64_t UInt128Low64(UInt128 v) {
CH_ABSEIL_BIGNUM_DEPRECATED static inline uint64_t UInt128Low64(UInt128 v) {
return absl::Uint128Low64(v);
}

static inline uint64_t UInt128High64(UInt128 v) {
CH_ABSEIL_BIGNUM_DEPRECATED static inline uint64_t UInt128High64(UInt128 v) {
return absl::Uint128High64(v);
}

Expand Down
Loading