//===----------------------------------------------------------------------===// // DuckDB // // duckdb/parser/tableref.hpp // // //===----------------------------------------------------------------------===// #pragma once #include "duckdb/common/common.hpp" #include "duckdb/common/enums/tableref_type.hpp" #include "duckdb/parser/parsed_data/sample_options.hpp" namespace duckdb { class Deserializer; class Serializer; //! Represents a generic expression that returns a table. class TableRef { public: static constexpr const TableReferenceType TYPE = TableReferenceType::INVALID; public: explicit TableRef(TableReferenceType type) : type(type) { } virtual ~TableRef() { } TableReferenceType type; string alias; //! Sample options (if any) unique_ptr sample; //! The location in the query (if any) idx_t query_location = DConstants::INVALID_INDEX; public: //! Convert the object to a string virtual string ToString() const = 0; string BaseToString(string result) const; string BaseToString(string result, const vector &column_name_alias) const; void Print(); virtual bool Equals(const TableRef &other) const; static bool Equals(const unique_ptr &left, const unique_ptr &right); virtual unique_ptr Copy() = 0; //! Serializes a TableRef to a stand-alone binary blob DUCKDB_API void Serialize(Serializer &serializer) const; //! Serializes a TableRef to a stand-alone binary blob DUCKDB_API virtual void Serialize(FieldWriter &writer) const = 0; //! Deserializes a blob back into a TableRef DUCKDB_API static unique_ptr Deserialize(Deserializer &source); //! Copy the properties of this table ref to the target void CopyProperties(TableRef &target) const; virtual void FormatSerialize(FormatSerializer &serializer) const; static unique_ptr FormatDeserialize(FormatDeserializer &deserializer); public: template TARGET &Cast() { if (type != TARGET::TYPE && TARGET::TYPE != TableReferenceType::INVALID) { throw InternalException("Failed to cast constraint to type - constraint type mismatch"); } return reinterpret_cast(*this); } template const TARGET &Cast() const { if (type != TARGET::TYPE && TARGET::TYPE != TableReferenceType::INVALID) { throw InternalException("Failed to cast constraint to type - constraint type mismatch"); } return reinterpret_cast(*this); } }; } // namespace duckdb