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

Public Member Functions

 PreparedStatementVerifier (unique_ptr< SQLStatement > statement_p, optional_ptr< case_insensitive_map_t< BoundParameterData > > parameters)
bool Run (ClientContext &context, const string &query, const std::function< unique_ptr< QueryResult >(const string &, unique_ptr< SQLStatement >, optional_ptr< case_insensitive_map_t< BoundParameterData > >)> &run) override
 Run the select statement and store the result.
Public Member Functions inherited from duckdb::StatementVerifier
 StatementVerifier (VerificationType type, string name, unique_ptr< SQLStatement > statement_p, optional_ptr< case_insensitive_map_t< BoundParameterData > > values)
 StatementVerifier (unique_ptr< SQLStatement > statement_p, optional_ptr< case_insensitive_map_t< BoundParameterData > > values)
void CheckExpressions (const StatementVerifier &other) const
 Check whether expressions in this verifier and the other verifier match.
void CheckExpressions () const
 Check whether expressions within this verifier match.
string CompareResults (const StatementVerifier &other)
 Compare this verifier's results with another verifier.
virtual bool RequireEquality () const
virtual bool DisableOptimizer () const
virtual bool DisableOperatorCaching () const
virtual bool ForceExternal () const
virtual bool ForceFetchRow () const

Static Public Member Functions

static unique_ptr< StatementVerifier > Create (const SQLStatement &statement_p, optional_ptr< case_insensitive_map_t< BoundParameterData > > parameters)
Static Public Member Functions inherited from duckdb::StatementVerifier
static unique_ptr< StatementVerifier > Create (VerificationType type, const SQLStatement &statement_p, optional_ptr< case_insensitive_map_t< BoundParameterData > > values)

Private Member Functions

void Extract ()
void ConvertConstants (unique_ptr< ParsedExpression > &child)

Private Attributes

case_insensitive_map_t< unique_ptr< ParsedExpression > > values
unique_ptr< SQLStatement > prepare_statement
unique_ptr< SQLStatement > execute_statement
unique_ptr< SQLStatement > dealloc_statement

Additional Inherited Members

Public Attributes inherited from duckdb::StatementVerifier
const VerificationType type
const string name
unique_ptr< SQLStatement > statement
optional_ptr< SelectStatement > select_statement
optional_ptr< case_insensitive_map_t< BoundParameterData > > parameters
const vector< unique_ptr< ParsedExpression > > & select_list
unique_ptr< MaterializedQueryResult > materialized_result

Constructor & Destructor Documentation

◆ PreparedStatementVerifier()

duckdb::PreparedStatementVerifier::PreparedStatementVerifier ( unique_ptr< SQLStatement > statement_p,
optional_ptr< case_insensitive_map_t< BoundParameterData > > parameters )
explicit
448585 : StatementVerifier(VerificationType::PREPARED, "Prepared", std::move(statement_p), parameters) {
448586}

Member Function Documentation

◆ Create()

unique_ptr< StatementVerifier > duckdb::PreparedStatementVerifier::Create ( const SQLStatement & statement_p,
optional_ptr< case_insensitive_map_t< BoundParameterData > > parameters )
static
448590 {
448591 return make_uniq<PreparedStatementVerifier>(statement.Copy(), parameters);
448592}

◆ Run()

bool duckdb::PreparedStatementVerifier::Run ( ClientContext & context,
const string & query,
const std::function< unique_ptr< QueryResult >(const string &, unique_ptr< SQLStatement >, optional_ptr< case_insensitive_map_t< BoundParameterData > >)> & run )
overridevirtual

Run the select statement and store the result.

Reimplemented from duckdb::StatementVerifier.

448654 {
448655 bool failed = false;
448656 // verify that we can extract all constants from the query and run the query as a prepared statement
448657 // create the PREPARE and EXECUTE statements
448658 Extract();
448659 // execute the prepared statements
448660 try {
448661 auto prepare_result = run(string(), std::move(prepare_statement), parameters);
448662 if (prepare_result->HasError()) {
448663 prepare_result->ThrowError("Failed prepare during verify: ");
448664 }
448665 auto execute_result = run(string(), std::move(execute_statement), parameters);
448666 if (execute_result->HasError()) {
448667 execute_result->ThrowError("Failed execute during verify: ");
448668 }
448669 materialized_result = unique_ptr_cast<QueryResult, MaterializedQueryResult>(std::move(execute_result));
448670 } catch (const std::exception &ex) {
448671 ErrorData error(ex);
448672 if (error.Type() != ExceptionType::PARAMETER_NOT_ALLOWED) {
448673 materialized_result = make_uniq<MaterializedQueryResult>(std::move(error));
448674 }
448675 failed = true;
448676 }
448677 run(string(), std::move(dealloc_statement), parameters);
448678 context.interrupted = false;
448679
448680 return failed;
448681}

◆ Extract()

void duckdb::PreparedStatementVerifier::Extract ( )
private
448594 {
448595 auto &select = *select_statement;
448596 // replace all the constants from the select statement and replace them with parameter expressions
448597 ParsedExpressionIterator::EnumerateQueryNodeChildren(
448598 *select.node, [&](unique_ptr<ParsedExpression> &child) { ConvertConstants(child); });
448599 for (auto &kv : values) {
448600 statement->named_param_map[kv.first] = 0;
448601 }
448602 // create the PREPARE and EXECUTE statements
448603 string name = "__duckdb_verification_prepared_statement";
448604 auto prepare = make_uniq<PrepareStatement>();
448605 prepare->name = name;
448606 prepare->statement = std::move(statement);
448607
448608 auto execute = make_uniq<ExecuteStatement>();
448609 execute->name = name;
448610 execute->named_values = std::move(values);
448611
448612 auto dealloc = make_uniq<DropStatement>();
448613 dealloc->info->type = CatalogType::PREPARED_STATEMENT;
448614 dealloc->info->name = string(name);
448615
448616 prepare_statement = std::move(prepare);
448617 execute_statement = std::move(execute);
448618 dealloc_statement = std::move(dealloc);
448619}
GMat select(const GMat &src1, const GMat &src2, const GMat &mask)

◆ ConvertConstants()

void duckdb::PreparedStatementVerifier::ConvertConstants ( unique_ptr< ParsedExpression > & child)
private
448621 {
448622 if (child->GetExpressionType() == ExpressionType::VALUE_CONSTANT) {
448623 // constant: extract the constant value
448624 auto alias = child->GetAlias();
448625 child->ClearAlias();
448626 // check if the value already exists
448627 idx_t index = values.size();
448628 auto identifier = std::to_string(index + 1);
448629 const auto predicate = [&](const std::pair<const string, unique_ptr<ParsedExpression>> &pair) {
448630 return pair.second->Equals(*child.get());
448631 };
448632 auto result = std::find_if(values.begin(), values.end(), predicate);
448633 if (result == values.end()) {
448634 // If it doesn't exist yet, add it
448635 values[identifier] = std::move(child);
448636 } else {
448637 identifier = result->first;
448638 }
448639
448640 // replace it with an expression
448641 auto parameter = make_uniq<ParameterExpression>();
448642 parameter->identifier = identifier;
448643 parameter->SetAlias(alias);
448644 child = std::move(parameter);
448645 return;
448646 }
448647 ParsedExpressionIterator::EnumerateChildren(*child,
448648 [&](unique_ptr<ParsedExpression> &child) { ConvertConstants(child); });
448649}
index
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237

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