Repository: apache/arrow
File: cpp/src/parquet/arrow/arrow_reader_writer_test.cc (C++)

Code before:
  ASSERT_OK_AND_ASSIGN(auto record_batch_reader,
                       file_reader->GetRecordBatchReader(row_group_indices));
  std::shared_ptr<::arrow::RecordBatch> record_batch;
  ASSERT_OK(record_batch_reader->ReadNext(&record_batch));
  // No read record batch for empty row groups request.
  ASSERT_FALSE(record_batch);
}

TEST(TestArrowFileReader, RecordBatchReaderEmptyInput) {
  const int num_columns = 1;
  // This is the important part in this test.
  const int num_rows = 0;
  const int num_chunks = 1;

  std::shared_ptr<Table> table;
  ASSERT_NO_FATAL_FAILURE(MakeDoubleTable(num_columns, num_rows, num_chunks, &table));

  const int64_t row_group_size = num_rows;
  std::shared_ptr<Buffer> buffer;
  ASSERT_NO_FATAL_FAILURE(WriteTableToBuffer(table, row_group_size,
                                             default_arrow_writer_properties(), &buffer));

  auto reader = ParquetFileReader::Open(std::make_shared<BufferReader>(buffer));
  std::unique_ptr<FileReader> file_reader;
  ASSERT_OK_AND_ASSIGN(
      file_reader, FileReader::Make(::arrow::default_memory_pool(), std::move(reader)));
  ASSERT_OK_AND_ASSIGN(auto record_batch_reader, file_reader->GetRecordBatchReader());
  std::shared_ptr<::arrow::RecordBatch> record_batch;
  ASSERT_OK(record_batch_reader->ReadNext(&record_batch));
  // No read record batch for empty data.
  ASSERT_FALSE(record_batch);
}

TEST(TestArrowColumnReader, NextBatchZeroBatchSize) {
  const int num_columns = 1;
  const int num_rows = 3;
  const int num_chunks = 1;

  std::shared_ptr<Table> table;
  ASSERT_NO_FATAL_FAILURE(MakeDoubleTable(num_columns, num_rows, num_chunks, &table));

  const int64_t row_group_size = num_rows;
  std::shared_ptr<Buffer> buffer;
  ASSERT_NO_FATAL_FAILURE(WriteTableToBuffer(table, row_group_size,
                                             default_arrow_writer_properties(), &buffer));

  auto reader = ParquetFileReader::Open(std::make_shared<BufferReader>(buffer));
  std::unique_ptr<FileReader> file_reader;
  ASSERT_OK_AND_ASSIGN(
      file_reader, FileReader::Make(::arrow::default_memory_pool(), std::move(reader)));
  std::unique_ptr<arrow::ColumnReader> column_reader;

Review comment (suggestion):
```suggestion
  ASSERT_OK_AND_ASSIGN(
      auto file_reader, FileReader::Make(::arrow::default_memory_pool(), std::move(reader)));
```

Code after:
  // No read record batch for empty row groups request.
  ASSERT_FALSE(record_batch);
}

TEST(TestArrowFileReader, RecordBatchReaderEmptyInput) {
  const int num_columns = 1;
  // This is the important part in this test.
  const int num_rows = 0;
  const int num_chunks = 1;

  std::shared_ptr<Table> table;
  ASSERT_NO_FATAL_FAILURE(MakeDoubleTable(num_columns, num_rows, num_chunks, &table));

  const int64_t row_group_size = num_rows;
  std::shared_ptr<Buffer> buffer;
  ASSERT_NO_FATAL_FAILURE(WriteTableToBuffer(table, row_group_size,
                                             default_arrow_writer_properties(), &buffer));

  auto reader = ParquetFileReader::Open(std::make_shared<BufferReader>(buffer));
  ASSERT_OK_AND_ASSIGN(auto file_reader, FileReader::Make(::arrow::default_memory_pool(),
                                                          std::move(reader)));
  ASSERT_OK_AND_ASSIGN(auto record_batch_reader, file_reader->GetRecordBatchReader());
  std::shared_ptr<::arrow::RecordBatch> record_batch;
  ASSERT_OK(record_batch_reader->ReadNext(&record_batch));
  // No read record batch for empty data.
  ASSERT_FALSE(record_batch);
}

TEST(TestArrowColumnReader, NextBatchZeroBatchSize) {
  const int num_columns = 1;
  const int num_rows = 3;
  const int num_chunks = 1;

  std::shared_ptr<Table> table;
  ASSERT_NO_FATAL_FAILURE(MakeDoubleTable(num_columns, num_rows, num_chunks, &table));

  const int64_t row_group_size = num_rows;
  std::shared_ptr<Buffer> buffer;
  ASSERT_NO_FATAL_FAILURE(WriteTableToBuffer(table, row_group_size,
                                             default_arrow_writer_properties(), &buffer));

  auto reader = ParquetFileReader::Open(std::make_shared<BufferReader>(buffer));
  ASSERT_OK_AND_ASSIGN(auto file_reader, FileReader::Make(::arrow::default_memory_pool(),
                                                          std::move(reader)));
  std::unique_ptr<arrow::ColumnReader> column_reader;
  ASSERT_OK(file_reader->GetColumn(0, &column_reader));
  std::shared_ptr<ChunkedArray> chunked_array;
  // This is the important part in this test.
  ASSERT_OK(column_reader->NextBatch(0, &chunked_array));
  ASSERT_EQ(0, chunked_array->length());
}