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

Scanner that goes over the CSV and figures out how many columns each row has. Used for dialect sniffing. More...

Inheritance diagram for duckdb::ColumnCountScanner:
Collaboration diagram for duckdb::ColumnCountScanner:

Public Member Functions

 ColumnCountScanner (shared_ptr< CSVBufferManager > buffer_manager, const shared_ptr< CSVStateMachine > &state_machine, shared_ptr< CSVErrorHandler > error_handler, idx_t result_size=STANDARD_VECTOR_SIZE, CSVIterator iterator={})
ColumnCountResult & ParseChunk () override
 Parses data into an output_chunk.
ColumnCountResult & GetResult () override
 Returns the result from the last Parse call. Shouts at you if you call it wrong.
unique_ptr< StringValueScanner > UpgradeToStringValueScanner ()
Public Member Functions inherited from duckdb::BaseScanner
 BaseScanner (shared_ptr< CSVBufferManager > buffer_manager, shared_ptr< CSVStateMachine > state_machine, shared_ptr< CSVErrorHandler > error_handler, bool sniffing=false, shared_ptr< CSVFileScan > csv_file_scan=nullptr, const CSVIterator &iterator={})
void Print () const
bool FinishedFile () const
 Returns true if the scanner is finished.
CSVIterator & GetIterator ()
void SetIterator (const CSVIterator &it)
idx_t GetBoundaryIndex () const
idx_t GetLinesRead () const
CSVPosition GetIteratorPosition () const
CSVStateMachine & GetStateMachine () const

Private Member Functions

void Initialize () override
void FinalizeChunkProcess () override
 Finalizes the process of the chunk.

Private Attributes

ColumnCountResult result
idx_t column_count
idx_t result_size

Additional Inherited Members

Static Public Member Functions inherited from duckdb::BaseScanner
static string RemoveSeparator (const char *value_ptr, const idx_t size, char thousands_separator)
 Removes thousands separator.
static CSVIterator SkipCSVRows (shared_ptr< CSVBufferManager > buffer_manager, const shared_ptr< CSVStateMachine > &state_machine, idx_t rows_to_skip)
static bool ContainsZeroByte (uint64_t v)
Public Attributes inherited from duckdb::BaseScanner
shared_ptr< CSVFileScan > csv_file_scan
bool sniffing = false
 If this scanner is being used for sniffing.
shared_ptr< CSVErrorHandler > error_handler
 The guy that handles errors.
shared_ptr< CSVStateMachine > state_machine
 Shared pointer to the state machine, this is used across multiple scanners.
CSVStates states
 States.
bool ever_quoted = false
 If the scanner ever entered a quoted state.
bool ever_escaped = false
 If the scanner ever entered an escaped state.
bool used_unstrictness = false
 If the scanner ever used advantage of the non-strict mode.
shared_ptr< CSVBufferManager > buffer_manager
 Shared pointer to the buffer_manager, this is shared across multiple scanners.
Protected Member Functions inherited from duckdb::BaseScanner
template<class T>
void Process (T &result)
 Process one chunk.
template<class T>
void ParseChunkInternal (T &result)
 Internal function for parse chunk.
Protected Attributes inherited from duckdb::BaseScanner
CSVIterator iterator
 Boundaries of this scanner.
shared_ptr< CSVBufferHandle > cur_buffer_handle
char * buffer_handle_ptr = nullptr
 Hold the current buffer ptr.
bool initialized = false
 If this scanner has been initialized.
idx_t lines_read = 0
 How many lines were read by this scanner.
idx_t bytes_read = 0

Detailed Description

Scanner that goes over the CSV and figures out how many columns each row has. Used for dialect sniffing.

Constructor & Destructor Documentation

◆ ColumnCountScanner()

duckdb::ColumnCountScanner::ColumnCountScanner ( shared_ptr< CSVBufferManager > buffer_manager,
const shared_ptr< CSVStateMachine > & state_machine,
shared_ptr< CSVErrorHandler > error_handler,
idx_t result_size = STANDARD_VECTOR_SIZE,
CSVIterator iterator = {} )
168553 : BaseScanner(std::move(buffer_manager), state_machine, std::move(error_handler_p), true, nullptr, iterator),
168554 result(states, *state_machine, result_size_p, *error_handler), column_count(1), result_size(result_size_p) {
168555 sniffing = true;
168556 idx_t actual_size = 0;
168557 if (cur_buffer_handle) {
168558 actual_size = cur_buffer_handle->actual_size;
168559 result.buffer_handles[0] = cur_buffer_handle;
168560 }
168561 result.last_position = {iterator.pos.buffer_idx, iterator.pos.buffer_pos, actual_size};
168562 result.current_buffer_size = actual_size;
168563 result.cur_buffer_idx = iterator.pos.buffer_idx;
168564}
shared_ptr< CSVStateMachine > state_machine
Shared pointer to the state machine, this is used across multiple scanners.
Definition duckdb.cpp:167295
bool sniffing
If this scanner is being used for sniffing.
Definition duckdb.cpp:167290
CSVIterator iterator
Boundaries of this scanner.
Definition duckdb.cpp:167323
CSVStates states
States.
Definition duckdb.cpp:167298
shared_ptr< CSVBufferManager > buffer_manager
Shared pointer to the buffer_manager, this is shared across multiple scanners.
Definition duckdb.cpp:167310
shared_ptr< CSVErrorHandler > error_handler
The guy that handles errors.
Definition duckdb.cpp:167292
shared_ptr< CSVBufferHandle > cur_buffer_handle
Definition duckdb.cpp:167327
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237

Member Function Documentation

◆ ParseChunk()

