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::PhysicalLimit Class Reference

PhyisicalLimit represents the LIMIT operator. More...

Inheritance diagram for duckdb::PhysicalLimit:
Collaboration diagram for duckdb::PhysicalLimit:

Public Member Functions

 PhysicalLimit (PhysicalPlan &physical_plan, vector< LogicalType > types, BoundLimitNode limit_val, BoundLimitNode offset_val, idx_t estimated_cardinality)
bool SinkOrderDependent () const override
unique_ptr< GlobalSourceState > GetGlobalSourceState (ClientContext &context) const override
SourceResultType GetDataInternal (ExecutionContext &context, DataChunk &chunk, OperatorSourceInput &input) const override
bool IsSource () const override
SinkResultType Sink (ExecutionContext &context, DataChunk &chunk, OperatorSinkInput &input) const override
SinkCombineResultType Combine (ExecutionContext &context, OperatorSinkCombineInput &input) const override
unique_ptr< LocalSinkState > GetLocalSinkState (ExecutionContext &context) const override
unique_ptr< GlobalSinkState > GetGlobalSinkState (ClientContext &context) const override
bool IsSink () const override
bool ParallelSink () const override
OperatorPartitionInfo RequiredPartitionInfo () const override
Public Member Functions inherited from duckdb::PhysicalOperator
 PhysicalOperator (PhysicalPlan &physical_plan, PhysicalOperatorType type, vector< LogicalType > types, idx_t estimated_cardinality)
 PhysicalOperator (const PhysicalOperator &other)=delete
 Deleted copy constructors.
PhysicalOperator & operator= (const PhysicalOperator &)=delete
virtual string GetName () const
virtual InsertionOrderPreservingMap< string > ParamsToString () const
virtual string ToString (ExplainFormat format=ExplainFormat::DEFAULT) const
void Print () const
virtual vector< const_reference< PhysicalOperator > > GetChildren () const
const vector< LogicalType > & GetTypes () const
 Return a vector of the types that will be returned by this operator.
virtual bool Equals (const PhysicalOperator &other) const
idx_t EstimatedThreadCount () const
 Functions to help decide how to set up pipeline dependencies.
bool CanSaturateThreads (ClientContext &context) const
virtual void Verify ()
virtual unique_ptr< OperatorState > GetOperatorState (ExecutionContext &context) const
virtual unique_ptr< GlobalOperatorState > GetGlobalOperatorState (ClientContext &context) const
virtual OperatorResultType Execute (ExecutionContext &context, DataChunk &input, DataChunk &chunk, GlobalOperatorState &gstate, OperatorState &state) const
virtual OperatorFinalizeResultType FinalExecute (ExecutionContext &context, DataChunk &chunk, GlobalOperatorState &gstate, OperatorState &state) const
virtual OperatorFinalResultType OperatorFinalize (Pipeline &pipeline, Event &event, ClientContext &context, OperatorFinalizeInput &input) const
virtual bool ParallelOperator () const
virtual bool RequiresFinalExecute () const
virtual bool RequiresOperatorFinalize () const
virtual OrderPreservationType OperatorOrder () const
 The influence the operator has on order (insertion order means no influence).
virtual unique_ptr< LocalSourceState > GetLocalSourceState (ExecutionContext &context, GlobalSourceState &gstate) const
SourceResultType GetData (ExecutionContext &context, DataChunk &chunk, OperatorSourceInput &input) const
virtual OperatorPartitionData GetPartitionData (ExecutionContext &context, DataChunk &chunk, GlobalSourceState &gstate, LocalSourceState &lstate, const OperatorPartitionInfo &partition_info) const
virtual bool ParallelSource () const
virtual bool SupportsPartitioning (const OperatorPartitionInfo &partition_info) const
virtual OrderPreservationType SourceOrder () const
 The type of order emitted by the operator (as a source).
virtual ProgressData GetProgress (ClientContext &context, GlobalSourceState &gstate) const
 Returns the current progress percentage, or a negative value if progress bars are not supported.
virtual ProgressData GetSinkProgress (ClientContext &context, GlobalSinkState &gstate, const ProgressData source_progress) const
 Returns the current progress percentage, or a negative value if progress bars are not supported.
virtual InsertionOrderPreservingMap< string > ExtraSourceParams (GlobalSourceState &gstate, LocalSourceState &lstate) const
virtual void PrepareFinalize (ClientContext &context, GlobalSinkState &sink_state) const
virtual SinkFinalizeType Finalize (Pipeline &pipeline, Event &event, ClientContext &context, OperatorSinkFinalizeInput &input) const
virtual SinkNextBatchType NextBatch (ExecutionContext &context, OperatorSinkNextBatchInput &input) const
virtual vector< const_reference< PhysicalOperator > > GetSources () const
bool AllSourcesSupportBatchIndex () const
virtual void BuildPipelines (Pipeline &current, MetaPipeline &meta_pipeline)
template<class TARGET>
TARGET & Cast ()
template<class TARGET>
const TARGET & Cast () const

