1//===----------------------------------------------------------------------===//
2// DuckDB
3//
4// duckdb/parser/column_definition.hpp
5//
6//
7//===----------------------------------------------------------------------===//
8
9#pragma once
10
11#include "duckdb/common/common.hpp"
12#include "duckdb/common/types/value.hpp"
13#include "duckdb/parser/parsed_expression.hpp"
14#include "duckdb/common/enums/compression_type.hpp"
15#include "duckdb/catalog/catalog_entry/table_column_type.hpp"
16#include "duckdb/common/case_insensitive_map.hpp"
17
18namespace duckdb {
19
20struct RenameColumnInfo;
21struct RenameTableInfo;
22
23class ColumnDefinition;
24
25//! A column of a table.
26class ColumnDefinition {
27public:
28 DUCKDB_API ColumnDefinition(string name, LogicalType type);
29 DUCKDB_API ColumnDefinition(string name, LogicalType type, unique_ptr<ParsedExpression> expression,
30 TableColumnType category);
31
32 //! The default value of the column (if any)
33 unique_ptr<ParsedExpression> default_value;
34
35public:
36 //! default_value
37 const unique_ptr<ParsedExpression> &DefaultValue() const;
38 void SetDefaultValue(unique_ptr<ParsedExpression> default_value);
39
40 //! type
41 DUCKDB_API const LogicalType &Type() const;
42 LogicalType &TypeMutable();
43 void SetType(const LogicalType &type);
44
45 //! name
46 DUCKDB_API const string &Name() const;
47 void SetName(const string &name);
48
49 //! compression_type
50 const duckdb::CompressionType &CompressionType() const;
51 void SetCompressionType(duckdb::CompressionType compression_type);
52
53 //! storage_oid
54 const storage_t &StorageOid() const;
55 void SetStorageOid(storage_t storage_oid);
56
57 LogicalIndex Logical() const;
58 PhysicalIndex Physical() const;
59
60 //! oid
61 const column_t &Oid() const;
62 void SetOid(column_t oid);
63
64 //! category
65 const TableColumnType &Category() const;
66 //! Whether this column is a Generated Column
67 bool Generated() const;
68 DUCKDB_API ColumnDefinition Copy() const;
69
70 DUCKDB_API void Serialize(Serializer &serializer) const;
71 DUCKDB_API static ColumnDefinition Deserialize(Deserializer &source);
72
73 //===--------------------------------------------------------------------===//
74 // Generated Columns (VIRTUAL)
75 //===--------------------------------------------------------------------===//
76
77 ParsedExpression &GeneratedExpressionMutable();
78 const ParsedExpression &GeneratedExpression() const;
79 void SetGeneratedExpression(unique_ptr<ParsedExpression> expression);
80 void ChangeGeneratedExpressionType(const LogicalType &type);
81 void GetListOfDependencies(vector<string> &dependencies) const;
82
83 string GetName() const;
84
85 LogicalType GetType() const;
86
87private:
88 //! The name of the entry
89 string name;
90 //! The type of the column
91 LogicalType type;
92 //! Compression Type used for this column
93 duckdb::CompressionType compression_type = duckdb::CompressionType::COMPRESSION_AUTO;
94 //! The index of the column in the storage of the table
95 storage_t storage_oid = DConstants::INVALID_INDEX;
96 //! The index of the column in the table
97 idx_t oid = DConstants::INVALID_INDEX;
98 //! The category of the column
99 TableColumnType category = TableColumnType::STANDARD;
100 //! Used by Generated Columns
101 unique_ptr<ParsedExpression> generated_expression;
102};
103
104} // namespace duckdb
105