diff --git a/clickhouse/columns/array.cpp b/clickhouse/columns/array.cpp index 92f3dc07..4e452000 100644 --- a/clickhouse/columns/array.cpp +++ b/clickhouse/columns/array.cpp @@ -52,11 +52,6 @@ ColumnRef ColumnArray::CloneEmpty() const { return std::make_shared(data_->CloneEmpty()); } -void ColumnArray::Reserve(size_t new_cap) { - data_->Reserve(new_cap); - offsets_->Reserve(new_cap); -} - void ColumnArray::Append(ColumnRef column) { if (auto col = column->As()) { for (size_t i = 0; i < col->Size(); ++i) { @@ -65,6 +60,15 @@ void ColumnArray::Append(ColumnRef column) { } } +void ColumnArray::Reserve(size_t new_cap) { + data_->Reserve(new_cap); + offsets_->Reserve(new_cap); +} + +size_t ColumnArray::Capacity() const { + return data_->Capacity(); +} + bool ColumnArray::LoadPrefix(InputStream* input, size_t rows) { if (!rows) { return true; diff --git a/clickhouse/columns/array.h b/clickhouse/columns/array.h index 0914c39a..0491dc65 100644 --- a/clickhouse/columns/array.h +++ b/clickhouse/columns/array.h @@ -47,11 +47,11 @@ class ColumnArray : public Column { } public: - /// Increase the capacity of the column for large block insertion. - void Reserve(size_t new_cap) override; - /// Appends content of given column to the end of current one. void Append(ColumnRef column) override; + /// Increase the capacity of the column for large block insertion. + void Reserve(size_t new_cap) override; + size_t Capacity() const override; /// Loads column prefix from input stream. bool LoadPrefix(InputStream* input, size_t rows) override; diff --git a/clickhouse/columns/column.h b/clickhouse/columns/column.h index 33404a39..b1fc643d 100644 --- a/clickhouse/columns/column.h +++ b/clickhouse/columns/column.h @@ -54,6 +54,7 @@ class Column : public std::enable_shared_from_this { /// Increase the capacity of the column for large block insertion. virtual void Reserve(size_t new_cap) = 0; + virtual size_t Capacity() const = 0; /// Template method to load column data from input stream. It'll call LoadPrefix and LoadBody. /// Should be called only once from the client. Derived classes should not call it. diff --git a/clickhouse/columns/date.cpp b/clickhouse/columns/date.cpp index 70b8c5ce..5be752a5 100644 --- a/clickhouse/columns/date.cpp +++ b/clickhouse/columns/date.cpp @@ -37,16 +37,16 @@ uint16_t ColumnDate::RawAt(size_t n) const { return data_->At(n); } +std::vector& ColumnDate::GetWritableData() { + return data_->GetWritableData(); +} + void ColumnDate::Append(ColumnRef column) { if (auto col = column->As()) { data_->Append(col->data_); } } -std::vector& ColumnDate::GetWritableData() { - return data_->GetWritableData(); -} - void ColumnDate::Reserve(size_t new_cap) { data_->Reserve(new_cap); } @@ -315,11 +315,14 @@ std::string ColumnDateTime64::Timezone() const { return type_->As()->Timezone(); } -void ColumnDateTime64::Reserve(size_t new_cap) -{ +void ColumnDateTime64::Reserve(size_t new_cap) { data_->Reserve(new_cap); } +size_t ColumnDateTime64::Capacity() const { + return data_->Capacity(); +} + void ColumnDateTime64::Append(ColumnRef column) { if (auto col = column->As()) { data_->Append(col->data_); diff --git a/clickhouse/columns/date.h b/clickhouse/columns/date.h index 6148918c..a2c5fcc2 100644 --- a/clickhouse/columns/date.h +++ b/clickhouse/columns/date.h @@ -27,18 +27,18 @@ class ColumnDate : public Column { /// Do append data as is -- number of day in Unix epoch, no conversions performed. void AppendRaw(uint16_t value); uint16_t RawAt(size_t n) const; + /// Get Raw Vector Contents + std::vector& GetWritableData(); +public: /// Appends content of given column to the end of current one. void Append(ColumnRef column) override; - /// Get Raw Vector Contents - std::vector& GetWritableData(); - /// Increase the capacity of the column for large block insertion. void Reserve(size_t new_cap) override; /// Returns the capacity of the column - size_t Capacity() const; + size_t Capacity() const override; /// Loads column data from input stream. bool LoadBody(InputStream* input, size_t rows) override; @@ -89,15 +89,13 @@ class ColumnDate32 : public Column { /// Get Raw Vector Contents std::vector& GetWritableData(); - /// Returns the capacity of the column - size_t Capacity() const; - public: - /// Increase the capacity of the column for large block insertion. - void Reserve(size_t new_cap) override; - /// Appends content of given column to the end of current one. void Append(ColumnRef column) override; + /// Increase the capacity of the column for large block insertion. + void Reserve(size_t new_cap) override; + /// Returns the capacity of the column + size_t Capacity() const override; /// Loads column data from input stream. bool LoadBody(InputStream* input, size_t rows) override; @@ -151,15 +149,13 @@ class ColumnDateTime : public Column { /// Get Raw Vector Contents std::vector& GetWritableData(); - /// Returns the capacity of the column - size_t Capacity() const; - public: - /// Increase the capacity of the column for large block insertion. - void Reserve(size_t new_cap) override; - /// Appends content of given column to the end of current one. void Append(ColumnRef column) override; + /// Increase the capacity of the column for large block insertion. + void Reserve(size_t new_cap) override; + /// Returns the capacity of the column + size_t Capacity() const override; /// Loads column data from input stream. bool LoadBody(InputStream* input, size_t rows) override; @@ -209,11 +205,11 @@ class ColumnDateTime64 : public Column { std::string Timezone() const; public: - /// Increase the capacity of the column for large block insertion. - void Reserve(size_t new_cap) override; - /// Appends content of given column to the end of current one. void Append(ColumnRef column) override; + /// Increase the capacity of the column for large block insertion. + void Reserve(size_t new_cap) override; + size_t Capacity() const override; /// Loads column data from input stream. bool LoadBody(InputStream* input, size_t rows) override; diff --git a/clickhouse/columns/decimal.cpp b/clickhouse/columns/decimal.cpp index 758af019..03c2765b 100644 --- a/clickhouse/columns/decimal.cpp +++ b/clickhouse/columns/decimal.cpp @@ -191,13 +191,26 @@ Int128 ColumnDecimal::At(size_t i) const { } } +void ColumnDecimal::Append(ColumnRef column) { + if (auto col = column->As()) { + data_->Append(col->data_); + } +} + void ColumnDecimal::Reserve(size_t new_cap) { data_->Reserve(new_cap); } -void ColumnDecimal::Append(ColumnRef column) { - if (auto col = column->As()) { - data_->Append(col->data_); +size_t ColumnDecimal::Capacity() const { + switch (data_->Type()->GetCode()) { + case Type::Int32: + return data_->As()->Capacity(); + case Type::Int64: + return data_->As()->Capacity(); + case Type::Int128: + return data_->As()->Capacity(); + default: + throw ValidationError("Invalid data_ column type in ColumnDecimal"); } } diff --git a/clickhouse/columns/decimal.h b/clickhouse/columns/decimal.h index 2c4dc100..fea87f68 100644 --- a/clickhouse/columns/decimal.h +++ b/clickhouse/columns/decimal.h @@ -22,8 +22,9 @@ class ColumnDecimal : public Column { public: /// Increase the capacity of the column for large block insertion. - void Reserve(size_t new_cap) override; void Append(ColumnRef column) override; + void Reserve(size_t new_cap) override; + size_t Capacity() const override; bool LoadBody(InputStream* input, size_t rows) override; void SaveBody(OutputStream* output) override; void Clear() override; diff --git a/clickhouse/columns/enum.cpp b/clickhouse/columns/enum.cpp index 90f316ff..3f99762d 100644 --- a/clickhouse/columns/enum.cpp +++ b/clickhouse/columns/enum.cpp @@ -68,10 +68,6 @@ void ColumnEnum::SetNameAt(size_t n, const std::string& name) { data_.at(n) = static_cast(type_->As()->GetEnumValue(name)); } -template -void ColumnEnum::Reserve(size_t new_cap) { - data_.reserve(new_cap); -} template void ColumnEnum::Append(ColumnRef column) { @@ -80,6 +76,17 @@ void ColumnEnum::Append(ColumnRef column) { } } +template +void ColumnEnum::Reserve(size_t new_cap) { + data_.reserve(new_cap); +} + +template +size_t ColumnEnum::Capacity() const { + return data_.capacity(); +} + + template bool ColumnEnum::LoadBody(InputStream* input, size_t rows) { data_.resize(rows); diff --git a/clickhouse/columns/enum.h b/clickhouse/columns/enum.h index 1e9d7aea..f251ae47 100644 --- a/clickhouse/columns/enum.h +++ b/clickhouse/columns/enum.h @@ -30,11 +30,11 @@ class ColumnEnum : public Column { void SetNameAt(size_t n, const std::string& name); public: - /// Increase the capacity of the column for large block insertion. - void Reserve(size_t new_cap) override; - /// Appends content of given column to the end of current one. void Append(ColumnRef column) override; + /// Increase the capacity of the column for large block insertion. + void Reserve(size_t new_cap) override; + size_t Capacity() const override; /// Loads column data from input stream. bool LoadBody(InputStream* input, size_t rows) override; diff --git a/clickhouse/columns/geo.cpp b/clickhouse/columns/geo.cpp index 1e73520d..bb2eb9c2 100644 --- a/clickhouse/columns/geo.cpp +++ b/clickhouse/columns/geo.cpp @@ -54,11 +54,6 @@ const typename ColumnGeo::ValueType ColumnGeoAt(n); } -template -void ColumnGeo::Reserve(size_t new_cap) { - data_->Reserve(new_cap); -} - template void ColumnGeo::Append(ColumnRef column) { if (auto col = column->template As()) { @@ -66,6 +61,15 @@ void ColumnGeo::Append(ColumnRef column) { } } +template +void ColumnGeo::Reserve(size_t new_cap) { + data_->Reserve(new_cap); +} +template +size_t ColumnGeo::Capacity() const { + return data_->Capacity(); +} + template bool ColumnGeo::LoadBody(InputStream* input, size_t rows) { return data_->LoadBody(input, rows); diff --git a/clickhouse/columns/geo.h b/clickhouse/columns/geo.h index 628936ba..40748e7e 100644 --- a/clickhouse/columns/geo.h +++ b/clickhouse/columns/geo.h @@ -29,11 +29,11 @@ class ColumnGeo : public Column { inline const ValueType operator[](size_t n) const { return At(n); } public: - /// Increase the capacity of the column for large block insertion. - void Reserve(size_t new_cap) override; - /// Appends content of given column to the end of current one. void Append(ColumnRef column) override; + /// Increase the capacity of the column for large block insertion. + void Reserve(size_t new_cap) override; + size_t Capacity() const override; /// Loads column data from input stream. bool LoadBody(InputStream* input, size_t rows) override; diff --git a/clickhouse/columns/ip4.cpp b/clickhouse/columns/ip4.cpp index 3d5231f1..867d4cfb 100644 --- a/clickhouse/columns/ip4.cpp +++ b/clickhouse/columns/ip4.cpp @@ -74,16 +74,20 @@ std::string ColumnIPv4::AsString(size_t n) const { return ip_str; } -void ColumnIPv4::Reserve(size_t new_cap) { - data_->Reserve(new_cap); -} - void ColumnIPv4::Append(ColumnRef column) { if (auto col = column->As()) { data_->Append(col->data_); } } +void ColumnIPv4::Reserve(size_t new_cap) { + data_->Reserve(new_cap); +} + +size_t ColumnIPv4::Capacity() const { + return data_->Capacity(); +} + bool ColumnIPv4::LoadBody(InputStream * input, size_t rows) { return data_->LoadBody(input, rows); } diff --git a/clickhouse/columns/ip4.h b/clickhouse/columns/ip4.h index 1f9ef962..b13fd486 100644 --- a/clickhouse/columns/ip4.h +++ b/clickhouse/columns/ip4.h @@ -39,11 +39,11 @@ class ColumnIPv4 : public Column { std::string AsString(size_t n) const; public: - /// Increase the capacity of the column for large block insertion. - void Reserve(size_t new_cap) override; - /// Appends content of given column to the end of current one. void Append(ColumnRef column) override; + /// Increase the capacity of the column for large block insertion. + void Reserve(size_t new_cap) override; + size_t Capacity() const override; /// Loads column data from input stream. bool LoadBody(InputStream* input, size_t rows) override; diff --git a/clickhouse/columns/ip6.cpp b/clickhouse/columns/ip6.cpp index 5df4c61f..0199eed9 100644 --- a/clickhouse/columns/ip6.cpp +++ b/clickhouse/columns/ip6.cpp @@ -65,16 +65,20 @@ in6_addr ColumnIPv6::operator [] (size_t n) const { return *reinterpret_cast(data_->At(n).data()); } -void ColumnIPv6::Reserve(size_t new_cap) { - data_->Reserve(new_cap); -} - void ColumnIPv6::Append(ColumnRef column) { if (auto col = column->As()) { data_->Append(col->data_); } } +void ColumnIPv6::Reserve(size_t new_cap) { + data_->Reserve(new_cap); +} + +size_t ColumnIPv6::Capacity() const { + return data_->Capacity(); +} + bool ColumnIPv6::LoadBody(InputStream* input, size_t rows) { return data_->LoadBody(input, rows); } diff --git a/clickhouse/columns/ip6.h b/clickhouse/columns/ip6.h index fc9a9246..dcb969b4 100644 --- a/clickhouse/columns/ip6.h +++ b/clickhouse/columns/ip6.h @@ -35,11 +35,11 @@ class ColumnIPv6 : public Column { std::string AsString(size_t n) const; public: - /// Increase the capacity of the column for large block insertion. - void Reserve(size_t new_cap) override; - /// Appends content of given column to the end of current one. void Append(ColumnRef column) override; + /// Increase the capacity of the column for large block insertion. + void Reserve(size_t new_cap) override; + size_t Capacity() const override; /// Loads column data from input stream. bool LoadBody(InputStream* input, size_t rows) override; diff --git a/clickhouse/columns/lowcardinality.cpp b/clickhouse/columns/lowcardinality.cpp index 03e0c8ba..3bde75e1 100644 --- a/clickhouse/columns/lowcardinality.cpp +++ b/clickhouse/columns/lowcardinality.cpp @@ -209,6 +209,12 @@ void ColumnLowCardinality::Reserve(size_t new_cap) { dictionary_column_->Reserve(EstimateDictionaryCapacity(new_cap)); } +size_t ColumnLowCardinality::Capacity() const { + return VisitIndexColumn([](auto & index_column) { + return index_column.Capacity(); + }, *index_column_); +} + void ColumnLowCardinality::Setup(ColumnRef dictionary_column) { AppendDefaultItem(); diff --git a/clickhouse/columns/lowcardinality.h b/clickhouse/columns/lowcardinality.h index 13a75e2d..09c6c1c0 100644 --- a/clickhouse/columns/lowcardinality.h +++ b/clickhouse/columns/lowcardinality.h @@ -65,11 +65,13 @@ class ColumnLowCardinality : public Column { ~ColumnLowCardinality(); + /// Appends another LowCardinality column to the end of this one, updating dictionary. + void Append(ColumnRef /*column*/) override; + /// Increase the capacity of the column for large block insertion. void Reserve(size_t new_cap) override; - /// Appends another LowCardinality column to the end of this one, updating dictionary. - void Append(ColumnRef /*column*/) override; + size_t Capacity() const override; bool LoadPrefix(InputStream* input, size_t rows) override; diff --git a/clickhouse/columns/map.cpp b/clickhouse/columns/map.cpp index 494a43f1..dfefbed0 100644 --- a/clickhouse/columns/map.cpp +++ b/clickhouse/columns/map.cpp @@ -33,18 +33,22 @@ ColumnMap::ColumnMap(ColumnRef data) : Column(GetMapType(data->GetType())), data_(data->As()) { } +void ColumnMap::Append(ColumnRef column) { + if (auto col = column->As()) { + data_->Append(col->data_); + } +} + void ColumnMap::Reserve(size_t new_cap) { data_->Reserve(new_cap); } -void ColumnMap::Clear() { - data_->Clear(); +size_t ColumnMap::Capacity() const { + return data_->Capacity(); } -void ColumnMap::Append(ColumnRef column) { - if (auto col = column->As()) { - data_->Append(col->data_); - } +void ColumnMap::Clear() { + data_->Clear(); } bool ColumnMap::LoadPrefix(InputStream* input, size_t rows) { diff --git a/clickhouse/columns/map.h b/clickhouse/columns/map.h index 4245d514..4117db72 100644 --- a/clickhouse/columns/map.h +++ b/clickhouse/columns/map.h @@ -25,11 +25,11 @@ class ColumnMap : public Column { */ explicit ColumnMap(ColumnRef data); - /// Increase the capacity of the column for large block insertion. - void Reserve(size_t new_cap) override; - /// Appends content of given column to the end of current one. void Append(ColumnRef column) override; + /// Increase the capacity of the column for large block insertion. + void Reserve(size_t new_cap) override; + size_t Capacity() const override; /// Loads column prefix from input stream. bool LoadPrefix(InputStream* input, size_t rows) override; diff --git a/clickhouse/columns/nothing.h b/clickhouse/columns/nothing.h index fdd6382c..bc7b9047 100644 --- a/clickhouse/columns/nothing.h +++ b/clickhouse/columns/nothing.h @@ -26,11 +26,11 @@ class ColumnNothing : public Column { { } - /// Increase the capacity of the column for large block insertion. - void Reserve(size_t) override {}; - /// Appends one element to the column. void Append(std::unique_ptr) { ++size_; } + /// Increase the capacity of the column for large block insertion. + void Reserve(size_t) override {}; + size_t Capacity() const override {return 0;} /// Returns element at given row number. std::nullptr_t At(size_t) const { return nullptr; }; diff --git a/clickhouse/columns/nullable.cpp b/clickhouse/columns/nullable.cpp index 6bb4812c..23e66276 100644 --- a/clickhouse/columns/nullable.cpp +++ b/clickhouse/columns/nullable.cpp @@ -34,11 +34,6 @@ ColumnRef ColumnNullable::Nulls() const return nulls_; } -void ColumnNullable::Reserve(size_t new_cap) { - nested_->Reserve(new_cap); - nulls_->Reserve(new_cap); -} - void ColumnNullable::Append(ColumnRef column) { if (auto col = column->As()) { if (!col->nested_->Type()->IsEqual(nested_->Type())) { @@ -50,6 +45,15 @@ void ColumnNullable::Append(ColumnRef column) { } } +void ColumnNullable::Reserve(size_t new_cap) { + nested_->Reserve(new_cap); + nulls_->Reserve(new_cap); +} + +size_t ColumnNullable::Capacity() const { + return nested_->Capacity(); +} + void ColumnNullable::Clear() { nested_->Clear(); nulls_->Clear(); diff --git a/clickhouse/columns/nullable.h b/clickhouse/columns/nullable.h index f31e6fb8..85624b81 100644 --- a/clickhouse/columns/nullable.h +++ b/clickhouse/columns/nullable.h @@ -27,11 +27,11 @@ class ColumnNullable : public Column { ColumnRef Nulls() const; public: - /// Increase the capacity of the column for large block insertion. - void Reserve(size_t new_cap) override; - /// Appends content of given column to the end of current one. void Append(ColumnRef column) override; + /// Increase the capacity of the column for large block insertion. + void Reserve(size_t new_cap) override; + size_t Capacity() const override; /// Loads column prefix from input stream. bool LoadPrefix(InputStream* input, size_t rows) override; diff --git a/clickhouse/columns/numeric.cpp b/clickhouse/columns/numeric.cpp index 6cebdb76..71da9c9d 100644 --- a/clickhouse/columns/numeric.cpp +++ b/clickhouse/columns/numeric.cpp @@ -43,6 +43,13 @@ std::vector& ColumnVector::GetWritableData() { return data_; } +template +void ColumnVector::Append(ColumnRef column) { + if (auto col = column->As>()) { + data_.insert(data_.end(), col->data_.begin(), col->data_.end()); + } +} + template void ColumnVector::Reserve(size_t new_cap) { data_.reserve(new_cap); @@ -63,13 +70,6 @@ const T& ColumnVector::At(size_t n) const { return data_.at(n); } -template -void ColumnVector::Append(ColumnRef column) { - if (auto col = column->As>()) { - data_.insert(data_.end(), col->data_.begin(), col->data_.end()); - } -} - template bool ColumnVector::LoadBody(InputStream* input, size_t rows) { data_.resize(rows); diff --git a/clickhouse/columns/numeric.h b/clickhouse/columns/numeric.h index e3b1cdf2..58f7daeb 100644 --- a/clickhouse/columns/numeric.h +++ b/clickhouse/columns/numeric.h @@ -19,9 +19,6 @@ class ColumnVector : public Column { explicit ColumnVector(const std::vector& data); explicit ColumnVector(std::vector && data); - /// Increase the capacity of the column for large block insertion. - void Reserve(size_t new_cap) override; - /// Appends one element to the end of column. void Append(const T& value); @@ -36,12 +33,13 @@ class ColumnVector : public Column { /// Get Raw Vector Contents std::vector& GetWritableData(); - /// Returns the capacity of the column - size_t Capacity() const; - public: /// Appends content of given column to the end of current one. void Append(ColumnRef column) override; + /// Increase the capacity of the column for large block insertion. + void Reserve(size_t new_cap) override; + /// Returns the capacity of the column + size_t Capacity() const override; /// Loads column data from input stream. bool LoadBody(InputStream* input, size_t rows) override; diff --git a/clickhouse/columns/string.cpp b/clickhouse/columns/string.cpp index 5c5a51ef..f0d34aed 100644 --- a/clickhouse/columns/string.cpp +++ b/clickhouse/columns/string.cpp @@ -70,6 +70,11 @@ void ColumnFixedString::Reserve(size_t new_cap) { data_.reserve(string_size_ * new_cap); } +size_t ColumnFixedString::Capacity() const { + const auto data_cap = data_.capacity(); + return (data_cap - data_.size()) / string_size_; +} + void ColumnFixedString::Append(std::string_view str) { if (str.size() > string_size_) { throw ValidationError("Expected string of length not greater than " @@ -255,6 +260,10 @@ void ColumnString::Reserve(size_t new_cap) { } } +size_t ColumnString::Capacity() const { + return items_.capacity(); +} + void ColumnString::SetEstimatedValueSize(EstimatedValueSize value_size_estimation) { value_size_estimation_ = static_cast(Validate(value_size_estimation)); } diff --git a/clickhouse/columns/string.h b/clickhouse/columns/string.h index a4a2004c..839f5b9b 100644 --- a/clickhouse/columns/string.h +++ b/clickhouse/columns/string.h @@ -27,9 +27,6 @@ class ColumnFixedString : public Column { Append(v); } - /// Increase the capacity of the column for large block insertion. - void Reserve(size_t) override; - /// Appends one element to the column. void Append(std::string_view str); @@ -45,6 +42,9 @@ class ColumnFixedString : public Column { public: /// Appends content of given column to the end of current one. void Append(ColumnRef column) override; + /// Increase the capacity of the column for large block insertion. + void Reserve(size_t) override; + size_t Capacity() const override; /// Loads column data from input stream. bool LoadBody(InputStream* input, size_t rows) override; @@ -137,6 +137,9 @@ class ColumnString : public Column { /// Increase the capacity of the column for large block insertion. void Reserve(size_t new_cap) override; + /// Returns the capacity of the column + size_t Capacity() const override; + /// Loads column data from input stream. bool LoadBody(InputStream* input, size_t rows) override; diff --git a/clickhouse/columns/tuple.cpp b/clickhouse/columns/tuple.cpp index af3ca650..3174449b 100644 --- a/clickhouse/columns/tuple.cpp +++ b/clickhouse/columns/tuple.cpp @@ -20,12 +20,6 @@ size_t ColumnTuple::TupleSize() const { return columns_.size(); } -void ColumnTuple::Reserve(size_t new_cap) { - for (auto& column : columns_) { - column->Reserve(new_cap); - } -} - void ColumnTuple::Append(ColumnRef column) { if (!this->Type()->IsEqual(column->Type())) { throw ValidationError( @@ -37,6 +31,17 @@ void ColumnTuple::Append(ColumnRef column) { columns_[ci]->Append((*source_tuple_column)[ci]); } } + +void ColumnTuple::Reserve(size_t new_cap) { + for (auto& column : columns_) { + column->Reserve(new_cap); + } +} + +size_t ColumnTuple::Capacity() const { + return columns_.size() ? columns_[0]->Capacity() : 0; +} + size_t ColumnTuple::Size() const { return columns_.empty() ? 0 : columns_[0]->Size(); } diff --git a/clickhouse/columns/tuple.h b/clickhouse/columns/tuple.h index 9b3a7501..307d9a42 100644 --- a/clickhouse/columns/tuple.h +++ b/clickhouse/columns/tuple.h @@ -26,11 +26,11 @@ class ColumnTuple : public Column { } public: - /// Increase the capacity of the column for large block insertion. - void Reserve(size_t new_cap) override; - /// Appends content of given column to the end of current one. void Append(ColumnRef column) override; + /// Increase the capacity of the column for large block insertion. + void Reserve(size_t new_cap) override; + size_t Capacity() const override; /// Loads column prefix from input stream. bool LoadPrefix(InputStream* input, size_t rows) override; diff --git a/clickhouse/columns/uuid.cpp b/clickhouse/columns/uuid.cpp index 0b6f9320..6dd2af69 100644 --- a/clickhouse/columns/uuid.cpp +++ b/clickhouse/columns/uuid.cpp @@ -38,6 +38,10 @@ void ColumnUUID::Reserve(size_t new_cap) { data_->Reserve(new_cap); } +size_t ColumnUUID::Capacity() const { + return data_->Capacity(); +} + void ColumnUUID::Append(ColumnRef column) { if (auto col = column->As()) { data_->Append(col->data_); diff --git a/clickhouse/columns/uuid.h b/clickhouse/columns/uuid.h index 518aad59..07547f58 100644 --- a/clickhouse/columns/uuid.h +++ b/clickhouse/columns/uuid.h @@ -26,11 +26,11 @@ class ColumnUUID : public Column { inline const UUID operator [] (size_t n) const { return At(n); } public: - /// Increase the capacity of the column for large block insertion. - void Reserve(size_t new_cap) override; - /// Appends content of given column to the end of current one. void Append(ColumnRef column) override; + /// Increase the capacity of the column for large block insertion. + void Reserve(size_t new_cap) override; + size_t Capacity() const override; /// Loads column data from input stream. bool LoadBody(InputStream* input, size_t rows) override; diff --git a/ut/ColumnLowCardinalityT_ut.cpp b/ut/ColumnLowCardinalityT_ut.cpp index fe5cedf3..9c813a48 100644 --- a/ut/ColumnLowCardinalityT_ut.cpp +++ b/ut/ColumnLowCardinalityT_ut.cpp @@ -229,7 +229,7 @@ TEST(ColumnLowCardinalityString, WithSizeEstimation) { } } - dumpMemoryUsage("After appending all values", col) << std::endl; + dumpMemoryUsage("After appending all values", col); } } } diff --git a/ut/Column_ut.cpp b/ut/Column_ut.cpp index 9940ea60..79c70a6f 100644 --- a/ut/Column_ut.cpp +++ b/ut/Column_ut.cpp @@ -445,8 +445,11 @@ TYPED_TEST(GenericColumnTest, ReserveAndCapacity) { if constexpr (has_method_Reserve_v && has_method_Capacity_v) { auto column = this->MakeColumn(); - EXPECT_EQ(0u, column->Capacity()); + + EXPECT_GT(16u, column->Capacity()); // Column might have some non-zero capacity initially + EXPECT_NO_THROW(column->Reserve(100u)); + EXPECT_EQ(100u, column->Capacity()); EXPECT_EQ(0u, column->Size()); diff --git a/ut/utils.cpp b/ut/utils.cpp index b7cfe305..c9b86c93 100644 --- a/ut/utils.cpp +++ b/ut/utils.cpp @@ -415,6 +415,10 @@ std::string ToString(const clickhouse::UUID& v) { return result; } -std::ostream & dumpMemoryUsage(const char * prefix, const clickhouse::ColumnRef col) { - return std::cerr << prefix << " " << col->GetType().GetName() << " : " << PrettyPrintByteSize{col->MemoryUsage()} << std::endl; +void dumpMemoryUsage(const char * prefix, const clickhouse::ColumnRef col) { +#if defined(_NDEBUG) + return; +#else + std::cerr << prefix << " " << col->GetType().GetName() << " : " << PrettyPrintByteSize{col->MemoryUsage()} << std::endl; +#endif } diff --git a/ut/utils.h b/ut/utils.h index 8b8fb4d7..36306acb 100644 --- a/ut/utils.h +++ b/ut/utils.h @@ -221,4 +221,4 @@ uint64_t versionNumber(const clickhouse::ServerInfo & server_info); std::string ToString(const clickhouse::UUID& v); -std::ostream & dumpMemoryUsage(const char * prefix, const clickhouse::ColumnRef col); +void dumpMemoryUsage(const char * prefix, const clickhouse::ColumnRef col);