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::StreamingWindowState::AggregateState Struct Reference
Collaboration diagram for duckdb::StreamingWindowState::AggregateState:

Public Member Functions

 AggregateState (ClientContext &client, BoundWindowExpression &wexpr, Allocator &allocator)
void Execute (ExecutionContext &context, DataChunk &input, Vector &result)

Public Attributes

BoundWindowExpression & wexpr
 The aggregate expression.
ArenaAllocator arena_allocator
 The allocator to use for aggregate data structures.
ExpressionExecutor executor
 Reusable executor for the children.
ExpressionExecutor filter_executor
 Shared executor for FILTER clauses.
vector< data_t > state
 The single aggregate state we update row-by-row.
data_ptr_t state_ptr = nullptr
 The pointer to the state stored in the state vector.
Vector statev
 The state vector for the single state.
FunctionData * bind_data = nullptr
 The aggregate binding data (if any).
aggregate_destructor_t dtor = nullptr
 The aggregate state destructor (if any).
SelectionVector filter_sel
 The inputs rows that pass the FILTER.
int64_t unfiltered = 0
 The number of unfiltered rows so far for COUNT(*).
vector< LogicalType > arg_types
 Argument types.
DataChunk arg_chunk
 Argument value buffer.
DataChunk arg_cursor
 Argument cursor (a one element slice of arg_chunk).
unique_ptr< GroupedAggregateHashTable > distinct
 Hash table for accumulating the distinct values.
DataChunk distinct_args
 Filtered arguments for checking distinctness.
Vector hashes
 Reusable hash vector.
SelectionVector distinct_sel
 Rows that produced new distinct values.
Vector addresses
 Pointers to groups in the hash table.

Constructor & Destructor Documentation

◆ AggregateState()

duckdb::StreamingWindowState::AggregateState::AggregateState ( ClientContext & client,
BoundWindowExpression & wexpr,
Allocator & allocator )
inline
161767 : wexpr(wexpr), arena_allocator(BufferAllocator::Get((client))), executor(client), filter_executor(client),
161768 statev(LogicalType::POINTER, data_ptr_cast(&state_ptr)), hashes(LogicalType::HASH),
161769 addresses(LogicalType::POINTER) {
161770 D_ASSERT(wexpr.GetExpressionType() == ExpressionType::WINDOW_AGGREGATE);
161771 auto &aggregate = *wexpr.aggregate;
161772 bind_data = wexpr.bind_info.get();
161773 dtor = aggregate.GetStateDestructorCallback();
161774 state.resize(aggregate.GetStateSizeCallback()(aggregate));
161775 state_ptr = state.data();
161776 aggregate.GetStateInitCallback()(aggregate, state.data());
161777 for (auto &child : wexpr.children) {
161778 arg_types.push_back(child->return_type);
161779 executor.AddExpression(*child);
161780 }
161781 if (!arg_types.empty()) {
161782 arg_chunk.Initialize(allocator, arg_types);
161783 arg_cursor.Initialize(allocator, arg_types);
161784 }
161785 if (wexpr.filter_expr) {
161786 filter_executor.AddExpression(*wexpr.filter_expr);
161787 filter_sel.Initialize();
161788 }
161789 if (wexpr.distinct) {
161790 distinct = make_uniq<GroupedAggregateHashTable>(client, allocator, arg_types);
161791 distinct_args.Initialize(allocator, arg_types);
161792 distinct_sel.Initialize();
161793 }
161794 }
unique_ptr< GroupedAggregateHashTable > distinct
Hash table for accumulating the distinct values.
Definition duckdb.cpp:161836
DataChunk distinct_args
Filtered arguments for checking distinctness.
Definition duckdb.cpp:161838
FunctionData * bind_data
The aggregate binding data (if any).
Definition duckdb.cpp:161821
ExpressionExecutor executor
Reusable executor for the children.
Definition duckdb.cpp:161811
DataChunk arg_chunk
Argument value buffer.
Definition duckdb.cpp:161831
Vector addresses
Pointers to groups in the hash table.
Definition duckdb.cpp:161844
SelectionVector filter_sel
The inputs rows that pass the FILTER.
Definition duckdb.cpp:161825
Vector hashes
Reusable hash vector.
Definition duckdb.cpp:161840
aggregate_destructor_t dtor
The aggregate state destructor (if any).
Definition duckdb.cpp:161823
Vector statev
The state vector for the single state.
Definition duckdb.cpp:161819
data_ptr_t state_ptr
The pointer to the state stored in the state vector.
Definition duckdb.cpp:161817
ExpressionExecutor filter_executor
Shared executor for FILTER clauses.
Definition duckdb.cpp:161813
ArenaAllocator arena_allocator
The allocator to use for aggregate data structures.
Definition duckdb.cpp:161809
vector< LogicalType > arg_types
Argument types.
Definition duckdb.cpp:161829
BoundWindowExpression & wexpr
The aggregate expression.
Definition duckdb.cpp:161807
vector< data_t > state
The single aggregate state we update row-by-row.
Definition duckdb.cpp:161815
DataChunk arg_cursor
Argument cursor (a one element slice of arg_chunk).
Definition duckdb.cpp:161833
SelectionVector distinct_sel
Rows that produced new distinct values.
Definition duckdb.cpp:161842

◆ ~AggregateState()

duckdb::StreamingWindowState::AggregateState::~AggregateState ( )
inline
161796 {
161797 if (dtor) {
161798 AggregateInputData aggr_input_data(bind_data, arena_allocator);
161799 state_ptr = state.data();
161800 dtor(statev, aggr_input_data, 1);
161801 }
161802 }

