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

Public Member Functions

 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.
virtual ScannerResult & ParseChunk ()
 Parses data into an output_chunk.
virtual ScannerResult & GetResult ()
 Returns the result from the last Parse call. Shouts at you if you call it wrong.
CSVIterator & GetIterator ()
void SetIterator (const CSVIterator &it)
idx_t GetBoundaryIndex () const
idx_t GetLinesRead () const
CSVPosition GetIteratorPosition () const
CSVStateMachine & GetStateMachine () const

Static Public Member Functions

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

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

virtual void Initialize ()
template<class T>
void Process (T &result)
 Process one chunk.
virtual void FinalizeChunkProcess ()
 Finalizes the process of the chunk.
template<class T>
void ParseChunkInternal (T &result)
 Internal function for parse chunk.

Protected Attributes

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

This is the base of our CSV scanners. Scanners differ on what they are used for, and consequently have different performance benefits.

Constructor & Destructor Documentation

◆ BaseScanner()

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 = {} )
explicit
168351 : csv_file_scan(std::move(csv_file_scan_p)), sniffing(sniffing_p), error_handler(std::move(error_handler_p)),
168352 state_machine(std::move(state_machine_p)), states(), buffer_manager(std::move(buffer_manager_p)),
168353 iterator(iterator_p) {
168354 D_ASSERT(buffer_manager);
168355 D_ASSERT(state_machine);
168356 // Initialize current buffer handle
168357 cur_buffer_handle = buffer_manager->GetBuffer(iterator.GetBufferIdx());
168358 if (!cur_buffer_handle) {
168359 buffer_handle_ptr = nullptr;
168360 } else {
168362 }
168363}
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
char * buffer_handle_ptr
Hold the current buffer ptr.
Definition duckdb.cpp:167330

Member Function Documentation

◆ Print()

void duckdb::BaseScanner::Print ( ) const
168365 {
168366 state_machine->Print();
168367}

◆ FinishedFile()

bool duckdb::BaseScanner::FinishedFile ( ) const

Returns true if the scanner is finished.

168380 {
168381 if (!cur_buffer_handle) {
168382 return true;
168383 }
168384 // we have to scan to infinity, so we must check if we are done checking the whole file
168385 if (!buffer_manager->Done()) {
168386 return false;
168387 }
168388 // If yes, are we in the last buffer?
168389 if (iterator.pos.buffer_idx != buffer_manager->BufferCount()) {
168390 return false;
168391 }
168392 // If yes, are we in the last position?
168393 return iterator.pos.buffer_pos + 1 == cur_buffer_handle->actual_size;
168394}
Here is the caller graph for this function:

◆ ParseChunk()

ScannerResult & duckdb::BaseScanner::ParseChunk ( )
virtual

Parses data into an output_chunk.

Reimplemented in duckdb::ColumnCountScanner, duckdb::SkipScanner, and duckdb::StringValueScanner.

168415 {
168416 throw InternalException("ParseChunk() from CSV Base Scanner is not implemented");
168417}

◆ GetResult()

ScannerResult & duckdb::BaseScanner::GetResult ( )
virtual

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

Reimplemented in duckdb::ColumnCountScanner, and duckdb::SkipScanner.

168419 {
168420 throw InternalException("GetResult() from CSV Base Scanner is not implemented");
168421}

◆ GetIterator()

CSVIterator & duckdb::BaseScanner::GetIterator ( )
168407 {
168408 return iterator;
168409}

◆ SetIterator()

void duckdb::BaseScanner::SetIterator ( const CSVIterator & it)
168411 {
168412 iterator = it;
168413}

◆ GetBoundaryIndex()

idx_t duckdb::BaseScanner::GetBoundaryIndex ( ) const
inline
167270 {
167271 return iterator.GetBoundaryIdx();
167272 }

◆ GetLinesRead()

idx_t duckdb::BaseScanner::GetLinesRead ( ) const
inline
167274 {
167275 return lines_read;
167276 }
idx_t lines_read
How many lines were read by this scanner.
Definition duckdb.cpp:167335

◆ GetIteratorPosition()

CSVPosition duckdb::BaseScanner::GetIteratorPosition ( ) const
inline
167278 {
167279 return iterator.pos;
167280 }

◆ GetStateMachine()

CSVStateMachine & duckdb::BaseScanner::GetStateMachine ( ) const
168431 {
168432 return *state_machine;
168433}

◆ RemoveSeparator()

string duckdb::BaseScanner::RemoveSeparator ( const char * value_ptr,
const idx_t size,
char thousands_separator )
static

Removes thousands separator.

