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

Public Member Functions

 ConjunctionSimplificationRule (ExpressionRewriter &rewriter)
unique_ptr< Expression > Apply (LogicalOperator &op, vector< reference< Expression > > &bindings, bool &changes_made, bool is_root) override
unique_ptr< Expression > RemoveExpression (BoundConjunctionExpression &conj, const Expression &expr)
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

◆ ConjunctionSimplificationRule()

duckdb::ConjunctionSimplificationRule::ConjunctionSimplificationRule ( ExpressionRewriter & rewriter)
explicit
319893 : Rule(rewriter) {
319894 // match on a ComparisonExpression that has a ConstantExpression as a check
319895 auto op = make_uniq<ConjunctionExpressionMatcher>();
319896 op->matchers.push_back(make_uniq<FoldableConstantMatcher>());
319897 op->policy = SetMatcher::Policy::SOME;
319898 root = std::move(op);
319899}
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::ConjunctionSimplificationRule::Apply ( LogicalOperator & op,
vector< reference< Expression > > & bindings,
bool & changes_made,
bool is_root )
overridevirtual

Implements duckdb::Rule.

319919 {
319920 auto &conjunction = bindings[0].get().Cast<BoundConjunctionExpression>();
319921 auto &constant_expr = bindings[1].get();
319922 // the constant_expr is a scalar expression that we have to fold
319923 // use an ExpressionExecutor to execute the expression
319924 D_ASSERT(constant_expr.IsFoldable());
319925 Value constant_value;
319926 if (!ExpressionExecutor::TryEvaluateScalar(GetContext(), constant_expr, constant_value)) {
319927 return nullptr;
319928 }
319929 constant_value = constant_value.DefaultCastAs(LogicalType::BOOLEAN);
319930 if (constant_value.IsNull()) {
319931 // we can't simplify conjunctions with a constant NULL
319932 return nullptr;
319933 }
319934 if (conjunction.GetExpressionType() == ExpressionType::CONJUNCTION_AND) {
319935 if (!BooleanValue::Get(constant_value)) {
319936 // FALSE in AND, result of expression is false
319937 return make_uniq<BoundConstantExpression>(Value::BOOLEAN(false));
319938 } else {
319939 // TRUE in AND, remove the expression from the set
319940 return RemoveExpression(conjunction, constant_expr);
319941 }
319942 } else {
319943 D_ASSERT(conjunction.GetExpressionType() == ExpressionType::CONJUNCTION_OR);
319944 if (!BooleanValue::Get(constant_value)) {
319945 // FALSE in OR, remove the expression from the set
319946 return RemoveExpression(conjunction, constant_expr);
319947 } else {
319948 // TRUE in OR, result of expression is true
319949 return make_uniq<BoundConstantExpression>(Value::BOOLEAN(true));
319950 }
319951 }
319952}
static DUCKDB_API bool TryEvaluateScalar(ClientContext &context, const Expression &expr, Value &result)
Try to evaluate a scalar expression and fold it into a single value, returns false if an exception is...
Definition duckdb.cpp:150008
static DUCKDB_API Value BOOLEAN(bool value)
Create a boolean Value from a specified value.
Definition duckdb.cpp:132118

◆ RemoveExpression()

unique_ptr< Expression > duckdb::ConjunctionSimplificationRule::RemoveExpression ( BoundConjunctionExpression & conj,
const Expression & expr )
319902 {
319903 for (idx_t i = 0; i < conj.children.size(); i++) {
319904 if (conj.children[i].get() == &expr) {
319905 // erase the expression
319906 conj.children.erase_at(i);
319907 break;
319908 }
319909 }
319910 if (conj.children.size() == 1) {
319911 // one expression remaining: simply return that expression and erase the conjunction
319912 return std::move(conj.children[0]);
319913 }
319914 return nullptr;
319915}
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: