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

Public Member Functions

DUCKDB_API Appender (Connection &con, const string &database_name, const string &schema_name, const string &table_name, const idx_t flush_memory_threshold=DConstants::INVALID_INDEX)
DUCKDB_API Appender (Connection &con, const string &schema_name, const string &table_name, const idx_t flush_memory_threshold=DConstants::INVALID_INDEX)
DUCKDB_API Appender (Connection &con, const string &table_name, const idx_t flush_memory_threshold=DConstants::INVALID_INDEX)
void AppendDefault () override
void AppendDefault (DataChunk &chunk, idx_t col, idx_t row) override
void AddColumn (const string &name) override
 Appends a column to the active column list. Immediately flushes all previous data.
void ClearColumns () override
 Removes all columns from the active column list. Immediately flushes all previous data.
vector< string > GetExpectedNames ()
 Get the expected names based on the active columns.
Public Member Functions inherited from duckdb::BaseAppender
DUCKDB_API void BeginRow ()
 Begins a new row append, after calling this the other AppendX() functions should be called the correct amount of times. After that, EndRow() should be called.
DUCKDB_API void EndRow ()
 Finishes appending the current row.
template<class T>
void Append (T value)=delete
DUCKDB_API void Append (DataChunk &target, const Value &value, idx_t col, idx_t row)
DUCKDB_API void Append (const char *value, uint32_t length)
template<typename... ARGS>
void AppendRow (ARGS... args)
DUCKDB_API void Flush ()
 Commit the changes made by the appender.
DUCKDB_API void Close ()
 Flush the changes made by the appender and close it. The appender cannot be used after this point.
DUCKDB_API void Clear ()
 Clears any appended data (without flushing).
const vector< LogicalType > & GetActiveTypes () const
 Returns the active types of the appender.
idx_t CurrentColumn () const
DUCKDB_API void AppendDataChunk (DataChunk &value)
template<>
void Append (bool value)
template<>
void Append (int8_t value)
template<>
void Append (int16_t value)
template<>
void Append (int32_t value)
template<>
void Append (int64_t value)
template<>
void Append (hugeint_t value)
template<>
void Append (uhugeint_t value)
template<>
void Append (uint8_t value)
template<>
void Append (uint16_t value)
template<>
void Append (uint32_t value)
template<>
void Append (uint64_t value)
template<>
void Append (const char *value)
template<>
void Append (string_t value)
template<>
void Append (float value)
template<>
void Append (double value)
template<>
void Append (date_t value)
template<>
void Append (dtime_t value)
template<>
void Append (timestamp_t value)
template<>
void Append (interval_t value)
template<>
void Append (Value value)
template<>
void Append (std::nullptr_t value)
template<>
DUCKDB_API void Append (bool value)
template<>
DUCKDB_API void Append (int8_t value)
template<>
DUCKDB_API void Append (int16_t value)
template<>
DUCKDB_API void Append (int32_t value)
template<>
DUCKDB_API void Append (int64_t value)
template<>
DUCKDB_API void Append (hugeint_t value)
template<>
DUCKDB_API void Append (uhugeint_t value)
template<>
DUCKDB_API void Append (uint8_t value)
template<>
DUCKDB_API void Append (uint16_t value)
template<>
DUCKDB_API void Append (uint32_t value)
template<>
DUCKDB_API void Append (uint64_t value)
template<>
DUCKDB_API void Append (float value)
template<>
DUCKDB_API void Append (double value)
template<>
DUCKDB_API void Append (date_t value)
template<>
DUCKDB_API void Append (dtime_t value)
template<>
DUCKDB_API void Append (timestamp_t value)
template<>
DUCKDB_API void Append (interval_t value)
template<>
DUCKDB_API void Append (const char *value)
template<>
DUCKDB_API void Append (string_t value)
template<>
DUCKDB_API void Append (Value value)
template<>
DUCKDB_API void Append (std::nullptr_t value)

Static Public Member Functions

static string ConstructQuery (TableDescription &description_p, const string &table_name, const vector< string > &expected_names)
 Construct a query that appends data from, typically, a column data collection.
Static Public Member Functions inherited from duckdb::BaseAppender
static unique_ptr< TableRef > GetColumnDataTableRef (ColumnDataCollection &collection, const string &table_name, const vector< string > &expected_names)
 Returns a table reference to the appended data.
static unique_ptr< SQLStatement > ParseStatement (unique_ptr< TableRef > table_ref, const string &query, const string &table_name)
 Parses the statement to append data.

Protected Member Functions

