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

The CSVLogStorage implements an additional layer on the BufferingLogStorage which will handle converting the log entries and contexts to CSV lines. It provides functionality to write log data in CSV format with automatic type casting and configuration of CSV writers. This class serves as a base for both file-based and stdout-based CSV logging. More...

#include <duckdb.hpp>

Inheritance diagram for duckdb::CSVLogStorage:
Collaboration diagram for duckdb::CSVLogStorage:

Public Member Functions

 CSVLogStorage (DatabaseInstance &db, bool normalize, idx_t buffer_size)
Public Member Functions inherited from duckdb::BufferingLogStorage
 BufferingLogStorage (DatabaseInstance &db_p, idx_t buffer_size, bool normalize)
void WriteLogEntry (timestamp_t timestamp, LogLevel level, const string &log_type, const string &log_message, const RegisteredLoggingContext &context) final
 (Partially) Implements LogStorage API
void WriteLogEntries (DataChunk &chunk, const RegisteredLoggingContext &context) final
 Write out the chunk to the buffers.
void FlushAll () final
 Flushes buffers for all tables.
void Flush (LoggingTargetTable table) final
 Flushes buffer for a specific table.
void Truncate () override
 Truncates log storage: both buffers and persistent storage (if applicable).
void UpdateConfig (DatabaseInstance &db, case_insensitive_map_t< Value > &config) override
 Apply a new log storage configuration.
bool IsEnabled (LoggingTargetTable table) override
 Returns whether the table is enabled for this storage.
Public Member Functions inherited from duckdb::LogStorage
virtual const string GetStorageName ()=0
virtual DUCKDB_API bool CanScan (LoggingTargetTable table)
 READING (OPTIONAL).
virtual DUCKDB_API unique_ptr< LogStorageScanState > CreateScanState (LoggingTargetTable table) const
virtual DUCKDB_API bool Scan (LogStorageScanState &state, DataChunk &result) const
virtual DUCKDB_API void InitializeScan (LogStorageScanState &state) const
virtual DUCKDB_API unique_ptr< TableRef > BindReplace (ClientContext &context, TableFunctionBindInput &input, LoggingTargetTable table)

Protected Member Functions

void FlushChunk (LoggingTargetTable table, DataChunk &chunk) final
 Implement the BufferingLogStorage interface.
void ResetAllBuffers () override
 Resets all buffers and state.
void UpdateConfigInternal (DatabaseInstance &db, case_insensitive_map_t< Value > &config) override
 Implements CSVLogStorage specific config handling.
virtual void BeforeFlush (LoggingTargetTable table, DataChunk &chunk)
 Interface to child classes.
virtual void AfterFlush (LoggingTargetTable table, DataChunk &chunk)
void RegisterWriter (LoggingTargetTable table, unique_ptr< CSVWriter > writer)
 Helper functions.
CSVWriter & GetWriter (LoggingTargetTable table)
 Returns the writer for a table.
void SetWriterConfigs (CSVWriter &Writer, vector< string > column_names)
 Configure a CSV writer by initializing its settings with the writer_options and reader_options settings.
CSVWriterOptions & GetCSVWriterOptions ()
 Allows child classes to manipulate options.
CSVReaderOptions & GetCSVReaderOptions ()
 Allows child classes to manipulate options.
Protected Member Functions inherited from duckdb::BufferingLogStorage
void FlushAllInternal ()
 Helper methods.
void FlushInternal (LoggingTargetTable table)
 Flushes one of the tables.
bool IsEnabledInternal (LoggingTargetTable table)
 Whether a specific table is available in the log storage.
idx_t GetBufferLimit () const

Private Member Functions

void ExecuteCast (LoggingTargetTable table, DataChunk &chunk)
 Perform the cast (does not reset input chunk!).
void ResetCastChunk ()
 Reset the Cast chunks.
void InitializeCastChunk (LoggingTargetTable table)
 Initialize the cast chunks.

Private Attributes

map< LoggingTargetTable, unique_ptr< DataChunk > > cast_buffers
 The cast buffers used to cast from the original types to the VARCHAR types ready to write to CSV format.
map< LoggingTargetTable, unique_ptr< CSVWriter > > writers
 The writers to be registered by child classes.
unique_ptr< CSVWriterOptions > writer_options
 CSV Options to initialize the CSVWriters with. TODO: cleanup, this is now a little bit of a mixed bag of settings.
unique_ptr< CSVReaderOptions > reader_options

Additional Inherited Members

Static Public Member Functions inherited from duckdb::LogStorage
static vector< LogicalType > GetSchema (LoggingTargetTable table)
static vector< string > GetColumnNames (LoggingTargetTable table)
Protected Attributes inherited from duckdb::BufferingLogStorage
mutex lock
 lock to be used by this class and child classes to ensure thread safety TODO: maybe remove and delegate thread-safety to LogManager?
