duckdb 0.3.3-dev948.0 → 0.3.3-dev993.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 "41e7c6bd4"
15
- #define DUCKDB_VERSION "v0.3.3-dev948"
14
+ #define DUCKDB_SOURCE_ID "ae38c6025"
15
+ #define DUCKDB_VERSION "v0.3.3-dev993"
16
16
  //===----------------------------------------------------------------------===//
17
17
  // DuckDB
18
18
  //
@@ -1970,7 +1970,8 @@ public:
1970
1970
  DUCKDB_API static string ExtractBaseName(const string &path);
1971
1971
 
1972
1972
  //! Runs a glob on the file system, returning a list of matching files
1973
- DUCKDB_API virtual vector<string> Glob(const string &path);
1973
+ DUCKDB_API virtual vector<string> Glob(const string &path, FileOpener *opener = nullptr);
1974
+ DUCKDB_API virtual vector<string> Glob(const string &path, ClientContext &context);
1974
1975
 
1975
1976
  //! registers a sub-file system to handle certain file name prefixes, e.g. http:// etc.
1976
1977
  DUCKDB_API virtual void RegisterSubSystem(unique_ptr<FileSystem> sub_fs);
@@ -11155,6 +11156,7 @@ public:
11155
11156
 
11156
11157
 
11157
11158
 
