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

Public Member Functions

 ConstantOrderNormalizationRule (ExpressionRewriter &rewriter)
unique_ptr< Expression > Apply (LogicalOperator &op, vector< reference< Expression > > &bindings, bool &changes_made, bool is_root) override
Public Member Functions inherited from duckdb::Rule
 Rule (ExpressionRewriter &rewriter)
ClientContext & GetContext () const

Additional Inherited Members

Public Attributes inherited from duckdb::Rule
ExpressionRewriter & rewriter
 The expression rewriter this rule belongs to.
unique_ptr< ExpressionMatcher > root
 The expression matcher of the rule.

Constructor & Destructor Documentation

◆ ConstantOrderNormalizationRule()

duckdb::ConstantOrderNormalizationRule::ConstantOrderNormalizationRule ( ExpressionRewriter & rewriter)
explicit
320046 : Rule(rewriter) {
320047 // '+' and '*' satisfy commutative law and associative law.
320048 auto add_matcher = make_uniq<FunctionExpressionMatcher>();
320049 add_matcher->function = make_uniq<SpecificFunctionMatcher>("+");
320050 add_matcher->type = make_uniq<IntegerTypeMatcher>();
320051 auto left_expression_matcher = make_uniq<ExpressionMatcher>();
320052 auto right_expression_matcher = make_uniq<ExpressionMatcher>();
320053 left_expression_matcher->type = make_uniq<IntegerTypeMatcher>();
320054 right_expression_matcher->type = make_uniq<IntegerTypeMatcher>();
320055 add_matcher->matchers.push_back(std::move(left_expression_matcher));
320056 add_matcher->matchers.push_back(std::move(right_expression_matcher));
320057 add_matcher->policy = SetMatcher::Policy::ORDERED;
320058
320059 auto multiply_matcher = make_uniq<FunctionExpressionMatcher>();
320060 multiply_matcher->function = make_uniq<SpecificFunctionMatcher>("*");
320061 multiply_matcher->type = make_uniq<IntegerTypeMatcher>();
320062 left_expression_matcher = make_uniq<ExpressionMatcher>();
320063 right_expression_matcher = make_uniq<ExpressionMatcher>();
320064 left_expression_matcher->type = make_uniq<IntegerTypeMatcher>();
320065 right_expression_matcher->type = make_uniq<IntegerTypeMatcher>();
320066 multiply_matcher->matchers.push_back(std::move(left_expression_matcher));
320067 multiply_matcher->matchers.push_back(std::move(right_expression_matcher));
320068 multiply_matcher->policy = SetMatcher::Policy::ORDERED;
320069
320070 vector<unique_ptr<FunctionExpressionMatcher>> func_matchers;
320071 func_matchers.push_back(std::move(add_matcher));
320072 func_matchers.push_back(std::move(multiply_matcher));
320073 auto op = make_uniq<RecursiveFunctionExpressionMatcher>(std::move(func_matchers));
320074 root = std::move(op);
320075}
ExpressionRewriter & rewriter
The expression rewriter this rule belongs to.
Definition duckdb.cpp:69564
unique_ptr< ExpressionMatcher > root
The expression matcher of the rule.
Definition duckdb.cpp:69566
@ ORDERED
All entries have to be matched, and the matches have to be ordered.
Definition duckdb.cpp:69121

Member Function Documentation

◆ Apply()

unique_ptr< Expression > duckdb::ConstantOrderNormalizationRule::Apply ( LogicalOperator & op,
vector< reference< Expression > > & bindings,
bool & changes_made,
bool is_root )
overridevirtual

Implements duckdb::Rule.

320079 {
320080 auto &root = bindings.back().get().Cast<BoundFunctionExpression>();
320081
320082 // Put all constant expressions in front.
320083 vector<reference<Expression>> ordered_bindings;
320084 vector<reference<Expression>> remain_bindings;
320085 idx_t last_constant_position = 0;
320086 for (idx_t i = 0; i < bindings.size() - 1; ++i) {
320087 if (bindings[i].get().IsFoldable()) {
320088 ordered_bindings.push_back(bindings[i]);
320089 last_constant_position = i;
320090 } else {
320091 remain_bindings.push_back(bindings[i]);
320092 }
320093 }
320094
320095 if (ordered_bindings.size() <= 1 || last_constant_position == ordered_bindings.size() - 1) {
320096 return nullptr;
320097 }
320098 ordered_bindings.insert(ordered_bindings.end(), remain_bindings.begin(), remain_bindings.end());
320099
320100 // Reconstruct the expression.
320101 FunctionBinder binder(rewriter.context);
320102 ErrorData error;
320103 unique_ptr<Expression> new_root = ordered_bindings[0].get().Copy();
320104 vector<unique_ptr<Expression>> children;
320105 children.push_back(std::move(new_root));
320106 for (idx_t i = 1; i < ordered_bindings.size(); ++i) {
320107 // Right child.
320108 children.push_back(ordered_bindings[i].get().Copy());
320109 new_root =
320110 binder.BindScalarFunction(DEFAULT_SCHEMA, root.function.name, std::move(children), error, root.is_operator);
320111 if (!new_root) {
320112 error.Throw();
320113 }
320114 children.clear();
320115 // Left child.
320116 children.push_back(std::move(new_root));
320117 }
320118
320119 D_ASSERT(children.size() == 1);
320120 D_ASSERT(children[0]->return_type == root.return_type);
320121
320122 return std::move(children[0]);
320123}
__host__ cudaTextureObject_t get() const noexcept
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: