Skip to content
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

fix clang tidy for columns #3153

Closed
wants to merge 14 commits into from
42 changes: 21 additions & 21 deletions dbms/src/Columns/ColumnArray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,21 +149,21 @@ void ColumnArray::insertData(const char * pos, size_t length)
{
/** Similarly - only for arrays of fixed length values.
*/
IColumn * data_ = &getData();
if (!data_->isFixedAndContiguous())
IColumn * array_data = &getData();
if (!array_data->isFixedAndContiguous())
throw Exception("Method insertData is not supported for " + getName(), ErrorCodes::NOT_IMPLEMENTED);

size_t field_size = data_->sizeOfValueIfFixed();
size_t field_size = array_data->sizeOfValueIfFixed();

const char * end = pos + length;
size_t elems = 0;
for (; pos + field_size <= end; pos += field_size, ++elems)
data_->insertData(pos, field_size);
array_data->insertData(pos, field_size);

if (pos != end)
throw Exception("Incorrect length argument for method ColumnArray::insertData", ErrorCodes::BAD_ARGUMENTS);

getOffsets().push_back((getOffsets().size() == 0 ? 0 : getOffsets().back()) + elems);
getOffsets().push_back((getOffsets().empty() ? 0 : getOffsets().back()) + elems);
}


Expand Down Expand Up @@ -191,7 +191,7 @@ const char * ColumnArray::deserializeAndInsertFromArena(const char * pos, const
for (size_t i = 0; i < array_size; ++i)
pos = getData().deserializeAndInsertFromArena(pos, collator);

getOffsets().push_back((getOffsets().size() == 0 ? 0 : getOffsets().back()) + array_size);
getOffsets().push_back((getOffsets().empty() ? 0 : getOffsets().back()) + array_size);
return pos;
}

Expand Down Expand Up @@ -258,7 +258,7 @@ void ColumnArray::insert(const Field & x)
size_t size = array.size();
for (size_t i = 0; i < size; ++i)
getData().insert(array[i]);
getOffsets().push_back((getOffsets().size() == 0 ? 0 : getOffsets().back()) + size);
getOffsets().push_back((getOffsets().empty() ? 0 : getOffsets().back()) + size);
}


Expand All @@ -269,13 +269,13 @@ void ColumnArray::insertFrom(const IColumn & src_, size_t n)
size_t offset = src.offsetAt(n);

getData().insertRangeFrom(src.getData(), offset, size);
getOffsets().push_back((getOffsets().size() == 0 ? 0 : getOffsets().back()) + size);
getOffsets().push_back((getOffsets().empty() ? 0 : getOffsets().back()) + size);
}


void ColumnArray::insertDefault()
{
getOffsets().push_back(getOffsets().size() == 0 ? 0 : getOffsets().back());
getOffsets().push_back(getOffsets().empty() ? 0 : getOffsets().back());
}


