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::CSVGlobalState Struct Reference

CSV Global State is used in the CSV Reader Table Function, it controls what each thread. More...

Inheritance diagram for duckdb::CSVGlobalState:
Collaboration diagram for duckdb::CSVGlobalState:

Public Member Functions

 CSVGlobalState (ClientContext &context_p, const CSVReaderOptions &options, idx_t total_file_count, const MultiFileBindData &bind_data)
void FinishScan (unique_ptr< StringValueScanner > scanner)
unique_ptr< StringValueScanner > Next (shared_ptr< CSVFileScan > &file)
void FinishLaunchingTasks (CSVFileScan &scan)
void FillRejectsTable (CSVFileScan &scan)
void FinishTask (CSVFileScan &scan)
void FinishFile (CSVFileScan &scan)
bool SingleThreadedRead () const
 Whether or not to read individual CSV files single-threaded.
Public Member Functions inherited from duckdb::GlobalTableFunctionState
virtual idx_t MaxThreads () const
template<class TARGET>
TARGET & Cast ()
template<class TARGET>
const TARGET & Cast () const

Private Attributes

ClientContext & context
 Reference to the client context that created this scan.
const MultiFileBindData & bind_data
string sniffer_mismatch_error
bool initialized = false
bool single_threaded = false
atomic< idx_t > scanner_idx
shared_ptr< CSVBufferUsage > current_buffer_in_use
CSVIterator current_boundary
 We hold information on the current scanner boundary.
vector< idx_t > rejects_file_indexes

Additional Inherited Members

Static Public Attributes inherited from duckdb::GlobalTableFunctionState
static constexpr const int64_t MAX_THREADS = 999999999

Detailed Description

CSV Global State is used in the CSV Reader Table Function, it controls what each thread.

Constructor & Destructor Documentation

◆ CSVGlobalState()

duckdb::CSVGlobalState::CSVGlobalState ( ClientContext & context_p,
const CSVReaderOptions & options,
idx_t total_file_count,
const MultiFileBindData & bind_data )
175344 : context(context_p), bind_data(bind_data), sniffer_mismatch_error(options.sniffer_user_mismatch_error) {
175345 // There are situations where we only support single threaded scanning
175346 auto system_threads = context.db->NumberOfThreads();
175347 bool many_csv_files = total_file_count > 1 && total_file_count > system_threads * 2;
175348 single_threaded = many_csv_files || !options.parallel;
175349 scanner_idx = 0;
175350 initialized = false;
175351}
ClientContext & context
Reference to the client context that created this scan.
Definition duckdb.cpp:174825

◆ ~CSVGlobalState()

duckdb::CSVGlobalState::~CSVGlobalState ( )
inlineoverride
174805 {
174806 }

Member Function Documentation

◆ FinishScan()

void duckdb::CSVGlobalState::FinishScan ( unique_ptr< StringValueScanner > scanner)

Generates a CSV Scanner, with information regarding the piece of buffer it should be read. In case it returns a nullptr it means we are done reading these files.

175364 {
175365 if (!scanner) {
175366 return;
175367 }
175368 // We have to insert information for validation
175369 auto previous_file = scanner->csv_file_scan;
175370 previous_file->validator.Insert(scanner->scanner_idx, scanner->GetValidationLine());
175371 scanner.reset();
175372 FinishTask(*previous_file);
175373}

◆ Next()

unique_ptr< StringValueScanner > duckdb::CSVGlobalState::Next ( shared_ptr< CSVFileScan > & file)
175375 {
175376 auto &current_file = *current_file_ptr;
175377 if (!initialized) {
175378 // initialize the boundary for this file
175379 current_boundary = current_file.start_iterator;
175380 current_boundary.SetCurrentBoundaryToPosition(single_threaded, current_file.options);
175381 if (current_boundary.done && context.client_data->debug_set_max_line_length) {
175382 context.client_data->debug_max_line_length =
175383 MaxValue<idx_t>(context.client_data->debug_max_line_length, current_boundary.pos.buffer_pos);
175384 }
175385 current_buffer_in_use =
175386 make_shared_ptr<CSVBufferUsage>(*current_file.buffer_manager, current_boundary.GetBufferIdx());
175387 initialized = true;
175388 } else {
175389 // produce the next boundary for this file
175390 if (current_boundary.done || !current_boundary.Next(*current_file.buffer_manager, current_file.options)) {
175391 // finished processing this file - return
175392 return nullptr;
175393 }
175394 }
175395 // create the scanner for this file
175396 if (current_buffer_in_use->buffer_idx != current_boundary.GetBufferIdx()) {
175397 current_buffer_in_use =
175398 make_shared_ptr<CSVBufferUsage>(*current_file.buffer_manager, current_boundary.GetBufferIdx());
175399 }
175400 ++current_file.started_tasks;
175401 // We first create the scanner for the current boundary
175402 auto csv_scanner =
175403 make_uniq<StringValueScanner>(scanner_idx++, current_file.buffer_manager, current_file.state_machine,
175404 current_file.error_handler, current_file_ptr, false, current_boundary);
175405
175406 csv_scanner->buffer_tracker = current_buffer_in_use;
175407 // We initialize the scan
175408 return csv_scanner;
175409}
CSVIterator current_boundary
We hold information on the current scanner boundary.
Definition duckdb.cpp:174839

