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

Public Member Functions

 RegexOptimizationRule (ExpressionRewriter &rewriter)
unique_ptr< Expression > Apply (LogicalOperator &op, vector< reference< Expression > > &bindings, bool &changes_made, bool is_root) override
unique_ptr< Expression > ApplyRule (BoundFunctionExpression *expr, ScalarFunction function, string pattern, bool is_not_like)
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

◆ RegexOptimizationRule()

duckdb::RegexOptimizationRule::RegexOptimizationRule ( ExpressionRewriter & rewriter)
explicit
322879 : Rule(rewriter) {
322880 auto func = make_uniq<FunctionExpressionMatcher>();
322881 func->function = make_uniq<SpecificFunctionMatcher>("regexp_matches");
322882 func->policy = SetMatcher::Policy::SOME_ORDERED;
322883 func->matchers.push_back(make_uniq<ExpressionMatcher>());
322884 func->matchers.push_back(make_uniq<ConstantExpressionMatcher>());
322885
322886 root = std::move(func);
322887}
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_ORDERED
Only some entries have to be matched. The order of the matches does matter.
Definition duckdb.cpp:69127

Member Function Documentation

◆ Apply()

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

Implements duckdb::Rule.

323014 {
323015 auto &root = bindings[0].get().Cast<BoundFunctionExpression>();
323016 auto &constant_expr = bindings[2].get().Cast<BoundConstantExpression>();
323017 D_ASSERT(root.children.size() == 2 || root.children.size() == 3);
323018 auto regexp_bind_data = root.bind_info.get()->Cast<RegexpMatchesBindData>();
323019
323020 auto constant_value = ExpressionExecutor::EvaluateScalar(GetContext(), constant_expr);
323021 D_ASSERT(constant_value.type() == constant_expr.return_type);
323022
323023 duckdb_re2::RE2::Options parsed_options = regexp_bind_data.options;
323024
323025 if (constant_expr.value.IsNull()) {
323026 return make_uniq<BoundConstantExpression>(Value(root.return_type));
323027 }
323028 auto patt_str = StringValue::Get(constant_value);
323029
323030 // the constant_expr is a scalar expression that we have to fold
323031 if (!constant_expr.IsFoldable()) {
323032 return nullptr;
323033 };
323034
323035 duckdb_re2::RE2 pattern(patt_str, parsed_options);
323036 if (!pattern.ok()) {
323037 return nullptr; // this should fail somewhere else
323038 }
323039
323040 LikeString like_string;
323041 // check for a like string. If we can convert it to a like string, the like string
323042 // optimizer will further optimize suffix and prefix things.
323043 if (pattern.Regexp()->op() == duckdb_re2::kRegexpLiteralString ||
323044 pattern.Regexp()->op() == duckdb_re2::kRegexpLiteral) {
323045 // convert to contains.
323046 LikeString escaped_like_string = GetLikeStringEscaped(pattern.Regexp(), true);
323047 if (!escaped_like_string.exists) {
323048 return nullptr;
323049 }
323050
323051 // if regexp had options, remove them so the new Contains Expression can be matched for other optimizers.
323052 if (root.children.size() == 3) {
323053 root.children.pop_back();
323054 D_ASSERT(root.children.size() == 2);
323055 }
323056
323057 auto parameter = make_uniq<BoundConstantExpression>(Value(std::move(escaped_like_string.like_string)));
323058 auto contains = make_uniq<BoundFunctionExpression>(root.return_type, GetStringContains(),
323059 std::move(root.children), nullptr);
323060 contains->children[1] = std::move(parameter);
323061
323062 return std::move(contains);
323063 } else if (pattern.Regexp()->op() == duckdb_re2::kRegexpConcat) {
323064 like_string = LikeMatchFromRegex(pattern);
323065 } else {
323066 like_string.exists = false;
323067 }
323068
323069 if (!like_string.exists) {
323070 return nullptr;
323071 }
323072
323073 // if regexp had options, remove them so the new Like Expression can be matched for other optimizers.
323074 if (root.children.size() == 3) {
323075 root.children.pop_back();
323076 D_ASSERT(root.children.size() == 2);
323077 }
323078
323079 auto like_expression =
323080 make_uniq<BoundFunctionExpression>(root.return_type, LikeFun::GetFunction(), std::move(root.children), nullptr);
323081 auto parameter = make_uniq<BoundConstantExpression>(Value(std::move(like_string.like_string)));
323082 like_expression->children[1] = std::move(parameter);
323083 return std::move(like_expression);
323084}
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

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