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

A view catalog entry. More...

Inheritance diagram for duckdb::ViewCatalogEntry:
Collaboration diagram for duckdb::ViewCatalogEntry:

Public Member Functions

 ViewCatalogEntry (Catalog &catalog, SchemaCatalogEntry &schema, CreateViewInfo &info)
 Create a real TableCatalogEntry and initialize storage for it.
 
virtual shared_ptr< ViewColumnInfoGetColumnInfo () const
 Returns the view column info, if the view is bound. Otherwise returns nullptr
 
virtual void BindView (ClientContext &context, BindViewAction action=BindViewAction::BIND_IF_UNBOUND)
 Bind a view so we know the types / names returned by it.
 
virtual void UpdateBinding (const vector< LogicalType > &types, const vector< string > &names)
 Update the view with a new set of types / names.
 
Value GetColumnComment (idx_t column_index)
 
unique_ptr< CreateInfoGetInfo () const override
 
unique_ptr< CatalogEntryAlterEntry (ClientContext &context, AlterInfo &info) override
 
unique_ptr< CatalogEntryCopy (ClientContext &context) const override
 
virtual const SelectStatementGetQuery ()
 
string ToSQL () const override
 Convert the catalog entry to a SQL string that can be used to re-construct the catalog entry.
 
- Public Member Functions inherited from duckdb::StandardEntry
 StandardEntry (CatalogType type, SchemaCatalogEntry &schema, Catalog &catalog, string name)
 
SchemaCatalogEntryParentSchema () override
 
const SchemaCatalogEntryParentSchema () const override
 
- Public Member Functions inherited from duckdb::InCatalogEntry
 InCatalogEntry (CatalogType type, Catalog &catalog, string name)
 
CatalogParentCatalog () override
 
const CatalogParentCatalog () const override
 
void Verify (Catalog &catalog) override
 
- Public Member Functions inherited from duckdb::CatalogEntry
 CatalogEntry (CatalogType type, Catalog &catalog, string name)
 
 CatalogEntry (CatalogType type, string name, idx_t oid)
 
virtual unique_ptr< CatalogEntryAlterEntry (CatalogTransaction transaction, AlterInfo &info)
 
virtual void UndoAlter (ClientContext &context, AlterInfo &info)
 
virtual void Rollback (CatalogEntry &prev_entry)
 
virtual void OnDrop ()
 
virtual void SetAsRoot ()
 Sets the CatalogEntry as the new root entry (i.e. the newest entry)
 
void Serialize (Serializer &serializer) const
 
void SetChild (unique_ptr< CatalogEntry > child)
 
unique_ptr< CatalogEntryTakeChild ()
 
bool HasChild () const
 
bool HasParent () const
 
CatalogEntryChild ()
 
CatalogEntryParent ()
 
const CatalogEntryParent () const
 
template<class TARGET >
TARGETCast ()
 
template<class TARGET >
const TARGETCast () const
 

Public Attributes

unique_ptr< SelectStatementquery
 The query of the view.
 
string sql
 The SQL query (if any)
 
vector< string > aliases
 The set of aliases associated with the view.
 
- Public Attributes inherited from duckdb::StandardEntry
SchemaCatalogEntryschema
 The schema the entry belongs to.
 
LogicalDependencyList dependencies
 The dependencies of the entry, can be empty.
 
- Public Attributes inherited from duckdb::InCatalogEntry
Catalogcatalog
 The catalog the entry belongs to.
 
- Public Attributes inherited from duckdb::CatalogEntry
idx_t oid
 The oid of the entry.
 
CatalogType type
 The type of this catalog entry.
 
optional_ptr< CatalogSetset
 Reference to the catalog set this entry is stored in.
 
string name
 The name of the entry.
 
bool deleted
 Whether or not the object is deleted.
 
bool temporary
 Whether or not the object is temporary and should not be added to the WAL.
 
bool internal
 Whether or not the entry is an internal entry (cannot be deleted, not dumped, etc)
 