Static Public Member Functions

static void SetInitialLimits (const BoundLimitNode &limit_val, const BoundLimitNode &offset_val, optional_idx &limit, optional_idx &offset)
static bool ComputeOffset (ExecutionContext &context, DataChunk &input, optional_idx &limit, optional_idx &offset, idx_t current_offset, idx_t &max_element, const BoundLimitNode &limit_val, const BoundLimitNode &offset_val)
static bool HandleOffset (DataChunk &input, idx_t &current_offset, idx_t offset, idx_t limit)
static Value GetDelimiter (ExecutionContext &context, DataChunk &input, const Expression &expr)
Static Public Member Functions inherited from duckdb::PhysicalOperator
static void SetEstimatedCardinality (InsertionOrderPreservingMap< string > &result, idx_t estimated_cardinality)
static idx_t GetMaxThreadMemory (ClientContext &context)
 The maximum amount of memory the operator should use per thread.
static OperatorCachingMode SelectOperatorCachingMode (ExecutionContext &context)
 Whether operator caching is allowed in the current execution context.

Public Attributes

BoundLimitNode limit_val
BoundLimitNode offset_val
Public Attributes inherited from duckdb::PhysicalOperator
ArenaLinkedList< reference< PhysicalOperator > > children
 The child operators.
PhysicalOperatorType type
 The physical operator type.
vector< LogicalType > types
 The return types.
idx_t estimated_cardinality
 The estimated cardinality.
unique_ptr< GlobalSinkState > sink_state
 The global sink state.
unique_ptr< GlobalOperatorState > op_state
 The global operator state.
mutex lock
 Lock for (re)setting any of the operator states.

Static Public Attributes

static constexpr const PhysicalOperatorType TYPE = PhysicalOperatorType::LIMIT
static constexpr const idx_t MAX_LIMIT_VALUE = 1ULL << 62ULL
Static Public Attributes inherited from duckdb::PhysicalOperator
static constexpr const PhysicalOperatorType TYPE = PhysicalOperatorType::INVALID

Detailed Description

PhyisicalLimit represents the LIMIT operator.

Constructor & Destructor Documentation

◆ PhysicalLimit()

duckdb::PhysicalLimit::PhysicalLimit ( PhysicalPlan & physical_plan,
vector< LogicalType > types,
BoundLimitNode limit_val,
BoundLimitNode offset_val,
idx_t estimated_cardinality )
178311 : PhysicalOperator(physical_plan, PhysicalOperatorType::LIMIT, std::move(types), estimated_cardinality),
178312 limit_val(std::move(limit_val_p)), offset_val(std::move(offset_val_p)) {
178313}
vector< LogicalType > types
The return types.
Definition duckdb.hpp:22152
idx_t estimated_cardinality
The estimated cardinality.
Definition duckdb.hpp:22154

Member Function Documentation

◆ SinkOrderDependent()

bool duckdb::PhysicalLimit::SinkOrderDependent ( ) const
inlineoverridevirtual

Whether or not the sink operator depends on the order of the input chunks If this is set to true, we cannot do things like caching intermediate vectors

Reimplemented from duckdb::PhysicalOperator.

178213 {
178214 return true;
178215 }

◆ GetGlobalSourceState()

unique_ptr< GlobalSourceState > duckdb::PhysicalLimit::GetGlobalSourceState ( ClientContext & context) const
overridevirtual

Reimplemented from duckdb::PhysicalOperator.

178462 {
178463 return make_uniq<LimitSourceState>();
178464}

◆ GetDataInternal()

SourceResultType duckdb::PhysicalLimit::GetDataInternal ( ExecutionContext & context,
DataChunk & chunk,
OperatorSourceInput & input ) const
overridevirtual

Reimplemented from duckdb::PhysicalOperator.

178467 {
178468 auto &gstate = sink_state->Cast<LimitGlobalState>();
178469 auto &state = input.global_state.Cast<LimitSourceState>();
178470 while (state.current_offset < gstate.limit + gstate.offset) {
178471 if (!state.initialized) {
178472 gstate.data.InitializeScan(state.scan_state);
178473 state.initialized = true;
178474 }
178475 gstate.data.Scan(state.scan_state, chunk);
178476 if (chunk.size() == 0) {
178477 return SourceResultType::FINISHED;
178478 }
178479 if (HandleOffset(chunk, state.current_offset, gstate.offset, gstate.limit)) {
178480 break;
178481 }
178482 }
178483
178484 return chunk.size() > 0 ? SourceResultType::HAVE_MORE_OUTPUT : SourceResultType::FINISHED;
178485}
unique_ptr< GlobalSinkState > sink_state
The global sink state.
Definition duckdb.hpp:22157

