userver
C++ Async Framework
Toggle main menu visibility
Documentation
API Groups
Namespaces
Reference
Class List
Class Index
File List
Macros
All
e
i
l
r
t
u
Functions
Macros
e
i
l
r
t
u
Examples
•
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Modules
Pages
Concepts
Loading...
Searching...
No Matches
execution_result.hpp
Go to the documentation of this file.
1
#
pragma
once
2
3
/// @file userver/storages/clickhouse/execution_result.hpp
4
/// @brief Result accessor.
5
6
#
include
<
memory
>
7
#
include
<
type_traits
>
8
9
#
include
<
boost
/
pfr
/
core
.
hpp
>
10
11
#
include
<
userver
/
storages
/
clickhouse
/
impl
/
block_wrapper_fwd
.
hpp
>
12
#
include
<
userver
/
storages
/
clickhouse
/
io
/
impl
/
validate
.
hpp
>
13
14
#
include
<
userver
/
storages
/
clickhouse
/
io
/
result_mapper
.
hpp
>
15
16
USERVER_NAMESPACE_BEGIN
17
18
namespace
storages::
clickhouse
{
19
20
// clang-format off
21
22
/// Thin wrapper over underlying block of data, returned by
23
/// storages::clickhouse::Cluster Execute methods
24
///
25
/// ## Usage example:
26
///
27
/// @snippet storages/tests/execute_chtest.cpp Sample CppToClickhouse specialization
28
///
29
/// @snippet storages/tests/execute_chtest.cpp Sample ExecutionResult usage
30
31
// clang-format on
32
class
ExecutionResult
final
{
33
public
:
34
explicit
ExecutionResult(impl::BlockWrapperPtr);
35
ExecutionResult(ExecutionResult&&)
noexcept
;
36
~ExecutionResult();
37
38
/// Returns number of columns in underlying block.
39
size_t
GetColumnsCount
()
const
;
40
41
/// Returns number of rows in underlying block columns.
42
size_t
GetRowsCount
()
const
;
43
44
/// Converts underlying block to strongly-typed struct of vectors.
45
/// See @ref clickhouse_io for better understanding of `T`'s requirements.
46
template
<
typename
T>
47
T
As
() &&;
48
49
/// Converts underlying block to iterable of strongly-typed struct.
50
/// See @ref clickhouse_io for better understanding of `T`'s requirements.
51
template
<
typename
T>
52
auto
AsRows
() &&;
53
54
/// Converts underlying block to strongly-typed container.
55
/// See @ref clickhouse_io for better understanding
56
/// of `Container::value_type`'s requirements.
57
template
<
typename
Container>
58
Container
AsContainer
() &&;
59
60
private
:
61
impl::BlockWrapperPtr block_;
62
};
32
class
ExecutionResult
final
{
…
};
63
64
template
<
typename
T>
65
T ExecutionResult::
As
() && {
66
UASSERT
(block_);
67
T result{};
68
io
::impl::ValidateColumnsMapping(result);
69
io
::impl::ValidateColumnsCount<T>(
GetColumnsCount
(
)
);
70
71
using
MappedType =
typename
io
::CppToClickhouse<T>::mapped_type;
72
io
::ColumnsMapper<MappedType> mapper{*block_};
73
74
boost::pfr::for_each_field(result, mapper);
75
76
return
result;
77
}
65
T ExecutionResult::
As
() && {
…
}
78
79
template
<
typename
T>
80
auto
ExecutionResult::
AsRows
() && {
81
UASSERT
(block_);
82
io
::impl::ValidateRowsMapping<T>();
83
io
::impl::ValidateColumnsCount<T>(
GetColumnsCount
(
)
);
84
85
return
io
::RowsMapper<T>{std::move(block_)};
86
}
80
auto
ExecutionResult::
AsRows
() && {
…
}
87
88
template
<
typename
Container>
89
Container ExecutionResult::
AsContainer
() && {
90
UASSERT
(block_);
91
using
Row =
typename
Container::value_type;
92
93
Container result;
94
if
constexpr
(
io
::traits::kIsReservable<Container>) {
95
result.reserve(
GetRowsCount
(
)
);
96
}
97
98
auto
rows = std::move(*
this
).AsRows<Row>();
99
std::move(rows.begin(), rows.end(),
io
::traits::Inserter(result));
100
return
result;
101
}
89
Container ExecutionResult::
AsContainer
() && {
…
}
102
103
}
// namespace storages::clickhouse
104
105
USERVER_NAMESPACE_END
userver
storages
clickhouse
execution_result.hpp
Generated on Wed Apr 30 2025 15:49:55 for userver by
Doxygen
1.13.2