ClickHouse

Форк
0
/
createArraySource.cpp 
69 строк · 2.4 Кб
1
#include "GatherUtils.h"
2
#include "Sinks.h"
3
#include "Sources.h"
4
#include <base/TypeLists.h>
5

6
namespace DB::GatherUtils
7
{
8
/// Creates IArraySource from ColumnArray
9

10
namespace
11
{
12

13
template <typename... Types>
14
struct ArraySourceCreator;
15

16
template <typename Type, typename... Types>
17
struct ArraySourceCreator<Type, Types...>
18
{
19
    static std::unique_ptr<IArraySource> create(const ColumnArray & col, const NullMap * null_map, bool is_const, size_t total_rows)
20
    {
21
        using ColVecType = ColumnVectorOrDecimal<Type>;
22

23
        if (typeid_cast<const ColVecType *>(&col.getData()))
24
        {
25
            if (null_map)
26
            {
27
                if (is_const)
28
                    return std::make_unique<ConstSource<NullableArraySource<NumericArraySource<Type>>>>(col, *null_map, total_rows);
29
                return std::make_unique<NullableArraySource<NumericArraySource<Type>>>(col, *null_map);
30
            }
31
            if (is_const)
32
                return std::make_unique<ConstSource<NumericArraySource<Type>>>(col, total_rows);
33
            return std::make_unique<NumericArraySource<Type>>(col);
34
        }
35

36
        return ArraySourceCreator<Types...>::create(col, null_map, is_const, total_rows);
37
    }
38
};
39

40
template <>
41
struct ArraySourceCreator<>
42
{
43
    static std::unique_ptr<IArraySource> create(const ColumnArray & col, const NullMap * null_map, bool is_const, size_t total_rows)
44
    {
45
        if (null_map)
46
        {
47
            if (is_const)
48
                return std::make_unique<ConstSource<NullableArraySource<GenericArraySource>>>(col, *null_map, total_rows);
49
            return std::make_unique<NullableArraySource<GenericArraySource>>(col, *null_map);
50
        }
51
        if (is_const)
52
            return std::make_unique<ConstSource<GenericArraySource>>(col, total_rows);
53
        return std::make_unique<GenericArraySource>(col);
54
    }
55
};
56

57
}
58

59
std::unique_ptr<IArraySource> createArraySource(const ColumnArray & col, bool is_const, size_t total_rows)
60
{
61
    using Creator = TypeListChangeRoot<ArraySourceCreator, TypeListNumberWithUUID>;
62
    if (const auto * column_nullable = typeid_cast<const ColumnNullable *>(&col.getData()))
63
    {
64
        auto column = ColumnArray::create(column_nullable->getNestedColumnPtr(), col.getOffsetsPtr());
65
        return Creator::create(*column, &column_nullable->getNullMapData(), is_const, total_rows);
66
    }
67
    return Creator::create(col, nullptr, is_const, total_rows);
68
}
69
}
70

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.