userver: userver/storages/clickhouse/io/columns/base_column.hpp Source File
Loading...
Searching...
No Matches
base_column.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/storages/clickhouse/io/columns/base_column.hpp
4/// @brief @copybrief storages::clickhouse::io::columns::ClickhouseColumn
5
6#include <userver/storages/clickhouse/io/columns/column_iterator.hpp>
7#include <userver/storages/clickhouse/io/columns/column_wrapper.hpp>
8
9USERVER_NAMESPACE_BEGIN
10
11namespace storages::clickhouse::io::columns {
12
13// clang-format off
14/// @brief Base class for every typed ClickHouse column.
15/// To add new columns one should derive from this class,
16/// define types aliases:
17/// - `cpp_type` - to what C++ types are column values mapped,
18/// - `container_type` (being `std::vector<cpp_type>`)
19///
20/// and implement 3 methods:
21/// - `ctor(ColumnRef)` - column constructor,
22/// - `static ColumnRef Serialize(const container_type&)` - constructs a column from C++ container,
23/// - `cpp_type ColumnIterator<YourColumnType>::DataHolder::Get()`
24///
25/// see implementation of any of the existing columns for better understanding.
26// clang-format on
27template <typename ColumnType>
29 public:
30 using iterator = ColumnIterator<ColumnType>;
31
32 ClickhouseColumn(ColumnRef column) : column_{std::move(column)} {}
33
34 iterator begin() const { return iterator{column_}; }
35
36 iterator end() const { return iterator::End(column_); }
37
38 size_t Size() const { return GetColumnSize(column_); }
39
40 private:
41 ColumnRef column_;
42};
43
44} // namespace storages::clickhouse::io::columns
45
46USERVER_NAMESPACE_END