11#include <userver/clients/dns/resolver_fwd.hpp>
12#include <userver/components/component_fwd.hpp>
14#include <userver/storages/clickhouse/fwd.hpp>
15#include <userver/storages/clickhouse/impl/insertion_request.hpp>
16#include <userver/storages/clickhouse/impl/pool.hpp>
17#include <userver/storages/clickhouse/options.hpp>
18#include <userver/storages/clickhouse/query.hpp>
19#include <userver/utils/statistics/writer.hpp>
21USERVER_NAMESPACE_BEGIN
28struct ClickhouseSettings;
46 const impl::ClickhouseSettings& settings,
52 Cluster(
const Cluster&) =
delete;
56 template <
typename... Args>
57 ExecutionResult
Execute(
const Query& query,
const Args&... args)
const;
61 template <
typename... Args>
62 ExecutionResult
Execute(OptionalCommandControl,
const Query& query,
const Args&... args)
const;
71 void Insert(
const std::string& table_name,
const std::vector<std::string_view>& column_names,
const T& data)
const;
82 OptionalCommandControl,
83 const std::string& table_name,
84 const std::vector<std::string_view>& column_names,
99 template <
typename Container>
101 const std::string& table_name,
102 const std::vector<std::string_view>& column_names,
103 const Container& data
118 template <
typename Container>
120 OptionalCommandControl,
121 const std::string& table_name,
122 const std::vector<std::string_view>& column_names,
123 const Container& data
131 using std::runtime_error::runtime_error;
135 void DoInsert(OptionalCommandControl,
const impl::InsertionRequest& request)
const;
137 ExecutionResult DoExecute(OptionalCommandControl,
const Query& query)
const;
139 const impl::Pool& GetPool()
const;
141 std::vector<impl::Pool> pools_;
142 mutable std::atomic<std::size_t> current_pool_ind_{0};
146void Cluster::
Insert(
const std::string& table_name,
const std::vector<std::string_view>& column_names,
const T& data)
148 Insert(OptionalCommandControl{}, table_name, column_names, data);
153 OptionalCommandControl optional_cc,
154 const std::string& table_name,
155 const std::vector<std::string_view>& column_names,
158 const auto request = impl::InsertionRequest::Create(table_name, column_names, data);
160 DoInsert(optional_cc, request);
163template <
typename Container>
165 const std::string& table_name,
166 const std::vector<std::string_view>& column_names,
167 const Container& data
169 InsertRows(OptionalCommandControl{}, table_name, column_names, data);
172template <
typename Container>
174 OptionalCommandControl optional_cc,
175 const std::string& table_name,
176 const std::vector<std::string_view>& column_names,
177 const Container& data
179 if (data.empty())
return;
181 const auto request = impl::InsertionRequest::CreateFromRows(table_name, column_names, data);
183 DoInsert(optional_cc, request);
186template <
typename... Args>
187ExecutionResult Cluster::
Execute(
const Query& query,
const Args&... args)
const {
188 return Execute(OptionalCommandControl{}, query, args...);
191template <
typename... Args>
192ExecutionResult Cluster::
Execute(OptionalCommandControl optional_cc,
const Query& query,
const Args&... args)
const {
193 const auto formatted_query = query.WithArgs(args...);
194 return DoExecute(optional_cc, formatted_query);