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::CSVBuffer Class Reference

CSV Buffers are parts of a decompressed CSV File. For a decompressed file of 100Mb. With our Buffer size set to 32Mb, we would generate 4 buffers. One for the first 32Mb, second and third for the other 32Mb, and the last one with 4 Mb These buffers are actually used for sniffing and parsing! More...

#include <duckdb.hpp>

Collaboration diagram for duckdb::CSVBuffer:

Public Member Functions

 CSVBuffer (ClientContext &context, idx_t buffer_size_p, CSVFileHandle &file_handle, const idx_t &global_csv_current_position)
 Constructor for Initial Buffer.
 CSVBuffer (CSVFileHandle &file_handle, ClientContext &context, idx_t buffer_size, idx_t global_csv_current_position, idx_t buffer_idx)
 Constructor for Next() Buffers.
shared_ptr< CSVBuffer > Next (CSVFileHandle &file_handle, idx_t buffer_size, bool &has_seeked) const
 Creates a new buffer with the next part of the CSV File.
idx_t GetBufferSize () const
 Gets the buffer actual size.
bool IsCSVFileLastBuffer () const
 If this buffer is the last buffer of the CSV File.
void AllocateBuffer (idx_t buffer_size)
 Allocates internal buffer, sets 'block' and 'handle' variables.
void Reload (CSVFileHandle &file_handle)
shared_ptr< CSVBufferHandle > Pin (CSVFileHandle &file_handle, bool &has_seeked)
 Wrapper for the Pin Function, if it can seek, it means that the buffer might have been destroyed, hence we must Scan it from the disk file again.
void Unpin ()
 Wrapper for unpin.
char * Ptr ()
bool IsUnloaded () const

Public Attributes

bool last_buffer = false

Static Public Attributes

static constexpr idx_t ROWS_PER_BUFFER = 16
 By default, we use CSV_BUFFER_SIZE to allocate each buffer.
static constexpr idx_t MIN_ROWS_PER_BUFFER = 4

Private Attributes

ClientContext & context
idx_t actual_buffer_size
 Actual size can be smaller than the buffer size in case we allocate it too optimistically.
idx_t requested_size
idx_t global_csv_start = 0
 Global position from the CSV File where this buffer starts.
bool can_seek
 If we can seek in the file or not.
bool is_pipe
 If this file is being fed by a pipe.
idx_t buffer_idx = 0
 Buffer Index, used as a batch index for insertion-order preservation.
shared_ptr< BlockHandle > block
 -----— Allocated Block ------—// Block created in allocation
BufferHandle handle

Detailed Description

CSV Buffers are parts of a decompressed CSV File. For a decompressed file of 100Mb. With our Buffer size set to 32Mb, we would generate 4 buffers. One for the first 32Mb, second and third for the other 32Mb, and the last one with 4 Mb These buffers are actually used for sniffing and parsing!

Constructor & Destructor Documentation

◆ CSVBuffer() [1/2]

duckdb::CSVBuffer::CSVBuffer ( ClientContext & context,
idx_t buffer_size_p,
CSVFileHandle & file_handle,
const idx_t & global_csv_current_position )

Constructor for Initial Buffer.

165576 : context(context), requested_size(buffer_size_p), can_seek(file_handle.CanSeek()), is_pipe(file_handle.IsPipe()) {
165577 AllocateBuffer(buffer_size_p);
165578 auto buffer = Ptr();
165579 actual_buffer_size = file_handle.Read(buffer, buffer_size_p);
165580 while (actual_buffer_size < buffer_size_p && !file_handle.FinishedReading()) {
165581 // We keep reading until this block is full
165582 actual_buffer_size += file_handle.Read(&buffer[actual_buffer_size], buffer_size_p - actual_buffer_size);
165583 }
165584 global_csv_start = global_csv_current_position;
165585 last_buffer = file_handle.FinishedReading();
165586}
idx_t global_csv_start
Global position from the CSV File where this buffer starts.
Definition duckdb.hpp:45996
void AllocateBuffer(idx_t buffer_size)
Allocates internal buffer, sets 'block' and 'handle' variables.
Definition duckdb.cpp:165618
idx_t actual_buffer_size
Actual size can be smaller than the buffer size in case we allocate it too optimistically.
Definition duckdb.hpp:45993
bool can_seek
If we can seek in the file or not.
Definition duckdb.hpp:45998
bool is_pipe
If this file is being fed by a pipe.
Definition duckdb.hpp:46000
std::shared_ptr< _Tp > Ptr
Here is the call graph for this function:

◆ CSVBuffer() [2/2]

duckdb::CSVBuffer::CSVBuffer ( CSVFileHandle & file_handle,
ClientContext & context,
idx_t buffer_size,
idx_t global_csv_current_position,
idx_t buffer_idx )

