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

Public Member Functions

 WindowConstantAggregator (BoundWindowExpression &wexpr, WindowSharedExpressions &shared, ClientContext &context)
unique_ptr< GlobalSinkState > GetGlobalState (ClientContext &context, idx_t group_count, const ValidityMask &partition_mask) const override
void Sink (ExecutionContext &context, DataChunk &sink_chunk, DataChunk &coll_chunk, idx_t input_idx, optional_ptr< SelectionVector > filter_sel, idx_t filtered, OperatorSinkInput &sink) override
void Finalize (ExecutionContext &context, CollectionPtr collection, const FrameStats &stats, OperatorSinkInput &sink) override
unique_ptr< LocalSinkState > GetLocalState (ExecutionContext &context, const GlobalSinkState &gstate) const override
void Evaluate (ExecutionContext &context, const DataChunk &bounds, Vector &result, idx_t count, idx_t row_idx, OperatorSinkInput &sink) const override
Public Member Functions inherited from duckdb::WindowAggregator
 WindowAggregator (const BoundWindowExpression &wexpr)
 WindowAggregator (const BoundWindowExpression &wexpr, WindowSharedExpressions &shared)

Static Public Member Functions

static bool CanAggregate (const BoundWindowExpression &wexpr)
static BoundWindowExpression & RebindAggregate (ClientContext &client, BoundWindowExpression &wexpr)
Static Public Member Functions inherited from duckdb::WindowAggregator
template<typename OP>
static void EvaluateSubFrames (const DataChunk &bounds, const WindowExcludeMode exclude_mode, idx_t count, idx_t row_idx, SubFrames &frames, OP operation)

Additional Inherited Members

Public Types inherited from duckdb::WindowAggregator
using CollectionPtr = optional_ptr<WindowCollection>
Public Attributes inherited from duckdb::WindowAggregator
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

◆ WindowConstantAggregator()

duckdb::WindowConstantAggregator::WindowConstantAggregator ( BoundWindowExpression & wexpr,
WindowSharedExpressions & shared,
ClientContext & context )
255092 : WindowAggregator(RebindAggregate(context, wexpr)) {
255093 // We only need these values for Sink
255094 for (auto &child : wexpr.children) {
255095 child_idx.emplace_back(shared.RegisterSink(child));
255096 }
255097}
const BoundWindowExpression & wexpr
The window function.
Definition duckdb.cpp:164034
vector< column_t > child_idx
Partition collection column indicies.
Definition duckdb.cpp:164046

◆ ~WindowConstantAggregator()

duckdb::WindowConstantAggregator::~WindowConstantAggregator ( )
inlineoverride
253036 {
253037 }

Member Function Documentation

◆ CanAggregate()

bool duckdb::WindowConstantAggregator::CanAggregate ( const BoundWindowExpression & wexpr)
static
255015 {
255016 if (!wexpr.aggregate) {
255017 return false;
255018 }
255019
255020 // The function must be able to be used as an aggregate
255021 if (!wexpr.aggregate->CanAggregate()) {
255022 return false;
255023 }
255024
255025 // window exclusion cannot be handled by constant aggregates
255026 if (wexpr.exclude_clause != WindowExcludeMode::NO_OTHER) {
255027 return false;
255028 }
255029
255030 // DISTINCT aggregation cannot be handled by constant aggregation
255031 if (wexpr.distinct) {
255032 return false;
255033 }
255034
255035 // COUNT(*) is already handled efficiently by segment trees.
255036 if (wexpr.children.empty()) {
255037 return false;
255038 }
255039
255040 /*
255041 The default framing option is RANGE UNBOUNDED PRECEDING, which
255042 is the same as RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT
255043 ROW; it sets the frame to be all rows from the partition start
255044 up through the current row's last peer (a row that the window's
255045 ORDER BY clause considers equivalent to the current row; all
255046 rows are peers if there is no ORDER BY). In general, UNBOUNDED
255047 PRECEDING means that the frame starts with the first row of the
255048 partition, and similarly UNBOUNDED FOLLOWING means that the
255049 frame ends with the last row of the partition, regardless of
255050 RANGE, ROWS or GROUPS mode. In ROWS mode, CURRENT ROW means that
255051 the frame starts or ends with the current row; but in RANGE or
255052 GROUPS mode it means that the frame starts or ends with the
255053 current row's first or last peer in the ORDER BY ordering. The
255054 offset PRECEDING and offset FOLLOWING options vary in meaning
255055 depending on the frame mode.
255056 */
255057 switch (wexpr.start) {
255058 case WindowBoundary::UNBOUNDED_PRECEDING:
255059 break;
255060 case WindowBoundary::CURRENT_ROW_RANGE:
255061 if (!wexpr.orders.empty()) {
255062 return false;
255063 }
255064 break;
255065 default:
255066 return false;
255067 }
255068
255069 switch (wexpr.end) {
255070 case WindowBoundary::UNBOUNDED_FOLLOWING:
255071 break;
255072 case WindowBoundary::CURRENT_ROW_RANGE:
255073 if (!wexpr.orders.empty()) {
255074 return false;
255075 }
255076 break;
255077 default:
255078 return false;
255079 }
255080
255081 return true;
255082}

