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

Represents a scan of a base table. More...

Inheritance diagram for duckdb::PhysicalTableScan:
Collaboration diagram for duckdb::PhysicalTableScan:

Public Member Functions

 PhysicalTableScan (PhysicalPlan &physical_plan, vector< LogicalType > types, TableFunction function, unique_ptr< FunctionData > bind_data, vector< LogicalType > returned_types, vector< ColumnIndex > column_ids, vector< idx_t > projection_ids, vector< string > names, unique_ptr< TableFilterSet > table_filters, idx_t estimated_cardinality, ExtraOperatorInfo extra_info, vector< Value > parameters, virtual_column_map_t virtual_columns)
 Table scan that immediately projects out filter columns that are unused in the remainder of the query plan.
string GetName () const override
InsertionOrderPreservingMap< string > ParamsToString () const override
bool Equals (const PhysicalOperator &other) const override
OrderPreservationType SourceOrder () const override
 The type of order emitted by the operator (as a source).
unique_ptr< LocalSourceState > GetLocalSourceState (ExecutionContext &context, GlobalSourceState &gstate) const override
unique_ptr< GlobalSourceState > GetGlobalSourceState (ClientContext &context) const override
SourceResultType GetDataInternal (ExecutionContext &context, DataChunk &chunk, OperatorSourceInput &input) const override
OperatorPartitionData GetPartitionData (ExecutionContext &context, DataChunk &chunk, GlobalSourceState &gstate, LocalSourceState &lstate, const OperatorPartitionInfo &partition_info) const override
bool IsSource () const override
bool ParallelSource () const override
bool SupportsPartitioning (const OperatorPartitionInfo &partition_info) const override
ProgressData GetProgress (ClientContext &context, GlobalSourceState &gstate) const override
 Returns the current progress percentage, or a negative value if progress bars are not supported.
InsertionOrderPreservingMap< string > ExtraSourceParams (GlobalSourceState &gstate, LocalSourceState &lstate) const override
optional_idx GetRowsScanned (GlobalSourceState &gstate_p, LocalSourceState &lstate) const
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 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.
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).
SourceResultType GetData (ExecutionContext &context, DataChunk &chunk, OperatorSourceInput &input) const
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 SinkResultType Sink (ExecutionContext &context, DataChunk &chunk, OperatorSinkInput &input) 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 unique_ptr< GlobalSinkState > GetGlobalSinkState (ClientContext &context) const
virtual bool IsSink () const
virtual bool ParallelSink () 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

TableFunction function
 The table function.
unique_ptr< FunctionData > bind_data
 Bind data of the function.
vector< LogicalType > returned_types
 The types of ALL columns that can be returned by the table function.
vector< ColumnIndex > column_ids
 The column ids used within the table function.
vector< idx_t > projection_ids
 The projected-out column ids.
vector< string > names
 The names of the columns.
unique_ptr< TableFilterSet > table_filters
 The table filters.
ExtraOperatorInfo extra_info
vector< Value > parameters
 Parameters.
shared_ptr< DynamicTableFilterSet > dynamic_filters
 Contains a reference to dynamically generated table filters (through e.g. a join up in the tree).
virtual_column_map_t virtual_columns
 Virtual columns.
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::TABLE_SCAN
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

Represents a scan of a base table.

Constructor & Destructor Documentation

◆ PhysicalTableScan()

duckdb::PhysicalTableScan::PhysicalTableScan ( PhysicalPlan & physical_plan,
vector< LogicalType > types,
TableFunction function,
unique_ptr< FunctionData > bind_data,
vector< LogicalType > returned_types,
vector< ColumnIndex > column_ids,
vector< idx_t > projection_ids,
vector< string > names,
unique_ptr< TableFilterSet > table_filters,
idx_t estimated_cardinality,
ExtraOperatorInfo extra_info,
vector< Value > parameters,
virtual_column_map_t virtual_columns )

Table scan that immediately projects out filter columns that are unused in the remainder of the query plan.

198806 : PhysicalOperator(physical_plan, PhysicalOperatorType::TABLE_SCAN, std::move(types), estimated_cardinality),
198807
198808 function(std::move(function_p)), bind_data(std::move(bind_data_p)), returned_types(std::move(returned_types_p)),
198809 column_ids(std::move(column_ids_p)), projection_ids(std::move(projection_ids_p)), names(std::move(names_p)),
198810 table_filters(std::move(table_filters_p)), extra_info(std::move(extra_info)), parameters(std::move(parameters_p)),
198811 virtual_columns(std::move(virtual_columns_p)) {
198812}
vector< LogicalType > types
The return types.
Definition duckdb.hpp:22152
idx_t estimated_cardinality
The estimated cardinality.
Definition duckdb.hpp:22154
TableFunction function
The table function.
Definition duckdb.cpp:198727
unique_ptr< TableFilterSet > table_filters
The table filters.
Definition duckdb.cpp:198739
vector< idx_t > projection_ids
The projected-out column ids.
Definition duckdb.cpp:198735
vector< string > names
The names of the columns.
Definition duckdb.cpp:198737
virtual_column_map_t virtual_columns
Virtual columns.
Definition duckdb.cpp:198748
unique_ptr< FunctionData > bind_data
Bind data of the function.
Definition duckdb.cpp:198729
vector< Value > parameters
Parameters.
Definition duckdb.cpp:198744
ExtraOperatorInfo extra_info
Definition duckdb.cpp:198742
vector< ColumnIndex > column_ids
The column ids used within the table function.
Definition duckdb.cpp:198733
vector< LogicalType > returned_types
The types of ALL columns that can be returned by the table function.
Definition duckdb.cpp:198731

Member Function Documentation

◆ GetName()

string duckdb::PhysicalTableScan::GetName ( ) const
overridevirtual

Reimplemented from duckdb::PhysicalOperator.

199058 {
199059 return StringUtil::Upper(function.name + (function.extra_info.empty() ? "" : " " + function.extra_info));
199060}
static DUCKDB_API string Upper(const string &str)
Convert a string to UPPERCASE.
Definition duckdb.cpp:109624

◆ ParamsToString()

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

Reimplemented from duckdb::PhysicalOperator.

199121 {
199122 InsertionOrderPreservingMap<string> result;
199123 if (function.to_string) {
199124 TableFunctionToStringInput input(function, bind_data.get());
199125 auto to_string_result = function.to_string(input);
199126 for (const auto &it : to_string_result) {
199127 result[it.first] = it.second;
199128 }
199129 } else {
199130 result["Function"] = StringUtil::Upper(function.name);
199131 }
199132 if (function.projection_pushdown) {
199133 string projections;
199134 idx_t projected_column_count = function.filter_prune ? projection_ids.size() : column_ids.size();
199135 for (idx_t i = 0; i < projected_column_count; i++) {
199136 auto base_index = function.filter_prune ? projection_ids[i] : i;
199137 auto &column_index = column_ids[base_index];
199138 auto column_id = column_index.GetPrimaryIndex();
199139 if (column_id >= names.size()) {
199140 continue;
199141 }
199142 AddProjectionNames(column_index, names[column_id], returned_types[column_id], projections);
199143 }
199144 result["Projections"] = projections;
199145 }
199146 if (function.filter_pushdown && table_filters) {
199147 result["Filters"] = GetFilterInfo(this, table_filters);
199148 }
199149
199150 if (function.filter_pushdown && dynamic_filters && dynamic_filters->HasFilters()) {
199151 result["Dynamic Filters"] = GetFilterInfo(this, dynamic_filters->GetFinalTableFilters(*this, nullptr));
199152 }
199153
199154 if (extra_info.sample_options) {
199155 result["Sample Method"] = "System: " + extra_info.sample_options->sample_size.ToString() + "%";
199156 }
199157 if (!extra_info.file_filters.empty()) {
199158 result["File Filters"] = extra_info.file_filters;
199159 if (extra_info.filtered_files.IsValid() && extra_info.total_files.IsValid()) {
199160 result["Scanning Files"] = StringUtil::Format("%llu/%llu", extra_info.filtered_files.GetIndex(),
199161 extra_info.total_files.GetIndex());
199162 }
199163 }
199164
199165 SetEstimatedCardinality(result, estimated_cardinality);
199166 return result;
199167}
shared_ptr< DynamicTableFilterSet > dynamic_filters
Contains a reference to dynamically generated table filters (through e.g. a join up in the tree).
Definition duckdb.cpp:198746
static string Format(const string fmt_str, ARGS... params)
Format a string using printf semantics.
Definition duckdb.hpp:4002
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237

◆ Equals()

bool duckdb::PhysicalTableScan::Equals ( const PhysicalOperator & other) const
overridevirtual

Reimplemented from duckdb::PhysicalOperator.

199169 {
199170 if (type != other_p.type) {
199171 return false;
199172 }
199173 auto &other = other_p.Cast<PhysicalTableScan>();
199174 if (function != other.function) {
199175 return false;
199176 }
199177 if (column_ids != other.column_ids) {
199178 return false;
199179 }
199180 if (!FunctionData::Equals(bind_data.get(), other.bind_data.get())) {
199181 return false;
199182 }
199183 return true;
199184}
PhysicalOperatorType type
The physical operator type.
Definition duckdb.hpp:22150
PhysicalTableScan(PhysicalPlan &physical_plan, vector< LogicalType > types, TableFunction function, unique_ptr< FunctionData > bind_data, vector< LogicalType > returned_types, vector< ColumnIndex > column_ids, vector< idx_t > projection_ids, vector< string > names, unique_ptr< TableFilterSet > table_filters, idx_t estimated_cardinality, ExtraOperatorInfo extra_info, vector< Value > parameters, virtual_column_map_t virtual_columns)
Table scan that immediately projects out filter columns that are unused in the remainder of the query...
Definition duckdb.cpp:198800

◆ SourceOrder()

OrderPreservationType duckdb::PhysicalTableScan::SourceOrder ( ) const
inlineoverridevirtual

The type of order emitted by the operator (as a source).

Reimplemented from duckdb::PhysicalOperator.

198756 {
198757 return function.order_preservation_type;
198758 }

◆ GetLocalSourceState()

unique_ptr< LocalSourceState > duckdb::PhysicalTableScan::GetLocalSourceState ( ExecutionContext & context,
GlobalSourceState & gstate ) const
overridevirtual

Reimplemented from duckdb::PhysicalOperator.

198880 {
198881 return make_uniq<TableScanLocalSourceState>(context, gstate.Cast<TableScanGlobalSourceState>(), *this);
198882}

◆ GetGlobalSourceState()

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

Reimplemented from duckdb::PhysicalOperator.

198884 {
198885 return make_uniq<TableScanGlobalSourceState>(context, *this);
198886}

◆ GetDataInternal()

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

Reimplemented from duckdb::PhysicalOperator.

198944 {
198945 D_ASSERT(!column_ids.empty());
198946 auto &g_state = input.global_state.Cast<TableScanGlobalSourceState>();
198947 auto &l_state = input.local_state.Cast<TableScanLocalSourceState>();
198948
198949 TableFunctionInput data(bind_data.get(), l_state.local_state.get(), g_state.global_state.get());
198950
198951 if (function.function) {
198952 data.async_result = AsyncResultType::IMPLICIT;
198953
198954 const auto initial_async_result = data.async_result.GetResultType();
198955 const auto execution_strategy = g_state.physical_table_scan_execution_strategy;
198956 const auto input_execution_mode = AsyncResult::ConvertToAsyncResultExecutionMode(execution_strategy);
198957 data.results_execution_mode = input_execution_mode;
198958
198959 // Actually call the function
198960 function.function(context.client, data, chunk);
198961
198962 const auto output_async_result = data.async_result.GetResultType();
198963
198964 // Compare and check whether state before and after function.function call is compatible, will throw in case of
198965 // inconsistencies
198966 ValidateAsyncStrategyResult(execution_strategy, input_execution_mode, data.results_execution_mode,
198967 initial_async_result, output_async_result, chunk.size());
198968
198969 // Handle results
198970 switch (output_async_result) {
198971 case AsyncResultType::BLOCKED: {
198972 D_ASSERT(data.async_result.HasTasks());
198973 auto guard = g_state.Lock();
198974 if (g_state.CanBlock(guard)) {
198975 data.async_result.ScheduleTasks(input.interrupt_state, context.pipeline->executor);
198976 return SourceResultType::BLOCKED;
198977 }
198978 return SourceResultType::FINISHED;
198979 }
198980 case AsyncResultType::IMPLICIT:
198981 if (chunk.size() > 0) {
198982 return SourceResultType::HAVE_MORE_OUTPUT;
198983 }
198984 return SourceResultType::FINISHED;
198985 case AsyncResultType::FINISHED:
198986 return SourceResultType::FINISHED;
198987 case AsyncResultType::HAVE_MORE_OUTPUT:
198988 return SourceResultType::HAVE_MORE_OUTPUT;
198989 default:
198990 throw InternalException(
198991 "PhysicalTableScan::GetData call of function.function returned unexpected return '%'",
198992 EnumUtil::ToChars(data.async_result.GetResultType()));
198993 }
198994 throw InternalException("PhysicalTableScan::GetData hasn't handled a function.function return");
198995 }
198996
198997 if (g_state.in_out_final) {
198998 function.in_out_function_final(context, data, chunk);
198999 }
199000 switch (function.in_out_function(context, data, g_state.input_chunk, chunk)) {
199001 case OperatorResultType::BLOCKED: {
199002 auto guard = g_state.Lock();
199003 return g_state.BlockSource(guard, input.interrupt_state);
199004 }
199005 default:
199006 // FIXME: Handling for other cases (such as NEED_MORE_INPUT) breaks current functionality and extensions that
199007 // might be relying on current behaviour. Needs a rework that is not in scope
199008 break;
199009 }
199010
199011 if (chunk.size() == 0 && function.in_out_function_final) {
199012 function.in_out_function_final(context, data, chunk);
199013 g_state.in_out_final = true;
199014 }
199015 return chunk.size() == 0 ? SourceResultType::FINISHED : SourceResultType::HAVE_MORE_OUTPUT;
199016}

◆ GetPartitionData()

OperatorPartitionData duckdb::PhysicalTableScan::GetPartitionData ( ExecutionContext & context,
DataChunk & chunk,
GlobalSourceState & gstate,
LocalSourceState & lstate,
const OperatorPartitionInfo & partition_info ) const
overridevirtual

Reimplemented from duckdb::PhysicalOperator.

199048 {
199049 D_ASSERT(SupportsPartitioning(partition_info));
199050 D_ASSERT(function.get_partition_data);
199051 auto &gstate = gstate_p.Cast<TableScanGlobalSourceState>();
199052 auto &state = lstate.Cast<TableScanLocalSourceState>();
199053 TableFunctionGetPartitionInput input(bind_data.get(), state.local_state.get(), gstate.global_state.get(),
199054 partition_info);
199055 return function.get_partition_data(context.client, input);
199056}

◆ IsSource()

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

Reimplemented from duckdb::PhysicalOperator.

198770 {
198771 return true;
198772 }

◆ ParallelSource()

bool duckdb::PhysicalTableScan::ParallelSource ( ) const
overridevirtual

Reimplemented from duckdb::PhysicalOperator.

199186 {
199187 if (!function.function) {
199188 // table in-out functions cannot be executed in parallel as part of a PhysicalTableScan
199189 // since they have only a single input row
199190 return false;
199191 }
199192 return true;
199193}

◆ SupportsPartitioning()

bool duckdb::PhysicalTableScan::SupportsPartitioning ( const OperatorPartitionInfo & partition_info) const
overridevirtual

Reimplemented from duckdb::PhysicalOperator.

199038 {
199039 if (!function.get_partition_data) {
199040 return false;
199041 }
199042 // FIXME: actually check if partition info is supported
199043 return true;
199044}

◆ GetProgress()

ProgressData duckdb::PhysicalTableScan::GetProgress ( ClientContext & context,
GlobalSourceState & gstate ) const
overridevirtual

Returns the current progress percentage, or a negative value if progress bars are not supported.

Reimplemented from duckdb::PhysicalOperator.

199018 {
199019 auto &gstate = gstate_p.Cast<TableScanGlobalSourceState>();
199020 ProgressData res;
199021 if (function.table_scan_progress) {
199022 double table_progress = function.table_scan_progress(context, bind_data.get(), gstate.global_state.get());
199023 if (table_progress < 0.0) {
199024 res.SetInvalid();
199025 } else {
199026 res.done = table_progress;
199027 res.total = 100.0;
199028 // Assume cardinality is always 1e3
199029 res.Normalize(1e3);
199030 }
199031 } else {
199032 // if table_scan_progress is not implemented we don't support this function yet in the progress bar
199033 res.SetInvalid();
199034 }
199035 return res;
199036}

◆ ExtraSourceParams()

InsertionOrderPreservingMap< string > duckdb::PhysicalTableScan::ExtraSourceParams ( GlobalSourceState & gstate,
LocalSourceState & lstate ) const
overridevirtual

Reimplemented from duckdb::PhysicalOperator.

199196 {
199197 if (!function.dynamic_to_string) {
199198 return InsertionOrderPreservingMap<string>();
199199 }
199200 auto &gstate = gstate_p.Cast<TableScanGlobalSourceState>();
199201 auto &state = lstate.Cast<TableScanLocalSourceState>();
199202 TableFunctionDynamicToStringInput input(function, bind_data.get(), state.local_state.get(),
199203 gstate.global_state.get());
199204 return function.dynamic_to_string(input);
199205}

◆ GetRowsScanned()

optional_idx duckdb::PhysicalTableScan::GetRowsScanned ( GlobalSourceState & gstate_p,
LocalSourceState & lstate ) const
199207 {
199208 if (function.rows_scanned) {
199209 auto &gstate = gstate_p.Cast<TableScanGlobalSourceState>();
199210 auto &state = lstate.Cast<TableScanLocalSourceState>();
199211 return function.rows_scanned(*gstate.global_state, *state.local_state);
199212 }
199213 return optional_idx();
199214}

Member Data Documentation

◆ extra_info

ExtraOperatorInfo duckdb::PhysicalTableScan::extra_info

Currently stores info related to filters pushed down into MultiFileLists and sample rate pushed down into the table scan


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