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.
227 lines
8.2 KiB
C++
227 lines
8.2 KiB
C++
#include <datastore/types/types.h>
|
|
#include <datastore/columns/bool.h>
|
|
#include <datastore/columns/factory.h>
|
|
#include <datastore/columns/numeric.h>
|
|
#include <ut/utils.h>
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
using namespace datastore;
|
|
|
|
TEST(TypesCase, TypeName) {
|
|
ASSERT_EQ(Type::CreateDate()->GetName(), "Date");
|
|
|
|
ASSERT_EQ(Type::CreateArray(Type::CreateSimple<int32_t>())->GetName(), "Array(Int32)");
|
|
|
|
ASSERT_EQ(Type::CreateNullable(Type::CreateSimple<int32_t>())->GetName(), "Nullable(Int32)");
|
|
|
|
ASSERT_EQ(Type::CreateArray(Type::CreateSimple<int32_t>())->As<ArrayType>()->GetItemType()->GetCode(), Type::Int32);
|
|
|
|
ASSERT_EQ(Type::CreateTuple({Type::CreateSimple<int32_t>(), Type::CreateString()})->GetName(), "Tuple(Int32, String)");
|
|
|
|
ASSERT_EQ(
|
|
Type::CreateTuple({
|
|
Type::CreateSimple<int32_t>(),
|
|
Type::CreateString()})->GetName(),
|
|
"Tuple(Int32, String)"
|
|
);
|
|
|
|
ASSERT_EQ(
|
|
Type::CreateEnum8({{"One", 1}})->GetName(),
|
|
"Enum8('One' = 1)"
|
|
);
|
|
ASSERT_EQ(
|
|
Type::CreateEnum8({})->GetName(),
|
|
"Enum8()"
|
|
);
|
|
|
|
ASSERT_EQ(Type::CreateMap(Type::CreateSimple<int32_t>(), Type::CreateString())->GetName(), "Map(Int32, String)");
|
|
|
|
ASSERT_EQ(Type::CreateSimple<bool>()->GetName(), "Bool");
|
|
}
|
|
|
|
TEST(TypesCase, NullableType) {
|
|
TypeRef nested = Type::CreateSimple<int32_t>();
|
|
ASSERT_EQ(Type::CreateNullable(nested)->As<NullableType>()->GetNestedType(), nested);
|
|
}
|
|
|
|
TEST(TypesCase, TupleTypeItemNames) {
|
|
auto unnamed = Type::CreateTuple({
|
|
Type::CreateSimple<int32_t>(),
|
|
Type::CreateString()});
|
|
ASSERT_TRUE(unnamed->As<TupleType>()->GetItemNames().empty());
|
|
|
|
auto named = Type::CreateTuple(
|
|
{Type::CreateSimple<int32_t>(), Type::CreateString()},
|
|
{"a", "b"});
|
|
const auto& names = named->As<TupleType>()->GetItemNames();
|
|
ASSERT_EQ(names.size(), 2u);
|
|
ASSERT_EQ(names[0], "a");
|
|
ASSERT_EQ(names[1], "b");
|
|
}
|
|
|
|
TEST(TypesCase, TupleTypeNameIncludesFieldNames) {
|
|
auto named = Type::CreateTuple(
|
|
{Type::CreateSimple<uint8_t>(), Type::CreateString()},
|
|
{"a", "b"});
|
|
ASSERT_EQ(named->GetName(), "Tuple(a UInt8, b String)");
|
|
|
|
ASSERT_THROW(
|
|
Type::CreateTuple(
|
|
{Type::CreateSimple<uint8_t>(), Type::CreateString()},
|
|
{"a", ""}),
|
|
ValidationError);
|
|
|
|
ASSERT_THROW(
|
|
Type::CreateTuple(
|
|
{Type::CreateSimple<uint8_t>(), Type::CreateString()},
|
|
{"a"}),
|
|
ValidationError);
|
|
}
|
|
|
|
TEST(TypesCase, TupleTypeNamesFromFactory) {
|
|
auto col = CreateColumnByType("Tuple(a UInt8, b String)");
|
|
ASSERT_NE(col, nullptr);
|
|
const auto& names = col->Type()->As<TupleType>()->GetItemNames();
|
|
ASSERT_EQ(names.size(), 2u);
|
|
ASSERT_EQ(names[0], "a");
|
|
ASSERT_EQ(names[1], "b");
|
|
|
|
auto col_unnamed = CreateColumnByType("Tuple(UInt8, String)");
|
|
ASSERT_NE(col_unnamed, nullptr);
|
|
ASSERT_TRUE(col_unnamed->Type()->As<TupleType>()->GetItemNames().empty());
|
|
}
|
|
|
|
TEST(TypesCase, TupleTypeEqualityIncludesFieldNames) {
|
|
auto unnamed = Type::CreateTuple(
|
|
{Type::CreateSimple<uint8_t>(), Type::CreateString()});
|
|
auto named_ab = Type::CreateTuple(
|
|
{Type::CreateSimple<uint8_t>(), Type::CreateString()},
|
|
{"a", "b"});
|
|
auto named_xy = Type::CreateTuple(
|
|
{Type::CreateSimple<uint8_t>(), Type::CreateString()},
|
|
{"x", "y"});
|
|
|
|
ASSERT_TRUE(named_ab->IsEqual(named_ab));
|
|
ASSERT_FALSE(named_ab->IsEqual(unnamed));
|
|
ASSERT_FALSE(named_ab->IsEqual(named_xy));
|
|
}
|
|
|
|
TEST(TypesCase, EnumTypes) {
|
|
auto enum8 = Type::CreateEnum8({{"One", 1}, {"Two", 2}});
|
|
ASSERT_EQ(enum8->GetName(), "Enum8('One' = 1, 'Two' = 2)");
|
|
ASSERT_TRUE(enum8->As<EnumType>()->HasEnumValue(1));
|
|
ASSERT_TRUE(enum8->As<EnumType>()->HasEnumName("Two"));
|
|
ASSERT_FALSE(enum8->As<EnumType>()->HasEnumValue(10));
|
|
ASSERT_FALSE(enum8->As<EnumType>()->HasEnumName("Ten"));
|
|
ASSERT_EQ(enum8->As<EnumType>()->GetEnumName(2), "Two");
|
|
ASSERT_EQ(enum8->As<EnumType>()->GetEnumValue("Two"), 2);
|
|
|
|
auto enum16 = Type::CreateEnum16({{"Green", 1}, {"Red", 2}, {"Yellow", 3}});
|
|
ASSERT_EQ(enum16->GetName(), "Enum16('Green' = 1, 'Red' = 2, 'Yellow' = 3)");
|
|
ASSERT_TRUE(enum16->As<EnumType>()->HasEnumValue(3));
|
|
ASSERT_TRUE(enum16->As<EnumType>()->HasEnumName("Green"));
|
|
ASSERT_FALSE(enum16->As<EnumType>()->HasEnumValue(10));
|
|
ASSERT_FALSE(enum16->As<EnumType>()->HasEnumName("Black"));
|
|
ASSERT_EQ(enum16->As<EnumType>()->GetEnumName(2), "Red");
|
|
ASSERT_EQ(enum16->As<EnumType>()->GetEnumValue("Green"), 1);
|
|
|
|
ASSERT_EQ(std::distance(enum16->As<EnumType>()->BeginValueToName(), enum16->As<EnumType>()->EndValueToName()), 3u);
|
|
ASSERT_EQ(enum16->As<EnumType>()->BeginValueToName()->first, 1);
|
|
ASSERT_EQ(enum16->As<EnumType>()->BeginValueToName()->second, "Green");
|
|
ASSERT_EQ((++enum16->As<EnumType>()->BeginValueToName())->first, 2);
|
|
ASSERT_EQ((++enum16->As<EnumType>()->BeginValueToName())->second, "Red");
|
|
}
|
|
|
|
TEST(TypesCase, EnumTypesEmpty) {
|
|
ASSERT_EQ("Enum8()", Type::CreateEnum8({})->GetName());
|
|
ASSERT_EQ("Enum16()", Type::CreateEnum16({})->GetName());
|
|
}
|
|
|
|
TEST(TypesCase, DecimalTypes) {
|
|
// TODO: implement this test.
|
|
}
|
|
|
|
TEST(TypesCase, IsEqual) {
|
|
const std::string type_names[] = {
|
|
#if !DS_MAP_BOOL_TO_UINT8
|
|
"Bool",
|
|
#endif
|
|
"UInt8",
|
|
"Int8",
|
|
// "UInt128",
|
|
"String",
|
|
"FixedString(0)",
|
|
"FixedString(10000)",
|
|
"DateTime('UTC')",
|
|
"DateTime64(3, 'UTC')",
|
|
"Decimal(9,3)",
|
|
"Decimal(18,3)",
|
|
"Enum8('ONE' = 1)",
|
|
"Enum8('ONE' = 1, 'TWO' = 2)",
|
|
"Enum16('ONE' = 1, 'TWO' = 2, 'THREE' = 3, 'FOUR' = 4)",
|
|
"Nullable(FixedString(10000))",
|
|
"Nullable(LowCardinality(FixedString(10000)))",
|
|
"Array(Int8)",
|
|
"Array(UInt8)",
|
|
"Array(String)",
|
|
"Array(Nullable(LowCardinality(FixedString(10000))))",
|
|
"Array(Enum8('ONE' = 1, 'TWO' = 2))"
|
|
"Tuple(String, Int8, Date, DateTime)",
|
|
"Nullable(Tuple(String, Int8, Date, DateTime))",
|
|
"Array(Nullable(Tuple(String, Int8, Date, DateTime)))",
|
|
"Array(Array(Nullable(Tuple(String, Int8, Date, DateTime))))",
|
|
"Array(Array(Array(Nullable(Tuple(String, Int8, Date, DateTime)))))",
|
|
"Array(Array(Array(Array(Nullable(Tuple(String, Int8, Date, DateTime('UTC')))))))"
|
|
"Array(Array(Array(Array(Nullable(Tuple(String, Int8, Date, DateTime('UTC'), Tuple(LowCardinality(String), Enum8('READ'=1, 'WRITE'=0))))))))",
|
|
"Map(String, Int8)",
|
|
"Map(String, Tuple(String, Int8, Date, DateTime))",
|
|
"Map(UUID, Array(Tuple(String, Int8, Date, DateTime)))",
|
|
"Map(String, Array(Array(Array(Nullable(Tuple(String, Int8, Date, DateTime))))))",
|
|
"Map(LowCardinality(FixedString(10)), Array(Array(Array(Array(Nullable(Tuple(String, Int8, Date, DateTime('UTC'))))))))",
|
|
"Point",
|
|
"Ring",
|
|
"Polygon",
|
|
"MultiPolygon",
|
|
"JSON",
|
|
};
|
|
|
|
// Check that Type::IsEqual returns true only if:
|
|
// - same Type instance
|
|
// - same Type layout (matching outer type with all nested types and/or parameters)
|
|
for (const auto & type_name : type_names) {
|
|
SCOPED_TRACE(type_name);
|
|
const auto type = datastore::CreateColumnByType(type_name)->Type();
|
|
|
|
// Should be equal to itself
|
|
EXPECT_TRUE(type->IsEqual(type));
|
|
EXPECT_TRUE(type->IsEqual(*type));
|
|
|
|
for (const auto & other_type_name : type_names) {
|
|
SCOPED_TRACE(other_type_name);
|
|
const auto other_column = datastore::CreateColumnByType(other_type_name);
|
|
ASSERT_NE(nullptr, other_column);
|
|
|
|
const auto other_type = other_column->Type();
|
|
|
|
const auto should_be_equal = type_name == other_type_name;
|
|
EXPECT_EQ(should_be_equal, type->IsEqual(other_type))
|
|
<< "For types: " << type_name << " and " << other_type_name;
|
|
}
|
|
}
|
|
}
|
|
|
|
TEST(TypesCase, ErrorEnumContent) {
|
|
const std::string type_names[] = {
|
|
"Enum8()",
|
|
"Enum8('ONE')",
|
|
"Enum8('ONE'=1,'TWO')",
|
|
"Enum16('TWO'=,'TWO')",
|
|
};
|
|
|
|
for (const auto& type_name : type_names) {
|
|
SCOPED_TRACE(type_name);
|
|
EXPECT_THROW(datastore::CreateColumnByType(type_name)->Type(), ValidationError);
|
|
}
|
|
}
|