Skip to content
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
6 changes: 5 additions & 1 deletion clickhouse/columns/string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,11 @@ ColumnRef ColumnFixedString::CloneEmpty() const {

void ColumnFixedString::Swap(Column& other) {
auto & col = dynamic_cast<ColumnFixedString &>(other);
std::swap(string_size_, col.string_size_);
if (string_size_ != col.string_size_) {
throw ValidationError("Can't swap FixedString columns when sizes are not the same: "
+ std::to_string(string_size_) + "(this) != "
+ std::to_string(col.string_size_) + "(that)");
}
data_.swap(col.data_);
}

Expand Down
26 changes: 26 additions & 0 deletions ut/columns_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,32 @@ TEST(ColumnsCase, FixedString_Type_Size_Eq10) {
ASSERT_EQ(col->FixedSize(), col->Type()->As<FixedStringType>()->GetSize());
}

TEST(ColumnsCase, FixedStringSwap) {
auto column1 = std::make_shared<ColumnFixedString>(2);
auto column2 = std::make_shared<ColumnFixedString>(2);
column1->Append("aa");
column2->Append("bb");

column1->Swap(*column2);

EXPECT_EQ(column1->At(0), "bb");
EXPECT_EQ(column2->At(0), "aa");
}

TEST(ColumnsCase, FixedStringSwapDifferentSize) {
auto column1 = std::make_shared<ColumnFixedString>(2);
auto column2 = std::make_shared<ColumnFixedString>(4);
column1->Append("aa");
column2->Append("bbbb");

EXPECT_THROW(column1->Swap(*column2), ValidationError);

EXPECT_EQ(column1->FixedSize(), 2u);
EXPECT_EQ(column2->FixedSize(), 4u);
EXPECT_EQ(column1->At(0), "aa");
EXPECT_EQ(column2->At(0), "bbbb");
}

TEST(ColumnsCase, StringInit) {
auto values = MakeStrings();
auto col = std::make_shared<ColumnString>(values);
Expand Down
Loading