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::QueryNode Class Referenceabstract
Inheritance diagram for duckdb::QueryNode:
Collaboration diagram for duckdb::QueryNode:

Public Member Functions

 QueryNode (QueryNodeType type)
virtual string ToString () const =0
 Convert the query node to a string.
virtual bool Equals (const QueryNode *other) const
virtual unique_ptr< QueryNode > Copy () const =0
 Create a copy of this QueryNode.
string ResultModifiersToString () const
void AddDistinct ()
 Adds a distinct modifier to the query node.
virtual void Serialize (Serializer &serializer) const
template<class TARGET>
TARGET & Cast ()
template<class TARGET>
const TARGET & Cast () const

Static Public Member Functions

static unique_ptr< QueryNode > Deserialize (Deserializer &deserializer)

Public Attributes

QueryNodeType type
 The type of the query node, either SetOperation or Select.
vector< unique_ptr< ResultModifier > > modifiers
 The set of result modifiers associated with this query node.
CommonTableExpressionMap cte_map
 CTEs (used by SelectNode and SetOperationNode).

Protected Member Functions

void CopyProperties (QueryNode &other) const
 Copy base QueryNode properties from another expression to this one, used in Copy method.

Constructor & Destructor Documentation

◆ QueryNode()

duckdb::QueryNode::QueryNode ( QueryNodeType type)
inlineexplicit
53572 : type(type) {
53573 }
QueryNodeType type
The type of the query node, either SetOperation or Select.
Definition duckdb.hpp:53578

◆ ~QueryNode()

virtual duckdb::QueryNode::~QueryNode ( )
inlinevirtual
53574 {
53575 }

Member Function Documentation

◆ ToString()

virtual string duckdb::QueryNode::ToString ( ) const
pure virtual

◆ Equals()

bool duckdb::QueryNode::Equals ( const QueryNode * other) const
virtual
348559 {
348560 if (!other) {
348561 return false;
348562 }
348563 if (this == other) {
348564 return true;
348565 }
348566 if (other->type != this->type) {
348567 return false;
348568 }
348569
348570 if (modifiers.size() != other->modifiers.size()) {
348571 return false;
348572 }
348573 for (idx_t i = 0; i < modifiers.size(); i++) {
348574 if (!modifiers[i]->Equals(*other->modifiers[i])) {
348575 return false;
348576 }
348577 }
348578 // WITH clauses (CTEs)
348579 if (cte_map.map.size() != other->cte_map.map.size()) {
348580 return false;
348581 }
348582
348583 for (auto &entry : cte_map.map) {
348584 auto other_entry = other->cte_map.map.find(entry.first);
348585 if (other_entry == other->cte_map.map.end()) {
348586 return false;
348587 }
348588
348589 if (entry.second->aliases != other->cte_map.map.at(entry.first)->aliases) {
348590 return false;
348591 }
348592 if (!ParsedExpression::ListEquals(entry.second->key_targets, other_entry->second->key_targets)) {
348593 return false;
348594 }
348595 if (!entry.second->query->Equals(*other->cte_map.map.at(entry.first)->query)) {
348596 return false;
348597 }
348598 }
348599 return other->type == type;
348600}
CommonTableExpressionMap cte_map
CTEs (used by SelectNode and SetOperationNode).
Definition duckdb.hpp:53582
vector< unique_ptr< ResultModifier > > modifiers
The set of result modifiers associated with this query node.
Definition duckdb.hpp:53580
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237

◆ Copy()

virtual unique_ptr< QueryNode > duckdb::QueryNode::Copy ( ) const
pure virtual

◆ ResultModifiersToString()

string duckdb::QueryNode::ResultModifiersToString ( ) const
348525 {
348526 string result;
348527 for (idx_t modifier_idx = 0; modifier_idx < modifiers.size(); modifier_idx++) {
348528 auto &modifier = *modifiers[modifier_idx];
348529 if (modifier.type == ResultModifierType::ORDER_MODIFIER) {
348530 auto &order_modifier = modifier.Cast<OrderModifier>();
348531 result += " ORDER BY ";
348532 for (idx_t k = 0; k < order_modifier.orders.size(); k++) {
348533 if (k > 0) {
348534 result += ", ";
348535 }
348536 result += order_modifier.orders[k].ToString();
348537 }
348538 } else if (modifier.type == ResultModifierType::LIMIT_MODIFIER) {
348539 auto &limit_modifier = modifier.Cast<LimitModifier>();
348540 if (limit_modifier.limit) {
348541 result += " LIMIT " + limit_modifier.limit->ToString();
348542 }
348543 if (limit_modifier.offset) {
348544 result += " OFFSET " + limit_modifier.offset->ToString();
348545 }
348546 } else if (modifier.type == ResultModifierType::LIMIT_PERCENT_MODIFIER) {
348547 auto &limit_p_modifier = modifier.Cast<LimitPercentModifier>();
348548 if (limit_p_modifier.limit) {
348549 result += " LIMIT (" + limit_p_modifier.limit->ToString() + ") %";
348550 }
348551 if (limit_p_modifier.offset) {
348552 result += " OFFSET " + limit_p_modifier.offset->ToString();
348553 }
348554 }
348555 }
348556 return result;
348557}

