ClickHouse
71 строка · 1.8 Кб
1#ifndef __clang_analyzer__ // It's too hard to analyze.2
3#include "GatherUtils.h"4#include "Selectors.h"5#include "Algorithms.h"6
7namespace DB8{
9
10namespace ErrorCodes11{
12extern const int LOGICAL_ERROR;13}
14
15
16namespace GatherUtils17{
18
19namespace
20{
21
22struct ArrayConcat : public ArraySourceSelector<ArrayConcat>23{
24using Sources = std::vector<std::unique_ptr<IArraySource>>;25
26template <typename Source>27static void selectSource(bool /*is_const*/, bool is_nullable, Source & source, const Sources & sources, ColumnArray::MutablePtr & result)28{29using SourceType = typename std::decay<Source>::type;30using Sink = typename SourceType::SinkType;31
32if (is_nullable)33{34using NullableSource = NullableArraySource<SourceType>;35using NullableSink = typename NullableSource::SinkType;36
37auto & nullable_source = static_cast<NullableSource &>(source);38
39
40result = ColumnArray::create(nullable_source.createValuesColumn());41NullableSink sink(result->getData(), result->getOffsets(), source.getColumnSize());42
43concat<NullableSource, NullableSink>(sources, std::move(sink));44}45else46{47result = ColumnArray::create(source.createValuesColumn());48Sink sink(result->getData(), result->getOffsets(), source.getColumnSize());49
50concat<SourceType, Sink>(sources, std::move(sink));51}52}53};54
55}
56
57ColumnArray::MutablePtr concat(const std::vector<std::unique_ptr<IArraySource>> & sources)58{
59if (sources.empty())60throw Exception(ErrorCodes::LOGICAL_ERROR, "Concat function should get at least 1 ArraySource");61
62ColumnArray::MutablePtr res;63ArrayConcat::select(*sources.front(), sources, res);64return res;65}
66
67}
68
69}
70
71#endif72