Expand Down Expand Up @@ -475,7 +475,7 @@ ColumnPtr ColumnArray::filter(const Filter & filt, ssize_t result_size_hint) con
template <typename T>
ColumnPtr ColumnArray::filterNumber(const Filter & filt, ssize_t result_size_hint) const
{
if (getOffsets().size() == 0)
if (getOffsets().empty())
return ColumnArray::create(data);

auto res = ColumnArray::create(data->cloneEmpty());
Expand Down Expand Up @@ -602,15 +602,15 @@ ColumnPtr ColumnArray::filterGeneric(const Filter & filt, ssize_t result_size_hi

ColumnPtr ColumnArray::filterNullable(const Filter & filt, ssize_t result_size_hint) const
{
if (getOffsets().size() == 0)
if (getOffsets().empty())
return ColumnArray::create(data);

const ColumnNullable & nullable_elems = static_cast<const ColumnNullable &>(*data);

auto array_of_nested = ColumnArray::create(nullable_elems.getNestedColumnPtr(), offsets);
auto filtered_array_of_nested_owner = array_of_nested->filter(filt, result_size_hint);
auto & filtered_array_of_nested = static_cast<const ColumnArray &>(*filtered_array_of_nested_owner);
auto & filtered_offsets = filtered_array_of_nested.getOffsetsPtr();
const auto & filtered_array_of_nested = static_cast<const ColumnArray &>(*filtered_array_of_nested_owner);
const auto & filtered_offsets = filtered_array_of_nested.getOffsetsPtr();

auto res_null_map = ColumnUInt8::create();

Expand All @@ -625,7 +625,7 @@ ColumnPtr ColumnArray::filterNullable(const Filter & filt, ssize_t result_size_h

ColumnPtr ColumnArray::filterTuple(const Filter & filt, ssize_t result_size_hint) const
{
if (getOffsets().size() == 0)
if (getOffsets().empty())
return ColumnArray::create(data);

const ColumnTuple & tuple = static_cast<const ColumnTuple &>(*data);
Expand Down Expand Up @@ -762,13 +762,13 @@ ColumnPtr ColumnArray::replicateNumber(const Offsets & replicate_offsets) const
if (0 == col_size)
return res;

ColumnArray & res_ = typeid_cast<ColumnArray &>(*res);
ColumnArray & array_res = typeid_cast<ColumnArray &>(*res);

const typename ColumnVector<T>::Container & src_data = typeid_cast<const ColumnVector<T> &>(*data).getData();
const Offsets & src_offsets = getOffsets();

typename ColumnVector<T>::Container & res_data = typeid_cast<ColumnVector<T> &>(res_.getData()).getData();
Offsets & res_offsets = res_.getOffsets();
typename ColumnVector<T>::Container & res_data = typeid_cast<ColumnVector<T> &>(array_res.getData()).getData();
Offsets & res_offsets = array_res.getOffsets();

res_data.reserve(data->size() / col_size * replicate_offsets.back());
res_offsets.reserve(replicate_offsets.back());
Expand Down Expand Up @@ -810,16 +810,16 @@ ColumnPtr ColumnArray::replicateString(const Offsets & replicate_offsets) const
if (0 == col_size)
return res;

ColumnArray & res_ = static_cast<ColumnArray &>(*res);
ColumnArray & array_res = static_cast<ColumnArray &>(*res);

const ColumnString & src_string = typeid_cast<const ColumnString &>(*data);
const ColumnString::Chars_t & src_chars = src_string.getChars();
const Offsets & src_string_offsets = src_string.getOffsets();
const Offsets & src_offsets = getOffsets();

ColumnString::Chars_t & res_chars = typeid_cast<ColumnString &>(res_.getData()).getChars();
Offsets & res_string_offsets = typeid_cast<ColumnString &>(res_.getData()).getOffsets();
Offsets & res_offsets = res_.getOffsets();
ColumnString::Chars_t & res_chars = typeid_cast<ColumnString &>(array_res.getData()).getChars();
Offsets & res_string_offsets = typeid_cast<ColumnString &>(array_res.getData()).getOffsets();
Offsets & res_offsets = array_res.getOffsets();

res_chars.reserve(src_chars.size() / col_size * replicate_offsets.back());
res_string_offsets.reserve(src_string_offsets.size() / col_size * replicate_offsets.back());
Expand Down
30 changes: 19 additions & 11 deletions dbms/src/Columns/ColumnConst.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <Common/HashTable/Hash.h>
#include <Common/typeid_cast.h>
#include <IO/WriteHelpers.h>
#include <fmt/core.h>

namespace DB
{
Expand All @@ -20,8 +21,9 @@ ColumnConst::ColumnConst(const ColumnPtr & data_, size_t s)
data = const_data->getDataColumnPtr();

if (data->size() != 1)
throw Exception("Incorrect size of nested column in constructor of ColumnConst: " + toString(data->size()) + ", must be 1.",
ErrorCodes::SIZES_OF_COLUMNS_DOESNT_MATCH);
throw Exception(
fmt::format("Incorrect size of nested column in constructor of ColumnConst: {}, must be 1.", data->size()),
ErrorCodes::SIZES_OF_COLUMNS_DOESNT_MATCH);
}

ColumnPtr ColumnConst::convertToFullColumn() const
Expand All @@ -32,17 +34,19 @@ ColumnPtr ColumnConst::convertToFullColumn() const
ColumnPtr ColumnConst::filter(const Filter & filt, ssize_t /*result_size_hint*/) const
{
if (s != filt.size())
throw Exception("Size of filter (" + toString(filt.size()) + ") doesn't match size of column (" + toString(s) + ")",
ErrorCodes::SIZES_OF_COLUMNS_DOESNT_MATCH);
throw Exception(
fmt::format("Size of filter ({}) doesn't match size of column ({})", filt.size(), s),
ErrorCodes::SIZES_OF_COLUMNS_DOESNT_MATCH);

return ColumnConst::create(data, countBytesInFilter(filt));
}

ColumnPtr ColumnConst::replicate(const Offsets & offsets) const
{
if (s != offsets.size())
throw Exception("Size of offsets (" + toString(offsets.size()) + ") doesn't match size of column (" + toString(s) + ")",
ErrorCodes::SIZES_OF_COLUMNS_DOESNT_MATCH);
throw Exception(
fmt::format("Size of offsets ({}) doesn't match size of column ({})", offsets.size(), s),
ErrorCodes::SIZES_OF_COLUMNS_DOESNT_MATCH);

size_t replicated_size = 0 == s ? 0 : offsets.back();
return ColumnConst::create(data, replicated_size);
Expand All @@ -56,17 +60,19 @@ ColumnPtr ColumnConst::permute(const Permutation & perm, size_t limit) const
limit = std::min(s, limit);

if (perm.size() < limit)
throw Exception("Size of permutation (" + toString(perm.size()) + ") is less than required (" + toString(limit) + ")",
ErrorCodes::SIZES_OF_COLUMNS_DOESNT_MATCH);
throw Exception(
fmt::format("Size of permutation ({}) is less than required ({})", perm.size(), limit),
ErrorCodes::SIZES_OF_COLUMNS_DOESNT_MATCH);

return ColumnConst::create(data, limit);
}

MutableColumns ColumnConst::scatter(ColumnIndex num_columns, const Selector & selector) const
{
if (s != selector.size())
throw Exception("Size of selector (" + toString(selector.size()) + ") doesn't match size of column (" + toString(s) + ")",
ErrorCodes::SIZES_OF_COLUMNS_DOESNT_MATCH);
throw Exception(
fmt::format("Size of selector ({}) doesn't match size of column ({})", selector.size(), s),
ErrorCodes::SIZES_OF_COLUMNS_DOESNT_MATCH);

std::vector<size_t> counts = countColumnsSizeInSelector(num_columns, selector);

Expand All @@ -87,7 +93,9 @@ void ColumnConst::getPermutation(bool /*reverse*/, size_t /*limit*/, int /*nan_d
void ColumnConst::updateWeakHash32(WeakHash32 & hash, const TiDB::TiDBCollatorPtr & collator, String & sort_key_container) const
{
if (hash.getData().size() != s)
throw Exception("Size of WeakHash32 does not match size of column: column size is " + std::to_string(s) + ", hash size is " + std::to_string(hash.getData().size()), ErrorCodes::LOGICAL_ERROR);
throw Exception(
fmt::format("Size of WeakHash32 does not match size of column: column size is {}, hash size is {}", s, hash.getData().size()),
ErrorCodes::LOGICAL_ERROR);

WeakHash32 element_hash(1);
data->updateWeakHash32(element_hash, collator, sort_key_container);
Expand Down
2 changes: 1 addition & 1 deletion dbms/src/Columns/ColumnConst.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class ColumnConst final : public COWPtrHelper<IColumn, ColumnConst>
const char * deserializeAndInsertFromArena(const char * pos, const TiDB::TiDBCollatorPtr & collator) override
{
auto & mutable_data = data->assumeMutableRef();
auto res = mutable_data.deserializeAndInsertFromArena(pos, collator);
const auto * res = mutable_data.deserializeAndInsertFromArena(pos, collator);
mutable_data.popBack(1);
++s;
return res;
Expand Down
8 changes: 4 additions & 4 deletions dbms/src/Columns/ColumnDecimal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ StringRef ColumnDecimal<T>::serializeValueIntoArena(size_t n, Arena & arena, cha
{
/// serialize Decimal256 in `Non-trivial, Binary` way, the serialization logical is
/// copied from https://github.com/pingcap/boost-extra/blob/master/boost/multiprecision/cpp_int/serialize.hpp#L149
size_t mem_size = 0;
size_t mem_size;
SeaRise marked this conversation as resolved.
Show resolved Hide resolved
const typename T::NativeType::backend_type & val = data[n].value.backend();
bool s = val.sign();
size_t limb_count = val.size();

mem_size = sizeof(bool) + sizeof(size_t) + limb_count * sizeof(boost::multiprecision::limb_type);

auto pos = arena.allocContinue(mem_size, begin);
auto current_pos = pos;
auto * pos = arena.allocContinue(mem_size, begin);
auto * current_pos = pos;
memcpy(current_pos, &s, sizeof(bool));
current_pos += sizeof(bool);

Expand All @@ -59,7 +59,7 @@ StringRef ColumnDecimal<T>::serializeValueIntoArena(size_t n, Arena & arena, cha
}
else
{
auto pos = arena.allocContinue(sizeof(T), begin);
auto * pos = arena.allocContinue(sizeof(T), begin);
memcpy(pos, &data[n], sizeof(T));
return StringRef(pos, sizeof(T));
}
Expand Down
5 changes: 2 additions & 3 deletions dbms/src/Columns/ColumnNothing.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@

namespace DB
{

class ColumnNothing final : public COWPtrHelper<IColumnDummy, ColumnNothing>
{
private:
friend class COWPtrHelper<IColumnDummy, ColumnNothing>;

ColumnNothing(size_t s_)
explicit ColumnNothing(size_t s_)
{
s = s_;
}
Expand All @@ -25,4 +24,4 @@ class ColumnNothing final : public COWPtrHelper<IColumnDummy, ColumnNothing>
bool canBeInsideNullable() const override { return true; }
};

}
} // namespace DB
26 changes: 13 additions & 13 deletions dbms/src/Columns/ColumnNullable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ void ColumnNullable::updateHashWithValues(
size_t null_count = 0;

/// TODO: use an more efficient way to calc the sum.
for (size_t i = 0, n = arr.size(); i < n; ++i)
for (const auto i : arr)
{
null_count += arr[i];
null_count += i;
}

if (null_count == 0)
Expand Down Expand Up @@ -162,7 +162,7 @@ StringRef ColumnNullable::serializeValueIntoArena(
const auto & arr = getNullMapData();
static constexpr auto s = sizeof(arr[0]);

auto pos = arena.allocContinue(s, begin);
auto * pos = arena.allocContinue(s, begin);
memcpy(pos, &arr[n], s);

size_t nested_size = 0;
Expand Down Expand Up @@ -478,25 +478,25 @@ void ColumnNullable::getExtremes(Field & min, Field & max) const

const auto & null_map = getNullMapData();

if (const auto col = typeid_cast<const ColumnInt8 *>(nested_column.get()))
if (const auto * const col = typeid_cast<const ColumnInt8 *>(nested_column.get()))
SeaRise marked this conversation as resolved.
Show resolved Hide resolved
getExtremesFromNullableContent<Int8>(*col, null_map, min, max);
else if (const auto col = typeid_cast<const ColumnInt16 *>(nested_column.get()))
else if (const auto * const col = typeid_cast<const ColumnInt16 *>(nested_column.get()))
getExtremesFromNullableContent<Int16>(*col, null_map, min, max);
else if (const auto col = typeid_cast<const ColumnInt32 *>(nested_column.get()))
else if (const auto * const col = typeid_cast<const ColumnInt32 *>(nested_column.get()))
getExtremesFromNullableContent<Int32>(*col, null_map, min, max);
else if (const auto col = typeid_cast<const ColumnInt64 *>(nested_column.get()))
else if (const auto * const col = typeid_cast<const ColumnInt64 *>(nested_column.get()))
getExtremesFromNullableContent<Int64>(*col, null_map, min, max);
else if (const auto col = typeid_cast<const ColumnUInt8 *>(nested_column.get()))
else if (const auto * const col = typeid_cast<const ColumnUInt8 *>(nested_column.get()))
getExtremesFromNullableContent<UInt8>(*col, null_map, min, max);
else if (const auto col = typeid_cast<const ColumnUInt16 *>(nested_column.get()))
else if (const auto * const col = typeid_cast<const ColumnUInt16 *>(nested_column.get()))
getExtremesFromNullableContent<UInt16>(*col, null_map, min, max);
else if (const auto col = typeid_cast<const ColumnUInt32 *>(nested_column.get()))
else if (const auto * const col = typeid_cast<const ColumnUInt32 *>(nested_column.get()))
getExtremesFromNullableContent<UInt32>(*col, null_map, min, max);
else if (const auto col = typeid_cast<const ColumnUInt64 *>(nested_column.get()))
else if (const auto * const col = typeid_cast<const ColumnUInt64 *>(nested_column.get()))
getExtremesFromNullableContent<UInt64>(*col, null_map, min, max);
else if (const auto col = typeid_cast<const ColumnFloat32 *>(nested_column.get()))
else if (const auto * const col = typeid_cast<const ColumnFloat32 *>(nested_column.get()))
getExtremesFromNullableContent<Float32>(*col, null_map, min, max);
else if (const auto col = typeid_cast<const ColumnFloat64 *>(nested_column.get()))
else if (const auto * const col = typeid_cast<const ColumnFloat64 *>(nested_column.get()))
getExtremesFromNullableContent<Float64>(*col, null_map, min, max);
}

Expand Down
2 changes: 1 addition & 1 deletion dbms/src/Columns/ColumnNullable.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class ColumnNullable final : public COWPtrHelper<IColumn, ColumnNullable>
StringRef serializeValueIntoArena(size_t n, Arena & arena, char const *& begin, const TiDB::TiDBCollatorPtr &, String &) const override;
const char * deserializeAndInsertFromArena(const char * pos, const TiDB::TiDBCollatorPtr &) override;
void insertRangeFrom(const IColumn & src, size_t start, size_t length) override;
;

void insert(const Field & x) override;
void insertFrom(const IColumn & src, size_t n) override;

Expand Down
10 changes: 5 additions & 5 deletions dbms/src/Columns/ColumnTuple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ void ColumnTuple::popBack(size_t n)
StringRef ColumnTuple::serializeValueIntoArena(size_t n, Arena & arena, char const *& begin, const TiDB::TiDBCollatorPtr & collator, String & sort_key_container) const
{
size_t values_size = 0;
for (auto & column : columns)
for (const auto & column : columns)
values_size += column->serializeValueIntoArena(n, arena, begin, collator, sort_key_container).size;

return StringRef(begin, values_size);
Expand All @@ -144,13 +144,13 @@ const char * ColumnTuple::deserializeAndInsertFromArena(const char * pos, const

void ColumnTuple::updateHashWithValue(size_t n, SipHash & hash, const TiDB::TiDBCollatorPtr & collator, String & sort_key_container) const
{
for (auto & column : columns)
for (const auto & column : columns)
column->updateHashWithValue(n, hash, collator, sort_key_container);
}

void ColumnTuple::updateHashWithValues(IColumn::HashValues & hash_values, const TiDB::TiDBCollatorPtr & collator, String & sort_key_container) const
{
for (auto & column : columns)
for (const auto & column : columns)
column->updateHashWithValues(hash_values, collator, sort_key_container);
}

Expand Down Expand Up @@ -254,9 +254,9 @@ struct ColumnTuple::Less

bool operator()(size_t a, size_t b) const
{
for (ColumnRawPtrs::const_iterator it = plain_columns.begin(); it != plain_columns.end(); ++it)
for (const auto * plain_column : plain_columns)
{
int res = (*it)->compareAt(a, b, **it, nan_direction_hint);
int res = plain_column->compareAt(a, b, *plain_column, nan_direction_hint);
if (res < 0)
return positive;
else if (res > 0)
Expand Down
Loading