Skip to content

Commit

Permalink
Merge pull request #355 from german3w1/german3w1-FixedStringType-impr…
Browse files Browse the repository at this point in the history
…ovement

Added `GetSize()` const method for FixedStringType
  • Loading branch information
Enmk authored Feb 1, 2024
2 parents 157369c + a7ac900 commit 6f056da
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions clickhouse/types/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,8 @@ class FixedStringType : public Type {

std::string GetName() const { return std::string("FixedString(") + std::to_string(size_) + ")"; }

inline size_t GetSize() const { return size_; }

private:
size_t size_;
};
Expand Down
16 changes: 16 additions & 0 deletions ut/columns_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,16 @@ TEST(ColumnsCase, FixedString_Append_LargeString) {
EXPECT_ANY_THROW(col->Append("this is a long string"));
}

TEST(ColumnsCase, FixedString_Type_Size_Eq0) {
const auto col = std::make_shared<ColumnFixedString>(0);
ASSERT_EQ(col->FixedSize(), col->Type()->As<FixedStringType>()->GetSize());
}

TEST(ColumnsCase, FixedString_Type_Size_Eq10) {
const auto col = std::make_shared<ColumnFixedString>(10);
ASSERT_EQ(col->FixedSize(), col->Type()->As<FixedStringType>()->GetSize());
}

TEST(ColumnsCase, StringInit) {
auto values = MakeStrings();
auto col = std::make_shared<ColumnString>(values);
Expand Down Expand Up @@ -866,6 +876,12 @@ TEST(ColumnsCase, ColumnLowCardinalityString_WithEmptyString_3) {
}
}

TEST(ColumnsCase, ColumnLowCardinalityFixedString_Type_Size_Eq) {
const size_t fixed_size = 10;
const auto col = std::make_shared<ColumnLowCardinalityT<ColumnFixedString>>(fixed_size);

ASSERT_EQ(fixed_size, col->GetNestedType()->As<FixedStringType>()->GetSize());
}

TEST(ColumnsCase, ColumnTupleT) {
using TestTuple = ColumnTupleT<ColumnUInt64, ColumnString, ColumnFixedString>;
Expand Down

0 comments on commit 6f056da

Please sign in to comment.