Autonomy Software C++ 24.5.1
Welcome to the Autonomy Software repository of the Mars Rover Design Team (MRDT) at Missouri University of Science and Technology (Missouri S&T)! API reference contains the source code and other resources for the development of the autonomy software for our Mars rover. The Autonomy Software project aims to compete in the University Rover Challenge (URC) by demonstrating advanced autonomous capabilities and robust navigation algorithms.
Loading...
Searching...
No Matches
duckdb::CompressedFile Class Reference
Inheritance diagram for duckdb::CompressedFile:
Collaboration diagram for duckdb::CompressedFile:

Public Member Functions

DUCKDB_API CompressedFile (CompressedFileSystem &fs, unique_ptr< FileHandle > child_handle_p, const string &path)
 
DUCKDB_API idx_t GetProgress () override
 
DUCKDB_API void Initialize (QueryContext context, bool write)
 
DUCKDB_API int64_t ReadData (void *buffer, int64_t nr_bytes)
 
DUCKDB_API int64_t WriteData (data_ptr_t buffer, int64_t nr_bytes)
 
DUCKDB_API void Close () override
 Closes the file handle.
 
- Public Member Functions inherited from duckdb::FileHandle
DUCKDB_API FileHandle (FileSystem &file_system, string path, FileOpenFlags flags)
 
 FileHandle (const FileHandle &)=delete
 
DUCKDB_API int64_t Read (void *buffer, idx_t nr_bytes)
 
DUCKDB_API int64_t Read (QueryContext context, void *buffer, idx_t nr_bytes)
 
DUCKDB_API int64_t Write (void *buffer, idx_t nr_bytes)
 
DUCKDB_API int64_t Write (QueryContext context, void *buffer, idx_t nr_bytes)
 
DUCKDB_API void Read (void *buffer, idx_t nr_bytes, idx_t location)
 
DUCKDB_API void Read (QueryContext context, void *buffer, idx_t nr_bytes, idx_t location)
 
DUCKDB_API void Write (QueryContext context, void *buffer, idx_t nr_bytes, idx_t location)
 
DUCKDB_API void Seek (idx_t location)
 
DUCKDB_API void Reset ()
 
DUCKDB_API idx_t SeekPosition ()
 
DUCKDB_API void Sync ()
 
DUCKDB_API void Truncate (int64_t new_size)
 
DUCKDB_API string ReadLine ()
 
DUCKDB_API string ReadLine (QueryContext context)
 
DUCKDB_API bool Trim (idx_t offset_bytes, idx_t length_bytes)
 
virtual DUCKDB_API FileCompressionType GetFileCompressionType ()
 
DUCKDB_API bool CanSeek ()
 
DUCKDB_API bool IsPipe ()
 
DUCKDB_API bool OnDiskFile ()
 
DUCKDB_API idx_t GetFileSize ()
 
DUCKDB_API FileType GetType ()
 
DUCKDB_API FileMetadata Stats ()
 
DUCKDB_API void TryAddLogger (FileOpener &opener)
 
string GetPath () const
 
FileOpenFlags GetFlags () const
 
template<class TARGET >
TARGETCast ()
 
template<class TARGET >
const TARGETCast () const
 

Public Attributes

CompressedFileSystemcompressed_fs
 
unique_ptr< FileHandlechild_handle
 
bool write = false
 Whether the file is opened for reading or for writing.
 
StreamData stream_data
 
- Public Attributes inherited from duckdb::FileHandle
FileSystemfile_system
 
string path
 
FileOpenFlags flags
 
shared_ptr< Loggerlogger
 

Private Attributes

idx_t current_position = 0
 
unique_ptr< StreamWrapperstream_wrapper
 

Constructor & Destructor Documentation

◆ CompressedFile()

duckdb::CompressedFile::CompressedFile ( CompressedFileSystem fs,
unique_ptr< FileHandle child_handle_p,
const string &  path 
)
50127 : FileHandle(fs, path, child_handle_p->GetFlags()), compressed_fs(fs), child_handle(std::move(child_handle_p)) {
50128}

◆ ~CompressedFile()

duckdb::CompressedFile::~CompressedFile ( )
override
50130 {
50131 try {
50132 // stream_wrapper->Close() might throw
50134 } catch (std::exception &ex) {
50135 if (child_handle) {
50136 // FIXME: Make any log context available here.
50137 ErrorData data(ex);
50138 try {
50139 const auto logger = child_handle->logger;
50140 if (logger) {
50141 DUCKDB_LOG_ERROR(logger, "CompressedFile::~CompressedFile()\t\t" + data.Message());
50142 }
50143 } catch (...) { // NOLINT
50144 }
50145 }
50146 } catch (...) { // NOLINT
50147 }
50148}
DUCKDB_API void Close() override
Closes the file handle.
Definition duckdb.cpp:50245

Member Function Documentation

◆ GetProgress()

idx_t duckdb::CompressedFile::GetProgress ( )
overridevirtual

Reimplemented from duckdb::FileHandle.

50169 {
50170 return current_position;
50171}

◆ Initialize()