168369 {
168370 string result;
168371 result.reserve(size);
168372 for (idx_t i = 0; i < size; i++) {
168373 if (value_ptr[i] != thousands_separator) {
168374 result.push_back(value_ptr[i]);
168375 }
168376 }
168377 return result;
168378}
GOpaque< Size > size(const GMat &src)
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237
Here is the caller graph for this function:

◆ SkipCSVRows()

CSVIterator duckdb::BaseScanner::SkipCSVRows ( shared_ptr< CSVBufferManager > buffer_manager,
const shared_ptr< CSVStateMachine > & state_machine,
idx_t rows_to_skip )
static

Skips Notes and/or parts of the data, starting from the top. notes are dirty lines on top of the file, before the actual data

168397 {
168398 if (rows_to_skip == 0) {
168399 return {};
168400 }
168401 auto error_handler = make_shared_ptr<CSVErrorHandler>();
168402 SkipScanner row_skipper(std::move(buffer_manager), state_machine, error_handler, rows_to_skip);
168403 row_skipper.ParseChunk();
168404 return row_skipper.GetIterator();
168405}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ContainsZeroByte()

bool duckdb::BaseScanner::ContainsZeroByte ( uint64_t v)
inlinestatic
167317 {
167318 return (v - UINT64_C(0x0101010101010101)) & ~(v)&UINT64_C(0x8080808080808080);
167319 }
uint32_t v

◆ Initialize()

void duckdb::BaseScanner::Initialize ( )
protectedvirtual

Internal Functions used to perform the parsing Initializes the scanner

Reimplemented in duckdb::ColumnCountScanner, duckdb::SkipScanner, and duckdb::StringValueScanner.

168423 {
168424 throw InternalException("Initialize() from CSV Base Scanner is not implemented");
168425}
Here is the caller graph for this function:

◆ Process()

template<class T>
void duckdb::BaseScanner::Process ( T & result)
inlineprotected

Process one chunk.

