Skip to content

Commit ce78176

Browse files
committed
Start adding Bool type
1 parent b8544bb commit ce78176

File tree

10 files changed

+21
-5
lines changed

10 files changed

+21
-5
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ C++ client for [ClickHouse](https://clickhouse.com/).
1818
* String
1919
* LowCardinality(String) or LowCardinality(FixedString(N))
2020
* Tuple
21-
* UInt8, UInt16, UInt32, UInt64, Int8, Int16, Int32, Int64
21+
* UInt8, UInt16, UInt32, UInt64, Int8, Int16, Int32, Int64, Bool
2222
* UInt128, Int128
2323
* UUID
2424
* Map

clickhouse/columns/factory.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ static ColumnRef CreateTerminalColumn(const TypeAst& ast) {
4848
case Type::Void:
4949
return std::make_shared<ColumnNothing>();
5050

51+
case Type::Bool:
52+
return std::make_shared<ColumnBool>();
5153
case Type::UInt8:
5254
return std::make_shared<ColumnUInt8>();
5355
case Type::UInt16:

clickhouse/columns/itemview.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ void ItemView::ValidateData(Type::Code type, DataType data) {
4141
case Type::Code::Void:
4242
return AssertSize({0});
4343

44+
case Type::Code::Bool:
4445
case Type::Code::Int8:
4546
case Type::Code::UInt8:
4647
case Type::Code::Enum8:

clickhouse/columns/itemview.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ struct ItemView {
6969
if (sizeof(ValueType) == data.size()) {
7070
return *reinterpret_cast<const T*>(data.data());
7171
} else {
72-
throw AssertionError("Incompatitable value type and size. Requested size: "
72+
throw AssertionError("Incompatible value type and size. Requested size: "
7373
+ std::to_string(sizeof(ValueType)) + " stored size: " + std::to_string(data.size()));
7474
}
7575
}

clickhouse/columns/numeric.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ using Int128 = absl::int128;
7070
using UInt128 = absl::uint128;
7171
using Int64 = int64_t;
7272

73+
using ColumnBool = ColumnVector<uint8_t>;
7374
using ColumnUInt8 = ColumnVector<uint8_t>;
7475
using ColumnUInt16 = ColumnVector<uint16_t>;
7576
using ColumnUInt32 = ColumnVector<uint32_t>;

clickhouse/types/type_parser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ static const std::unordered_map<std::string, Type::Code> kTypeCode = {
3232
{ "Int16", Type::Int16 },
3333
{ "Int32", Type::Int32 },
3434
{ "Int64", Type::Int64 },
35-
{ "Bool", Type::UInt8 },
35+
{ "Bool", Type::Bool },
3636
{ "UInt8", Type::UInt8 },
3737
{ "UInt16", Type::UInt16 },
3838
{ "UInt32", Type::UInt32 },

clickhouse/types/types.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const char* Type::TypeName(Type::Code code) {
2020
case Type::Code::Int16: return "Int16";
2121
case Type::Code::Int32: return "Int32";
2222
case Type::Code::Int64: return "Int64";
23+
case Type::Code::Bool: return "Bool";
2324
case Type::Code::UInt8: return "UInt8";
2425
case Type::Code::UInt16: return "UInt16";
2526
case Type::Code::UInt32: return "UInt32";
@@ -65,6 +66,7 @@ std::string Type::GetName() const {
6566
case Int32:
6667
case Int64:
6768
case Int128:
69+
case Bool:
6870
case UInt8:
6971
case UInt16:
7072
case UInt32:
@@ -124,6 +126,7 @@ uint64_t Type::GetTypeUniqueId() const {
124126
case Int32:
125127
case Int64:
126128
case Int128:
129+
case Bool:
127130
case UInt8:
128131
case UInt16:
129132
case UInt32:

clickhouse/types/types.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class Type {
2525
Int16,
2626
Int32,
2727
Int64,
28+
Bool,
2829
UInt8,
2930
UInt16,
3031
UInt32,
@@ -346,6 +347,11 @@ inline TypeRef Type::CreateSimple<UInt128>() {
346347
return TypeRef(new Type(UInt128));
347348
}
348349

350+
template <>
351+
inline TypeRef Type::CreateSimple<bool>() {
352+
return TypeRef(new Type(Bool));
353+
}
354+
349355
template <>
350356
inline TypeRef Type::CreateSimple<uint8_t>() {
351357
return TypeRef(new Type(UInt8));

ut/CreateColumnByType_ut.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class CreateColumnByTypeWithName : public ::testing::TestWithParam<const char* /
6262
TEST(CreateColumnByType, Bool) {
6363
const auto col = CreateColumnByType("Bool");
6464
ASSERT_NE(nullptr, col);
65-
EXPECT_EQ(col->GetType().GetName(), "UInt8");
65+
EXPECT_EQ(col->GetType().GetName(), "Bool");
6666
}
6767

6868
TEST_P(CreateColumnByTypeWithName, CreateColumnByType)
@@ -74,7 +74,7 @@ TEST_P(CreateColumnByTypeWithName, CreateColumnByType)
7474

7575
INSTANTIATE_TEST_SUITE_P(Basic, CreateColumnByTypeWithName, ::testing::Values(
7676
"Int8", "Int16", "Int32", "Int64",
77-
"UInt8", "UInt16", "UInt32", "UInt64",
77+
"UInt8", "UInt16", "UInt32", "UInt64", "Bool",
7878
"String", "Date", "DateTime",
7979
"UUID", "Int128", "UInt128"
8080
));

ut/utils.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,9 @@ std::ostream& operator<<(std::ostream& ostr, const ItemView& item_view) {
358358
case Type::Int64:
359359
ostr << item_view.get<int64_t>();
360360
break;
361+
case Type::Bool:
362+
ostr << static_cast<bool>(item_view.get<bool>());
363+
break;
361364
case Type::UInt8:
362365
ostr << static_cast<unsigned int>(item_view.get<uint8_t>());
363366
break;

0 commit comments

Comments
 (0)