ColumnCountResult & duckdb::ColumnCountScanner::ParseChunk ( )
overridevirtual

Parses data into an output_chunk.

Reimplemented from duckdb::BaseScanner.

168578 {
168579 result.result_position = 0;
168580 column_count = 1;
168581 if (cur_buffer_handle) {
168582 result.current_buffer_size = cur_buffer_handle->actual_size;
168583 }
168584 ParseChunkInternal(result);
168585 return result;
168586}
void ParseChunkInternal(T &result)
Internal function for parse chunk.
Definition duckdb.cpp:167542
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetResult()

ColumnCountResult & duckdb::ColumnCountScanner::GetResult ( )
overridevirtual

Returns the result from the last Parse call. Shouts at you if you call it wrong.

Reimplemented from duckdb::BaseScanner.

168588 {
168589 return result;
168590}

◆ UpgradeToStringValueScanner()

unique_ptr< StringValueScanner > duckdb::ColumnCountScanner::UpgradeToStringValueScanner ( )
168566 {
168567 idx_t rows_to_skip = state_machine->dialect_options.skip_rows.GetValue();
168568 auto iterator = SkipCSVRows(buffer_manager, state_machine, rows_to_skip);
168569 if (iterator.done) {
168570 CSVIterator it {};
168571 return make_uniq<StringValueScanner>(0U, buffer_manager, state_machine, error_handler, nullptr, true, it,
168572 result_size);
168573 }
168574 return make_uniq<StringValueScanner>(0U, buffer_manager, state_machine, error_handler, nullptr, true, iterator,
168575 result_size);
168576}
static CSVIterator SkipCSVRows(shared_ptr< CSVBufferManager > buffer_manager, const shared_ptr< CSVStateMachine > &state_machine, idx_t rows_to_skip)
Definition duckdb.cpp:168396

◆ Initialize()

void duckdb::ColumnCountScanner::Initialize ( )
overrideprivatevirtual

Internal Functions used to perform the parsing Initializes the scanner

Reimplemented from duckdb::BaseScanner.

168592 {
168593 states.Initialize();
168594}

◆ FinalizeChunkProcess()

void duckdb::ColumnCountScanner::FinalizeChunkProcess ( )
overrideprivatevirtual

Finalizes the process of the chunk.

Reimplemented from duckdb::BaseScanner.

168596 {
168597 if (result.result_position == result.result_size || result.error) {
168598 // We are done
168599 return;
168600 }
168601 // We run until we have a full chunk, or we are done scanning
168602 while (!FinishedFile() && result.result_position < result.result_size && !result.error) {
168603 if (iterator.pos.buffer_pos == cur_buffer_handle->actual_size) {
168604 // Move to next buffer
168605 cur_buffer_handle = buffer_manager->GetBuffer(++iterator.pos.buffer_idx);
168606
168607 if (!cur_buffer_handle) {
168608 buffer_handle_ptr = nullptr;
168609 if (states.IsQuotedCurrent() && !states.IsUnquoted()) {
168610 // We are finishing our file on a quoted value that is never unquoted, straight to jail.
168611 result.error = true;
168612 return;
168613 }
168614 if (states.EmptyLine() || states.NewRow() || states.IsCurrentNewRow() || states.IsNotSet()) {
168615 return;
168616 }
168617 // This means we reached the end of the file, we must add a last line if there is any to be added
168618 if (result.comment) {
168619 // If it's a comment we add the last line via unset comment
168620 result.UnsetComment(result, NumericLimits<idx_t>::Maximum());
168621 } else {
168622 // OW, we do a regular AddRow
168623 result.AddRow(result, NumericLimits<idx_t>::Maximum());
168624 }
168625 return;
168626 } else {
168627 result.buffer_handles[iterator.pos.buffer_idx] = cur_buffer_handle;
168628 result.cur_buffer_idx = iterator.pos.buffer_idx;
168629 result.current_buffer_size = cur_buffer_handle->actual_size;
168630 // Do a quick check that the line is still sane
168631 const LinePosition cur_position(result.cur_buffer_idx, 0, result.current_buffer_size);
168632 LinesPerBoundary lines_per_batch;
168633 if (cur_position - result.last_position > result.state_machine.options.maximum_line_size.GetValue()) {
168634 FullLinePosition current_line_position;
168635 current_line_position.begin = result.last_position;
168636 current_line_position.end = cur_position;
168637 bool mock = false;
168638 string csv_row = current_line_position.ReconstructCurrentLine(mock, result.buffer_handles, true);
168639 auto error =
168640 CSVError::LineSizeError(result.state_machine.options, lines_per_batch, csv_row,
168641 result.last_position.GetGlobalPosition(
168642 result.state_machine.options.buffer_size_option.GetValue(), false),
168643 result.state_machine.options.file_path);
168644 error_handler->Error(error);
168645 result.error = true;
168646 return;
168647 }
168648 }
168649 if (result.buffer_handles.size() > 2) {
168650 // pop lowest value
168651 result.buffer_handles.erase(result.buffer_handles.begin());
168652 }
168653 iterator.pos.buffer_pos = 0;
168655 }
168656 Process(result);
168657 }
168658}
void Process(T &result)
Process one chunk.
Definition duckdb.cpp:167343
bool FinishedFile() const
Returns true if the scanner is finished.
Definition duckdb.cpp:168380
char * buffer_handle_ptr
Hold the current buffer ptr.
Definition duckdb.cpp:167330
static CSVError LineSizeError(const CSVReaderOptions &options, LinesPerBoundary error_info, string &csv_row, idx_t byte_position, const String &current_path)
Produces error for when the line size exceeds the maximum line size option.
Definition duckdb.cpp:175889
Here is the call graph for this function:

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