◆ AddDistinct()

void duckdb::QueryNode::AddDistinct ( )

Adds a distinct modifier to the query node.

348620 {
348621 // check if we already have a DISTINCT modifier
348622 for (idx_t modifier_idx = modifiers.size(); modifier_idx > 0; modifier_idx--) {
348623 auto &modifier = *modifiers[modifier_idx - 1];
348624 if (modifier.type == ResultModifierType::DISTINCT_MODIFIER) {
348625 auto &distinct_modifier = modifier.Cast<DistinctModifier>();
348626 if (distinct_modifier.distinct_on_targets.empty()) {
348627 // we have a DISTINCT without an ON clause - this distinct does not need to be added
348628 return;
348629 }
348630 } else if (modifier.type == ResultModifierType::LIMIT_MODIFIER ||
348631 modifier.type == ResultModifierType::LIMIT_PERCENT_MODIFIER) {
348632 // we encountered a LIMIT or LIMIT PERCENT - these change the result of DISTINCT, so we do need to push a
348633 // DISTINCT relation
348634 break;
348635 }
348636 }
348637 modifiers.push_back(make_uniq<DistinctModifier>());
348638}

◆ Serialize()

void duckdb::QueryNode::Serialize ( Serializer & serializer) const
virtual

Reimplemented in duckdb::RecursiveCTENode, duckdb::SelectNode, duckdb::SetOperationNode, and duckdb::StatementNode.

419041 {
419042 serializer.WriteProperty<QueryNodeType>(100, "type", type);
419043 serializer.WritePropertyWithDefault<vector<unique_ptr<ResultModifier>>>(101, "modifiers", modifiers);
419044 serializer.WriteProperty<CommonTableExpressionMap>(102, "cte_map", cte_map);
419045}

◆ Deserialize()

unique_ptr< QueryNode > duckdb::QueryNode::Deserialize ( Deserializer & deserializer)
static
419047 {
419048 auto type = deserializer.ReadProperty<QueryNodeType>(100, "type");
419049 auto modifiers = deserializer.ReadPropertyWithDefault<vector<unique_ptr<ResultModifier>>>(101, "modifiers");
419050 auto cte_map = deserializer.ReadProperty<CommonTableExpressionMap>(102, "cte_map");
419051 unique_ptr<QueryNode> result;
419052 switch (type) {
419053 case QueryNodeType::CTE_NODE:
419054 result = CTENode::Deserialize(deserializer);
419055 break;
419056 case QueryNodeType::RECURSIVE_CTE_NODE:
419057 result = RecursiveCTENode::Deserialize(deserializer);
419058 break;
419059 case QueryNodeType::SELECT_NODE:
419060 result = SelectNode::Deserialize(deserializer);
419061 break;
419062 case QueryNodeType::SET_OPERATION_NODE:
419063 result = SetOperationNode::Deserialize(deserializer);
419064 break;
419065 default:
419066 throw SerializationException("Unsupported type for deserialization of QueryNode!");
419067 }
419068 result->modifiers = std::move(modifiers);
419069 result->cte_map = std::move(cte_map);
419070 if (type == QueryNodeType::CTE_NODE) {
419071 result = std::move(result->Cast<CTENode>().child);
419072 }
419073 return result;
419074}

◆ CopyProperties()

void duckdb::QueryNode::CopyProperties ( QueryNode & other) const
protected

Copy base QueryNode properties from another expression to this one, used in Copy method.

348602 {
348603 for (auto &modifier : modifiers) {
348604 other.modifiers.push_back(modifier->Copy());
348605 }
348606 for (auto &kv : cte_map.map) {
348607 auto kv_info = make_uniq<CommonTableExpressionInfo>();
348608 for (auto &al : kv.second->aliases) {
348609 kv_info->aliases.push_back(al);
348610 }
348611 for (auto &key : kv.second->key_targets) {
348612 kv_info->key_targets.push_back(key->Copy());
348613 }
348614 kv_info->query = unique_ptr_cast<SQLStatement, SelectStatement>(kv.second->query->Copy());
348615 kv_info->materialized = kv.second->materialized;
348616 other.cte_map.map[kv.first] = std::move(kv_info);
348617 }
348618}
Here is the caller graph for this function:

◆ Cast() [1/2]

template<class TARGET>
TARGET & duckdb::QueryNode::Cast ( )
inline
53608 {
53609 if (type != TARGET::TYPE) {
53610 throw InternalException("Failed to cast query node to type - query node type mismatch");
53611 }
53612 return reinterpret_cast<TARGET &>(*this);
53613 }

◆ Cast() [2/2]

template<class TARGET>
const TARGET & duckdb::QueryNode::Cast ( ) const
inline
53616 {
53617 if (type != TARGET::TYPE) {
53618 throw InternalException("Failed to cast query node to type - query node type mismatch");
53619 }
53620 return reinterpret_cast<const TARGET &>(*this);
53621 }

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