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
12 changes: 6 additions & 6 deletions clickhouse/columns/date.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ void ColumnDate::Append(ColumnRef column) {
}
}

std::vector<uint16_t> &ColumnDate::GetRawVector() {
return data_->GetRawVector();
std::vector<uint16_t>& ColumnDate::GetWritableData() {
return data_->GetWritableData();
}

void ColumnDate::Reserve(size_t new_cap) {
Expand Down Expand Up @@ -122,8 +122,8 @@ void ColumnDate32::Append(ColumnRef column) {
}
}

std::vector<int32_t> & ColumnDate32::GetRawVector() {
return data_->GetRawVector();
std::vector<int32_t>& ColumnDate32::GetWritableData() {
return data_->GetWritableData();
}

void ColumnDate32::Reserve(size_t new_cap) {
Expand Down Expand Up @@ -220,8 +220,8 @@ void ColumnDateTime::Append(ColumnRef column) {
}
}

std::vector<uint32_t> & ColumnDateTime::GetRawVector() {
return data_->GetRawVector();
std::vector<uint32_t>& ColumnDateTime::GetWritableData() {
return data_->GetWritableData();
}

void ColumnDateTime::Reserve(size_t new_cap) {
Expand Down
6 changes: 3 additions & 3 deletions clickhouse/columns/date.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class ColumnDate : public Column {
void Append(ColumnRef column) override;

/// Get Raw Vector Contents
std::vector<uint16_t> & GetRawVector();
std::vector<uint16_t>& GetWritableData();

/// Increase the capacity of the column
void Reserve(size_t new_cap);
Expand Down Expand Up @@ -89,7 +89,7 @@ class ColumnDate32 : public Column {
int32_t RawAt(size_t n) const;

/// Get Raw Vector Contents
std::vector<int32_t> & GetRawVector();
std::vector<int32_t>& GetWritableData();

/// Increase the capacity of the column
void Reserve(size_t new_cap);
Expand Down Expand Up @@ -146,7 +146,7 @@ class ColumnDateTime : public Column {
std::string Timezone() const;

/// Get Raw Vector Contents
std::vector<uint32_t> & GetRawVector();
std::vector<uint32_t>& GetWritableData();

/// Increase the capacity of the column
void Reserve(size_t new_cap);
Expand Down
2 changes: 1 addition & 1 deletion clickhouse/columns/numeric.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void ColumnVector<T>::Erase(size_t pos, size_t count) {
}

template <typename T>
std::vector<T> & ColumnVector<T>::GetRawVector() {
std::vector<T>& ColumnVector<T>::GetWritableData() {
return data_;
}

Expand Down
2 changes: 1 addition & 1 deletion clickhouse/columns/numeric.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class ColumnVector : public Column {
void Erase(size_t pos, size_t count = 1);

/// Get Raw Vector Contents
std::vector<T> & GetRawVector();
std::vector<T>& GetWritableData();

/// Increase the capacity of the column
void Reserve(size_t new_cap);
Expand Down
80 changes: 80 additions & 0 deletions ut/Column_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@
#include <clickhouse/client.h>

#include <gtest/gtest.h>
#include <algorithm>
#include <initializer_list>
#include <memory>
#include <type_traits>

#include "gtest/internal/gtest-internal.h"
#include "ut/utils_comparison.h"
#include "ut/utils_meta.h"
#include "utils.h"
#include "roundtrip_column.h"
#include "value_generators.h"
Expand Down Expand Up @@ -364,6 +368,82 @@ TYPED_TEST(GenericColumnTest, Swap) {
EXPECT_TRUE(CompareRecursive(values, *column_B));
}

// GTEST_SKIP for debug builds to draw attention of developer
#if !defined(NDEBUG)
#define COLUMN_DOESNT_IMPLEMENT(comment) GTEST_SKIP() << this->MakeColumn()->GetType().GetName() << " doesn't implement " << comment;
#else
#define COLUMN_DOESNT_IMPLEMENT(comment) GTEST_SUCCEED() << this->MakeColumn()->GetType().GetName() << " doesn't implement " << comment;
#endif

TYPED_TEST(GenericColumnTest, ReserveAndCapacity) {
if constexpr (
// TODO(venemkov): test that ColumnType has Reserve() and Capacity() methods
is_one_of_v<typename TestFixture::ColumnType,
// Only types that support Reserve() and Capacity() methods
ColumnUInt8,
ColumnUInt16,
ColumnUInt32,
ColumnUInt64,
ColumnInt8,
ColumnInt16,
ColumnInt32,
ColumnInt64,
ColumnInt128,
ColumnFloat32,
ColumnFloat64,
ColumnDate,
ColumnDate32,
ColumnDateTime>) {

auto column = this->MakeColumn();
EXPECT_EQ(0u, column->Capacity());
EXPECT_NO_THROW(column->Reserve(100u));
EXPECT_EQ(100u, column->Capacity());
EXPECT_EQ(0u, column->Size());
}
else {
COLUMN_DOESNT_IMPLEMENT("method Reserve() and Capacity()");
}
}


TYPED_TEST(GenericColumnTest, GetWritableData) {
if constexpr (
// TODO(venemkov): test that ColumnType has GetWritableData() method
is_one_of_v<typename TestFixture::ColumnType,
// Only types that support GetWritableData() method
ColumnUInt8,
ColumnUInt16,
ColumnUInt32,
ColumnUInt64,
ColumnInt8,
ColumnInt16,
ColumnInt32,
ColumnInt64,
ColumnInt128,
ColumnFloat32,
ColumnFloat64,
ColumnDate,
ColumnDate32,
ColumnDateTime>) {
auto [column, values] = this->MakeColumnWithValues(111);
// Do conversion from time_t to internal representation, similar to what ColumnDate and ColumnDate32 do
if constexpr (is_one_of_v<typename TestFixture::ColumnType,
ColumnDate,
ColumnDate32>) {
std::for_each(values.begin(), values.end(), [](auto & value) {
value /= 86400;
});
}

EXPECT_TRUE(CompareRecursive(values, column->GetWritableData()));
}
else {
COLUMN_DOESNT_IMPLEMENT("method GetWritableData()");
}
}


TYPED_TEST(GenericColumnTest, LoadAndSave) {
auto [column_A, values] = this->MakeColumnWithValues(100);

Expand Down
90 changes: 0 additions & 90 deletions ut/columns_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -965,93 +965,3 @@ TEST(ColumnsCase, ColumnMapT_Wrap) {
EXPECT_EQ("123", map_view.At(1));
EXPECT_EQ("abc", map_view.At(2));
}

TEST(ColumnsCase, ReservedAndCapacity) {
std::vector<std::shared_ptr<Column>> columns;

#define RaC_TEST_CASE(test_id_in, column_type) \
case test_id_in: { \
columns.push_back(std::make_shared<column_type>()); \
auto column = std::static_pointer_cast<column_type>(columns[test_id_in]); \
column->Reserve(100u); \
ASSERT_EQ(column->Capacity(), 100u); \
ASSERT_EQ(columns[test_id_in]->Size(), 0u); \
break; \
}

for (uint8_t rac_test_id = 0; rac_test_id < 14; ++rac_test_id) {
switch (rac_test_id) {
RaC_TEST_CASE( 0, ColumnUInt8);
RaC_TEST_CASE( 1, ColumnUInt16);
RaC_TEST_CASE( 2, ColumnUInt32);
RaC_TEST_CASE( 3, ColumnUInt64);
RaC_TEST_CASE( 4, ColumnInt8);
RaC_TEST_CASE( 5, ColumnInt16);
RaC_TEST_CASE( 6, ColumnInt32);
RaC_TEST_CASE( 7, ColumnInt64);
RaC_TEST_CASE( 8, ColumnInt128);
RaC_TEST_CASE( 9, ColumnFloat32);
RaC_TEST_CASE(10, ColumnFloat64);
RaC_TEST_CASE(11, ColumnDate);
RaC_TEST_CASE(12, ColumnDate32);
RaC_TEST_CASE(13, ColumnDateTime);
default: {
EXPECT_NE(0, 0);
break;
}
}
}
}

TEST(ColumnsCase, RawVector) {
std::vector<std::shared_ptr<Column>> columns;

#define RV_TEST_CASE(test_id_in, column_type) \
case test_id_in: { \
columns.push_back(std::make_shared<column_type>()); \
auto column = std::static_pointer_cast<column_type>(columns[test_id_in]); \
column->Append(10u); \
column->Append(20u); \
ASSERT_EQ(columns[test_id_in]->Size(), 2u); \
auto column_v = column->GetRawVector(); \
ASSERT_EQ(static_cast<uint32_t>(column_v[0]), 10u); \
ASSERT_EQ(static_cast<uint32_t>(column_v[1]), 20u); \
break; \
}

#define RV_TEST_CASE_D(test_id_in, column_type) \
case test_id_in: { \
columns.push_back(std::make_shared<column_type>()); \
auto column = std::static_pointer_cast<column_type>(columns[test_id_in]); \
column->AppendRaw(10u); \
column->AppendRaw(20u); \
ASSERT_EQ(columns[test_id_in]->Size(), 2u); \
auto column_v = column->GetRawVector(); \
ASSERT_EQ(static_cast<uint32_t>(column_v[0]), 10u); \
ASSERT_EQ(static_cast<uint32_t>(column_v[1]), 20u); \
break; \
}

for (uint8_t rv_test_id = 0; rv_test_id < 14; ++rv_test_id) {
switch (rv_test_id) {
RV_TEST_CASE( 0, ColumnUInt8);
RV_TEST_CASE( 1, ColumnUInt16);
RV_TEST_CASE( 2, ColumnUInt32);
RV_TEST_CASE( 3, ColumnUInt64);
RV_TEST_CASE( 4, ColumnInt8);
RV_TEST_CASE( 5, ColumnInt16);
RV_TEST_CASE( 6, ColumnInt32);
RV_TEST_CASE( 7, ColumnInt64);
RV_TEST_CASE( 8, ColumnInt128);
RV_TEST_CASE( 9, ColumnFloat32);
RV_TEST_CASE( 10, ColumnFloat64);
RV_TEST_CASE_D( 11, ColumnDate);
RV_TEST_CASE_D( 12, ColumnDate32);
RV_TEST_CASE_D( 13, ColumnDateTime);
default: {
EXPECT_NE(0, 0);
break;
}
}
}
}
3 changes: 2 additions & 1 deletion ut/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "utils_meta.h"
#include "utils_comparison.h"

#include <iterator>
#include <optional>
#include <ostream>
#include <ratio>
Expand Down Expand Up @@ -181,7 +182,7 @@ std::ostream& operator<<(std::ostream & ostr, const PrintContainer<T>& print_con
}
}

return ostr << "]";
return ostr << "] (" << std::size(container) << " items)";
}

inline uint64_t versionNumber(
Expand Down
15 changes: 15 additions & 0 deletions ut/utils_meta.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,18 @@ struct is_instantiation_of< Template, Template<Args...> > : std::true_type {};

template <typename T>
inline constexpr bool is_string_v = std::is_same_v<std::string, std::decay_t<T>> || std::is_same_v<std::string_view, std::decay_t<T>>;

// https://stackoverflow.com/a/34111095
template <typename...>
struct is_one_of {
static constexpr bool value = false;
};

template <typename F, typename S, typename... T>
struct is_one_of<F, S, T...> {
static constexpr bool value =
std::is_same<F, S>::value || is_one_of<F, T...>::value;
};

template <typename F, typename S, typename... T>
inline constexpr bool is_one_of_v = is_one_of<F, S, T...>::value;