duckdb 0.3.5-dev765.0 → 0.3.5-dev894.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/duckdb.hpp CHANGED
@@ -11,8 +11,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
11
11
  #pragma once
12
12
  #define DUCKDB_AMALGAMATION 1
13
13
  #define DUCKDB_AMALGAMATION_EXTENDED 1
14
- #define DUCKDB_SOURCE_ID "a9c194b69"
15
- #define DUCKDB_VERSION "v0.3.5-dev765"
14
+ #define DUCKDB_SOURCE_ID "5287a381f"
15
+ #define DUCKDB_VERSION "v0.3.5-dev894"
16
16
  //===----------------------------------------------------------------------===//
17
17
  // DuckDB
18
18
  //
@@ -162,6 +162,8 @@ typedef idx_t transaction_t;
162
162
 
163
163
  //! Type used for column identifiers
164
164
  typedef idx_t column_t;
165
+ //! Type used for storage (column) identifiers
166
+ typedef idx_t storage_t;
165
167
  //! Special value used to signify the ROW ID of a table
166
168
  extern const column_t COLUMN_IDENTIFIER_ROW_ID;
167
169
 
@@ -6204,31 +6206,104 @@ string CompressionTypeToString(CompressionType type);
6204
6206
 
6205
6207
  } // namespace duckdb
6206
6208
 
6209
+ //===----------------------------------------------------------------------===//
6210
+ // DuckDB
6211
+ //
6212
+ // duckdb/catalog/catalog_entry/table_column_type.hpp
6213
+ //
6214
+ //
6215
+ //===----------------------------------------------------------------------===//
6216
+
6217
+
6218
+
6219
+
6207
6220
 
6208
6221
  namespace duckdb {
6209
6222
 
6223
+ enum class TableColumnType : uint8_t { STANDARD = 0, GENERATED = 1 };
6224
+
6225
+ } // namespace duckdb
6226
+
6227
+
6228
+
6229
+ namespace duckdb {
6230
+
6231
+ struct RenameColumnInfo;
6232
+ struct RenameTableInfo;
6233
+
6234
+ class ColumnDefinition;
6235
+
6210
6236
  //! A column of a table.
6211
6237
  class ColumnDefinition {
6212
6238
  public:
6213
6239
  DUCKDB_API ColumnDefinition(string name, LogicalType type);
6214
- DUCKDB_API ColumnDefinition(string name, LogicalType type, unique_ptr<ParsedExpression> default_value);
6240
+ DUCKDB_API ColumnDefinition(string name, LogicalType type, unique_ptr<ParsedExpression> expression,
6241
+ TableColumnType category);
6215
6242
 
6216
- //! The name of the entry
6217
- string name;
6218
- //! The index of the column in the table
6219
- idx_t oid;
6220
- //! The type of the column
6221
- LogicalType type;
6222
6243
  //! The default value of the column (if any)
6223
6244
  unique_ptr<ParsedExpression> default_value;
6224
- //! Compression Type used for this column
6225
- CompressionType compression_type = CompressionType::COMPRESSION_AUTO;
6226
6245
 
6227
6246
  public:
6247
+ //! default_value
6248
+ const unique_ptr<ParsedExpression> &DefaultValue() const;
6249
+ void SetDefaultValue(unique_ptr<ParsedExpression> default_value);
6250
+
6251
+ //! type
6252
+ DUCKDB_API const LogicalType &Type() const;
6253
+ LogicalType &TypeMutable();
6254
+ void SetType(const LogicalType &type);
6255
+
6256
+ //! name
6257
+ DUCKDB_API const string &Name() const;
6258
+ void SetName(const string &name);
6259
+
6260
+ //! compression_type
6261
+ const duckdb::CompressionType &CompressionType() const;
6262
+ void SetCompressionType(duckdb::CompressionType compression_type);
6263
+
6264
+ //! storage_oid
6265
+ const storage_t &StorageOid() const;
6266
+ void SetStorageOid(storage_t storage_oid);
6267
+
6268
+ //! oid
6269
+ const column_t &Oid() const;
6270
+ void SetOid(column_t oid);
6271
+
6272
+ //! category
6273
+ const TableColumnType &Category() const;
6274
+ //! Whether this column is a Generated Column
6275
+ bool Generated() const;
6228
6276
  DUCKDB_API ColumnDefinition Copy() const;
6229
6277
 
6230
6278
  DUCKDB_API void Serialize(Serializer &serializer) const;
6231
6279
  DUCKDB_API static ColumnDefinition Deserialize(Deserializer &source);
6280
+
6281
+ //===--------------------------------------------------------------------===//
6282
+ // Generated Columns (VIRTUAL)
6283
+ //===--------------------------------------------------------------------===//
6284
+
6285
+ ParsedExpression &GeneratedExpressionMutable();
6286
+ const ParsedExpression &GeneratedExpression() const;
6287
+ void SetGeneratedExpression(unique_ptr<ParsedExpression> expression);
6288
+ void ChangeGeneratedExpressionType(const LogicalType &type);
6289
+ void GetListOfDependencies(vector<string> &dependencies) const;
6290
+
6291
+ private:
6292
+ private:
6293
+ //! The name of the entry
6294
+ string name;
6295
+ //! The type of the column
6296
+ LogicalType type;
6297
+ //! Compression Type used for this column
6298
+ duckdb::CompressionType compression_type = duckdb::CompressionType::COMPRESSION_AUTO;
6299
+ //! The index of the column in the storage of the table
6300
+ storage_t storage_oid;
6301
+ //! The index of the column in the table
6302
+ idx_t oid;
6303
+ //! The category of the column
6304
+ TableColumnType category = TableColumnType::STANDARD;
6305
+ //! Used by Generated Columns
6306
+ unique_ptr<ParsedExpression> generated_expression;
6232
6307
  };
6233
6308
 
6234
6309
  } // namespace duckdb
