1 | //===----------------------------------------------------------------------===// |
---|---|
2 | // DuckDB |
3 | // |
4 | // duckdb/parser/tableref.hpp |
5 | // |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | #pragma once |
10 | |
11 | #include "duckdb/common/common.hpp" |
12 | #include "duckdb/common/enums/tableref_type.hpp" |
13 | #include "duckdb/parser/parsed_data/sample_options.hpp" |
14 | |
15 | namespace duckdb { |
16 | class Deserializer; |
17 | class Serializer; |
18 | |
19 | //! Represents a generic expression that returns a table. |
20 | class TableRef { |
21 | public: |
22 | static constexpr const TableReferenceType TYPE = TableReferenceType::INVALID; |
23 | |
24 | public: |
25 | explicit TableRef(TableReferenceType type) : type(type) { |
26 | } |
27 | virtual ~TableRef() { |
28 | } |
29 | |
30 | TableReferenceType type; |
31 | string alias; |
32 | //! Sample options (if any) |
33 | unique_ptr<SampleOptions> sample; |
34 | //! The location in the query (if any) |
35 | idx_t query_location = DConstants::INVALID_INDEX; |
36 | |
37 | public: |
38 | //! Convert the object to a string |
39 | virtual string ToString() const = 0; |
40 | string BaseToString(string result) const; |
41 | string BaseToString(string result, const vector<string> &column_name_alias) const; |
42 | void Print(); |
43 | |
44 | virtual bool Equals(const TableRef &other) const; |
45 | static bool Equals(const unique_ptr<TableRef> &left, const unique_ptr<TableRef> &right); |
46 | |
47 | virtual unique_ptr<TableRef> Copy() = 0; |
48 | |
49 | //! Serializes a TableRef to a stand-alone binary blob |
50 | DUCKDB_API void Serialize(Serializer &serializer) const; |
51 | //! Serializes a TableRef to a stand-alone binary blob |
52 | DUCKDB_API virtual void Serialize(FieldWriter &writer) const = 0; |
53 | //! Deserializes a blob back into a TableRef |
54 | DUCKDB_API static unique_ptr<TableRef> Deserialize(Deserializer &source); |
55 | //! Copy the properties of this table ref to the target |
56 | void CopyProperties(TableRef &target) const; |
57 | |
58 | virtual void FormatSerialize(FormatSerializer &serializer) const; |
59 | static unique_ptr<TableRef> FormatDeserialize(FormatDeserializer &deserializer); |
60 | |
61 | public: |
62 | template <class TARGET> |
63 | TARGET &Cast() { |
64 | if (type != TARGET::TYPE && TARGET::TYPE != TableReferenceType::INVALID) { |
65 | throw InternalException("Failed to cast constraint to type - constraint type mismatch"); |
66 | } |
67 | return reinterpret_cast<TARGET &>(*this); |
68 | } |
69 | |
70 | template <class TARGET> |
71 | const TARGET &Cast() const { |
72 | if (type != TARGET::TYPE && TARGET::TYPE != TableReferenceType::INVALID) { |
73 | throw InternalException("Failed to cast constraint to type - constraint type mismatch"); |
74 | } |
75 | return reinterpret_cast<const TARGET &>(*this); |
76 | } |
77 | }; |
78 | } // namespace duckdb |
79 |