ClickHouse
69 строк · 2.4 Кб
1#include "GatherUtils.h"
2#include "Sinks.h"
3#include "Sources.h"
4#include <base/TypeLists.h>
5
6namespace DB::GatherUtils
7{
8/// Creates IArraySource from ColumnArray
9
10namespace
11{
12
13template <typename... Types>
14struct ArraySourceCreator;
15
16template <typename Type, typename... Types>
17struct ArraySourceCreator<Type, Types...>
18{
19static std::unique_ptr<IArraySource> create(const ColumnArray & col, const NullMap * null_map, bool is_const, size_t total_rows)
20{
21using ColVecType = ColumnVectorOrDecimal<Type>;
22
23if (typeid_cast<const ColVecType *>(&col.getData()))
24{
25if (null_map)
26{
27if (is_const)
28return std::make_unique<ConstSource<NullableArraySource<NumericArraySource<Type>>>>(col, *null_map, total_rows);
29return std::make_unique<NullableArraySource<NumericArraySource<Type>>>(col, *null_map);
30}
31if (is_const)
32return std::make_unique<ConstSource<NumericArraySource<Type>>>(col, total_rows);
33return std::make_unique<NumericArraySource<Type>>(col);
34}
35
36return ArraySourceCreator<Types...>::create(col, null_map, is_const, total_rows);
37}
38};
39
40template <>
41struct ArraySourceCreator<>
42{
43static std::unique_ptr<IArraySource> create(const ColumnArray & col, const NullMap * null_map, bool is_const, size_t total_rows)
44{
45if (null_map)
46{
47if (is_const)
48return std::make_unique<ConstSource<NullableArraySource<GenericArraySource>>>(col, *null_map, total_rows);
49return std::make_unique<NullableArraySource<GenericArraySource>>(col, *null_map);
50}
51if (is_const)
52return std::make_unique<ConstSource<GenericArraySource>>(col, total_rows);
53return std::make_unique<GenericArraySource>(col);
54}
55};
56
57}
58
59std::unique_ptr<IArraySource> createArraySource(const ColumnArray & col, bool is_const, size_t total_rows)
60{
61using Creator = TypeListChangeRoot<ArraySourceCreator, TypeListNumberWithUUID>;
62if (const auto * column_nullable = typeid_cast<const ColumnNullable *>(&col.getData()))
63{
64auto column = ColumnArray::create(column_nullable->getNestedColumnPtr(), col.getOffsetsPtr());
65return Creator::create(*column, &column_nullable->getNullMapData(), is_const, total_rows);
66}
67return Creator::create(col, nullptr, is_const, total_rows);
68}
69}
70