MCPcopy Create free account
hub / github.com/bytedance/bolt / arrayOfRowVector

Method arrayOfRowVector

bolt/vector/tests/utils/VectorMaker.cpp:158–217  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

156} // namespace
157
158ArrayVectorPtr VectorMaker::arrayOfRowVector(
159 const RowTypePtr& rowType,
160 const std::vector<std::vector<variant>>& data) {
161 vector_size_t size = data.size();
162 BufferPtr offsets = AlignedBuffer::allocate<vector_size_t>(size, pool_);
163 BufferPtr sizes = AlignedBuffer::allocate<vector_size_t>(size, pool_);
164
165 auto rawOffsets = offsets->asMutable<vector_size_t>();
166 auto rawSizes = sizes->asMutable<vector_size_t>();
167
168 // Count number of elements.
169 vector_size_t numElements = 0;
170 for (const auto& array : data) {
171 numElements += array.size();
172 }
173
174 // Create the underlying vector.
175 auto rowVector = std::dynamic_pointer_cast<RowVector>(
176 BaseVector::create(rowType, numElements, pool_));
177 for (auto& field : rowVector->children()) {
178 field->resize(numElements);
179 }
180
181 vector_size_t currentIdx = 0;
182 for (const auto& arrayValue : data) {
183 *rawSizes++ = arrayValue.size();
184 *rawOffsets++ = currentIdx;
185
186 for (auto arrayElement : arrayValue) {
187 if (arrayElement.isNull()) {
188 rowVector->setNull(currentIdx, true);
189 } else {
190 for (auto i = 0; i < rowType->size(); i++) {
191 const auto& value = arrayElement.row()[i];
192 if (value.isNull()) {
193 rowVector->childAt(i)->setNull(currentIdx, true);
194 } else {
195 BOLT_DYNAMIC_SCALAR_TYPE_DISPATCH(
196 setNotNullValue,
197 rowType->childAt(i)->kind(),
198 rowVector->childAt(i),
199 currentIdx,
200 value);
201 }
202 }
203 }
204 currentIdx++;
205 }
206 }
207
208 return std::make_shared<ArrayVector>(
209 pool_,
210 ARRAY(rowType),
211 nullptr,
212 size,
213 offsets,
214 sizes,
215 std::move(rowVector),

Callers 3

TEST_FFunction · 0.45
makeArrayOfRowVectorMethod · 0.45
TEST_FFunction · 0.45

Calls 10

ARRAYFunction · 0.85
childAtMethod · 0.80
createFunction · 0.50
sizeMethod · 0.45
childrenMethod · 0.45
resizeMethod · 0.45
isNullMethod · 0.45
setNullMethod · 0.45
rowMethod · 0.45
kindMethod · 0.45

Tested by

no test coverage detected