◆ IsSource()

bool duckdb::PhysicalLimit::IsSource ( ) const
inlineoverridevirtual

Reimplemented from duckdb::PhysicalOperator.

178223 {
178224 return true;
178225 }

◆ Sink()

SinkResultType duckdb::PhysicalLimit::Sink ( ExecutionContext & context,
DataChunk & chunk,
OperatorSinkInput & input ) const
overridevirtual

The sink method is called constantly with new input, as long as new input is available. Note that this method CAN be called in parallel, proper locking is needed when accessing dat a inside the GlobalSinkState.

Reimplemented from duckdb::PhysicalOperator.

178409 {
178410 D_ASSERT(chunk.size() > 0);
178411 auto &state = input.local_state.Cast<LimitLocalState>();
178412 auto &limit = state.limit;
178413 auto &offset = state.offset;
178414
178415 idx_t max_element;
178416 if (!ComputeOffset(context, chunk, limit, offset, state.current_offset, max_element, limit_val, offset_val)) {
178417 return SinkResultType::FINISHED;
178418 }
178419 auto max_cardinality = max_element - state.current_offset;
178420 if (max_cardinality < chunk.size()) {
178421 chunk.SetCardinality(max_cardinality);
178422 }
178423 state.data.Append(chunk, state.partition_info.batch_index.GetIndex());
178424 state.current_offset += chunk.size();
178425 if (state.current_offset == max_element) {
178426 return SinkResultType::FINISHED;
178427 }
178428 return SinkResultType::NEED_MORE_INPUT;
178429}
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237

◆ Combine()

SinkCombineResultType duckdb::PhysicalLimit::Combine ( ExecutionContext & context,
OperatorSinkCombineInput & input ) const
overridevirtual

The combine is called when a single thread has completed execution of its part of the pipeline, it is the final time that a specific LocalSinkState is accessible. This method can be called in parallel while other Sink() or Combine() calls are active on the same GlobalSinkState.

Reimplemented from duckdb::PhysicalOperator.

178431 {
178432 auto &gstate = input.global_state.Cast<LimitGlobalState>();
178433 auto &state = input.local_state.Cast<LimitLocalState>();
178434
178435 lock_guard<mutex> lock(gstate.glock);
178436 if (state.limit.IsValid()) {
178437 gstate.limit = state.limit.GetIndex();
178438 }
178439 if (state.offset.IsValid()) {
178440 gstate.offset = state.offset.GetIndex();
178441 }
178442 gstate.data.Merge(state.data);
178443
178444 return SinkCombineResultType::FINISHED;
178445}
mutex lock
Lock for (re)setting any of the operator states.
Definition duckdb.hpp:22161

◆ GetLocalSinkState()

unique_ptr< LocalSinkState > duckdb::PhysicalLimit::GetLocalSinkState ( ExecutionContext & context) const
overridevirtual

Reimplemented from duckdb::PhysicalOperator.

178349 {
178350 return make_uniq<LimitLocalState>(context.client, *this);
178351}

◆ GetGlobalSinkState()

unique_ptr< GlobalSinkState > duckdb::PhysicalLimit::GetGlobalSinkState ( ClientContext & context) const
overridevirtual

Reimplemented from duckdb::PhysicalOperator.

178345 {
178346 return make_uniq<LimitGlobalState>(context, *this);
178347}

◆ IsSink()

bool duckdb::PhysicalLimit::IsSink ( ) const
inlineoverridevirtual

Reimplemented from duckdb::PhysicalOperator.

178234 {
178235 return true;
178236 }

◆ ParallelSink()

bool duckdb::PhysicalLimit::ParallelSink ( ) const
inlineoverridevirtual

Reimplemented from duckdb::PhysicalOperator.

178238 {
178239 return true;
178240 }

◆ RequiredPartitionInfo()

OperatorPartitionInfo duckdb::PhysicalLimit::RequiredPartitionInfo ( ) const
inlineoverridevirtual

Reimplemented from duckdb::PhysicalOperator.

178242 {
178243 return OperatorPartitionInfo::BatchIndex();
178244 }

◆ SetInitialLimits()

void duckdb::PhysicalLimit::SetInitialLimits ( const BoundLimitNode & limit_val,
const BoundLimitNode & offset_val,
optional_idx & limit,
optional_idx & offset )
static
178354 {
178355 switch (limit_val.Type()) {
178356 case LimitNodeType::CONSTANT_VALUE:
178357 limit = limit_val.GetConstantValue();
178358 break;
178359 case LimitNodeType::UNSET:
178360 limit = MAX_LIMIT_VALUE;
178361 break;
178362 default:
178363 break;
178364 }
178365 switch (offset_val.Type()) {
178366 case LimitNodeType::CONSTANT_VALUE:
178367 offset = offset_val.GetConstantValue();
178368 break;
178369 case LimitNodeType::UNSET:
178370 offset = 0;
178371 break;
178372 default:
178373 break;
178374 }
178375}

