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

Public Member Functions

 CSVRejectsTable (string rejects_scan, string rejects_error)
void InitializeTable (ClientContext &context, const ReadCSVData &options)
TableCatalogEntry & GetErrorsTable (ClientContext &context)
TableCatalogEntry & GetScansTable (ClientContext &context)
idx_t GetCurrentFileIndex (idx_t query_id)
string GetObjectType () override
optional_idx GetEstimatedCacheMemory () const override

Static Public Member Functions

static shared_ptr< CSVRejectsTable > GetOrCreate (ClientContext &context, const string &rejects_scan, const string &rejects_error)
static string ObjectType ()

Public Attributes

mutex write_lock
string name
idx_t count
string scan_table
string errors_table

Private Attributes

idx_t current_file_idx = 0
 Current File Index being used in the query.
idx_t current_query_id = 0
 Current Query ID being executed.

Constructor & Destructor Documentation

◆ CSVRejectsTable()

duckdb::CSVRejectsTable::CSVRejectsTable ( string rejects_scan,
string rejects_error )
inline
174873 : count(0), scan_table(std::move(rejects_scan)), errors_table(std::move(rejects_error)) {
174874 }

Member Function Documentation

◆ GetOrCreate()

shared_ptr< CSVRejectsTable > duckdb::CSVRejectsTable::GetOrCreate ( ClientContext & context,
const string & rejects_scan,
const string & rejects_error )
static
191515 {
191516 // Check that these names can't be the same
191517 if (rejects_scan == rejects_error) {
191518 throw BinderException("The names of the rejects scan and rejects error tables can't be the same. Use different "
191519 "names for these tables.");
191520 }
191521 auto key =
191522 "CSV_REJECTS_TABLE_CACHE_ENTRY_" + StringUtil::Upper(rejects_scan) + "_" + StringUtil::Upper(rejects_error);
191523 auto &cache = ObjectCache::GetObjectCache(context);
191524 auto &catalog = Catalog::GetCatalog(context, TEMP_CATALOG);
191525 auto rejects_scan_exist = catalog.GetEntry<TableCatalogEntry>(context, DEFAULT_SCHEMA, rejects_scan,
191526 OnEntryNotFound::RETURN_NULL) != nullptr;
191527 auto rejects_error_exist = catalog.GetEntry<TableCatalogEntry>(context, DEFAULT_SCHEMA, rejects_error,
191528 OnEntryNotFound::RETURN_NULL) != nullptr;
191529 if ((rejects_scan_exist || rejects_error_exist) && !cache.Get<CSVRejectsTable>(key)) {
191530 std::ostringstream error;
191531 if (rejects_scan_exist) {
191532 error << "Reject Scan Table name \"" << rejects_scan << "\" is already in use. ";
191533 }
191534 if (rejects_error_exist) {
191535 error << "Reject Error Table name \"" << rejects_error << "\" is already in use. ";
191536 }
191537 error << "Either drop the used name(s), or give other name options in the CSV Reader function.\n";
191538 throw BinderException(error.str());
191539 }
191540
191541 return cache.GetOrCreate<CSVRejectsTable>(key, rejects_scan, rejects_error);
191542}
static DUCKDB_API Catalog & GetCatalog(ClientContext &context, const string &catalog_name)
Get the specified Catalog from the ClientContext.
Definition duckdb.cpp:7211
static DUCKDB_API string Upper(const string &str)
Convert a string to UPPERCASE.
Definition duckdb.cpp:109624

◆ InitializeTable()