Constructor for Next() Buffers.

165590 : context(context), requested_size(buffer_size), global_csv_start(global_csv_current_position),
165591 can_seek(file_handle.CanSeek()), is_pipe(file_handle.IsPipe()), buffer_idx(buffer_idx_p) {
165592 AllocateBuffer(buffer_size);
165593 auto buffer = handle.Ptr();
165594 actual_buffer_size = file_handle.Read(handle.Ptr(), buffer_size);
165595 while (actual_buffer_size < buffer_size && !file_handle.FinishedReading()) {
165596 // We keep reading until this block is full
165597 actual_buffer_size += file_handle.Read(&buffer[actual_buffer_size], buffer_size - actual_buffer_size);
165598 }
165599 last_buffer = file_handle.FinishedReading();
165600}
idx_t buffer_idx
Buffer Index, used as a batch index for insertion-order preservation.
Definition duckdb.hpp:46002
Here is the call graph for this function:

Member Function Documentation

◆ Next()

shared_ptr< CSVBuffer > duckdb::CSVBuffer::Next ( CSVFileHandle & file_handle,
idx_t buffer_size,
bool & has_seeked ) const

Creates a new buffer with the next part of the CSV File.

165602 {
165603 if (has_seeked) {
165604 // This means that at some point a reload was done, and we are currently on the incorrect position in our file
165605 // handle
165606 file_handle.Seek(global_csv_start + actual_buffer_size);
165607 has_seeked = false;
165608 }
165609 auto next_csv_buffer = make_shared_ptr<CSVBuffer>(file_handle, context, buffer_size,
165611 if (next_csv_buffer->GetBufferSize() == 0) {
165612 // We are done reading
165613 return nullptr;
165614 }
165615 return next_csv_buffer;
165616}

◆ GetBufferSize()

idx_t duckdb::CSVBuffer::GetBufferSize ( ) const

Gets the buffer actual size.

165626 {
165627 return actual_buffer_size;
165628}

◆ IsCSVFileLastBuffer()

bool duckdb::CSVBuffer::IsCSVFileLastBuffer ( ) const

If this buffer is the last buffer of the CSV File.

165655 {
165656 return last_buffer;
165657}

◆ AllocateBuffer()

void duckdb::CSVBuffer::AllocateBuffer ( idx_t buffer_size)

Allocates internal buffer, sets 'block' and 'handle' variables.

165618 {
165619 auto &buffer_manager = BufferManager::GetBufferManager(context);
165620 bool can_destroy = !is_pipe;
165621 handle = buffer_manager.Allocate(MemoryTag::CSV_READER, MaxValue<idx_t>(buffer_manager.GetBlockSize(), buffer_size),
165622 can_destroy);
165623 block = handle.GetBlockHandle();
165624}
shared_ptr< BlockHandle > block
-----— Allocated Block ------—// Block created in allocation
Definition duckdb.hpp:46005
Here is the caller graph for this function:

◆ Reload()

void duckdb::CSVBuffer::Reload ( CSVFileHandle & file_handle)
165630 {
165632 // If we can seek, we seek and return the correct pointers
165633 file_handle.Seek(global_csv_start);
165634 file_handle.Read(handle.Ptr(), actual_buffer_size);
165635}

◆ Pin()

shared_ptr< CSVBufferHandle > duckdb::CSVBuffer::Pin ( CSVFileHandle & file_handle,
bool & has_seeked )

Wrapper for the Pin Function, if it can seek, it means that the buffer might have been destroyed, hence we must Scan it from the disk file again.

165637 {
165638 auto &buffer_manager = BufferManager::GetBufferManager(context);
165639 if (!block || (!is_pipe && block->GetMemory().IsUnloaded())) {
165640 // We have to reload it from disk
165641 block = nullptr;
165642 Reload(file_handle);
165643 has_seeked = true;
165644 }
165645 return make_shared_ptr<CSVBufferHandle>(buffer_manager.Pin(block), actual_buffer_size, requested_size, last_buffer,
165646 buffer_idx);
165647}

◆ Unpin()

void duckdb::CSVBuffer::Unpin ( )

Wrapper for unpin.

165649 {
165650 if (handle.IsValid()) {
165651 handle.Destroy();
165652 }
165653}

◆ Ptr()

char * duckdb::CSVBuffer::Ptr ( )
inline
45977 {
45978 return char_ptr_cast(handle.Ptr());
45979 }

◆ IsUnloaded()

bool duckdb::CSVBuffer::IsUnloaded ( ) const
inline
45980 {
45981 return block->GetMemory().IsUnloaded();
45982 }

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