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.
265 lines
8.1 KiB
C++
265 lines
8.1 KiB
C++
#pragma once
|
|
|
|
#include "utils_meta.h"
|
|
|
|
#include <datastore/base/socket.h> // for ipv4-ipv6 platform-specific stuff
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
#include <string_view>
|
|
#include <cstring>
|
|
#include <cmath>
|
|
#include <type_traits>
|
|
|
|
namespace datastore {
|
|
class Block;
|
|
class Column;
|
|
|
|
std::ostream& operator<<(std::ostream& ostr, const ItemView& item_view);
|
|
}
|
|
|
|
inline bool operator==(const in6_addr& left, const in6_addr& right) {
|
|
return memcmp(&left, &right, sizeof(left)) == 0;
|
|
}
|
|
|
|
inline bool operator==(const in_addr& left, const in_addr& right) {
|
|
return memcmp(&left, &right, sizeof(left)) == 0;
|
|
}
|
|
|
|
inline bool operator==(const in_addr & left, const uint32_t& right) {
|
|
return memcmp(&left, &right, sizeof(left)) == 0;
|
|
}
|
|
|
|
inline bool operator==(const uint32_t& left, const in_addr& right) {
|
|
return memcmp(&left, &right, sizeof(left)) == 0;
|
|
}
|
|
|
|
inline bool operator==(const in6_addr & left, const std::string_view & right) {
|
|
return right.size() == sizeof(left) && memcmp(&left, right.data(), sizeof(left)) == 0;
|
|
}
|
|
|
|
inline bool operator==(const std::string_view & left, const in6_addr & right) {
|
|
return left.size() == sizeof(right) && memcmp(left.data(), &right, sizeof(right)) == 0;
|
|
}
|
|
|
|
inline bool operator!=(const in6_addr& left, const in6_addr& right) {
|
|
return !(left == right);
|
|
}
|
|
|
|
inline bool operator!=(const in_addr& left, const in_addr& right) {
|
|
return !(left == right);
|
|
}
|
|
|
|
inline bool operator!=(const in_addr & left, const uint32_t& right) {
|
|
return !(left == right);
|
|
}
|
|
|
|
inline bool operator!=(const uint32_t& left, const in_addr& right) {
|
|
return !(left == right);
|
|
}
|
|
|
|
inline bool operator!=(const in6_addr & left, const std::string_view & right) {
|
|
return !(left == right);
|
|
}
|
|
|
|
inline bool operator!=(const std::string_view & left, const in6_addr & right) {
|
|
return !(left == right);
|
|
}
|
|
|
|
namespace details {
|
|
// Make a column a RO stl-like container
|
|
template <typename NestedColumnType>
|
|
struct ColumnAsContainerWrapper {
|
|
const NestedColumnType& nested_col;
|
|
|
|
struct Iterator {
|
|
const NestedColumnType& nested_col;
|
|
size_t i = 0;
|
|
|
|
auto& operator++() {
|
|
++i;
|
|
return *this;
|
|
}
|
|
|
|
auto operator*() const {
|
|
return nested_col.At(i);
|
|
}
|
|
|
|
bool operator==(const Iterator & other) const {
|
|
return &other.nested_col == &this->nested_col && other.i == this->i;
|
|
}
|
|
|
|
bool operator!=(const Iterator & other) const {
|
|
return !(other == *this);
|
|
}
|
|
};
|
|
|
|
size_t size() const {
|
|
return nested_col.Size();
|
|
}
|
|
|
|
auto begin() const {
|
|
return Iterator{nested_col, 0};
|
|
}
|
|
|
|
auto end() const {
|
|
return Iterator{nested_col, nested_col.Size()};
|
|
}
|
|
};
|
|
|
|
// Helper to allow comparing values of two instances of datastore::Column, when concrete type is unknown.
|
|
// Comparison is done by comparing result of Column::GetItem().
|
|
template <>
|
|
struct ColumnAsContainerWrapper<datastore::Column> {
|
|
const datastore::Column& nested_col;
|
|
|
|
struct Iterator {
|
|
const datastore::Column& nested_col;
|
|
size_t i = 0;
|
|
|
|
auto& operator++() {
|
|
++i;
|
|
return *this;
|
|
}
|
|
|
|
struct ItemWrapper {
|
|
const datastore::ItemView item_view;
|
|
|
|
bool operator==(const ItemWrapper & other) const {
|
|
// type-erased comparison, byte-by-byte
|
|
return item_view.type == other.item_view.type
|
|
&& item_view.data == other.item_view.data;
|
|
}
|
|
|
|
template <typename U>
|
|
bool operator==(const U & other) const {
|
|
return item_view.get<U>() == other;
|
|
}
|
|
|
|
template <typename U>
|
|
bool operator!=(const U & other) const {
|
|
return !(*this == other);
|
|
}
|
|
|
|
friend std::ostream& operator<<(std::ostream& ostr, const ItemWrapper& val) {
|
|
return ostr << val.item_view;
|
|
}
|
|
};
|
|
|
|
auto operator*() const {
|
|
return ItemWrapper{nested_col.GetItem(i)};
|
|
}
|
|
|
|
bool operator==(const Iterator & other) const {
|
|
return &other.nested_col == &this->nested_col && other.i == this->i;
|
|
}
|
|
|
|
bool operator!=(const Iterator & other) const {
|
|
return !(other == *this);
|
|
}
|
|
};
|
|
|
|
size_t size() const {
|
|
return nested_col.Size();
|
|
}
|
|
|
|
auto begin() const {
|
|
return Iterator{nested_col, 0};
|
|
}
|
|
|
|
auto end() const {
|
|
return Iterator{nested_col, nested_col.Size()};
|
|
}
|
|
};
|
|
|
|
}
|
|
|
|
template <typename T>
|
|
auto maybeWrapColumnAsContainer(const T & t) {
|
|
if constexpr (std::is_base_of_v<datastore::Column, T>) {
|
|
return ::details::ColumnAsContainerWrapper<T>{t};
|
|
} else {
|
|
return t;
|
|
}
|
|
}
|
|
|
|
|
|
// Compare values to each other, if values are container-ish, then recursively deep compare those containers.
|
|
template <typename Left, typename Right>
|
|
::testing::AssertionResult CompareRecursive(const Left & left, const Right & right);
|
|
|
|
// Compare containers element-wise, if elements are containers themselves - compare recursevely
|
|
template <typename LeftContainer, typename RightContainer>
|
|
::testing::AssertionResult CompareCotainersRecursive(const LeftContainer& left, const RightContainer& right) {
|
|
if (left.size() != right.size())
|
|
return ::testing::AssertionFailure() << "\nMismatching containers size, expected: " << left.size() << " actual: " << right.size();
|
|
|
|
auto l_i = std::begin(left);
|
|
auto r_i = std::begin(right);
|
|
|
|
for (size_t i = 0; i < left.size(); ++i, ++l_i, ++r_i) {
|
|
auto result = CompareRecursive(*l_i, *r_i);
|
|
if (!result)
|
|
return result << "\n\nMismatch at pos: " << i + 1;
|
|
}
|
|
|
|
return ::testing::AssertionSuccess();
|
|
}
|
|
|
|
template <typename Container>
|
|
struct PrintContainer;
|
|
|
|
|
|
template <typename Left, typename Right>
|
|
::testing::AssertionResult CompareRecursive(const Left & left, const Right & right) {
|
|
using L = std::decay_t<Left>;
|
|
using R = std::decay_t<Right>;
|
|
|
|
if constexpr (!is_string_v<L> && !is_string_v<R>
|
|
&& (is_container_v<L> || std::is_base_of_v<datastore::Column, L>)
|
|
&& (is_container_v<R> || std::is_base_of_v<datastore::Column, R>) ) {
|
|
|
|
const auto & l = maybeWrapColumnAsContainer(left);
|
|
const auto & r = maybeWrapColumnAsContainer(right);
|
|
|
|
if (auto result = CompareCotainersRecursive(l, r))
|
|
return result;
|
|
else
|
|
return result << "\nExpected container: " << PrintContainer{l}
|
|
<< "\nActual container : " << PrintContainer{r};
|
|
}
|
|
else if constexpr (std::is_same_v<char const *, L> || std::is_same_v<char *, L>) {
|
|
return CompareRecursive(std::string_view(left), right);
|
|
}
|
|
else if constexpr (std::is_same_v<char const *, R> || std::is_same_v<char *, R>) {
|
|
return CompareRecursive(left, std::string_view(right));
|
|
} else {
|
|
if (left != right) {
|
|
// Handle std::optional<float>(nan)
|
|
// I'm too lazy to code comparison against std::nullopt, but this shouldn't be a problem in real life.
|
|
// RN comparing against std::nullopt, you'll get a compilation error.
|
|
if constexpr (is_instantiation_of<std::optional, L>::value && is_instantiation_of<std::optional, R>::value)
|
|
{
|
|
if (left.has_value() && right.has_value())
|
|
return CompareRecursive(*left, *right);
|
|
}
|
|
else if constexpr (is_instantiation_of<std::optional, L>::value) {
|
|
if (left)
|
|
return CompareRecursive(*left, right);
|
|
} else if constexpr (is_instantiation_of<std::optional, R>::value) {
|
|
if (right)
|
|
return CompareRecursive(left, *right);
|
|
} else if constexpr (std::is_floating_point_v<L> && std::is_floating_point_v<R>) {
|
|
if (std::isnan(left) && std::isnan(right))
|
|
return ::testing::AssertionSuccess();
|
|
}
|
|
|
|
return ::testing::AssertionFailure()
|
|
<< "\nExpected value: " << left
|
|
<< "\nActual value : " << right;
|
|
}
|
|
|
|
return ::testing::AssertionSuccess();
|
|
}
|
|
}
|