21 #include <boost/filesystem.hpp>
22 #include "rapidjson/document.h"
32 namespace foreign_storage {
57 virtual size_t read(
void* buffer,
size_t max_size) = 0;
73 virtual size_t readRegion(
void* buffer,
size_t offset,
size_t size) = 0;
97 throw std::runtime_error{
"APPEND mode not yet supported for this table."};
108 virtual void serialize(rapidjson::Value& value,
109 rapidjson::Document::AllocatorType& allocator)
const = 0;
159 const rapidjson::Value& value);
166 size_t read(
void* buffer,
size_t max_size)
override {
167 size_t bytes_read = fread(buffer, 1, max_size,
file_);
176 size_t readRegion(
void* buffer,
size_t offset,
size_t size)
override {
179 throw std::runtime_error{
"An error occurred when attempting to read offset " +
181 "\". " + strerror(errno)};
183 return fread(buffer, 1, size,
file_);
198 rapidjson::Document::AllocatorType& allocator)
const override;
275 const rapidjson::Value& value);
276 size_t read(
void* buffer,
size_t max_size)
override;
278 size_t readRegion(
void* buffer,
size_t offset,
size_t size)
override;
286 rapidjson::Document::AllocatorType& allocator)
const override;
316 size_t readInternal(
void* buffer,
size_t read_size,
size_t buffer_size);
352 const rapidjson::Value& value);
358 size_t read(
void* buffer,
size_t max_size)
override;
360 size_t readRegion(
void* buffer,
size_t offset,
size_t size)
override;
365 rapidjson::Document::AllocatorType& allocator)
const override;
380 std::vector<std::unique_ptr<FileReader>>
files_;
401 const std::optional<size_t>& max_file_count);
405 const rapidjson::Value& value);
virtual bool isScanFinished() const =0
void checkForMoreRows(size_t file_offset, const shared::FilePathOptions &options, const ForeignServer *server_options, const UserMapping *user_mapping) override
std::vector< std::string > sourcenames_
void skipHeader() override
virtual std::string getFirstLine() const =0
virtual size_t read(void *buffer, size_t max_size)=0
std::vector< int > archive_entry_index_
std::vector< std::string > getAllFilePaths(const shared::FilePathOptions &file_path_options) const override
int getCurrentEntryIndex() const
bool isScanFinished() const override
std::string getFirstLine() const override
bool isEndOfLastFile() override
virtual void skipHeader()=0
std::vector< size_t > cumulative_sizes_
CompressedFileReader(const std::string &file_path, const import_export::CopyParams ©_params)
virtual std::vector< std::string > getAllFilePaths(const shared::FilePathOptions &file_path_options) const =0
virtual size_t readRegion(void *buffer, size_t offset, size_t size)=0
FirstLineByFilePath getFirstLineForEachFile() const override
size_t readRegion(void *buffer, size_t offset, size_t size) override
size_t readRegion(void *buffer, size_t offset, size_t size) override
void checkForMoreRows(size_t file_offset, const shared::FilePathOptions &options, const ForeignServer *server_options, const UserMapping *user_mapping) override
bool is_end_of_last_file_
SingleTextFileReader(const std::string &file_path, const import_export::CopyParams ©_params)
bool isRemainingSizeKnown() override
FileReader(const std::string &file_path, const import_export::CopyParams ©_params)
size_t readInternal(void *buffer, size_t read_size, size_t buffer_size)
std::map< std::string, std::string > FirstLineByFilePath
virtual bool isEndOfLastFile()=0
virtual size_t getRemainingSize()=0
MultiFileReader(const std::string &file_path, const import_export::CopyParams ©_params)
virtual ~FileReader()=default
void insertFile(std::string location)
import_export::CopyParams copy_params_
virtual void checkForMoreRows(size_t file_offset, const shared::FilePathOptions &options, const ForeignServer *server_options=nullptr, const UserMapping *user_mapping=nullptr)
void serialize(rapidjson::Value &value, rapidjson::Document::AllocatorType &allocator) const override
bool isRemainingSizeKnown() override
void serialize(rapidjson::Value &value, rapidjson::Document::AllocatorType &allocator) const override
size_t getRemainingSize() override
bool isScanFinished() const override
void consumeDataFromCurrentEntry(size_t size, char *dest_buffer=nullptr)
size_t getRemainingSize() override
bool isRemainingSizeKnown() override
SingleTextFileReader & operator=(const SingleTextFileReader &)=delete
FirstLineByFilePath getFirstLineForEachFile() const override
ArchiveWrapper(const std::string &file_path)
bool currentEntryFinished() const
LocalMultiFileReader(const std::string &file_path, const import_export::CopyParams ©_params, const shared::FilePathOptions &options, const std::optional< size_t > &max_file_count)
size_t readRegion(void *buffer, size_t offset, size_t size) override
void checkForMoreRows(size_t file_offset, const shared::FilePathOptions &options, const ForeignServer *server_options, const UserMapping *user_mapping) override
void skipBytes(size_t n_bytes)
void consumeFirstLine(std::optional< std::string > &dest_str)
virtual void serialize(rapidjson::Value &value, rapidjson::Document::AllocatorType &allocator) const =0
std::unique_ptr< Archive > arch_
bool isScanFinished() const override
const void * current_block_
static constexpr size_t DEFAULT_HEADER_READ_SIZE
SingleFileReader(const std::string &file_path, const import_export::CopyParams ©_params)
size_t read(void *buffer, size_t max_size) override
void skipToEntry(int entry_number)
~SingleTextFileReader() override
size_t currentEntryDataAvailable() const
virtual bool isRemainingSizeKnown()=0
std::string getCurrentFilePath() const override
std::string getFirstLine() const override
std::string getCurrentFilePath() const override
size_t getRemainingSize() override
void skipHeader() override
virtual FirstLineByFilePath getFirstLineForEachFile() const =0
std::vector< std::string > file_locations_
void serialize(rapidjson::Value &value, rapidjson::Document::AllocatorType &allocator) const override
size_t read(void *buffer, size_t max_size) override
virtual std::set< std::string > checkForRolledOffFiles(const shared::FilePathOptions &file_path_options)
bool isEndOfLastFile() override
std::vector< std::unique_ptr< FileReader > > files_
std::vector< size_t > cumulative_sizes_
size_t read(void *buffer, size_t max_size) override
virtual std::string getCurrentFilePath() const =0
size_t block_chars_remaining_
~SingleFileReader() override=default