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::CSVFileHandle Class Reference
Collaboration diagram for duckdb::CSVFileHandle:

Public Member Functions

 CSVFileHandle (ClientContext &context, unique_ptr< FileHandle > file_handle_p, const OpenFileInfo &file, const CSVReaderOptions &options)
bool CanSeek () const
void Seek (idx_t position) const
bool OnDiskFile () const
bool IsPipe () const
void Reset ()
idx_t FileSize () const
bool FinishedReading () const
idx_t Read (void *buffer, idx_t nr_bytes)
string ReadLine ()
string GetFilePath ()
double GetProgress () const

Static Public Member Functions

static unique_ptr< FileHandle > OpenFileHandle (FileSystem &fs, Allocator &allocator, const OpenFileInfo &file, FileCompressionType compression)
static unique_ptr< CSVFileHandle > OpenFile (ClientContext &context, const OpenFileInfo &file, const CSVReaderOptions &options)

Public Attributes

mutex main_mutex
FileCompressionType compression_type

Private Attributes

QueryContext context
unique_ptr< FileHandle > file_handle
CSVEncoder encoder
const OpenFileInfo file
bool can_seek = false
bool on_disk_file = false
bool is_pipe = false
idx_t uncompressed_bytes_read = 0
idx_t file_size = 0
idx_t requested_bytes = 0
bool finished = false
 If we finished reading the file.

Constructor & Destructor Documentation

◆ CSVFileHandle()

duckdb::CSVFileHandle::CSVFileHandle ( ClientContext & context,
unique_ptr< FileHandle > file_handle_p,
const OpenFileInfo & file,
const CSVReaderOptions & options )
166861 : compression_type(options.compression), context(context_p), file_handle(std::move(file_handle_p)),
166862 encoder(context_p, options.encoding, options.buffer_size_option.GetValue()), file(file_p) {
166863 can_seek = file_handle->CanSeek();
166864 on_disk_file = file_handle->OnDiskFile();
166865 file_size = file_handle->GetFileSize();
166866 is_pipe = file_handle->IsPipe();
166867 compression_type = file_handle->GetFileCompressionType();
166868}

Member Function Documentation

◆ CanSeek()

bool duckdb::CSVFileHandle::CanSeek ( ) const
166891 {
166892 return can_seek;
166893}

◆ Seek()

void duckdb::CSVFileHandle::Seek ( idx_t position) const
166895 {
166896 if (!can_seek) {
166897 if (is_pipe) {
166898 throw InternalException("Trying to seek a piped CSV File.");
166899 }
166900 throw InternalException("Trying to seek a compressed CSV File.");
166901 }
166902 file_handle->Seek(position);
166903}

◆ OnDiskFile()

bool duckdb::CSVFileHandle::OnDiskFile ( ) const
166905 {
166906 return on_disk_file;
166907}

◆ IsPipe()

bool duckdb::CSVFileHandle::IsPipe ( ) const
166915 {
166916 return is_pipe;
166917}

◆ Reset()

void duckdb::CSVFileHandle::Reset ( )
166909 {
166910 file_handle->Reset();
166911 finished = false;
166912 requested_bytes = 0;
166913}
bool finished
If we finished reading the file.
Definition duckdb.hpp:45120

◆ FileSize()

idx_t duckdb::CSVFileHandle::FileSize ( ) const
166919 {
166920 return file_size;
166921}

◆ FinishedReading()

bool duckdb::CSVFileHandle::FinishedReading ( ) const
166923 {
166924 return finished;
166925}

◆ Read()

idx_t duckdb::CSVFileHandle::Read ( void * buffer,
idx_t nr_bytes )
166927 {
166928 // We avoid reading past the original size of the file for uncompressed files in utf-8 encoding. This avoids reading
166929 // the data that is written after opening the file. This can be useful, for example when reading a duckdb log file
166930 // in csv format while logging is enabled
166931 if (file_handle->GetFileCompressionType() == FileCompressionType::UNCOMPRESSED && file_handle->CanSeek() &&
166932 encoder.encoding_name == "utf-8") {
166933 nr_bytes = MinValue<idx_t>(nr_bytes, file_size - file_handle->SeekPosition());
166934 }
166935
166936 requested_bytes += nr_bytes;
166937 // if this is a plain file source OR we can seek we are not caching anything
166938 idx_t bytes_read = 0;
166939 if (encoder.encoding_name == "utf-8") {
166940 bytes_read = static_cast<idx_t>(file_handle->Read(context, buffer, nr_bytes));
166941 } else {
166942 bytes_read = encoder.Encode(*file_handle, static_cast<char *>(buffer), nr_bytes);
166943 }
166944 if (!finished) {
166945 finished = bytes_read == 0;
166946 }
166947 uncompressed_bytes_read += static_cast<idx_t>(bytes_read);
166948 return UnsafeNumericCast<idx_t>(bytes_read);
166949}
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237

◆ ReadLine()

string duckdb::CSVFileHandle::ReadLine ( )
166951 {
166952 bool carriage_return = false;
166953 string result;
166954 char buffer[1];
166955 while (true) {
166956 idx_t bytes_read = Read(buffer, 1);
166957 if (bytes_read == 0) {
166958 return result;
166959 }
166960 if (carriage_return) {
166961 if (buffer[0] != '\n') {
166962 if (!file_handle->CanSeek()) {
166963 throw BinderException(
166964 "Carriage return newlines not supported when reading CSV files in which we cannot seek");
166965 }
166966 file_handle->Seek(file_handle->SeekPosition() - 1);
166967 return result;
166968 }
166969 }
166970 if (buffer[0] == '\n') {
166971 return result;
166972 }
166973 if (buffer[0] != '\r') {
166974 result += buffer[0];
166975 } else {
166976 carriage_return = true;
166977 }
166978 }
166979}

◆ GetFilePath()

string duckdb::CSVFileHandle::GetFilePath ( )
166981 {
166982 return file.path;
166983}

◆ OpenFileHandle()

unique_ptr< FileHandle > duckdb::CSVFileHandle::OpenFileHandle ( FileSystem & fs,
Allocator & allocator,
const OpenFileInfo & file,
FileCompressionType compression )
static
166871 {
166872 auto file_handle = fs.OpenFile(file, FileFlags::FILE_FLAGS_READ | compression);
166873 if (file_handle->CanSeek()) {
166874 file_handle->Reset();
166875 }
166876 return file_handle;
166877}
static constexpr FileOpenFlags FILE_FLAGS_READ
Open file with read access.
Definition duckdb.hpp:7850

◆ OpenFile()

unique_ptr< CSVFileHandle > duckdb::CSVFileHandle::OpenFile ( ClientContext & context,
const OpenFileInfo & file,
const CSVReaderOptions & options )
static
166880 {
166881 auto &fs = FileSystem::GetFileSystem(context);
166882 auto &allocator = BufferAllocator::Get(context);
166883 auto file_handle = OpenFileHandle(fs, allocator, file, options.compression);
166884 return make_uniq<CSVFileHandle>(context, std::move(file_handle), file, options);
166885}

◆ GetProgress()

double duckdb::CSVFileHandle::GetProgress ( ) const
166887 {
166888 return static_cast<double>(file_handle->GetProgress());
166889}

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