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

Public Member Functions

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

Static Public Member Functions

static unique_ptr< Expression > Apply (ClientContext &context, BoundAggregateExpression &aggr, vector< unique_ptr< Expression > > &groups, optional_ptr< vector< GroupingSet > > grouping_sets, bool &changes_made)

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

◆ OrderedAggregateOptimizer()

duckdb::OrderedAggregateOptimizer::OrderedAggregateOptimizer ( ExpressionRewriter & rewriter)
explicit
321689 : Rule(rewriter) {
321690 // we match on an OR expression within a LogicalFilter node
321691 root = make_uniq<ExpressionMatcher>();
321692 root->expr_class = ExpressionClass::BOUND_AGGREGATE;
321693}
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

Member Function Documentation

◆ Apply() [1/2]

unique_ptr< Expression > duckdb::OrderedAggregateOptimizer::Apply ( ClientContext & context,
BoundAggregateExpression & aggr,
vector< unique_ptr< Expression > > & groups,
optional_ptr< vector< GroupingSet > > grouping_sets,
bool & changes_made )
static
321698 {
321699 if (!aggr.order_bys) {
321700 // no ORDER BYs defined
321701 return nullptr;
321702 }
321703 if (aggr.function.GetOrderDependent() == AggregateOrderDependent::NOT_ORDER_DEPENDENT) {
321704 // not an order dependent aggregate but we have an ORDER BY clause - remove it
321705 aggr.order_bys.reset();
321706 changes_made = true;
321707 return nullptr;
321708 }
321709
321710 // Remove unnecessary ORDER BY clauses and return if nothing remains
321711 if (aggr.order_bys->Simplify(groups, grouping_sets)) {
321712 aggr.order_bys.reset();
321713 changes_made = true;
321714 return nullptr;
321715 }
321716
321717 // Rewrite first/last/arbitrary/any_value to use arg_xxx[_null] and create_sort_key
321718 const auto &aggr_name = aggr.function.name;
321719 string arg_xxx_name;
321720 if (aggr_name == "last") {
321721 arg_xxx_name = "arg_max_null";
321722 } else if (aggr_name == "first" || aggr_name == "arbitrary") {
321723 arg_xxx_name = "arg_min_null";
321724 } else if (aggr_name == "any_value") {
321725 arg_xxx_name = "arg_min";
321726 } else {
321727 return nullptr;
321728 }
321729
321730 FunctionBinder binder(context);
321731 vector<unique_ptr<Expression>> sort_children;
321732 for (auto &order : aggr.order_bys->orders) {
321733 sort_children.emplace_back(std::move(order.expression));
321734 sort_children.emplace_back(make_uniq<BoundConstantExpression>(Value(order.GetOrderModifier())));
321735 }
321736 aggr.order_bys.reset();
321737
321738 ErrorData error;
321739 auto sort_key = binder.BindScalarFunction(DEFAULT_SCHEMA, "create_sort_key", std::move(sort_children), error);
321740 if (!sort_key) {
321741 error.Throw();
321742 }
321743
321744 auto &children = aggr.children;
321745 children.emplace_back(std::move(sort_key));
321746
321747 // Look up the arg_xxx_name function in the catalog
321748 QueryErrorContext error_context;
321749 auto &func = Catalog::GetEntry<AggregateFunctionCatalogEntry>(context, SYSTEM_CATALOG, DEFAULT_SCHEMA, arg_xxx_name,
321750 error_context);
321751 D_ASSERT(func.type == CatalogType::AGGREGATE_FUNCTION_ENTRY);
321752
321753 // bind the aggregate
321754 vector<LogicalType> types;
321755 for (const auto &child : children) {
321756 types.emplace_back(child->return_type);
321757 }
321758 auto best_function = binder.BindFunction(func.name, func.functions, types, error);
321759 if (!best_function.IsValid()) {
321760 error.Throw();
321761 }
321762 // found a matching function!
321763 auto bound_function = func.functions.GetFunctionByOffset(best_function.GetIndex());
321764 return binder.BindAggregateFunction(bound_function, std::move(children), std::move(aggr.filter),
321765 aggr.IsDistinct() ? AggregateType::DISTINCT : AggregateType::NON_DISTINCT);
321766}
DUCKDB_API optional_ptr< CatalogEntry > GetEntry(ClientContext &context, const string &schema, const EntryLookupInfo &lookup_info, OnEntryNotFound if_not_found)
Gets the "schema.name" entry of the specified type, if entry does not exist behavior depends on OnEnt...
Definition duckdb.cpp:8156

◆ Apply() [2/2]

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

Implements duckdb::Rule.

321769 {
321770 auto &aggr = bindings[0].get().Cast<BoundAggregateExpression>();
321771 return Apply(rewriter.context, aggr, op.Cast<LogicalAggregate>().groups, op.Cast<LogicalAggregate>().grouping_sets,
321772 changes_made);
321773}

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