diff --git a/README.md b/README.md index bd485753..8212fb03 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ C++ client for [ClickHouse](https://clickhouse.com/). * String * LowCardinality(String) or LowCardinality(FixedString(N)) * Tuple -* UInt8, UInt16, UInt32, UInt64, Int8, Int16, Int32, Int64 +* UInt8, UInt16, UInt32, UInt64, Int8, Int16, Int32, Int64, Bool * UInt128, Int128 * UUID * Map diff --git a/clickhouse/columns/factory.cpp b/clickhouse/columns/factory.cpp index 73f2cde1..193a232e 100644 --- a/clickhouse/columns/factory.cpp +++ b/clickhouse/columns/factory.cpp @@ -48,6 +48,8 @@ static ColumnRef CreateTerminalColumn(const TypeAst& ast) { case Type::Void: return std::make_shared(); + case Type::Bool: + return std::make_shared(); case Type::UInt8: return std::make_shared(); case Type::UInt16: diff --git a/clickhouse/columns/itemview.cpp b/clickhouse/columns/itemview.cpp index c92627d2..7c4a8afc 100644 --- a/clickhouse/columns/itemview.cpp +++ b/clickhouse/columns/itemview.cpp @@ -41,6 +41,7 @@ void ItemView::ValidateData(Type::Code type, DataType data) { case Type::Code::Void: return AssertSize({0}); + case Type::Code::Bool: case Type::Code::Int8: case Type::Code::UInt8: case Type::Code::Enum8: diff --git a/clickhouse/columns/itemview.h b/clickhouse/columns/itemview.h index 199994b6..66474cdd 100644 --- a/clickhouse/columns/itemview.h +++ b/clickhouse/columns/itemview.h @@ -69,7 +69,7 @@ struct ItemView { if (sizeof(ValueType) == data.size()) { return *reinterpret_cast(data.data()); } else { - throw AssertionError("Incompatitable value type and size. Requested size: " + throw AssertionError("Incompatible value type and size. Requested size: " + std::to_string(sizeof(ValueType)) + " stored size: " + std::to_string(data.size())); } } diff --git a/clickhouse/columns/numeric.h b/clickhouse/columns/numeric.h index 5187b727..f82c6aa0 100644 --- a/clickhouse/columns/numeric.h +++ b/clickhouse/columns/numeric.h @@ -70,6 +70,7 @@ using Int128 = absl::int128; using UInt128 = absl::uint128; using Int64 = int64_t; +using ColumnBool = ColumnVector; using ColumnUInt8 = ColumnVector; using ColumnUInt16 = ColumnVector; using ColumnUInt32 = ColumnVector; diff --git a/clickhouse/types/type_parser.cpp b/clickhouse/types/type_parser.cpp index 52058e80..6d10ead4 100644 --- a/clickhouse/types/type_parser.cpp +++ b/clickhouse/types/type_parser.cpp @@ -32,7 +32,7 @@ static const std::unordered_map kTypeCode = { { "Int16", Type::Int16 }, { "Int32", Type::Int32 }, { "Int64", Type::Int64 }, - { "Bool", Type::UInt8 }, + { "Bool", Type::Bool }, { "UInt8", Type::UInt8 }, { "UInt16", Type::UInt16 }, { "UInt32", Type::UInt32 }, diff --git a/clickhouse/types/types.cpp b/clickhouse/types/types.cpp index c14c86c5..36bcd95d 100644 --- a/clickhouse/types/types.cpp +++ b/clickhouse/types/types.cpp @@ -20,6 +20,7 @@ const char* Type::TypeName(Type::Code code) { case Type::Code::Int16: return "Int16"; case Type::Code::Int32: return "Int32"; case Type::Code::Int64: return "Int64"; + case Type::Code::Bool: return "Bool"; case Type::Code::UInt8: return "UInt8"; case Type::Code::UInt16: return "UInt16"; case Type::Code::UInt32: return "UInt32"; @@ -65,6 +66,7 @@ std::string Type::GetName() const { case Int32: case Int64: case Int128: + case Bool: case UInt8: case UInt16: case UInt32: @@ -124,6 +126,7 @@ uint64_t Type::GetTypeUniqueId() const { case Int32: case Int64: case Int128: + case Bool: case UInt8: case UInt16: case UInt32: diff --git a/clickhouse/types/types.h b/clickhouse/types/types.h index 71613323..1dfa3a73 100644 --- a/clickhouse/types/types.h +++ b/clickhouse/types/types.h @@ -25,6 +25,7 @@ class Type { Int16, Int32, Int64, + Bool, UInt8, UInt16, UInt32, @@ -346,6 +347,11 @@ inline TypeRef Type::CreateSimple() { return TypeRef(new Type(UInt128)); } +template <> +inline TypeRef Type::CreateSimple() { + return TypeRef(new Type(Bool)); +} + template <> inline TypeRef Type::CreateSimple() { return TypeRef(new Type(UInt8)); diff --git a/ut/CreateColumnByType_ut.cpp b/ut/CreateColumnByType_ut.cpp index 556dfc36..871db8d9 100644 --- a/ut/CreateColumnByType_ut.cpp +++ b/ut/CreateColumnByType_ut.cpp @@ -62,7 +62,7 @@ class CreateColumnByTypeWithName : public ::testing::TestWithParamGetType().GetName(), "UInt8"); + EXPECT_EQ(col->GetType().GetName(), "Bool"); } TEST_P(CreateColumnByTypeWithName, CreateColumnByType) @@ -74,7 +74,7 @@ TEST_P(CreateColumnByTypeWithName, CreateColumnByType) INSTANTIATE_TEST_SUITE_P(Basic, CreateColumnByTypeWithName, ::testing::Values( "Int8", "Int16", "Int32", "Int64", - "UInt8", "UInt16", "UInt32", "UInt64", + "UInt8", "UInt16", "UInt32", "UInt64", "Bool", "String", "Date", "DateTime", "UUID", "Int128", "UInt128" )); diff --git a/ut/utils.cpp b/ut/utils.cpp index e2219dcd..3778690a 100644 --- a/ut/utils.cpp +++ b/ut/utils.cpp @@ -358,6 +358,9 @@ std::ostream& operator<<(std::ostream& ostr, const ItemView& item_view) { case Type::Int64: ostr << item_view.get(); break; + case Type::Bool: + ostr << static_cast(item_view.get()); + break; case Type::UInt8: ostr << static_cast(item_view.get()); break;