void FlushInternal (ColumnDataCollection &collection) override
Value GetDefaultValue (idx_t column)
Protected Member Functions inherited from duckdb::BaseAppender
DUCKDB_API BaseAppender (Allocator &allocator, const AppenderType type)
DUCKDB_API BaseAppender (Allocator &allocator, vector< LogicalType > types, const AppenderType type, const idx_t flush_count=DEFAULT_FLUSH_COUNT)
void Destructor ()
virtual void FlushInternal (ColumnDataCollection &collection)=0
void InitializeChunk ()
void FlushChunk ()
bool ShouldFlushChunk () const
bool ShouldFlush () const
template<class T>
void AppendValueInternal (T value)
template<class SRC, class DST>
void AppendValueInternal (Vector &vector, SRC input)
template<class SRC, class DST>
void AppendDecimalValueInternal (Vector &vector, SRC input)
void AppendRowRecursive ()
template<typename T, typename... ARGS>
void AppendRowRecursive (T value, ARGS... args)
void AppendValue (const Value &value)
void AppendValue (DataChunk target, const Value &value)

Private Attributes

weak_ptr< ClientContext > context
 A shared pointer to the context of this appender.
unique_ptr< TableDescription > description
 The table description including the column names.
unordered_map< column_t, Value > default_values
 All table default values.
vector< LogicalIndex > column_ids
 If not empty, then this holds all logical column IDs of columns provided by the appender. Any other columns default to NULL, or their default values.

Additional Inherited Members

Static Public Attributes inherited from duckdb::BaseAppender
static constexpr const idx_t DEFAULT_FLUSH_COUNT = STANDARD_VECTOR_SIZE * 100ULL
 The amount of tuples that are gathered in the column data collection before flushing.
Protected Attributes inherited from duckdb::BaseAppender
Allocator & allocator
 The allocator for the column data collection.
vector< LogicalType > types
 The column types of the associated table.
vector< LogicalType > active_types
 The active column types.
unique_ptr< ColumnDataCollection > collection
 The buffered to-be-appended data.
DataChunk chunk
 The active chunk for row-based appends.
idx_t column = 0
 The currently active column of row-based appends.
AppenderType appender_type
 The type of the appender.
idx_t flush_count = DEFAULT_FLUSH_COUNT
 The amount of rows after which the appender flushes automatically.
optional_idx flush_memory_threshold
 Peak allocation threshold at which to flush the allocator when appender flushs chunk.

Constructor & Destructor Documentation

◆ Appender() [1/3]

duckdb::Appender::Appender ( Connection & con,
const string & database_name,
const string & schema_name,
const string & table_name,
const idx_t flush_memory_threshold = DConstants::INVALID_INDEX )
261776 : BaseAppender(Allocator::DefaultAllocator(), AppenderType::LOGICAL), context(con.context) {
261777 flush_memory_threshold = (flush_memory_threshold_p == DConstants::INVALID_INDEX)
261778 ? optional_idx::Invalid()
261779 : optional_idx(flush_memory_threshold_p);
261780
261781 description = con.TableInfo(database_name, schema_name, table_name);
261782 if (!description) {
261783 throw CatalogException(
261784 StringUtil::Format("Table \"%s.%s.%s\" could not be found", database_name, schema_name, table_name));
261785 }
261786 if (description->readonly) {
261787 throw InvalidInputException("Cannot append to a readonly database.");
261788 }
261789
261790 vector<optional_ptr<const ParsedExpression>> defaults;
261791 for (auto &column : description->columns) {
261792 if (column.Generated()) {
261793 continue;
261794 }
261795 types.push_back(column.Type());
261796 defaults.push_back(column.HasDefaultValue() ? &column.DefaultValue() : nullptr);
261797 }
261798 auto &context_ref = *con.context;
261799 auto binder = Binder::CreateBinder(context_ref);
261800 context_ref.RunFunctionInTransaction([&]() {
261801 for (idx_t i = 0; i < types.size(); i++) {
261802 auto &type = types[i];
261803 auto &expr = defaults[i];
261804
261805 if (!expr) {
261806 // The default value is NULL.
261807 default_values[i] = Value(type);
261808 continue;
261809 }
261810
261811 auto default_copy = expr->Copy();
261812 D_ASSERT(!default_copy->HasParameter());
261813
261814 ConstantBinder default_binder(*binder, context_ref, "DEFAULT value");
261815 default_binder.target_type = type;
261816 auto bound_default = default_binder.Bind(default_copy);
261817
261818 if (!bound_default->IsFoldable()) {
261819 // Not supported yet.
261820 continue;
261821 }
261822
261823 Value result_value;
261824 auto eval_success = ExpressionExecutor::TryEvaluateScalar(context_ref, *bound_default, result_value);
261825 // Insert the default Value.
261826 if (eval_success) {
261827 default_values[i] = result_value;
261828 }
261829 }
261830 });
261831
261832 InitializeChunk();
261833 collection = make_uniq<ColumnDataCollection>(allocator, GetActiveTypes());
261834}
unique_ptr< TableDescription > description
The table description including the column names.
Definition duckdb.hpp:54460
unordered_map< column_t, Value > default_values
All table default values.
Definition duckdb.hpp:54462
weak_ptr< ClientContext > context
A shared pointer to the context of this appender.
Definition duckdb.hpp:54458
const vector< LogicalType > & GetActiveTypes() const
Returns the active types of the appender.
Definition duckdb.cpp:261335
idx_t column
The currently active column of row-based appends.
Definition duckdb.hpp:54345
Allocator & allocator
The allocator for the column data collection.
Definition duckdb.hpp:54335
vector< LogicalType > types
The column types of the associated table.
Definition duckdb.hpp:54337
optional_idx flush_memory_threshold
Peak allocation threshold at which to flush the allocator when appender flushs chunk.
Definition duckdb.hpp:54351
unique_ptr< ColumnDataCollection > collection
The buffered to-be-appended data.
Definition duckdb.hpp:54341
DUCKDB_API unique_ptr< TableDescription > TableInfo(const string &database_name, const string &schema_name, const string &table_name)
Get the table info of a specific table, or nullptr if it cannot be found.
Definition duckdb.cpp:275938
static DUCKDB_API bool TryEvaluateScalar(ClientContext &context, const Expression &expr, Value &result)
Try to evaluate a scalar expression and fold it into a single value, returns false if an exception is...
Definition duckdb.cpp:150008
static string Format(const string fmt_str, ARGS... params)
Format a string using printf semantics.
Definition duckdb.hpp:4002
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237
static constexpr const idx_t INVALID_INDEX
The value used to signify an invalid index entry.
Definition duckdb.hpp:1117

