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

Preprocesses parsed statements: expands pragmas, unpacks multi-statements, and wraps in transactions. More...

Collaboration diagram for duckdb::StatementPreprocessor:

Public Member Functions

 StatementPreprocessor (ClientContext &context)
void Preprocess (ClientContextLock &lock, vector< unique_ptr< SQLStatement > > &statements, CurrentTransactionState transaction_context_state)
void PreprocessInternal (ClientContextLock &lock, vector< unique_ptr< SQLStatement > > &statements, CurrentTransactionState transaction_context_state)

Private Member Functions

vector< unique_ptr< SQLStatement > > TryReparsePragma (unique_ptr< SQLStatement > statement) const

Private Attributes

ClientContext & context

Detailed Description

Preprocesses parsed statements: expands pragmas, unpacks multi-statements, and wraps in transactions.

Constructor & Destructor Documentation

◆ StatementPreprocessor()

duckdb::StatementPreprocessor::StatementPreprocessor ( ClientContext & context)
explicit
383803 : context(context) {
383804}

Member Function Documentation

◆ Preprocess()

void duckdb::StatementPreprocessor::Preprocess ( ClientContextLock & lock,
vector< unique_ptr< SQLStatement > > & statements,
CurrentTransactionState transaction_context_state )
383861 {
383862 // Quick check: do we need preprocessing at all?
383863 bool needs_preprocessing = false;
383864 for (auto &stmt : statements) {
383865 if (stmt->type == StatementType::PRAGMA_STATEMENT || stmt->type == StatementType::MULTI_STATEMENT) {
383866 needs_preprocessing = true;
383867 break;
383868 }
383869 }
383870 if (!needs_preprocessing) {
383871 return;
383872 }
383873
383874 context.RunFunctionInTransactionInternal(lock,
383875 [&] { PreprocessInternal(lock, statements, transaction_context_state); });
383876}

◆ PreprocessInternal()

void duckdb::StatementPreprocessor::PreprocessInternal ( ClientContextLock & lock,
vector< unique_ptr< SQLStatement > > & statements,
CurrentTransactionState transaction_context_state )
383879 {
383880 CurrentTransactionState chained_transaction_state = NOT_IN_ACTIVE_TRANSACTION;
383881 vector<unique_ptr<SQLStatement>> new_statements;
383882 for (idx_t i = 0; i < statements.size(); i++) {
383883 auto query = statements[i]->query;
383884 const CurrentTransactionState full_transaction_state =
383885 (transaction_context_state == IN_ACTIVE_TRANSACTION || chained_transaction_state == IN_ACTIVE_TRANSACTION)
383886 ? IN_ACTIVE_TRANSACTION
383887 : NOT_IN_ACTIVE_TRANSACTION;
383888
383889 switch (statements[i]->type) {
383890 case StatementType::PRAGMA_STATEMENT: {
383891 auto reparsed_statements = TryReparsePragma(std::move(statements[i]));
383892 const auto handling = GetTransactionHandling(reparsed_statements, full_transaction_state);
383893 AddStatements(reparsed_statements, handling, new_statements);
383894 break;
383895 }
383896 case StatementType::MULTI_STATEMENT: {
383897 auto &multi_statement = statements[i]->Cast<MultiStatement>();
383898 UnpackMultiStatement(multi_statement, full_transaction_state, new_statements);
383899 break;
383900 }
383901 case StatementType::TRANSACTION_STATEMENT: {
383902 auto &transaction_stmt = statements[i]->Cast<TransactionStatement>();
383903
383904 if (transaction_stmt.info->type == TransactionType::BEGIN_TRANSACTION) {
383905 new_statements.push_back(std::move(statements[i]));
383906 chained_transaction_state = IN_ACTIVE_TRANSACTION;
383907 break;
383908 }
383909 if (transaction_stmt.info->type == TransactionType::COMMIT ||
383910 transaction_stmt.info->type == TransactionType::ROLLBACK) {
383911 chained_transaction_state = NOT_IN_ACTIVE_TRANSACTION;
383912 }
383913 new_statements.push_back(std::move(statements[i]));
383914 break;
383915 }
383916 default: {
383917 new_statements.push_back(std::move(statements[i]));
383918 }
383919 }
383920 }
383921
383922 statements = std::move(new_statements);
383923}
vector< unique_ptr< SQLStatement > > TryReparsePragma(unique_ptr< SQLStatement > statement) const
Definition duckdb.cpp:383841
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237

◆ TryReparsePragma()

vector< unique_ptr< SQLStatement > > duckdb::StatementPreprocessor::TryReparsePragma ( unique_ptr< SQLStatement > statement) const
private

Handles a pragma statement, determines whether the statement needs reparsing, if it does, it returns the statement(s) to replace the current one. Otherwise, it just returns back the original statement in a vector.

383841 {
383842 // Try reparsing
383843 const auto info = statement->Cast<PragmaStatement>().info->Copy();
383844 QueryErrorContext error_context(statement->stmt_location);
383845 const auto binder = Binder::CreateBinder(context);
383846 const auto bound_info = binder->BindPragma(*info, error_context);
383847 if (bound_info->function.query) {
383848 // Needs reparsing
383849 FunctionParameters parameters {bound_info->parameters, bound_info->named_parameters};
383850 const auto query_to_reparse = bound_info->function.query(context, parameters);
383851 Parser parser(context.GetParserOptions());
383852 parser.ParseQuery(query_to_reparse);
383853 return std::move(parser.statements);
383854 }
383855 vector<unique_ptr<SQLStatement>> res;
383856 res.push_back(std::move(statement));
383857 return res;
383858}
Here is the call graph for this function:

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