| 1417 | static constexpr int TYPE = Type::type_num; |
| 1418 | |
| 1419 | void CheckRoundtrip() override { |
| 1420 | auto encoder = MakeTypedEncoder<Type>(Encoding::BYTE_STREAM_SPLIT, |
| 1421 | /*use_dictionary=*/false, descr_.get()); |
| 1422 | auto decoder = MakeTypedDecoder<Type>(Encoding::BYTE_STREAM_SPLIT, descr_.get()); |
| 1423 | encoder->Put(draws_, num_values_); |
| 1424 | encode_buffer_ = encoder->FlushValues(); |
| 1425 | |
| 1426 | { |
| 1427 | decoder->SetData(num_values_, encode_buffer_->data(), |
| 1428 | static_cast<int>(encode_buffer_->size())); |
| 1429 | int values_decoded = decoder->Decode(decode_buf_, num_values_); |
| 1430 | ASSERT_EQ(num_values_, values_decoded); |
| 1431 | ASSERT_NO_FATAL_FAILURE(VerifyResults<c_type>(decode_buf_, draws_, num_values_)); |
| 1432 | } |
| 1433 | |
| 1434 | { |
| 1435 | // Try again but with a small step. |
| 1436 | decoder->SetData(num_values_, encode_buffer_->data(), |
| 1437 | static_cast<int>(encode_buffer_->size())); |
| 1438 | int step = 131; |
| 1439 | int remaining = num_values_; |
| 1440 | for (int i = 0; i < num_values_; i += step) { |
| 1441 | int num_decoded = decoder->Decode(decode_buf_, step); |
| 1442 | ASSERT_EQ(num_decoded, std::min(step, remaining)); |
| 1443 | ASSERT_NO_FATAL_FAILURE( |
| 1444 | VerifyResults<c_type>(decode_buf_, &draws_[i], num_decoded)); |
| 1445 | remaining -= num_decoded; |
| 1446 | } |
| 1447 | } |
| 1448 | |
| 1449 | { |
| 1450 | std::vector<uint8_t> valid_bits(::arrow::bit_util::BytesForBits(num_values_), 0); |
| 1451 | std::vector<c_type> expected_filtered_output; |
| 1452 | const int every_nth = 5; |
| 1453 | expected_filtered_output.reserve((num_values_ + every_nth - 1) / every_nth); |
| 1454 | ::arrow::internal::BitmapWriter writer{valid_bits.data(), 0, num_values_}; |
| 1455 | // Set every fifth bit. |
| 1456 | for (int i = 0; i < num_values_; ++i) { |
| 1457 | if (i % every_nth == 0) { |
| 1458 | writer.Set(); |
| 1459 | expected_filtered_output.push_back(draws_[i]); |
| 1460 | } |
| 1461 | writer.Next(); |
| 1462 | } |
| 1463 | writer.Finish(); |
| 1464 | const int expected_size = static_cast<int>(expected_filtered_output.size()); |
| 1465 | ASSERT_NO_THROW(encoder->PutSpaced(draws_, num_values_, valid_bits.data(), 0)); |
| 1466 | encode_buffer_ = encoder->FlushValues(); |
| 1467 | |
| 1468 | decoder->SetData(expected_size, encode_buffer_->data(), |
| 1469 | static_cast<int>(encode_buffer_->size())); |
| 1470 | int values_decoded = decoder->Decode(decode_buf_, num_values_); |
| 1471 | ASSERT_EQ(expected_size, values_decoded); |
| 1472 | ASSERT_NO_FATAL_FAILURE(VerifyResults<c_type>( |
| 1473 | decode_buf_, expected_filtered_output.data(), expected_size)); |
| 1474 | } |
| 1475 | } |
| 1476 |
nothing calls this directly
no test coverage detected