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

Public Member Functions

 PhysicalReservoirSample (PhysicalPlan &physical_plan, vector< LogicalType > types, unique_ptr< SampleOptions > options, idx_t estimated_cardinality)
SourceResultType GetDataInternal (ExecutionContext &context, DataChunk &chunk, OperatorSourceInput &input) const override
bool IsSource () const override
SinkResultType Sink (ExecutionContext &context, DataChunk &chunk, OperatorSinkInput &input) const override
unique_ptr< GlobalSinkState > GetGlobalSinkState (ClientContext &context) const override
SinkCombineResultType Combine (ExecutionContext &context, OperatorSinkCombineInput &input) const override
SinkFinalizeType Finalize (Pipeline &pipeline, Event &event, ClientContext &context, OperatorSinkFinalizeInput &input) const override
bool ParallelSink () const override
bool IsSink () const override
InsertionOrderPreservingMap< string > ParamsToString () 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 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
virtual unique_ptr< GlobalSourceState > GetGlobalSourceState (ClientContext &context) 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 SinkNextBatchType NextBatch (ExecutionContext &context, OperatorSinkNextBatchInput &input) const
virtual unique_ptr< LocalSinkState > GetLocalSinkState (ExecutionContext &context) const
virtual OperatorPartitionInfo RequiredPartitionInfo () const
virtual bool SinkOrderDependent () 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

unique_ptr< SampleOptions > options
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.

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

Detailed Description

PhysicalReservoirSample represents a sample taken using reservoir sampling, which is a blocking sampling method

Constructor & Destructor Documentation

◆ PhysicalReservoirSample()

duckdb::PhysicalReservoirSample::PhysicalReservoirSample ( PhysicalPlan & physical_plan,
vector< LogicalType > types,
unique_ptr< SampleOptions > options,
idx_t estimated_cardinality )
inline
179135 : PhysicalOperator(physical_plan, PhysicalOperatorType::RESERVOIR_SAMPLE, std::move(types),
179137 options(std::move(options)) {
179138 }
vector< LogicalType > types
The return types.
Definition duckdb.hpp:22152
idx_t estimated_cardinality
The estimated cardinality.
Definition duckdb.hpp:22154

Member Function Documentation

◆ GetDataInternal()

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

Reimplemented from duckdb::PhysicalOperator.

179251 {
179252 auto &sink = this->sink_state->Cast<SampleGlobalSinkState>();
179253 lock_guard<mutex> glock(sink.lock);
179254 if (!sink.sample) {
179255 return SourceResultType::FINISHED;
179256 }
179257 auto sample_chunk = sink.sample->GetChunk();
179258
179259 if (!sample_chunk) {
179260 return SourceResultType::FINISHED;
179261 }
179262 chunk.Move(*sample_chunk);
179263
179264 return SourceResultType::HAVE_MORE_OUTPUT;
179265}
DUCKDB_API void Move(DataChunk &chunk)
Set the DataChunk to own the data of data chunk, destroying the other chunk in the process.
Definition duckdb.cpp:116888
unique_ptr< GlobalSinkState > sink_state
The global sink state.
Definition duckdb.hpp:22157

◆ IsSource()

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

Reimplemented from duckdb::PhysicalOperator.

179147 {
179148 return true;
179149 }

◆ Sink()

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

179210 {
179211 auto &global_state = input.global_state.Cast<SampleGlobalSinkState>();
179212 // Percentage only has a global sample.
179213 lock_guard<mutex> glock(global_state.lock);
179214 if (!global_state.sample) {
179215 // always gather full thread percentage
179216 auto &allocator = Allocator::Get(context.client);
179217 if (options->is_percentage) {
179218 double percentage = options->sample_size.GetValue<double>();
179219 if (percentage == 0) {
179220 return SinkResultType::FINISHED;
179221 }
179222 global_state.sample = make_uniq<ReservoirSamplePercentage>(allocator, percentage,
179223 static_cast<int64_t>(options->seed.GetIndex()));
179224 } else {
179225 idx_t num_samples = options->sample_size.GetValue<idx_t>();
179226 if (num_samples == 0) {
179227 return SinkResultType::FINISHED;
179228 }
179229 global_state.sample =
179230 make_uniq<ReservoirSample>(allocator, num_samples, static_cast<int64_t>(options->seed.GetIndex()));
179231 }
179232 }
179233 global_state.sample->AddToReservoir(chunk);
179234 return SinkResultType::NEED_MORE_INPUT;
179235}
::int64_t int64_t
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237

◆ GetGlobalSinkState()

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

Reimplemented from duckdb::PhysicalOperator.

179205 {
179206 return make_uniq<SampleGlobalSinkState>(Allocator::Get(context), *options);
179207}

◆ Combine()

SinkCombineResultType duckdb::PhysicalReservoirSample::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.

179238 {
179239 return SinkCombineResultType::FINISHED;
179240}

◆ Finalize()

SinkFinalizeType duckdb::PhysicalReservoirSample::Finalize ( Pipeline & pipeline,
Event & event,
ClientContext & context,
OperatorSinkFinalizeInput & input ) const
overridevirtual

The finalize is called when ALL threads are finished execution. It is called only once per pipeline, and is entirely single threaded. If Finalize returns SinkResultType::Finished, the sink is marked as finished

Reimplemented from duckdb::PhysicalOperator.

179243 {
179244 return SinkFinalizeType::READY;
179245}

◆ ParallelSink()

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

Reimplemented from duckdb::PhysicalOperator.

179158 {
179159 return !options->repeatable;
179160 }

◆ IsSink()

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

Reimplemented from duckdb::PhysicalOperator.

179162 {
179163 return true;
179164 }

◆ ParamsToString()

InsertionOrderPreservingMap< string > duckdb::PhysicalReservoirSample::ParamsToString ( ) const
overridevirtual

Reimplemented from duckdb::PhysicalOperator.

179267 {
179268 InsertionOrderPreservingMap<string> result;
179269 result["Sample Size"] = options->sample_size.ToString() + (options->is_percentage ? "%" : " rows");
179270 return result;
179271}

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