| 368 | |
| 369 | template <typename VectorType> |
| 370 | Status fill_doc_sparse_vector(const arrow::StructArray *typed_arr, |
| 371 | const std::string &field_name, |
| 372 | DocPtrList::iterator doc_it) { |
| 373 | auto *indices = (const arrow::BinaryArray *)typed_arr->field(0).get(); |
| 374 | auto *values = (const arrow::BinaryArray *)typed_arr->field(1).get(); |
| 375 | bool has_null = typed_arr->null_count() > 0; |
| 376 | for (int64_t i = 0; i < typed_arr->length(); ++i, ++doc_it) { |
| 377 | if (has_null && typed_arr->IsNull(i)) { |
| 378 | continue; |
| 379 | } |
| 380 | auto indice_data = indices->GetView(i); |
| 381 | auto value_data = values->GetView(i); |
| 382 | uint32_t count = indice_data.size() / sizeof(uint32_t); |
| 383 | if (count != value_data.size() / sizeof(VectorType)) { |
| 384 | return Status::InvalidArgument( |
| 385 | "Sparse vector indices and values size mismatch [", field_name, |
| 386 | "]: indices count=", count, |
| 387 | " vs values count=", value_data.size() / sizeof(VectorType)); |
| 388 | } |
| 389 | (*doc_it)->set( |
| 390 | field_name, |
| 391 | std::make_pair(to_vector<uint32_t>(indice_data.data(), count), |
| 392 | to_vector<VectorType>(value_data.data(), count))); |
| 393 | } |
| 394 | return Status::OK(); |
| 395 | } |
| 396 | |
| 397 | template <typename VectorType> |
| 398 | Status fill_doc_vector(const arrow::BinaryArray *typed_arr, |