◆ Appender() [2/3]

duckdb::Appender::Appender ( Connection & con,
const string & schema_name,
const string & table_name,
const idx_t flush_memory_threshold = DConstants::INVALID_INDEX )
261838 : Appender(con, INVALID_CATALOG, schema_name, table_name, flush_memory_threshold_p) {
261839}

◆ Appender() [3/3]

duckdb::Appender::Appender ( Connection & con,
const string & table_name,
const idx_t flush_memory_threshold = DConstants::INVALID_INDEX )
261842 : Appender(con, INVALID_CATALOG, DEFAULT_SCHEMA, table_name, flush_memory_threshold_p) {
261843}

◆ ~Appender()

duckdb::Appender::~Appender ( )
override
261845 {
261846 Destructor();
261847}

Member Function Documentation

◆ AppendDefault() [1/2]

void duckdb::Appender::AppendDefault ( )
overridevirtual

Reimplemented from duckdb::BaseAppender.

261898 {
261899 auto value = GetDefaultValue(column);
261900 Append(value);
261901}

◆ AppendDefault() [2/2]

void duckdb::Appender::AppendDefault ( DataChunk & chunk,
idx_t col,
idx_t row )
overridevirtual

Reimplemented from duckdb::BaseAppender.

261903 {
261904 auto value = GetDefaultValue(col);
261905 Append(chunk, value, col, row);
261906}
DataChunk chunk
The active chunk for row-based appends.
Definition duckdb.hpp:54343

◆ AddColumn()

void duckdb::Appender::AddColumn ( const string & name)
overridevirtual

Appends a column to the active column list. Immediately flushes all previous data.

Reimplemented from duckdb::BaseAppender.

261927 {
261928 Flush();
261929
261930 auto exists = false;
261931 for (idx_t col_idx = 0; col_idx < description->columns.size(); col_idx++) {
261932 auto &col_def = description->columns[col_idx];
261933 if (col_def.Name() != name) {
261934 continue;
261935 }
261936
261937 // Ensure that we are not adding a generated column.
261938 if (col_def.Generated()) {
261939 throw InvalidInputException("cannot add a generated column to the appender");
261940 }
261941
261942 // Ensure that we haven't added this column before.
261943 for (const auto &column_id : column_ids) {
261944 if (column_id == col_def.Logical()) {
261945 throw InvalidInputException("cannot add the same column twice");
261946 }
261947 }
261948
261949 active_types.push_back(col_def.Type());
261950 column_ids.push_back(col_def.Logical());
261951 exists = true;
261952 break;
261953 }
261954 if (!exists) {
261955 throw InvalidInputException("the column must exist in the table");
261956 }
261957
261958 InitializeChunk();
261959 collection = make_uniq<ColumnDataCollection>(allocator, GetActiveTypes());
261960}
vector< LogicalIndex > column_ids
If not empty, then this holds all logical column IDs of columns provided by the appender....
Definition duckdb.hpp:54466
vector< LogicalType > active_types
The active column types.
Definition duckdb.hpp:54339
DUCKDB_API void Flush()
Commit the changes made by the appender.
Definition duckdb.cpp:261681
bool exists(const cv::String &path)

