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

The ExpressionRewriter performs a set of fixed rewrite rules on the expressions that occur in a SQL statement. More...

Inheritance diagram for duckdb::ExpressionRewriter:
Collaboration diagram for duckdb::ExpressionRewriter:

Public Member Functions

 ExpressionRewriter (ClientContext &context)
void VisitOperator (LogicalOperator &op) override
void VisitExpression (unique_ptr< Expression > *expression) override

Static Public Member Functions

static unique_ptr< Expression > ConstantOrNull (unique_ptr< Expression > child, Value value)
static unique_ptr< Expression > ConstantOrNull (vector< unique_ptr< Expression > > children, Value value)
Static Public Member Functions inherited from duckdb::LogicalOperatorVisitor
static void EnumerateExpressions (LogicalOperator &op, const std::function< void(unique_ptr< Expression > *child)> &callback)

Public Attributes

vector< unique_ptr< Rule > > rules
 The set of rules as known by the Expression Rewriter.
ClientContext & context

Static Private Member Functions

static unique_ptr< Expression > ApplyRules (LogicalOperator &op, const vector< reference< Rule > > &rules, unique_ptr< Expression > expr, bool &changes_made, bool is_root=false)
 Apply a set of rules to a specific expression.

Private Attributes

optional_ptr< LogicalOperator > op
vector< reference< Rule > > to_apply_rules

Additional Inherited Members

Protected Member Functions inherited from duckdb::LogicalOperatorVisitor
void VisitOperatorChildren (LogicalOperator &op)
void VisitOperatorExpressions (LogicalOperator &op)
void VisitOperatorWithProjectionMapChildren (LogicalOperator &op)
 Alternatives for VisitOperatorChildren for operators that have a projection map.
void VisitChildOfOperatorWithProjectionMap (LogicalOperator &child, vector< idx_t > &projection_map)
virtual void VisitExpressionChildren (Expression &expression)
virtual unique_ptr< Expression > VisitReplace (BoundAggregateExpression &expr, unique_ptr< Expression > *expr_ptr)
virtual unique_ptr< Expression > VisitReplace (BoundBetweenExpression &expr, unique_ptr< Expression > *expr_ptr)
virtual unique_ptr< Expression > VisitReplace (BoundCaseExpression &expr, unique_ptr< Expression > *expr_ptr)
virtual unique_ptr< Expression > VisitReplace (BoundCastExpression &expr, unique_ptr< Expression > *expr_ptr)
virtual unique_ptr< Expression > VisitReplace (BoundColumnRefExpression &expr, unique_ptr< Expression > *expr_ptr)
virtual unique_ptr< Expression > VisitReplace (BoundComparisonExpression &expr, unique_ptr< Expression > *expr_ptr)
virtual unique_ptr< Expression > VisitReplace (BoundConjunctionExpression &expr, unique_ptr< Expression > *expr_ptr)
virtual unique_ptr< Expression > VisitReplace (BoundConstantExpression &expr, unique_ptr< Expression > *expr_ptr)
virtual unique_ptr< Expression > VisitReplace (BoundDefaultExpression &expr, unique_ptr< Expression > *expr_ptr)
virtual unique_ptr< Expression > VisitReplace (BoundFunctionExpression &expr, unique_ptr< Expression > *expr_ptr)
virtual unique_ptr< Expression > VisitReplace (BoundOperatorExpression &expr, unique_ptr< Expression > *expr_ptr)
virtual unique_ptr< Expression > VisitReplace (BoundReferenceExpression &expr, unique_ptr< Expression > *expr_ptr)
virtual unique_ptr< Expression > VisitReplace (BoundSubqueryExpression &expr, unique_ptr< Expression > *expr_ptr)
virtual unique_ptr< Expression > VisitReplace (BoundParameterExpression &expr, unique_ptr< Expression > *expr_ptr)
virtual unique_ptr< Expression > VisitReplace (BoundWindowExpression &expr, unique_ptr< Expression > *expr_ptr)
virtual unique_ptr< Expression > VisitReplace (BoundUnnestExpression &expr, unique_ptr< Expression > *expr_ptr)

Detailed Description

The ExpressionRewriter performs a set of fixed rewrite rules on the expressions that occur in a SQL statement.

Constructor & Destructor Documentation

◆ ExpressionRewriter()

duckdb::ExpressionRewriter::ExpressionRewriter ( ClientContext & context)
inlineexplicit
69584 : context(context) {
69585 }

Member Function Documentation

