| 320 | } |
| 321 | |
| 322 | Status RowTableImpl::AppendSelectionFrom(const RowTableImpl& from, |
| 323 | uint32_t num_rows_to_append, |
| 324 | const uint16_t* source_row_ids) { |
| 325 | DCHECK(metadata_.is_compatible(from.metadata())); |
| 326 | |
| 327 | RETURN_NOT_OK(ResizeFixedLengthBuffers(num_rows_to_append)); |
| 328 | |
| 329 | if (!metadata_.is_fixed_length) { |
| 330 | // Varying-length rows |
| 331 | auto from_offsets = reinterpret_cast<const offset_type*>(from.offsets_->data()); |
| 332 | auto to_offsets = reinterpret_cast<offset_type*>(offsets_->mutable_data()); |
| 333 | offset_type total_length = to_offsets[num_rows_]; |
| 334 | int64_t total_length_to_append = 0; |
| 335 | for (uint32_t i = 0; i < num_rows_to_append; ++i) { |
| 336 | uint16_t row_id = source_row_ids ? source_row_ids[i] : i; |
| 337 | int64_t length = from_offsets[row_id + 1] - from_offsets[row_id]; |
| 338 | total_length_to_append += length; |
| 339 | to_offsets[num_rows_ + i + 1] = total_length + total_length_to_append; |
| 340 | } |
| 341 | |
| 342 | RETURN_NOT_OK(ResizeOptionalVaryingLengthBuffer(total_length_to_append)); |
| 343 | |
| 344 | const uint8_t* src = from.rows_->data(); |
| 345 | uint8_t* dst = rows_->mutable_data() + total_length; |
| 346 | for (uint32_t i = 0; i < num_rows_to_append; ++i) { |
| 347 | uint16_t row_id = source_row_ids ? source_row_ids[i] : i; |
| 348 | int64_t length = from_offsets[row_id + 1] - from_offsets[row_id]; |
| 349 | DCHECK_LE(length, std::numeric_limits<uint32_t>::max()); |
| 350 | auto src64 = reinterpret_cast<const uint64_t*>(src + from_offsets[row_id]); |
| 351 | auto dst64 = reinterpret_cast<uint64_t*>(dst); |
| 352 | for (uint32_t j = 0; j < bit_util::CeilDiv(length, 8); ++j) { |
| 353 | dst64[j] = src64[j]; |
| 354 | } |
| 355 | dst += length; |
| 356 | } |
| 357 | } else { |
| 358 | // Fixed-length rows |
| 359 | const uint8_t* src = from.rows_->data(); |
| 360 | uint8_t* dst = rows_->mutable_data() + num_rows_ * metadata_.fixed_length; |
| 361 | for (uint32_t i = 0; i < num_rows_to_append; ++i) { |
| 362 | uint16_t row_id = source_row_ids ? source_row_ids[i] : i; |
| 363 | uint32_t length = metadata_.fixed_length; |
| 364 | auto src64 = reinterpret_cast<const uint64_t*>(src + length * row_id); |
| 365 | auto dst64 = reinterpret_cast<uint64_t*>(dst); |
| 366 | for (uint32_t j = 0; j < bit_util::CeilDiv(length, 8); ++j) { |
| 367 | dst64[j] = src64[j]; |
| 368 | } |
| 369 | dst += length; |
| 370 | } |
| 371 | } |
| 372 | |
| 373 | // Null masks |
| 374 | uint32_t byte_length = metadata_.null_masks_bytes_per_row; |
| 375 | uint64_t dst_byte_offset = num_rows_ * byte_length; |
| 376 | const uint8_t* src_base = from.null_masks_->data(); |
| 377 | uint8_t* dst_base = null_masks_->mutable_data(); |
| 378 | for (uint32_t i = 0; i < num_rows_to_append; ++i) { |
| 379 | uint32_t row_id = source_row_ids ? source_row_ids[i] : i; |