167343 {
167344 idx_t to_pos;
167345 const bool has_escaped_value = state_machine->dialect_options.state_machine_options.escape != '\0';
167346 const bool only_rn_newlines =
167347 state_machine->state_machine_options.strict_mode.GetValue() &&
167348 state_machine->state_machine_options.strict_mode.IsSetByUser() &&
167349 state_machine->state_machine_options.new_line.GetValue() == NewLineIdentifier::CARRY_ON &&
167350 state_machine->state_machine_options.new_line.IsSetByUser();
167351 const idx_t start_pos = iterator.pos.buffer_pos;
167352 if (iterator.IsBoundarySet()) {
167353 to_pos = iterator.GetEndPos();
167354 if (to_pos > cur_buffer_handle->actual_size) {
167355 to_pos = cur_buffer_handle->actual_size;
167356 }
167357 } else {
167358 to_pos = cur_buffer_handle->actual_size;
167359 }
167360 while (iterator.pos.buffer_pos < to_pos) {
167361 state_machine->Transition(states, buffer_handle_ptr[iterator.pos.buffer_pos]);
167362 switch (states.states[1]) {
167363 case CSVState::INVALID:
167364 T::InvalidState(result);
167365 iterator.pos.buffer_pos++;
167366 bytes_read = iterator.pos.buffer_pos - start_pos;
167367 return;
167369 if (states.states[0] == CSVState::RECORD_SEPARATOR || states.states[0] == CSVState::NOT_SET) {
167370 if (T::EmptyLine(result, iterator.pos.buffer_pos)) {
167371 iterator.pos.buffer_pos++;
167372 bytes_read = iterator.pos.buffer_pos - start_pos;
167373 lines_read++;
167374 return;
167375 }
167376 lines_read++;
167377
167378 } else if (states.states[0] != CSVState::CARRIAGE_RETURN) {
167379 if (T::IsCommentSet(result)) {
167380 if (T::UnsetComment(result, iterator.pos.buffer_pos)) {
167381 iterator.pos.buffer_pos++;
167382 bytes_read = iterator.pos.buffer_pos - start_pos;
167383 lines_read++;
167384 return;
167385 }
167386 } else {
167387 if (T::AddRow(result, iterator.pos.buffer_pos)) {
167388 iterator.pos.buffer_pos++;
167389 bytes_read = iterator.pos.buffer_pos - start_pos;
167390 lines_read++;
167391 return;
167392 }
167393 }
167394 lines_read++;
167395 }
167396 iterator.pos.buffer_pos++;
167397 break;
167399 if (states.states[0] == CSVState::RECORD_SEPARATOR || states.states[0] == CSVState::NOT_SET) {
167400 if (T::EmptyLine(result, iterator.pos.buffer_pos)) {
167401 iterator.pos.buffer_pos++;
167402 bytes_read = iterator.pos.buffer_pos - start_pos;
167403 lines_read++;
167404 return;
167405 }
167406 } else if (states.states[0] != CSVState::CARRIAGE_RETURN) {
167407 if (T::IsCommentSet(result)) {
167408 if (T::UnsetComment(result, iterator.pos.buffer_pos)) {
167409 iterator.pos.buffer_pos++;
167410 bytes_read = iterator.pos.buffer_pos - start_pos;
167411 lines_read++;
167412 return;
167413 }
167414 } else if (!only_rn_newlines) {
167415 if (T::AddRow(result, iterator.pos.buffer_pos)) {
167416 iterator.pos.buffer_pos++;
167417 bytes_read = iterator.pos.buffer_pos - start_pos;
167418 lines_read++;
167419 return;
167420 }
167421 }
167422 }
167423 iterator.pos.buffer_pos++;
167424 lines_read++;
167425 break;
167426 case CSVState::DELIMITER:
167427 T::AddValue(result, iterator.pos.buffer_pos);
167428 iterator.pos.buffer_pos++;
167429 break;
167430 case CSVState::QUOTED: {
167431 if ((states.states[0] == CSVState::UNQUOTED || states.states[0] == CSVState::MAYBE_QUOTED) &&
167432 has_escaped_value) {
167433 ever_escaped = true;
167434 T::SetEscaped(result);
167435 }
167436 if ((states.states[0] == CSVState::ESCAPE || states.states[0] == CSVState::ESCAPED_RETURN ||
167437 states.states[0] == CSVState::UNQUOTED_ESCAPE) &&
167438 (buffer_handle_ptr[iterator.pos.buffer_pos] ==
167439 state_machine->dialect_options.state_machine_options.quote.GetValue() ||
167440 !state_machine->dialect_options.state_machine_options.strict_mode.GetValue())) {
167441 // We only set the ever escaped variable if this is either a quote char OR strict mode is off
167442 ever_escaped = true;
167443 if (states.states[0] == CSVState::UNQUOTED_ESCAPE) {
167444 used_unstrictness = true;
167445 }
167446 }
167447 ever_quoted = true;
167448 T::SetQuoted(result, iterator.pos.buffer_pos);
167449 iterator.pos.buffer_pos++;
167450 while (iterator.pos.buffer_pos + 8 < to_pos) {
167451 const uint64_t value =
167452 Load<uint64_t>(reinterpret_cast<const_data_ptr_t>(&buffer_handle_ptr[iterator.pos.buffer_pos]));
167453 if (ContainsZeroByte((value ^ state_machine->transition_array.quote) &
167454 (value ^ state_machine->transition_array.escape))) {
167455 break;
167456 }
167457 iterator.pos.buffer_pos += 8;
167458 }
167459
167460 while (state_machine->transition_array
167461 .skip_quoted[static_cast<uint8_t>(buffer_handle_ptr[iterator.pos.buffer_pos])] &&
167462 iterator.pos.buffer_pos < to_pos - 1) {
167463 iterator.pos.buffer_pos++;
167464 }
167465 } break;
167466 case CSVState::UNQUOTED: {
167467 if (states.states[0] == CSVState::MAYBE_QUOTED) {
167468 ever_escaped = true;
167469 T::SetEscaped(result);
167470 }
167471 T::SetUnquoted(result);
167472 iterator.pos.buffer_pos++;
167473 break;
167474 }
167475 case CSVState::ESCAPE:
167477 T::SetEscaped(result);
167478 iterator.pos.buffer_pos++;
167479 break;
167481 T::SetEscaped(result);
167482 iterator.pos.buffer_pos++;
167483 used_unstrictness = true;
167484 break;
167485 case CSVState::STANDARD: {
167486 iterator.pos.buffer_pos++;
167487 while (iterator.pos.buffer_pos + 8 < to_pos) {
167488 uint64_t value =
167489 Load<uint64_t>(reinterpret_cast<const_data_ptr_t>(&buffer_handle_ptr[iterator.pos.buffer_pos]));
167490 if (ContainsZeroByte((value ^ state_machine->transition_array.delimiter) &
167491 (value ^ state_machine->transition_array.new_line) &
167492 (value ^ state_machine->transition_array.carriage_return) &
167493 (value ^ state_machine->transition_array.escape) &
167494 (value ^ state_machine->transition_array.comment))) {
167495 break;
167496 }
167497 iterator.pos.buffer_pos += 8;
167498 }
167499 while (state_machine->transition_array
167500 .skip_standard[static_cast<uint8_t>(buffer_handle_ptr[iterator.pos.buffer_pos])] &&
167501 iterator.pos.buffer_pos < to_pos - 1) {
167502 iterator.pos.buffer_pos++;
167503 }
167504 break;
167505 }
167507 T::QuotedNewLine(result);
167508 iterator.pos.buffer_pos++;
167509 break;
167510 case CSVState::COMMENT: {
167511 T::SetComment(result, iterator.pos.buffer_pos);
167512 iterator.pos.buffer_pos++;
167513 while (iterator.pos.buffer_pos + 8 < to_pos) {
167514 const uint64_t value =
167515 Load<uint64_t>(reinterpret_cast<const_data_ptr_t>(&buffer_handle_ptr[iterator.pos.buffer_pos]));
167516 if (ContainsZeroByte((value ^ state_machine->transition_array.new_line) &
167517 (value ^ state_machine->transition_array.carriage_return))) {
167518 break;
167519 }
167520 iterator.pos.buffer_pos += 8;
167521 }
167522 while (state_machine->transition_array
167523 .skip_comment[static_cast<uint8_t>(buffer_handle_ptr[iterator.pos.buffer_pos])] &&
167524 iterator.pos.buffer_pos < to_pos - 1) {
167525 iterator.pos.buffer_pos++;
167526 }
167527 break;
167528 }
167529 default:
167530 iterator.pos.buffer_pos++;
167531 break;
167532 }
167533 }
167534 bytes_read = iterator.pos.buffer_pos - start_pos;
167535 }
bool ever_escaped
If the scanner ever entered an escaped state.
Definition duckdb.cpp:167304
bool ever_quoted
If the scanner ever entered a quoted state.
Definition duckdb.cpp:167301
bool used_unstrictness
If the scanner ever used advantage of the non-strict mode.
Definition duckdb.cpp:167307
::uint8_t uint8_t
::uint64_t uint64_t
@ NOT_SET
Got to an Invalid State, this should error.
Definition duckdb.cpp:59187
@ UNQUOTED_ESCAPE
State used for figuring out a new line.
Definition duckdb.cpp:59192
@ QUOTED
State after encountering a carriage return(i.e., \r).
Definition duckdb.cpp:59183
@ CARRIAGE_RETURN
State after encountering a record separator (i.e., ).
Definition duckdb.cpp:59182
@ DELIMITER
Regular unquoted field state.
Definition duckdb.cpp:59175
@ UNQUOTED
State when inside a quoted field.
Definition duckdb.cpp:59184
@ INVALID
State when encountering an escape character (e.g., ).
Definition duckdb.cpp:59186
@ QUOTED_NEW_LINE
If the state is not set, usually the first state before getting the first character.
Definition duckdb.cpp:59188
@ ESCAPE
State when leaving a quoted field.
Definition duckdb.cpp:59185
@ ESCAPED_RETURN
State when encountering an escape character (e.g., ) in an unquoted field.
Definition duckdb.cpp:59193
@ MAYBE_QUOTED
State when the carriage return is preceded by an escape character (for '\r ' newline only).
Definition duckdb.cpp:59194
@ RECORD_SEPARATOR
-----------------------------------------------------------------------------------------------------...
Definition duckdb.cpp:59181
@ COMMENT
If we have empty spaces in the beginning and end of value.
Definition duckdb.cpp:59190
Here is the caller graph for this function:

