| 2555 | } |
| 2556 | |
| 2557 | void TestGetRecordBatchReader( |
| 2558 | ArrowReaderProperties properties = default_arrow_reader_properties()) { |
| 2559 | const int num_columns = 20; |
| 2560 | const int num_rows = 1000; |
| 2561 | const int batch_size = 100; |
| 2562 | |
| 2563 | std::shared_ptr<Table> table; |
| 2564 | ASSERT_NO_FATAL_FAILURE(MakeDoubleTable(num_columns, num_rows, 1, &table)); |
| 2565 | |
| 2566 | std::shared_ptr<Buffer> buffer; |
| 2567 | ASSERT_NO_FATAL_FAILURE(WriteTableToBuffer(table, num_rows / 2, |
| 2568 | default_arrow_writer_properties(), &buffer)); |
| 2569 | |
| 2570 | properties.set_batch_size(batch_size); |
| 2571 | |
| 2572 | std::unique_ptr<FileReader> reader; |
| 2573 | FileReaderBuilder builder; |
| 2574 | ASSERT_OK(builder.Open(std::make_shared<BufferReader>(buffer))); |
| 2575 | ASSERT_OK(builder.properties(properties)->Build(&reader)); |
| 2576 | |
| 2577 | // Read the whole file, one batch at a time. |
| 2578 | ASSERT_OK_AND_ASSIGN(auto rb_reader, reader->GetRecordBatchReader({0, 1})); |
| 2579 | std::shared_ptr<::arrow::RecordBatch> actual_batch, expected_batch; |
| 2580 | ::arrow::TableBatchReader table_reader(*table); |
| 2581 | table_reader.set_chunksize(batch_size); |
| 2582 | |
| 2583 | for (int i = 0; i < 10; ++i) { |
| 2584 | ASSERT_OK(rb_reader->ReadNext(&actual_batch)); |
| 2585 | ASSERT_OK(table_reader.ReadNext(&expected_batch)); |
| 2586 | ASSERT_NO_FATAL_FAILURE(::arrow::AssertBatchesEqual(*expected_batch, *actual_batch)); |
| 2587 | } |
| 2588 | |
| 2589 | ASSERT_OK(rb_reader->ReadNext(&actual_batch)); |
| 2590 | ASSERT_EQ(nullptr, actual_batch); |
| 2591 | |
| 2592 | // ARROW-6005: Read just the second row group |
| 2593 | ASSERT_OK_AND_ASSIGN(rb_reader, reader->GetRecordBatchReader({1})); |
| 2594 | std::shared_ptr<Table> second_rowgroup = table->Slice(num_rows / 2); |
| 2595 | ::arrow::TableBatchReader second_table_reader(*second_rowgroup); |
| 2596 | second_table_reader.set_chunksize(batch_size); |
| 2597 | |
| 2598 | for (int i = 0; i < 5; ++i) { |
| 2599 | ASSERT_OK(rb_reader->ReadNext(&actual_batch)); |
| 2600 | ASSERT_OK(second_table_reader.ReadNext(&expected_batch)); |
| 2601 | ASSERT_NO_FATAL_FAILURE(::arrow::AssertBatchesEqual(*expected_batch, *actual_batch)); |
| 2602 | } |
| 2603 | |
| 2604 | ASSERT_OK(rb_reader->ReadNext(&actual_batch)); |
| 2605 | ASSERT_EQ(nullptr, actual_batch); |
| 2606 | } |
| 2607 | |
| 2608 | TEST(TestArrowReadWrite, GetRecordBatchReader) { TestGetRecordBatchReader(); } |
| 2609 |
no test coverage detected