bool normalize_contexts = true
 Switches between using false = use LoggingTargetTable::ALL_LOGS, true = use LoggingTargetTable::LOG_ENTIRES + LoggingTargetTable::CONTEXTS.

Detailed Description

The CSVLogStorage implements an additional layer on the BufferingLogStorage which will handle converting the log entries and contexts to CSV lines. It provides functionality to write log data in CSV format with automatic type casting and configuration of CSV writers. This class serves as a base for both file-based and stdout-based CSV logging.

Constructor & Destructor Documentation

◆ CSVLogStorage()

duckdb::CSVLogStorage::CSVLogStorage ( DatabaseInstance & db,
bool normalize,
idx_t buffer_size )
explicit
259997 : BufferingLogStorage(db, buffer_size, normalize) {
259998 reader_options = make_uniq<CSVReaderOptions>();
259999 writer_options = make_uniq<CSVWriterOptions>(*reader_options);
260000
260001 reader_options->dialect_options.state_machine_options.escape = '\"';
260002 reader_options->dialect_options.state_machine_options.quote = '\"';
260003 reader_options->dialect_options.state_machine_options.delimiter = CSVOption<string>("\t");
260004
260005 ResetCastChunk();
260006}
unique_ptr< CSVWriterOptions > writer_options
CSV Options to initialize the CSVWriters with. TODO: cleanup, this is now a little bit of a mixed bag...
Definition duckdb.hpp:39669
void ResetCastChunk()
Reset the Cast chunks.
Definition duckdb.cpp:260094

◆ ~CSVLogStorage()

duckdb::CSVLogStorage::~CSVLogStorage ( )
override
259993 {
259994}

Member Function Documentation

◆ FlushChunk()

void duckdb::CSVLogStorage::FlushChunk ( LoggingTargetTable table,
DataChunk & chunk )
finalprotectedvirtual

Implement the BufferingLogStorage interface.

Flushes the Chunk to the CSV writers

Implements duckdb::BufferingLogStorage.

260117 {
260118 BeforeFlush(table, chunk);
260119
260120 // Execute the cast
260121 ExecuteCast(table, chunk);
260122
260123 // Write the chunk to the CSVWriter
260124 writers[table]->WriteChunk(*cast_buffers[table]);
260125 writers[table]->Flush();
260126
260127 // Call child class to implement any post flushing behaviour (e.g. calling sync)
260128 AfterFlush(table, chunk);
260129
260130 // Reset the cast buffer
260131 cast_buffers[table]->Reset();
260132}
map< LoggingTargetTable, unique_ptr< DataChunk > > cast_buffers
The cast buffers used to cast from the original types to the VARCHAR types ready to write to CSV form...
Definition duckdb.hpp:39663
void ExecuteCast(LoggingTargetTable table, DataChunk &chunk)
Perform the cast (does not reset input chunk!).
Definition duckdb.cpp:260030
map< LoggingTargetTable, unique_ptr< CSVWriter > > writers
The writers to be registered by child classes.
Definition duckdb.hpp:39665
virtual void BeforeFlush(LoggingTargetTable table, DataChunk &chunk)
Interface to child classes.
Definition duckdb.hpp:39638
Here is the call graph for this function:

◆ ResetAllBuffers()

void duckdb::CSVLogStorage::ResetAllBuffers ( )
overrideprotectedvirtual

Resets all buffers and state.

Reimplemented from duckdb::BufferingLogStorage.

260044 {
260046 ResetCastChunk();
260047}
virtual void ResetAllBuffers()
ResetAllBuffers will clear all buffered data. To be overridden by child classes to ensure their buffe...
Definition duckdb.cpp:260455
Here is the call graph for this function:
Here is the caller graph for this function:

◆ UpdateConfigInternal()

void duckdb::CSVLogStorage::UpdateConfigInternal ( DatabaseInstance & db,
case_insensitive_map_t< Value > & config )
overrideprotectedvirtual

Implements CSVLogStorage specific config handling.

Reimplemented from duckdb::BufferingLogStorage.

Reimplemented in duckdb::FileLogStorage.

260049 {
260050 auto config_copy = config;
260051
260052 bool changed_writer_settings = false;
260053
260054 vector<string> to_remove;
260055 for (const auto &it : config_copy) {
260056 auto key = StringUtil::Lower(it.first);
260057 if (key == "delim") {
260058 changed_writer_settings = true;
260059 reader_options->dialect_options.state_machine_options.delimiter = CSVOption<string>(it.second.ToString());
260060 to_remove.push_back(it.first);
260061 }
260062 }
260063
260064 if (changed_writer_settings) {
260065 for (auto &writer : writers) {
260066 SetWriterConfigs(*writer.second, GetColumnNames(writer.first));
260067 }
260068 }
260069
260070 for (const auto &it : to_remove) {
260071 config_copy.erase(it);
260072 }
260073
260074 return BufferingLogStorage::UpdateConfigInternal(db, config_copy);
260075}
virtual void UpdateConfigInternal(DatabaseInstance &db, case_insensitive_map_t< Value > &config)
This method is called in a chained way down the class hierarchy. This allows each class to interpret ...
Definition duckdb.cpp:260134
void SetWriterConfigs(CSVWriter &Writer, vector< string > column_names)
Configure a CSV writer by initializing its settings with the writer_options and reader_options settin...
Definition duckdb.cpp:260100
static DUCKDB_API string Lower(const string &str)
Convert a string to lowercase.
Definition duckdb.cpp:109630
Here is the call graph for this function:
Here is the caller graph for this function:

◆ BeforeFlush()

virtual void duckdb::CSVLogStorage::BeforeFlush ( LoggingTargetTable table,
DataChunk & chunk )
inlineprotectedvirtual

Interface to child classes.

Hooks for child class to run code pre-flush

Reimplemented in duckdb::FileLogStorage.

39638{};
Here is the caller graph for this function:

◆ AfterFlush()

virtual void duckdb::CSVLogStorage::AfterFlush ( LoggingTargetTable table,
DataChunk & chunk )
inlineprotectedvirtual

Reimplemented in duckdb::FileLogStorage.

39639{};

◆ RegisterWriter()

void duckdb::CSVLogStorage::RegisterWriter ( LoggingTargetTable table,
unique_ptr< CSVWriter > writer )
protected

Helper functions.

To be called by child classed to register the CSV writers used to write to.

260077 {
260078 writers[table] = std::move(writer);
260079}
Here is the caller graph for this function:

◆ GetWriter()

CSVWriter & duckdb::CSVLogStorage::GetWriter ( LoggingTargetTable table)
protected

Returns the writer for a table.

260081 {
260082 return *writers[table];
260083}
Here is the caller graph for this function:

◆ SetWriterConfigs()

void duckdb::CSVLogStorage::SetWriterConfigs ( CSVWriter & Writer,
vector< string > column_names )
protected

Configure a CSV writer by initializing its settings with the writer_options and reader_options settings.

260100 {
260101 writer.options = *reader_options;
260102 writer.writer_options = *writer_options;
260103
260104 // Update the config with the column names since that is different per schema
260105 writer.options.name_list = std::move(column_names);
260106 writer.options.force_quote = vector<bool>(writer.options.name_list.size(), false);
260107}
Here is the caller graph for this function:

◆ GetCSVWriterOptions()

CSVWriterOptions & duckdb::CSVLogStorage::GetCSVWriterOptions ( )
protected

Allows child classes to manipulate options.

260113 {
260114 return *writer_options;
260115}

◆ GetCSVReaderOptions()

CSVReaderOptions & duckdb::CSVLogStorage::GetCSVReaderOptions ( )
protected

Allows child classes to manipulate options.

260109 {
260110 return *reader_options;
260111}

◆ ExecuteCast()

void duckdb::CSVLogStorage::ExecuteCast ( LoggingTargetTable table,
DataChunk & chunk )
private

Perform the cast (does not reset input chunk!).

260030 {
260031 // Reset the cast buffer before use
260032 cast_buffers[table]->Reset();
260033
260034 auto &cast_buffer = *cast_buffers[table];
260035 idx_t count = chunk.size();
260036
260037 // Do default casts
260038 for (idx_t i = 0; i < chunk.data.size(); i++) {
260039 VectorOperations::DefaultCast(chunk.data[i], cast_buffer.data[i], count, false);
260040 }
260041 cast_buffer.SetCardinality(count);
260042}
vector< Vector > data
The vectors owned by the DataChunk.
Definition duckdb.hpp:11445
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237
Here is the caller graph for this function:

◆ ResetCastChunk()

void duckdb::CSVLogStorage::ResetCastChunk ( )
private

Reset the Cast chunks.

260094 {
260095 InitializeCastChunk(LoggingTargetTable::LOG_ENTRIES);
260096 InitializeCastChunk(LoggingTargetTable::LOG_CONTEXTS);
260097 InitializeCastChunk(LoggingTargetTable::ALL_LOGS);
260098}
void InitializeCastChunk(LoggingTargetTable table)
Initialize the cast chunks.
Definition duckdb.cpp:260085
Here is the call graph for this function:
Here is the caller graph for this function:

◆ InitializeCastChunk()

void duckdb::CSVLogStorage::InitializeCastChunk ( LoggingTargetTable table)
private

Initialize the cast chunks.

260085 {
260086 cast_buffers[table] = make_uniq<DataChunk>();
260087
260088 vector<LogicalType> types;
260089 types.resize(GetSchema(table).size(), LogicalType::VARCHAR);
260090 idx_t buffer_size = MaxValue<idx_t>(GetBufferLimit(), 1);
260091 cast_buffers[table]->Initialize(Allocator::DefaultAllocator(), types, buffer_size);
260092}
GOpaque< Size > size(const GMat &src)
Here is the caller graph for this function:

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