| 337 | } |
| 338 | |
| 339 | TEST(TestAdapterRead, ReadIntAndStringFileMultipleStripes) { |
| 340 | MemoryOutputStream mem_stream(kDefaultMemStreamSize); |
| 341 | std::unique_ptr<liborc::Type> type( |
| 342 | liborc::Type::buildTypeFromString("struct<col1:int,col2:string>")); |
| 343 | |
| 344 | constexpr uint64_t stripe_size = 1024; // 1K |
| 345 | constexpr uint64_t stripe_count = 10; |
| 346 | constexpr uint64_t stripe_row_count = 16384; |
| 347 | constexpr uint64_t reader_batch_size = 1024; |
| 348 | |
| 349 | auto writer = CreateWriter(stripe_size, *type, &mem_stream); |
| 350 | auto batch = writer->createRowBatch(stripe_row_count); |
| 351 | auto struct_batch = internal::checked_cast<liborc::StructVectorBatch*>(batch.get()); |
| 352 | auto long_batch = |
| 353 | internal::checked_cast<liborc::LongVectorBatch*>(struct_batch->fields[0]); |
| 354 | auto str_batch = |
| 355 | internal::checked_cast<liborc::StringVectorBatch*>(struct_batch->fields[1]); |
| 356 | int64_t accumulated = 0; |
| 357 | |
| 358 | for (uint64_t j = 0; j < stripe_count; ++j) { |
| 359 | std::string data_buffer(stripe_row_count * 5, '\0'); |
| 360 | uint64_t offset = 0; |
| 361 | for (uint64_t i = 0; i < stripe_row_count; ++i) { |
| 362 | std::string str_data = std::to_string(accumulated % stripe_row_count); |
| 363 | long_batch->data[i] = static_cast<int64_t>(accumulated % stripe_row_count); |
| 364 | str_batch->data[i] = &data_buffer[offset]; |
| 365 | str_batch->length[i] = static_cast<int64_t>(str_data.size()); |
| 366 | memcpy(&data_buffer[offset], str_data.c_str(), str_data.size()); |
| 367 | accumulated++; |
| 368 | offset += str_data.size(); |
| 369 | } |
| 370 | struct_batch->numElements = stripe_row_count; |
| 371 | long_batch->numElements = stripe_row_count; |
| 372 | str_batch->numElements = stripe_row_count; |
| 373 | |
| 374 | writer->add(*batch); |
| 375 | } |
| 376 | |
| 377 | writer->close(); |
| 378 | |
| 379 | std::shared_ptr<io::RandomAccessFile> in_stream(new io::BufferReader( |
| 380 | std::make_shared<Buffer>(reinterpret_cast<const uint8_t*>(mem_stream.getData()), |
| 381 | static_cast<int64_t>(mem_stream.getLength())))); |
| 382 | |
| 383 | ASSERT_OK_AND_ASSIGN( |
| 384 | auto reader, adapters::orc::ORCFileReader::Open(in_stream, default_memory_pool())); |
| 385 | |
| 386 | EXPECT_OK_AND_ASSIGN(auto metadata, reader->ReadMetadata()); |
| 387 | auto expected_metadata = std::const_pointer_cast<const KeyValueMetadata>( |
| 388 | key_value_metadata(std::vector<std::string>(), std::vector<std::string>())); |
| 389 | ASSERT_TRUE(metadata->Equals(*expected_metadata)); |
| 390 | ASSERT_EQ(stripe_row_count * stripe_count, reader->NumberOfRows()); |
| 391 | ASSERT_EQ(stripe_count, reader->NumberOfStripes()); |
| 392 | ASSERT_EQ(static_cast<int64_t>(stripe_row_count), |
| 393 | reader->GetStripeInformation(0).num_rows); |
| 394 | ASSERT_EQ(static_cast<int64_t>(reader->NumberOfRows() - stripe_row_count), |
| 395 | reader->GetStripeInformation(stripe_count - 1).first_row_id); |
| 396 | accumulated = 0; |
nothing calls this directly
no test coverage detected