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.
205 lines
7.0 KiB
C++
205 lines
7.0 KiB
C++
#include "value_generators.h"
|
|
|
|
#include <algorithm>
|
|
#include <type_traits>
|
|
#include <math.h>
|
|
|
|
namespace {
|
|
using namespace datastore;
|
|
}
|
|
|
|
std::vector<uint32_t> MakeNumbers() {
|
|
return std::vector<uint32_t> {1, 2, 3, 7, 11, 13, 17, 19, 23, 29, 31};
|
|
}
|
|
|
|
std::vector<uint8_t> MakeBools() {
|
|
return std::vector<uint8_t> {1, 0, 0, 0, 1, 1, 0, 1, 1, 1, 0};
|
|
}
|
|
|
|
std::vector<std::string> MakeFixedStrings(size_t string_size) {
|
|
std::vector<std::string> result = MakeStrings();
|
|
|
|
std::for_each(result.begin(), result.end(), [string_size](auto& value) {
|
|
value.resize(string_size, '\0');
|
|
});
|
|
|
|
return result;
|
|
}
|
|
|
|
std::vector<std::string> MakeStrings() {
|
|
return {
|
|
"a", "ab", "abc", "abcd",
|
|
"long string to test how those are handled. Here goes more text. "
|
|
"long string to test how those are handled. Here goes more text. "
|
|
"long string to test how those are handled. Here goes more text. "
|
|
"long string to test how those are handled. Here goes more text. "
|
|
"long string to test how those are handled. Here goes more text. "
|
|
"long string to test how those are handled. Here goes more text. "
|
|
"long string to test how those are handled. Here goes more text. "
|
|
"long string to test how those are handled. Here goes more text. "
|
|
"long string to test how those are handled. Here goes more text. "
|
|
"long string to test how those are handled. Here goes more text. "
|
|
"long string to test how those are handled. Here goes more text. "
|
|
"long string to test how those are handled. Here goes more text. "
|
|
"long string to test how those are handled. Here goes more text. "
|
|
"long string to test how those are handled. Here goes more text. "
|
|
"long string to test how those are handled. Here goes more text. "
|
|
"long string to test how those are handled. Here goes more text. "
|
|
"long string to test how those are handled. Here goes more text. "
|
|
"long string to test how those are handled. Here goes more text. "
|
|
"long string to test how those are handled. Here goes more text. "
|
|
};
|
|
}
|
|
|
|
std::vector<std::string> MakeJSONs() {
|
|
return {
|
|
R"({})",
|
|
R"({"a":"1"})",
|
|
R"({"age":"30","name":"Alice"})",
|
|
R"({"escapes":"line1\nline2\t\"quoted\"","unicode":"éèê"})",
|
|
};
|
|
}
|
|
|
|
std::vector<UUID> MakeUUIDs() {
|
|
return {
|
|
UUID(0llu, 0llu),
|
|
UUID(0xbb6a8c699ab2414cllu, 0x86697b7fd27f0825llu),
|
|
UUID(0x84b9f24bc26b49c6llu, 0xa03b4ab723341951llu),
|
|
UUID(0x3507213c178649f9llu, 0x9faf035d662f60aellu)
|
|
};
|
|
}
|
|
|
|
std::vector<Int64> MakeDateTime64s(size_t scale, size_t values_size) {
|
|
const auto seconds_multiplier = static_cast<size_t>(std::pow(10, scale));
|
|
const auto year = 86400ull * 365 * seconds_multiplier; // ~approx, but this doesn't matter here.
|
|
|
|
// Approximatelly +/- 200 years around epoch (and value of epoch itself)
|
|
// with non zero seconds and sub-seconds.
|
|
// Please note there are values outside of DateTime (32-bit) range that might
|
|
// not have correct string representation in CH yet,
|
|
// but still are supported as Int64 values.
|
|
return GenerateVector(values_size,
|
|
[seconds_multiplier, year] (size_t i )-> Int64 {
|
|
return (i - 100) * year * 2 + (i * 10) * seconds_multiplier + i;
|
|
});
|
|
}
|
|
|
|
std::vector<int32_t> MakeDates32() {
|
|
// in CH Date32 internally a UInt32 and stores a day number
|
|
// ColumnDate expects values to be seconds, which is then
|
|
// converted to day number internally, hence the `* 86400`.
|
|
// 114634 * 86400 is 2282-11-10, last integer that fits into DateTime32 range
|
|
// (max is 2283-11-11)
|
|
std::vector<int32_t> result = MakeDates<int32_t>();
|
|
|
|
// add corresponding negative values, since pre-epoch date are supported too.
|
|
const auto size = result.size();
|
|
for (size_t i = 0; i < size; ++i) {
|
|
result.push_back(result[i] * -1);
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
std::vector<datastore::Int64> MakeDateTimes() {
|
|
// in CH DateTime internally a UInt32
|
|
return {
|
|
0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536,
|
|
131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216, 33554432, 67108864,
|
|
134217728, 268435456, 536870912, 1073741824, 2147483648, 4294967296 - 1
|
|
};
|
|
}
|
|
|
|
std::vector<datastore::Int128> MakeInt128s() {
|
|
return {
|
|
absl::MakeInt128(0xffffffffffffffffll, 0xffffffffffffffffll), // -1
|
|
absl::MakeInt128(0, 0xffffffffffffffffll), // 2^64 - 1
|
|
absl::MakeInt128(0xffffffffffffffffll, 0),
|
|
absl::MakeInt128(0x8000000000000000ll, 0),
|
|
Int128(0)
|
|
};
|
|
}
|
|
|
|
std::vector<datastore::UInt128> MakeUInt128s() {
|
|
return {
|
|
absl::MakeUint128(0xffffffffffffffffll, 0xffffffffffffffffll), // 2^128 - 1
|
|
absl::MakeUint128(0, 0xffffffffffffffffll), // 2^64 - 1
|
|
absl::MakeUint128(0xffffffffffffffffll, 0), // 2^128 - 2^64
|
|
absl::MakeUint128(0x8000000000000000ll, 0),
|
|
UInt128(0)
|
|
};
|
|
}
|
|
|
|
std::vector<int32_t> MakeTime() {
|
|
std::vector<int32_t> values{
|
|
1, // 1 second
|
|
2,
|
|
5,
|
|
60,
|
|
60 * 2,
|
|
60 * 5,
|
|
3600,
|
|
3600 * 2,
|
|
3600 * 5,
|
|
3600 * 24,
|
|
3600 * 24 * 2,
|
|
3600 * 24 * 5,
|
|
3600 * 999 + 60 * 59 + 59,
|
|
};
|
|
|
|
auto ret = values;
|
|
ret.reserve(values.size() * 2 + 1);
|
|
ret.push_back(0);
|
|
|
|
// append negative values as well
|
|
std::transform(values.cbegin(), values.cend(), std::back_inserter(ret), [](int32_t x){ return -x; });
|
|
return ret;
|
|
}
|
|
|
|
std::vector<datastore::Int128> MakeDecimals(size_t /*precision*/, size_t scale) {
|
|
const auto scale_multiplier = static_cast<size_t>(std::pow(10, scale));
|
|
const long long int rhs_value = 12345678910;
|
|
|
|
const std::vector<long long int> vals {0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536 - 1};
|
|
|
|
std::vector<datastore::Int128> result;
|
|
result.reserve(vals.size());
|
|
|
|
std::transform(vals.begin(), vals.end(), std::back_inserter(result), [scale_multiplier, rhs_value](const auto& value) {
|
|
return value * scale_multiplier + rhs_value % scale_multiplier;
|
|
});
|
|
|
|
return result;
|
|
}
|
|
|
|
std::string FooBarGenerator(size_t i) {
|
|
std::string result;
|
|
if (i % 3 == 0)
|
|
result += "Foo";
|
|
if (i % 5 == 0)
|
|
result += "Bar";
|
|
if (result.empty())
|
|
result = std::to_string(i);
|
|
|
|
return result;
|
|
}
|
|
|
|
std::vector<in_addr> MakeIPv4s() {
|
|
return {
|
|
MakeIPv4(0x12345678), // 255.255.255.255
|
|
MakeIPv4(0x0100007f), // 127.0.0.1
|
|
MakeIPv4(3585395774),
|
|
MakeIPv4(0),
|
|
MakeIPv4(0x12345678),
|
|
};
|
|
}
|
|
|
|
std::vector<in6_addr> MakeIPv6s() {
|
|
return {
|
|
MakeIPv6(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15), // 1:203:405:607:809:a0b:c0d:e0f
|
|
MakeIPv6(0, 0, 0, 0, 0, 1), // ::1
|
|
MakeIPv6(0, 0, 0, 0, 0, 0), // ::
|
|
MakeIPv6(0xff, 0xff, 204, 152, 189, 116), // ::ffff:204.152.189.116
|
|
};
|
|
}
|