◆ FinishLaunchingTasks()

void duckdb::CSVGlobalState::FinishLaunchingTasks ( CSVFileScan & scan)
175411 {
175412 initialized = false;
175413 current_buffer_in_use.reset();
175414 // we are finished launching tasks for this file
175415 // finish a task to indicate we can begin cleanup once all scans are done
175416 FinishTask(file);
175417}

◆ FillRejectsTable()

void duckdb::CSVGlobalState::FillRejectsTable ( CSVFileScan & scan)
175503 {
175504 auto &csv_data = bind_data.bind_data->Cast<ReadCSVData>();
175505 auto &options = csv_data.options;
175506
175507 if (!options.store_rejects.GetValue()) {
175508 return;
175509 }
175510 auto limit = options.rejects_limit;
175511 auto rejects = CSVRejectsTable::GetOrCreate(context, options.rejects_scan_name.GetValue(),
175512 options.rejects_table_name.GetValue());
175513 const lock_guard<mutex> lock(rejects->write_lock);
175514 auto &errors_table = rejects->GetErrorsTable(context);
175515 auto &scans_table = rejects->GetScansTable(context);
175516 InternalAppender errors_appender(context, errors_table);
175517 InternalAppender scans_appender(context, scans_table);
175518 idx_t scan_idx = context.transaction.GetActiveQuery();
175519
175520 // get the file indexes for the rejects table
175521 // we store these so that they are deterministic (i.e. file index 0 always gets the lowest rejects index)
175522 // otherwise parallelism can result in out-of-order file indexes
175523 auto file_idx = scan.GetFileIndex();
175524 for (idx_t i = rejects_file_indexes.size(); i <= file_idx; i++) {
175525 rejects_file_indexes.push_back(rejects->GetCurrentFileIndex(scan_idx));
175526 }
175527 const idx_t rejects_file_idx = rejects_file_indexes[file_idx];
175528 scan.error_handler->FillRejectsTable(errors_appender, rejects_file_idx, scan_idx, scan, *rejects, bind_data, limit);
175529 if (rejects->count != 0) {
175530 rejects->count = 0;
175531 FillScanErrorTable(scans_appender, scan_idx, rejects_file_idx, scan);
175532 }
175533 errors_appender.Close();
175534 scans_appender.Close();
175535}
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237

◆ FinishTask()

void duckdb::CSVGlobalState::FinishTask ( CSVFileScan & scan)
175353 {
175354 auto started_tasks = scan.started_tasks.load();
175355 auto finished_tasks = ++scan.finished_tasks;
175356 if (finished_tasks == started_tasks) {
175357 // all scans finished for this file
175358 FinishFile(scan);
175359 } else if (finished_tasks > scan.started_tasks) {
175360 throw InternalException("Finished more tasks than were started for this file");
175361 }
175362}

◆ FinishFile()

void duckdb::CSVGlobalState::FinishFile ( CSVFileScan & scan)
175419 {
175420 if (current_buffer_in_use && RefersToSameObject(current_buffer_in_use->buffer_manager, *scan.buffer_manager)) {
175421 current_buffer_in_use.reset();
175422 }
175423 scan.Finish();
175424 auto &csv_data = bind_data.bind_data->Cast<ReadCSVData>();
175425 const bool ignore_or_store_errors =
175426 csv_data.options.ignore_errors.GetValue() || csv_data.options.store_rejects.GetValue();
175427 if (!single_threaded && !ignore_or_store_errors) {
175428 // If we are running multithreaded and not ignoring errors, we must run the validator
175429 scan.validator.Verify();
175430 }
175431 scan.error_handler->ErrorIfAny();
175432 FillRejectsTable(scan);
175433 if (context.client_data->debug_set_max_line_length) {
175434 context.client_data->debug_max_line_length =
175435 MaxValue<idx_t>(context.client_data->debug_max_line_length, scan.error_handler->GetMaxLineLength());
175436 }
175437}
bool RefersToSameObject(const reference< T > &a, const reference< T > &b)
Returns whether or not two reference wrappers refer to the same object.
Definition duckdb.hpp:2191

◆ SingleThreadedRead()

bool duckdb::CSVGlobalState::SingleThreadedRead ( ) const
inline

Whether or not to read individual CSV files single-threaded.

174819 {
174820 return single_threaded;
174821 }

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