void duckdb::CSVRejectsTable::InitializeTable ( ClientContext & context,
const ReadCSVData & options )
191544 {
191545 // (Re)Create the temporary rejects table
191546 auto &catalog = Catalog::GetCatalog(context, TEMP_CATALOG);
191547
191548 // Create CSV_ERROR_TYPE ENUM
191549 string enum_name = "CSV_ERROR_TYPE";
191550 constexpr uint8_t number_of_accepted_errors = 7;
191551 Vector order_errors(LogicalType::VARCHAR, number_of_accepted_errors);
191552 order_errors.SetValue(0, "CAST");
191553 order_errors.SetValue(1, "MISSING COLUMNS");
191554 order_errors.SetValue(2, "TOO MANY COLUMNS");
191555 order_errors.SetValue(3, "UNQUOTED VALUE");
191556 order_errors.SetValue(4, "LINE SIZE OVER MAXIMUM");
191557 order_errors.SetValue(5, "INVALID ENCODING");
191558 order_errors.SetValue(6, "INVALID STATE");
191559
191560 LogicalType enum_type = LogicalType::ENUM(enum_name, order_errors, number_of_accepted_errors);
191561 auto type_info = make_uniq<CreateTypeInfo>(enum_name, enum_type);
191562 type_info->temporary = true;
191563 type_info->on_conflict = OnCreateConflict::IGNORE_ON_CONFLICT;
191564 catalog.CreateType(context, *type_info);
191565
191566 // Create Rejects Scans Table
191567 {
191568 auto info = make_uniq<CreateTableInfo>(TEMP_CATALOG, DEFAULT_SCHEMA, scan_table);
191569 info->temporary = true;
191570 info->on_conflict = OnCreateConflict::IGNORE_ON_CONFLICT;
191571 // 0. Scan ID
191572 info->columns.AddColumn(ColumnDefinition("scan_id", LogicalType::UBIGINT));
191573 // 1. File ID (within the scan)
191574 info->columns.AddColumn(ColumnDefinition("file_id", LogicalType::UBIGINT));
191575 // 2. File Path
191576 info->columns.AddColumn(ColumnDefinition("file_path", LogicalType::VARCHAR));
191577 // 3. Delimiter
191578 info->columns.AddColumn(ColumnDefinition("delimiter", LogicalType::VARCHAR));
191579 // 4. Quote
191580 info->columns.AddColumn(ColumnDefinition("quote", LogicalType::VARCHAR));
191581 // 5. Escape
191582 info->columns.AddColumn(ColumnDefinition("escape", LogicalType::VARCHAR));
191583 // 6. NewLine Delimiter
191584 info->columns.AddColumn(ColumnDefinition("newline_delimiter", LogicalType::VARCHAR));
191585 // 7. Skip Rows
191586 info->columns.AddColumn(ColumnDefinition("skip_rows", LogicalType::UINTEGER));
191587 // 8. Has Header
191588 info->columns.AddColumn(ColumnDefinition("has_header", LogicalType::BOOLEAN));
191589 // 9. List<Struct<Column-Name:Types>>
191590 info->columns.AddColumn(ColumnDefinition("columns", LogicalType::VARCHAR));
191591 // 10. Date Format
191592 info->columns.AddColumn(ColumnDefinition("date_format", LogicalType::VARCHAR));
191593 // 11. Timestamp Format
191594 info->columns.AddColumn(ColumnDefinition("timestamp_format", LogicalType::VARCHAR));
191595 // 12. CSV read function with all the options used
191596 info->columns.AddColumn(ColumnDefinition("user_arguments", LogicalType::VARCHAR));
191597 catalog.CreateTable(context, std::move(info));
191598 }
191599 {
191600 // Create Rejects Error Table
191601 auto info = make_uniq<CreateTableInfo>(TEMP_CATALOG, DEFAULT_SCHEMA, errors_table);
191602 info->temporary = true;
191603 info->on_conflict = OnCreateConflict::IGNORE_ON_CONFLICT;
191604 // 0. Scan ID
191605 info->columns.AddColumn(ColumnDefinition("scan_id", LogicalType::UBIGINT));
191606 // 1. File ID (within the scan)
191607 info->columns.AddColumn(ColumnDefinition("file_id", LogicalType::UBIGINT));
191608 // 2. Row Line
191609 info->columns.AddColumn(ColumnDefinition("line", LogicalType::UBIGINT));
191610 // 3. Byte Position of the start of the line
191611 info->columns.AddColumn(ColumnDefinition("line_byte_position", LogicalType::UBIGINT));
191612 // 4. Byte Position where error occurred
191613 info->columns.AddColumn(ColumnDefinition("byte_position", LogicalType::UBIGINT));
191614 // 5. Column Index (If Applicable)
191615 info->columns.AddColumn(ColumnDefinition("column_idx", LogicalType::UBIGINT));
191616 // 6. Column Name (If Applicable)
191617 info->columns.AddColumn(ColumnDefinition("column_name", LogicalType::VARCHAR));
191618 // 7. Error Type
191619 info->columns.AddColumn(ColumnDefinition("error_type", enum_type));
191620 // 8. Original CSV Line
191621 info->columns.AddColumn(ColumnDefinition("csv_line", LogicalType::VARCHAR));
191622 // 9. Full Error Message
191623 info->columns.AddColumn(ColumnDefinition("error_message", LogicalType::VARCHAR));
191624 catalog.CreateTable(context, std::move(info));
191625 }
191626
191627 count = 0;
191628}
::uint8_t uint8_t

◆ GetErrorsTable()

TableCatalogEntry & duckdb::CSVRejectsTable::GetErrorsTable ( ClientContext & context)
191494 {
191495 auto &temp_catalog = Catalog::GetCatalog(context, TEMP_CATALOG);
191496 auto &table_entry = temp_catalog.GetEntry<TableCatalogEntry>(context, TEMP_CATALOG, DEFAULT_SCHEMA, errors_table);
191497 return table_entry;
191498}

◆ GetScansTable()

TableCatalogEntry & duckdb::CSVRejectsTable::GetScansTable ( ClientContext & context)
191500 {
191501 auto &temp_catalog = Catalog::GetCatalog(context, TEMP_CATALOG);
191502 auto &table_entry = temp_catalog.GetEntry<TableCatalogEntry>(context, TEMP_CATALOG, DEFAULT_SCHEMA, scan_table);
191503 return table_entry;
191504}

◆ GetCurrentFileIndex()

idx_t duckdb::CSVRejectsTable::GetCurrentFileIndex ( idx_t query_id)
191506 {
191507 if (current_query_id != query_id) {
191508 current_query_id = query_id;
191509 current_file_idx = 0;
191510 }
191511 return current_file_idx++;
191512}
idx_t current_file_idx
Current File Index being used in the query.
Definition duckdb.cpp:174905
idx_t current_query_id
Current Query ID being executed.
Definition duckdb.cpp:174907

◆ ObjectType()

string duckdb::CSVRejectsTable::ObjectType ( )
inlinestatic
174890 {
174891 return "csv_rejects_table_cache";
174892 }

◆ GetObjectType()

string duckdb::CSVRejectsTable::GetObjectType ( )
inlineoverridevirtual

Implements duckdb::ObjectCacheEntry.

174894 {
174895 return ObjectType();
174896 }

◆ GetEstimatedCacheMemory()

optional_idx duckdb::CSVRejectsTable::GetEstimatedCacheMemory ( ) const
inlineoverridevirtual

Get the rough cache memory usage in bytes for this entry. Used for eviction decisions. Return invalid index to prevent eviction.

Implements duckdb::ObjectCacheEntry.

174899 {
174900 return optional_idx {};
174901 }

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