atomic< transaction_ttimestamp
 Timestamp at which the catalog entry was created.
 
Value comment
 (optional) comment on this entry
 
InsertionOrderPreservingMap< string > tags
 (optional) extra data associated with this entry
 

Static Public Attributes

static constexpr const CatalogType Type = CatalogType::VIEW_ENTRY
 
static constexpr const charName = "view"
 

Private Member Functions

void Initialize (CreateViewInfo &info)
 

Private Attributes

mutex bind_lock
 
shared_ptr< ViewColumnInfoview_columns
 Columns returned by the view, if bound.
 
atomic< ViewBindState > bind_state
 The current bind state of the view.
 
atomic< thread_id > bind_thread
 Current binding thread.
 
unordered_map< string, Valuecolumn_comments
 The comments on the columns of the view: can be empty if there are no comments.
 

Additional Inherited Members

- Static Public Member Functions inherited from duckdb::CatalogEntry
static unique_ptr< CreateInfoDeserialize (Deserializer &deserializer)
 

Detailed Description

A view catalog entry.

Constructor & Destructor Documentation

◆ ViewCatalogEntry()

duckdb::ViewCatalogEntry::ViewCatalogEntry ( Catalog catalog,
SchemaCatalogEntry schema,
CreateViewInfo info 
)

Create a real TableCatalogEntry and initialize storage for it.

21453 : StandardEntry(CatalogType::VIEW_ENTRY, schema, catalog, info.view_name), bind_state(ViewBindState::UNBOUND) {
21454 Initialize(info);
21455}
Catalog & catalog
The catalog the entry belongs to.
Definition duckdb.hpp:6387
SchemaCatalogEntry & schema
The schema the entry belongs to.
Definition duckdb.hpp:28008
atomic< ViewBindState > bind_state
The current bind state of the view.
Definition duckdb.cpp:2998

Member Function Documentation

◆ GetColumnInfo()

shared_ptr< ViewColumnInfo > duckdb::ViewCatalogEntry::GetColumnInfo ( ) const
virtual

Returns the view column info, if the view is bound. Otherwise returns nullptr

21517 {
21518 return view_columns.atomic_load();
21519}
shared_ptr< ViewColumnInfo > view_columns
Columns returned by the view, if bound.
Definition duckdb.cpp:2996

◆ BindView()

void duckdb::ViewCatalogEntry::BindView ( ClientContext context,
BindViewAction  action = BindViewAction::BIND_IF_UNBOUND 
)
virtual

Bind a view so we know the types / names returned by it.

21538 {
21539 if (bind_state == ViewBindState::BINDING && bind_thread == ThreadUtil::GetThreadId()) {
21540 throw InvalidInputException("View \"%s\" was requested to be bound but this thread is already binding that "
21541 "view - this likely means the view was attempted to be bound recursively",
21542 name);
21543 }
21544 lock_guard<mutex> guard(bind_lock);
21545 if (action == BindViewAction::BIND_IF_UNBOUND && view_columns) {
21546 // already bound
21547 return;
21548 }
21549 auto prev_bind_state = bind_state.load();
21550 bind_state = ViewBindState::BINDING;
21551 bind_thread = ThreadUtil::GetThreadId();
21552 try {
21553 auto columns = make_shared_ptr<ViewColumnInfo>();
21554 Binder::BindView(context, GetQuery(), ParentCatalog().GetName(), ParentSchema().name, nullptr, aliases,
21555 columns->types, columns->names);
21556 view_columns.atomic_store(columns);
21557 } catch (...) {
21558 bind_state = prev_bind_state;
21559 bind_thread = thread_id {};
21560 throw;
21561 }
21562 bind_state = ViewBindState::BOUND;
21563 bind_thread = thread_id {};
21564}
string name
The name of the entry.
Definition duckdb.hpp:6311
vector< string > aliases
The set of aliases associated with the view.
Definition duckdb.cpp:2972
atomic< thread_id > bind_thread
Current binding thread.
Definition duckdb.cpp:3000

