mirror of
https://github.com/hanzo-ds/cpp.git
synced 2026-10-30 20:31:26 +00:00
Pure rename applied on top of upstream tag v2.6.2 (8d2415d6), not HEAD.
The fork was cut at 737145d = v2.6.2-57, which still declared version 2.6.2
in version.h; renaming there would have shipped 57 unreleased commits wearing
a 2.6.2 label. Reset to the tag first so this commit changes names only.
clickhouse/ -> datastore/ (public include root)
namespace clickhouse -> namespace datastore
CLICKHOUSE_CPP_VERSION -> DATASTORE_CPP_VERSION
clickhouse-cpp-lib/-ut -> datastore-cpp-lib/-ut (CMake, Bazel)
CH_MAP_BOOL_TO_UINT8 -> DS_MAP_BOOL_TO_UINT8
CLICKHOUSE_* -> DATASTORE_* (test env vars)
doc links -> docs.hanzo.ai/datastore
This client speaks the NATIVE binary protocol only - there is no HTTP path
and no X-ClickHouse-* header anywhere in it, so the header rename that the
HTTP clients required does not apply and nothing here was broken.
The one string that reaches the wire is CLIENT_NAME, sent by both SendHello
and SendQuery's ClientInfo from a single macro, and it lands in
system.query_log.client_name. Both sites still read the one macro, so they
stay consistent and the server's Hello/Query consistency check is satisfied.
Old rows keep the old name; that is a reporting discontinuity, not a
migration, since nothing keys on it.
CI is repointed at our own server: ghcr.io/hanzoai/datastore:26.2.3.2, the
image production runs. Its entrypoint honours DATASTORE_SKIP_USER_SETUP, not
the CLICKHOUSE_ spelling the compose file used, and its config lives in
/etc/hanzo-datastore-server. ci/docker-compose/config.xml is now layered in
as a config.d drop-in so the image keeps its own white-labelling. That file
and users.xml deliberately keep a <clickhouse> root: it must match the roots
of the drop-ins the image ships, and a mismatch fails silently - the server
logs "Merging bypassed" and starts with every drop-in discarded.
The remote-TLS suites used to default to the third-party host
play.clickhouse.com. They now read DATASTORE_SECURE*_HOST and skip when it is
unset rather than point at a host we do not run.
Dropped as upstream infrastructure with no meaning here: AI_POLICY.md
(upstream's policy about their codebase), .travis.yml (dead CI referencing a
third-party apt repo), cross-repo-bug-relay.yml (relays our issues into an
upstream triage repo). LICENSE keeps its copyright notice, as Apache-2.0
requires.
Verified: cmake configure + 115-target build clean; the full suite is green
against ghcr.io/hanzoai/datastore:26.2.3.2 (894 passed, 0 failed); the
pristine v2.6.2 build run against that same server passes the identical set,
and both logged the same 3914 queries under their respective client names.
182 lines
5.8 KiB
C++
182 lines
5.8 KiB
C++
#include <datastore/client.h>
|
|
#include <datastore/columns/tuple.h>
|
|
#include <datastore/types/types.h>
|
|
|
|
#include "datastore/columns/column.h"
|
|
#include "datastore/columns/lowcardinality.h"
|
|
#include "gtest/gtest-message.h"
|
|
|
|
#include "ut/utils_comparison.h"
|
|
#include "utils.h"
|
|
|
|
#include <gtest/gtest.h>
|
|
#include <memory>
|
|
|
|
namespace {
|
|
using namespace datastore;
|
|
|
|
Block MakeBlock(std::vector<std::pair<std::string, ColumnRef>> columns) {
|
|
Block result;
|
|
|
|
const size_t number_of_rows = columns.size() ? columns[0].second->Size() : 0;
|
|
size_t i = 0;
|
|
for (const auto & name_and_col : columns) {
|
|
EXPECT_EQ(number_of_rows, name_and_col.second->Size())
|
|
<< "Column #" << i << " " << name_and_col.first << " has incorrect number of rows";
|
|
|
|
result.AppendColumn(name_and_col.first, name_and_col.second);
|
|
|
|
++i;
|
|
}
|
|
|
|
result.RefreshRowCount();
|
|
EXPECT_EQ(number_of_rows, result.GetRowCount());
|
|
|
|
return result;
|
|
}
|
|
|
|
}
|
|
|
|
TEST(BlockTest, Iterator) {
|
|
const auto block = MakeBlock({
|
|
{"foo", std::make_shared<ColumnUInt8>(std::vector<uint8_t>{1, 2, 3, 4, 5})},
|
|
{"bar", std::make_shared<ColumnString>(std::vector<std::string>{"1", "2", "3", "4", "5"})},
|
|
});
|
|
const char* names[] = {"foo", "bar"};
|
|
|
|
ASSERT_EQ(2u, block.GetColumnCount());
|
|
ASSERT_EQ(5u, block.GetRowCount());
|
|
|
|
size_t col_index = 0;
|
|
Block::Iterator i(block);
|
|
while (i.IsValid()) {
|
|
|
|
const auto& name_and_col = i;
|
|
ASSERT_EQ(col_index, name_and_col.ColumnIndex());
|
|
ASSERT_EQ(block[col_index].get(), name_and_col.Column().get());
|
|
ASSERT_EQ(names[col_index], name_and_col.Name());
|
|
|
|
i.Next();
|
|
++col_index;
|
|
}
|
|
}
|
|
|
|
TEST(BlockTest, RangeBasedForLoop) {
|
|
const auto block = MakeBlock({
|
|
{"foo", std::make_shared<ColumnUInt8>(std::vector<uint8_t>{1, 2, 3, 4, 5})},
|
|
{"bar", std::make_shared<ColumnString>(std::vector<std::string>{"1", "2", "3", "4", "5"})},
|
|
});
|
|
const char* names[] = {"foo", "bar"};
|
|
|
|
ASSERT_EQ(2u, block.GetColumnCount());
|
|
ASSERT_EQ(5u, block.GetRowCount());
|
|
|
|
size_t col_index = 0;
|
|
for (const auto & name_and_col : block) {
|
|
ASSERT_EQ(col_index, name_and_col.ColumnIndex());
|
|
ASSERT_EQ(block[col_index].get(), name_and_col.Column().get());
|
|
ASSERT_EQ(names[col_index], name_and_col.Name());
|
|
++col_index;
|
|
}
|
|
}
|
|
|
|
TEST(BlockTest, Iterators) {
|
|
Block block;
|
|
// Empty block, all iterators point to 'end'
|
|
ASSERT_EQ(block.begin(), block.cbegin());
|
|
ASSERT_EQ(block.end(), block.cend());
|
|
ASSERT_EQ(block.begin(), block.end());
|
|
|
|
block = MakeBlock({
|
|
{"foo", std::make_shared<ColumnUInt8>(std::vector<uint8_t>{1, 2, 3, 4, 5})},
|
|
{"bar", std::make_shared<ColumnString>(std::vector<std::string>{"1", "2", "3", "4", "5"})},
|
|
});
|
|
|
|
// Non-empty block
|
|
ASSERT_EQ(block.begin(), block.cbegin());
|
|
ASSERT_EQ(block.end(), block.cend());
|
|
ASSERT_NE(block.begin(), block.end());
|
|
ASSERT_NE(block.cbegin(), block.cend());
|
|
}
|
|
|
|
TEST(BlockTest, Clear) {
|
|
// Test that Block::Clear removes all rows from all of the columns,
|
|
// without changing column instances, types, names, etc.
|
|
|
|
auto block = MakeBlock({
|
|
{"foo", std::make_shared<ColumnUInt8>(std::vector<uint8_t>{1, 2, 3, 4, 5})},
|
|
{"bar", std::make_shared<ColumnString>(std::vector<std::string>{"1", "2", "3", "4", "5"})},
|
|
});
|
|
|
|
std::vector<std::tuple<std::string, Column*>> expected_columns_description;
|
|
for (const auto & c : block) {
|
|
expected_columns_description.emplace_back(c.Name(), c.Column().get());
|
|
}
|
|
|
|
block.Clear();
|
|
|
|
// Block must report empty after being cleared
|
|
EXPECT_EQ(0u, block.GetRowCount());
|
|
|
|
size_t i = 0;
|
|
for (const auto & c : block) {
|
|
const auto & [expected_name, expected_column] = expected_columns_description[i];
|
|
SCOPED_TRACE(testing::Message("col #") << c.ColumnIndex() << " \"" << c.Name() << "\"");
|
|
|
|
// MUST be same column object
|
|
EXPECT_EQ(expected_column, c.Column().get());
|
|
|
|
// MUST have same column name
|
|
EXPECT_EQ(expected_name, c.Name());
|
|
|
|
// column MUST be empty
|
|
EXPECT_EQ(0u, c.Column()->Size());
|
|
|
|
++i;
|
|
}
|
|
}
|
|
|
|
TEST(BlockTest, Reserve) {
|
|
// Test that Block::Reserve reserves space in all columns (uncheckable now),
|
|
// without changing column instances, names, and previously stored rows.
|
|
|
|
auto block = MakeBlock({
|
|
{"foo", std::make_shared<ColumnUInt8>(std::vector<uint8_t>{1, 2, 3, 4, 5})},
|
|
{"bar", std::make_shared<ColumnString>(std::vector<std::string>{"1", "2", "3", "4", "5"})},
|
|
{"quix", std::make_shared<ColumnLowCardinalityT<ColumnString>>(std::vector<std::string>{"1", "2", "3", "4", "5"})},
|
|
});
|
|
|
|
const size_t initial_rows_count = block.GetRowCount();
|
|
|
|
std::vector<std::tuple<std::string, Column*, ColumnRef>> expected_columns_description;
|
|
for (const auto & c : block) {
|
|
expected_columns_description.emplace_back(
|
|
c.Name(),
|
|
c.Column().get(), // reference to the actual object
|
|
c.Column()->Slice(0, c.Column()->Size()) // reference to the values
|
|
);
|
|
}
|
|
|
|
block.Reserve(1000); // 1000 is arbitrary value
|
|
|
|
// Block must same number of rows as before Reserve
|
|
EXPECT_EQ(initial_rows_count, block.GetRowCount());
|
|
|
|
size_t i = 0;
|
|
for (const auto & c : block) {
|
|
const auto & [expected_name, expected_column, expected_values] = expected_columns_description[i];
|
|
SCOPED_TRACE(testing::Message("col #") << c.ColumnIndex() << " \"" << c.Name() << "\"");
|
|
|
|
// MUST have same column name
|
|
EXPECT_EQ(expected_name, c.Name());
|
|
|
|
// MUST be same column object
|
|
EXPECT_EQ(expected_column, c.Column().get());
|
|
|
|
// column MUST have the same values
|
|
EXPECT_TRUE(CompareRecursive(*expected_values, *c.Column()));
|
|
|
|
++i;
|
|
}
|
|
}
|