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

*: Rename the function with “withCollation” postfix #3790

Merged
merged 10 commits into from
May 24, 2022
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
37 changes: 20 additions & 17 deletions dbms/src/Columns/ColumnNullable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <Common/assert_cast.h>
#include <Common/typeid_cast.h>
#include <DataStreams/ColumnGathererStream.h>
#include <fmt/core.h>


namespace DB
Expand All @@ -41,10 +42,10 @@ ColumnNullable::ColumnNullable(MutableColumnPtr && nested_column_, MutableColumn
nested_column = nested_column_materialized;

if (!getNestedColumn().canBeInsideNullable())
throw Exception{getNestedColumn().getName() + " cannot be inside Nullable column", ErrorCodes::ILLEGAL_COLUMN};
throw Exception(fmt::format("{} cannot be inside Nullable column", getNestedColumn().getName()), ErrorCodes::ILLEGAL_COLUMN);

if (null_map->isColumnConst())
throw Exception{"ColumnNullable cannot have constant null map", ErrorCodes::ILLEGAL_COLUMN};
throw Exception("ColumnNullable cannot have constant null map", ErrorCodes::ILLEGAL_COLUMN);
}


Expand Down Expand Up @@ -106,7 +107,7 @@ void ColumnNullable::updateWeakHash32(WeakHash32 & hash, const TiDB::TiDBCollato
auto s = size();

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 old_hash = hash;
nested_column->updateWeakHash32(hash, collator, sort_key_container);
Expand Down Expand Up @@ -158,12 +159,12 @@ void ColumnNullable::get(size_t n, Field & res) const

StringRef ColumnNullable::getDataAt(size_t /*n*/) const
{
throw Exception{"Method getDataAt is not supported for " + getName(), ErrorCodes::NOT_IMPLEMENTED};
throw Exception(fmt::format("Method getDataAt is not supported for {}", getName()), ErrorCodes::NOT_IMPLEMENTED);
}

void ColumnNullable::insertData(const char * /*pos*/, size_t /*length*/)
{
throw Exception{"Method insertData is not supported for " + getName(), ErrorCodes::NOT_IMPLEMENTED};
throw Exception(fmt::format("Method insertData is not supported for {}", getName()), ErrorCodes::NOT_IMPLEMENTED);
}

bool ColumnNullable::decodeTiDBRowV2Datum(size_t cursor, const String & raw_value, size_t length, bool force_decode)
Expand Down Expand Up @@ -212,7 +213,7 @@ const char * ColumnNullable::deserializeAndInsertFromArena(const char * pos, con

void ColumnNullable::insertRangeFrom(const IColumn & src, size_t start, size_t length)
{
const ColumnNullable & nullable_col = static_cast<const ColumnNullable &>(src);
const auto & nullable_col = static_cast<const ColumnNullable &>(src);
getNullMapColumn().insertRangeFrom(*nullable_col.null_map, start, length);
getNestedColumn().insertRangeFrom(*nullable_col.nested_column, start, length);
}
Expand All @@ -233,7 +234,7 @@ void ColumnNullable::insert(const Field & x)

void ColumnNullable::insertFrom(const IColumn & src, size_t n)
{
const ColumnNullable & src_concrete = static_cast<const ColumnNullable &>(src);
const auto & src_concrete = static_cast<const ColumnNullable &>(src);
getNestedColumn().insertFrom(src_concrete.getNestedColumn(), n);
getNullMapData().push_back(src_concrete.getNullMapData()[n]);
}
Expand Down Expand Up @@ -285,40 +286,40 @@ std::tuple<bool, int> ColumnNullable::compareAtCheckNull(size_t n, size_t m, con
return std::make_tuple(has_null, res);
}

int ColumnNullable::compareAtWithCollation(
int ColumnNullable::compareAt(
size_t n,
size_t m,
const IColumn & rhs_,
int null_direction_hint,
const ICollator & collator) const
{
const ColumnNullable & nullable_rhs = static_cast<const ColumnNullable &>(rhs_);
const auto & nullable_rhs = static_cast<const ColumnNullable &>(rhs_);
auto [has_null, res] = compareAtCheckNull(n, m, nullable_rhs, null_direction_hint);
if (has_null)
return res;
const IColumn & nested_rhs = nullable_rhs.getNestedColumn();
return getNestedColumn().compareAtWithCollation(n, m, nested_rhs, null_direction_hint, collator);
return getNestedColumn().compareAt(n, m, nested_rhs, null_direction_hint, collator);
}

int ColumnNullable::compareAt(size_t n, size_t m, const IColumn & rhs_, int null_direction_hint) const
{
const ColumnNullable & nullable_rhs = static_cast<const ColumnNullable &>(rhs_);
const auto & nullable_rhs = static_cast<const ColumnNullable &>(rhs_);
auto [has_null, res] = compareAtCheckNull(n, m, nullable_rhs, null_direction_hint);
if (has_null)
return res;
const IColumn & nested_rhs = nullable_rhs.getNestedColumn();
return getNestedColumn().compareAt(n, m, nested_rhs, null_direction_hint);
}

void ColumnNullable::getPermutationWithCollation(
void ColumnNullable::getPermutation(
const ICollator & collator,
bool reverse,
size_t limit,
int null_direction_hint,
DB::IColumn::Permutation & res) const
{
/// Cannot pass limit because of unknown amount of NULLs.
getNestedColumn().getPermutationWithCollation(collator, reverse, 0, null_direction_hint, res);
getNestedColumn().getPermutation(collator, reverse, 0, null_direction_hint, res);
adjustPermutationWithNullDirection(reverse, limit, null_direction_hint, res);
}

Expand Down Expand Up @@ -538,7 +539,7 @@ void ColumnNullable::applyNullMapImpl(const ColumnUInt8 & map)
const NullMap & arr2 = map.getData();

if (arr1.size() != arr2.size())
throw Exception{"Inconsistent sizes of ColumnNullable objects", ErrorCodes::LOGICAL_ERROR};
throw Exception("Inconsistent sizes of ColumnNullable objects", ErrorCodes::LOGICAL_ERROR);

for (size_t i = 0, size = arr1.size(); i < size; ++i)
arr1[i] |= negative ^ arr2[i];
Expand All @@ -565,9 +566,11 @@ void ColumnNullable::applyNullMap(const ColumnNullable & other)
void ColumnNullable::checkConsistency() const
{
if (null_map->size() != getNestedColumn().size())
throw Exception("Logical error: Sizes of nested column and null map of Nullable column are not equal: null size is : "
+ std::to_string(null_map->size()) + " column size is : " + std::to_string(getNestedColumn().size()),
ErrorCodes::SIZES_OF_NESTED_COLUMNS_ARE_INCONSISTENT);
throw Exception(
fmt::format("Logical error: Sizes of nested column and null map of Nullable column are not equal: null size is : {} column size is : {}",
null_map->size(),
getNestedColumn().size()),
ErrorCodes::SIZES_OF_NESTED_COLUMNS_ARE_INCONSISTENT);
}


Expand Down
4 changes: 2 additions & 2 deletions dbms/src/Columns/ColumnNullable.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ class ColumnNullable final : public COWPtrHelper<IColumn, ColumnNullable>
ColumnPtr permute(const Permutation & perm, size_t limit) const override;
std::tuple<bool, int> compareAtCheckNull(size_t n, size_t m, const ColumnNullable & rhs, int null_direction_hint) const;
int compareAt(size_t n, size_t m, const IColumn & rhs_, int null_direction_hint) const override;
int compareAtWithCollation(size_t n, size_t m, const IColumn & rhs_, int null_direction_hint, const ICollator & collator) const override;
int compareAt(size_t n, size_t m, const IColumn & rhs_, int null_direction_hint, const ICollator & collator) const override;
void getPermutation(bool reverse, size_t limit, int null_direction_hint, Permutation & res) const override;
void getPermutationWithCollation(const ICollator & collator, bool reverse, size_t limit, int null_direction_hint, Permutation & res) const override;
void getPermutation(const ICollator & collator, bool reverse, size_t limit, int null_direction_hint, Permutation & res) const override;
void adjustPermutationWithNullDirection(bool reverse, size_t limit, int null_direction_hint, Permutation & res) const;
void reserve(size_t n) override;
size_t byteSize() const override;
Expand Down
7 changes: 4 additions & 3 deletions dbms/src/Columns/ColumnString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <Columns/ColumnsCommon.h>
#include <Common/HashTable/Hash.h>
#include <DataStreams/ColumnGathererStream.h>
#include <fmt/core.h>

/// Used in the `reserve` method, when the number of rows is known, but sizes of elements are not.
#define APPROX_STRING_SIZE 64
Expand Down Expand Up @@ -80,7 +81,7 @@ void ColumnString::insertRangeFrom(const IColumn & src, size_t start, size_t len
if (length == 0)
return;

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

if (start + length > src_concrete.offsets.size())
throw Exception("Parameter out of bound in IColumnString::insertRangeFrom method.",
Expand Down Expand Up @@ -310,7 +311,7 @@ void ColumnString::getExtremes(Field & min, Field & max) const

int ColumnString::compareAtWithCollationImpl(size_t n, size_t m, const IColumn & rhs_, const ICollator & collator) const
{
const ColumnString & rhs = static_cast<const ColumnString &>(rhs_);
const auto & rhs = static_cast<const ColumnString &>(rhs_);

return collator.compare(
reinterpret_cast<const char *>(&chars[offsetAt(n)]),
Expand Down Expand Up @@ -374,7 +375,7 @@ void ColumnString::updateWeakHash32(WeakHash32 & hash, const TiDB::TiDBCollatorP
auto s = offsets.size();

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);

const UInt8 * pos = chars.data();
UInt32 * hash_data = hash.getData().data();
Expand Down
4 changes: 2 additions & 2 deletions dbms/src/Columns/ColumnString.h
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ class ColumnString final : public COWPtrHelper<IColumn, ColumnString>
return size > rhs_size ? 1 : (size < rhs_size ? -1 : 0);
}

int compareAtWithCollation(size_t n, size_t m, const IColumn & rhs_, int, const ICollator & collator) const override
int compareAt(size_t n, size_t m, const IColumn & rhs_, int, const ICollator & collator) const override
{
return compareAtWithCollationImpl(n, m, rhs_, collator);
}
Expand All @@ -324,7 +324,7 @@ class ColumnString final : public COWPtrHelper<IColumn, ColumnString>

void getPermutation(bool reverse, size_t limit, int nan_direction_hint, Permutation & res) const override;

void getPermutationWithCollation(const ICollator & collator, bool reverse, size_t limit, int, Permutation & res) const override
void getPermutation(const ICollator & collator, bool reverse, size_t limit, int, Permutation & res) const override
{
getPermutationWithCollationImpl(collator, reverse, limit, res);
}
Expand Down
8 changes: 4 additions & 4 deletions dbms/src/Columns/IColumn.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,9 @@ class IColumn : public COWPtr<IColumn>
*/
virtual int compareAt(size_t n, size_t m, const IColumn & rhs, int nan_direction_hint) const = 0;

virtual int compareAtWithCollation(size_t, size_t, const IColumn &, int, const ICollator &) const
virtual int compareAt(size_t, size_t, const IColumn &, int, const ICollator &) const
{
throw Exception("Method compareAtWithCollation is not supported for " + getName(), ErrorCodes::NOT_IMPLEMENTED);
throw Exception(fmt::format("Method compareAt with collation is not supported for {}" + getName()), ErrorCodes::NOT_IMPLEMENTED);
}

/** Returns a permutation that sorts elements of this column,
Expand All @@ -252,9 +252,9 @@ class IColumn : public COWPtr<IColumn>
*/
virtual void getPermutation(bool reverse, size_t limit, int nan_direction_hint, Permutation & res) const = 0;

virtual void getPermutationWithCollation(const ICollator &, bool, size_t, int, Permutation &) const
virtual void getPermutation(const ICollator &, bool, size_t, int, Permutation &) const
{
throw Exception("Method getPermutationWithCollation is not supported for " + getName(), ErrorCodes::NOT_IMPLEMENTED);
throw Exception(fmt::format("Method getPermutation with collation is not supported for {}", getName()), ErrorCodes::NOT_IMPLEMENTED);
}

/** Copies each element according offsets parameter.
Expand Down
4 changes: 2 additions & 2 deletions dbms/src/Core/SortCursor.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ struct SortCursorWithCollation
int nulls_direction = impl->desc[i].nulls_direction;
int res;
if (impl->need_collation[i])
res = impl->sort_columns[i]->compareAtWithCollation(lhs_pos, rhs_pos, *(rhs.impl->sort_columns[i]), nulls_direction, *impl->desc[i].collator);
res = impl->sort_columns[i]->compareAt(lhs_pos, rhs_pos, *(rhs.impl->sort_columns[i]), nulls_direction, *impl->desc[i].collator);
else
res = impl->sort_columns[i]->compareAt(lhs_pos, rhs_pos, *(rhs.impl->sort_columns[i]), nulls_direction);

Expand All @@ -241,7 +241,7 @@ struct SortCursorWithCollation
int res;
if (impl->need_collation[i])
{
res = impl->sort_columns[i]->compareAtWithCollation(lhs_pos, rhs_pos, *(rhs.impl->sort_columns[i]), nulls_direction, *impl->desc[i].collator);
res = impl->sort_columns[i]->compareAt(lhs_pos, rhs_pos, *(rhs.impl->sort_columns[i]), nulls_direction, *impl->desc[i].collator);
}
else
res = impl->sort_columns[i]->compareAt(lhs_pos, rhs_pos, *(rhs.impl->sort_columns[i]), nulls_direction);
Expand Down
12 changes: 6 additions & 6 deletions dbms/src/DataStreams/WindowBlockInputStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,11 @@ bool WindowBlockInputStream::isDifferentFromPrevPartition(UInt64 current_partiti
const auto * compared_column = compared_columns[partition_column_indices[i]].get();
if (window_description.partition_by[i].collator)
{
if (compared_column->compareAtWithCollation(current_partition_row,
prev_frame_start.row,
*reference_column,
1 /* nan_direction_hint */,
*window_description.partition_by[i].collator)
if (compared_column->compareAt(current_partition_row,
prev_frame_start.row,
*reference_column,
1 /* nan_direction_hint */,
*window_description.partition_by[i].collator)
!= 0)
{
return true;
Expand Down Expand Up @@ -278,7 +278,7 @@ bool WindowBlockInputStream::arePeers(const RowNumber & x, const RowNumber & y)
const auto * column_y = inputAt(y)[order_column_indices[i]].get();
if (window_description.order_by[i].collator)
{
if (column_x->compareAtWithCollation(x.row, y.row, *column_y, 1 /* nan_direction_hint */, *window_description.order_by[i].collator) != 0)
if (column_x->compareAt(x.row, y.row, *column_y, 1 /* nan_direction_hint */, *window_description.order_by[i].collator) != 0)
{
return false;
}
Expand Down
18 changes: 9 additions & 9 deletions dbms/src/Interpreters/sortBlock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ static inline bool needCollation(const IColumn * column, const SortColumnDescrip
{
if (!description.collator)
return false;
auto not_null_column = column->isColumnNullable() ? typeid_cast<const ColumnNullable *>(column)->getNestedColumnPtr().get() : column;
const auto * not_null_column = column->isColumnNullable() ? typeid_cast<const ColumnNullable *>(column)->getNestedColumnPtr().get() : column;

if (not_null_column->isColumnConst())
return false;
Expand All @@ -73,9 +73,9 @@ struct PartialSortingLess

bool operator()(size_t a, size_t b) const
{
for (ColumnsWithSortDescriptions::const_iterator it = columns.begin(); it != columns.end(); ++it)
for (const auto & column : columns)
{
int res = it->second.direction * it->first->compareAt(a, b, *it->first, it->second.nulls_direction);
int res = column.second.direction * column.first->compareAt(a, b, *column.first, column.second.nulls_direction);
if (res < 0)
return true;
else if (res > 0)
Expand All @@ -95,15 +95,15 @@ struct PartialSortingLessWithCollation

bool operator()(size_t a, size_t b) const
{
for (ColumnsWithSortDescriptions::const_iterator it = columns.begin(); it != columns.end(); ++it)
for (const auto & column : columns)
{
int res;
if (needCollation(it->first, it->second))
res = it->first->compareAtWithCollation(a, b, *it->first, it->second.nulls_direction, *it->second.collator);
if (needCollation(column.first, column.second))
res = column.first->compareAt(a, b, *column.first, column.second.nulls_direction, *column.second.collator);
else
res = it->first->compareAt(a, b, *it->first, it->second.nulls_direction);
res = column.first->compareAt(a, b, *column.first, column.second.nulls_direction);

res *= it->second.direction;
res *= column.second.direction;
if (res < 0)
return true;
else if (res > 0)
Expand All @@ -130,7 +130,7 @@ void sortBlock(Block & block, const SortDescription & description, size_t limit)

IColumn::Permutation perm;
if (needCollation(column, description[0]))
column->getPermutationWithCollation(*description[0].collator, reverse, limit, description[0].nulls_direction, perm);
column->getPermutation(*description[0].collator, reverse, limit, description[0].nulls_direction, perm);
else
column->getPermutation(reverse, limit, description[0].nulls_direction, perm);

Expand Down