◆ UpdateBinding()

void duckdb::ViewCatalogEntry::UpdateBinding ( const vector< LogicalType > &  types,
const vector< string > &  names 
)
virtual

Update the view with a new set of types / names.

21566 {
21567 auto columns = view_columns.atomic_load();
21568 if (columns && columns->types == types_p && columns->names == names_p) {
21569 // already bound with the current info
21570 return;
21571 }
21572 lock_guard<mutex> guard(bind_lock);
21573 auto new_columns = make_shared_ptr<ViewColumnInfo>();
21574 new_columns->types = types_p;
21575 new_columns->names = names_p;
21576 view_columns.atomic_store(new_columns);
21577 bind_state = ViewBindState::BOUND;
21578}

◆ GetColumnComment()

Value duckdb::ViewCatalogEntry::GetColumnComment ( idx_t  column_index)
21521 {
21522 auto view_columns = GetColumnInfo();
21523 if (!view_columns) {
21524 throw InternalException("ViewCatalogEntry::GetColumnComment called - but view has not been bound yet");
21525 }
21526 auto &names = view_columns->names;
21527 if (column_index >= names.size()) {
21528 return Value();
21529 }
21530 auto &name = names[column_index];
21531 auto entry = column_comments.find(name);
21532 if (entry != column_comments.end()) {
21533 return entry->second;
21534 }
21535 return Value();
21536}
unordered_map< string, Value > column_comments
The comments on the columns of the view: can be empty if there are no comments.
Definition duckdb.cpp:3002
virtual shared_ptr< ViewColumnInfo > GetColumnInfo() const
Returns the view column info, if the view is bound. Otherwise returns nullptr
Definition duckdb.cpp:21517

◆ GetInfo()

unique_ptr< CreateInfo > duckdb::ViewCatalogEntry::GetInfo ( ) const
overridevirtual

Reimplemented from duckdb::CatalogEntry.

21457 {
21458 auto result = make_uniq<CreateViewInfo>();
21459 result->schema = schema.name;
21460 result->view_name = name;
21461 result->sql = sql;
21462 result->query = query ? unique_ptr_cast<SQLStatement, SelectStatement>(query->Copy()) : nullptr;
21463 result->aliases = aliases;
21464 auto view_columns = GetColumnInfo();
21465 if (view_columns) {
21466 result->names = view_columns->names;
21467 result->types = view_columns->types;
21468 }
21469 result->temporary = temporary;
21470 result->dependencies = dependencies;
21471 result->comment = comment;
21472 result->tags = tags;
21473 result->column_comments_map = column_comments;
21474 return std::move(result);
21475}
InsertionOrderPreservingMap< string > tags
(optional) extra data associated with this entry
Definition duckdb.hpp:6323
Value comment
(optional) comment on this entry
Definition duckdb.hpp:6321
bool temporary
Whether or not the object is temporary and should not be added to the WAL.
Definition duckdb.hpp:6315
LogicalDependencyList dependencies
The dependencies of the entry, can be empty.
Definition duckdb.hpp:28010
string sql
The SQL query (if any)
Definition duckdb.cpp:2970
unique_ptr< SelectStatement > query
The query of the view.
Definition duckdb.cpp:2968

◆ AlterEntry()

unique_ptr< CatalogEntry > duckdb::ViewCatalogEntry::AlterEntry ( ClientContext context,
AlterInfo info 
)
overridevirtual

Reimplemented from duckdb::CatalogEntry.

