LIST array helper
| 429 | |
| 430 | // LIST<INT64> array helper |
| 431 | inline void createListInt64Array(ArrowArray* array, |
| 432 | const std::vector<std::vector<int64_t>>& lists) { |
| 433 | int32_t total = 0; |
| 434 | for (const auto& lst : lists) { |
| 435 | total += static_cast<int32_t>(lst.size()); |
| 436 | } |
| 437 | |
| 438 | auto* offsets = static_cast<int32_t*>(malloc((lists.size() + 1) * sizeof(int32_t))); |
| 439 | offsets[0] = 0; |
| 440 | for (size_t i = 0; i < lists.size(); ++i) { |
| 441 | offsets[i + 1] = offsets[i] + static_cast<int32_t>(lists[i].size()); |
| 442 | } |
| 443 | |
| 444 | auto* values = static_cast<int64_t*>(malloc(total > 0 ? total * sizeof(int64_t) : 1)); |
| 445 | int32_t pos = 0; |
| 446 | for (const auto& lst : lists) { |
| 447 | for (auto value : lst) { |
| 448 | values[pos++] = value; |
| 449 | } |
| 450 | } |
| 451 | |
| 452 | struct ChildPD { |
| 453 | int64_t* values; |
| 454 | }; |
| 455 | auto* childPrivateData = new ChildPD{values}; |
| 456 | auto* child = static_cast<ArrowArray*>(malloc(sizeof(ArrowArray))); |
| 457 | child->length = total; |
| 458 | child->null_count = 0; |
| 459 | child->offset = 0; |
| 460 | child->n_buffers = 2; |
| 461 | child->n_children = 0; |
| 462 | child->buffers = static_cast<const void**>(malloc(sizeof(void*) * 2)); |
| 463 | child->buffers[0] = nullptr; |
| 464 | child->buffers[1] = values; |
| 465 | child->children = nullptr; |
| 466 | child->dictionary = nullptr; |
| 467 | child->release = [](ArrowArray* a) { |
| 468 | if (a->private_data) { |
| 469 | auto* privateData = static_cast<ChildPD*>(a->private_data); |
| 470 | free(privateData->values); |
| 471 | delete privateData; |
| 472 | } |
| 473 | if (a->buffers) { |
| 474 | free(const_cast<void**>(a->buffers)); |
| 475 | } |
| 476 | a->release = nullptr; |
| 477 | }; |
| 478 | child->private_data = childPrivateData; |
| 479 | |
| 480 | struct ListPD { |
| 481 | int32_t* offsets; |
| 482 | }; |
| 483 | auto* listPrivateData = new ListPD{offsets}; |
| 484 | array->length = static_cast<int64_t>(lists.size()); |
| 485 | array->null_count = 0; |
| 486 | array->offset = 0; |
| 487 | array->n_buffers = 2; |
| 488 | array->n_children = 1; |
no test coverage detected