diff --git a/clickhouse/columns/date.cpp b/clickhouse/columns/date.cpp index 3bc9662b..4e48129f 100644 --- a/clickhouse/columns/date.cpp +++ b/clickhouse/columns/date.cpp @@ -23,11 +23,14 @@ std::time_t ColumnDate::At(size_t n) const { return static_cast(data_->At(n)) * 86400; } - void ColumnDate::Append(uint16_t value) { data_->Append(value); } +void ColumnDate::AppendRaw(uint16_t value) { + data_->Append(value); +} + uint16_t ColumnDate::RawAt(size_t n) const { return data_->At(n); } @@ -77,7 +80,6 @@ ItemView ColumnDate::GetItem(size_t index) const { } - ColumnDate32::ColumnDate32() : Column(Type::CreateDate32()) , data_(std::make_shared()) @@ -108,6 +110,10 @@ void ColumnDate32::Append(int32_t value) { data_->Append(value); } +void ColumnDate32::AppendRaw(int32_t value) { + data_->Append(value); +} + int32_t ColumnDate32::RawAt(size_t n) const { return data_->At(n); } diff --git a/clickhouse/columns/date.h b/clickhouse/columns/date.h index 2c5202ff..5d3770be 100644 --- a/clickhouse/columns/date.h +++ b/clickhouse/columns/date.h @@ -24,7 +24,7 @@ class ColumnDate : public Column { /// Do data as is -- number of day in Unix epoch, no conversions performed void Append(uint16_t value); - void AppendRaw(uint16_t value) { Append(value); } + void AppendRaw(uint16_t value); uint16_t RawAt(size_t n) const; uint16_t operator [] (size_t n) const; @@ -74,7 +74,7 @@ class ColumnDate32 : public Column { /// Do data as is -- number of day in Unix epoch, no conversions performed void Append(int32_t value); - void AppendRaw(int32_t value) { Append(value); } + void AppendRaw(int32_t value); int32_t RawAt(size_t n) const; int32_t operator [] (size_t n) const; diff --git a/ut/Column_ut.cpp b/ut/Column_ut.cpp index 544be975..8432009f 100644 --- a/ut/Column_ut.cpp +++ b/ut/Column_ut.cpp @@ -66,7 +66,7 @@ class GenericColumnTest : public testing::Test { } else if constexpr (std::is_same_v) { return GenerateVector(values_size, FromVectorGenerator{MakeFixedStrings(12)}); } else if constexpr (std::is_same_v) { - return GenerateVector(values_size, FromVectorGenerator{MakeDates()}); + return GenerateVector(values_size, FromVectorGenerator{MakeDates()}); } else if constexpr (std::is_same_v) { return GenerateVector(values_size, FromVectorGenerator{MakeDateTimes()}); } else if constexpr (std::is_same_v) { @@ -143,6 +143,14 @@ using ValueColumns = ::testing::Types< >; TYPED_TEST_SUITE(GenericColumnTest, ValueColumns); +//TestCase(TypeCreatorFunc, ValuesGeneratorFunc) + + +//class GenericColumnTestCase +//{ +// virutual +//}; + TYPED_TEST(GenericColumnTest, Construct) { auto column = this->MakeColumn(); ASSERT_EQ(0u, column->Size()); diff --git a/ut/value_generators.cpp b/ut/value_generators.cpp index 41e36a61..805f22ad 100644 --- a/ut/value_generators.cpp +++ b/ut/value_generators.cpp @@ -1,6 +1,7 @@ #include "value_generators.h" #include +#include #include namespace { @@ -53,25 +54,13 @@ std::vector MakeDateTime64s(size_t scale, size_t values_size) { }); } -std::vector MakeDates() { - // in CH Date internally a UInt16 and stores a day number - // ColumnDate expects values to be seconds, which is then - // converted to day number internally, hence the `* 86400`. - std::vector result {0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536 - 1}; - std::for_each(result.begin(), result.end(), [](auto& value) { - value *= 86400; - }); - - return result; -} - -std::vector MakeDates32() { +std::vector MakeDates32() { // in CH Date32 internally a UInt32 and stores a day number // ColumnDate expects values to be seconds, which is then // converted to day number internally, hence the `* 86400`. // 114634 * 86400 is 2282-11-10, last integer that fits into DateTime32 range // (max is 2283-11-11) - std::vector result = MakeDates(); + std::vector result = MakeDates(); // add corresponding negative values, since pre-epoch date are supported too. const auto size = result.size(); diff --git a/ut/value_generators.h b/ut/value_generators.h index 3632ca9e..28e54adc 100644 --- a/ut/value_generators.h +++ b/ut/value_generators.h @@ -33,8 +33,7 @@ std::vector MakeBools(); std::vector MakeFixedStrings(size_t string_size); std::vector MakeStrings(); std::vector MakeDateTime64s(size_t scale, size_t values_size = 200); -std::vector MakeDates(); -std::vector MakeDates32(); +std::vector MakeDates32(); std::vector MakeDateTimes(); std::vector MakeIPv4s(); std::vector MakeIPv6s(); @@ -42,6 +41,23 @@ std::vector MakeUUIDs(); std::vector MakeInt128s(); std::vector MakeDecimals(size_t precision, size_t scale); +template +std::vector MakeDates() { + std::vector result {0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536 - 1}; + + if constexpr (std::is_same_v) { + // in CH Date internally a UInt16 and stores a day number + // ColumnDate expects values to be seconds, which is then + // converted to day number internally, hence the `* 86400`. + std::for_each(result.begin(), result.end(), [](auto& value) { + value *= 86400; + }); + } + + return result; +} + + std::string FooBarGenerator(size_t i); template