◆ ComputeOffset()

bool duckdb::PhysicalLimit::ComputeOffset ( ExecutionContext & context,
DataChunk & input,
optional_idx & limit,
optional_idx & offset,
idx_t current_offset,
idx_t & max_element,
const BoundLimitNode & limit_val,
const BoundLimitNode & offset_val )
static
178379 {
178380 if (!limit.IsValid()) {
178381 Value val = GetDelimiter(context, input, limit_val.GetValueExpression());
178382 if (!val.IsNull()) {
178383 limit = val.GetValue<idx_t>();
178384 } else {
178385 limit = MAX_LIMIT_VALUE;
178386 }
178387 if (limit.GetIndex() > MAX_LIMIT_VALUE) {
178388 throw BinderException("Max value %lld for LIMIT/OFFSET is %lld", limit.GetIndex(), MAX_LIMIT_VALUE);
178389 }
178390 }
178391 if (!offset.IsValid()) {
178392 Value val = GetDelimiter(context, input, offset_val.GetValueExpression());
178393 if (!val.IsNull()) {
178394 offset = val.GetValue<idx_t>();
178395 } else {
178396 offset = 0;
178397 }
178398 if (offset.GetIndex() > MAX_LIMIT_VALUE) {
178399 throw BinderException("Max value %lld for LIMIT/OFFSET is %lld", offset.GetIndex(), MAX_LIMIT_VALUE);
178400 }
178401 }
178402 max_element = limit.GetIndex() + offset.GetIndex();
178403 if (limit == 0 || current_offset >= max_element) {
178404 return false;
178405 }
178406 return true;
178407}

◆ HandleOffset()

bool duckdb::PhysicalLimit::HandleOffset ( DataChunk & input,
idx_t & current_offset,
idx_t offset,
idx_t limit )
static
178487 {
178488 idx_t max_element = limit + offset;
178489 if (limit == DConstants::INVALID_INDEX) {
178490 max_element = DConstants::INVALID_INDEX;
178491 }
178492 idx_t input_size = input.size();
178493 if (current_offset < offset) {
178494 // we are not yet at the offset point
178495 if (current_offset + input.size() > offset) {
178496 // however we will reach it in this chunk
178497 // we have to copy part of the chunk with an offset
178498 idx_t start_position = offset - current_offset;
178499 auto chunk_count = MinValue<idx_t>(limit, input.size() - start_position);
178500 SelectionVector sel(STANDARD_VECTOR_SIZE);
178501 for (idx_t i = 0; i < chunk_count; i++) {
178502 sel.set_index(i, start_position + i);
178503 }
178504 // set up a slice of the input chunks
178505 input.Slice(input, sel, chunk_count);
178506 } else {
178507 current_offset += input_size;
178508 return false;
178509 }
178510 } else {
178511 // have to copy either the entire chunk or part of it
178512 idx_t chunk_count;
178513 if (current_offset + input.size() >= max_element) {
178514 // have to limit the count of the chunk
178515 chunk_count = max_element - current_offset;
178516 } else {
178517 // we copy the entire chunk
178518 chunk_count = input.size();
178519 }
178520 // instead of copying we just change the pointer in the current chunk
178521 input.Reference(input);
178522 input.SetCardinality(chunk_count);
178523 }
178524
178525 current_offset += input_size;
178526 return true;
178527}
DUCKDB_API void Reference(DataChunk &chunk)
Set the DataChunk to reference another data chunk.
Definition duckdb.cpp:116879
static constexpr const idx_t INVALID_INDEX
The value used to signify an invalid index entry.
Definition duckdb.hpp:1117

◆ GetDelimiter()

Value duckdb::PhysicalLimit::GetDelimiter ( ExecutionContext & context,
DataChunk & input,
const Expression & expr )
static
178529 {
178530 DataChunk limit_chunk;
178531 vector<LogicalType> types {expr.return_type};
178532 auto &allocator = Allocator::Get(context.client);
178533 limit_chunk.Initialize(allocator, types);
178534 ExpressionExecutor limit_executor(context.client, &expr);
178535 auto input_size = input.size();
178536 input.SetCardinality(1);
178537 limit_executor.Execute(input, limit_chunk);
178538 input.SetCardinality(input_size);
178539 auto limit_value = limit_chunk.GetValue(0, 0);
178540 return limit_value;
178541}
DUCKDB_API void Initialize(ClientContext &context, const vector< LogicalType > &types, idx_t capacity=STANDARD_VECTOR_SIZE)
Definition duckdb.cpp:116791

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