Skip to content

Commit

Permalink
Refactor FileReader::Make methods to align with Result-based API
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohammad Linjawi authored and Mohammad Linjawi committed Dec 2, 2024
1 parent b54b107 commit 4687dbe
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 15 deletions.
20 changes: 16 additions & 4 deletions cpp/src/parquet/arrow/reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1315,20 +1315,32 @@ Status FileReader::GetRecordBatchReader(const std::vector<int>& row_group_indice
return Status::OK();
}

Result<std::unique_ptr<FileReader>> Make(::arrow::MemoryPool* pool,
std::unique_ptr<ParquetFileReader> reader,
Status FileReader::Make(MemoryPool* pool, std::unique_ptr<ParquetFileReader> reader,
const ArrowReaderProperties& properties,
std::unique_ptr<FileReader>* out) {
*out = std::make_unique<FileReaderImpl>(pool, std::move(reader), properties);
return static_cast<FileReaderImpl*>(out->get())->Init();
}

Result<std::unique_ptr<FileReader>> Make(::arrow::MemoryPool* pool,
std::unique_ptr<ParquetFileReader> reader,
Result<std::unique_ptr<FileReader>> FileReader::Make(
MemoryPool* pool, std::unique_ptr<ParquetFileReader> reader,
const ArrowReaderProperties& properties) {
auto file_reader =
std::make_unique<FileReaderImpl>(pool, std::move(reader), properties);
RETURN_NOT_OK(file_reader->Init());
return file_reader;
}

Status FileReader::Make(MemoryPool* pool, std::unique_ptr<ParquetFileReader> reader,
std::unique_ptr<FileReader>* out) {
return Make(pool, std::move(reader), default_arrow_reader_properties(), out);
}

Result<std::unique_ptr<FileReader>> FileReader::Make(
MemoryPool* pool, std::unique_ptr<ParquetFileReader> reader) {
return Make(pool, std::move(reader), default_arrow_reader_properties());
}

FileReaderBuilder::FileReaderBuilder()
: pool_(::arrow::default_memory_pool()),
properties_(default_arrow_reader_properties()) {}
Expand Down
23 changes: 12 additions & 11 deletions cpp/src/parquet/arrow/reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,27 +118,28 @@ class PARQUET_EXPORT FileReader {
// Factory function to create a FileReader from a ParquetFileReader and properties.
// \deprecated Deprecated in 19.0.0. Use arrow::Result version instead.
ARROW_DEPRECATED("Deprecated in 19.0.0. Use arrow::Result version instead.")
static ::arrow::Status Make(
::arrow::MemoryPool* pool, std::unique_ptr<ParquetFileReader> reader,
const ArrowReaderProperties& properties, std::unique_ptr<FileReader>* out);

/// Factory function to create a FileReader from a ParquetFileReader and properties
static ::arrow::Status Make(::arrow::MemoryPool* pool,
std::unique_ptr<ParquetFileReader> reader,
const ArrowReaderProperties& properties,
std::unique_ptr<FileReader>* out);

// Factory function to create a FileReader from a ParquetFileReader and properties
// Returns an arrow::Result containing a unique pointer to the FileReader.
static ::arrow::Result<std::unique_ptr<FileReader>> Make(
::arrow::MemoryPool* pool, std::unique_ptr<ParquetFileReader> reader,
const ArrowReaderProperties& properties, std::unique_ptr<FileReader>* out);
const ArrowReaderProperties& properties);

// Factory function to create a FileReader from a ParquetFileReader.
// \deprecated Deprecated in 19.0.0. Use arrow::Result version instead.
ARROW_DEPRECATED("Deprecated in 19.0.0. Use arrow::Result version instead.")
static ::arrow::Result<std::unique_ptr<FileReader>> Make(
::arrow::MemoryPool* pool, std::unique_ptr<ParquetFileReader> reader,
std::unique_ptr<FileReader>* out);
static ::arrow::Status Make(::arrow::MemoryPool* pool,
std::unique_ptr<ParquetFileReader> reader,
std::unique_ptr<FileReader>* out);

// Factory function to create a FileReader from a ParquetFileReader.
// Returns an arrow::Result containing a unique pointer to the FileReader.
static ::arrow::Result<std::unique_ptr<FileReader>> Make(
::arrow::MemoryPool* pool, std::unique_ptr<ParquetFileReader> reader,
std::unique_ptr<FileReader>* out);
::arrow::MemoryPool* pool, std::unique_ptr<ParquetFileReader> reader);

// Since the distribution of columns amongst a Parquet file's row groups may
// be uneven (the number of values in each column chunk can be different), we
Expand Down

0 comments on commit 4687dbe

Please sign in to comment.