userver: userver/storages/clickhouse/io/columns/uuid_column.hpp Source File
Loading...
Searching...
No Matches
uuid_column.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/storages/clickhouse/io/columns/uuid_column.hpp
4/// @brief UUID column support
5/// @ingroup userver_clickhouse_types
6
7#include <boost/uuid/uuid.hpp>
8
9#include <userver/storages/clickhouse/io/columns/column_includes.hpp>
10
11USERVER_NAMESPACE_BEGIN
12
13namespace storages::clickhouse::io::columns {
14
15/// @brief Legacy broken ClickHouse UUID column representation.
16///
17/// @warning This implementation is broken in a way that uuids endianness is
18/// mismatched:
19/// uuid "30eec7b3-0b5c-451e-8976-98f62b4c4448" will be stored as
20/// uuid "1e455c0b-b3c7-ee30-4844-4c2bf6987689" in ClickHouse (notice that each
21/// of 8 hex bytes group is bytewise reversed).
22///
23/// Requires **both** writes and reads to be performed via userver to work.
24class MismatchedEndiannessUuidColumn final : public ClickhouseColumn<MismatchedEndiannessUuidColumn> {
25public:
26 using cpp_type = boost::uuids::uuid;
27 using container_type = std::vector<cpp_type>;
28
29 MismatchedEndiannessUuidColumn(ColumnRef column);
30
31 static ColumnRef Serialize(const container_type& from);
32};
33
34/// @brief Represents ClickHouse UUID column.
35class UuidRfc4122Column final : public ClickhouseColumn<UuidRfc4122Column> {
36public:
37 using cpp_type = boost::uuids::uuid;
38 using container_type = std::vector<cpp_type>;
39
40 UuidRfc4122Column(ColumnRef column);
41
42 static ColumnRef Serialize(const container_type& from);
43};
44
45// Dummy implementation to force a compile-time error on usage attempt.
46class UuidColumn final : public ClickhouseColumn<UuidColumn> {
47public:
48 using cpp_type = boost::uuids::uuid;
49 using container_type = std::vector<cpp_type>;
50
51 template <typename T>
52 UuidColumn(T) {
53 ReportMisuse<T>();
54 }
55
56 template <typename T>
57 static ColumnRef Serialize(const T&) {
58 ReportMisuse<T>();
59 return {};
60 }
61
62private:
63 template <typename T>
64 static void ReportMisuse() {
65 static_assert(
66 !sizeof(T),
67 "UuidColumn is deprecated: for old code rename it to "
68 "MismatchedEndiannessUuidColumn, for new code we encourage "
69 "you to use UuidRfc4122Column instead. See the "
70 "MismatchedEndiannessUuidColumn docs for explanation."
71 );
72 }
73};
74
75} // namespace storages::clickhouse::io::columns
76
77USERVER_NAMESPACE_END