Repository: apache/arrow
File: cpp/src/arrow/filesystem/s3fs_benchmark.cc (C++)

Code before:
/// Read a Parquet file from S3.
static void ParquetRead(benchmark::State& st, S3FileSystem* fs, const std::string& path,
                        std::vector<int> column_indices, bool pre_buffer,
                        std::string read_strategy) {
  int64_t total_bytes = 0;
  int total_items = 0;

  parquet::ArrowReaderProperties properties;
  properties.set_use_threads(true);
  properties.set_pre_buffer(pre_buffer);
  parquet::ReaderProperties parquet_properties = parquet::default_reader_properties();

  for (auto _ : st) {
    std::shared_ptr<io::RandomAccessFile> file;
    int64_t size = 0;
    ASSERT_OK_AND_ASSIGN(file, fs->OpenInputFile(path));
    ASSERT_OK_AND_ASSIGN(size, file->GetSize());

    std::unique_ptr<parquet::arrow::FileReader> reader;
    parquet::arrow::FileReaderBuilder builder;
    ASSERT_OK(builder.Open(file, parquet_properties));
    ASSERT_OK(builder.properties(properties)->Build(&reader));

    if (read_strategy == "ReadTable") {
      auto table_result = reader->ReadTable(column_indices);
      ASSERT_OK(table_result.status());
    } else {
      ASSERT_OK_AND_ASSIGN(auto rb_reader, reader->GetRecordBatchReader(
                                               std::vector<int>{0}, column_indices));
      ASSERT_OK(rb_reader->ToTable());
    }

    // TODO: actually measure table memory usage
    total_bytes += size;
    total_items += 1;
  }
  st.SetBytesProcessed(total_bytes);
  st.SetItemsProcessed(total_items);
}

/// Helper function used in the macros below to template benchmarks.
static void ParquetReadAll(benchmark::State& st, S3FileSystem* fs,
                           const std::string& bucket, int64_t file_rows,
                           int64_t file_cols, bool pre_buffer,
                           std::string read_strategy) {
  std::vector<int> column_indices(file_cols);
  std::iota(column_indices.begin(), column_indices.end(), 0);
  std::stringstream ss;
  ss << bucket << "/pq_c" << file_cols << "_r" << file_rows << "k";
  ParquetRead(st, fs, ss.str(), column_indices, false, read_strategy);
}

Review comment (suggestion):
```suggestion
      ASSERT_OK_AND_ASSIGN(auto table, reader->ReadTable(column_indices));
```

If this reports the "variable is not used" warning, we can use `ASSERT_OK(reader->ReadTable(column_indices).status());`

Code after:
/// Read a Parquet file from S3.
static void ParquetRead(benchmark::State& st, S3FileSystem* fs, const std::string& path,
                        std::vector<int> column_indices, bool pre_buffer,
                        std::string read_strategy) {
  int64_t total_bytes = 0;
  int total_items = 0;

  parquet::ArrowReaderProperties properties;
  properties.set_use_threads(true);
  properties.set_pre_buffer(pre_buffer);
  parquet::ReaderProperties parquet_properties = parquet::default_reader_properties();

  for (auto _ : st) {
    std::shared_ptr<io::RandomAccessFile> file;
    int64_t size = 0;
    ASSERT_OK_AND_ASSIGN(file, fs->OpenInputFile(path));
    ASSERT_OK_AND_ASSIGN(size, file->GetSize());

    std::unique_ptr<parquet::arrow::FileReader> reader;
    parquet::arrow::FileReaderBuilder builder;
    ASSERT_OK(builder.Open(file, parquet_properties));
    ASSERT_OK(builder.properties(properties)->Build(&reader));

    if (read_strategy == "ReadTable") {
      ASSERT_OK_AND_ASSIGN(auto table, reader->ReadTable(column_indices));
    } else {
      ASSERT_OK_AND_ASSIGN(auto rb_reader, reader->GetRecordBatchReader(
                                               std::vector<int>{0}, column_indices));
      ASSERT_OK(rb_reader->ToTable());
    }

    // TODO: actually measure table memory usage
    total_bytes += size;
    total_items += 1;
  }
  st.SetBytesProcessed(total_bytes);
  st.SetItemsProcessed(total_items);
}

/// Helper function used in the macros below to template benchmarks.
static void ParquetReadAll(benchmark::State& st, S3FileSystem* fs,
                           const std::string& bucket, int64_t file_rows,
                           int64_t file_cols, bool pre_buffer,
                           std::string read_strategy) {
  std::vector<int> column_indices(file_cols);
  std::iota(column_indices.begin(), column_indices.end(), 0);
  std::stringstream ss;
  ss << bucket << "/pq_c" << file_cols << "_r" << file_rows << "k";
  ParquetRead(st, fs, ss.str(), column_indices, false, read_strategy);
}