1#include "GatherUtils.h"
2#include "Sinks.h"
3#include "Sources.h"
4#include <Core/TypeListNumber.h>
5
6namespace DB::GatherUtils
7{
8/// Creates IArraySink from ColumnArray
9
10template <typename... Types>
11struct ArraySinkCreator;
12
13template <typename Type, typename... Types>
14struct 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
31template <>
32struct 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
42std::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