◆ VisitOperator()

void duckdb::ExpressionRewriter::VisitOperator ( LogicalOperator & op)
overridevirtual

Reimplemented from duckdb::LogicalOperatorVisitor.

308298 {
308300 this->op = &op;
308301
308302 to_apply_rules.clear();
308303 for (auto &rule : rules) {
308304 to_apply_rules.push_back(*rule);
308305 }
308306
308308
308309 // if it is a LogicalFilter, we split up filter conjunctions again
308310 if (op.type == LogicalOperatorType::LOGICAL_FILTER) {
308311 auto &filter = op.Cast<LogicalFilter>();
308312 filter.SplitPredicates();
308313 }
308314}
vector< unique_ptr< Rule > > rules
The set of rules as known by the Expression Rewriter.
Definition duckdb.cpp:69589
void VisitOperatorExpressions(LogicalOperator &op)
Definition duckdb.cpp:381188
void VisitOperatorChildren(LogicalOperator &op)
Definition duckdb.cpp:380983
void filter(InputArray image, InputArray kernel, OutputArray output)

◆ VisitExpression()

void duckdb::ExpressionRewriter::VisitExpression ( unique_ptr< Expression > * expression)
overridevirtual

Reimplemented from duckdb::LogicalOperatorVisitor.

308316 {
308317 bool changes_made;
308318 do {
308319 changes_made = false;
308320 *expression = ExpressionRewriter::ApplyRules(*op, to_apply_rules, std::move(*expression), changes_made, true);
308321 } while (changes_made);
308322}
static unique_ptr< Expression > ApplyRules(LogicalOperator &op, const vector< reference< Rule > > &rules, unique_ptr< Expression > expr, bool &changes_made, bool is_root=false)
Apply a set of rules to a specific expression.
Definition duckdb.cpp:308248

◆ ConstantOrNull() [1/2]

unique_ptr< Expression > duckdb::ExpressionRewriter::ConstantOrNull ( unique_ptr< Expression > child,
Value value )
static
308282 {
308283 vector<unique_ptr<Expression>> children;
308284 children.push_back(make_uniq<BoundConstantExpression>(value));
308285 children.push_back(std::move(child));
308286 return ConstantOrNull(std::move(children), std::move(value));
308287}

◆ ConstantOrNull() [2/2]

unique_ptr< Expression > duckdb::ExpressionRewriter::ConstantOrNull ( vector< unique_ptr< Expression > > children,
Value value )
static
308289 {
308290 auto type = value.type();
308291 auto func = ConstantOrNullFun::GetFunction();
308292 func.arguments[0] = type;
308293 func.SetReturnType(type);
308294 children.insert(children.begin(), make_uniq<BoundConstantExpression>(value));
308295 return make_uniq<BoundFunctionExpression>(type, func, std::move(children), ConstantOrNull::Bind(std::move(value)));
308296}

◆ ApplyRules()

unique_ptr< Expression > duckdb::ExpressionRewriter::ApplyRules ( LogicalOperator & op,
const vector< reference< Rule > > & rules,
unique_ptr< Expression > expr,
bool & changes_made,
bool is_root = false )
staticprivate

Apply a set of rules to a specific expression.

308249 {
308250 for (auto &rule : rules) {
308251 vector<reference<Expression>> bindings;
308252 if (rule.get().root->Match(*expr, bindings)) {
308253 // the rule matches! try to apply it
308254 bool rule_made_change = false;
308255 auto alias = expr->alias;
308256 auto result = rule.get().Apply(op, bindings, rule_made_change, is_root);
308257 if (result) {
308258 changes_made = true;
308259 // the base node changed: the rule applied changes
308260 // rerun on the new node
308261 if (!alias.empty()) {
308262 result->alias = std::move(alias);
308263 }
308264 return ExpressionRewriter::ApplyRules(op, rules, std::move(result), changes_made);
308265 } else if (rule_made_change) {
308266 changes_made = true;
308267 // the base node didn't change, but changes were made, rerun
308268 return expr;
308269 }
308270 // else nothing changed, continue to the next rule
308271 continue;
308272 }
308273 }
308274 // no changes could be made to this node
308275 // recursively run on the children of this node
308276 ExpressionIterator::EnumerateChildren(*expr, [&](unique_ptr<Expression> &child) {
308277 child = ExpressionRewriter::ApplyRules(op, rules, std::move(child), changes_made);
308278 });
308279 return expr;
308280}
Here is the call graph for this function:
Here is the caller graph for this function:

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