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

PhyisicalLimitPercent represents the LIMIT PERCENT operator. More...

Inheritance diagram for duckdb::PhysicalLimitPercent:
Collaboration diagram for duckdb::PhysicalLimitPercent:

Public Member Functions

 PhysicalLimitPercent (PhysicalPlan &physical_plan, vector< LogicalType > types, BoundLimitNode limit_val_p, BoundLimitNode offset_val_p, 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
unique_ptr< GlobalSinkState > GetGlobalSinkState (ClientContext &context) const override
SinkResultType Sink (ExecutionContext &context, DataChunk &chunk, OperatorSinkInput &input) const override
bool IsSink () 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 SinkCombineResultType Combine (ExecutionContext &context, OperatorSinkCombineInput &input) 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 unique_ptr< LocalSinkState > GetLocalSinkState (ExecutionContext &context) const
virtual bool ParallelSink () const
virtual OperatorPartitionInfo RequiredPartitionInfo () 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

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_PERCENT
Static Public Attributes inherited from duckdb::PhysicalOperator
static constexpr const PhysicalOperatorType TYPE = PhysicalOperatorType::INVALID

Additional Inherited Members

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.

Detailed Description

PhyisicalLimitPercent represents the LIMIT PERCENT operator.

Constructor & Destructor Documentation

◆ PhysicalLimitPercent()

duckdb::PhysicalLimitPercent::PhysicalLimitPercent ( PhysicalPlan & physical_plan,
vector< LogicalType > types,
BoundLimitNode limit_val_p,
BoundLimitNode offset_val_p,
idx_t estimated_cardinality )
178610 : PhysicalOperator(physical_plan, PhysicalOperatorType::LIMIT_PERCENT, std::move(types), estimated_cardinality),
178611 limit_val(std::move(limit_val_p)), offset_val(std::move(offset_val_p)) {
178612 D_ASSERT(limit_val.Type() == LimitNodeType::CONSTANT_PERCENTAGE ||
178613 limit_val.Type() == LimitNodeType::EXPRESSION_PERCENTAGE);
178614}
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::PhysicalLimitPercent::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.

178573 {
178574 return true;
178575 }

◆ GetGlobalSourceState()

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

Reimplemented from duckdb::PhysicalOperator.

178714 {
178715 return make_uniq<LimitPercentOperatorState>(*this);
178716}

◆ GetDataInternal()

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

Reimplemented from duckdb::PhysicalOperator.

178719 {
178720 auto &gstate = sink_state->Cast<LimitPercentGlobalState>();
178721 auto &state = input.global_state.Cast<LimitPercentOperatorState>();
178722 auto &percent_limit = gstate.limit_percent;
178723 auto &offset = gstate.offset;
178724 auto &limit = state.limit;
178725 auto &current_offset = state.current_offset;
178726
178727 if (!limit.IsValid()) {
178728 if (!gstate.is_limit_set) {
178729 // no limit value and we have not set limit_percent
178730 // we are running LIMIT % with a subquery over an empty table
178731 D_ASSERT(gstate.data.Count() == 0);
178732 return SourceResultType::FINISHED;
178733 }
178734 idx_t count = gstate.data.Count();
178735 if (count > 0) {
178736 count += offset.GetIndex();
178737 }
178738 if (Value::IsNan(percent_limit) || percent_limit < 0 || percent_limit > 100) {
178739 throw OutOfRangeException("Limit percent out of range, should be between 0% and 100%");
178740 }
178741 auto limit_percentage = idx_t(percent_limit / 100.0 * double(count));
178742 if (limit_percentage > count) {
178743 limit = count;
178744 } else {
178745 limit = idx_t(limit_percentage);
178746 }
178747 if (limit == 0) {
178748 return SourceResultType::FINISHED;
178749 }
178750 }
178751
178752 if (current_offset >= limit.GetIndex()) {
178753 return SourceResultType::FINISHED;
178754 }
178755 if (!gstate.data.Scan(state.scan_state, chunk)) {
178756 return SourceResultType::FINISHED;
178757 }
178758
178759 PhysicalLimit::HandleOffset(chunk, current_offset, 0, limit.GetIndex());
178760
178761 return SourceResultType::HAVE_MORE_OUTPUT;
178762}
unique_ptr< GlobalSinkState > sink_state
The global sink state.
Definition duckdb.hpp:22157
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237

◆ IsSource()

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

Reimplemented from duckdb::PhysicalOperator.

178583 {
178584 return true;
178585 }

◆ GetGlobalSinkState()

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

Reimplemented from duckdb::PhysicalOperator.

178655 {
178656 return make_uniq<LimitPercentGlobalState>(context, *this);
178657}

◆ Sink()

SinkResultType duckdb::PhysicalLimitPercent::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.

178659 {
178660 D_ASSERT(chunk.size() > 0);
178661 auto &state = input.global_state.Cast<LimitPercentGlobalState>();
178662 auto &limit_percent = state.limit_percent;
178663 auto &offset = state.offset;
178664
178665 // get the next chunk from the child
178666 if (!state.is_limit_set) {
178667 Value val = PhysicalLimit::GetDelimiter(context, chunk, limit_val.GetPercentageExpression());
178668 if (!val.IsNull()) {
178669 limit_percent = val.GetValue<double>();
178670 } else {
178671 limit_percent = 100.0;
178672 }
178673 if (limit_percent < 0.0) {
178674 throw BinderException("Percentage value(%f) can't be negative", limit_percent);
178675 }
178676 state.is_limit_set = true;
178677 }
178678 if (!state.offset.IsValid()) {
178679 Value val = PhysicalLimit::GetDelimiter(context, chunk, offset_val.GetValueExpression());
178680 if (!val.IsNull()) {
178681 offset = val.GetValue<idx_t>();
178682 } else {
178683 offset = 0;
178684 }
178685 if (offset.GetIndex() > 1ULL << 62ULL) {
178686 throw BinderException("Max value %lld for LIMIT/OFFSET is %lld", offset.GetIndex(), 1ULL << 62ULL);
178687 }
178688 }
178689
178690 if (!PhysicalLimit::HandleOffset(chunk, state.current_offset, offset.GetIndex(), NumericLimits<idx_t>::Maximum())) {
178691 return SinkResultType::NEED_MORE_INPUT;
178692 }
178693
178694 state.data.Append(chunk);
178695 return SinkResultType::NEED_MORE_INPUT;
178696}

◆ IsSink()

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

Reimplemented from duckdb::PhysicalOperator.

178592 {
178593 return true;
178594 }

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