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