Skip to content

Commit

Permalink
Merge branch 'master' into optimize-agg-collation
Browse files Browse the repository at this point in the history
  • Loading branch information
solotzg authored Sep 16, 2022
2 parents 3e3080d + 892f852 commit ce367a6
Show file tree
Hide file tree
Showing 94 changed files with 4,278 additions and 1,755 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,6 @@
[submodule "contrib/arm-optimized-routines"]
path = contrib/arm-optimized-routines
url = https://github.com/ARM-software/optimized-routines
[submodule "contrib/magic_enum"]
path = contrib/magic_enum
url = https://github.com/Neargye/magic_enum.git
2 changes: 2 additions & 0 deletions contrib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,5 @@ endif()
if (ARCH_AARCH64 AND ARCH_LINUX)
add_subdirectory(arm-optimized-routines-cmake)
endif ()

add_subdirectory(magic_enum)
1 change: 1 addition & 0 deletions contrib/magic_enum
Submodule magic_enum added at 43a927
2 changes: 2 additions & 0 deletions dbms/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ add_headers_and_sources(dbms src/DataStreams)
add_headers_and_sources(dbms src/DataTypes)
add_headers_and_sources(dbms src/Databases)
add_headers_and_sources(dbms src/Debug)
add_headers_and_sources(dbms src/Debug/MockExecutor)
add_headers_and_sources(dbms src/Dictionaries)
add_headers_and_sources(dbms src/Dictionaries/Embedded)
add_headers_and_sources(dbms src/Dictionaries/Embedded/GeodataProviders)
Expand Down Expand Up @@ -192,6 +193,7 @@ target_link_libraries (clickhouse_common_io
prometheus-cpp::push
prometheus-cpp::pull
cpptoml
magic_enum
libsymbolization
)
target_include_directories (clickhouse_common_io BEFORE PRIVATE ${kvClient_SOURCE_DIR}/include)
Expand Down
4 changes: 2 additions & 2 deletions dbms/src/Columns/ColumnAggregateFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ MutableColumnPtr ColumnAggregateFunction::convertToValues() const
* AggregateFunction(quantileTiming(0.5), UInt64)
* into UInt16 - already finished result of `quantileTiming`.
*/
if (const AggregateFunctionState * function_state = typeid_cast<const AggregateFunctionState *>(function))
if (const auto * function_state = typeid_cast<const AggregateFunctionState *>(function))
{
auto res = createView();
res->set(function_state->getNestedFunction());
Expand All @@ -96,7 +96,7 @@ MutableColumnPtr ColumnAggregateFunction::convertToValues() const

void ColumnAggregateFunction::insertRangeFrom(const IColumn & from, size_t start, size_t length)
{
const ColumnAggregateFunction & from_concrete = static_cast<const ColumnAggregateFunction &>(from);
const auto & from_concrete = static_cast<const ColumnAggregateFunction &>(from);

if (start + length > from_concrete.getData().size())
throw Exception(
Expand Down
4 changes: 2 additions & 2 deletions dbms/src/Columns/ColumnAggregateFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@ class ColumnAggregateFunction final : public COWPtrHelper<IColumn, ColumnAggrega

void insertDefault() override;

StringRef serializeValueIntoArena(size_t n, Arena & arena, char const *& begin, const TiDB::TiDBCollatorPtr &, String &) const override;
StringRef serializeValueIntoArena(size_t n, Arena & dst, char const *& begin, const TiDB::TiDBCollatorPtr &, String &) const override;

const char * deserializeAndInsertFromArena(const char * pos, const TiDB::TiDBCollatorPtr &) override;
const char * deserializeAndInsertFromArena(const char * src_arena, const TiDB::TiDBCollatorPtr &) override;

void updateHashWithValue(size_t n, SipHash & hash, const TiDB::TiDBCollatorPtr &, String &) const override;

Expand Down
22 changes: 11 additions & 11 deletions dbms/src/Columns/ColumnArray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ void ColumnArray::get(size_t n, Field & res) const
size_t offset = offsetAt(n);
size_t size = sizeAt(n);
res = Array(size);
Array & res_arr = DB::get<Array &>(res);
auto & res_arr = DB::get<Array &>(res);

for (size_t i = 0; i < size; ++i)
getData().get(offset + i, res_arr[i]);
Expand Down Expand Up @@ -268,7 +268,7 @@ void ColumnArray::updateWeakHash32(WeakHash32 & hash, const TiDB::TiDBCollatorPt

void ColumnArray::insert(const Field & x)
{
const Array & array = DB::get<const Array &>(x);
const auto & array = DB::get<const Array &>(x);
size_t size = array.size();
for (size_t i = 0; i < size; ++i)
getData().insert(array[i]);
Expand All @@ -278,7 +278,7 @@ void ColumnArray::insert(const Field & x)

void ColumnArray::insertFrom(const IColumn & src_, size_t n)
{
const ColumnArray & src = static_cast<const ColumnArray &>(src_);
const auto & src = static_cast<const ColumnArray &>(src_);
size_t size = src.sizeAt(n);
size_t offset = src.offsetAt(n);

Expand All @@ -305,7 +305,7 @@ void ColumnArray::popBack(size_t n)

int ColumnArray::compareAt(size_t n, size_t m, const IColumn & rhs_, int nan_direction_hint) const
{
const ColumnArray & rhs = static_cast<const ColumnArray &>(rhs_);
const auto & rhs = static_cast<const ColumnArray &>(rhs_);

/// Suboptimal
size_t lhs_size = sizeAt(n);
Expand Down Expand Up @@ -425,7 +425,7 @@ void ColumnArray::insertRangeFrom(const IColumn & src, size_t start, size_t leng
if (length == 0)
return;

const ColumnArray & src_concrete = static_cast<const ColumnArray &>(src);
const auto & src_concrete = static_cast<const ColumnArray &>(src);

if (start + length > src_concrete.getOffsets().size())
throw Exception("Parameter out of bound in ColumnArray::insertRangeFrom method.",
Expand Down Expand Up @@ -619,7 +619,7 @@ ColumnPtr ColumnArray::filterNullable(const Filter & filt, ssize_t result_size_h
if (getOffsets().empty())
return ColumnArray::create(data);

const ColumnNullable & nullable_elems = static_cast<const ColumnNullable &>(*data);
const auto & 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);
Expand All @@ -642,7 +642,7 @@ ColumnPtr ColumnArray::filterTuple(const Filter & filt, ssize_t result_size_hint
if (getOffsets().empty())
return ColumnArray::create(data);

const ColumnTuple & tuple = static_cast<const ColumnTuple &>(*data);
const auto & tuple = static_cast<const ColumnTuple &>(*data);

/// Make temporary arrays for each components of Tuple, then filter and collect back.

Expand Down Expand Up @@ -824,7 +824,7 @@ ColumnPtr ColumnArray::replicateString(const Offsets & replicate_offsets) const
if (0 == col_size)
return res;

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

const ColumnString & src_string = typeid_cast<const ColumnString &>(*data);
const ColumnString::Chars_t & src_chars = src_string.getChars();
Expand Down Expand Up @@ -935,7 +935,7 @@ ColumnPtr ColumnArray::replicateGeneric(const Offsets & replicate_offsets) const
throw Exception("Size of offsets doesn't match size of column.", ErrorCodes::SIZES_OF_COLUMNS_DOESNT_MATCH);

MutableColumnPtr res = cloneEmpty();
ColumnArray & res_concrete = static_cast<ColumnArray &>(*res);
auto & res_concrete = static_cast<ColumnArray &>(*res);

if (0 == col_size)
return res;
Expand All @@ -956,7 +956,7 @@ ColumnPtr ColumnArray::replicateGeneric(const Offsets & replicate_offsets) const

ColumnPtr ColumnArray::replicateNullable(const Offsets & replicate_offsets) const
{
const ColumnNullable & nullable = static_cast<const ColumnNullable &>(*data);
const auto & nullable = static_cast<const ColumnNullable &>(*data);

/// Make temporary arrays for each components of Nullable. Then replicate them independently and collect back to result.
/// NOTE Offsets are calculated twice and it is redundant.
Expand All @@ -976,7 +976,7 @@ ColumnPtr ColumnArray::replicateNullable(const Offsets & replicate_offsets) cons

ColumnPtr ColumnArray::replicateTuple(const Offsets & replicate_offsets) const
{
const ColumnTuple & tuple = static_cast<const ColumnTuple &>(*data);
const auto & tuple = static_cast<const ColumnTuple &>(*data);

/// Make temporary arrays for each components of Tuple. In the same way as for Nullable.

Expand Down
2 changes: 1 addition & 1 deletion dbms/src/Columns/ColumnConst.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ ColumnConst::ColumnConst(const ColumnPtr & data_, size_t s)
, s(s)
{
/// Squash Const of Const.
while (const ColumnConst * const_data = typeid_cast<const ColumnConst *>(data.get()))
while (const auto * const_data = typeid_cast<const ColumnConst *>(data.get()))
data = const_data->getDataColumnPtr();

if (data->size() != 1)
Expand Down
20 changes: 10 additions & 10 deletions dbms/src/Columns/ColumnDecimal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ const char * ColumnDecimal<T>::deserializeAndInsertFromArena(const char * pos, c
size_t offset = 0;
bool s = unalignedLoad<bool>(pos + offset);
offset += sizeof(bool);
size_t limb_count = unalignedLoad<size_t>(pos + offset);
auto limb_count = unalignedLoad<size_t>(pos + offset);
offset += sizeof(size_t);

val.resize(limb_count, limb_count);
Expand Down Expand Up @@ -244,7 +244,7 @@ void ColumnDecimal<T>::insertData(const char * src [[maybe_unused]], size_t /*le
}
else
{
T tmp;
T tmp{};
memcpy(&tmp, src, sizeof(T));
data.emplace_back(tmp);
}
Expand All @@ -253,23 +253,23 @@ void ColumnDecimal<T>::insertData(const char * src [[maybe_unused]], size_t /*le
template <typename T>
bool ColumnDecimal<T>::decodeTiDBRowV2Datum(size_t cursor, const String & raw_value, size_t /* length */, bool /* force_decode */)
{
PrecType prec_ = raw_value[cursor++];
ScaleType scale_ = raw_value[cursor++];
auto type = createDecimal(prec_, scale_);
if (unlikely(!checkDecimal<T>(*type)))
PrecType dec_prec = static_cast<uint8_t>(raw_value[cursor++]);
ScaleType dec_scale = static_cast<uint8_t>(raw_value[cursor++]);
auto dec_type = createDecimal(dec_prec, dec_scale);
if (unlikely(!checkDecimal<T>(*dec_type)))
{
throw Exception("Detected unmatched decimal value type: Decimal( " + std::to_string(prec_) + ", " + std::to_string(scale_) + ") when decoding with column type " + this->getName(),
throw Exception("Detected unmatched decimal value type: Decimal( " + std::to_string(dec_prec) + ", " + std::to_string(dec_scale) + ") when decoding with column type " + this->getName(),
ErrorCodes::LOGICAL_ERROR);
}
auto res = DecodeDecimalImpl<T>(cursor, raw_value, prec_, scale_);
data.push_back(DecimalField<T>(res, scale_));
auto res = DecodeDecimalImpl<T>(cursor, raw_value, dec_prec, dec_scale);
data.push_back(DecimalField<T>(res, dec_scale));
return true;
}

template <typename T>
void ColumnDecimal<T>::insertRangeFrom(const IColumn & src, size_t start, size_t length)
{
const ColumnDecimal & src_vec = static_cast<const ColumnDecimal &>(src);
const auto & src_vec = static_cast<const ColumnDecimal &>(src);

if (start + length > src_vec.data.size())
throw Exception("Parameters start = " + toString(start) + ", length = " + toString(length) + " are out of bound in ColumnDecimal<T>::insertRangeFrom method (data.size() = " + toString(src_vec.data.size()) + ").",
Expand Down
2 changes: 1 addition & 1 deletion dbms/src/Columns/ColumnDecimal.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class ColumnDecimal final : public COWPtrHelper<ColumnVectorHelper, ColumnDecima
void reserve(size_t n) override { data.reserve(n); }

void insertFrom(const IColumn & src, size_t n) override { data.push_back(static_cast<const Self &>(src).getData()[n]); }
void insertData(const char * pos, size_t /*length*/) override;
void insertData(const char * src, size_t /*length*/) override;
bool decodeTiDBRowV2Datum(size_t cursor, const String & raw_value, size_t length, bool force_decode) override;
void insertDefault() override { data.push_back(T()); }
void insert(const Field & x) override { data.push_back(DB::get<typename NearestFieldType<T>::Type>(x)); }
Expand Down
6 changes: 3 additions & 3 deletions dbms/src/Columns/ColumnFixedString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ MutableColumnPtr ColumnFixedString::cloneResized(size_t size) const

void ColumnFixedString::insert(const Field & x)
{
const String & s = DB::get<const String &>(x);
const auto & s = DB::get<const String &>(x);

if (s.size() > n)
throw Exception("Too large string '" + s + "' for FixedString column", ErrorCodes::TOO_LARGE_STRING_SIZE);
Expand All @@ -69,7 +69,7 @@ void ColumnFixedString::insert(const Field & x)

void ColumnFixedString::insertFrom(const IColumn & src_, size_t index)
{
const ColumnFixedString & src = static_cast<const ColumnFixedString &>(src_);
const auto & src = static_cast<const ColumnFixedString &>(src_);

if (n != src.getN())
throw Exception("Size of FixedString doesn't match", ErrorCodes::SIZE_OF_FIXED_STRING_DOESNT_MATCH);
Expand Down Expand Up @@ -180,7 +180,7 @@ void ColumnFixedString::getPermutation(bool reverse, size_t limit, int /*nan_dir

void ColumnFixedString::insertRangeFrom(const IColumn & src, size_t start, size_t length)
{
const ColumnFixedString & src_concrete = static_cast<const ColumnFixedString &>(src);
const auto & src_concrete = static_cast<const ColumnFixedString &>(src);

if (start + length > src_concrete.size())
throw Exception("Parameters start = "
Expand Down
4 changes: 2 additions & 2 deletions dbms/src/Columns/ColumnNullable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -486,8 +486,8 @@ void getExtremesFromNullableContent(const ColumnVector<T> & col, const NullMap &

if (has_not_null)
{
min = typename NearestFieldType<T>::Type(cur_min);
max = typename NearestFieldType<T>::Type(cur_max);
min = static_cast<typename NearestFieldType<T>::Type>(cur_min);
max = static_cast<typename NearestFieldType<T>::Type>(cur_max);
}
}

Expand Down
2 changes: 1 addition & 1 deletion dbms/src/Columns/ColumnTuple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ void ColumnTuple::insert(const Field & x)

void ColumnTuple::insertFrom(const IColumn & src_, size_t n)
{
const ColumnTuple & src = static_cast<const ColumnTuple &>(src_);
const auto & src = static_cast<const ColumnTuple &>(src_);

const size_t tuple_size = columns.size();
if (src.columns.size() != tuple_size)
Expand Down
14 changes: 7 additions & 7 deletions dbms/src/Columns/ColumnVector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,19 +181,19 @@ UInt64 ColumnVector<T>::get64(size_t n) const
template <typename T>
UInt64 ColumnVector<T>::getUInt(size_t n) const
{
return UInt64(data[n]);
return static_cast<UInt64>(data[n]);
}

template <typename T>
Int64 ColumnVector<T>::getInt(size_t n) const
{
return Int64(data[n]);
return static_cast<Int64>(data[n]);
}

template <typename T>
void ColumnVector<T>::insertRangeFrom(const IColumn & src, size_t start, size_t length)
{
const ColumnVector & src_vec = static_cast<const ColumnVector &>(src);
const auto & src_vec = static_cast<const ColumnVector &>(src);

if (start + length > src_vec.data.size())
throw Exception(
Expand Down Expand Up @@ -334,8 +334,8 @@ void ColumnVector<T>::getExtremes(Field & min, Field & max) const

if (size == 0)
{
min = typename NearestFieldType<T>::Type(0);
max = typename NearestFieldType<T>::Type(0);
min = static_cast<typename NearestFieldType<T>::Type>(0);
max = static_cast<typename NearestFieldType<T>::Type>(0);
return;
}

Expand Down Expand Up @@ -369,8 +369,8 @@ void ColumnVector<T>::getExtremes(Field & min, Field & max) const
cur_max = x;
}

min = typename NearestFieldType<T>::Type(cur_min);
max = typename NearestFieldType<T>::Type(cur_max);
min = static_cast<typename NearestFieldType<T>::Type>(cur_min);
max = static_cast<typename NearestFieldType<T>::Type>(cur_max);
}

/// Explicit template instantiations - to avoid code bloat in headers.
Expand Down
10 changes: 5 additions & 5 deletions dbms/src/Columns/FilterDescription.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ ConstantFilterDescription::ConstantFilterDescription(const IColumn & column)

if (column.isColumnConst())
{
const ColumnConst & column_const = static_cast<const ColumnConst &>(column);
const auto & column_const = static_cast<const ColumnConst &>(column);
const IColumn & column_nested = column_const.getDataColumn();

if (!typeid_cast<const ColumnUInt8 *>(&column_nested))
{
const ColumnNullable * column_nested_nullable = typeid_cast<const ColumnNullable *>(&column_nested);
const auto * column_nested_nullable = typeid_cast<const ColumnNullable *>(&column_nested);
if (!column_nested_nullable || !typeid_cast<const ColumnUInt8 *>(&column_nested_nullable->getNestedColumn()))
{
throw Exception(
Expand All @@ -63,18 +63,18 @@ ConstantFilterDescription::ConstantFilterDescription(const IColumn & column)

FilterDescription::FilterDescription(const IColumn & column)
{
if (const ColumnUInt8 * concrete_column = typeid_cast<const ColumnUInt8 *>(&column))
if (const auto * concrete_column = typeid_cast<const ColumnUInt8 *>(&column))
{
data = &concrete_column->getData();
return;
}

if (const ColumnNullable * nullable_column = typeid_cast<const ColumnNullable *>(&column))
if (const auto * nullable_column = typeid_cast<const ColumnNullable *>(&column))
{
ColumnPtr nested_column = nullable_column->getNestedColumnPtr();
MutableColumnPtr mutable_holder = (*std::move(nested_column)).mutate();

ColumnUInt8 * concrete_column = typeid_cast<ColumnUInt8 *>(mutable_holder.get());
auto * concrete_column = typeid_cast<ColumnUInt8 *>(mutable_holder.get());
if (!concrete_column)
throw Exception(
fmt::format("Illegal type {} of column for filter. Must be UInt8 or Nullable(UInt8).", column.getName()),
Expand Down
Loading

0 comments on commit ce367a6

Please sign in to comment.