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::WindowAggregator Class Referenceabstract
Inheritance diagram for duckdb::WindowAggregator:
Collaboration diagram for duckdb::WindowAggregator:

Public Types

using CollectionPtr = optional_ptr<WindowCollection>

Public Member Functions

 WindowAggregator (const BoundWindowExpression &wexpr)
 WindowAggregator (const BoundWindowExpression &wexpr, WindowSharedExpressions &shared)
virtual unique_ptr< GlobalSinkState > GetGlobalState (ClientContext &client, idx_t group_count, const ValidityMask &partition_mask) const
virtual unique_ptr< LocalSinkState > GetLocalState (ExecutionContext &context, const GlobalSinkState &gstate) const =0
virtual void Sink (ExecutionContext &context, DataChunk &sink_chunk, DataChunk &coll_chunk, idx_t input_idx, optional_ptr< SelectionVector > filter_sel, idx_t filtered, OperatorSinkInput &sink)
virtual void Finalize (ExecutionContext &context, CollectionPtr collection, const FrameStats &stats, OperatorSinkInput &sink)
virtual void Evaluate (ExecutionContext &context, const DataChunk &bounds, Vector &result, idx_t count, idx_t row_idx, OperatorSinkInput &sink) const =0

Static Public Member Functions

template<typename OP>
static void EvaluateSubFrames (const DataChunk &bounds, const WindowExcludeMode exclude_mode, idx_t count, idx_t row_idx, SubFrames &frames, OP operation)

Public Attributes

const BoundWindowExpression & wexpr
 The window function.
const AggregateObject aggr
 A description of the aggregator.
vector< LogicalType > arg_types
 The argument types for the function.
const LogicalType result_type
 The result type of the window function.
const idx_t state_size
 The size of a single aggregate state.
const WindowExcludeMode exclude_mode
 The window exclusion clause.
vector< column_t > child_idx
 Partition collection column indicies.

Constructor & Destructor Documentation

◆ WindowAggregator() [1/2]

duckdb::WindowAggregator::WindowAggregator ( const BoundWindowExpression & wexpr)
explicit
253569 : wexpr(wexpr), aggr(wexpr), result_type(wexpr.return_type),
253570 state_size(aggr.function.GetStateSizeCallback()(aggr.function)), exclude_mode(wexpr.exclude_clause) {
253571 for (auto &child : wexpr.children) {
253572 arg_types.emplace_back(child->return_type);
253573 }
253574}
vector< LogicalType > arg_types
The argument types for the function.
Definition duckdb.cpp:164038
const LogicalType result_type
The result type of the window function.
Definition duckdb.cpp:164040
const BoundWindowExpression & wexpr
The window function.
Definition duckdb.cpp:164034
const WindowExcludeMode exclude_mode
The window exclusion clause.
Definition duckdb.cpp:164044
const AggregateObject aggr
A description of the aggregator.
Definition duckdb.cpp:164036
const idx_t state_size
The size of a single aggregate state.
Definition duckdb.cpp:164042

◆ WindowAggregator() [2/2]

duckdb::WindowAggregator::WindowAggregator ( const BoundWindowExpression & wexpr,
WindowSharedExpressions & shared )
253577 : WindowAggregator(wexpr) {
253578 for (auto &child : wexpr.children) {
253579 child_idx.emplace_back(shared.RegisterCollection(child, false));
253580 }
253581}
vector< column_t > child_idx
Partition collection column indicies.
Definition duckdb.cpp:164046

◆ ~WindowAggregator()

duckdb::WindowAggregator::~WindowAggregator ( )
virtual
253583 {
253584}

Member Function Documentation

◆ EvaluateSubFrames()

