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

Public Member Functions

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

◆ DatePartSimplificationRule()

duckdb::DatePartSimplificationRule::DatePartSimplificationRule ( ExpressionRewriter & rewriter)
explicit
320139 : Rule(rewriter) {
320140 auto func = make_uniq<FunctionExpressionMatcher>();
320141 func->function = make_uniq<SpecificFunctionMatcher>("date_part");
320142 func->matchers.push_back(make_uniq<ConstantExpressionMatcher>());
320143 func->matchers.push_back(make_uniq<ExpressionMatcher>());
320144 func->policy = SetMatcher::Policy::ORDERED;
320145 root = std::move(func);
320146}
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
@ ORDERED
All entries have to be matched, and the matches have to be ordered.
Definition duckdb.cpp:69121

Member Function Documentation

◆ Apply()

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

Implements duckdb::Rule.

320149 {
320150 auto &date_part = bindings[0].get().Cast<BoundFunctionExpression>();
320151 auto &constant_expr = bindings[1].get().Cast<BoundConstantExpression>();
320152 auto &constant = constant_expr.value;
320153
320154 if (constant.IsNull()) {
320155 // NULL specifier: return constant NULL
320156 return make_uniq<BoundConstantExpression>(Value(date_part.return_type));
320157 }
320158 // otherwise check the specifier
320159 auto specifier = GetDatePartSpecifier(StringValue::Get(constant));
320160 string new_function_name;
320161 switch (specifier) {
320162 case DatePartSpecifier::YEAR:
320163 new_function_name = "year";
320164 break;
320165 case DatePartSpecifier::MONTH:
320166 new_function_name = "month";
320167 break;
320168 case DatePartSpecifier::DAY:
320169 new_function_name = "day";
320170 break;
320171 case DatePartSpecifier::DECADE:
320172 new_function_name = "decade";
320173 break;
320174 case DatePartSpecifier::CENTURY:
320175 new_function_name = "century";
320176 break;
320177 case DatePartSpecifier::MILLENNIUM:
320178 new_function_name = "millennium";
320179 break;
320180 case DatePartSpecifier::QUARTER:
320181 new_function_name = "quarter";
320182 break;
320183 case DatePartSpecifier::WEEK:
320184 new_function_name = "week";
320185 break;
320186 case DatePartSpecifier::YEARWEEK:
320187 new_function_name = "yearweek";
320188 break;
320189 case DatePartSpecifier::DOW:
320190 new_function_name = "dayofweek";
320191 break;
320192 case DatePartSpecifier::ISODOW:
320193 new_function_name = "isodow";
320194 break;
320195 case DatePartSpecifier::DOY:
320196 new_function_name = "dayofyear";
320197 break;
320198 case DatePartSpecifier::MICROSECONDS:
320199 new_function_name = "microsecond";
320200 break;
320201 case DatePartSpecifier::MILLISECONDS:
320202 new_function_name = "millisecond";
320203 break;
320204 case DatePartSpecifier::SECOND:
320205 new_function_name = "second";
320206 break;
320207 case DatePartSpecifier::MINUTE:
320208 new_function_name = "minute";
320209 break;
320210 case DatePartSpecifier::HOUR:
320211 new_function_name = "hour";
320212 break;
320213 default:
320214 return nullptr;
320215 }
320216 // found a replacement function: bind it
320217 vector<unique_ptr<Expression>> children;
320218 children.push_back(std::move(date_part.children[1]));
320219
320220 ErrorData error;
320221 FunctionBinder binder(rewriter.context);
320222 auto function = binder.BindScalarFunction(DEFAULT_SCHEMA, new_function_name, std::move(children), error, false);
320223 if (!function) {
320224 error.Throw();
320225 }
320226 return function;
320227}

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