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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
|
#pragma once
#include "IArraySink.h"
#include <Columns/ColumnVector.h>
#include <Columns/ColumnDecimal.h>
#include <Columns/ColumnArray.h>
#include <Columns/ColumnString.h>
#include <Columns/ColumnFixedString.h>
#include <Columns/ColumnConst.h>
#include <Columns/ColumnNullable.h>
#include <Common/typeid_cast.h>
#include <Common/assert_cast.h>
namespace DB::GatherUtils
{
template <typename T>
struct NumericArraySource;
struct GenericArraySource;
template <typename ArraySource>
struct NullableArraySource;
template <typename T>
struct NumericValueSource;
struct GenericValueSource;
template <typename ArraySource>
struct NullableValueSource;
template <typename T>
struct NumericArraySink : public ArraySinkImpl<NumericArraySink<T>>
{
using ColVecType = ColumnVectorOrDecimal<T>;
using CompatibleArraySource = NumericArraySource<T>;
using CompatibleValueSource = NumericValueSource<T>;
typename ColVecType::Container & elements;
typename ColumnArray::Offsets & offsets;
size_t row_num = 0;
ColumnArray::Offset current_offset = 0;
NumericArraySink(IColumn & elements_, ColumnArray::Offsets & offsets_, size_t column_size)
: elements(assert_cast<ColVecType&>(elements_).getData()), offsets(offsets_)
{
offsets.resize(column_size);
}
void next()
{
offsets[row_num] = current_offset;
++row_num;
}
bool isEnd() const
{
return row_num == offsets.size();
}
size_t rowNum() const
{
return row_num;
}
void reserve(size_t num_elements)
{
elements.reserve(num_elements);
}
};
struct StringSink
{
typename ColumnString::Chars & elements;
typename ColumnString::Offsets & offsets;
size_t row_num = 0;
ColumnString::Offset current_offset = 0;
StringSink(ColumnString & col, size_t column_size)
: elements(col.getChars()), offsets(col.getOffsets())
{
offsets.resize(column_size);
}
void ALWAYS_INLINE next()
{
elements.push_back(0);
++current_offset;
offsets[row_num] = current_offset;
++row_num;
}
bool isEnd() const
{
return row_num == offsets.size();
}
size_t rowNum() const
{
return row_num;
}
void reserve(size_t num_elements)
{
elements.reserve(num_elements);
}
};
struct FixedStringSink
{
typename ColumnString::Chars & elements;
size_t string_size;
size_t row_num = 0;
size_t total_rows;
ColumnString::Offset current_offset = 0;
FixedStringSink(ColumnFixedString & col, size_t column_size)
: elements(col.getChars()), string_size(col.getN()), total_rows(column_size)
{
elements.resize(column_size * string_size);
}
void next()
{
current_offset += string_size;
++row_num;
}
bool isEnd() const
{
return row_num == total_rows;
}
size_t rowNum() const
{
return row_num;
}
void reserve(size_t num_elements)
{
elements.reserve(num_elements);
}
};
struct GenericArraySink : public ArraySinkImpl<GenericArraySink>
{
using CompatibleArraySource = GenericArraySource;
using CompatibleValueSource = GenericValueSource;
IColumn & elements;
ColumnArray::Offsets & offsets;
size_t row_num = 0;
ColumnArray::Offset current_offset = 0;
GenericArraySink(IColumn & elements_, ColumnArray::Offsets & offsets_, size_t column_size)
: elements(elements_), offsets(offsets_)
{
offsets.resize(column_size);
}
void next()
{
offsets[row_num] = current_offset;
++row_num;
}
bool isEnd() const
{
return row_num == offsets.size();
}
size_t rowNum() const
{
return row_num;
}
void reserve(size_t num_elements)
{
elements.reserve(num_elements);
}
};
template <typename ArraySink>
struct NullableArraySink : public ArraySink
{
using CompatibleArraySource = NullableArraySource<typename ArraySink::CompatibleArraySource>;
using CompatibleValueSource = NullableValueSource<typename ArraySink::CompatibleValueSource>;
NullMap & null_map;
NullableArraySink(IColumn & elements_, ColumnArray::Offsets & offsets_, size_t column_size)
: ArraySink(assert_cast<ColumnNullable &>(elements_).getNestedColumn(), offsets_, column_size)
, null_map(assert_cast<ColumnNullable &>(elements_).getNullMapData())
{
}
void accept(ArraySinkVisitor & visitor) override { visitor.visit(*this); }
void reserve(size_t num_elements)
{
ArraySink::reserve(num_elements);
null_map.reserve(num_elements);
}
};
}
|