@@ -8310,8 +8385,9 @@ public:
8310
8385
  mutex write_lock;
8311
8386
 
8312
8387
  public:
8313
- //! Get the ClientContext from the Catalog
8388
+ //! Get the Catalog from the ClientContext
8314
8389
  DUCKDB_API static Catalog &GetCatalog(ClientContext &context);
8390
+ //! Get the Catalog from the DatabaseInstance
8315
8391
  DUCKDB_API static Catalog &GetCatalog(DatabaseInstance &db);
8316
8392
 
8317
8393
  DUCKDB_API DependencyManager &GetDependencyManager() {
@@ -11403,11 +11479,11 @@ class FieldReader;
11403
11479
  // Constraint Types
11404
11480
  //===--------------------------------------------------------------------===//
11405
11481
  enum class ConstraintType : uint8_t {
11406
- INVALID = 0, // invalid constraint type
11407
- NOT_NULL = 1, // NOT NULL constraint
11408
- CHECK = 2, // CHECK constraint
11409
- UNIQUE = 3, // UNIQUE constraint
11410
- FOREIGN_KEY = 4 // FOREIGN KEY constraint
11482
+ INVALID = 0, // invalid constraint type
11483
+ NOT_NULL = 1, // NOT NULL constraint
11484
+ CHECK = 2, // CHECK constraint
11485
+ UNIQUE = 3, // UNIQUE constraint
11486
+ FOREIGN_KEY = 4, // FOREIGN KEY constraint
11411
11487
  };
11412
11488
 
11413
11489
  enum class ForeignKeyType : uint8_t {
@@ -11423,7 +11499,7 @@ struct ForeignKeyInfo {
11423
11499
  //! key table
11424
11500
  string table;
11425
11501
  //! The set of main key table's column's index
11426
- vector<idx_t> pk_keys;
11502
+ vector<storage_t> pk_keys;
11427
11503
  //! The set of foreign key table's column's index
11428
11504
  vector<idx_t> fk_keys;
11429
11505
  };
@@ -11478,6 +11554,103 @@ public:
11478
11554
 
11479
11555
 
11480
11556
 
11557
+ //===----------------------------------------------------------------------===//
11558
+ // DuckDB
11559
+ //
11560
+ // duckdb/catalog/catalog_entry/column_dependency_manager.hpp
11561
+ //
11562
+ //
11563
+ //===----------------------------------------------------------------------===//
11564
+
11565
+
11566
+
11567
+
11568
+
11569
+
11570
+ //===----------------------------------------------------------------------===//
11571
+ // DuckDB
11572
+ //
11573
+ // duckdb/common/set.hpp
11574
+ //
11575
+ //
11576
+ //===----------------------------------------------------------------------===//
11577
+
11578
+
11579
+
11580
+ #include <set>
11581
+
11582
+ namespace duckdb {
11583
+ using std::set;
11584
+ }
11585
+
11586
+ //===----------------------------------------------------------------------===//
11587
+ // DuckDB
11588
+ //
11589
+ // duckdb/common/stack.hpp
11590
+ //
11591
+ //
11592
+ //===----------------------------------------------------------------------===//
11593
+
11594
+
11595
+
11596
+ #include <stack>
11597
+
11598
+ namespace duckdb {
11599
+ using std::stack;
11600
+ }
11601
+
11602
+
11603
+ namespace duckdb {
11604
+
11605
+ //! Dependency Manager local to a table, responsible for keeping track of generated column dependencies
11606
+
11607
+ class ColumnDependencyManager {
11608
+ public:
11609
+ DUCKDB_API ColumnDependencyManager();
11610
+ DUCKDB_API ~ColumnDependencyManager();
11611
+ DUCKDB_API ColumnDependencyManager(ColumnDependencyManager &&other) = default;
11612
+ DUCKDB_API ColumnDependencyManager(const ColumnDependencyManager &other) = delete;
11613
+
11614
+ public:
11615
+ //! Get the bind order that ensures dependencies are resolved before dependents are
11616
+ stack<column_t> GetBindOrder(const vector<ColumnDefinition> &columns);
11617
+
11618
+ //! Adds a connection between the dependent and its dependencies
11619
+ void AddGeneratedColumn(column_t index, const vector<column_t> &indices, bool root = true);
11620
+ //! Add a generated column from a column definition
11621
+ void AddGeneratedColumn(const ColumnDefinition &column, const case_insensitive_map_t<column_t> &name_map);
11622
+
11623
+ //! Removes the column(s) and outputs the new column indices
11624
+ vector<column_t> RemoveColumn(column_t index, column_t column_amount);
11625
+
11626
+ bool IsDependencyOf(column_t dependent, column_t dependency) const;
11627
+ bool HasDependencies(column_t index) const;
11628
+ const unordered_set<column_t> &GetDependencies(column_t index) const;
11629
+
11630
+ bool HasDependents(column_t index) const;
11631
+ const unordered_set<column_t> &GetDependents(column_t index) const;
11632
+
11633
+ private:
11634
+ void RemoveStandardColumn(column_t index);
11635
+ void RemoveGeneratedColumn(column_t index);
11636
+
11637
+ void AdjustSingle(column_t idx, idx_t offset);
11638
+ // Clean up the gaps created by a Remove operation
11639
+ vector<column_t> CleanupInternals(column_t column_amount);
11640
+
11641
+ private:
11642
+ //! A map of column dependency to generated column(s)
11643
+ unordered_map<column_t, unordered_set<column_t>> dependencies_map;
11644
+ //! A map of generated column name to (potentially generated)column dependencies
11645
+ unordered_map<column_t, unordered_set<column_t>> dependents_map;
11646
+ //! For resolve-order purposes, keep track of the 'direct' (not inherited) dependencies of a generated column
11647
+ unordered_map<column_t, unordered_set<column_t>> direct_dependencies;
11648
+ set<column_t> deleted_columns;
11649
+ };
11650
+
11651
+ } // namespace duckdb
11652
+
11653
+
11481
11654
  namespace duckdb {
11482
11655
 
11483
11656
  class ColumnStatistics;
@@ -11507,13 +11680,16 @@ public:
11507
11680
  vector<unique_ptr<Constraint>> constraints;
11508
11681
  //! A list of constraints that are part of this table
11509
11682
  vector<unique_ptr<BoundConstraint>> bound_constraints;
11683
+ ColumnDependencyManager column_dependency_manager;
11510
11684
  //! A map of column name to column index
11511
11685
  case_insensitive_map_t<column_t> name_map;
11512
11686
 
11513
11687
  public:
11688
+ //! For debugging purposes, count how many columns are STANDARD
11689
+ idx_t StandardColumnCount() const;
11514
11690
  unique_ptr<CatalogEntry> AlterEntry(ClientContext &context, AlterInfo *info) override;
11515
11691
  //! Returns whether or not a column with the given name exists
11516
- bool ColumnExists(const string &name);
11692
+ DUCKDB_API bool ColumnExists(const string &name);
11517
11693
  //! Returns a reference to the column of the specified name. Throws an
11518
11694
  //! exception if the column does not exist.
11519
11695
  ColumnDefinition &GetColumn(const string &name);
@@ -11537,9 +11713,10 @@ public:
11537
11713
  //! If the column does not exist:
11538
11714
  //! If if_exists is true, returns DConstants::INVALID_INDEX
11539
11715
  //! If if_exists is false, throws an exception
11540
- idx_t GetColumnIndex(string &name, bool if_exists = false);
11716
+ column_t GetColumnIndex(string &name, bool if_exists = false);
11541
11717
 
11542
11718
  private:
11719
+ const string &GetColumnName(column_t index);
11543
11720
  unique_ptr<CatalogEntry> RenameColumn(ClientContext &context, RenameColumnInfo &info);
11544
11721
  unique_ptr<CatalogEntry> AddColumn(ClientContext &context, AddColumnInfo &info);
11545
11722
  unique_ptr<CatalogEntry> RemoveColumn(ClientContext &context, RemoveColumnInfo &info);
@@ -11707,6 +11884,7 @@ public:
11707
11884
 
11708
11885
 
11709
11886
 
11887
+
11710
11888
  namespace duckdb {
11711
11889
 
11712
11890
  enum class AlterType : uint8_t {
@@ -11769,7 +11947,7 @@ enum class AlterTableType : uint8_t {
11769
11947
  REMOVE_COLUMN = 4,
11770
11948
  ALTER_COLUMN_TYPE = 5,
11771
11949
  SET_DEFAULT = 6,
11772
- FOREIGN_KEY_CONSTRAINT = 7
11950
+ FOREIGN_KEY_CONSTRAINT = 7,
11773
11951
  };
11774
11952
 
11775
11953
  struct AlterTableInfo : public AlterInfo {
@@ -11839,13 +12017,15 @@ public:
11839
12017
  // RemoveColumnInfo
11840
12018
  //===--------------------------------------------------------------------===//
11841
12019
  struct RemoveColumnInfo : public AlterTableInfo {
11842
- RemoveColumnInfo(string schema, string table, string removed_column, bool if_exists);
12020
+ RemoveColumnInfo(string schema, string table, string removed_column, bool if_exists, bool cascade);
11843
12021
  ~RemoveColumnInfo() override;
11844
12022
 
11845
12023
  //! The column to remove
11846
12024
  string removed_column;
11847
12025
  //! Whether or not an error should be thrown if the column does not exist
11848
12026
  bool if_exists;
12027
+ //! Whether or not the column should be removed if a dependency conflict arises (used by GENERATED columns)
12028
+ bool cascade;
11849
12029
 
11850
12030
  public:
11851
12031
  unique_ptr<AlterInfo> Copy() const override;
@@ -12776,10 +12956,10 @@ namespace duckdb {
12776
12956
  class BoundReferenceExpression : public Expression {
12777
12957
  public:
12778
12958
  BoundReferenceExpression(string alias, LogicalType type, idx_t index);
12779
- BoundReferenceExpression(LogicalType type, idx_t index);
12959
+ BoundReferenceExpression(LogicalType type, storage_t index);
12780
12960
 
12781
12961
  //! Index used to access data in the chunks
12782
- idx_t index;
12962
+ storage_t index;
12783
12963
 
12784
12964
  public:
12785
12965
  bool IsScalar() const override {
@@ -13350,6 +13530,7 @@ protected:
13350
13530
 
13351
13531
 
13352
13532
 
13533
+
13353
13534
  namespace duckdb {
13354
13535
  class BindContext;
13355
13536
  class BoundQueryNode;
@@ -13360,11 +13541,16 @@ class TableCatalogEntry;
13360
13541
  class TableFunctionCatalogEntry;
13361
13542
  class BoundTableFunction;
13362
13543
 
13544
+ enum class BindingType { BASE, TABLE, MACRO };
13545
+
13363
13546
  //! A Binding represents a binding to a table, table-producing function or subquery with a specified table index.
13364
13547
  struct Binding {
13365
- Binding(const string &alias, vector<LogicalType> types, vector<string> names, idx_t index);
13548
+ Binding(BindingType binding_type, const string &alias, vector<LogicalType> types, vector<string> names,
13549
+ idx_t index);
13366
13550
  virtual ~Binding() = default;
13367
13551
 
13552
+ //! The type of Binding
13553
+ BindingType binding_type;
13368
13554
  //! The alias of the binding
13369
13555
  string alias;
13370
13556
  //! The table index of the binding
@@ -13394,6 +13580,7 @@ struct TableBinding : public Binding {
13394
13580
  LogicalGet &get;
13395
13581
 
13396
13582
  public:
13583
+ unique_ptr<ParsedExpression> ExpandGeneratedColumn(const string &column_name);
13397
13584
  BindResult Bind(ColumnRefExpression &colref, idx_t depth) override;
13398
13585
  TableCatalogEntry *GetTableEntry() override;
13399
13586
  string ColumnNotFoundError(const string &column_name) const override;
@@ -13459,6 +13646,8 @@ public:
13459
13646
  string BindColumn(PositionalReferenceExpression &ref, string &table_name, string &column_name);
13460
13647
  BindResult BindColumn(PositionalReferenceExpression &ref, idx_t depth);
13461
13648
 
13649
+ unique_ptr<ParsedExpression> ExpandGeneratedColumn(const string &table_name, const string &column_name);
13650
+
13462
13651
  unique_ptr<ParsedExpression> CreateColumnReference(const string &table_name, const string &column_name);
13463
13652
  unique_ptr<ParsedExpression> CreateColumnReference(const string &schema_name, const string &table_name,
13464
13653
  const string &column_name);
@@ -13726,6 +13915,8 @@ private:
13726
13915
  unordered_set<ViewCatalogEntry *> bound_views;
13727
13916
 
13728
13917
  private:
13918
+ //! Bind the expressions of generated columns to check for errors
13919
+ void BindGeneratedColumns(BoundCreateTableInfo &info);
13729
13920
  //! Bind the default values of the columns of a table
13730
13921
  void BindDefaultValues(vector<ColumnDefinition> &columns, vector<unique_ptr<Expression>> &bound_defaults);
13731
13922
  //! Bind a limit value (LIMIT or OFFSET)
@@ -18197,21 +18388,6 @@ struct ReplacementScan {
18197
18388
 
18198
18389
  } // namespace duckdb
18199
18390
 
18200
- //===----------------------------------------------------------------------===//
18201
- // DuckDB
18202
- //
18203
- // duckdb/common/set.hpp
18204
- //
18205
- //
18206
- //===----------------------------------------------------------------------===//
18207
-
18208
-
18209
-
18210
- #include <set>
18211
-
18212
- namespace duckdb {
18213
- using std::set;
18214
- }
18215
18391
 
18216
18392
 
18217
18393
  //===----------------------------------------------------------------------===//
@@ -19564,6 +19740,7 @@ public:
19564
19740
 
19565
19741
 
19566
19742
 
19743
+
19567
19744
  namespace duckdb {
19568
19745
 
19569
19746
  struct CreateTableInfo : public CreateInfo {
@@ -20187,6 +20364,8 @@ public:
20187
20364
 
20188
20365
 
20189
20366
 
20367
+
20368
+
20190
20369
  namespace duckdb {
20191
20370
  class CatalogEntry;
20192
20371
 
@@ -20201,6 +20380,8 @@ struct BoundCreateTableInfo {
20201
20380
  unique_ptr<CreateInfo> base;
20202
20381
  //! The map of column names -> column index, used during binding
20203
20382
  case_insensitive_map_t<column_t> name_map;
20383
+ //! Column dependency manager of the table
20384
+ ColumnDependencyManager column_dependency_manager;
20204
20385
  //! List of constraints on the table
20205
20386
  vector<unique_ptr<Constraint>> constraints;
20206
20387
  //! List of bound constraints on the table
@@ -22267,9 +22448,24 @@ protected:
22267
22448
 
22268
22449
 
22269
22450
 
22451
+ //===----------------------------------------------------------------------===//
22452
+ // DuckDB
22453
+ //
22454
+ // duckdb/common/queue.hpp
22455
+ //
22456
+ //
22457
+ //===----------------------------------------------------------------------===//
22458
+
22459
+
22460
+
22461
+ #include <queue>
22462
+
22463
+ namespace duckdb {
22464
+ using std::queue;
22465
+ }
22466
+
22270
22467
 
22271
22468
  #include <sstream>
22272
- #include <queue>
22273
22469
 
22274
22470
  namespace duckdb {
22275
22471
  struct CopyInfo;