◆ ClearColumns()

void duckdb::Appender::ClearColumns ( )
overridevirtual

Removes all columns from the active column list. Immediately flushes all previous data.

Reimplemented from duckdb::BaseAppender.

261962 {
261963 Flush();
261964 column_ids.clear();
261965 active_types.clear();
261966
261967 InitializeChunk();
261968 collection = make_uniq<ColumnDataCollection>(allocator, GetActiveTypes());
261969}

◆ GetExpectedNames()

vector< string > duckdb::Appender::GetExpectedNames ( )

Get the expected names based on the active columns.

261849 {
261850 vector<string> expected_names;
261851 for (idx_t i = 0; i < column_ids.size(); i++) {
261852 auto &col_name = description->columns[column_ids[i].index].Name();
261853 expected_names.push_back(col_name);
261854 }
261855 return expected_names;
261856}

◆ ConstructQuery()

string duckdb::Appender::ConstructQuery ( TableDescription & description_p,
const string & table_name,
const vector< string > & expected_names )
static

Construct a query that appends data from, typically, a column data collection.

261859 {
261860 string query = "INSERT INTO ";
261861 if (!description_p.database.empty()) {
261862 query += StringUtil::Format("%s.", SQLIdentifier(description_p.database));
261863 }
261864 if (!description_p.schema.empty()) {
261865 query += StringUtil::Format("%s.", SQLIdentifier(description_p.schema));
261866 }
261867 query += StringUtil::Format("%s", SQLIdentifier(description_p.table));
261868 if (!expected_names.empty()) {
261869 query += "(";
261870 for (idx_t i = 0; i < expected_names.size(); i++) {
261871 if (i > 0) {
261872 query += ", ";
261873 }
261874 query += StringUtil::Format("%s", SQLIdentifier(expected_names[i]));
261875 }
261876 query += ")";
261877 }
261878 query += " FROM ";
261879 query += table_name;
261880 return query;
261881}
string schema
The schema of the table.
Definition duckdb.hpp:41356
string table
The name of the table.
Definition duckdb.hpp:41358
string database
The database of the table.
Definition duckdb.hpp:41354

◆ FlushInternal()

void duckdb::Appender::FlushInternal ( ColumnDataCollection & collection)
overrideprotected
261883 {
261884 auto context_ref = context.lock();
261885 if (!context_ref) {
261886 throw InvalidInputException("Appender: Attempting to flush data to a closed connection");
261887 }
261888
261889 string table_name = "__duckdb_internal_appended_data";
261890 auto expected_names = GetExpectedNames();
261891 auto query = ConstructQuery(*description, table_name, expected_names);
261892
261893 auto table_ref = GetColumnDataTableRef(collection, table_name, expected_names);
261894 auto stmt = ParseStatement(std::move(table_ref), query, table_name);
261895 context_ref->Append(std::move(stmt));
261896}
weak_ptr< ClientContext > context
A shared pointer to the context of this appender.
Definition duckdb.hpp:54458
vector< string > GetExpectedNames()
Get the expected names based on the active columns.
Definition duckdb.cpp:261849
static string ConstructQuery(TableDescription &description_p, const string &table_name, const vector< string > &expected_names)
Construct a query that appends data from, typically, a column data collection.
Definition duckdb.cpp:261858
static unique_ptr< TableRef > GetColumnDataTableRef(ColumnDataCollection &collection, const string &table_name, const vector< string > &expected_names)
Returns a table reference to the appended data.
Definition duckdb.cpp:261713
static unique_ptr< SQLStatement > ParseStatement(unique_ptr< TableRef > table_ref, const string &query, const string &table_name)
Parses the statement to append data.
Definition duckdb.cpp:261738

◆ GetDefaultValue()

Value duckdb::Appender::GetDefaultValue ( idx_t column)
protected
261908 {
261909 auto index = column;
261910
261911 if (!column_ids.empty()) {
261912 if (column >= column_ids.size()) {
261913 throw InvalidInputException("Column index out of bounds");
261914 }
261915 index = column_ids[column].index;
261916 }
261917
261918 auto it = default_values.find(index);
261919 if (it == default_values.end()) {
261920 auto &name = description->columns[index].Name();
261921 throw NotImplementedException(
261922 "AppendDefault is not supported for column \"%s\": not a foldable default expressions.", name);
261923 }
261924 return it->second;
261925}
index

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