void duckdb::CompressedFile::Initialize ( QueryContext  context,
bool  write 
)
50150 {
50151 Close();
50152
50153 this->write = write;
50154 stream_data.in_buf_size = compressed_fs.InBufferSize();
50155 stream_data.out_buf_size = compressed_fs.OutBufferSize();
50156 stream_data.in_buff = make_unsafe_uniq_array<data_t>(stream_data.in_buf_size);
50157 stream_data.in_buff_start = stream_data.in_buff.get();
50158 stream_data.in_buff_end = stream_data.in_buff.get();
50159 stream_data.out_buff = make_unsafe_uniq_array<data_t>(stream_data.out_buf_size);
50160 stream_data.out_buff_start = stream_data.out_buff.get();
50161 stream_data.out_buff_end = stream_data.out_buff.get();
50162
50163 current_position = 0;
50164
50165 stream_wrapper = compressed_fs.CreateStream();
50166 stream_wrapper->Initialize(context, *this, write);
50167}
bool write
Whether the file is opened for reading or for writing.
Definition duckdb.cpp:50102

◆ ReadData()

int64_t duckdb::CompressedFile::ReadData ( void buffer,
int64_t  nr_bytes 
)
50173 {
50174 idx_t total_read = 0;
50175 while (true) {
50176 // first check if there are input bytes available in the output buffers
50177 if (stream_data.out_buff_start != stream_data.out_buff_end) {
50178 // there is! copy it into the output buffer
50179 auto available =
50180 MinValue<idx_t>(UnsafeNumericCast<idx_t>(remaining),
50181 UnsafeNumericCast<idx_t>(stream_data.out_buff_end - stream_data.out_buff_start));
50182 memcpy(static_cast<data_ptr_t>(buffer) + total_read, stream_data.out_buff_start, available);
50183
50184 // increment the total read variables as required
50185 stream_data.out_buff_start += available;
50186 total_read += available;
50187 remaining = UnsafeNumericCast<int64_t>(UnsafeNumericCast<idx_t>(remaining) - available);
50188 if (remaining == 0) {
50189 // done! read enough
50190 return UnsafeNumericCast<int64_t>(total_read);
50191 }
50192 }
50193 if (!stream_wrapper) {
50194 return UnsafeNumericCast<int64_t>(total_read);
50195 }
50196 current_position += static_cast<idx_t>(stream_data.in_buff_end - stream_data.in_buff_start);
50197 // ran out of buffer: read more data from the child stream
50198 stream_data.out_buff_start = stream_data.out_buff.get();
50199 stream_data.out_buff_end = stream_data.out_buff.get();
50200 D_ASSERT(stream_data.in_buff_start <= stream_data.in_buff_end);
50201 D_ASSERT(stream_data.in_buff_end <= stream_data.in_buff_start + stream_data.in_buf_size);
50202
50203 // read more input when requested and still data in the input stream
50204 if (stream_data.refresh && (stream_data.in_buff_end == stream_data.in_buff.get() + stream_data.in_buf_size)) {
50205 auto bufrem = stream_data.in_buff_end - stream_data.in_buff_start;
50206 // buffer not empty, move remaining bytes to the beginning
50207 memmove(stream_data.in_buff.get(), stream_data.in_buff_start, UnsafeNumericCast<size_t>(bufrem));
50208 stream_data.in_buff_start = stream_data.in_buff.get();
50209 // refill the rest of input buffer
50210 auto sz = child_handle->Read(QueryContext(), stream_data.in_buff_start + bufrem,
50211 stream_data.in_buf_size - UnsafeNumericCast<idx_t>(bufrem));
50212 stream_data.in_buff_end = stream_data.in_buff_start + bufrem + sz;
50213 if (sz <= 0) {
50214 stream_wrapper.reset();
50215 break;
50216 }
50217 }
50218
50219 // read more input if none available
50220 if (stream_data.in_buff_start == stream_data.in_buff_end) {
50221 // empty input buffer: refill from the start
50222 stream_data.in_buff_start = stream_data.in_buff.get();
50223 stream_data.in_buff_end = stream_data.in_buff_start;
50224 auto sz = child_handle->Read(QueryContext(), stream_data.in_buff.get(), stream_data.in_buf_size);
50225 if (sz <= 0) {
50226 stream_wrapper.reset();
50227 break;
50228 }
50229 stream_data.in_buff_end = stream_data.in_buff_start + sz;
50230 }
50231
50232 auto finished = stream_wrapper->Read(stream_data);
50233 if (finished) {
50234 stream_wrapper.reset();
50235 }
50236 }
50237 return UnsafeNumericCast<int64_t>(total_read);
50238}

◆ WriteData()

int64_t duckdb::CompressedFile::WriteData ( data_ptr_t  buffer,
int64_t  nr_bytes 
)
50240 {
50241 stream_wrapper->Write(*this, stream_data, buffer, nr_bytes);
50242 return nr_bytes;
50243}

◆ Close()

void duckdb::CompressedFile::Close ( )
overridevirtual

Closes the file handle.

Implements duckdb::FileHandle.

50245 {
50246 if (stream_wrapper) {
50247 stream_wrapper->Close();
50248 stream_wrapper.reset();
50249 }
50250 stream_data.in_buff.reset();
50251 stream_data.out_buff.reset();
50252 stream_data.out_buff_start = nullptr;
50253 stream_data.out_buff_end = nullptr;
50254 stream_data.in_buff_start = nullptr;
50255 stream_data.in_buff_end = nullptr;
50256 stream_data.in_buf_size = 0;
50257 stream_data.out_buf_size = 0;
50258 stream_data.refresh = false;
50259}

The documentation for this class was generated from the following file: