Skip to content

Commit fce57f4

Browse files
committed
More column-generic tests
- roundtrip to server
1 parent 3ae6bf2 commit fce57f4

File tree

8 files changed

+74
-32
lines changed

8 files changed

+74
-32
lines changed

ut/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ SET ( clickhouse-cpp-ut-src
1919
array_of_low_cardinality_tests.cpp
2020
CreateColumnByType_ut.cpp
2121
Column_ut.cpp
22+
roundtrip_column.cpp
2223

2324
utils.cpp
2425
value_generators.cpp

ut/Column_ut.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,12 @@
1313
#include <clickhouse/base/output.h>
1414
#include <clickhouse/base/socket.h> // for ipv4-ipv6 platform-specific stuff
1515

16+
#include <clickhouse/client.h>
17+
1618
#include <gtest/gtest.h>
1719

1820
#include "utils.h"
21+
#include "roundtrip_column.h"
1922
#include "value_generators.h"
2023

2124
namespace {
@@ -262,3 +265,20 @@ TYPED_TEST(GenericColumnTest, LoadAndSave) {
262265

263266
EXPECT_TRUE(CompareRecursive(*column_A, *column_B));
264267
}
268+
269+
const auto LocalHostEndpoint = ClientOptions()
270+
.SetHost( getEnvOrDefault("CLICKHOUSE_HOST", "localhost"))
271+
.SetPort( getEnvOrDefault<size_t>("CLICKHOUSE_PORT", "9000"))
272+
.SetUser( getEnvOrDefault("CLICKHOUSE_USER", "default"))
273+
.SetPassword( getEnvOrDefault("CLICKHOUSE_PASSWORD", ""))
274+
.SetDefaultDatabase(getEnvOrDefault("CLICKHOUSE_DB", "default"));
275+
276+
TYPED_TEST(GenericColumnTest, RoundTrip) {
277+
auto [column, values] = this->MakeColumnWithValues(100);
278+
EXPECT_EQ(values.size(), column->Size());
279+
280+
clickhouse::Client client(LocalHostEndpoint);
281+
282+
auto result_typed = RoundtripColumnValues(client, column)->template AsStrict<typename TestFixture::ColumnType>();
283+
EXPECT_TRUE(CompareRecursive(*column, *result_typed));
284+
}

ut/client_ut.cpp

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "readonly_client_test.h"
44
#include "connection_failed_client_test.h"
55
#include "utils.h"
6+
#include "roundtrip_column.h"
67

78
#include <gtest/gtest.h>
89

@@ -978,35 +979,6 @@ TEST_P(ClientCase, DISABLED_ArrayArrayUInt64) {
978979
}
979980
}
980981

981-
ColumnRef RoundtripColumnValues(Client& client, ColumnRef expected) {
982-
// Create a temporary table with a single column
983-
// insert values from `expected`
984-
// select and aggregate all values from block into `result` column
985-
auto result = expected->CloneEmpty();
986-
987-
const std::string type_name = result->GetType().GetName();
988-
client.Execute("DROP TEMPORARY TABLE IF EXISTS temporary_roundtrip_table;");
989-
client.Execute("CREATE TEMPORARY TABLE IF NOT EXISTS temporary_roundtrip_table (col " + type_name + ");");
990-
{
991-
Block block;
992-
block.AppendColumn("col", expected);
993-
block.RefreshRowCount();
994-
client.Insert("temporary_roundtrip_table", block);
995-
}
996-
997-
client.Select("SELECT col FROM temporary_roundtrip_table", [&result](const Block& b) {
998-
if (b.GetRowCount() == 0)
999-
return;
1000-
1001-
ASSERT_EQ(1u, b.GetColumnCount());
1002-
result->Append(b[0]);
1003-
});
1004-
1005-
EXPECT_EQ(expected->GetType(), result->GetType());
1006-
EXPECT_EQ(expected->Size(), result->Size());
1007-
return result;
1008-
}
1009-
1010982
TEST_P(ClientCase, RoundtripArrayTUint64) {
1011983
auto array = std::make_shared<ColumnArrayT<ColumnUInt64>>();
1012984
array->Append({0, 1, 2});

ut/roundtrip_column.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#include "roundtrip_column.h"
2+
3+
#include <clickhouse/client.h>
4+
#include <clickhouse/block.h>
5+
6+
#include <gtest/gtest.h>
7+
8+
namespace {
9+
using namespace clickhouse;
10+
}
11+
12+
ColumnRef RoundtripColumnValues(Client& client, ColumnRef expected) {
13+
// Create a temporary table with a single column
14+
// insert values from `expected`
15+
// select and aggregate all values from block into `result` column
16+
auto result = expected->CloneEmpty();
17+
18+
const std::string type_name = result->GetType().GetName();
19+
client.Execute("DROP TEMPORARY TABLE IF EXISTS temporary_roundtrip_table;");
20+
client.Execute("CREATE TEMPORARY TABLE IF NOT EXISTS temporary_roundtrip_table (col " + type_name + ");");
21+
{
22+
Block block;
23+
block.AppendColumn("col", expected);
24+
block.RefreshRowCount();
25+
client.Insert("temporary_roundtrip_table", block);
26+
}
27+
28+
client.Select("SELECT col FROM temporary_roundtrip_table", [&result](const Block& b) {
29+
if (b.GetRowCount() == 0)
30+
return;
31+
32+
ASSERT_EQ(1u, b.GetColumnCount());
33+
result->Append(b[0]);
34+
});
35+
36+
EXPECT_EQ(expected->GetType(), result->GetType());
37+
EXPECT_EQ(expected->Size(), result->Size());
38+
39+
return result;
40+
}

ut/roundtrip_column.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#pragma once
2+
3+
#include <clickhouse/columns/column.h>
4+
5+
namespace clickhouse {
6+
class Client;
7+
}
8+
9+
clickhouse::ColumnRef RoundtripColumnValues(clickhouse::Client& client, clickhouse::ColumnRef expected);

ut/utils.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <iomanip>
1919
#include <sstream>
2020

21+
2122
namespace {
2223
using namespace clickhouse;
2324
std::ostream & printColumnValue(const ColumnRef& c, const size_t row, std::ostream & ostr);

ut/utils.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#pragma once
22

33
#include <clickhouse/base/platform.h>
4-
#include <clickhouse/columns/uuid.h>
54

65
#include "utils_meta.h"
76
#include "utils_comparison.h"
@@ -18,6 +17,7 @@
1817
#include <gtest/gtest.h>
1918

2019
namespace clickhouse {
20+
class Client;
2121
class Block;
2222
class Type;
2323
struct ServerInfo;
@@ -135,5 +135,3 @@ std::ostream& operator<<(std::ostream & ostr, const PrintContainer<T>& print_con
135135

136136
return ostr << "]";
137137
}
138-
139-

ut/value_generators.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include <clickhouse/base/socket.h> // for ipv4-ipv6 platform-specific stuff
44
#include <clickhouse/columns/numeric.h>
5+
#include <clickhouse/columns/uuid.h>
56

67
#include "utils.h"
78

0 commit comments

Comments
 (0)