11159
+
11158
11160
  namespace duckdb {
11159
11161
 
11160
11162
  class Serializer;
@@ -11173,6 +11175,24 @@ enum class ConstraintType : uint8_t {
11173
11175
  FOREIGN_KEY = 4 // FOREIGN KEY constraint
11174
11176
  };
11175
11177
 
11178
+ enum class ForeignKeyType : uint8_t {
11179
+ FK_TYPE_PRIMARY_KEY_TABLE = 0, // main table
11180
+ FK_TYPE_FOREIGN_KEY_TABLE = 1, // referencing table
11181
+ FK_TYPE_SELF_REFERENCE_TABLE = 2 // self refrencing table
11182
+ };
11183
+
11184
+ struct ForeignKeyInfo {
11185
+ ForeignKeyType type;
11186
+ string schema;
11187
+ //! if type is FK_TYPE_FOREIGN_KEY_TABLE, means main key table, if type is FK_TYPE_PRIMARY_KEY_TABLE, means foreign
11188
+ //! key table
11189
+ string table;
11190
+ //! The set of main key table's column's index
11191
+ vector<idx_t> pk_keys;
11192
+ //! The set of foreign key table's column's index
11193
+ vector<idx_t> fk_keys;
11194
+ };
11195
+
11176
11196
  //! Constraint is the base class of any type of table constraint.
11177
11197
  class Constraint {
11178
11198
  public:
@@ -11235,6 +11255,7 @@ struct AddColumnInfo;
11235
11255
  struct RemoveColumnInfo;
11236
11256
  struct SetDefaultInfo;
11237
11257
  struct ChangeColumnTypeInfo;
11258
+ struct AlterForeignKeyInfo;
11238
11259
 
11239
11260
  //! A table catalog entry
11240
11261
  class TableCatalogEntry : public StandardEntry {
@@ -11289,6 +11310,7 @@ private:
11289
11310
  unique_ptr<CatalogEntry> RemoveColumn(ClientContext &context, RemoveColumnInfo &info);
11290
11311
  unique_ptr<CatalogEntry> SetDefault(ClientContext &context, SetDefaultInfo &info);
11291
11312
  unique_ptr<CatalogEntry> ChangeColumnType(ClientContext &context, ChangeColumnTypeInfo &info);
11313
+ unique_ptr<CatalogEntry> SetForeignKeyConstraint(ClientContext &context, AlterForeignKeyInfo &info);
11292
11314
  };
11293
11315
  } // namespace duckdb
11294
11316
 
@@ -11460,6 +11482,8 @@ enum class AlterType : uint8_t {
11460
11482
  CHANGE_OWNERSHIP = 4
11461
11483
  };
11462
11484
 
11485
+ enum AlterForeignKeyType : uint8_t { AFT_ADD = 0, AFT_DELETE = 1 };
11486
+
11463
11487
  struct AlterInfo : public ParseInfo {
11464
11488
  AlterInfo(AlterType type, string schema, string name);
11465
11489
  ~AlterInfo() override;
@@ -11509,7 +11533,8 @@ enum class AlterTableType : uint8_t {
11509
11533
  ADD_COLUMN = 3,
11510
11534
  REMOVE_COLUMN = 4,
11511
11535
  ALTER_COLUMN_TYPE = 5,
11512
- SET_DEFAULT = 6
11536
+ SET_DEFAULT = 6,
11537
+ FOREIGN_KEY_CONSTRAINT = 7
11513
11538
  };
11514
11539
 
11515
11540
  struct AlterTableInfo : public AlterInfo {
@@ -11632,6 +11657,28 @@ public:
11632
11657
  static unique_ptr<AlterInfo> Deserialize(FieldReader &reader, string schema, string table);
11633
11658
  };
11634
11659
 
11660
+ //===--------------------------------------------------------------------===//
11661
+ // AlterForeignKeyInfo
11662
+ //===--------------------------------------------------------------------===//
11663
+ struct AlterForeignKeyInfo : public AlterTableInfo {
11664
+ AlterForeignKeyInfo(string schema, string table, string fk_table, vector<string> pk_columns,
11665
+ vector<string> fk_columns, vector<idx_t> pk_keys, vector<idx_t> fk_keys,
11666
+ AlterForeignKeyType type);
11667
+ ~AlterForeignKeyInfo() override;
11668
+
11669
+ string fk_table;
11670
+ vector<string> pk_columns;
11671
+ vector<string> fk_columns;
11672
+ vector<idx_t> pk_keys;
11673
+ vector<idx_t> fk_keys;
11674
+ AlterForeignKeyType type;
11675
+
11676
+ public:
11677
+ unique_ptr<AlterInfo> Copy() const override;
11678
+ void SerializeAlterTable(FieldWriter &writer) const override;
11679
+ static unique_ptr<AlterInfo> Deserialize(FieldReader &reader, string schema, string table);
11680
+ };
11681
+
11635
11682
  //===--------------------------------------------------------------------===//
11636
11683
  // Alter View
11637
11684
  //===--------------------------------------------------------------------===//
@@ -12638,6 +12685,7 @@ class Constraint;
12638
12685
  class NotNullConstraint;
12639
12686
  class CheckConstraint;
12640
12687
  class UniqueConstraint;
12688
+ class ForeignKeyConstraint;
12641
12689
 
12642
12690
  //===--------------------------------------------------------------------===//
12643
12691
  // TableRefs
@@ -14458,6 +14506,9 @@ public:
14458
14506
  void ChangeType(DataTable *old_dt, DataTable *new_dt, idx_t changed_idx, const LogicalType &target_type,
14459
14507
  const vector<column_t> &bound_columns, Expression &cast_expr);
14460
14508
 
14509
+ void FetchChunk(DataTable *table, Vector &row_ids, idx_t count, DataChunk &chunk);
14510
+ vector<unique_ptr<Index>> &GetIndexes(DataTable *table);
14511
+
14461
14512
  private:
14462
14513
  LocalTableStorage *GetStorage(DataTable *table);
14463
14514
 
@@ -19245,11 +19296,18 @@ class Transaction;
19245
19296
 
19246
19297
  struct IndexLock;
19247
19298
 
19299
+ enum IndexConstraintType : uint8_t {
19300
+ NONE = 0, // index is an index don't built to any constraint
19301
+ UNIQUE = 1, // index is an index built to enforce a UNIQUE constraint
19302
+ PRIMARY = 2, // index is an index built to enforce a PRIMARY KEY constraint
19303
+ FOREIGN = 3 // index is an index built to enforce a FOREIGN KEY constraint
19304
+ };
19305
+
19248
19306
  //! The index is an abstract base class that serves as the basis for indexes
19249
19307
  class Index {
19250
19308
  public:
19251
19309
  Index(IndexType type, const vector<column_t> &column_ids, const vector<unique_ptr<Expression>> &unbound_expressions,
19252
- bool is_unique, bool is_primary);
19310
+ IndexConstraintType constraint_type);
19253
19311
  virtual ~Index() = default;
19254
19312
 
19255
19313
  //! The type of the index
@@ -19264,10 +19322,8 @@ public:
19264
19322
  vector<PhysicalType> types;
19265
19323
  //! The logical types of the expressions
19266
19324
  vector<LogicalType> logical_types;
19267
- //! Whether or not the index is an index built to enforce a UNIQUE or PRIMARY KEY constraint
19268
- bool is_unique;
19269
- //! Whether or not the index is an index built to enforce a PRIMARY KEY constraint
19270
- bool is_primary;
19325
+ // ! constraint type
19326
+ IndexConstraintType constraint_type;
19271
19327
 
19272
19328
  public:
19273
19329
  //! Initialize a scan on the index with the given expression and column ids
@@ -19291,6 +19347,10 @@ public:
19291
19347
  bool Append(DataChunk &entries, Vector &row_identifiers);
19292
19348
  //! Verify that data can be appended to the index
19293
19349
  virtual void VerifyAppend(DataChunk &chunk) = 0;
19350
+ //! Verify that data can be appended to the index for foreign key constraint
19351
+ virtual void VerifyAppendForeignKey(DataChunk &chunk, string *err_msg_ptr) = 0;
19352
+ //! Verify that data can be delete from the index for foreign key constraint
19353
+ virtual void VerifyDeleteForeignKey(DataChunk &chunk, string *err_msg_ptr) = 0;
19294
19354
 
19295
19355
  //! Called when data inside the index is Deleted
19296
19356
  virtual void Delete(IndexLock &state, DataChunk &entries, Vector &row_identifiers) = 0;
@@ -19302,6 +19362,19 @@ public:
19302
19362
  //! Returns true if the index is affected by updates on the specified column ids, and false otherwise
19303
19363
  bool IndexIsUpdated(const vector<column_t> &column_ids) const;
19304
19364
 
19365
+ //! Returns unique flag
19366
+ bool IsUnique() {
19367
+ return (constraint_type == IndexConstraintType::UNIQUE || constraint_type == IndexConstraintType::PRIMARY);
19368
+ }
19369
+ //! Returns primary flag
19370
+ bool IsPrimary() {
19371
+ return (constraint_type == IndexConstraintType::PRIMARY);
19372
+ }
19373
+ //! Returns foreign flag
19374
+ bool IsForeign() {
19375
+ return (constraint_type == IndexConstraintType::FOREIGN);
19376
+ }
19377
+
19305
19378
  protected:
19306
19379
  void ExecuteExpressions(DataChunk &input, DataChunk &result);
19307
19380
 
@@ -20161,9 +20234,11 @@ public:
20161
20234
 
20162
20235
  private:
20163
20236
  //! Verify constraints with a chunk from the Append containing all columns of the table
20164
- void VerifyAppendConstraints(TableCatalogEntry &table, DataChunk &chunk);
20237
+ void VerifyAppendConstraints(TableCatalogEntry &table, ClientContext &context, DataChunk &chunk);
20165
20238
  //! Verify constraints with a chunk from the Update containing only the specified column_ids
20166
20239
  void VerifyUpdateConstraints(TableCatalogEntry &table, DataChunk &chunk, const vector<column_t> &column_ids);
20240
+ //! Verify constraints with a chunk from the Delete containing all columns of the table
20241
+ void VerifyDeleteConstraints(TableCatalogEntry &table, ClientContext &context, DataChunk &chunk);
20167
20242
 
20168
20243
  void InitializeScanWithOffset(TableScanState &state, const vector<column_t> &column_ids, idx_t start_row,
20169
20244
  idx_t end_row);
@@ -22661,8 +22736,13 @@ struct ExportedTableData {
22661
22736
  string file_path;
22662
22737
  };
22663
22738
 
22739
+ struct ExportedTableInfo {
22740
+ TableCatalogEntry *entry;
22741
+ ExportedTableData table_data;
22742
+ };
22743
+
22664
22744
  struct BoundExportData : public ParseInfo {
22665
- unordered_map<TableCatalogEntry *, ExportedTableData> data;
22745
+ std::vector<ExportedTableInfo> data;
22666
22746
  };
22667
22747
 
22668
22748
  } // namespace duckdb