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 IArraySink from ColumnArray |
9 | |
10 | template <typename... Types> |
11 | struct ArraySinkCreator; |
12 | |
13 | template <typename Type, typename... Types> |
14 | struct ArraySinkCreator<Type, Types...> |
15 | { |
16 | static std::unique_ptr<IArraySink> create(ColumnArray & col, NullMap * null_map, size_t column_size) |
17 | { |
18 | using ColVecType = std::conditional_t<IsDecimalNumber<Type>, ColumnDecimal<Type>, ColumnVector<Type>>; |
19 | |
20 | if (typeid_cast<ColVecType *>(&col.getData())) |
21 | { |
22 | if (null_map) |
23 | return std::make_unique<NullableArraySink<NumericArraySink<Type>>>(col, *null_map, column_size); |
24 | return std::make_unique<NumericArraySink<Type>>(col, column_size); |
25 | } |
26 | |
27 | return ArraySinkCreator<Types...>::create(col, null_map, column_size); |
28 | } |
29 | }; |
30 | |
31 | template <> |
32 | struct ArraySinkCreator<> |
33 | { |
34 | static std::unique_ptr<IArraySink> create(ColumnArray & col, NullMap * null_map, size_t column_size) |
35 | { |
36 | if (null_map) |
37 | return std::make_unique<NullableArraySink<GenericArraySink>>(col, *null_map, column_size); |
38 | return std::make_unique<GenericArraySink>(col, column_size); |
39 | } |
40 | }; |
41 | |
42 | std::unique_ptr<IArraySink> createArraySink(ColumnArray & col, size_t column_size) |
43 | { |
44 | using Creator = ApplyTypeListForClass<ArraySinkCreator, TypeListNumbers>::Type; |
45 | if (auto column_nullable = typeid_cast<ColumnNullable *>(&col.getData())) |
46 | { |
47 | auto column = ColumnArray::create(column_nullable->getNestedColumnPtr()->assumeMutable(), col.getOffsetsPtr()->assumeMutable()); |
48 | return Creator::create(*column, &column_nullable->getNullMapData(), column_size); |
49 | } |
50 | return Creator::create(col, nullptr, column_size); |
51 | } |
52 | } |
53 | |