| 398 | static constexpr int TYPE = Type::type_num; |
| 399 | |
| 400 | void CheckRoundtrip() { |
| 401 | std::vector<uint8_t> valid_bits(::arrow::bit_util::BytesForBits(num_values_) + 1, |
| 402 | 255); |
| 403 | |
| 404 | auto base_encoder = MakeEncoder(Type::type_num, Encoding::PLAIN, true, descr_.get()); |
| 405 | auto encoder = |
| 406 | dynamic_cast<typename EncodingTraits<Type>::Encoder*>(base_encoder.get()); |
| 407 | auto dict_traits = dynamic_cast<DictEncoder<Type>*>(base_encoder.get()); |
| 408 | |
| 409 | ASSERT_NO_THROW(encoder->Put(draws_, num_values_)); |
| 410 | dict_buffer_ = |
| 411 | AllocateBuffer(default_memory_pool(), dict_traits->dict_encoded_size()); |
| 412 | dict_traits->WriteDict(dict_buffer_->mutable_data()); |
| 413 | std::shared_ptr<Buffer> indices = encoder->FlushValues(); |
| 414 | if constexpr (std::is_same_v<Type, ByteArrayType>) { |
| 415 | ASSERT_EQ(encoder->ReportUnencodedDataBytes(), |
| 416 | this->unencoded_byte_array_data_bytes_); |
| 417 | } |
| 418 | |
| 419 | auto base_spaced_encoder = |
| 420 | MakeEncoder(Type::type_num, Encoding::PLAIN, true, descr_.get()); |
| 421 | auto spaced_encoder = |
| 422 | dynamic_cast<typename EncodingTraits<Type>::Encoder*>(base_spaced_encoder.get()); |
| 423 | |
| 424 | // PutSpaced should lead to the same results |
| 425 | // This also checks the PutSpaced implementation for valid_bits=nullptr |
| 426 | ASSERT_NO_THROW(spaced_encoder->PutSpaced(draws_, num_values_, nullptr, 0)); |
| 427 | std::shared_ptr<Buffer> indices_from_spaced = spaced_encoder->FlushValues(); |
| 428 | ASSERT_TRUE(indices_from_spaced->Equals(*indices)); |
| 429 | |
| 430 | auto dict_decoder = MakeTypedDecoder<Type>(Encoding::PLAIN, descr_.get()); |
| 431 | dict_decoder->SetData(dict_traits->num_entries(), dict_buffer_->data(), |
| 432 | static_cast<int>(dict_buffer_->size())); |
| 433 | |
| 434 | auto decoder = MakeDictDecoder<Type>(descr_.get()); |
| 435 | decoder->SetDict(dict_decoder.get()); |
| 436 | |
| 437 | decoder->SetData(num_values_, indices->data(), static_cast<int>(indices->size())); |
| 438 | int values_decoded = decoder->Decode(decode_buf_, num_values_); |
| 439 | ASSERT_EQ(num_values_, values_decoded); |
| 440 | |
| 441 | // TODO(wesm): The DictionaryDecoder must stay alive because the decoded |
| 442 | // values' data is owned by a buffer inside the DictionaryEncoder. We |
| 443 | // should revisit when data lifetime is reviewed more generally. |
| 444 | ASSERT_NO_FATAL_FAILURE(VerifyResults<c_type>(decode_buf_, draws_, num_values_)); |
| 445 | |
| 446 | // Also test spaced decoding |
| 447 | decoder->SetData(num_values_, indices->data(), static_cast<int>(indices->size())); |
| 448 | // Also tests DecodeSpaced handling for valid_bits=nullptr |
| 449 | values_decoded = decoder->DecodeSpaced(decode_buf_, num_values_, 0, nullptr, 0); |
| 450 | ASSERT_EQ(num_values_, values_decoded); |
| 451 | ASSERT_NO_FATAL_FAILURE(VerifyResults<c_type>(decode_buf_, draws_, num_values_)); |
| 452 | } |
| 453 | |
| 454 | protected: |
| 455 | USING_BASE_MEMBERS(); |
nothing calls this directly
no test coverage detected