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

Method append

bolt/serializers/ArrowSerializer.cpp:271–368  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

269 }
270
271 void append(
272 const RowVectorPtr& vector,
273 const folly::Range<const IndexRange*>& ranges,
274 Scratch& scratch) override {
275 vector_size_t total = 0;
276 for (const auto& rg : ranges)
277 total += rg.size;
278 if (!vector || vector->size() == 0 || total == 0)
279 return;
280
281 if (arrowBridgeOptions_.exportToView) {
282 heldVectors_.push_back(vector);
283 }
284
285 ArrowArray cArray{};
286 ArrowSchema cSchema{};
287 ArrowArrayReleaser arrayRel(&cArray);
288 ArrowSchemaReleaser schemaRel(&cSchema);
289
290 VectorPtr useVec = vector;
291 if (ranges.size() == 1) {
292 const auto& rg = ranges[0];
293 const bool identity = (rg.begin == 0 && rg.size == vector->size());
294 if (!identity) {
295 useVec = vector->slice(rg.begin, rg.size);
296 }
297 } else {
298 auto idx = AlignedBuffer::allocate<vector_size_t>(total, vector->pool());
299 auto* raw = idx->asMutable<vector_size_t>();
300 size_t p = 0;
301 for (const auto& rg : ranges) {
302 for (vector_size_t i = 0; i < rg.size; ++i) {
303 raw[p++] = rg.begin + i;
304 }
305 }
306 useVec = BaseVector::wrapInDictionary(nullptr, idx, total, vector);
307 }
308
309 // for lazy
310 SelectivityVector sv(useVec->size(), true);
311 LazyVector::ensureLoadedRows(useVec, sv);
312
313 // Vector → Arrow C-Data
314 exportToArrow(useVec, cArray, vector->pool(), arrowBridgeOptions_);
315 exportToArrow(useVec, cSchema, arrowBridgeOptions_, {});
316
317 // C-Data → Arrow C++
318 auto schRes = ::arrow::ImportSchema(&cSchema);
319 BOLT_USER_CHECK(
320 schRes.ok(), "ImportSchema failed: {}", schRes.status().ToString());
321 auto schema = *schRes;
322
323 auto rbRes = ::arrow::ImportRecordBatch(&cArray, schema);
324 BOLT_USER_CHECK(
325 rbRes.ok(), "ImportRecordBatch failed: {}", rbRes.status().ToString());
326 auto rb = *rbRes;
327
328 schemaRel.disarm();

Callers 2

serializeMethod · 0.45
deserializeMethod · 0.45

Calls 15

wrapInDictionaryFunction · 0.85
SerializeSchemaFunction · 0.85
memcpyFunction · 0.85
statusMethod · 0.80
accountLogicalMethod · 0.80
exportToArrowFunction · 0.50
sizeMethod · 0.45
push_backMethod · 0.45
sliceMethod · 0.45
poolMethod · 0.45
okMethod · 0.45
ToStringMethod · 0.45

Tested by

no test coverage detected