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
25 : public ClickhouseColumn<MismatchedEndiannessUuidColumn> {
26 public:
27 using cpp_type = boost::uuids::uuid;
28 using container_type = std::vector<cpp_type>;
29
30 MismatchedEndiannessUuidColumn(ColumnRef column);
31
32 static ColumnRef Serialize(const container_type& from);
33};
34
35/// @brief Represents ClickHouse UUID column.
36class UuidRfc4122Column final : public ClickhouseColumn<UuidRfc4122Column> {
37 public:
38 using cpp_type = boost::uuids::uuid;
39 using container_type = std::vector<cpp_type>;
40
41 UuidRfc4122Column(ColumnRef column);
42
43 static ColumnRef Serialize(const container_type& from);
44};
45
46// Dummy implementation to force a compile-time error on usage attempt.
47class UuidColumn final : public ClickhouseColumn<UuidColumn> {
48 public:
49 using cpp_type = boost::uuids::uuid;
50 using container_type = std::vector<cpp_type>;
51
52 template <typename T>
53 UuidColumn(T) {
54 ReportMisuse<T>();
55 }
56
57 template <typename T>
58 static ColumnRef Serialize(const T&) {
59 ReportMisuse<T>();
60 return {};
61 }
62
63 private:
64 template <typename T>
65 static void ReportMisuse() {
66 static_assert(!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} // namespace storages::clickhouse::io::columns
75
76USERVER_NAMESPACE_END