Skip to content

Commit b5da527

Browse files
authored
Merge pull request #279 from ays7/bool-column
Handle "Bool" columns
2 parents 819efc8 + 9fc86b9 commit b5da527

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

clickhouse/types/type_parser.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +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 },
3536
{ "UInt8", Type::UInt8 },
3637
{ "UInt16", Type::UInt16 },
3738
{ "UInt32", Type::UInt32 },

ut/CreateColumnByType_ut.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ TEST(CreateColumnByType, AggregateFunction) {
5959
class CreateColumnByTypeWithName : public ::testing::TestWithParam<const char* /*Column Type String*/>
6060
{};
6161

62+
TEST(CreateColumnByType, Bool) {
63+
const auto col = CreateColumnByType("Bool");
64+
ASSERT_NE(nullptr, col);
65+
EXPECT_EQ(col->GetType().GetName(), "UInt8");
66+
}
67+
6268
TEST_P(CreateColumnByTypeWithName, CreateColumnByType)
6369
{
6470
const auto col = CreateColumnByType(GetParam());

ut/client_ut.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -272,16 +272,17 @@ TEST_P(ClientCase, LowCardinalityString_AsString) {
272272

273273
TEST_P(ClientCase, Generic) {
274274
client_->Execute(
275-
"CREATE TEMPORARY TABLE IF NOT EXISTS test_clickhouse_cpp_client (id UInt64, name String) ");
275+
"CREATE TEMPORARY TABLE IF NOT EXISTS test_clickhouse_cpp_client (id UInt64, name String, f Bool) ");
276276

277277
const struct {
278278
uint64_t id;
279279
std::string name;
280+
bool f;
280281
} TEST_DATA[] = {
281-
{ 1, "id" },
282-
{ 3, "foo" },
283-
{ 5, "bar" },
284-
{ 7, "name" },
282+
{ 1, "id", true },
283+
{ 3, "foo", false },
284+
{ 5, "bar", true },
285+
{ 7, "name", false },
285286
};
286287

287288
/// Insert some values.
@@ -290,20 +291,23 @@ TEST_P(ClientCase, Generic) {
290291

291292
auto id = std::make_shared<ColumnUInt64>();
292293
auto name = std::make_shared<ColumnString>();
294+
auto f = std::make_shared<ColumnUInt8> ();
293295
for (auto const& td : TEST_DATA) {
294296
id->Append(td.id);
295297
name->Append(td.name);
298+
f->Append(td.f);
296299
}
297300

298301
block.AppendColumn("id" , id);
299302
block.AppendColumn("name", name);
303+
block.AppendColumn("f", f);
300304

301305
client_->Insert("test_clickhouse_cpp_client", block);
302306
}
303307

304308
/// Select values inserted in the previous step.
305309
size_t row = 0;
306-
client_->Select("SELECT id, name FROM test_clickhouse_cpp_client", [TEST_DATA, &row](const Block& block)
310+
client_->Select("SELECT id, name, f FROM test_clickhouse_cpp_client", [TEST_DATA, &row](const Block& block)
307311
{
308312
if (block.GetRowCount() == 0) {
309313
return;
@@ -313,6 +317,7 @@ TEST_P(ClientCase, Generic) {
313317
for (size_t c = 0; c < block.GetRowCount(); ++c, ++row) {
314318
EXPECT_EQ(TEST_DATA[row].id, (*block[0]->As<ColumnUInt64>())[c]);
315319
EXPECT_EQ(TEST_DATA[row].name, (*block[1]->As<ColumnString>())[c]);
320+
EXPECT_EQ(TEST_DATA[row].f, (*block[2]->As<ColumnUInt8>())[c]);
316321
}
317322
}
318323
);

0 commit comments

Comments
 (0)