Skip to content

Commit

Permalink
code change for review
Browse files Browse the repository at this point in the history
  • Loading branch information
1261385937 committed Nov 1, 2023
1 parent 6a8729c commit 79f311f
Show file tree
Hide file tree
Showing 13 changed files with 26 additions and 30 deletions.
3 changes: 1 addition & 2 deletions clickhouse/columns/array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ ColumnRef ColumnArray::CloneEmpty() const {
return std::make_shared<ColumnArray>(data_->CloneEmpty());
}

void ColumnArray::Reserve(size_t new_cap)
{
void ColumnArray::Reserve(size_t new_cap) {
data_->Reserve(new_cap);
offsets_->Reserve(new_cap);
}
Expand Down
3 changes: 1 addition & 2 deletions clickhouse/columns/decimal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,7 @@ Int128 ColumnDecimal::At(size_t i) const {
}
}

void ColumnDecimal::Reserve(size_t new_cap)
{
void ColumnDecimal::Reserve(size_t new_cap) {
data_->Reserve(new_cap);
}

Expand Down
3 changes: 1 addition & 2 deletions clickhouse/columns/enum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ void ColumnEnum<T>::SetNameAt(size_t n, const std::string& name) {
}

template<typename T>
void ColumnEnum<T>::Reserve(size_t new_cap)
{
void ColumnEnum<T>::Reserve(size_t new_cap) {
data_.reserve(new_cap);
}

Expand Down
3 changes: 1 addition & 2 deletions clickhouse/columns/geo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ const typename ColumnGeo<NestedColumnType, type_code>::ValueType ColumnGeo<Neste
}

template<typename NestedColumnType, Type::Code type_code>
void ColumnGeo<NestedColumnType, type_code>::Reserve(size_t new_cap)
{
void ColumnGeo<NestedColumnType, type_code>::Reserve(size_t new_cap) {
data_->Reserve(new_cap);
}

Expand Down
3 changes: 1 addition & 2 deletions clickhouse/columns/ip4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ std::string ColumnIPv4::AsString(size_t n) const {
return ip_str;
}

void ColumnIPv4::Reserve(size_t new_cap)
{
void ColumnIPv4::Reserve(size_t new_cap) {
data_->Reserve(new_cap);
}

Expand Down
3 changes: 1 addition & 2 deletions clickhouse/columns/ip6.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ in6_addr ColumnIPv6::operator [] (size_t n) const {
return *reinterpret_cast<const in6_addr*>(data_->At(n).data());
}

void ColumnIPv6::Reserve(size_t new_cap)
{
void ColumnIPv6::Reserve(size_t new_cap) {
data_->Reserve(new_cap);
}

Expand Down
3 changes: 1 addition & 2 deletions clickhouse/columns/lowcardinality.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,7 @@ ColumnLowCardinality::ColumnLowCardinality(std::shared_ptr<ColumnNullable> dicti
ColumnLowCardinality::~ColumnLowCardinality()
{}

void ColumnLowCardinality::Reserve(size_t new_cap)
{
void ColumnLowCardinality::Reserve(size_t new_cap) {
dictionary_column_->Reserve(new_cap);
index_column_->Reserve(new_cap);
}
Expand Down
3 changes: 1 addition & 2 deletions clickhouse/columns/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ ColumnMap::ColumnMap(ColumnRef data)
: Column(GetMapType(data->GetType())), data_(data->As<ColumnArray>()) {
}

void ColumnMap::Reserve(size_t new_cap)
{
void ColumnMap::Reserve(size_t new_cap) {
data_->Reserve(new_cap);
}

Expand Down
3 changes: 1 addition & 2 deletions clickhouse/columns/nullable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ ColumnRef ColumnNullable::Nulls() const
return nulls_;
}

void ColumnNullable::Reserve(size_t new_cap)
{
void ColumnNullable::Reserve(size_t new_cap) {
nested_->Reserve(new_cap);
nulls_->Reserve(new_cap);
}
Expand Down
17 changes: 11 additions & 6 deletions clickhouse/columns/string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ ColumnFixedString::ColumnFixedString(size_t n)
{
}

void ColumnFixedString::Reserve(size_t new_cap) {
data_.reserve(string_size_ * new_cap);
}

void ColumnFixedString::Append(std::string_view str) {
if (str.size() > string_size_) {
throw ValidationError("Expected string of length not greater than "
Expand All @@ -45,8 +49,10 @@ void ColumnFixedString::Append(std::string_view str) {

data_.insert(data_.size(), str);
// Pad up to string_size_ with zeroes.
const auto padding_size = string_size_ - str.size();
data_.resize(data_.size() + padding_size, char(0));
if (str.size() < string_size_) {
const auto padding_size = string_size_ - str.size();
data_.resize(data_.size() + padding_size, char(0));
}
}

void ColumnFixedString::Clear() {
Expand Down Expand Up @@ -160,8 +166,8 @@ ColumnString::ColumnString(size_t element_count)
: Column(Type::CreateString())
{
items_.reserve(element_count);
// 100 is arbitrary number, assumption that string values are about ~40 bytes long.
blocks_.reserve(std::max<size_t>(1, element_count / 100));
// 16 is arbitrary number, assumption that string values are about ~256 bytes long.
blocks_.reserve(std::max<size_t>(1, element_count / 16));
}

ColumnString::ColumnString(const std::vector<std::string>& data)
Expand Down Expand Up @@ -190,8 +196,7 @@ ColumnString::ColumnString(std::vector<std::string>&& data)
ColumnString::~ColumnString()
{}

void ColumnString::Reserve(size_t new_cap)
{
void ColumnString::Reserve(size_t new_cap) {
items_.reserve(new_cap);
// 16 is arbitrary number, assumption that string values are about ~256 bytes long.
blocks_.reserve(std::max<size_t>(1, new_cap / 16));
Expand Down
2 changes: 1 addition & 1 deletion clickhouse/columns/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class ColumnFixedString : public Column {
}

/// Increase the capacity of the column for large block insertion.
void Reserve(size_t) override {};
void Reserve(size_t) override;

/// Appends one element to the column.
void Append(std::string_view str);
Expand Down
7 changes: 4 additions & 3 deletions clickhouse/columns/tuple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ size_t ColumnTuple::TupleSize() const {
return columns_.size();
}

void ColumnTuple::Reserve(size_t new_cap)
{
columns_.reserve(new_cap);
void ColumnTuple::Reserve(size_t new_cap) {
for (auto& column : columns_) {
column->Reserve(new_cap);
}
}

void ColumnTuple::Append(ColumnRef column) {
Expand Down
3 changes: 1 addition & 2 deletions clickhouse/columns/uuid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ const UUID ColumnUUID::At(size_t n) const {
return UUID(data_->At(n * 2), data_->At(n * 2 + 1));
}

void ColumnUUID::Reserve(size_t new_cap)
{
void ColumnUUID::Reserve(size_t new_cap) {
data_->Reserve(new_cap);
}

Expand Down

0 comments on commit 79f311f

Please sign in to comment.