aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/Functions/GatherUtils/createArraySink.cpp
blob: a47ca312955f5ece0a1bf18aee208ae164f8803a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include "GatherUtils.h"
#include "Sinks.h"
#include "Sources.h"
#include <base/TypeLists.h>

namespace DB::GatherUtils
{
/// Creates IArraySink from ColumnArray

namespace
{

template <typename... Types>
struct ArraySinkCreator;

template <typename Type, typename... Types>
struct ArraySinkCreator<Type, Types...>
{
    static std::unique_ptr<IArraySink> create(IColumn & values, ColumnArray::Offsets & offsets, size_t column_size)
    {
        using ColVecType = ColumnVectorOrDecimal<Type>;

        IColumn * not_null_values = &values;
        bool is_nullable = false;

        if (auto * nullable = typeid_cast<ColumnNullable *>(&values))
        {
            not_null_values = &nullable->getNestedColumn();
            is_nullable = true;
        }

        if (typeid_cast<ColVecType *>(not_null_values))
        {
            if (is_nullable)
                return std::make_unique<NullableArraySink<NumericArraySink<Type>>>(values, offsets, column_size);
            return std::make_unique<NumericArraySink<Type>>(values, offsets, column_size);
        }

        return ArraySinkCreator<Types...>::create(values, offsets, column_size);
    }
};

template <>
struct ArraySinkCreator<>
{
    static std::unique_ptr<IArraySink> create(IColumn & values, ColumnArray::Offsets & offsets, size_t column_size)
    {
        if (typeid_cast<ColumnNullable *>(&values))
            return std::make_unique<NullableArraySink<GenericArraySink>>(values, offsets, column_size);
        return std::make_unique<GenericArraySink>(values, offsets, column_size);
    }
};

}

std::unique_ptr<IArraySink> createArraySink(ColumnArray & col, size_t column_size)
{
    using Creator = TypeListChangeRoot<ArraySinkCreator, TypeListNumberWithUUID>;
    return Creator::create(col.getData(), col.getOffsets(), column_size);
}
}