Skip to content

Commit b7a279e

Browse files
committed
Fixed UUID cases, a bit more rigorous tests
1 parent fb91b7c commit b7a279e

File tree

7 files changed

+72
-26
lines changed

7 files changed

+72
-26
lines changed

ut/Column_ut.cpp

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,14 @@ class GenericColumnTest : public testing::Test {
6262
return GenerateVector(values_size, FromVectorGenerator{MakeIPv4s()});
6363
} else if constexpr (std::is_same_v<ColumnType, ColumnIPv6>) {
6464
return GenerateVector(values_size, FromVectorGenerator{MakeIPv6s()});
65+
} else if constexpr (std::is_same_v<ColumnType, ColumnInt128>) {
66+
return GenerateVector(values_size, FromVectorGenerator{MakeInt128s()});
67+
} else if constexpr (std::is_same_v<ColumnType, ColumnDecimal>) {
68+
return GenerateVector(values_size, FromVectorGenerator{MakeDecimals(3, 10)});
69+
} else if constexpr (std::is_same_v<ColumnType, ColumnUUID>) {
70+
return GenerateVector(values_size, FromVectorGenerator{MakeUUIDs()});
6571
} else if constexpr (std::is_integral_v<typename ColumnType::ValueType>
66-
|| std::is_floating_point_v<typename ColumnType::ValueType>
67-
|| std::is_same_v<ColumnType, ColumnInt128>) {
72+
|| std::is_floating_point_v<typename ColumnType::ValueType>) {
6873
// ColumnUIntX and ColumnIntX
6974
// OR ColumnFloatX
7075
return GenerateVector<typename ColumnType::ValueType>(values_size, RandomGenerator<typename ColumnType::ValueType>());
@@ -91,13 +96,12 @@ using ValueColumns = ::testing::Types<
9196
ColumnUInt8, ColumnUInt16, ColumnUInt32, ColumnUInt64
9297
, ColumnInt8, ColumnInt16, ColumnInt32, ColumnInt64
9398
, ColumnFloat32, ColumnFloat64
94-
, ColumnString//, //ColumnFixedString
95-
, ColumnDate
96-
, ColumnDateTime//, ColumnDateTime64
99+
, ColumnString, ColumnFixedString
100+
, ColumnDate, ColumnDateTime, ColumnDateTime64
97101
, ColumnIPv4, ColumnIPv6
98102
// , ColumnInt128
99103
// , ColumnDecimal
100-
// , ColumnUUID
104+
, ColumnUUID
101105
>;
102106
TYPED_TEST_SUITE(GenericColumnTest, ValueColumns);
103107

@@ -108,6 +112,9 @@ TYPED_TEST(GenericColumnTest, EmptyColumn) {
108112

109113
// Shouldn't be able to get items on empty column.
110114
ASSERT_ANY_THROW(column->At(0));
115+
116+
// TODO: verify that Column methods work as expected on empty column:
117+
// some throw exceptions, some return poper values (like CloneEmpty)
111118
}
112119

113120
TYPED_TEST(GenericColumnTest, Append) {
@@ -126,6 +133,8 @@ TYPED_TEST(GenericColumnTest, Slice) {
126133

127134
auto untyped_slice = column->Slice(0, column->Size());
128135
auto slice = untyped_slice->template AsStrict<typename TestFixture::ColumnType>();
136+
EXPECT_EQ(column->GetType(), slice->GetType());
137+
129138
EXPECT_TRUE(CompareRecursive(values, *slice));
130139

131140
// TODO: slices of different sizes
@@ -138,6 +147,8 @@ TYPED_TEST(GenericColumnTest, CloneEmpty) {
138147
// Check that type matches
139148
auto clone = clone_untyped->template AsStrict<typename TestFixture::ColumnType>();
140149
EXPECT_EQ(0u, clone->Size());
150+
151+
EXPECT_EQ(column->GetType(), clone->GetType());
141152
}
142153

143154
TYPED_TEST(GenericColumnTest, Clear) {

ut/columns_ut.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,16 +351,25 @@ TEST(ColumnsCase, NullableSlice) {
351351
ASSERT_EQ(subData->At(3), 17u);
352352
}
353353

354+
// internal representation of UUID data in ColumnUUID
355+
std::vector<uint64_t> MakeUUID_data() {
356+
return {
357+
0xbb6a8c699ab2414cllu, 0x86697b7fd27f0825llu,
358+
0x84b9f24bc26b49c6llu, 0xa03b4ab723341951llu,
359+
0x3507213c178649f9llu, 0x9faf035d662f60aellu
360+
};
361+
}
362+
354363
TEST(ColumnsCase, UUIDInit) {
355-
auto col = std::make_shared<ColumnUUID>(std::make_shared<ColumnUInt64>(MakeUUIDs()));
364+
auto col = std::make_shared<ColumnUUID>(std::make_shared<ColumnUInt64>(MakeUUID_data()));
356365

357366
ASSERT_EQ(col->Size(), 3u);
358367
ASSERT_EQ(col->At(0), UInt128(0xbb6a8c699ab2414cllu, 0x86697b7fd27f0825llu));
359368
ASSERT_EQ(col->At(2), UInt128(0x3507213c178649f9llu, 0x9faf035d662f60aellu));
360369
}
361370

362371
TEST(ColumnsCase, UUIDSlice) {
363-
auto col = std::make_shared<ColumnUUID>(std::make_shared<ColumnUInt64>(MakeUUIDs()));
372+
auto col = std::make_shared<ColumnUUID>(std::make_shared<ColumnUInt64>(MakeUUID_data()));
364373
auto sub = col->Slice(1, 2)->As<ColumnUUID>();
365374

366375
ASSERT_EQ(sub->Size(), 2u);

ut/utils.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,3 +248,8 @@ std::ostream& operator<<(std::ostream& ostr, const in6_addr& addr) {
248248

249249
return ostr << ip_str;
250250
}
251+
252+
std::ostream& operator<<(std::ostream & ostr, const clickhouse::Type & type) {
253+
return ostr << type.GetName();
254+
}
255+

ut/utils.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
#pragma once
22

33
#include <clickhouse/base/platform.h>
4+
#include <clickhouse/columns/uuid.h>
5+
6+
#include "utils_meta.h"
7+
#include "utils_comparison.h"
48

59
#include <ostream>
610
#include <ratio>
@@ -13,11 +17,9 @@
1317

1418
#include <gtest/gtest.h>
1519

16-
#include "utils_meta.h"
17-
#include "utils_comparison.h"
18-
1920
namespace clickhouse {
2021
class Block;
22+
class Type;
2123
}
2224

2325
template <typename ResultType = std::string>
@@ -76,6 +78,11 @@ template <typename R, typename P>
7678
inline ostream & operator<<(ostream & ostr, const chrono::duration<R, P> & d) {
7779
return ostr << d.count() << ::getPrefix<P>() << "s";
7880
}
81+
82+
template <typename F, typename S>
83+
inline ostream & operator<<(ostream & ostr, const pair<F, S> & t) {
84+
return ostr << "{ " << t.first << ", " << t.second << " }";
85+
}
7986
}
8087

8188

@@ -88,6 +95,7 @@ struct PrettyPrintBlock {
8895

8996
std::ostream& operator<<(std::ostream & ostr, const clickhouse::Block & block);
9097
std::ostream& operator<<(std::ostream & ostr, const PrettyPrintBlock & block);
98+
std::ostream& operator<<(std::ostream & ostr, const clickhouse::Type & type);
9199
std::ostream& operator<<(std::ostream& ostr, const in_addr& addr);
92100
std::ostream& operator<<(std::ostream& ostr, const in6_addr& addr);
93101

ut/utils_comparison.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ inline bool operator!=(const std::string_view & left, const in6_addr & right) {
6262
return !(left == right);
6363
}
6464

65-
6665
namespace details {
6766
// Make a column a RO stl-like container
6867
template <typename NestedColumnType>

ut/value_generators.cpp

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,15 @@ using namespace clickhouse;
88
}
99

1010
std::vector<uint32_t> MakeNumbers() {
11-
return std::vector<uint32_t>
12-
{1, 2, 3, 7, 11, 13, 17, 19, 23, 29, 31};
11+
return std::vector<uint32_t> {1, 2, 3, 7, 11, 13, 17, 19, 23, 29, 31};
1312
}
1413

1514
std::vector<uint8_t> MakeBools() {
16-
return std::vector<uint8_t>
17-
{1, 0, 0, 0, 1, 1, 0, 1, 1, 1, 0};
15+
return std::vector<uint8_t> {1, 0, 0, 0, 1, 1, 0, 1, 1, 1, 0};
1816
}
1917

2018
std::vector<std::string> MakeFixedStrings(size_t string_size) {
21-
std::vector<std::string> result
22-
{"aaa", "bbb", "ccc", "ddd"};
19+
std::vector<std::string> result {"aaa", "bbb", "ccc", "ddd"};
2320

2421
std::for_each(result.begin(), result.end(), [string_size](auto& value) {
2522
value.resize(string_size, '\0');
@@ -29,15 +26,16 @@ std::vector<std::string> MakeFixedStrings(size_t string_size) {
2926
}
3027

3128
std::vector<std::string> MakeStrings() {
32-
return std::vector<std::string>
33-
{"a", "ab", "abc", "abcd"};
29+
return {"a", "ab", "abc", "abcd"};
3430
}
3531

36-
std::vector<uint64_t> MakeUUIDs() {
37-
return std::vector<uint64_t>
38-
{0xbb6a8c699ab2414cllu, 0x86697b7fd27f0825llu,
39-
0x84b9f24bc26b49c6llu, 0xa03b4ab723341951llu,
40-
0x3507213c178649f9llu, 0x9faf035d662f60aellu};
32+
std::vector<UInt128> MakeUUIDs() {
33+
return {
34+
UInt128(0llu, 0llu),
35+
UInt128(0xbb6a8c699ab2414cllu, 0x86697b7fd27f0825llu),
36+
UInt128(0x84b9f24bc26b49c6llu, 0xa03b4ab723341951llu),
37+
UInt128(0x3507213c178649f9llu, 0x9faf035d662f60aellu)
38+
};
4139
}
4240

4341
std::vector<Int64> MakeDateTime64s(size_t scale, size_t values_size) {
@@ -76,6 +74,20 @@ std::vector<clickhouse::Int64> MakeDateTimes() {
7674
};
7775
}
7876

77+
std::vector<clickhouse::Int128> MakeInt128s() {
78+
return {
79+
absl::MakeInt128(0xffffffffffffffffll, 0xffffffffffffffffll), // -1
80+
absl::MakeInt128(0, 0xffffffffffffffffll), // 2^64
81+
absl::MakeInt128(0xffffffffffffffffll, 0),
82+
absl::MakeInt128(0x8000000000000000ll, 0),
83+
Int128(0)
84+
};
85+
}
86+
87+
std::vector<clickhouse::Int128> MakeDecimals(size_t /*precision*/, size_t /*scale*/) {
88+
return MakeInt128s();
89+
}
90+
7991
std::string FooBarGenerator(size_t i) {
8092
std::string result;
8193
if (i % 3 == 0)

ut/value_generators.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,14 @@ std::vector<uint32_t> MakeNumbers();
3131
std::vector<uint8_t> MakeBools();
3232
std::vector<std::string> MakeFixedStrings(size_t string_size);
3333
std::vector<std::string> MakeStrings();
34-
std::vector<uint64_t> MakeUUIDs();
3534
std::vector<clickhouse::Int64> MakeDateTime64s(size_t scale, size_t values_size = 200);
3635
std::vector<clickhouse::Int64> MakeDates();
3736
std::vector<clickhouse::Int64> MakeDateTimes();
3837
std::vector<in_addr> MakeIPv4s();
3938
std::vector<in6_addr> MakeIPv6s();
39+
std::vector<clickhouse::UInt128> MakeUUIDs();
40+
std::vector<clickhouse::Int128> MakeInt128s();
41+
std::vector<clickhouse::Int128> MakeDecimals(size_t precision, size_t scale);
4042

4143
std::string FooBarGenerator(size_t i);
4244

0 commit comments

Comments
 (0)