Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jacktengg committed Mar 7, 2025
1 parent 739fc59 commit 92e0daa
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 14 deletions.
31 changes: 21 additions & 10 deletions be/src/vec/columns/column_string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,14 @@ template <typename T>
void ColumnStr<T>::sanity_check() const {
#ifndef NDEBUG
sanity_check_simple();
auto count = cast_set<int>(offsets.size());
for (int i = 0; i < count; ++i) {
auto count = offsets.size();
if (count == 1) {
if (offsets[0] < offsets[-1]) {
throw Exception(Status::InternalError("row count: {}, offsets[{}]: {}, offsets[{}]: {}",
count, 0, offsets[9], -1, offsets[-1]));
}
}
for (size_t i = 0; i < count; ++i) {
if (offsets[i] < offsets[i - 1]) {
throw Exception(Status::InternalError("row count: {}, offsets[{}]: {}, offsets[{}]: {}",
count, i, offsets[i], i - 1, offsets[i - 1]));
Expand All @@ -53,10 +59,19 @@ void ColumnStr<T>::sanity_check() const {
template <typename T>
void ColumnStr<T>::sanity_check_simple() const {
#ifndef NDEBUG
auto count = cast_set<int>(offsets.size());
if (chars.size() != offsets[count - 1]) {
throw Exception(Status::InternalError("row count: {}, chars.size(): {}, offset[{}]: {}",
count, chars.size(), count - 1, offsets[count - 1]));
auto count = offsets.size();
if (count == 0) {
if (chars.size() != offsets[-1]) {
throw Exception(Status::InternalError("row count: {}, chars.size(): {}, offset[{}]: {}",
count, chars.size(), -1, offsets[-1]));
}
} else {
auto size_may_overflow = cast_set<UInt32>(chars.size());
if (size_may_overflow != offsets[count - 1]) {
throw Exception(Status::InternalError("row count: {}, chars.size(): {}, offset[{}]: {}",
count, chars.size(), count - 1,
offsets[count - 1]));
}
}
if (offsets[-1] != 0) {
throw Exception(Status::InternalError("wrong offsets[-1]: {}", offsets[-1]));
Expand Down Expand Up @@ -668,11 +683,7 @@ void ColumnStr<T>::compare_internal(size_t rhs_row_id, const IColumn& rhs, int n

template <typename T>
ColumnPtr ColumnStr<T>::convert_column_if_overflow() {
#ifdef BE_TEST
if (std::is_same_v<T, UInt32> && chars.size() > 10) {
#else
if (std::is_same_v<T, UInt32> && chars.size() > config::string_overflow_size) {
#endif
auto new_col = ColumnStr<uint64_t>::create();

const auto length = offsets.size();
Expand Down
17 changes: 13 additions & 4 deletions be/test/vec/columns/column_string_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -878,13 +878,22 @@ TEST_F(ColumnStringTest, convert_column_if_overflow) {
}
{
auto tmp_col = column_str32->clone();
auto* tmp_col_str32 = assert_cast<ColumnString*>(tmp_col.get());
auto src_size = column_str32->size();
auto* tmp_col_str = assert_cast<ColumnString*>(tmp_col.get());
EXPECT_GT(tmp_col_str->get_chars().size(), 10);
auto chars_size = column_str32->get_chars().size();
auto max_chars_size = config::string_overflow_size;
while (chars_size < max_chars_size) {
tmp_col->insert_range_from_ignore_overflow(*column_str32, 0, column_str32->size());
chars_size = tmp_col_str32->get_chars().size();
}
tmp_col->insert_range_from_ignore_overflow(*column_str32, 0, column_str32->size());
auto tmp_col_row_count = tmp_col->size();
chars_size = tmp_col_str32->get_chars().size();
EXPECT_GT(chars_size, max_chars_size);
auto tmp_col_converted = tmp_col->convert_column_if_overflow();
EXPECT_TRUE(tmp_col_converted->is_column_string64());
for (size_t i = 0; i < src_size; ++i) {
EXPECT_EQ(tmp_col_converted->get_data_at(i), column_str32->get_data_at(i));
for (size_t i = 0; i < tmp_col_row_count; ++i) {
EXPECT_EQ(tmp_col_converted->get_data_at(i), column_str32->get_data_at(i % src_size));
}
}
}
Expand Down

0 comments on commit 92e0daa

Please sign in to comment.