Skip to content

Commit

Permalink
Merge pull request #317 from alenstarx/master
Browse files Browse the repository at this point in the history
Fix abnormal column names in gcc7.3.1
  • Loading branch information
Enmk authored Jul 31, 2023
2 parents de6f56a + 1701f1e commit f8c43da
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 2 deletions.
4 changes: 2 additions & 2 deletions clickhouse/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -609,9 +609,9 @@ bool Client::Impl::ReadBlock(InputStream& input, Block* block) {
CreateColumnByTypeSettings create_column_settings;
create_column_settings.low_cardinality_as_wrapped_column = options_.backward_compatibility_lowcardinality_as_wrapped_column;

std::string name;
std::string type;
for (size_t i = 0; i < num_columns; ++i) {
std::string name;
std::string type;
if (!WireFormat::ReadString(input, &name)) {
return false;
}
Expand Down
1 change: 1 addition & 0 deletions ut/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ SET ( clickhouse-cpp-ut-src
performance_tests.cpp
tcp_server.cpp
readonly_client_test.cpp
abnormal_column_names_test.cpp
connection_failed_client_test.cpp
array_of_low_cardinality_tests.cpp
CreateColumnByType_ut.cpp
Expand Down
75 changes: 75 additions & 0 deletions ut/abnormal_column_names_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#include "abnormal_column_names_test.h"
#include "utils.h"

#include <clickhouse/columns/column.h>
#include <clickhouse/block.h>
#include <unordered_set>
#include <iostream>

namespace {
using namespace clickhouse;
}

void AbnormalColumnNamesClientTest::SetUp() {
client_ = std::make_unique<Client>(std::get<0>(GetParam()));
}

void AbnormalColumnNamesClientTest::TearDown() {
client_.reset();
}

// Sometimes gtest fails to detect that this test is instantiated elsewhere, suppress the error explicitly.
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(AbnormalColumnNamesClientTest);
TEST_P(AbnormalColumnNamesClientTest, Select) {
static const std::vector<std::string> expect_results {
"+-------+-------+-------+\n"\
"| 123 | 231 | 113 |\n"\
"+-------+-------+-------+\n"\
"| UInt8 | UInt8 | UInt8 |\n"\
"+-------+-------+-------+\n"\
"| 123 | 231 | 113 |\n"\
"+-------+-------+-------+\n",
"+--------+--------+--------+--------+\n"\
"| 'ABC' | 'AAA' | 'BBB' | 'CCC' |\n"\
"+--------+--------+--------+--------+\n"\
"| String | String | String | String |\n"\
"+--------+--------+--------+--------+\n"\
"| ABC | AAA | BBB | CCC |\n"\
"+--------+--------+--------+--------+\n"
};
const auto & queries = std::get<1>(GetParam());
for (size_t i = 0; i < queries.size(); ++i) {
const auto & query = queries.at(i);
client_->Select(query,
[& queries, i](const Block& block) {
if (block.GetRowCount() == 0 || block.GetColumnCount() == 0)
return;
EXPECT_EQ(1UL, block.GetRowCount());
EXPECT_EQ(i == 0 ? 3UL: 4UL, block.GetColumnCount());

std::stringstream sstr;
sstr << PrettyPrintBlock{block};
auto result = sstr.str();
std::cout << "query => " << queries.at(i) <<"\n" << PrettyPrintBlock{block};
ASSERT_EQ(expect_results.at(i), result);
}
);
}
}


INSTANTIATE_TEST_SUITE_P(ClientColumnNames, AbnormalColumnNamesClientTest,
::testing::Values(AbnormalColumnNamesClientTest::ParamType{
ClientOptions()
.SetHost( getEnvOrDefault("CLICKHOUSE_HOST", "localhost"))
.SetPort( getEnvOrDefault<size_t>("CLICKHOUSE_PORT", "9000"))
.SetUser( getEnvOrDefault("CLICKHOUSE_USER", "default"))
.SetPassword( getEnvOrDefault("CLICKHOUSE_PASSWORD", ""))
.SetDefaultDatabase(getEnvOrDefault("CLICKHOUSE_DB", "default"))
.SetSendRetries(1)
.SetPingBeforeQuery(true)
.SetCompressionMethod(CompressionMethod::None),
{"select 123,231,113", "select 'ABC','AAA','BBB','CCC'"}
}
));

18 changes: 18 additions & 0 deletions ut/abnormal_column_names_test.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#pragma once

#include <clickhouse/client.h>

#include <gtest/gtest.h>

#include <string>
#include <tuple>
#include <vector>

class AbnormalColumnNamesClientTest : public testing::TestWithParam<
std::tuple<clickhouse::ClientOptions, std::vector<std::string> > /*queries*/> {
protected:
void SetUp() override;
void TearDown() override;

std::unique_ptr<clickhouse::Client> client_;
};
1 change: 1 addition & 0 deletions ut/client_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1196,6 +1196,7 @@ INSTANTIATE_TEST_SUITE_P(ClientLocalReadonly, ReadonlyClientTest,
}
));


INSTANTIATE_TEST_SUITE_P(ClientLocalFailed, ConnectionFailedClientTest,
::testing::Values(ConnectionFailedClientTest::ParamType{
ClientOptions()
Expand Down

0 comments on commit f8c43da

Please sign in to comment.