| 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(); |
no test coverage detected