1
- #include " abnormal_column_names_test.h"
2
- #include " utils.h"
3
1
4
2
#include < clickhouse/columns/column.h>
5
3
#include < clickhouse/block.h>
4
+
5
+ #include " utils.h"
6
+
7
+ #include < gtest/gtest.h>
8
+
6
9
#include < unordered_set>
7
10
#include < iostream>
8
11
9
12
namespace {
10
- using namespace clickhouse ;
11
- }
13
+ using namespace clickhouse ;
12
14
13
- void AbnormalColumnNamesClientTest::SetUp () {
14
- client_ = std::make_unique<Client>(std::get<0 >(GetParam ()));
15
- }
15
+ std::string getColumnNames (const Block& block) {
16
+ std::string result;
17
+ for (size_t i = 0 ; i < block.GetColumnCount (); ++i) {
18
+ result += block.GetColumnName (i);
19
+ if (i != block.GetColumnCount () - 1 )
20
+ result += ' ,' ;
21
+ }
16
22
17
- void AbnormalColumnNamesClientTest::TearDown () {
18
- client_.reset ();
23
+ return result;
19
24
}
25
+ }
26
+
27
+ struct AbnormalColumnNamesClientTestCase {
28
+ ClientOptions client_options;
29
+ std::vector<std::string> queries;
30
+ std::vector<std::string> expected_names;
31
+ };
32
+
33
+ class AbnormalColumnNamesClientTest : public testing ::TestWithParam<AbnormalColumnNamesClientTestCase> {
34
+ protected:
35
+ void SetUp () override {
36
+ client_ = std::make_unique<Client>(GetParam ().client_options );
37
+ }
38
+ void TearDown () override {
39
+ client_.reset ();
40
+ }
41
+
42
+ std::unique_ptr<clickhouse::Client> client_;
43
+ };
44
+
20
45
21
- // Sometimes gtest fails to detect that this test is instantiated elsewhere, suppress the error explicitly.
22
- GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST (AbnormalColumnNamesClientTest);
23
46
TEST_P (AbnormalColumnNamesClientTest, Select) {
24
- // TODO(vnemkov): move expected results into the test parameters, also get rid of PrettyPrintBlock
25
- static const std::vector<std::string> expect_results {
26
- " +-------+-------+-------+\n " \
27
- " | 123 | 231 | 113 |\n " \
28
- " +-------+-------+-------+\n " \
29
- " | UInt8 | UInt8 | UInt8 |\n " \
30
- " +-------+-------+-------+\n " \
31
- " | 123 | 231 | 113 |\n " \
32
- " +-------+-------+-------+\n " ,
33
- " +--------+--------+--------+--------+\n " \
34
- " | 'ABC' | 'AAA' | 'BBB' | 'CCC' |\n " \
35
- " +--------+--------+--------+--------+\n " \
36
- " | String | String | String | String |\n " \
37
- " +--------+--------+--------+--------+\n " \
38
- " | ABC | AAA | BBB | CCC |\n " \
39
- " +--------+--------+--------+--------+\n "
40
- };
41
- const auto & queries = std::get<1 >(GetParam ());
47
+ const auto & queries = GetParam ().queries ;
42
48
for (size_t i = 0 ; i < queries.size (); ++i) {
49
+
43
50
const auto & query = queries.at (i);
44
- client_->Select (query,
45
- [& queries, i](const Block& block) {
46
- if (block.GetRowCount () == 0 || block.GetColumnCount () == 0 )
47
- return ;
48
- EXPECT_EQ (1UL , block.GetRowCount ());
49
- EXPECT_EQ (i == 0 ? 3UL : 4UL , block.GetColumnCount ());
50
-
51
- std::stringstream sstr;
52
- sstr << PrettyPrintBlock{block};
53
- auto result = sstr.str ();
54
- std::cout << " query => " << queries.at (i) <<" \n " << PrettyPrintBlock{block};
55
- ASSERT_EQ (expect_results.at (i), result);
56
- }
57
- );
51
+ const auto & expected = GetParam ().expected_names [i];
52
+
53
+ client_->Select (query, [query, expected](const Block& block) {
54
+ if (block.GetRowCount () == 0 || block.GetColumnCount () == 0 )
55
+ return ;
56
+
57
+ EXPECT_EQ (1UL , block.GetRowCount ());
58
+
59
+ EXPECT_EQ (expected, getColumnNames (block))
60
+ << " For query: " << query;
61
+ });
58
62
}
59
63
}
60
64
@@ -70,7 +74,8 @@ INSTANTIATE_TEST_SUITE_P(ClientColumnNames, AbnormalColumnNamesClientTest,
70
74
.SetSendRetries (1 )
71
75
.SetPingBeforeQuery (true )
72
76
.SetCompressionMethod (CompressionMethod::None),
73
- {" select 123,231,113" , " select 'ABC','AAA','BBB','CCC'" }
77
+ {" select 123,231,113" , " select 'ABC','AAA','BBB','CCC'" },
78
+ {" 123,231,113" , " 'ABC','AAA','BBB','CCC'" },
74
79
}
75
80
));
76
81
0 commit comments