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

Public Member Functions

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

◆ InClauseSimplificationRule()

duckdb::InClauseSimplificationRule::InClauseSimplificationRule ( ExpressionRewriter & rewriter)
explicit
321159 : Rule(rewriter) {
321160 // match on InClauseExpression that has a ConstantExpression as a check
321161 auto op = make_uniq<InClauseExpressionMatcher>();
321162 op->policy = SetMatcher::Policy::SOME;
321163 root = std::move(op);
321164}
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
@ SOME
Only some entries have to be matched, the order of the matches does not matter.
Definition duckdb.cpp:69125

Member Function Documentation

◆ Apply()

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

The goal here is to remove the cast from the probe expression and apply a cast to the constant expressions. We can only do this if the semantics do not change, which only happens when BOTH casts are invertible.

First check if we can cast all children

We can cast, so we move the new constant

We can cast the full list, so we move the column

Implements duckdb::Rule.

321167 {
321168 auto &expr = bindings[0].get().Cast<BoundOperatorExpression>();
321169 if (expr.children[0]->GetExpressionClass() != ExpressionClass::BOUND_CAST) {
321170 return nullptr;
321171 }
321172 auto &cast_expression = expr.children[0]->Cast<BoundCastExpression>();
321173 if (cast_expression.child->GetExpressionClass() != ExpressionClass::BOUND_COLUMN_REF) {
321174 return nullptr;
321175 }
321180 auto target_type = cast_expression.source_type();
321181 if (!BoundCastExpression::CastIsInvertible(target_type, cast_expression.return_type)) {
321182 return nullptr;
321183 }
321184 vector<unique_ptr<BoundConstantExpression>> cast_list;
321186 for (size_t i = 1; i < expr.children.size(); i++) {
321187 if (expr.children[i]->GetExpressionClass() != ExpressionClass::BOUND_CONSTANT) {
321188 return nullptr;
321189 }
321190 D_ASSERT(expr.children[i]->IsFoldable());
321191 auto constant_value = ExpressionExecutor::EvaluateScalar(GetContext(), *expr.children[i]);
321192 if (!BoundCastExpression::CastIsInvertible(constant_value.type(), target_type)) {
321193 return nullptr;
321194 }
321195 auto new_constant = constant_value.DefaultTryCastAs(target_type);
321196 if (!new_constant) {
321197 return nullptr;
321198 } else {
321199 auto new_constant_expr = make_uniq<BoundConstantExpression>(constant_value);
321200 cast_list.push_back(std::move(new_constant_expr));
321201 }
321202 }
321204 for (size_t i = 1; i < expr.children.size(); i++) {
321205 expr.children[i] = std::move(cast_list[i - 1]);
321206
321207 // expr->children[i] = std::move(new_constant_expr);
321208 }
321210 expr.children[0] = std::move(cast_expression.child);
321211 return nullptr;
321212}
static bool CastIsInvertible(const LogicalType &source_type, const LogicalType &target_type)
Definition duckdb.cpp:375885
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
Here is the call graph for this function:

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