duckdb 0.3.3-dev944.0 → 0.3.3-dev977.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 "8b73feaf4"
15
- #define DUCKDB_VERSION "v0.3.3-dev944"
14
+ #define DUCKDB_SOURCE_ID "440cba203"
15
+ #define DUCKDB_VERSION "v0.3.3-dev977"
16
16
  //===----------------------------------------------------------------------===//
17
17
  // DuckDB
18
18
  //
@@ -11155,6 +11155,7 @@ public:
11155
11155
 
11156
11156
 
11157
11157
 
11158
+
11158
11159
  namespace duckdb {
11159
11160
 
11160
11161
  class Serializer;
@@ -11173,6 +11174,24 @@ enum class ConstraintType : uint8_t {
11173
11174
  FOREIGN_KEY = 4 // FOREIGN KEY constraint
11174
11175
  };
11175
11176
 
11177
+ enum class ForeignKeyType : uint8_t {
11178
+ FK_TYPE_PRIMARY_KEY_TABLE = 0, // main table
11179
+ FK_TYPE_FOREIGN_KEY_TABLE = 1, // referencing table
11180
+ FK_TYPE_SELF_REFERENCE_TABLE = 2 // self refrencing table
11181
+ };
11182
+
11183
+ struct ForeignKeyInfo {
11184
+ ForeignKeyType type;
11185
+ string schema;
11186
+ //! if type is FK_TYPE_FOREIGN_KEY_TABLE, means main key table, if type is FK_TYPE_PRIMARY_KEY_TABLE, means foreign
11187
+ //! key table
11188
+ string table;
11189
+ //! The set of main key table's column's index
11190
+ vector<idx_t> pk_keys;
11191
+ //! The set of foreign key table's column's index
11192
+ vector<idx_t> fk_keys;
11193
+ };
11194
+
11176
11195
  //! Constraint is the base class of any type of table constraint.
11177
11196
  class Constraint {
11178
11197
  public:
@@ -11235,6 +11254,7 @@ struct AddColumnInfo;
11235
11254
  struct RemoveColumnInfo;
11236
11255
  struct SetDefaultInfo;
11237
11256
  struct ChangeColumnTypeInfo;
11257
+ struct AlterForeignKeyInfo;
11238
11258
 
11239
11259
  //! A table catalog entry
11240
11260
  class TableCatalogEntry : public StandardEntry {
@@ -11289,6 +11309,7 @@ private:
11289
11309
  unique_ptr<CatalogEntry> RemoveColumn(ClientContext &context, RemoveColumnInfo &info);
11290
11310
  unique_ptr<CatalogEntry> SetDefault(ClientContext &context, SetDefaultInfo &info);
11291
11311
  unique_ptr<CatalogEntry> ChangeColumnType(ClientContext &context, ChangeColumnTypeInfo &info);
11312
+ unique_ptr<CatalogEntry> SetForeignKeyConstraint(ClientContext &context, AlterForeignKeyInfo &info);
11292
11313
  };
11293
11314
  } // namespace duckdb
11294
11315
 
@@ -11460,6 +11481,8 @@ enum class AlterType : uint8_t {
11460
11481
  CHANGE_OWNERSHIP = 4
11461
11482
  };
11462
11483
 
11484
+ enum AlterForeignKeyType : uint8_t { AFT_ADD = 0, AFT_DELETE = 1 };
11485
+
11463
11486
  struct AlterInfo : public ParseInfo {
11464
11487
  AlterInfo(AlterType type, string schema, string name);
11465
11488
  ~AlterInfo() override;
@@ -11509,7 +11532,8 @@ enum class AlterTableType : uint8_t {
11509
11532
  ADD_COLUMN = 3,
11510
11533
  REMOVE_COLUMN = 4,
11511
11534
  ALTER_COLUMN_TYPE = 5,
11512
- SET_DEFAULT = 6
11535
+ SET_DEFAULT = 6,
11536
+ FOREIGN_KEY_CONSTRAINT = 7
11513
11537
  };
11514
11538
 
11515
11539
  struct AlterTableInfo : public AlterInfo {
@@ -11632,6 +11656,28 @@ public:
11632
11656
  static unique_ptr<AlterInfo> Deserialize(FieldReader &reader, string schema, string table);
11633
11657
  };
11634
11658
 
11659
+ //===--------------------------------------------------------------------===//
11660
+ // AlterForeignKeyInfo
11661
+ //===--------------------------------------------------------------------===//
11662
+ struct AlterForeignKeyInfo : public AlterTableInfo {
11663
+ AlterForeignKeyInfo(string schema, string table, string fk_table, vector<string> pk_columns,
11664
+ vector<string> fk_columns, vector<idx_t> pk_keys, vector<idx_t> fk_keys,
11665
+ AlterForeignKeyType type);
11666
+ ~AlterForeignKeyInfo() override;
11667
+
11668
+ string fk_table;
11669
+ vector<string> pk_columns;
11670
+ vector<string> fk_columns;
11671
+ vector<idx_t> pk_keys;
11672
+ vector<idx_t> fk_keys;
11673
+ AlterForeignKeyType type;
11674
+
11675
+ public:
11676
+ unique_ptr<AlterInfo> Copy() const override;
11677
+ void SerializeAlterTable(FieldWriter &writer) const override;
11678
+ static unique_ptr<AlterInfo> Deserialize(FieldReader &reader, string schema, string table);
11679
+ };
11680
+
11635
11681
  //===--------------------------------------------------------------------===//
11636
11682
  // Alter View
11637
11683
  //===--------------------------------------------------------------------===//
@@ -12638,6 +12684,7 @@ class Constraint;
12638
12684
  class NotNullConstraint;
12639
12685
  class CheckConstraint;
12640
12686
  class UniqueConstraint;
12687
+ class ForeignKeyConstraint;
12641
12688
 
12642
12689
  //===--------------------------------------------------------------------===//
12643
12690
  // TableRefs
@@ -14458,6 +14505,9 @@ public:
14458
14505
  void ChangeType(DataTable *old_dt, DataTable *new_dt, idx_t changed_idx, const LogicalType &target_type,
14459
14506
  const vector<column_t> &bound_columns, Expression &cast_expr);
14460
14507
 
14508
+ void FetchChunk(DataTable *table, Vector &row_ids, idx_t count, DataChunk &chunk);
14509
+ vector<unique_ptr<Index>> &GetIndexes(DataTable *table);
14510
+
14461
14511
  private:
14462
14512
  LocalTableStorage *GetStorage(DataTable *table);
14463
14513
 
@@ -16518,6 +16568,8 @@ class LogicalOperator;
16518
16568
  class QueryNode;
16519
16569
  class TableRef;
16520
16570
 
16571
+ class ExtraDependencies {};
16572
+
16521
16573
  class Relation : public std::enable_shared_from_this<Relation> {
16522
16574
  public:
16523
16575
  DUCKDB_API Relation(const std::shared_ptr<ClientContext> &context, RelationType type)
@@ -16532,6 +16584,8 @@ public:
16532
16584
 
16533
16585
  RelationType type;
16534
16586
 
16587
+ unique_ptr<ExtraDependencies> extra_dependencies;
16588
+
16535
16589
  public:
16536
16590
  DUCKDB_API virtual const vector<ColumnDefinition> &Columns() = 0;
16537
16591
  DUCKDB_API virtual unique_ptr<QueryNode> GetQueryNode();
@@ -19241,11 +19295,18 @@ class Transaction;
19241
19295
 
19242
19296
  struct IndexLock;
19243
19297
 
19298
+ enum IndexConstraintType : uint8_t {
19299
+ NONE = 0, // index is an index don't built to any constraint
19300
+ UNIQUE = 1, // index is an index built to enforce a UNIQUE constraint
19301
+ PRIMARY = 2, // index is an index built to enforce a PRIMARY KEY constraint
19302
+ FOREIGN = 3 // index is an index built to enforce a FOREIGN KEY constraint
19303
+ };
19304
+
19244
19305
  //! The index is an abstract base class that serves as the basis for indexes
19245
19306
  class Index {
19246
19307
  public:
19247
19308
  Index(IndexType type, const vector<column_t> &column_ids, const vector<unique_ptr<Expression>> &unbound_expressions,
19248
- bool is_unique, bool is_primary);
19309
+ IndexConstraintType constraint_type);
19249
19310
  virtual ~Index() = default;
19250
19311
 
19251
19312
  //! The type of the index
@@ -19260,10 +19321,8 @@ public:
19260
19321
  vector<PhysicalType> types;
19261
19322
  //! The logical types of the expressions
19262
19323
  vector<LogicalType> logical_types;
19263
- //! Whether or not the index is an index built to enforce a UNIQUE or PRIMARY KEY constraint
19264
- bool is_unique;
19265
- //! Whether or not the index is an index built to enforce a PRIMARY KEY constraint
19266
- bool is_primary;
19324
+ // ! constraint type
19325
+ IndexConstraintType constraint_type;
19267
19326
 
19268
19327
  public:
19269
19328
  //! Initialize a scan on the index with the given expression and column ids
@@ -19287,6 +19346,10 @@ public:
19287
19346
  bool Append(DataChunk &entries, Vector &row_identifiers);
19288
19347
  //! Verify that data can be appended to the index
19289
19348
  virtual void VerifyAppend(DataChunk &chunk) = 0;
19349
+ //! Verify that data can be appended to the index for foreign key constraint
19350
+ virtual void VerifyAppendForeignKey(DataChunk &chunk, string *err_msg_ptr) = 0;
19351
+ //! Verify that data can be delete from the index for foreign key constraint
19352
+ virtual void VerifyDeleteForeignKey(DataChunk &chunk, string *err_msg_ptr) = 0;
19290
19353
 
19291
19354
  //! Called when data inside the index is Deleted
19292
19355
  virtual void Delete(IndexLock &state, DataChunk &entries, Vector &row_identifiers) = 0;
@@ -19298,6 +19361,19 @@ public:
19298
19361
  //! Returns true if the index is affected by updates on the specified column ids, and false otherwise
19299
19362
  bool IndexIsUpdated(const vector<column_t> &column_ids) const;
19300
19363
 
19364
+ //! Returns unique flag
19365
+ bool IsUnique() {
19366
+ return (constraint_type == IndexConstraintType::UNIQUE || constraint_type == IndexConstraintType::PRIMARY);
19367
+ }
19368
+ //! Returns primary flag
19369
+ bool IsPrimary() {
19370
+ return (constraint_type == IndexConstraintType::PRIMARY);
19371
+ }
19372
+ //! Returns foreign flag
19373
+ bool IsForeign() {
19374
+ return (constraint_type == IndexConstraintType::FOREIGN);
19375
+ }
19376
+
19301
19377
  protected:
19302
19378
  void ExecuteExpressions(DataChunk &input, DataChunk &result);
19303
19379
 
@@ -20157,9 +20233,11 @@ public:
20157
20233
 
20158
20234
  private:
20159
20235
  //! Verify constraints with a chunk from the Append containing all columns of the table
20160
- void VerifyAppendConstraints(TableCatalogEntry &table, DataChunk &chunk);
20236
+ void VerifyAppendConstraints(TableCatalogEntry &table, ClientContext &context, DataChunk &chunk);
20161
20237
  //! Verify constraints with a chunk from the Update containing only the specified column_ids
20162
20238
  void VerifyUpdateConstraints(TableCatalogEntry &table, DataChunk &chunk, const vector<column_t> &column_ids);
20239
+ //! Verify constraints with a chunk from the Delete containing all columns of the table
20240
+ void VerifyDeleteConstraints(TableCatalogEntry &table, ClientContext &context, DataChunk &chunk);
20163
20241
 
20164
20242
  void InitializeScanWithOffset(TableScanState &state, const vector<column_t> &column_ids, idx_t start_row,
20165
20243
  idx_t end_row);
@@ -22657,8 +22735,13 @@ struct ExportedTableData {
22657
22735
  string file_path;
22658
22736
  };
22659
22737
 
22738
+ struct ExportedTableInfo {
22739
+ TableCatalogEntry *entry;
22740
+ ExportedTableData table_data;
22741
+ };
22742
+
22660
22743
  struct BoundExportData : public ParseInfo {
22661
- unordered_map<TableCatalogEntry *, ExportedTableData> data;
22744
+ std::vector<ExportedTableInfo> data;
22662
22745
  };
22663
22746
 
22664
22747
  } // namespace duckdb