diff --git a/cpp/src/arrow/flight/test-integration-client.cc b/cpp/src/arrow/flight/test-integration-client.cc index 64f9dc3cd158e..7952668bfdbcd 100644 --- a/cpp/src/arrow/flight/test-integration-client.cc +++ b/cpp/src/arrow/flight/test-integration-client.cc @@ -51,17 +51,11 @@ int main(int argc, char** argv) { // 1. Put the data to the server. std::unique_ptr reader; - std::shared_ptr in_file; std::cout << "Opening JSON file '" << FLAGS_path << "'" << std::endl; + std::shared_ptr in_file; ABORT_NOT_OK(arrow::io::ReadableFile::Open(FLAGS_path, &in_file)); - - int64_t file_size = 0; - ABORT_NOT_OK(in_file->GetSize(&file_size)); - - std::shared_ptr json_buffer; - ABORT_NOT_OK(in_file->Read(file_size, &json_buffer)); - - ABORT_NOT_OK(arrow::ipc::internal::json::JsonReader::Open(json_buffer, &reader)); + ABORT_NOT_OK(arrow::ipc::internal::json::JsonReader::Open(arrow::default_memory_pool(), + in_file, &reader)); std::unique_ptr write_stream; ABORT_NOT_OK(client->DoPut(descr, reader->schema(), &write_stream)); diff --git a/cpp/src/arrow/ipc/json.cc b/cpp/src/arrow/ipc/json.cc index 61c242ca2dbbb..56fe31cbf5691 100644 --- a/cpp/src/arrow/ipc/json.cc +++ b/cpp/src/arrow/ipc/json.cc @@ -22,6 +22,7 @@ #include #include "arrow/buffer.h" +#include "arrow/io/file.h" #include "arrow/ipc/json-internal.h" #include "arrow/memory_pool.h" #include "arrow/record_batch.h" @@ -157,6 +158,18 @@ Status JsonReader::Open(MemoryPool* pool, const std::shared_ptr& data, return (*reader)->impl_->ParseAndReadSchema(); } +Status JsonReader::Open(MemoryPool* pool, + const std::shared_ptr& in_file, + std::unique_ptr* reader) { + int64_t file_size = 0; + RETURN_NOT_OK(in_file->GetSize(&file_size)); + + std::shared_ptr json_buffer; + RETURN_NOT_OK(in_file->Read(file_size, &json_buffer)); + + return Open(pool, json_buffer, reader); +} + std::shared_ptr JsonReader::schema() const { return impl_->schema(); } int JsonReader::num_record_batches() const { return impl_->num_record_batches(); } diff --git a/cpp/src/arrow/ipc/json.h b/cpp/src/arrow/ipc/json.h index 5c00555de8ec0..aeed7070fe96e 100644 --- a/cpp/src/arrow/ipc/json.h +++ b/cpp/src/arrow/ipc/json.h @@ -33,6 +33,10 @@ class MemoryPool; class RecordBatch; class Schema; +namespace io { +class ReadableFile; +} // namespace io + namespace ipc { namespace internal { namespace json { @@ -95,6 +99,15 @@ class ARROW_EXPORT JsonReader { static Status Open(const std::shared_ptr& data, std::unique_ptr* reader); + /// \brief Create a new JSON reader from a file + /// + /// \param[in] pool a MemoryPool to use for buffer allocations + /// \param[in] in_file a ReadableFile containing JSON data + /// \param[out] reader the returned reader object + /// \return Status + static Status Open(MemoryPool* pool, const std::shared_ptr& in_file, + std::unique_ptr* reader); + /// \brief Return the schema read from the JSON std::shared_ptr schema() const;