Member Function Documentation

◆ Execute()

void duckdb::StreamingWindowState::AggregateState::Execute ( ExecutionContext & context,
DataChunk & input,
Vector & result )
162139 {
162140 // Establish the aggregation environment
162141 const idx_t count = input.size();
162142 auto &aggregate = *wexpr.aggregate;
162143 auto &aggr_state = *this;
162144 auto &statev = aggr_state.statev;
162145
162146 // Compute the FILTER mask (if any)
162147 ValidityMask filter_mask;
162148 auto filtered = count;
162149 auto &filter_sel = aggr_state.filter_sel;
162150 if (wexpr.filter_expr) {
162151 filtered = filter_executor.SelectExpression(input, filter_sel);
162152 if (filtered < count) {
162153 filter_mask.Initialize(count);
162154 filter_mask.SetAllInvalid(count);
162155 for (idx_t f = 0; f < filtered; ++f) {
162156 filter_mask.SetValid(filter_sel.get_index(f));
162157 }
162158 }
162159 }
162160
162161 // Check for COUNT(*)
162162 if (wexpr.children.empty()) {
162163 D_ASSERT(GetTypeIdSize(result.GetType().InternalType()) == sizeof(int64_t));
162164 auto data = FlatVector::GetData<int64_t>(result);
162165 auto &unfiltered = aggr_state.unfiltered;
162166 for (idx_t i = 0; i < count; ++i) {
162167 unfiltered += int64_t(filter_mask.RowIsValid(i));
162168 data[i] = unfiltered;
162169 }
162170 return;
162171 }
162172
162173 // Compute the arguments
162174 auto &arg_chunk = aggr_state.arg_chunk;
162175 arg_chunk.Reset();
162176 executor.Execute(input, arg_chunk);
162177 arg_chunk.Flatten();
162178
162179 // Update the distinct hash table
162180 ValidityMask distinct_mask;
162181 if (aggr_state.distinct) {
162182 auto &distinct_args = aggr_state.distinct_args;
162183 distinct_args.Reference(arg_chunk);
162184 if (wexpr.filter_expr) {
162185 distinct_args.Slice(filter_sel, filtered);
162186 }
162187 idx_t distinct = 0;
162188 auto &distinct_sel = aggr_state.distinct_sel;
162189 if (filtered) {
162190 // FindOrCreateGroups assumes non-empty input
162191 auto &hashes = aggr_state.hashes;
162192 distinct_args.Hash(hashes);
162193
162194 auto &addresses = aggr_state.addresses;
162195 distinct = aggr_state.distinct->FindOrCreateGroups(distinct_args, hashes, addresses, distinct_sel);
162196 }
162197
162198 // Translate the distinct selection from filtered row numbers
162199 // back to input row numbers. We need to produce output for all input rows,
162200 // so we filter out
162201 if (distinct < filtered) {
162202 distinct_mask.Initialize(count);
162203 distinct_mask.SetAllInvalid(count);
162204 for (idx_t d = 0; d < distinct; ++d) {
162205 const auto f = distinct_sel.get_index(d);
162206 distinct_mask.SetValid(filter_sel.get_index(f));
162207 }
162208 }
162209 }
162210
162211 // Iterate through them using a single SV
162212 sel_t s = 0;
162213 SelectionVector sel(&s);
162214 auto &arg_cursor = aggr_state.arg_cursor;
162215 arg_cursor.Reset();
162216 arg_cursor.Slice(sel, 1);
162217 // This doesn't work for STRUCTs because the SV
162218 // is not copied to the children when you slice
162219 vector<column_t> structs;
162220 for (column_t col_idx = 0; col_idx < arg_chunk.ColumnCount(); ++col_idx) {
162221 auto &col_vec = arg_cursor.data[col_idx];
162222 DictionaryVector::Child(col_vec).Reference(arg_chunk.data[col_idx]);
162223 if (col_vec.GetType().InternalType() == PhysicalType::STRUCT) {
162224 structs.emplace_back(col_idx);
162225 }
162226 }
162227
162228 // Update the state and finalize it one row at a time.
162229 AggregateInputData aggr_input_data(wexpr.bind_info.get(), aggr_state.arena_allocator);
162230 for (idx_t i = 0; i < count; ++i) {
162231 sel.set_index(0, i);
162232 for (const auto struct_idx : structs) {
162233 arg_cursor.data[struct_idx].Slice(arg_chunk.data[struct_idx], sel, 1);
162234 }
162235 if (filter_mask.RowIsValid(i) && distinct_mask.RowIsValid(i)) {
162236 aggregate.GetStateUpdateCallback()(arg_cursor.data.data(), aggr_input_data, arg_cursor.ColumnCount(),
162237 statev, 1);
162238 }
162239 aggregate.GetStateFinalizeCallback()(statev, aggr_input_data, result, 1, i);
162240 }
162241}
SelectionVector sel
A temporary selection vector.
Definition duckdb.cpp:162084
::int64_t int64_t
idx_t column_t
Type used for column identifiers.
Definition duckdb.hpp:259
@ STRUCT
Struct of logical types.
Definition duckdb.hpp:2816
uint32_t sel_t
Type used for the selection vector.
Definition duckdb.hpp:251
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237
int64_t unfiltered
The number of unfiltered rows so far for COUNT(*).
Definition duckdb.cpp:161827

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