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

Public Member Functions

 CaseSimplificationRule (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

◆ CaseSimplificationRule()

duckdb::CaseSimplificationRule::CaseSimplificationRule ( ExpressionRewriter & rewriter)
explicit
319767 : Rule(rewriter) {
319768 // match on a CaseExpression that has a ConstantExpression as a check
319769 auto op = make_uniq<CaseExpressionMatcher>();
319770 root = std::move(op);
319771}
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

Member Function Documentation

◆ Apply()

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

Implements duckdb::Rule.

319774 {
319775 auto &root = bindings[0].get().Cast<BoundCaseExpression>();
319776 for (idx_t i = 0; i < root.case_checks.size(); i++) {
319777 auto &case_check = root.case_checks[i];
319778 if (case_check.when_expr->IsFoldable()) {
319779 // the WHEN check is a foldable expression
319780 // use an ExpressionExecutor to execute the expression
319781 auto constant_value = ExpressionExecutor::EvaluateScalar(GetContext(), *case_check.when_expr);
319782
319783 // fold based on the constant condition
319784 auto condition = constant_value.DefaultCastAs(LogicalType::BOOLEAN);
319785 if (condition.IsNull() || !BooleanValue::Get(condition)) {
319786 // the condition is always false: remove this case check
319787 root.case_checks.erase_at(i);
319788 i--;
319789 } else {
319790 // the condition is always true
319791 // move the THEN clause to the ELSE of the case
319792 root.else_expr = std::move(case_check.then_expr);
319793 // remove this case check and any case checks after this one
319794 root.case_checks.erase(root.case_checks.begin() + NumericCast<int64_t>(i), root.case_checks.end());
319795 break;
319796 }
319797 }
319798 }
319799 if (root.case_checks.empty()) {
319800 // no case checks left: return the ELSE expression
319801 return std::move(root.else_expr);
319802 }
319803 return nullptr;
319804}
static DUCKDB_API Value EvaluateScalar(ClientContext &context, const Expression &expr, bool allow_unfoldable=false)
Evaluate a scalar expression and fold it into a single value.
Definition duckdb.cpp:149993
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: