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

Public Member Functions

 WindowNtileExecutor (BoundWindowExpression &wexpr, WindowSharedExpressions &shared)
Public Member Functions inherited from duckdb::WindowRowNumberExecutor
 WindowRowNumberExecutor (BoundWindowExpression &wexpr, WindowSharedExpressions &shared)
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 bool IgnoreNulls () const
virtual void Sink (ExecutionContext &context, DataChunk &sink_chunk, DataChunk &coll_chunk, const idx_t input_idx, OperatorSinkInput &sink) const
virtual void Finalize (ExecutionContext &context, CollectionPtr collection, OperatorSinkInput &sink) const
void Evaluate (ExecutionContext &context, idx_t row_idx, DataChunk &eval_chunk, Vector &result, OperatorSinkInput &sink) const

Protected Member Functions

void EvaluateInternal (ExecutionContext &context, DataChunk &eval_chunk, Vector &result, idx_t count, idx_t row_idx, OperatorSinkInput &sink) const override
Protected Member Functions inherited from duckdb::WindowRowNumberExecutor
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>
Public Attributes inherited from duckdb::WindowRowNumberExecutor
column_t ntile_idx = DConstants::INVALID_INDEX
 The evaluation index of the NTILE 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

Constructor & Destructor Documentation

◆ WindowNtileExecutor()

duckdb::WindowNtileExecutor::WindowNtileExecutor ( BoundWindowExpression & wexpr,
WindowSharedExpressions & shared )
257486 : WindowRowNumberExecutor(wexpr, shared) {
257487 // NTILE has one argument
257488 ntile_idx = shared.RegisterEvaluate(wexpr.children[0]);
257489}
column_t ntile_idx
The evaluation index of the NTILE column.
Definition duckdb.cpp:164221

Member Function Documentation

◆ EvaluateInternal()

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

Implements duckdb::WindowExecutor.

257492 {
257493 auto &grstate = sink.global_state.Cast<WindowRowNumberGlobalState>();
257494 auto &lrstate = sink.local_state.Cast<WindowRowNumberLocalState>();
257495 auto partition_begin = FlatVector::GetData<const idx_t>(lrstate.bounds.data[PARTITION_BEGIN]);
257496 auto partition_end = FlatVector::GetData<const idx_t>(lrstate.bounds.data[PARTITION_END]);
257497 if (grstate.use_framing) {
257498 // With secondary sorts, we restrict to the frame boundaries, but everything else should compute the same.
257499 partition_begin = FlatVector::GetData<const idx_t>(lrstate.bounds.data[FRAME_BEGIN]);
257500 partition_end = FlatVector::GetData<const idx_t>(lrstate.bounds.data[FRAME_END]);
257501 }
257502 auto rdata = FlatVector::GetData<int64_t>(result);
257503 WindowInputExpression ntile_col(eval_chunk, ntile_idx);
257504 for (idx_t i = 0; i < count; ++i, ++row_idx) {
257505 if (ntile_col.CellIsNull(i)) {
257506 FlatVector::SetNull(result, i, true);
257507 } else {
257508 auto n_param = ntile_col.GetCell<int64_t>(i);
257509 if (n_param < 1) {
257510 throw InvalidInputException("Argument for ntile must be greater than zero");
257511 }
257512 // With thanks from SQLite's ntileValueFunc()
257513 auto n_total = NumericCast<int64_t>(partition_end[i] - partition_begin[i]);
257514 if (n_param > n_total) {
257515 // more groups allowed than we have values
257516 // map every entry to a unique group
257517 n_param = n_total;
257518 }
257519 int64_t n_size = (n_total / n_param);
257520 // find the row idx within the group
257521 D_ASSERT(row_idx >= partition_begin[i]);
257522 idx_t partition_idx = 0;
257523 if (grstate.token_tree) {
257524 partition_idx = grstate.token_tree->Rank(partition_begin[i], partition_end[i], row_idx) - 1;
257525 } else {
257526 partition_idx = row_idx - partition_begin[i];
257527 }
257528 auto adjusted_row_idx = NumericCast<int64_t>(partition_idx);
257529
257530 // now compute the ntile
257531 int64_t n_large = n_total - n_param * n_size;
257532 int64_t i_small = n_large * (n_size + 1);
257533 int64_t result_ntile;
257534
257535 D_ASSERT((n_large * (n_size + 1) + (n_param - n_large) * n_size) == n_total);
257536
257537 if (adjusted_row_idx < i_small) {
257538 result_ntile = 1 + adjusted_row_idx / (n_size + 1);
257539 } else {
257540 result_ntile = 1 + n_large + (adjusted_row_idx - i_small) / n_size;
257541 }
257542 // result has to be between [1, NTILE]
257543 D_ASSERT(result_ntile >= 1 && result_ntile <= n_param);
257544 rdata[i] = result_ntile;
257545 }
257546 }
257547}
::int64_t int64_t
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: