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

Public Member Functions

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

◆ EmptyNeedleRemovalRule()

duckdb::EmptyNeedleRemovalRule::EmptyNeedleRemovalRule ( ExpressionRewriter & rewriter)
explicit
320895 : Rule(rewriter) {
320896 // match on a FunctionExpression that has a foldable ConstantExpression
320897 auto func = make_uniq<FunctionExpressionMatcher>();
320898 func->matchers.push_back(make_uniq<ExpressionMatcher>());
320899 func->matchers.push_back(make_uniq<ExpressionMatcher>());
320900 func->policy = SetMatcher::Policy::SOME;
320901
320902 unordered_set<string> functions = {"prefix", "contains", "suffix"};
320903 func->function = make_uniq<ManyFunctionMatcher>(functions);
320904 root = std::move(func);
320905}
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::EmptyNeedleRemovalRule::Apply ( LogicalOperator & op,
vector< reference< Expression > > & bindings,
bool & changes_made,
bool is_root )
overridevirtual

Implements duckdb::Rule.

320908 {
320909 auto &root = bindings[0].get().Cast<BoundFunctionExpression>();
320910 D_ASSERT(root.children.size() == 2);
320911 auto &prefix_expr = bindings[2].get();
320912
320913 // the constant_expr is a scalar expression that we have to fold
320914 if (!prefix_expr.IsFoldable()) {
320915 return nullptr;
320916 }
320917 D_ASSERT(root.return_type.id() == LogicalTypeId::BOOLEAN);
320918
320919 auto prefix_value = ExpressionExecutor::EvaluateScalar(GetContext(), prefix_expr);
320920
320921 if (prefix_value.IsNull()) {
320922 return make_uniq<BoundConstantExpression>(Value(LogicalType::BOOLEAN));
320923 }
320924
320925 D_ASSERT(prefix_value.type() == prefix_expr.return_type);
320926 if (prefix_value.type().InternalType() != PhysicalType::VARCHAR) {
320927 return nullptr;
320928 }
320929 auto &needle_string = StringValue::Get(prefix_value);
320930
320931 // PREFIX('xyz', '') is TRUE
320932 // PREFIX(NULL, '') is NULL
320933 // so rewrite PREFIX(x, '') to TRUE_OR_NULL(x)
320934 if (needle_string.empty()) {
320935 return ExpressionRewriter::ConstantOrNull(std::move(root.children[0]), Value::BOOLEAN(true));
320936 }
320937 return nullptr;
320938}
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
static DUCKDB_API Value BOOLEAN(bool value)
Create a boolean Value from a specified value.
Definition duckdb.cpp:132118
@ VARCHAR
DuckDB Extensions.
Definition duckdb.hpp:2847

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