21477 {
21478 D_ASSERT(!internal);
21479
21480 // Column comments have a special alter type
21481 if (info.type == AlterType::SET_COLUMN_COMMENT) {
21482 auto &comment_on_column_info = info.Cast<SetColumnCommentInfo>();
21483 auto copied_view = Copy(context);
21484
21485 auto view_columns = GetColumnInfo();
21486 if (view_columns) {
21487 // if the view is bound - verify the name we are commenting on exists
21488 auto &names = view_columns->names;
21489 auto entry = std::find(names.begin(), names.end(), comment_on_column_info.column_name);
21490 if (entry == names.end()) {
21491 throw BinderException("View \"%s\" does not have a column with name \"%s\"", name,
21492 comment_on_column_info.column_name);
21493 }
21494 }
21495 // apply the comment to the view
21496 auto &copied_view_entry = copied_view->Cast<ViewCatalogEntry>();
21497 copied_view_entry.column_comments[comment_on_column_info.column_name] = comment_on_column_info.comment_value;
21498 return copied_view;
21499 }
21500
21501 if (info.type != AlterType::ALTER_VIEW) {
21502 throw CatalogException("Can only modify view with ALTER VIEW statement");
21503 }
21504 auto &view_info = info.Cast<AlterViewInfo>();
21505 switch (view_info.alter_view_type) {
21506 case AlterViewType::RENAME_VIEW: {
21507 auto &rename_info = view_info.Cast<RenameViewInfo>();
21508 auto copied_view = Copy(context);
21509 copied_view->name = rename_info.new_view_name;
21510 return copied_view;
21511 }
21512 default:
21513 throw InternalException("Unrecognized alter view type!");
21514 }
21515}
bool internal
Whether or not the entry is an internal entry (cannot be deleted, not dumped, etc)
Definition duckdb.hpp:6317
ViewCatalogEntry(Catalog &catalog, SchemaCatalogEntry &schema, CreateViewInfo &info)
Create a real TableCatalogEntry and initialize storage for it.
Definition duckdb.cpp:21452

◆ Copy()

unique_ptr< CatalogEntry > duckdb::ViewCatalogEntry::Copy ( ClientContext context) const
overridevirtual

Reimplemented from duckdb::CatalogEntry.

21594 {
21595 D_ASSERT(!internal);
21596 auto create_info = GetInfo();
21597
21598 return make_uniq<ViewCatalogEntry>(catalog, schema, create_info->Cast<CreateViewInfo>());
21599}

◆ GetQuery()

const SelectStatement & duckdb::ViewCatalogEntry::GetQuery ( )
virtual
21590 {
21591 return *query;
21592}

◆ ToSQL()

string duckdb::ViewCatalogEntry::ToSQL ( ) const
overridevirtual

Convert the catalog entry to a SQL string that can be used to re-construct the catalog entry.

Return empty sql with view name so pragma view_tables don't complain

Reimplemented from duckdb::CatalogEntry.

21580 {
21581 if (sql.empty()) {
21583 return sql;
21584 }
21585 auto info = GetInfo();
21586 auto result = info->ToString();
21587 return result;
21588}

◆ Initialize()

void duckdb::ViewCatalogEntry::Initialize ( CreateViewInfo info)
private
21425 {
21426 query = std::move(info.query);
21427 this->aliases = info.aliases;
21428 if (!info.types.empty()) {
21429 bind_state = ViewBindState::BOUND;
21430 view_columns = make_shared_ptr<ViewColumnInfo>();
21431 view_columns->types = info.types;
21432 view_columns->names = info.names;
21433 if (view_columns->names.empty()) {
21434 // DuckDB v0.9.2 and below store their names in the "aliases" field
21435 view_columns->names = info.aliases;
21436 }
21437 if (view_columns->types.size() != view_columns->names.size()) {
21438 throw InvalidInputException(
21439 "Error creating view %s - view types / names size mismatch (%d types, %d names)", name,
21440 view_columns->types.size(), view_columns->names.size());
21441 }
21442 }
21443 this->temporary = info.temporary;
21444 this->sql = info.sql;
21445 this->internal = info.internal;
21446 this->dependencies = info.dependencies;
21447 this->comment = info.comment;
21448 this->tags = info.tags;
21449 this->column_comments = info.column_comments_map;
21450}

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