◆ RebindAggregate()

BoundWindowExpression & duckdb::WindowConstantAggregator::RebindAggregate ( ClientContext & client,
BoundWindowExpression & wexpr )
static
255084 {
255085 FunctionBinder::BindSortedAggregate(context, wexpr);
255086
255087 return wexpr;
255088}

◆ GetGlobalState()

unique_ptr< GlobalSinkState > duckdb::WindowConstantAggregator::GetGlobalState ( ClientContext & context,
idx_t group_count,
const ValidityMask & partition_mask ) const
overridevirtual

Reimplemented from duckdb::WindowAggregator.

255100 {
255101 return make_uniq<WindowConstantAggregatorGlobalState>(context, *this, group_count, partition_mask);
255102}

◆ Sink()

void duckdb::WindowConstantAggregator::Sink ( ExecutionContext & context,
DataChunk & sink_chunk,
DataChunk & coll_chunk,
idx_t input_idx,
optional_ptr< SelectionVector > filter_sel,
idx_t filtered,
OperatorSinkInput & sink )
overridevirtual

Reimplemented from duckdb::WindowAggregator.

255106 {
255107 auto &lastate = sink.local_state.Cast<WindowConstantAggregatorLocalState>();
255108
255109 lastate.Sink(context, sink_chunk, coll_chunk, input_idx, filter_sel, filtered);
255110}

◆ Finalize()

void duckdb::WindowConstantAggregator::Finalize ( ExecutionContext & context,
CollectionPtr collection,
const FrameStats & stats,
OperatorSinkInput & sink )
overridevirtual

Reimplemented from duckdb::WindowAggregator.

255199 {
255200 auto &gastate = sink.global_state.Cast<WindowConstantAggregatorGlobalState>();
255201 auto &lastate = sink.local_state.Cast<WindowConstantAggregatorLocalState>();
255202
255203 // Single-threaded combine
255204 lock_guard<mutex> finalize_guard(gastate.lock);
255205 lastate.statef.Combine(gastate.statef);
255206 lastate.statef.Destroy();
255207
255208 if (!--gastate.locals) {
255209 gastate.statef.Finalize(*gastate.results);
255210 }
255211}

◆ GetLocalState()

unique_ptr< LocalSinkState > duckdb::WindowConstantAggregator::GetLocalState ( ExecutionContext & context,
const GlobalSinkState & gstate ) const
overridevirtual

Implements duckdb::WindowAggregator.

255214 {
255215 return make_uniq<WindowConstantAggregatorLocalState>(context, gstate.Cast<WindowConstantAggregatorGlobalState>());
255216}

◆ Evaluate()

void duckdb::WindowConstantAggregator::Evaluate ( ExecutionContext & context,
const DataChunk & bounds,
Vector & result,
idx_t count,
idx_t row_idx,
OperatorSinkInput & sink ) const
overridevirtual

Implements duckdb::WindowAggregator.

255219 {
255220 auto &gasink = sink.global_state.Cast<WindowConstantAggregatorGlobalState>();
255221 const auto &partition_offsets = gasink.partition_offsets;
255222 const auto &results = *gasink.results;
255223
255224 auto begins = FlatVector::GetData<const idx_t>(bounds.data[FRAME_BEGIN]);
255225 // Chunk up the constants and copy them one at a time
255226 auto &lcstate = sink.local_state.Cast<WindowConstantAggregatorLocalState>();
255227 idx_t matched = 0;
255228 idx_t target_offset = 0;
255229 for (idx_t i = 0; i < count; ++i) {
255230 const auto begin = begins[i];
255231 // Find the partition containing [begin, end)
255232 while (partition_offsets[lcstate.partition + 1] <= begin) {
255233 // Flush the previous partition's data
255234 if (matched) {
255235 VectorOperations::Copy(results, result, lcstate.matches, matched, 0, target_offset);
255236 target_offset += matched;
255237 matched = 0;
255238 }
255239 ++lcstate.partition;
255240 }
255241
255242 lcstate.matches.set_index(matched++, lcstate.partition);
255243 }
255244
255245 // Flush the last partition
255246 if (matched) {
255247 // Optimize constant result
255248 if (target_offset == 0 && matched == count) {
255249 VectorOperations::Copy(results, result, lcstate.matches, 1, 0, target_offset);
255250 result.SetVectorType(VectorType::CONSTANT_VECTOR);
255251 } else {
255252 VectorOperations::Copy(results, result, lcstate.matches, matched, 0, target_offset);
255253 }
255254 }
255255}
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

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