template<typename OP>
void duckdb::WindowAggregator::EvaluateSubFrames ( const DataChunk & bounds,
const WindowExcludeMode exclude_mode,
idx_t count,
idx_t row_idx,
SubFrames & frames,
OP operation )
inlinestatic
163952 {
163953 auto begins = FlatVector::GetData<const idx_t>(bounds.data[FRAME_BEGIN]);
163954 auto ends = FlatVector::GetData<const idx_t>(bounds.data[FRAME_END]);
163955 auto peer_begin = FlatVector::GetData<const idx_t>(bounds.data[PEER_BEGIN]);
163956 auto peer_end = FlatVector::GetData<const idx_t>(bounds.data[PEER_END]);
163957
163958 for (idx_t i = 0, cur_row = row_idx; i < count; ++i, ++cur_row) {
163959 idx_t nframes = 0;
163960 if (exclude_mode == WindowExcludeMode::NO_OTHER) {
163961 auto begin = begins[i];
163962 auto end = ends[i];
163963 frames[nframes++] = FrameBounds(begin, end);
163964 } else {
163965 // The frame_exclusion option allows rows around the current row to be excluded from the frame,
163966 // even if they would be included according to the frame start and frame end options.
163967 // EXCLUDE CURRENT ROW excludes the current row from the frame.
163968 // EXCLUDE GROUP excludes the current row and its ordering peers from the frame.
163969 // EXCLUDE TIES excludes any peers of the current row from the frame, but not the current row itself.
163970 // EXCLUDE NO OTHERS simply specifies explicitly the default behavior
163971 // of not excluding the current row or its peers.
163972 // https://www.postgresql.org/docs/current/sql-expressions.html#SYNTAX-WINDOW-FUNCTIONS
163973 //
163974 // For the sake of the client, we make some guarantees about the subframes:
163975 // * They are in order left-to-right
163976 // * They do not intersect
163977 // * start <= end
163978 // * The number is always the same
163979 //
163980 // Since we always have peer_begin <= cur_row < cur_row + 1 <= peer_end
163981 // this is not too hard to arrange, but it may be that some subframes are contiguous,
163982 // and some are empty.
163983
163984 // WindowExcludePart::LEFT
163985 const auto frame_begin = begins[i];
163986 const auto frame_end = ends[i];
163987 auto begin = frame_begin;
163988 auto end = (exclude_mode == WindowExcludeMode::CURRENT_ROW) ? cur_row : peer_begin[i];
163989 end = MinValue(end, frame_end);
163990 end = MaxValue(end, frame_begin);
163991 frames[nframes++] = FrameBounds(begin, end);
163992
163993 // with EXCLUDE TIES, in addition to the frame part right of the peer group's end,
163994 // we also need to consider the current row
163995 if (exclude_mode == WindowExcludeMode::TIES) {
163996 begin = MinValue(MaxValue(cur_row, frame_begin), frame_end);
163997 end = MaxValue(MinValue(cur_row + 1, frame_end), frame_begin);
163998 frames[nframes++] = FrameBounds(begin, end);
163999 }
164000
164001 // WindowExcludePart::RIGHT
164002 end = frame_end;
164003 begin = (exclude_mode == WindowExcludeMode::CURRENT_ROW) ? (cur_row + 1) : peer_end[i];
164004 begin = MaxValue(begin, frame_begin);
164005 begin = MinValue(begin, frame_end);
164006 frames[nframes++] = FrameBounds(begin, end);
164007 }
164008
164009 operation(i);
164010 }
164011 }
vector< Vector > data
The vectors owned by the DataChunk.
Definition duckdb.hpp:11445
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237

◆ GetGlobalState()

unique_ptr< GlobalSinkState > duckdb::WindowAggregator::GetGlobalState ( ClientContext & client,
idx_t group_count,
const ValidityMask & partition_mask ) const
virtual
253599 {
253600 return make_uniq<WindowAggregatorGlobalState>(context, *this, group_count);
253601}

◆ Sink()

void duckdb::WindowAggregator::Sink ( ExecutionContext & context,
DataChunk & sink_chunk,
DataChunk & coll_chunk,
idx_t input_idx,
optional_ptr< SelectionVector > filter_sel,
idx_t filtered,
OperatorSinkInput & sink )
virtual
253612 {
253613 auto &gastate = sink.global_state.Cast<WindowAggregatorGlobalState>();
253614 auto &lastate = sink.local_state.Cast<WindowAggregatorLocalState>();
253615 lastate.Sink(context, gastate, sink_chunk, coll_chunk, input_idx);
253616 if (filter_sel) {
253617 auto &filter_mask = gastate.filter_mask;
253618 for (idx_t f = 0; f < filtered; ++f) {
253619 filter_mask.SetValid(input_idx + filter_sel->get_index(f));
253620 }
253621 }
253622}

◆ Finalize()

void duckdb::WindowAggregator::Finalize ( ExecutionContext & context,
CollectionPtr collection,
const FrameStats & stats,
OperatorSinkInput & sink )
virtual
253650 {
253651 auto &gasink = sink.global_state.Cast<WindowAggregatorGlobalState>();
253652 auto &lastate = sink.local_state.Cast<WindowAggregatorLocalState>();
253653 lastate.Finalize(context, gasink, collection);
253654}

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