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

Public Member Functions

 WindowFillExecutor (BoundWindowExpression &wexpr, ClientContext &client, WindowSharedExpressions &shared)
bool IgnoreNulls () const override
 Never ignore nulls (that's the point!).
unique_ptr< GlobalSinkState > GetGlobalState (ClientContext &client, const idx_t payload_count, const ValidityMask &partition_mask, const ValidityMask &order_mask) const override
unique_ptr< LocalSinkState > GetLocalState (ExecutionContext &context, const GlobalSinkState &gstate) const override
Public Member Functions inherited from duckdb::WindowValueExecutor
 WindowValueExecutor (BoundWindowExpression &wexpr, WindowSharedExpressions &shared)
void Finalize (ExecutionContext &context, CollectionPtr collection, OperatorSinkInput &sink) const override
unique_ptr< GlobalSinkState > GetGlobalState (ClientContext &client, const idx_t payload_count, const ValidityMask &partition_mask, const ValidityMask &order_mask) const override
unique_ptr< LocalSinkState > GetLocalState (ExecutionContext &context, const GlobalSinkState &gstate) const override
Public Member Functions inherited from duckdb::WindowExecutor
 WindowExecutor (BoundWindowExpression &wexpr, WindowSharedExpressions &shared)
virtual void Sink (ExecutionContext &context, DataChunk &sink_chunk, DataChunk &coll_chunk, const idx_t input_idx, OperatorSinkInput &sink) const
void Evaluate (ExecutionContext &context, idx_t row_idx, DataChunk &eval_chunk, Vector &result, OperatorSinkInput &sink) const

Public Attributes

idx_t order_idx = DConstants::INVALID_INDEX
 Secondary order collection index.
Public Attributes inherited from duckdb::WindowValueExecutor
column_t child_idx = DConstants::INVALID_INDEX
 The column index of the value column.
column_t nth_idx = DConstants::INVALID_INDEX
 The column index of the Nth column.
column_t offset_idx = DConstants::INVALID_INDEX
 The column index of the offset column.
column_t default_idx = DConstants::INVALID_INDEX
 The column index of the default value column.
vector< column_t > arg_order_idx
 The column indices of any ORDER BY argument expressions.
Public Attributes inherited from duckdb::WindowExecutor
const BoundWindowExpression & wexpr
column_t boundary_start_idx = DConstants::INVALID_INDEX
column_t boundary_end_idx = DConstants::INVALID_INDEX
optional_ptr< Expression > range_expr
column_t range_idx = DConstants::INVALID_INDEX

Protected Member Functions

void EvaluateInternal (ExecutionContext &context, DataChunk &eval_chunk, Vector &result, idx_t count, idx_t row_idx, OperatorSinkInput &sink) const override

Additional Inherited Members

Public Types inherited from duckdb::WindowExecutor
using CollectionPtr = optional_ptr<WindowCollection>

Constructor & Destructor Documentation

◆ WindowFillExecutor()

duckdb::WindowFillExecutor::WindowFillExecutor ( BoundWindowExpression & wexpr,
ClientContext & client,
WindowSharedExpressions & shared )
259212 : WindowValueExecutor(wexpr, shared) {
259213 // If the argument order is prefix of the partition ordering,
259214 // then we can just use the partition ordering.
259215 auto &arg_orders = wexpr.arg_orders;
259216 const auto optimize = ClientConfig::GetConfig(client).enable_optimizer;
259217 if (optimize && BoundWindowExpression::GetSharedOrders(wexpr.orders, arg_orders) == arg_orders.size()) {
259218 arg_order_idx.clear();
259219 }
259220
259221 // We need the sort values for interpolation, so either use the range or the secondary ordering expression
259222 if (arg_order_idx.empty()) {
259223 // We use the range ordering, even if it has not been defined
259224 if (!range_expr) {
259225 D_ASSERT(wexpr.orders.size() == 1);
259226 // We don't need the validity mask because we have also requested the valid range for the ordering.
259227 range_idx = shared.RegisterCollection(wexpr.orders[0].expression, false);
259228 }
259229 } else {
259230 // For secondary sorts, we need the entire collection so we can interpolate using the values
259231 D_ASSERT(arg_order_idx.size() == 1);
259232 order_idx = shared.RegisterCollection(wexpr.arg_orders[0].expression, false);
259233 }
259234}
static idx_t GetSharedOrders(const vector< BoundOrderByNode > &lhs, const vector< BoundOrderByNode > &rhs)
The number of ordering clauses the functions share.
Definition duckdb.cpp:376957
idx_t order_idx
Secondary order collection index.
Definition duckdb.cpp:164413
vector< column_t > arg_order_idx
The column indices of any ORDER BY argument expressions.
Definition duckdb.cpp:164354

Member Function Documentation

◆ IgnoreNulls()

bool duckdb::WindowFillExecutor::IgnoreNulls ( ) const
inlineoverridevirtual

Never ignore nulls (that's the point!).

Reimplemented from duckdb::WindowExecutor.

164403 {
164404 return false;
164405 }

◆ GetGlobalState()

unique_ptr< GlobalSinkState > duckdb::WindowFillExecutor::GetGlobalState ( ClientContext & client,
const idx_t payload_count,
const ValidityMask & partition_mask,
const ValidityMask & order_mask ) const
overridevirtual

Reimplemented from duckdb::WindowExecutor.

259289 {
259290 return make_uniq<WindowFillGlobalState>(client, *this, payload_count, partition_mask, order_mask);
259291}

◆ GetLocalState()

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

Reimplemented from duckdb::WindowExecutor.

259294 {
259295 const auto &gfstate = gstate.Cast<WindowFillGlobalState>();
259296 return make_uniq<WindowFillLocalState>(context, gfstate);
259297}

◆ EvaluateInternal()

void duckdb::WindowFillExecutor::EvaluateInternal ( ExecutionContext & context,
DataChunk & eval_chunk,
Vector & result,
idx_t count,
idx_t row_idx,
OperatorSinkInput & sink ) const
overrideprotectedvirtual

Implements duckdb::WindowExecutor.

259300 {
259301 auto &lfstate = sink.local_state.Cast<WindowFillLocalState>();
259302 auto &cursor = *lfstate.cursor;
259303
259304 // Assume the best and just batch copy all the values
259305 WindowFillCopy(cursor, result, count, row_idx, 0);
259306
259307 // If all are valid, we are done
259308 UnifiedVectorFormat arg_data;
259309 result.ToUnifiedFormat(count, arg_data);
259310 if (arg_data.validity.AllValid()) {
259311 return;
259312 }
259313
259314 // Missing values - linear interpolation
259315 auto &gfstate = sink.global_state.Cast<WindowFillGlobalState>();
259316 auto partition_begin = FlatVector::GetData<const idx_t>(lfstate.bounds.data[PARTITION_BEGIN]);
259317 auto partition_end = FlatVector::GetData<const idx_t>(lfstate.bounds.data[PARTITION_END]);
259318
259319 idx_t prev_valid = DConstants::INVALID_INDEX;
259320 idx_t next_valid = DConstants::INVALID_INDEX;
259321
259322 auto interpolate_func = GetFillInterpolateFunction(wexpr.children[0]->return_type);
259323 auto value_func = GetFillValueFunction(wexpr.children[0]->return_type);
259324
259325 // Secondary sort - use the MSTs
259326 if (gfstate.value_tree) {
259327 // Roughly what we need to do is find the previous and next non-null values
259328 // with non-null ordering values. This is essentially LEAD/LAG(IGNORE NULLS)
259329 auto &order_cursor = *lfstate.order_cursor;
259330 auto slope_func = GetFillSlopeFunction(wexpr.arg_orders[0].expression->return_type);
259331 auto order_value_func = GetFillValueFunction(wexpr.arg_orders[0].expression->return_type);
259332 auto &frames = lfstate.frames;
259333 frames.resize(1);
259334 auto &frame = frames[0];
259335 for (idx_t i = 0; i < count; ++i, ++row_idx) {
259336 // If this value is valid, move on
259337 const auto idx = arg_data.sel->get_index(i);
259338 if (arg_data.validity.RowIsValid(idx)) {
259339 continue;
259340 }
259341
259342 // Frame is the entire partition
259343 frame = {partition_begin[i], partition_end[i]};
259344 const auto frame_width = frame.end - frame.start;
259345 D_ASSERT(frame.end != frame.start);
259346
259347 // If we are outside the validity range of the sort column, we can't fix this value.
259348 if (!order_value_func(row_idx, order_cursor)) {
259349 continue;
259350 }
259351
259352 // Find the own row number in the secondary sort
259353 const auto own_row = gfstate.row_tree->Rank(frame.start, frame.end, row_idx) - 1;
259354
259355 // Find the previous valid value, scanning backwards from the current row
259356 // Note that we can't reuse previous values as the scan order is not the sort order
259357 prev_valid = DConstants::INVALID_INDEX;
259359 for (idx_t n = own_row; n-- > 0;) {
259360 auto j = gfstate.value_tree->SelectNth(frames, n).first;
259361 if (!order_value_func(j, order_cursor)) {
259362 break;
259363 }
259364 if (value_func(j, cursor)) {
259365 prev_valid = j;
259366 prev_n = n;
259367 break;
259368 }
259369 }
259370
259371 // If there is nothing beind us (missing early value) then scan forward
259372 if (prev_valid == DConstants::INVALID_INDEX) {
259373 for (idx_t n = own_row + 1; n < frame_width; ++n) {
259374 auto j = gfstate.value_tree->SelectNth(frames, n).first;
259375 if (!order_value_func(j, order_cursor)) {
259376 break;
259377 }
259378 if (value_func(j, cursor)) {
259379 prev_valid = j;
259380 prev_n = n;
259381 break;
259382 }
259383 }
259384 }
259385
259386 // No valid values!
259387 if (prev_valid == DConstants::INVALID_INDEX) {
259388 // Skip to the next partition
259389 i += partition_end[i] - row_idx - 1;
259390 if (i >= count) {
259391 return;
259392 }
259393 row_idx = partition_end[i] - 1;
259394 continue;
259395 }
259396
259397 // Find the next valid value after the previous
259398 next_valid = DConstants::INVALID_INDEX;
259399 for (idx_t n = prev_n + 1; n < frame_width; ++n) {
259400 auto j = gfstate.value_tree->SelectNth(frames, n).first;
259401 if (!order_value_func(j, order_cursor)) {
259402 break;
259403 }
259404 if (value_func(j, cursor)) {
259405 next_valid = j;
259406 break;
259407 }
259408 }
259409
259410 // Nothing after, so scan backwards from the previous
259411 if (next_valid == DConstants::INVALID_INDEX && prev_n > 0) {
259412 for (idx_t n = prev_n; n-- > 0;) {
259413 auto j = gfstate.value_tree->SelectNth(frames, n).first;
259414 if (!order_value_func(j, order_cursor)) {
259415 break;
259416 }
259417 if (value_func(j, cursor)) {
259418 next_valid = j;
259419 // Restore ordering
259420 std::swap(prev_valid, next_valid);
259421 break;
259422 }
259423 }
259424 }
259425
259426 // If we only have one value, then just copy it
259427 if (next_valid == DConstants::INVALID_INDEX) {
259428 cursor.CopyCell(0, prev_valid, result, i);
259429 continue;
259430 }
259431
259432 // Two values, so interpolate
259433 // y = y0 + (y1 - y0) / (x1 - x0) * (x - x0)
259434 const auto slope = slope_func(order_cursor, row_idx, prev_valid, next_valid);
259435 interpolate_func(result, i, cursor, prev_valid, next_valid, slope);
259436 }
259437 return;
259438 }
259439
259440 auto valid_begin = FlatVector::GetData<const idx_t>(lfstate.bounds.data[VALID_BEGIN]);
259441 auto valid_end = FlatVector::GetData<const idx_t>(lfstate.bounds.data[VALID_END]);
259442 auto &order_cursor = *lfstate.range_cursor;
259443 idx_t prev_partition = DConstants::INVALID_INDEX;
259444 auto slope_func = GetFillSlopeFunction(wexpr.orders[0].expression->return_type);
259445 auto order_value_func = GetFillValueFunction(wexpr.orders[0].expression->return_type);
259446
259447 for (idx_t i = 0; i < count; ++i, ++row_idx) {
259448 // Did we change partitions?
259449 if (prev_partition != partition_begin[i]) {
259450 prev_partition = partition_begin[i];
259451 prev_valid = DConstants::INVALID_INDEX;
259452 next_valid = DConstants::INVALID_INDEX;
259453 }
259454
259455 // If we are outside the validity range of the sort column, we can't fix this value.
259456 if (row_idx < valid_begin[i] || valid_end[i] <= row_idx || !order_value_func(row_idx, order_cursor)) {
259457 continue;
259458 }
259459
259460 // If this value is valid,
259461 const auto idx = arg_data.sel->get_index(i);
259462 if (arg_data.validity.RowIsValid(idx)) {
259463 // If it is usable, track it for the next gap.
259464 if (value_func(row_idx, cursor)) {
259465 prev_valid = row_idx;
259466 }
259467 continue;
259468 }
259469
259470 // Missing value, so look for interpolation values
259471
259472 // Find the previous valid value, scanning backwards from the current row
259473 if (prev_valid == DConstants::INVALID_INDEX) {
259474 for (idx_t j = row_idx; j-- > valid_begin[i];) {
259475 if (!order_value_func(j, order_cursor)) {
259476 break;
259477 }
259478 if (value_func(j, cursor)) {
259479 prev_valid = j;
259480 break;
259481 }
259482 }
259483 }
259484
259485 // If there is nothing behind us (missing early value) then scan forward
259486 if (prev_valid == DConstants::INVALID_INDEX) {
259487 for (idx_t j = row_idx + 1; j < valid_end[i]; ++j) {
259488 if (!order_value_func(j, order_cursor)) {
259489 break;
259490 }
259491 if (value_func(j, cursor)) {
259492 prev_valid = j;
259493 break;
259494 }
259495 }
259496 }
259497
259498 // No valid values!
259499 if (prev_valid == DConstants::INVALID_INDEX) {
259500 // Skip to the next partition
259501 i += partition_end[i] - row_idx - 1;
259502 if (i >= count) {
259503 break;
259504 }
259505 row_idx = partition_end[i] - 1;
259506 continue;
259507 }
259508
259509 // Find the next valid value after the previous
259510 next_valid = DConstants::INVALID_INDEX;
259511 for (idx_t j = prev_valid + 1; j < valid_end[i]; ++j) {
259512 if (!order_value_func(j, order_cursor)) {
259513 break;
259514 }
259515 if (value_func(j, cursor)) {
259516 next_valid = j;
259517 break;
259518 }
259519 }
259520
259521 // Nothing after, so scan backwards
259522 if (next_valid == DConstants::INVALID_INDEX) {
259523 for (idx_t j = prev_valid; j-- > valid_begin[i];) {
259524 if (!order_value_func(j, order_cursor)) {
259525 break;
259526 }
259527 if (value_func(j, cursor)) {
259528 next_valid = j;
259529 // Restore ordering
259530 std::swap(prev_valid, next_valid);
259531 break;
259532 }
259533 }
259534 }
259535
259536 // If we only have one value, then just copy it
259537 if (next_valid == DConstants::INVALID_INDEX) {
259538 cursor.CopyCell(0, prev_valid, result, i);
259539 continue;
259540 }
259541
259542 // Two values, so interpolate
259543 // y = y0 + (y1 - y0) / (x1 - x0) * (x - x0)
259544 const auto slope = slope_func(order_cursor, row_idx, prev_valid, next_valid);
259545 interpolate_func(result, i, cursor, prev_valid, next_valid, slope);
259546 }
259547}
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237
static constexpr const idx_t INVALID_INDEX
The value used to signify an invalid index entry.
Definition duckdb.hpp:1117

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