◆ FinalizeChunkProcess()

void duckdb::BaseScanner::FinalizeChunkProcess ( )
protectedvirtual

Finalizes the process of the chunk.

Reimplemented in duckdb::ColumnCountScanner, duckdb::SkipScanner, and duckdb::StringValueScanner.

168427 {
168428 throw InternalException("FinalizeChunkProcess() from CSV Base Scanner is not implemented");
168429}
Here is the caller graph for this function:

◆ ParseChunkInternal()

template<class T>
void duckdb::BaseScanner::ParseChunkInternal ( T & result)
inlineprotected

Internal function for parse chunk.

167542 {
167543 if (iterator.done) {
167544 return;
167545 }
167546 if (!initialized) {
167547 Initialize();
167548 initialized = true;
167549 }
167550 if (!iterator.done && cur_buffer_handle) {
167551 Process(result);
167552 }
167554 }
virtual void Initialize()
Definition duckdb.cpp:168423
void Process(T &result)
Process one chunk.
Definition duckdb.cpp:167343
bool initialized
If this scanner has been initialized.
Definition duckdb.cpp:167333
virtual void FinalizeChunkProcess()
Finalizes the process of the chunk.
Definition duckdb.cpp:168427
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ cur_buffer_handle

shared_ptr<CSVBufferHandle> duckdb::BaseScanner::cur_buffer_handle
protected

Unique pointer to the buffer_handle, this is unique per scanner, since it also contains the necessary counters To offload buffers to disk if necessary


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