duckdb 0.3.2-dev524.0 → 0.3.2-dev577.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.
Files changed (3) hide show
  1. package/package.json +1 -1
  2. package/src/duckdb.cpp +577 -3315
  3. package/src/duckdb.hpp +3588 -483
package/src/duckdb.hpp CHANGED
@@ -10,8 +10,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
10
10
 
11
11
  #pragma once
12
12
  #define DUCKDB_AMALGAMATION 1
13
- #define DUCKDB_SOURCE_ID "469e6a48f"
14
- #define DUCKDB_VERSION "0.3.2-dev524"
13
+ #define DUCKDB_SOURCE_ID "66bf4ed98"
14
+ #define DUCKDB_VERSION "0.3.2-dev577"
15
15
  //===----------------------------------------------------------------------===//
16
16
  // DuckDB
17
17
  //
@@ -586,6 +586,7 @@ class Serializer;
586
586
  class Deserializer;
587
587
  class Value;
588
588
  class TypeCatalogEntry;
589
+ class Vector;
589
590
  //! Type used to represent dates (days since 1970-01-01)
590
591
  struct date_t {
591
592
  int32_t days;
@@ -1040,7 +1041,7 @@ public:
1040
1041
  DUCKDB_API static LogicalType STRUCT( child_list_t<LogicalType> children); // NOLINT
1041
1042
  DUCKDB_API static LogicalType MAP( child_list_t<LogicalType> children); // NOLINT
1042
1043
  DUCKDB_API static LogicalType MAP(LogicalType key, LogicalType value); // NOLINT
1043
- DUCKDB_API static LogicalType ENUM(const string &enum_name, const vector<string> &ordered_data); // NOLINT
1044
+ DUCKDB_API static LogicalType ENUM(const string &enum_name, Vector &ordered_data, idx_t size); // NOLINT
1044
1045
  DUCKDB_API static LogicalType USER(const string &user_type_name); // NOLINT
1045
1046
  //! A list of all NUMERIC types (integral and floating point types)
1046
1047
  DUCKDB_API static const vector<LogicalType> NUMERIC;
@@ -1070,9 +1071,9 @@ struct UserType{
1070
1071
  struct EnumType{
1071
1072
  DUCKDB_API static const string &GetTypeName(const LogicalType &type);
1072
1073
  DUCKDB_API static int64_t GetPos(const LogicalType &type, const string& key);
1073
- DUCKDB_API static const vector<string> &GetValuesInsertOrder(const LogicalType &type);
1074
+ DUCKDB_API static Vector &GetValuesInsertOrder(const LogicalType &type);
1074
1075
  DUCKDB_API static idx_t GetSize(const LogicalType &type);
1075
- DUCKDB_API static const string& GetValue(const Value &val);
1076
+ DUCKDB_API static const string GetValue(const Value &val);
1076
1077
  DUCKDB_API static void SetCatalog(LogicalType &type, TypeCatalogEntry* catalog_entry);
1077
1078
  DUCKDB_API static TypeCatalogEntry* GetCatalog(const LogicalType &type);
1078
1079
  DUCKDB_API static PhysicalType GetPhysicalType(idx_t size);
@@ -7257,7 +7258,7 @@ public:
7257
7258
  atomic<transaction_t> timestamp;
7258
7259
  //! Child entry
7259
7260
  unique_ptr<CatalogEntry> child;
7260
- //! Parent entry (the node that owns this node)
7261
+ //! Parent entry (the node that dependents_map this node)
7261
7262
  CatalogEntry *parent;
7262
7263
 
7263
7264
  public:
@@ -7445,7 +7446,7 @@ public:
7445
7446
  DUCKDB_API CatalogEntry *CreateFunction(ClientContext &context, CreateFunctionInfo *info);
7446
7447
  //! Creates a table in the catalog.
7447
7448
  DUCKDB_API CatalogEntry *CreateView(ClientContext &context, CreateViewInfo *info);
7448
- //! Creates a table in the catalog.
7449
+ //! Creates a sequence in the catalog.
7449
7450
  DUCKDB_API CatalogEntry *CreateSequence(ClientContext &context, CreateSequenceInfo *info);
7450
7451
  //! Creates a Enum in the catalog.
7451
7452
  DUCKDB_API CatalogEntry *CreateType(ClientContext &context, CreateTypeInfo *info);
@@ -7493,6 +7494,9 @@ public:
7493
7494
  const string &name, bool if_exists = false,
7494
7495
  QueryErrorContext error_context = QueryErrorContext());
7495
7496
 
7497
+ //! Gets the "schema.name" entry without a specified type, if entry does not exist an exception is thrown
7498
+ DUCKDB_API CatalogEntry *GetEntry(ClientContext &context, const string &schema, const string &name);
7499
+
7496
7500
  template <class T>
7497
7501
  T *GetEntry(ClientContext &context, const string &schema_name, const string &name, bool if_exists = false,
7498
7502
  QueryErrorContext error_context = QueryErrorContext());
@@ -11779,6 +11783,7 @@ namespace duckdb {
11779
11783
  //! The UUID class contains static operations for the UUID type
11780
11784
  class UUID {
11781
11785
  public:
11786
+ constexpr static const uint8_t STRING_SIZE = 36;
11782
11787
  //! Convert a uuid string to a hugeint object
11783
11788
  static bool FromString(string str, hugeint_t &result);
11784
11789
  //! Convert a uuid string to a hugeint object
@@ -11790,9 +11795,9 @@ public:
11790
11795
 
11791
11796
  //! Convert a hugeint object to a uuid style string
11792
11797
  static string ToString(hugeint_t input) {
11793
- char buff[36];
11798
+ char buff[STRING_SIZE];
11794
11799
  ToString(input, buff);
11795
- return string(buff, 36);
11800
+ return string(buff, STRING_SIZE);
11796
11801
  }
11797
11802
 
11798
11803
  static hugeint_t FromString(string str) {
@@ -12422,274 +12427,42 @@ private:
12422
12427
  };
12423
12428
  } // namespace duckdb
12424
12429
 
12425
- #include <functional>
12426
- #include <memory>
12427
-
12428
- namespace duckdb {
12429
- struct AlterInfo;
12430
-
12431
- class ClientContext;
12432
-
12433
- typedef unordered_map<CatalogSet *, unique_lock<mutex>> set_lock_map_t;
12434
-
12435
- struct MappingValue {
12436
- explicit MappingValue(idx_t index_) : index(index_), timestamp(0), deleted(false), parent(nullptr) {
12437
- }
12438
-
12439
- idx_t index;
12440
- transaction_t timestamp;
12441
- bool deleted;
12442
- unique_ptr<MappingValue> child;
12443
- MappingValue *parent;
12444
- };
12445
-
12446
- //! The Catalog Set stores (key, value) map of a set of CatalogEntries
12447
- class CatalogSet {
12448
- friend class DependencyManager;
12449
-
12450
- public:
12451
- DUCKDB_API explicit CatalogSet(Catalog &catalog, unique_ptr<DefaultGenerator> defaults = nullptr);
12452
-
12453
- //! Create an entry in the catalog set. Returns whether or not it was
12454
- //! successful.
12455
- DUCKDB_API bool CreateEntry(ClientContext &context, const string &name, unique_ptr<CatalogEntry> value,
12456
- unordered_set<CatalogEntry *> &dependencies);
12457
-
12458
- DUCKDB_API bool AlterEntry(ClientContext &context, const string &name, AlterInfo *alter_info);
12459
-
12460
- DUCKDB_API bool DropEntry(ClientContext &context, const string &name, bool cascade);
12461
-
12462
- void CleanupEntry(CatalogEntry *catalog_entry);
12463
-
12464
- //! Returns the entry with the specified name
12465
- DUCKDB_API CatalogEntry *GetEntry(ClientContext &context, const string &name);
12466
-
12467
- //! Gets the entry that is most similar to the given name (i.e. smallest levenshtein distance), or empty string if
12468
- //! none is found. The returned pair consists of the entry name and the distance (smaller means closer).
12469
- pair<string, idx_t> SimilarEntry(ClientContext &context, const string &name);
12470
-
12471
- //! Rollback <entry> to be the currently valid entry for a certain catalog
12472
- //! entry
12473
- void Undo(CatalogEntry *entry);
12474
-
12475
- //! Scan the catalog set, invoking the callback method for every committed entry
12476
- DUCKDB_API void Scan(const std::function<void(CatalogEntry *)> &callback);
12477
- //! Scan the catalog set, invoking the callback method for every entry
12478
- DUCKDB_API void Scan(ClientContext &context, const std::function<void(CatalogEntry *)> &callback);
12479
-
12480
- template <class T>
12481
- vector<T *> GetEntries(ClientContext &context) {
12482
- vector<T *> result;
12483
- Scan(context, [&](CatalogEntry *entry) { result.push_back((T *)entry); });
12484
- return result;
12485
- }
12486
-
12487
- DUCKDB_API static bool HasConflict(ClientContext &context, transaction_t timestamp);
12488
- DUCKDB_API static bool UseTimestamp(ClientContext &context, transaction_t timestamp);
12489
-
12490
- CatalogEntry *GetEntryFromIndex(idx_t index);
12491
- void UpdateTimestamp(CatalogEntry *entry, transaction_t timestamp);
12492
-
12493
- private:
12494
- //! Adjusts table dependencies on the event of an UNDO
12495
- void AdjustTableDependencies(CatalogEntry *entry);
12496
- //! Adjust one dependency
12497
- void AdjustDependency(CatalogEntry *entry, TableCatalogEntry *table, ColumnDefinition &column, bool remove);
12498
- //! Adjust Enum dependency
12499
- void AdjustEnumDependency(CatalogEntry *entry, ColumnDefinition &column, bool remove);
12500
- //! Given a root entry, gets the entry valid for this transaction
12501
- CatalogEntry *GetEntryForTransaction(ClientContext &context, CatalogEntry *current);
12502
- CatalogEntry *GetCommittedEntry(CatalogEntry *current);
12503
- bool GetEntryInternal(ClientContext &context, const string &name, idx_t &entry_index, CatalogEntry *&entry);
12504
- bool GetEntryInternal(ClientContext &context, idx_t entry_index, CatalogEntry *&entry);
12505
- //! Drops an entry from the catalog set; must hold the catalog_lock to safely call this
12506
- void DropEntryInternal(ClientContext &context, idx_t entry_index, CatalogEntry &entry, bool cascade,
12507
- set_lock_map_t &lock_set);
12508
- CatalogEntry *CreateEntryInternal(ClientContext &context, unique_ptr<CatalogEntry> entry);
12509
- MappingValue *GetMapping(ClientContext &context, const string &name, bool get_latest = false);
12510
- void PutMapping(ClientContext &context, const string &name, idx_t entry_index);
12511
- void DeleteMapping(ClientContext &context, const string &name);
12512
-
12513
- private:
12514
- Catalog &catalog;
12515
- //! The catalog lock is used to make changes to the data
12516
- mutex catalog_lock;
12517
- //! Mapping of string to catalog entry
12518
- case_insensitive_map_t<unique_ptr<MappingValue>> mapping;
12519
- //! The set of catalog entries
12520
- unordered_map<idx_t, unique_ptr<CatalogEntry>> entries;
12521
- //! The current catalog entry index
12522
- idx_t current_entry = 0;
12523
- //! The generator used to generate default internal entries
12524
- unique_ptr<DefaultGenerator> defaults;
12525
- };
12526
-
12527
- } // namespace duckdb
12528
-
12529
-
12530
-
12531
- namespace duckdb {
12532
- class ClientContext;
12533
-
12534
- class StandardEntry;
12535
- class TableCatalogEntry;
12536
- class TableFunctionCatalogEntry;
12537
- class SequenceCatalogEntry;
12538
- class Serializer;
12539
- class Deserializer;
12540
-
12541
- enum class OnCreateConflict : uint8_t;
12542
-
12543
- struct AlterTableInfo;
12544
- struct CreateIndexInfo;
12545
- struct CreateFunctionInfo;
12546
- struct CreateCollationInfo;
12547
- struct CreateViewInfo;
12548
- struct BoundCreateTableInfo;
12549
- struct CreatePragmaFunctionInfo;
12550
- struct CreateSequenceInfo;
12551
- struct CreateSchemaInfo;
12552
- struct CreateTableFunctionInfo;
12553
- struct CreateCopyFunctionInfo;
12554
- struct CreateTypeInfo;
12555
-
12556
- struct DropInfo;
12557
-
12558
- //! A schema in the catalog
12559
- class SchemaCatalogEntry : public CatalogEntry {
12560
- friend class Catalog;
12561
-
12562
- public:
12563
- SchemaCatalogEntry(Catalog *catalog, string name, bool is_internal);
12564
-
12565
- private:
12566
- //! The catalog set holding the tables
12567
- CatalogSet tables;
12568
- //! The catalog set holding the indexes
12569
- CatalogSet indexes;
12570
- //! The catalog set holding the table functions
12571
- CatalogSet table_functions;
12572
- //! The catalog set holding the copy functions
12573
- CatalogSet copy_functions;
12574
- //! The catalog set holding the pragma functions
12575
- CatalogSet pragma_functions;
12576
- //! The catalog set holding the scalar and aggregate functions
12577
- CatalogSet functions;
12578
- //! The catalog set holding the sequences
12579
- CatalogSet sequences;
12580
- //! The catalog set holding the collations
12581
- CatalogSet collations;
12582
- //! The catalog set holding the types
12583
- CatalogSet types;
12584
-
12585
- public:
12586
- //! Scan the specified catalog set, invoking the callback method for every entry
12587
- void Scan(ClientContext &context, CatalogType type, const std::function<void(CatalogEntry *)> &callback);
12588
- //! Scan the specified catalog set, invoking the callback method for every committed entry
12589
- void Scan(CatalogType type, const std::function<void(CatalogEntry *)> &callback);
12590
-
12591
- //! Serialize the meta information of the SchemaCatalogEntry a serializer
12592
- virtual void Serialize(Serializer &serializer);
12593
- //! Deserializes to a CreateSchemaInfo
12594
- static unique_ptr<CreateSchemaInfo> Deserialize(Deserializer &source);
12595
-
12596
- string ToSQL() override;
12597
-
12598
- //! Creates an index with the given name in the schema
12599
- CatalogEntry *CreateIndex(ClientContext &context, CreateIndexInfo *info, TableCatalogEntry *table);
12600
-
12601
- private:
12602
- //! Create a scalar or aggregate function within the given schema
12603
- CatalogEntry *CreateFunction(ClientContext &context, CreateFunctionInfo *info);
12604
- //! Creates a table with the given name in the schema
12605
- CatalogEntry *CreateTable(ClientContext &context, BoundCreateTableInfo *info);
12606
- //! Creates a view with the given name in the schema
12607
- CatalogEntry *CreateView(ClientContext &context, CreateViewInfo *info);
12608
- //! Creates a sequence with the given name in the schema
12609
- CatalogEntry *CreateSequence(ClientContext &context, CreateSequenceInfo *info);
12610
- //! Create a table function within the given schema
12611
- CatalogEntry *CreateTableFunction(ClientContext &context, CreateTableFunctionInfo *info);
12612
- //! Create a copy function within the given schema
12613
- CatalogEntry *CreateCopyFunction(ClientContext &context, CreateCopyFunctionInfo *info);
12614
- //! Create a pragma function within the given schema
12615
- CatalogEntry *CreatePragmaFunction(ClientContext &context, CreatePragmaFunctionInfo *info);
12616
- //! Create a collation within the given schema
12617
- CatalogEntry *CreateCollation(ClientContext &context, CreateCollationInfo *info);
12618
- //! Create a enum within the given schema
12619
- CatalogEntry *CreateType(ClientContext &context, CreateTypeInfo *info);
12620
-
12621
- //! Drops an entry from the schema
12622
- void DropEntry(ClientContext &context, DropInfo *info);
12623
-
12624
- //! Append a scalar or aggregate function within the given schema
12625
- CatalogEntry *AddFunction(ClientContext &context, CreateFunctionInfo *info);
12626
-
12627
- //! Alters a catalog entry
12628
- void Alter(ClientContext &context, AlterInfo *info);
12629
-
12630
- //! Add a catalog entry to this schema
12631
- CatalogEntry *AddEntry(ClientContext &context, unique_ptr<StandardEntry> entry, OnCreateConflict on_conflict);
12632
- //! Add a catalog entry to this schema
12633
- CatalogEntry *AddEntry(ClientContext &context, unique_ptr<StandardEntry> entry, OnCreateConflict on_conflict,
12634
- unordered_set<CatalogEntry *> dependencies);
12635
-
12636
- //! Get the catalog set for the specified type
12637
- CatalogSet &GetCatalogSet(CatalogType type);
12638
- };
12639
- } // namespace duckdb
12640
-
12641
-
12642
12430
  //===----------------------------------------------------------------------===//
12643
12431
  // DuckDB
12644
12432
  //
12645
- // duckdb/common/deque.hpp
12433
+ // duckdb/catalog/catalog_entry/sequence_catalog_entry.hpp
12646
12434
  //
12647
12435
  //
12648
12436
  //===----------------------------------------------------------------------===//
12649
12437
 
12650
12438
 
12651
12439
 
12652
- #include <deque>
12653
12440
 
12654
- namespace duckdb {
12655
- using std::deque;
12656
- }
12657
12441
 
12658
12442
  //===----------------------------------------------------------------------===//
12659
12443
  // DuckDB
12660
12444
  //
12661
- // duckdb/common/progress_bar.hpp
12445
+ // duckdb/parser/parsed_data/create_sequence_info.hpp
12662
12446
  //
12663
12447
  //
12664
12448
  //===----------------------------------------------------------------------===//
12665
12449
 
12666
12450
 
12667
12451
 
12668
- #ifndef DUCKDB_NO_THREADS
12669
12452
  //===----------------------------------------------------------------------===//
12670
12453
  // DuckDB
12671
12454
  //
12672
- // duckdb/common/thread.hpp
12455
+ // duckdb/parser/parsed_data/create_info.hpp
12673
12456
  //
12674
12457
  //
12675
12458
  //===----------------------------------------------------------------------===//
12676
12459
 
12677
12460
 
12678
12461
 
12679
- #include <thread>
12680
-
12681
- namespace duckdb {
12682
- using std::thread;
12683
- }
12684
-
12685
- #include <future>
12686
- #endif
12687
-
12688
-
12689
12462
  //===----------------------------------------------------------------------===//
12690
12463
  // DuckDB
12691
12464
  //
12692
- // duckdb/execution/executor.hpp
12465
+ // duckdb/parser/parsed_data/parse_info.hpp
12693
12466
  //
12694
12467
  //
12695
12468
  //===----------------------------------------------------------------------===//
@@ -12698,21 +12471,3580 @@ using std::thread;
12698
12471
 
12699
12472
 
12700
12473
 
12701
- //===----------------------------------------------------------------------===//
12702
- // DuckDB
12703
- //
12704
- // duckdb/parallel/pipeline.hpp
12705
- //
12706
- //
12707
- //===----------------------------------------------------------------------===//
12474
+ namespace duckdb {
12708
12475
 
12476
+ struct ParseInfo {
12477
+ virtual ~ParseInfo() {
12478
+ }
12479
+ };
12709
12480
 
12481
+ } // namespace duckdb
12710
12482
 
12711
12483
 
12712
- //===----------------------------------------------------------------------===//
12713
- // DuckDB
12714
- //
12715
- // duckdb/execution/physical_operator.hpp
12484
+
12485
+ namespace duckdb {
12486
+
12487
+ enum class OnCreateConflict : uint8_t {
12488
+ // Standard: throw error
12489
+ ERROR_ON_CONFLICT,
12490
+ // CREATE IF NOT EXISTS, silently do nothing on conflict
12491
+ IGNORE_ON_CONFLICT,
12492
+ // CREATE OR REPLACE
12493
+ REPLACE_ON_CONFLICT
12494
+ };
12495
+
12496
+ struct CreateInfo : public ParseInfo {
12497
+ explicit CreateInfo(CatalogType type, string schema = DEFAULT_SCHEMA)
12498
+ : type(type), schema(schema), on_conflict(OnCreateConflict::ERROR_ON_CONFLICT), temporary(false),
12499
+ internal(false) {
12500
+ }
12501
+ ~CreateInfo() override {
12502
+ }
12503
+
12504
+ //! The to-be-created catalog type
12505
+ CatalogType type;
12506
+ //! The schema name of the entry
12507
+ string schema;
12508
+ //! What to do on create conflict
12509
+ OnCreateConflict on_conflict;
12510
+ //! Whether or not the entry is temporary
12511
+ bool temporary;
12512
+ //! Whether or not the entry is an internal entry
12513
+ bool internal;
12514
+ //! The SQL string of the CREATE statement
12515
+ string sql;
12516
+
12517
+ public:
12518
+ virtual unique_ptr<CreateInfo> Copy() const = 0;
12519
+ void CopyProperties(CreateInfo &other) const {
12520
+ other.type = type;
12521
+ other.schema = schema;
12522
+ other.on_conflict = on_conflict;
12523
+ other.temporary = temporary;
12524
+ other.internal = internal;
12525
+ other.sql = sql;
12526
+ }
12527
+ };
12528
+
12529
+ } // namespace duckdb
12530
+
12531
+
12532
+
12533
+ namespace duckdb {
12534
+
12535
+ struct CreateSequenceInfo : public CreateInfo {
12536
+ CreateSequenceInfo()
12537
+ : CreateInfo(CatalogType::SEQUENCE_ENTRY, INVALID_SCHEMA), name(string()), usage_count(0), increment(1),
12538
+ min_value(1), max_value(NumericLimits<int64_t>::Maximum()), start_value(1), cycle(false) {
12539
+ }
12540
+
12541
+ //! Sequence name to create
12542
+ string name;
12543
+ //! Usage count of the sequence
12544
+ uint64_t usage_count;
12545
+ //! The increment value
12546
+ int64_t increment;
12547
+ //! The minimum value of the sequence
12548
+ int64_t min_value;
12549
+ //! The maximum value of the sequence
12550
+ int64_t max_value;
12551
+ //! The start value of the sequence
12552
+ int64_t start_value;
12553
+ //! Whether or not the sequence cycles
12554
+ bool cycle;
12555
+
12556
+ public:
12557
+ unique_ptr<CreateInfo> Copy() const override {
12558
+ auto result = make_unique<CreateSequenceInfo>();
12559
+ CopyProperties(*result);
12560
+ result->name = name;
12561
+ result->schema = schema;
12562
+ result->usage_count = usage_count;
12563
+ result->increment = increment;
12564
+ result->min_value = min_value;
12565
+ result->max_value = max_value;
12566
+ result->start_value = start_value;
12567
+ result->cycle = cycle;
12568
+ return move(result);
12569
+ }
12570
+ };
12571
+
12572
+ } // namespace duckdb
12573
+
12574
+ //===----------------------------------------------------------------------===//
12575
+ // DuckDB
12576
+ //
12577
+ // duckdb/parser/parsed_data/alter_table_info.hpp
12578
+ //
12579
+ //
12580
+ //===----------------------------------------------------------------------===//
12581
+
12582
+
12583
+
12584
+
12585
+
12586
+
12587
+
12588
+ namespace duckdb {
12589
+
12590
+ enum class AlterType : uint8_t {
12591
+ INVALID = 0,
12592
+ ALTER_TABLE = 1,
12593
+ ALTER_VIEW = 2,
12594
+ ALTER_SEQUENCE = 3,
12595
+ CHANGE_OWNERSHIP = 4
12596
+ };
12597
+
12598
+ struct AlterInfo : public ParseInfo {
12599
+ AlterInfo(AlterType type, string schema, string name) : type(type), schema(move(schema)), name(move(name)) {
12600
+ }
12601
+ ~AlterInfo() override {
12602
+ }
12603
+
12604
+ AlterType type;
12605
+ //! Schema name to alter
12606
+ string schema;
12607
+ //! Entry name to alter
12608
+ string name;
12609
+
12610
+ public:
12611
+ virtual CatalogType GetCatalogType() = 0;
12612
+ virtual unique_ptr<AlterInfo> Copy() const = 0;
12613
+ virtual void Serialize(Serializer &serializer);
12614
+ static unique_ptr<AlterInfo> Deserialize(Deserializer &source);
12615
+ };
12616
+
12617
+ //===--------------------------------------------------------------------===//
12618
+ // Change Ownership
12619
+ //===--------------------------------------------------------------------===//
12620
+ struct ChangeOwnershipInfo : public AlterInfo {
12621
+ ChangeOwnershipInfo(CatalogType entry_catalog_type, string entry_schema, string entry_name, string owner_schema,
12622
+ string owner_name)
12623
+ : AlterInfo(AlterType::CHANGE_OWNERSHIP, entry_schema, entry_name), entry_catalog_type(entry_catalog_type),
12624
+ owner_schema(owner_schema), owner_name(owner_name) {
12625
+ }
12626
+
12627
+ // Catalog type refers to the entry type, since this struct is usually built from an
12628
+ // ALTER <TYPE> <schema>.<name> OWNED BY <owner_schema>.<owner_name> statement
12629
+ // here it is only possible to know the type of who is to be owned
12630
+ CatalogType entry_catalog_type;
12631
+
12632
+ string owner_schema;
12633
+ string owner_name;
12634
+
12635
+ public:
12636
+ CatalogType GetCatalogType() override;
12637
+ unique_ptr<AlterInfo> Copy() const override;
12638
+ };
12639
+
12640
+ //===--------------------------------------------------------------------===//
12641
+ // Alter Table
12642
+ //===--------------------------------------------------------------------===//
12643
+ enum class AlterTableType : uint8_t {
12644
+ INVALID = 0,
12645
+ RENAME_COLUMN = 1,
12646
+ RENAME_TABLE = 2,
12647
+ ADD_COLUMN = 3,
12648
+ REMOVE_COLUMN = 4,
12649
+ ALTER_COLUMN_TYPE = 5,
12650
+ SET_DEFAULT = 6
12651
+ };
12652
+
12653
+ struct AlterTableInfo : public AlterInfo {
12654
+ AlterTableInfo(AlterTableType type, string schema, string table)
12655
+ : AlterInfo(AlterType::ALTER_TABLE, schema, table), alter_table_type(type) {
12656
+ }
12657
+ ~AlterTableInfo() override {
12658
+ }
12659
+
12660
+ AlterTableType alter_table_type;
12661
+
12662
+ public:
12663
+ CatalogType GetCatalogType() override {
12664
+ return CatalogType::TABLE_ENTRY;
12665
+ }
12666
+ void Serialize(Serializer &serializer) override;
12667
+ static unique_ptr<AlterInfo> Deserialize(Deserializer &source);
12668
+ };
12669
+
12670
+ //===--------------------------------------------------------------------===//
12671
+ // RenameColumnInfo
12672
+ //===--------------------------------------------------------------------===//
12673
+ struct RenameColumnInfo : public AlterTableInfo {
12674
+ RenameColumnInfo(string schema, string table, string old_name_p, string new_name_p)
12675
+ : AlterTableInfo(AlterTableType::RENAME_COLUMN, move(schema), move(table)), old_name(move(old_name_p)),
12676
+ new_name(move(new_name_p)) {
12677
+ }
12678
+ ~RenameColumnInfo() override {
12679
+ }
12680
+
12681
+ //! Column old name
12682
+ string old_name;
12683
+ //! Column new name
12684
+ string new_name;
12685
+
12686
+ public:
12687
+ unique_ptr<AlterInfo> Copy() const override;
12688
+ void Serialize(Serializer &serializer) override;
12689
+ static unique_ptr<AlterInfo> Deserialize(Deserializer &source, string schema, string table);
12690
+ };
12691
+
12692
+ //===--------------------------------------------------------------------===//
12693
+ // RenameTableInfo
12694
+ //===--------------------------------------------------------------------===//
12695
+ struct RenameTableInfo : public AlterTableInfo {
12696
+ RenameTableInfo(string schema, string table, string new_name)
12697
+ : AlterTableInfo(AlterTableType::RENAME_TABLE, schema, table), new_table_name(new_name) {
12698
+ }
12699
+ ~RenameTableInfo() override {
12700
+ }
12701
+
12702
+ //! Relation new name
12703
+ string new_table_name;
12704
+
12705
+ public:
12706
+ unique_ptr<AlterInfo> Copy() const override;
12707
+ void Serialize(Serializer &serializer) override;
12708
+ static unique_ptr<AlterInfo> Deserialize(Deserializer &source, string schema, string table);
12709
+ };
12710
+
12711
+ //===--------------------------------------------------------------------===//
12712
+ // AddColumnInfo
12713
+ //===--------------------------------------------------------------------===//
12714
+ struct AddColumnInfo : public AlterTableInfo {
12715
+ AddColumnInfo(string schema, string table, ColumnDefinition new_column)
12716
+ : AlterTableInfo(AlterTableType::ADD_COLUMN, schema, table), new_column(move(new_column)) {
12717
+ }
12718
+ ~AddColumnInfo() override {
12719
+ }
12720
+
12721
+ //! New column
12722
+ ColumnDefinition new_column;
12723
+
12724
+ public:
12725
+ unique_ptr<AlterInfo> Copy() const override;
12726
+ void Serialize(Serializer &serializer) override;
12727
+ static unique_ptr<AlterInfo> Deserialize(Deserializer &source, string schema, string table);
12728
+ };
12729
+
12730
+ //===--------------------------------------------------------------------===//
12731
+ // RemoveColumnInfo
12732
+ //===--------------------------------------------------------------------===//
12733
+ struct RemoveColumnInfo : public AlterTableInfo {
12734
+ RemoveColumnInfo(string schema, string table, string removed_column, bool if_exists)
12735
+ : AlterTableInfo(AlterTableType::REMOVE_COLUMN, schema, table), removed_column(move(removed_column)),
12736
+ if_exists(if_exists) {
12737
+ }
12738
+ ~RemoveColumnInfo() override {
12739
+ }
12740
+
12741
+ //! The column to remove
12742
+ string removed_column;
12743
+ //! Whether or not an error should be thrown if the column does not exist
12744
+ bool if_exists;
12745
+
12746
+ public:
12747
+ unique_ptr<AlterInfo> Copy() const override;
12748
+ void Serialize(Serializer &serializer) override;
12749
+ static unique_ptr<AlterInfo> Deserialize(Deserializer &source, string schema, string table);
12750
+ };
12751
+
12752
+ //===--------------------------------------------------------------------===//
12753
+ // ChangeColumnTypeInfo
12754
+ //===--------------------------------------------------------------------===//
12755
+ struct ChangeColumnTypeInfo : public AlterTableInfo {
12756
+ ChangeColumnTypeInfo(string schema, string table, string column_name, LogicalType target_type,
12757
+ unique_ptr<ParsedExpression> expression)
12758
+ : AlterTableInfo(AlterTableType::ALTER_COLUMN_TYPE, schema, table), column_name(move(column_name)),
12759
+ target_type(move(target_type)), expression(move(expression)) {
12760
+ }
12761
+ ~ChangeColumnTypeInfo() override {
12762
+ }
12763
+
12764
+ //! The column name to alter
12765
+ string column_name;
12766
+ //! The target type of the column
12767
+ LogicalType target_type;
12768
+ //! The expression used for data conversion
12769
+ unique_ptr<ParsedExpression> expression;
12770
+
12771
+ public:
12772
+ unique_ptr<AlterInfo> Copy() const override;
12773
+ void Serialize(Serializer &serializer) override;
12774
+ static unique_ptr<AlterInfo> Deserialize(Deserializer &source, string schema, string table);
12775
+ };
12776
+
12777
+ //===--------------------------------------------------------------------===//
12778
+ // SetDefaultInfo
12779
+ //===--------------------------------------------------------------------===//
12780
+ struct SetDefaultInfo : public AlterTableInfo {
12781
+ SetDefaultInfo(string schema, string table, string column_name, unique_ptr<ParsedExpression> new_default)
12782
+ : AlterTableInfo(AlterTableType::SET_DEFAULT, schema, table), column_name(move(column_name)),
12783
+ expression(move(new_default)) {
12784
+ }
12785
+ ~SetDefaultInfo() override {
12786
+ }
12787
+
12788
+ //! The column name to alter
12789
+ string column_name;
12790
+ //! The expression used for data conversion
12791
+ unique_ptr<ParsedExpression> expression;
12792
+
12793
+ public:
12794
+ unique_ptr<AlterInfo> Copy() const override;
12795
+ void Serialize(Serializer &serializer) override;
12796
+ static unique_ptr<AlterInfo> Deserialize(Deserializer &source, string schema, string table);
12797
+ };
12798
+
12799
+ //===--------------------------------------------------------------------===//
12800
+ // Alter View
12801
+ //===--------------------------------------------------------------------===//
12802
+ enum class AlterViewType : uint8_t { INVALID = 0, RENAME_VIEW = 1 };
12803
+
12804
+ struct AlterViewInfo : public AlterInfo {
12805
+ AlterViewInfo(AlterViewType type, string schema, string view)
12806
+ : AlterInfo(AlterType::ALTER_VIEW, schema, view), alter_view_type(type) {
12807
+ }
12808
+ ~AlterViewInfo() override {
12809
+ }
12810
+
12811
+ AlterViewType alter_view_type;
12812
+
12813
+ public:
12814
+ CatalogType GetCatalogType() override {
12815
+ return CatalogType::VIEW_ENTRY;
12816
+ }
12817
+ void Serialize(Serializer &serializer) override;
12818
+ static unique_ptr<AlterInfo> Deserialize(Deserializer &source);
12819
+ };
12820
+
12821
+ //===--------------------------------------------------------------------===//
12822
+ // RenameViewInfo
12823
+ //===--------------------------------------------------------------------===//
12824
+ struct RenameViewInfo : public AlterViewInfo {
12825
+ RenameViewInfo(string schema, string view, string new_name)
12826
+ : AlterViewInfo(AlterViewType::RENAME_VIEW, schema, view), new_view_name(new_name) {
12827
+ }
12828
+ ~RenameViewInfo() override {
12829
+ }
12830
+
12831
+ //! Relation new name
12832
+ string new_view_name;
12833
+
12834
+ public:
12835
+ unique_ptr<AlterInfo> Copy() const override;
12836
+ void Serialize(Serializer &serializer) override;
12837
+ static unique_ptr<AlterInfo> Deserialize(Deserializer &source, string schema, string table);
12838
+ };
12839
+
12840
+ } // namespace duckdb
12841
+
12842
+
12843
+ namespace duckdb {
12844
+ class Serializer;
12845
+ class Deserializer;
12846
+
12847
+ struct SequenceValue {
12848
+ SequenceValue() : usage_count(0), counter(-1) {
12849
+ }
12850
+ SequenceValue(uint64_t usage_count, int64_t counter) : usage_count(usage_count), counter(counter) {
12851
+ }
12852
+
12853
+ uint64_t usage_count;
12854
+ int64_t counter;
12855
+ };
12856
+
12857
+ //! A sequence catalog entry
12858
+ class SequenceCatalogEntry : public StandardEntry {
12859
+ public:
12860
+ //! Create a real TableCatalogEntry and initialize storage for it
12861
+ SequenceCatalogEntry(Catalog *catalog, SchemaCatalogEntry *schema, CreateSequenceInfo *info);
12862
+
12863
+ //! Lock for getting a value on the sequence
12864
+ mutex lock;
12865
+ //! The amount of times the sequence has been used
12866
+ uint64_t usage_count;
12867
+ //! The sequence counter
12868
+ int64_t counter;
12869
+ //! The most recently returned value
12870
+ int64_t last_value;
12871
+ //! The increment value
12872
+ int64_t increment;
12873
+ //! The minimum value of the sequence
12874
+ int64_t start_value;
12875
+ //! The minimum value of the sequence
12876
+ int64_t min_value;
12877
+ //! The maximum value of the sequence
12878
+ int64_t max_value;
12879
+ //! Whether or not the sequence cycles
12880
+ bool cycle;
12881
+
12882
+ public:
12883
+ //! Serialize the meta information of the SequenceCatalogEntry a serializer
12884
+ virtual void Serialize(Serializer &serializer);
12885
+ //! Deserializes to a CreateTableInfo
12886
+ static unique_ptr<CreateSequenceInfo> Deserialize(Deserializer &source);
12887
+
12888
+ string ToSQL() override;
12889
+
12890
+ CatalogEntry *AlterOwnership(ClientContext &context, AlterInfo *info);
12891
+ };
12892
+ } // namespace duckdb
12893
+
12894
+ //===----------------------------------------------------------------------===//
12895
+ // DuckDB
12896
+ //
12897
+ // duckdb/transaction/transaction.hpp
12898
+ //
12899
+ //
12900
+ //===----------------------------------------------------------------------===//
12901
+
12902
+
12903
+
12904
+
12905
+
12906
+
12907
+ //===----------------------------------------------------------------------===//
12908
+ // DuckDB
12909
+ //
12910
+ // duckdb/transaction/undo_buffer.hpp
12911
+ //
12912
+ //
12913
+ //===----------------------------------------------------------------------===//
12914
+
12915
+
12916
+
12917
+
12918
+ //===----------------------------------------------------------------------===//
12919
+ // DuckDB
12920
+ //
12921
+ // duckdb/common/enums/undo_flags.hpp
12922
+ //
12923
+ //
12924
+ //===----------------------------------------------------------------------===//
12925
+
12926
+
12927
+
12928
+
12929
+
12930
+ namespace duckdb {
12931
+
12932
+ enum class UndoFlags : uint32_t { // far to big but aligned (TM)
12933
+ EMPTY_ENTRY = 0,
12934
+ CATALOG_ENTRY = 1,
12935
+ INSERT_TUPLE = 2,
12936
+ DELETE_TUPLE = 3,
12937
+ UPDATE_TUPLE = 4
12938
+ };
12939
+
12940
+ } // namespace duckdb
12941
+
12942
+
12943
+ namespace duckdb {
12944
+
12945
+ class WriteAheadLog;
12946
+
12947
+ struct UndoChunk {
12948
+ explicit UndoChunk(idx_t size);
12949
+ ~UndoChunk();
12950
+
12951
+ data_ptr_t WriteEntry(UndoFlags type, uint32_t len);
12952
+
12953
+ unique_ptr<data_t[]> data;
12954
+ idx_t current_position;
12955
+ idx_t maximum_size;
12956
+ unique_ptr<UndoChunk> next;
12957
+ UndoChunk *prev;
12958
+ };
12959
+
12960
+ //! The undo buffer of a transaction is used to hold previous versions of tuples
12961
+ //! that might be required in the future (because of rollbacks or previous
12962
+ //! transactions accessing them)
12963
+ class UndoBuffer {
12964
+ public:
12965
+ struct IteratorState {
12966
+ UndoChunk *current;
12967
+ data_ptr_t start;
12968
+ data_ptr_t end;
12969
+ };
12970
+
12971
+ public:
12972
+ UndoBuffer();
12973
+
12974
+ //! Reserve space for an entry of the specified type and length in the undo
12975
+ //! buffer
12976
+ data_ptr_t CreateEntry(UndoFlags type, idx_t len);
12977
+
12978
+ bool ChangesMade();
12979
+ idx_t EstimatedSize();
12980
+
12981
+ //! Cleanup the undo buffer
12982
+ void Cleanup();
12983
+ //! Commit the changes made in the UndoBuffer: should be called on commit
12984
+ void Commit(UndoBuffer::IteratorState &iterator_state, WriteAheadLog *log, transaction_t commit_id);
12985
+ //! Revert committed changes made in the UndoBuffer up until the currently committed state
12986
+ void RevertCommit(UndoBuffer::IteratorState &iterator_state, transaction_t transaction_id);
12987
+ //! Rollback the changes made in this UndoBuffer: should be called on
12988
+ //! rollback
12989
+ void Rollback() noexcept;
12990
+
12991
+ private:
12992
+ unique_ptr<UndoChunk> head;
12993
+ UndoChunk *tail;
12994
+
12995
+ private:
12996
+ template <class T>
12997
+ void IterateEntries(UndoBuffer::IteratorState &state, T &&callback);
12998
+ template <class T>
12999
+ void IterateEntries(UndoBuffer::IteratorState &state, UndoBuffer::IteratorState &end_state, T &&callback);
13000
+ template <class T>
13001
+ void ReverseIterateEntries(T &&callback);
13002
+ };
13003
+
13004
+ } // namespace duckdb
13005
+
13006
+ //===----------------------------------------------------------------------===//
13007
+ // DuckDB
13008
+ //
13009
+ // duckdb/transaction/local_storage.hpp
13010
+ //
13011
+ //
13012
+ //===----------------------------------------------------------------------===//
13013
+
13014
+
13015
+
13016
+
13017
+ //===----------------------------------------------------------------------===//
13018
+ // DuckDB
13019
+ //
13020
+ // duckdb/storage/table/scan_state.hpp
13021
+ //
13022
+ //
13023
+ //===----------------------------------------------------------------------===//
13024
+
13025
+
13026
+
13027
+
13028
+ //===----------------------------------------------------------------------===//
13029
+ // DuckDB
13030
+ //
13031
+ // duckdb/storage/buffer/buffer_handle.hpp
13032
+ //
13033
+ //
13034
+ //===----------------------------------------------------------------------===//
13035
+
13036
+
13037
+
13038
+ //===----------------------------------------------------------------------===//
13039
+ // DuckDB
13040
+ //
13041
+ // duckdb/storage/storage_info.hpp
13042
+ //
13043
+ //
13044
+ //===----------------------------------------------------------------------===//
13045
+
13046
+
13047
+
13048
+
13049
+
13050
+ namespace duckdb {
13051
+ class Serializer;
13052
+ class Deserializer;
13053
+ struct FileHandle;
13054
+
13055
+ //! The version number of the database storage format
13056
+ extern const uint64_t VERSION_NUMBER;
13057
+
13058
+ using block_id_t = int64_t;
13059
+
13060
+ #define INVALID_BLOCK (-1)
13061
+
13062
+ // maximum block id, 2^62
13063
+ #define MAXIMUM_BLOCK 4611686018427388000LL
13064
+
13065
+ //! The MainHeader is the first header in the storage file. The MainHeader is typically written only once for a database
13066
+ //! file.
13067
+ struct MainHeader {
13068
+ static constexpr idx_t MAGIC_BYTE_SIZE = 4;
13069
+ static constexpr idx_t MAGIC_BYTE_OFFSET = sizeof(uint64_t);
13070
+ static constexpr idx_t FLAG_COUNT = 4;
13071
+ // the magic bytes in front of the file
13072
+ // should be "DUCK"
13073
+ static const char MAGIC_BYTES[];
13074
+ //! The version of the database
13075
+ uint64_t version_number;
13076
+ //! The set of flags used by the database
13077
+ uint64_t flags[FLAG_COUNT];
13078
+
13079
+ static void CheckMagicBytes(FileHandle &handle);
13080
+
13081
+ void Serialize(Serializer &ser);
13082
+ static MainHeader Deserialize(Deserializer &source);
13083
+ };
13084
+
13085
+ //! The DatabaseHeader contains information about the current state of the database. Every storage file has two
13086
+ //! DatabaseHeaders. On startup, the DatabaseHeader with the highest iteration count is used as the active header. When
13087
+ //! a checkpoint is performed, the active DatabaseHeader is switched by increasing the iteration count of the
13088
+ //! DatabaseHeader.
13089
+ struct DatabaseHeader {
13090
+ //! The iteration count, increases by 1 every time the storage is checkpointed.
13091
+ uint64_t iteration;
13092
+ //! A pointer to the initial meta block
13093
+ block_id_t meta_block;
13094
+ //! A pointer to the block containing the free list
13095
+ block_id_t free_list;
13096
+ //! The number of blocks that is in the file as of this database header. If the file is larger than BLOCK_SIZE *
13097
+ //! block_count any blocks appearing AFTER block_count are implicitly part of the free_list.
13098
+ uint64_t block_count;
13099
+
13100
+ void Serialize(Serializer &ser);
13101
+ static DatabaseHeader Deserialize(Deserializer &source);
13102
+ };
13103
+
13104
+ } // namespace duckdb
13105
+
13106
+
13107
+ namespace duckdb {
13108
+ class BlockHandle;
13109
+ class FileBuffer;
13110
+
13111
+ class BufferHandle {
13112
+ public:
13113
+ BufferHandle(shared_ptr<BlockHandle> handle, FileBuffer *node);
13114
+ ~BufferHandle();
13115
+
13116
+ //! The block handle
13117
+ shared_ptr<BlockHandle> handle;
13118
+ //! The managed buffer node
13119
+ FileBuffer *node;
13120
+ data_ptr_t Ptr();
13121
+ };
13122
+
13123
+ } // namespace duckdb
13124
+
13125
+ //===----------------------------------------------------------------------===//
13126
+ // DuckDB
13127
+ //
13128
+ // duckdb/storage/storage_lock.hpp
13129
+ //
13130
+ //
13131
+ //===----------------------------------------------------------------------===//
13132
+
13133
+
13134
+
13135
+
13136
+
13137
+
13138
+
13139
+ namespace duckdb {
13140
+ class StorageLock;
13141
+
13142
+ enum class StorageLockType { SHARED = 0, EXCLUSIVE = 1 };
13143
+
13144
+ class StorageLockKey {
13145
+ public:
13146
+ StorageLockKey(StorageLock &lock, StorageLockType type);
13147
+ ~StorageLockKey();
13148
+
13149
+ private:
13150
+ StorageLock &lock;
13151
+ StorageLockType type;
13152
+ };
13153
+
13154
+ class StorageLock {
13155
+ friend class StorageLockKey;
13156
+
13157
+ public:
13158
+ StorageLock();
13159
+
13160
+ //! Get an exclusive lock
13161
+ unique_ptr<StorageLockKey> GetExclusiveLock();
13162
+ //! Get a shared lock
13163
+ unique_ptr<StorageLockKey> GetSharedLock();
13164
+
13165
+ private:
13166
+ mutex exclusive_lock;
13167
+ atomic<idx_t> read_count;
13168
+
13169
+ private:
13170
+ //! Release an exclusive lock
13171
+ void ReleaseExclusiveLock();
13172
+ //! Release a shared lock
13173
+ void ReleaseSharedLock();
13174
+ };
13175
+
13176
+ } // namespace duckdb
13177
+
13178
+
13179
+ //===----------------------------------------------------------------------===//
13180
+ // DuckDB
13181
+ //
13182
+ // duckdb/execution/adaptive_filter.hpp
13183
+ //
13184
+ //
13185
+ //===----------------------------------------------------------------------===//
13186
+
13187
+
13188
+
13189
+ //===----------------------------------------------------------------------===//
13190
+ // DuckDB
13191
+ //
13192
+ // duckdb/planner/expression/bound_aggregate_expression.hpp
13193
+ //
13194
+ //
13195
+ //===----------------------------------------------------------------------===//
13196
+
13197
+
13198
+
13199
+
13200
+
13201
+ #include <memory>
13202
+
13203
+ namespace duckdb {
13204
+ class BoundAggregateExpression : public Expression {
13205
+ public:
13206
+ BoundAggregateExpression(AggregateFunction function, vector<unique_ptr<Expression>> children,
13207
+ unique_ptr<Expression> filter, unique_ptr<FunctionData> bind_info, bool distinct);
13208
+
13209
+ //! The bound function expression
13210
+ AggregateFunction function;
13211
+ //! List of arguments to the function
13212
+ vector<unique_ptr<Expression>> children;
13213
+ //! The bound function data (if any)
13214
+ unique_ptr<FunctionData> bind_info;
13215
+ //! True to aggregate on distinct values
13216
+ bool distinct;
13217
+
13218
+ //! Filter for this aggregate
13219
+ unique_ptr<Expression> filter;
13220
+
13221
+ public:
13222
+ bool IsAggregate() const override {
13223
+ return true;
13224
+ }
13225
+ bool IsFoldable() const override {
13226
+ return false;
13227
+ }
13228
+
13229
+ string ToString() const override;
13230
+
13231
+ hash_t Hash() const override;
13232
+ bool Equals(const BaseExpression *other) const override;
13233
+ unique_ptr<Expression> Copy() override;
13234
+ };
13235
+ } // namespace duckdb
13236
+
13237
+ //===----------------------------------------------------------------------===//
13238
+ // DuckDB
13239
+ //
13240
+ // duckdb/planner/expression/bound_between_expression.hpp
13241
+ //
13242
+ //
13243
+ //===----------------------------------------------------------------------===//
13244
+
13245
+
13246
+
13247
+
13248
+
13249
+ namespace duckdb {
13250
+
13251
+ class BoundBetweenExpression : public Expression {
13252
+ public:
13253
+ BoundBetweenExpression(unique_ptr<Expression> input, unique_ptr<Expression> lower, unique_ptr<Expression> upper,
13254
+ bool lower_inclusive, bool upper_inclusive);
13255
+
13256
+ unique_ptr<Expression> input;
13257
+ unique_ptr<Expression> lower;
13258
+ unique_ptr<Expression> upper;
13259
+ bool lower_inclusive;
13260
+ bool upper_inclusive;
13261
+
13262
+ public:
13263
+ string ToString() const override;
13264
+
13265
+ bool Equals(const BaseExpression *other) const override;
13266
+
13267
+ unique_ptr<Expression> Copy() override;
13268
+
13269
+ public:
13270
+ ExpressionType LowerComparisonType() {
13271
+ return lower_inclusive ? ExpressionType::COMPARE_GREATERTHANOREQUALTO : ExpressionType::COMPARE_GREATERTHAN;
13272
+ }
13273
+ ExpressionType UpperComparisonType() {
13274
+ return upper_inclusive ? ExpressionType::COMPARE_LESSTHANOREQUALTO : ExpressionType::COMPARE_LESSTHAN;
13275
+ }
13276
+ };
13277
+ } // namespace duckdb
13278
+
13279
+ //===----------------------------------------------------------------------===//
13280
+ // DuckDB
13281
+ //
13282
+ // duckdb/planner/expression/bound_case_expression.hpp
13283
+ //
13284
+ //
13285
+ //===----------------------------------------------------------------------===//
13286
+
13287
+
13288
+
13289
+
13290
+
13291
+ namespace duckdb {
13292
+
13293
+ struct BoundCaseCheck {
13294
+ unique_ptr<Expression> when_expr;
13295
+ unique_ptr<Expression> then_expr;
13296
+ };
13297
+
13298
+ class BoundCaseExpression : public Expression {
13299
+ public:
13300
+ BoundCaseExpression(LogicalType type);
13301
+ BoundCaseExpression(unique_ptr<Expression> when_expr, unique_ptr<Expression> then_expr,
13302
+ unique_ptr<Expression> else_expr);
13303
+
13304
+ vector<BoundCaseCheck> case_checks;
13305
+ unique_ptr<Expression> else_expr;
13306
+
13307
+ public:
13308
+ string ToString() const override;
13309
+
13310
+ bool Equals(const BaseExpression *other) const override;
13311
+
13312
+ unique_ptr<Expression> Copy() override;
13313
+ };
13314
+ } // namespace duckdb
13315
+
13316
+ //===----------------------------------------------------------------------===//
13317
+ // DuckDB
13318
+ //
13319
+ // duckdb/planner/expression/bound_cast_expression.hpp
13320
+ //
13321
+ //
13322
+ //===----------------------------------------------------------------------===//
13323
+
13324
+
13325
+
13326
+
13327
+
13328
+ namespace duckdb {
13329
+
13330
+ class BoundCastExpression : public Expression {
13331
+ public:
13332
+ BoundCastExpression(unique_ptr<Expression> child, LogicalType target_type, bool try_cast = false);
13333
+
13334
+ //! The child type
13335
+ unique_ptr<Expression> child;
13336
+ //! Whether to use try_cast or not. try_cast converts cast failures into NULLs instead of throwing an error.
13337
+ bool try_cast;
13338
+
13339
+ public:
13340
+ LogicalType source_type() {
13341
+ return child->return_type;
13342
+ }
13343
+
13344
+ //! Cast an expression to the specified SQL type if required
13345
+ static unique_ptr<Expression> AddCastToType(unique_ptr<Expression> expr, const LogicalType &target_type);
13346
+ //! Returns true if a cast is invertible (i.e. CAST(s -> t -> s) = s for all values of s). This is not true for e.g.
13347
+ //! boolean casts, because that can be e.g. -1 -> TRUE -> 1. This is necessary to prevent some optimizer bugs.
13348
+ static bool CastIsInvertible(const LogicalType &source_type, const LogicalType &target_type);
13349
+
13350
+ string ToString() const override;
13351
+
13352
+ bool Equals(const BaseExpression *other) const override;
13353
+
13354
+ unique_ptr<Expression> Copy() override;
13355
+ };
13356
+ } // namespace duckdb
13357
+
13358
+ //===----------------------------------------------------------------------===//
13359
+ // DuckDB
13360
+ //
13361
+ // duckdb/planner/expression/bound_columnref_expression.hpp
13362
+ //
13363
+ //
13364
+ //===----------------------------------------------------------------------===//
13365
+
13366
+
13367
+
13368
+
13369
+
13370
+
13371
+ namespace duckdb {
13372
+
13373
+ //! A BoundColumnRef expression represents a ColumnRef expression that was bound to an actual table and column index. It
13374
+ //! is not yet executable, however. The ColumnBindingResolver transforms the BoundColumnRefExpressions into
13375
+ //! BoundExpressions, which refer to indexes into the physical chunks that pass through the executor.
13376
+ class BoundColumnRefExpression : public Expression {
13377
+ public:
13378
+ BoundColumnRefExpression(LogicalType type, ColumnBinding binding, idx_t depth = 0);
13379
+ BoundColumnRefExpression(string alias, LogicalType type, ColumnBinding binding, idx_t depth = 0);
13380
+
13381
+ //! Column index set by the binder, used to generate the final BoundExpression
13382
+ ColumnBinding binding;
13383
+ //! The subquery depth (i.e. depth 0 = current query, depth 1 = parent query, depth 2 = parent of parent, etc...).
13384
+ //! This is only non-zero for correlated expressions inside subqueries.
13385
+ idx_t depth;
13386
+
13387
+ public:
13388
+ bool IsScalar() const override {
13389
+ return false;
13390
+ }
13391
+ bool IsFoldable() const override {
13392
+ return false;
13393
+ }
13394
+
13395
+ string ToString() const override;
13396
+
13397
+ bool Equals(const BaseExpression *other) const override;
13398
+ hash_t Hash() const override;
13399
+
13400
+ unique_ptr<Expression> Copy() override;
13401
+ };
13402
+ } // namespace duckdb
13403
+
13404
+ //===----------------------------------------------------------------------===//
13405
+ // DuckDB
13406
+ //
13407
+ // duckdb/planner/expression/bound_comparison_expression.hpp
13408
+ //
13409
+ //
13410
+ //===----------------------------------------------------------------------===//
13411
+
13412
+
13413
+
13414
+
13415
+
13416
+ namespace duckdb {
13417
+
13418
+ class BoundComparisonExpression : public Expression {
13419
+ public:
13420
+ BoundComparisonExpression(ExpressionType type, unique_ptr<Expression> left, unique_ptr<Expression> right);
13421
+
13422
+ unique_ptr<Expression> left;
13423
+ unique_ptr<Expression> right;
13424
+
13425
+ public:
13426
+ string ToString() const override;
13427
+
13428
+ bool Equals(const BaseExpression *other) const override;
13429
+
13430
+ unique_ptr<Expression> Copy() override;
13431
+
13432
+ public:
13433
+ static LogicalType BindComparison(LogicalType left_type, LogicalType right_type);
13434
+ };
13435
+ } // namespace duckdb
13436
+
13437
+ //===----------------------------------------------------------------------===//
13438
+ // DuckDB
13439
+ //
13440
+ // duckdb/planner/expression/bound_conjunction_expression.hpp
13441
+ //
13442
+ //
13443
+ //===----------------------------------------------------------------------===//
13444
+
13445
+
13446
+
13447
+
13448
+
13449
+ namespace duckdb {
13450
+
13451
+ class BoundConjunctionExpression : public Expression {
13452
+ public:
13453
+ explicit BoundConjunctionExpression(ExpressionType type);
13454
+ BoundConjunctionExpression(ExpressionType type, unique_ptr<Expression> left, unique_ptr<Expression> right);
13455
+
13456
+ vector<unique_ptr<Expression>> children;
13457
+
13458
+ public:
13459
+ string ToString() const override;
13460
+
13461
+ bool Equals(const BaseExpression *other) const override;
13462
+
13463
+ unique_ptr<Expression> Copy() override;
13464
+ };
13465
+ } // namespace duckdb
13466
+
13467
+ //===----------------------------------------------------------------------===//
13468
+ // DuckDB
13469
+ //
13470
+ // duckdb/planner/expression/bound_constant_expression.hpp
13471
+ //
13472
+ //
13473
+ //===----------------------------------------------------------------------===//
13474
+
13475
+
13476
+
13477
+
13478
+
13479
+
13480
+ namespace duckdb {
13481
+
13482
+ class BoundConstantExpression : public Expression {
13483
+ public:
13484
+ explicit BoundConstantExpression(Value value);
13485
+
13486
+ Value value;
13487
+
13488
+ public:
13489
+ string ToString() const override;
13490
+
13491
+ bool Equals(const BaseExpression *other) const override;
13492
+ hash_t Hash() const override;
13493
+
13494
+ unique_ptr<Expression> Copy() override;
13495
+ };
13496
+ } // namespace duckdb
13497
+
13498
+ //===----------------------------------------------------------------------===//
13499
+ // DuckDB
13500
+ //
13501
+ // duckdb/planner/expression/bound_default_expression.hpp
13502
+ //
13503
+ //
13504
+ //===----------------------------------------------------------------------===//
13505
+
13506
+
13507
+
13508
+
13509
+
13510
+ namespace duckdb {
13511
+
13512
+ class BoundDefaultExpression : public Expression {
13513
+ public:
13514
+ explicit BoundDefaultExpression(LogicalType type = LogicalType())
13515
+ : Expression(ExpressionType::VALUE_DEFAULT, ExpressionClass::BOUND_DEFAULT, type) {
13516
+ }
13517
+
13518
+ public:
13519
+ bool IsScalar() const override {
13520
+ return false;
13521
+ }
13522
+ bool IsFoldable() const override {
13523
+ return false;
13524
+ }
13525
+
13526
+ string ToString() const override {
13527
+ return "DEFAULT";
13528
+ }
13529
+
13530
+ unique_ptr<Expression> Copy() override {
13531
+ return make_unique<BoundDefaultExpression>(return_type);
13532
+ }
13533
+ };
13534
+ } // namespace duckdb
13535
+
13536
+ //===----------------------------------------------------------------------===//
13537
+ // DuckDB
13538
+ //
13539
+ // duckdb/planner/expression/bound_function_expression.hpp
13540
+ //
13541
+ //
13542
+ //===----------------------------------------------------------------------===//
13543
+
13544
+
13545
+
13546
+
13547
+
13548
+
13549
+ namespace duckdb {
13550
+ class ScalarFunctionCatalogEntry;
13551
+
13552
+ //! Represents a function call that has been bound to a base function
13553
+ class BoundFunctionExpression : public Expression {
13554
+ public:
13555
+ BoundFunctionExpression(LogicalType return_type, ScalarFunction bound_function,
13556
+ vector<unique_ptr<Expression>> arguments, unique_ptr<FunctionData> bind_info,
13557
+ bool is_operator = false);
13558
+
13559
+ // The bound function expression
13560
+ ScalarFunction function;
13561
+ //! List of child-expressions of the function
13562
+ vector<unique_ptr<Expression>> children;
13563
+ //! The bound function data (if any)
13564
+ unique_ptr<FunctionData> bind_info;
13565
+ //! Whether or not the function is an operator, only used for rendering
13566
+ bool is_operator;
13567
+
13568
+ public:
13569
+ bool HasSideEffects() const override;
13570
+ bool IsFoldable() const override;
13571
+ string ToString() const override;
13572
+
13573
+ hash_t Hash() const override;
13574
+ bool Equals(const BaseExpression *other) const override;
13575
+
13576
+ unique_ptr<Expression> Copy() override;
13577
+ };
13578
+ } // namespace duckdb
13579
+
13580
+ //===----------------------------------------------------------------------===//
13581
+ // DuckDB
13582
+ //
13583
+ // duckdb/planner/expression/bound_operator_expression.hpp
13584
+ //
13585
+ //
13586
+ //===----------------------------------------------------------------------===//
13587
+
13588
+
13589
+
13590
+
13591
+
13592
+ namespace duckdb {
13593
+
13594
+ class BoundOperatorExpression : public Expression {
13595
+ public:
13596
+ BoundOperatorExpression(ExpressionType type, LogicalType return_type);
13597
+
13598
+ vector<unique_ptr<Expression>> children;
13599
+
13600
+ public:
13601
+ string ToString() const override;
13602
+
13603
+ bool Equals(const BaseExpression *other) const override;
13604
+
13605
+ unique_ptr<Expression> Copy() override;
13606
+ };
13607
+ } // namespace duckdb
13608
+
13609
+ //===----------------------------------------------------------------------===//
13610
+ // DuckDB
13611
+ //
13612
+ // duckdb/planner/expression/bound_parameter_expression.hpp
13613
+ //
13614
+ //
13615
+ //===----------------------------------------------------------------------===//
13616
+
13617
+
13618
+
13619
+
13620
+
13621
+
13622
+ namespace duckdb {
13623
+
13624
+ class BoundParameterExpression : public Expression {
13625
+ public:
13626
+ explicit BoundParameterExpression(idx_t parameter_nr);
13627
+
13628
+ idx_t parameter_nr;
13629
+ Value *value;
13630
+
13631
+ public:
13632
+ bool IsScalar() const override;
13633
+ bool HasParameter() const override;
13634
+ bool IsFoldable() const override;
13635
+
13636
+ string ToString() const override;
13637
+
13638
+ bool Equals(const BaseExpression *other) const override;
13639
+ hash_t Hash() const override;
13640
+
13641
+ unique_ptr<Expression> Copy() override;
13642
+ };
13643
+ } // namespace duckdb
13644
+
13645
+ //===----------------------------------------------------------------------===//
13646
+ // DuckDB
13647
+ //
13648
+ // duckdb/planner/expression/bound_reference_expression.hpp
13649
+ //
13650
+ //
13651
+ //===----------------------------------------------------------------------===//
13652
+
13653
+
13654
+
13655
+
13656
+
13657
+ namespace duckdb {
13658
+
13659
+ //! A BoundReferenceExpression represents a physical index into a DataChunk
13660
+ class BoundReferenceExpression : public Expression {
13661
+ public:
13662
+ BoundReferenceExpression(string alias, LogicalType type, idx_t index);
13663
+ BoundReferenceExpression(LogicalType type, idx_t index);
13664
+
13665
+ //! Index used to access data in the chunks
13666
+ idx_t index;
13667
+
13668
+ public:
13669
+ bool IsScalar() const override {
13670
+ return false;
13671
+ }
13672
+ bool IsFoldable() const override {
13673
+ return false;
13674
+ }
13675
+
13676
+ string ToString() const override;
13677
+
13678
+ hash_t Hash() const override;
13679
+ bool Equals(const BaseExpression *other) const override;
13680
+
13681
+ unique_ptr<Expression> Copy() override;
13682
+ };
13683
+ } // namespace duckdb
13684
+
13685
+ //===----------------------------------------------------------------------===//
13686
+ // DuckDB
13687
+ //
13688
+ // duckdb/planner/expression/bound_subquery_expression.hpp
13689
+ //
13690
+ //
13691
+ //===----------------------------------------------------------------------===//
13692
+
13693
+
13694
+
13695
+ //===----------------------------------------------------------------------===//
13696
+ // DuckDB
13697
+ //
13698
+ // duckdb/common/enums/subquery_type.hpp
13699
+ //
13700
+ //
13701
+ //===----------------------------------------------------------------------===//
13702
+
13703
+
13704
+
13705
+
13706
+
13707
+ namespace duckdb {
13708
+
13709
+ //===--------------------------------------------------------------------===//
13710
+ // Subquery Types
13711
+ //===--------------------------------------------------------------------===//
13712
+ enum class SubqueryType : uint8_t {
13713
+ INVALID = 0,
13714
+ SCALAR = 1, // Regular scalar subquery
13715
+ EXISTS = 2, // EXISTS (SELECT...)
13716
+ NOT_EXISTS = 3, // NOT EXISTS(SELECT...)
13717
+ ANY = 4, // x = ANY(SELECT...) OR x IN (SELECT...)
13718
+ };
13719
+
13720
+ } // namespace duckdb
13721
+
13722
+ //===----------------------------------------------------------------------===//
13723
+ // DuckDB
13724
+ //
13725
+ // duckdb/planner/binder.hpp
13726
+ //
13727
+ //
13728
+ //===----------------------------------------------------------------------===//
13729
+
13730
+
13731
+
13732
+
13733
+
13734
+ //===----------------------------------------------------------------------===//
13735
+ // DuckDB
13736
+ //
13737
+ // duckdb/parser/tokens.hpp
13738
+ //
13739
+ //
13740
+ //===----------------------------------------------------------------------===//
13741
+
13742
+
13743
+
13744
+ namespace duckdb {
13745
+
13746
+ //===--------------------------------------------------------------------===//
13747
+ // Statements
13748
+ //===--------------------------------------------------------------------===//
13749
+ class SQLStatement;
13750
+
13751
+ class AlterStatement;
13752
+ class CallStatement;
13753
+ class CopyStatement;
13754
+ class CreateStatement;
13755
+ class DeleteStatement;
13756
+ class DropStatement;
13757
+ class InsertStatement;
13758
+ class SelectStatement;
13759
+ class TransactionStatement;
13760
+ class UpdateStatement;
13761
+ class PrepareStatement;
13762
+ class ExecuteStatement;
13763
+ class PragmaStatement;
13764
+ class ShowStatement;
13765
+ class ExplainStatement;
13766
+ class ExportStatement;
13767
+ class VacuumStatement;
13768
+ class RelationStatement;
13769
+ class SetStatement;
13770
+ class LoadStatement;
13771
+
13772
+ //===--------------------------------------------------------------------===//
13773
+ // Query Node
13774
+ //===--------------------------------------------------------------------===//
13775
+ class QueryNode;
13776
+ class SelectNode;
13777
+ class SetOperationNode;
13778
+ class RecursiveCTENode;
13779
+
13780
+ //===--------------------------------------------------------------------===//
13781
+ // Expressions
13782
+ //===--------------------------------------------------------------------===//
13783
+ class ParsedExpression;
13784
+
13785
+ class BetweenExpression;
13786
+ class CaseExpression;
13787
+ class CastExpression;
13788
+ class CollateExpression;
13789
+ class ColumnRefExpression;
13790
+ class ComparisonExpression;
13791
+ class ConjunctionExpression;
13792
+ class ConstantExpression;
13793
+ class DefaultExpression;
13794
+ class FunctionExpression;
13795
+ class LambdaExpression;
13796
+ class OperatorExpression;
13797
+ class ParameterExpression;
13798
+ class PositionalReferenceExpression;
13799
+ class StarExpression;
13800
+ class SubqueryExpression;
13801
+ class WindowExpression;
13802
+
13803
+ //===--------------------------------------------------------------------===//
13804
+ // Constraints
13805
+ //===--------------------------------------------------------------------===//
13806
+ class Constraint;
13807
+
13808
+ class NotNullConstraint;
13809
+ class CheckConstraint;
13810
+ class UniqueConstraint;
13811
+
13812
+ //===--------------------------------------------------------------------===//
13813
+ // TableRefs
13814
+ //===--------------------------------------------------------------------===//
13815
+ class TableRef;
13816
+
13817
+ class BaseTableRef;
13818
+ class CrossProductRef;
13819
+ class JoinRef;
13820
+ class SubqueryRef;
13821
+ class TableFunctionRef;
13822
+ class EmptyTableRef;
13823
+ class ExpressionListRef;
13824
+
13825
+ //===--------------------------------------------------------------------===//
13826
+ // Other
13827
+ //===--------------------------------------------------------------------===//
13828
+ struct SampleOptions;
13829
+
13830
+ } // namespace duckdb
13831
+
13832
+ //===----------------------------------------------------------------------===//
13833
+ // DuckDB
13834
+ //
13835
+ // duckdb/planner/bind_context.hpp
13836
+ //
13837
+ //
13838
+ //===----------------------------------------------------------------------===//
13839
+
13840
+
13841
+
13842
+
13843
+
13844
+ //===----------------------------------------------------------------------===//
13845
+ // DuckDB
13846
+ //
13847
+ // duckdb/catalog/catalog_entry/table_function_catalog_entry.hpp
13848
+ //
13849
+ //
13850
+ //===----------------------------------------------------------------------===//
13851
+
13852
+
13853
+
13854
+
13855
+ //===----------------------------------------------------------------------===//
13856
+ // DuckDB
13857
+ //
13858
+ // duckdb/function/table_function.hpp
13859
+ //
13860
+ //
13861
+ //===----------------------------------------------------------------------===//
13862
+
13863
+
13864
+
13865
+
13866
+
13867
+
13868
+
13869
+ #include <functional>
13870
+
13871
+ namespace duckdb {
13872
+ class BaseStatistics;
13873
+ class LogicalGet;
13874
+ struct ParallelState;
13875
+ class TableFilterSet;
13876
+
13877
+ struct FunctionOperatorData {
13878
+ DUCKDB_API virtual ~FunctionOperatorData();
13879
+ };
13880
+
13881
+ struct TableFilterCollection {
13882
+ DUCKDB_API explicit TableFilterCollection(TableFilterSet *table_filters);
13883
+
13884
+ TableFilterSet *table_filters;
13885
+ };
13886
+
13887
+ typedef unique_ptr<FunctionData> (*table_function_bind_t)(ClientContext &context, vector<Value> &inputs,
13888
+ unordered_map<string, Value> &named_parameters,
13889
+ vector<LogicalType> &input_table_types,
13890
+ vector<string> &input_table_names,
13891
+ vector<LogicalType> &return_types, vector<string> &names);
13892
+ typedef unique_ptr<FunctionOperatorData> (*table_function_init_t)(ClientContext &context, const FunctionData *bind_data,
13893
+ const vector<column_t> &column_ids,
13894
+ TableFilterCollection *filters);
13895
+ typedef unique_ptr<BaseStatistics> (*table_statistics_t)(ClientContext &context, const FunctionData *bind_data,
13896
+ column_t column_index);
13897
+ typedef void (*table_function_t)(ClientContext &context, const FunctionData *bind_data,
13898
+ FunctionOperatorData *operator_state, DataChunk *input, DataChunk &output);
13899
+
13900
+ typedef void (*table_function_parallel_t)(ClientContext &context, const FunctionData *bind_data,
13901
+ FunctionOperatorData *operator_state, DataChunk *input, DataChunk &output,
13902
+ ParallelState *parallel_state);
13903
+
13904
+ typedef void (*table_function_cleanup_t)(ClientContext &context, const FunctionData *bind_data,
13905
+ FunctionOperatorData *operator_state);
13906
+ typedef idx_t (*table_function_max_threads_t)(ClientContext &context, const FunctionData *bind_data);
13907
+ typedef unique_ptr<ParallelState> (*table_function_init_parallel_state_t)(ClientContext &context,
13908
+ const FunctionData *bind_data,
13909
+ const vector<column_t> &column_ids,
13910
+ TableFilterCollection *filters);
13911
+ typedef unique_ptr<FunctionOperatorData> (*table_function_init_parallel_t)(ClientContext &context,
13912
+ const FunctionData *bind_data,
13913
+ ParallelState *state,
13914
+ const vector<column_t> &column_ids,
13915
+ TableFilterCollection *filters);
13916
+ typedef bool (*table_function_parallel_state_next_t)(ClientContext &context, const FunctionData *bind_data,
13917
+ FunctionOperatorData *state, ParallelState *parallel_state);
13918
+ typedef int (*table_function_progress_t)(ClientContext &context, const FunctionData *bind_data);
13919
+ typedef void (*table_function_dependency_t)(unordered_set<CatalogEntry *> &dependencies, const FunctionData *bind_data);
13920
+ typedef unique_ptr<NodeStatistics> (*table_function_cardinality_t)(ClientContext &context,
13921
+ const FunctionData *bind_data);
13922
+ typedef void (*table_function_pushdown_complex_filter_t)(ClientContext &context, LogicalGet &get,
13923
+ FunctionData *bind_data,
13924
+ vector<unique_ptr<Expression>> &filters);
13925
+ typedef string (*table_function_to_string_t)(const FunctionData *bind_data);
13926
+
13927
+ class TableFunction : public SimpleNamedParameterFunction {
13928
+ public:
13929
+ DUCKDB_API
13930
+ TableFunction(string name, vector<LogicalType> arguments, table_function_t function,
13931
+ table_function_bind_t bind = nullptr, table_function_init_t init = nullptr,
13932
+ table_statistics_t statistics = nullptr, table_function_cleanup_t cleanup = nullptr,
13933
+ table_function_dependency_t dependency = nullptr, table_function_cardinality_t cardinality = nullptr,
13934
+ table_function_pushdown_complex_filter_t pushdown_complex_filter = nullptr,
13935
+ table_function_to_string_t to_string = nullptr, table_function_max_threads_t max_threads = nullptr,
13936
+ table_function_init_parallel_state_t init_parallel_state = nullptr,
13937
+ table_function_parallel_t parallel_function = nullptr,
13938
+ table_function_init_parallel_t parallel_init = nullptr,
13939
+ table_function_parallel_state_next_t parallel_state_next = nullptr, bool projection_pushdown = false,
13940
+ bool filter_pushdown = false, table_function_progress_t query_progress = nullptr);
13941
+ DUCKDB_API
13942
+ TableFunction(const vector<LogicalType> &arguments, table_function_t function, table_function_bind_t bind = nullptr,
13943
+ table_function_init_t init = nullptr, table_statistics_t statistics = nullptr,
13944
+ table_function_cleanup_t cleanup = nullptr, table_function_dependency_t dependency = nullptr,
13945
+ table_function_cardinality_t cardinality = nullptr,
13946
+ table_function_pushdown_complex_filter_t pushdown_complex_filter = nullptr,
13947
+ table_function_to_string_t to_string = nullptr, table_function_max_threads_t max_threads = nullptr,
13948
+ table_function_init_parallel_state_t init_parallel_state = nullptr,
13949
+ table_function_parallel_t parallel_function = nullptr,
13950
+ table_function_init_parallel_t parallel_init = nullptr,
13951
+ table_function_parallel_state_next_t parallel_state_next = nullptr, bool projection_pushdown = false,
13952
+ bool filter_pushdown = false, table_function_progress_t query_progress = nullptr);
13953
+ DUCKDB_API TableFunction();
13954
+
13955
+ //! Bind function
13956
+ //! This function is used for determining the return type of a table producing function and returning bind data
13957
+ //! The returned FunctionData object should be constant and should not be changed during execution.
13958
+ table_function_bind_t bind;
13959
+ //! (Optional) init function
13960
+ //! Initialize the operator state of the function. The operator state is used to keep track of the progress in the
13961
+ //! table function.
13962
+ table_function_init_t init;
13963
+ //! The main function
13964
+ table_function_t function;
13965
+ //! (Optional) statistics function
13966
+ //! Returns the statistics of a specified column
13967
+ table_statistics_t statistics;
13968
+ //! (Optional) cleanup function
13969
+ //! The final cleanup function, called after all data is exhausted from the main function
13970
+ table_function_cleanup_t cleanup;
13971
+ //! (Optional) dependency function
13972
+ //! Sets up which catalog entries this table function depend on
13973
+ table_function_dependency_t dependency;
13974
+ //! (Optional) cardinality function
13975
+ //! Returns the expected cardinality of this scan
13976
+ table_function_cardinality_t cardinality;
13977
+ //! (Optional) pushdown a set of arbitrary filter expressions, rather than only simple comparisons with a constant
13978
+ //! Any functions remaining in the expression list will be pushed as a regular filter after the scan
13979
+ table_function_pushdown_complex_filter_t pushdown_complex_filter;
13980
+ //! (Optional) function for rendering the operator to a string in profiling output
13981
+ table_function_to_string_t to_string;
13982
+ //! (Optional) function that returns the maximum amount of threads that can work on this task
13983
+ table_function_max_threads_t max_threads;
13984
+ //! (Optional) initialize the parallel scan state, called once in total.
13985
+ table_function_init_parallel_state_t init_parallel_state;
13986
+ //! (Optional) Parallel version of the main function
13987
+ table_function_parallel_t parallel_function;
13988
+ //! (Optional) initialize the parallel scan given the parallel state. Called once per task. Return nullptr if there
13989
+ //! is nothing left to scan.
13990
+ table_function_init_parallel_t parallel_init;
13991
+ //! (Optional) return the next chunk to process in the parallel scan, or return nullptr if there is none
13992
+ table_function_parallel_state_next_t parallel_state_next;
13993
+ //! (Optional) return how much of the table we have scanned up to this point (% of the data)
13994
+ table_function_progress_t table_scan_progress;
13995
+ //! Whether or not the table function supports projection pushdown. If not supported a projection will be added
13996
+ //! that filters out unused columns.
13997
+ bool projection_pushdown;
13998
+ //! Whether or not the table function supports filter pushdown. If not supported a filter will be added
13999
+ //! that applies the table filter directly.
14000
+ bool filter_pushdown;
14001
+ };
14002
+
14003
+ } // namespace duckdb
14004
+
14005
+
14006
+
14007
+ namespace duckdb {
14008
+
14009
+ class Catalog;
14010
+ class Constraint;
14011
+
14012
+ struct CreateTableFunctionInfo;
14013
+
14014
+ //! A table function in the catalog
14015
+ class TableFunctionCatalogEntry : public StandardEntry {
14016
+ public:
14017
+ TableFunctionCatalogEntry(Catalog *catalog, SchemaCatalogEntry *schema, CreateTableFunctionInfo *info);
14018
+
14019
+ //! The table function
14020
+ vector<TableFunction> functions;
14021
+ };
14022
+ } // namespace duckdb
14023
+
14024
+
14025
+
14026
+
14027
+ //===----------------------------------------------------------------------===//
14028
+ // DuckDB
14029
+ //
14030
+ // duckdb/parser/expression/columnref_expression.hpp
14031
+ //
14032
+ //
14033
+ //===----------------------------------------------------------------------===//
14034
+
14035
+
14036
+
14037
+
14038
+
14039
+
14040
+ namespace duckdb {
14041
+
14042
+ //! Represents a reference to a column from either the FROM clause or from an
14043
+ //! alias
14044
+ class ColumnRefExpression : public ParsedExpression {
14045
+ public:
14046
+ //! Specify both the column and table name
14047
+ ColumnRefExpression(string column_name, string table_name);
14048
+ //! Only specify the column name, the table name will be derived later
14049
+ explicit ColumnRefExpression(string column_name);
14050
+ //! Specify a set of names
14051
+ explicit ColumnRefExpression(vector<string> column_names);
14052
+
14053
+ //! The stack of names in order of which they appear (column_names[0].column_names[1].column_names[2]....)
14054
+ vector<string> column_names;
14055
+
14056
+ public:
14057
+ bool IsQualified() const;
14058
+ const string &GetColumnName() const;
14059
+ const string &GetTableName() const;
14060
+ bool IsScalar() const override {
14061
+ return false;
14062
+ }
14063
+
14064
+ string GetName() const override;
14065
+ string ToString() const override;
14066
+
14067
+ static bool Equals(const ColumnRefExpression *a, const ColumnRefExpression *b);
14068
+ hash_t Hash() const override;
14069
+
14070
+ unique_ptr<ParsedExpression> Copy() const override;
14071
+
14072
+ void Serialize(Serializer &serializer) override;
14073
+ static unique_ptr<ParsedExpression> Deserialize(ExpressionType type, Deserializer &source);
14074
+ };
14075
+ } // namespace duckdb
14076
+
14077
+
14078
+ //===----------------------------------------------------------------------===//
14079
+ // DuckDB
14080
+ //
14081
+ // duckdb/parser/qualified_name_set.hpp
14082
+ //
14083
+ //
14084
+ //===----------------------------------------------------------------------===//
14085
+
14086
+
14087
+
14088
+ //===----------------------------------------------------------------------===//
14089
+ // DuckDB
14090
+ //
14091
+ // duckdb/parser/qualified_name.hpp
14092
+ //
14093
+ //
14094
+ //===----------------------------------------------------------------------===//
14095
+
14096
+
14097
+
14098
+
14099
+
14100
+
14101
+ namespace duckdb {
14102
+
14103
+ struct QualifiedName {
14104
+ string schema;
14105
+ string name;
14106
+
14107
+ //! Parse the (optional) schema and a name from a string in the format of e.g. "schema"."table"; if there is no dot
14108
+ //! the schema will be set to INVALID_SCHEMA
14109
+ static QualifiedName Parse(string input) {
14110
+ string schema;
14111
+ string name;
14112
+ idx_t idx = 0;
14113
+ vector<string> entries;
14114
+ string entry;
14115
+ normal:
14116
+ //! quote
14117
+ for (; idx < input.size(); idx++) {
14118
+ if (input[idx] == '"') {
14119
+ idx++;
14120
+ goto quoted;
14121
+ } else if (input[idx] == '.') {
14122
+ goto separator;
14123
+ }
14124
+ entry += input[idx];
14125
+ }
14126
+ goto end;
14127
+ separator:
14128
+ entries.push_back(entry);
14129
+ entry = "";
14130
+ idx++;
14131
+ goto normal;
14132
+ quoted:
14133
+ //! look for another quote
14134
+ for (; idx < input.size(); idx++) {
14135
+ if (input[idx] == '"') {
14136
+ //! unquote
14137
+ idx++;
14138
+ goto normal;
14139
+ }
14140
+ entry += input[idx];
14141
+ }
14142
+ throw ParserException("Unterminated quote in qualified name!");
14143
+ end:
14144
+ if (entries.empty()) {
14145
+ schema = INVALID_SCHEMA;
14146
+ name = entry;
14147
+ } else if (entries.size() == 1) {
14148
+ schema = entries[0];
14149
+ name = entry;
14150
+ } else {
14151
+ throw ParserException("Expected schema.entry or entry: too many entries found");
14152
+ }
14153
+ return QualifiedName {schema, name};
14154
+ }
14155
+ };
14156
+
14157
+ struct QualifiedColumnName {
14158
+ QualifiedColumnName() {
14159
+ }
14160
+ QualifiedColumnName(string table_p, string column_p) : table(move(table_p)), column(move(column_p)) {
14161
+ }
14162
+
14163
+ string schema;
14164
+ string table;
14165
+ string column;
14166
+ };
14167
+
14168
+ } // namespace duckdb
14169
+
14170
+ //===----------------------------------------------------------------------===//
14171
+ // DuckDB
14172
+ //
14173
+ // duckdb/common/types/hash.hpp
14174
+ //
14175
+ //
14176
+ //===----------------------------------------------------------------------===//
14177
+
14178
+
14179
+
14180
+
14181
+
14182
+
14183
+ namespace duckdb {
14184
+
14185
+ struct string_t;
14186
+
14187
+ // efficient hash function that maximizes the avalanche effect and minimizes
14188
+ // bias
14189
+ // see: https://nullprogram.com/blog/2018/07/31/
14190
+
14191
+ inline hash_t murmurhash64(uint64_t x) {
14192
+ return x * UINT64_C(0xbf58476d1ce4e5b9);
14193
+ }
14194
+
14195
+ inline hash_t murmurhash32(uint32_t x) {
14196
+ return murmurhash64(x);
14197
+ }
14198
+
14199
+ template <class T>
14200
+ hash_t Hash(T value) {
14201
+ return murmurhash32(value);
14202
+ }
14203
+
14204
+ //! Combine two hashes by XORing them
14205
+ inline hash_t CombineHash(hash_t left, hash_t right) {
14206
+ return left ^ right;
14207
+ }
14208
+
14209
+ template <>
14210
+ hash_t Hash(uint64_t val);
14211
+ template <>
14212
+ hash_t Hash(int64_t val);
14213
+ template <>
14214
+ hash_t Hash(hugeint_t val);
14215
+ template <>
14216
+ hash_t Hash(float val);
14217
+ template <>
14218
+ hash_t Hash(double val);
14219
+ template <>
14220
+ hash_t Hash(const char *val);
14221
+ template <>
14222
+ hash_t Hash(char *val);
14223
+ template <>
14224
+ hash_t Hash(string_t val);
14225
+ template <>
14226
+ hash_t Hash(interval_t val);
14227
+ hash_t Hash(const char *val, size_t size);
14228
+ hash_t Hash(uint8_t *val, size_t size);
14229
+
14230
+ } // namespace duckdb
14231
+
14232
+
14233
+
14234
+ namespace duckdb {
14235
+
14236
+ struct QualifiedColumnHashFunction {
14237
+ uint64_t operator()(const QualifiedColumnName &a) const {
14238
+ std::hash<std::string> str_hasher;
14239
+ return str_hasher(a.schema) ^ str_hasher(a.table) ^ str_hasher(a.column);
14240
+ }
14241
+ };
14242
+
14243
+ struct QualifiedColumnEquality {
14244
+ bool operator()(const QualifiedColumnName &a, const QualifiedColumnName &b) const {
14245
+ return a.schema == b.schema && a.table == b.table && a.column == b.column;
14246
+ }
14247
+ };
14248
+
14249
+ using qualified_column_set_t = unordered_set<QualifiedColumnName, QualifiedColumnHashFunction, QualifiedColumnEquality>;
14250
+
14251
+ } // namespace duckdb
14252
+
14253
+
14254
+ //===----------------------------------------------------------------------===//
14255
+ // DuckDB
14256
+ //
14257
+ // duckdb/planner/expression_binder.hpp
14258
+ //
14259
+ //
14260
+ //===----------------------------------------------------------------------===//
14261
+
14262
+
14263
+
14264
+
14265
+ //===----------------------------------------------------------------------===//
14266
+ // DuckDB
14267
+ //
14268
+ // duckdb/parser/expression/bound_expression.hpp
14269
+ //
14270
+ //
14271
+ //===----------------------------------------------------------------------===//
14272
+
14273
+
14274
+
14275
+
14276
+
14277
+
14278
+
14279
+ namespace duckdb {
14280
+
14281
+ //! BoundExpression is an intermediate dummy class used by the binder. It is a ParsedExpression but holds an Expression.
14282
+ //! It represents a successfully bound expression. It is used in the Binder to prevent re-binding of already bound parts
14283
+ //! when dealing with subqueries.
14284
+ class BoundExpression : public ParsedExpression {
14285
+ public:
14286
+ BoundExpression(unique_ptr<Expression> expr)
14287
+ : ParsedExpression(ExpressionType::INVALID, ExpressionClass::BOUND_EXPRESSION), expr(move(expr)) {
14288
+ }
14289
+
14290
+ unique_ptr<Expression> expr;
14291
+
14292
+ public:
14293
+ string ToString() const override {
14294
+ return expr->ToString();
14295
+ }
14296
+
14297
+ bool Equals(const BaseExpression *other) const override {
14298
+ return false;
14299
+ }
14300
+ hash_t Hash() const override {
14301
+ return 0;
14302
+ }
14303
+
14304
+ unique_ptr<ParsedExpression> Copy() const override {
14305
+ throw SerializationException("Cannot copy or serialize bound expression");
14306
+ }
14307
+ };
14308
+
14309
+ } // namespace duckdb
14310
+
14311
+
14312
+
14313
+
14314
+
14315
+
14316
+ namespace duckdb {
14317
+
14318
+ class Binder;
14319
+ class ClientContext;
14320
+ class QueryNode;
14321
+
14322
+ class ScalarFunctionCatalogEntry;
14323
+ class AggregateFunctionCatalogEntry;
14324
+ class MacroCatalogEntry;
14325
+ class CatalogEntry;
14326
+ class SimpleFunction;
14327
+
14328
+ struct MacroBinding;
14329
+
14330
+ struct BoundColumnReferenceInfo {
14331
+ string name;
14332
+ idx_t query_location;
14333
+ };
14334
+
14335
+ struct BindResult {
14336
+ BindResult() {
14337
+ }
14338
+ explicit BindResult(string error) : error(error) {
14339
+ }
14340
+ explicit BindResult(unique_ptr<Expression> expr) : expression(move(expr)) {
14341
+ }
14342
+
14343
+ bool HasError() {
14344
+ return !error.empty();
14345
+ }
14346
+
14347
+ unique_ptr<Expression> expression;
14348
+ string error;
14349
+ };
14350
+
14351
+ class ExpressionBinder {
14352
+ public:
14353
+ ExpressionBinder(Binder &binder, ClientContext &context, bool replace_binder = false);
14354
+ virtual ~ExpressionBinder();
14355
+
14356
+ //! The target type that should result from the binder. If the result is not of this type, a cast to this type will
14357
+ //! be added. Defaults to INVALID.
14358
+ LogicalType target_type;
14359
+
14360
+ public:
14361
+ unique_ptr<Expression> Bind(unique_ptr<ParsedExpression> &expr, LogicalType *result_type = nullptr,
14362
+ bool root_expression = true);
14363
+
14364
+ //! Returns whether or not any columns have been bound by the expression binder
14365
+ bool HasBoundColumns() {
14366
+ return !bound_columns.empty();
14367
+ }
14368
+ const vector<BoundColumnReferenceInfo> &GetBoundColumns() {
14369
+ return bound_columns;
14370
+ }
14371
+
14372
+ string Bind(unique_ptr<ParsedExpression> *expr, idx_t depth, bool root_expression = false);
14373
+
14374
+ unique_ptr<ParsedExpression> CreateStructExtract(unique_ptr<ParsedExpression> base, string field_name);
14375
+ BindResult BindQualifiedColumnName(ColumnRefExpression &colref, const string &table_name);
14376
+
14377
+ unique_ptr<ParsedExpression> QualifyColumnName(const string &column_name, string &error_message);
14378
+ unique_ptr<ParsedExpression> QualifyColumnName(ColumnRefExpression &colref, string &error_message);
14379
+
14380
+ // Bind table names to ColumnRefExpressions
14381
+ void QualifyColumnNames(unique_ptr<ParsedExpression> &expr);
14382
+ static void QualifyColumnNames(Binder &binder, unique_ptr<ParsedExpression> &expr);
14383
+
14384
+ static unique_ptr<Expression> PushCollation(ClientContext &context, unique_ptr<Expression> source,
14385
+ const string &collation, bool equality_only = false);
14386
+ static void TestCollation(ClientContext &context, const string &collation);
14387
+
14388
+ bool BindCorrelatedColumns(unique_ptr<ParsedExpression> &expr);
14389
+
14390
+ void BindChild(unique_ptr<ParsedExpression> &expr, idx_t depth, string &error);
14391
+ static void ExtractCorrelatedExpressions(Binder &binder, Expression &expr);
14392
+
14393
+ static bool ContainsNullType(const LogicalType &type);
14394
+ static LogicalType ExchangeNullType(const LogicalType &type);
14395
+ static bool ContainsType(const LogicalType &type, LogicalTypeId target);
14396
+ static LogicalType ExchangeType(const LogicalType &type, LogicalTypeId target, LogicalType new_type);
14397
+
14398
+ static void ResolveParameterType(LogicalType &type);
14399
+ static void ResolveParameterType(unique_ptr<Expression> &expr);
14400
+
14401
+ //! Bind the given expresion. Unlike Bind(), this does *not* mute the given ParsedExpression.
14402
+ //! Exposed to be used from sub-binders that aren't subclasses of ExpressionBinder.
14403
+ virtual BindResult BindExpression(unique_ptr<ParsedExpression> *expr_ptr, idx_t depth,
14404
+ bool root_expression = false);
14405
+
14406
+ protected:
14407
+ BindResult BindExpression(BetweenExpression &expr, idx_t depth);
14408
+ BindResult BindExpression(CaseExpression &expr, idx_t depth);
14409
+ BindResult BindExpression(CollateExpression &expr, idx_t depth);
14410
+ BindResult BindExpression(CastExpression &expr, idx_t depth);
14411
+ BindResult BindExpression(ColumnRefExpression &expr, idx_t depth);
14412
+ BindResult BindExpression(ComparisonExpression &expr, idx_t depth);
14413
+ BindResult BindExpression(ConjunctionExpression &expr, idx_t depth);
14414
+ BindResult BindExpression(ConstantExpression &expr, idx_t depth);
14415
+ BindResult BindExpression(FunctionExpression &expr, idx_t depth, unique_ptr<ParsedExpression> *expr_ptr);
14416
+ BindResult BindExpression(LambdaExpression &expr, idx_t depth);
14417
+ BindResult BindExpression(OperatorExpression &expr, idx_t depth);
14418
+ BindResult BindExpression(ParameterExpression &expr, idx_t depth);
14419
+ BindResult BindExpression(PositionalReferenceExpression &ref, idx_t depth);
14420
+ BindResult BindExpression(StarExpression &expr, idx_t depth);
14421
+ BindResult BindExpression(SubqueryExpression &expr, idx_t depth);
14422
+
14423
+ protected:
14424
+ virtual BindResult BindGroupingFunction(OperatorExpression &op, idx_t depth);
14425
+ virtual BindResult BindFunction(FunctionExpression &expr, ScalarFunctionCatalogEntry *function, idx_t depth);
14426
+ virtual BindResult BindAggregate(FunctionExpression &expr, AggregateFunctionCatalogEntry *function, idx_t depth);
14427
+ virtual BindResult BindUnnest(FunctionExpression &expr, idx_t depth);
14428
+ virtual BindResult BindMacro(FunctionExpression &expr, MacroCatalogEntry *macro, idx_t depth,
14429
+ unique_ptr<ParsedExpression> *expr_ptr);
14430
+
14431
+ void ReplaceMacroParametersRecursive(unique_ptr<ParsedExpression> &expr);
14432
+
14433
+ virtual string UnsupportedAggregateMessage();
14434
+ virtual string UnsupportedUnnestMessage();
14435
+
14436
+ Binder &binder;
14437
+ ClientContext &context;
14438
+ ExpressionBinder *stored_binder;
14439
+ MacroBinding *macro_binding;
14440
+ vector<BoundColumnReferenceInfo> bound_columns;
14441
+ };
14442
+
14443
+ } // namespace duckdb
14444
+
14445
+ //===----------------------------------------------------------------------===//
14446
+ // DuckDB
14447
+ //
14448
+ // duckdb/planner/table_binding.hpp
14449
+ //
14450
+ //
14451
+ //===----------------------------------------------------------------------===//
14452
+
14453
+
14454
+
14455
+
14456
+
14457
+
14458
+
14459
+
14460
+
14461
+ namespace duckdb {
14462
+ class BindContext;
14463
+ class BoundQueryNode;
14464
+ class ColumnRefExpression;
14465
+ class SubqueryRef;
14466
+ class LogicalGet;
14467
+ class TableCatalogEntry;
14468
+ class TableFunctionCatalogEntry;
14469
+ class BoundTableFunction;
14470
+
14471
+ //! A Binding represents a binding to a table, table-producing function or subquery with a specified table index.
14472
+ struct Binding {
14473
+ Binding(const string &alias, vector<LogicalType> types, vector<string> names, idx_t index);
14474
+ virtual ~Binding() = default;
14475
+
14476
+ //! The alias of the binding
14477
+ string alias;
14478
+ //! The table index of the binding
14479
+ idx_t index;
14480
+ vector<LogicalType> types;
14481
+ //! Column names of the subquery
14482
+ vector<string> names;
14483
+ //! Name -> index for the names
14484
+ case_insensitive_map_t<column_t> name_map;
14485
+
14486
+ public:
14487
+ bool TryGetBindingIndex(const string &column_name, column_t &column_index);
14488
+ column_t GetBindingIndex(const string &column_name);
14489
+ bool HasMatchingBinding(const string &column_name);
14490
+ virtual string ColumnNotFoundError(const string &column_name) const;
14491
+ virtual BindResult Bind(ColumnRefExpression &colref, idx_t depth);
14492
+ virtual TableCatalogEntry *GetTableEntry();
14493
+ };
14494
+
14495
+ //! TableBinding is exactly like the Binding, except it keeps track of which columns were bound in the linked LogicalGet
14496
+ //! node for projection pushdown purposes.
14497
+ struct TableBinding : public Binding {
14498
+ TableBinding(const string &alias, vector<LogicalType> types, vector<string> names, LogicalGet &get, idx_t index,
14499
+ bool add_row_id = false);
14500
+
14501
+ //! the underlying LogicalGet
14502
+ LogicalGet &get;
14503
+
14504
+ public:
14505
+ BindResult Bind(ColumnRefExpression &colref, idx_t depth) override;
14506
+ TableCatalogEntry *GetTableEntry() override;
14507
+ string ColumnNotFoundError(const string &column_name) const override;
14508
+ };
14509
+
14510
+ //! MacroBinding is like the Binding, except the alias and index are set by default. Used for binding Macro
14511
+ //! Params/Arguments.
14512
+ struct MacroBinding : public Binding {
14513
+ static constexpr const char *MACRO_NAME = "0_macro_parameters";
14514
+
14515
+ public:
14516
+ MacroBinding(vector<LogicalType> types_p, vector<string> names_p, string macro_name);
14517
+
14518
+ //! Arguments
14519
+ vector<unique_ptr<ParsedExpression>> arguments;
14520
+ //! The name of the macro
14521
+ string macro_name;
14522
+
14523
+ public:
14524
+ BindResult Bind(ColumnRefExpression &colref, idx_t depth) override;
14525
+
14526
+ //! Given the parameter colref, returns a copy of the argument that was supplied for this parameter
14527
+ unique_ptr<ParsedExpression> ParamToArg(ColumnRefExpression &colref);
14528
+ };
14529
+
14530
+ } // namespace duckdb
14531
+
14532
+
14533
+ namespace duckdb {
14534
+ class Binder;
14535
+ class LogicalGet;
14536
+ class BoundQueryNode;
14537
+
14538
+ class StarExpression;
14539
+
14540
+ struct UsingColumnSet {
14541
+ string primary_binding;
14542
+ unordered_set<string> bindings;
14543
+ };
14544
+
14545
+ //! The BindContext object keeps track of all the tables and columns that are
14546
+ //! encountered during the binding process.
14547
+ class BindContext {
14548
+ public:
14549
+ //! Keep track of recursive CTE references
14550
+ case_insensitive_map_t<std::shared_ptr<idx_t>> cte_references;
14551
+
14552
+ public:
14553
+ //! Given a column name, find the matching table it belongs to. Throws an
14554
+ //! exception if no table has a column of the given name.
14555
+ string GetMatchingBinding(const string &column_name);
14556
+ //! Like GetMatchingBinding, but instead of throwing an error if multiple tables have the same binding it will
14557
+ //! return a list of all the matching ones
14558
+ unordered_set<string> GetMatchingBindings(const string &column_name);
14559
+ //! Like GetMatchingBindings, but returns the top 3 most similar bindings (in levenshtein distance) instead of the
14560
+ //! matching ones
14561
+ vector<string> GetSimilarBindings(const string &column_name);
14562
+
14563
+ Binding *GetCTEBinding(const string &ctename);
14564
+ //! Binds a column expression to the base table. Returns the bound expression
14565
+ //! or throws an exception if the column could not be bound.
14566
+ BindResult BindColumn(ColumnRefExpression &colref, idx_t depth);
14567
+ string BindColumn(PositionalReferenceExpression &ref, string &table_name, string &column_name);
14568
+ BindResult BindColumn(PositionalReferenceExpression &ref, idx_t depth);
14569
+
14570
+ unique_ptr<ParsedExpression> CreateColumnReference(const string &table_name, const string &column_name);
14571
+ unique_ptr<ParsedExpression> CreateColumnReference(const string &schema_name, const string &table_name,
14572
+ const string &column_name);
14573
+
14574
+ //! Generate column expressions for all columns that are present in the
14575
+ //! referenced tables. This is used to resolve the * expression in a
14576
+ //! selection list.
14577
+ void GenerateAllColumnExpressions(StarExpression &expr, vector<unique_ptr<ParsedExpression>> &new_select_list);
14578
+ //! Check if the given (binding, column_name) is in the exclusion/replacement lists.
14579
+ //! Returns true if it is in one of these lists, and should therefore be skipped.
14580
+ bool CheckExclusionList(StarExpression &expr, Binding *binding, const string &column_name,
14581
+ vector<unique_ptr<ParsedExpression>> &new_select_list,
14582
+ case_insensitive_set_t &excluded_columns);
14583
+
14584
+ const vector<std::pair<string, Binding *>> &GetBindingsList() {
14585
+ return bindings_list;
14586
+ }
14587
+
14588
+ //! Adds a base table with the given alias to the BindContext.
14589
+ void AddBaseTable(idx_t index, const string &alias, const vector<string> &names, const vector<LogicalType> &types,
14590
+ LogicalGet &get);
14591
+ //! Adds a call to a table function with the given alias to the BindContext.
14592
+ void AddTableFunction(idx_t index, const string &alias, const vector<string> &names,
14593
+ const vector<LogicalType> &types, LogicalGet &get);
14594
+ //! Adds a subquery with a given alias to the BindContext.
14595
+ void AddSubquery(idx_t index, const string &alias, SubqueryRef &ref, BoundQueryNode &subquery);
14596
+ //! Adds a base table with the given alias to the BindContext.
14597
+ void AddGenericBinding(idx_t index, const string &alias, const vector<string> &names,
14598
+ const vector<LogicalType> &types);
14599
+
14600
+ //! Adds a base table with the given alias to the CTE BindContext.
14601
+ //! We need this to correctly bind recursive CTEs with multiple references.
14602
+ void AddCTEBinding(idx_t index, const string &alias, const vector<string> &names, const vector<LogicalType> &types);
14603
+
14604
+ //! Add an implicit join condition (e.g. USING (x))
14605
+ void AddUsingBinding(const string &column_name, UsingColumnSet *set);
14606
+
14607
+ void AddUsingBindingSet(unique_ptr<UsingColumnSet> set);
14608
+
14609
+ //! Returns any using column set for the given column name, or nullptr if there is none. On conflict (multiple using
14610
+ //! column sets with the same name) throw an exception.
14611
+ UsingColumnSet *GetUsingBinding(const string &column_name);
14612
+ //! Returns any using column set for the given column name, or nullptr if there is none
14613
+ UsingColumnSet *GetUsingBinding(const string &column_name, const string &binding_name);
14614
+ //! Erase a using binding from the set of using bindings
14615
+ void RemoveUsingBinding(const string &column_name, UsingColumnSet *set);
14616
+ //! Finds the using bindings for a given column. Returns true if any exists, false otherwise.
14617
+ bool FindUsingBinding(const string &column_name, unordered_set<UsingColumnSet *> **using_columns);
14618
+ //! Transfer a using binding from one bind context to this bind context
14619
+ void TransferUsingBinding(BindContext &current_context, UsingColumnSet *current_set, UsingColumnSet *new_set,
14620
+ const string &binding, const string &using_column);
14621
+
14622
+ //! Fetch the actual column name from the given binding, or throws if none exists
14623
+ //! This can be different from "column_name" because of case insensitivity
14624
+ //! (e.g. "column_name" might return "COLUMN_NAME")
14625
+ string GetActualColumnName(const string &binding, const string &column_name);
14626
+
14627
+ case_insensitive_map_t<std::shared_ptr<Binding>> GetCTEBindings() {
14628
+ return cte_bindings;
14629
+ }
14630
+ void SetCTEBindings(case_insensitive_map_t<std::shared_ptr<Binding>> bindings) {
14631
+ cte_bindings = bindings;
14632
+ }
14633
+
14634
+ //! Alias a set of column names for the specified table, using the original names if there are not enough aliases
14635
+ //! specified.
14636
+ static vector<string> AliasColumnNames(const string &table_name, const vector<string> &names,
14637
+ const vector<string> &column_aliases);
14638
+
14639
+ //! Add all the bindings from a BindContext to this BindContext. The other BindContext is destroyed in the process.
14640
+ void AddContext(BindContext other);
14641
+
14642
+ //! Gets a binding of the specified name. Returns a nullptr and sets the out_error if the binding could not be
14643
+ //! found.
14644
+ Binding *GetBinding(const string &name, string &out_error);
14645
+
14646
+ private:
14647
+ void AddBinding(const string &alias, unique_ptr<Binding> binding);
14648
+
14649
+ private:
14650
+ //! The set of bindings
14651
+ case_insensitive_map_t<unique_ptr<Binding>> bindings;
14652
+ //! The list of bindings in insertion order
14653
+ vector<std::pair<string, Binding *>> bindings_list;
14654
+ //! The set of columns used in USING join conditions
14655
+ case_insensitive_map_t<unordered_set<UsingColumnSet *>> using_columns;
14656
+ //! Using column sets
14657
+ vector<unique_ptr<UsingColumnSet>> using_column_sets;
14658
+
14659
+ //! The set of CTE bindings
14660
+ case_insensitive_map_t<std::shared_ptr<Binding>> cte_bindings;
14661
+ };
14662
+ } // namespace duckdb
14663
+
14664
+
14665
+
14666
+
14667
+
14668
+
14669
+
14670
+
14671
+ namespace duckdb {
14672
+ class BoundResultModifier;
14673
+ class BoundSelectNode;
14674
+ class ClientContext;
14675
+ class ExpressionBinder;
14676
+ class LimitModifier;
14677
+ class OrderBinder;
14678
+ class TableCatalogEntry;
14679
+ class ViewCatalogEntry;
14680
+
14681
+ struct CreateInfo;
14682
+ struct BoundCreateTableInfo;
14683
+ struct BoundCreateFunctionInfo;
14684
+ struct CommonTableExpressionInfo;
14685
+
14686
+ struct CorrelatedColumnInfo {
14687
+ ColumnBinding binding;
14688
+ LogicalType type;
14689
+ string name;
14690
+ idx_t depth;
14691
+
14692
+ explicit CorrelatedColumnInfo(BoundColumnRefExpression &expr)
14693
+ : binding(expr.binding), type(expr.return_type), name(expr.GetName()), depth(expr.depth) {
14694
+ }
14695
+
14696
+ bool operator==(const CorrelatedColumnInfo &rhs) const {
14697
+ return binding == rhs.binding;
14698
+ }
14699
+ };
14700
+
14701
+ //! Bind the parsed query tree to the actual columns present in the catalog.
14702
+ /*!
14703
+ The binder is responsible for binding tables and columns to actual physical
14704
+ tables and columns in the catalog. In the process, it also resolves types of
14705
+ all expressions.
14706
+ */
14707
+ class Binder : public std::enable_shared_from_this<Binder> {
14708
+ friend class ExpressionBinder;
14709
+ friend class SelectBinder;
14710
+ friend class RecursiveSubqueryPlanner;
14711
+
14712
+ public:
14713
+ static shared_ptr<Binder> CreateBinder(ClientContext &context, Binder *parent = nullptr, bool inherit_ctes = true);
14714
+
14715
+ //! The client context
14716
+ ClientContext &context;
14717
+ //! A mapping of names to common table expressions
14718
+ case_insensitive_map_t<CommonTableExpressionInfo *> CTE_bindings;
14719
+ //! The CTEs that have already been bound
14720
+ unordered_set<CommonTableExpressionInfo *> bound_ctes;
14721
+ //! The bind context
14722
+ BindContext bind_context;
14723
+ //! The set of correlated columns bound by this binder (FIXME: this should probably be an unordered_set and not a
14724
+ //! vector)
14725
+ vector<CorrelatedColumnInfo> correlated_columns;
14726
+ //! The set of parameter expressions bound by this binder
14727
+ vector<BoundParameterExpression *> *parameters;
14728
+ //! Whether or not the bound statement is read-only
14729
+ bool read_only;
14730
+ //! Whether or not the statement requires a valid transaction to run
14731
+ bool requires_valid_transaction;
14732
+ //! Whether or not the statement can be streamed to the client
14733
+ bool allow_stream_result;
14734
+ //! The alias for the currently processing subquery, if it exists
14735
+ string alias;
14736
+ //! Macro parameter bindings (if any)
14737
+ MacroBinding *macro_binding = nullptr;
14738
+
14739
+ public:
14740
+ BoundStatement Bind(SQLStatement &statement);
14741
+ BoundStatement Bind(QueryNode &node);
14742
+
14743
+ unique_ptr<BoundCreateTableInfo> BindCreateTableInfo(unique_ptr<CreateInfo> info);
14744
+ void BindCreateViewInfo(CreateViewInfo &base);
14745
+ SchemaCatalogEntry *BindSchema(CreateInfo &info);
14746
+ SchemaCatalogEntry *BindCreateFunctionInfo(CreateInfo &info);
14747
+
14748
+ //! Check usage, and cast named parameters to their types
14749
+ static void BindNamedParameters(unordered_map<string, LogicalType> &types, unordered_map<string, Value> &values,
14750
+ QueryErrorContext &error_context, string &func_name);
14751
+
14752
+ unique_ptr<BoundTableRef> Bind(TableRef &ref);
14753
+ unique_ptr<LogicalOperator> CreatePlan(BoundTableRef &ref);
14754
+
14755
+ //! Generates an unused index for a table
14756
+ idx_t GenerateTableIndex();
14757
+
14758
+ //! Add a common table expression to the binder
14759
+ void AddCTE(const string &name, CommonTableExpressionInfo *cte);
14760
+ //! Find a common table expression by name; returns nullptr if none exists
14761
+ CommonTableExpressionInfo *FindCTE(const string &name, bool skip = false);
14762
+
14763
+ bool CTEIsAlreadyBound(CommonTableExpressionInfo *cte);
14764
+
14765
+ void PushExpressionBinder(ExpressionBinder *binder);
14766
+ void PopExpressionBinder();
14767
+ void SetActiveBinder(ExpressionBinder *binder);
14768
+ ExpressionBinder *GetActiveBinder();
14769
+ bool HasActiveBinder();
14770
+
14771
+ vector<ExpressionBinder *> &GetActiveBinders();
14772
+
14773
+ void MergeCorrelatedColumns(vector<CorrelatedColumnInfo> &other);
14774
+ //! Add a correlated column to this binder (if it does not exist)
14775
+ void AddCorrelatedColumn(const CorrelatedColumnInfo &info);
14776
+
14777
+ string FormatError(ParsedExpression &expr_context, const string &message);
14778
+ string FormatError(TableRef &ref_context, const string &message);
14779
+
14780
+ string FormatErrorRecursive(idx_t query_location, const string &message, vector<ExceptionFormatValue> &values);
14781
+ template <class T, typename... Args>
14782
+ string FormatErrorRecursive(idx_t query_location, const string &msg, vector<ExceptionFormatValue> &values, T param,
14783
+ Args... params) {
14784
+ values.push_back(ExceptionFormatValue::CreateFormatValue<T>(param));
14785
+ return FormatErrorRecursive(query_location, msg, values, params...);
14786
+ }
14787
+
14788
+ template <typename... Args>
14789
+ string FormatError(idx_t query_location, const string &msg, Args... params) {
14790
+ vector<ExceptionFormatValue> values;
14791
+ return FormatErrorRecursive(query_location, msg, values, params...);
14792
+ }
14793
+
14794
+ static void BindLogicalType(ClientContext &context, LogicalType &type, const string &schema = "");
14795
+
14796
+ bool HasMatchingBinding(const string &table_name, const string &column_name, string &error_message);
14797
+ bool HasMatchingBinding(const string &schema_name, const string &table_name, const string &column_name,
14798
+ string &error_message);
14799
+
14800
+ private:
14801
+ //! The parent binder (if any)
14802
+ shared_ptr<Binder> parent;
14803
+ //! The vector of active binders
14804
+ vector<ExpressionBinder *> active_binders;
14805
+ //! The count of bound_tables
14806
+ idx_t bound_tables;
14807
+ //! Whether or not the binder has any unplanned subqueries that still need to be planned
14808
+ bool has_unplanned_subqueries = false;
14809
+ //! Whether or not subqueries should be planned already
14810
+ bool plan_subquery = true;
14811
+ //! Whether CTEs should reference the parent binder (if it exists)
14812
+ bool inherit_ctes = true;
14813
+ //! Whether or not the binder can contain NULLs as the root of expressions
14814
+ bool can_contain_nulls = false;
14815
+ //! The root statement of the query that is currently being parsed
14816
+ SQLStatement *root_statement = nullptr;
14817
+
14818
+ private:
14819
+ //! Bind the default values of the columns of a table
14820
+ void BindDefaultValues(vector<ColumnDefinition> &columns, vector<unique_ptr<Expression>> &bound_defaults);
14821
+ //! Bind a delimiter value (LIMIT or OFFSET)
14822
+ unique_ptr<Expression> BindDelimiter(ClientContext &context, unique_ptr<ParsedExpression> delimiter,
14823
+ const LogicalType &type, Value &delimiter_value);
14824
+
14825
+ //! Move correlated expressions from the child binder to this binder
14826
+ void MoveCorrelatedExpressions(Binder &other);
14827
+
14828
+ BoundStatement Bind(SelectStatement &stmt);
14829
+ BoundStatement Bind(InsertStatement &stmt);
14830
+ BoundStatement Bind(CopyStatement &stmt);
14831
+ BoundStatement Bind(DeleteStatement &stmt);
14832
+ BoundStatement Bind(UpdateStatement &stmt);
14833
+ BoundStatement Bind(CreateStatement &stmt);
14834
+ BoundStatement Bind(DropStatement &stmt);
14835
+ BoundStatement Bind(AlterStatement &stmt);
14836
+ BoundStatement Bind(TransactionStatement &stmt);
14837
+ BoundStatement Bind(PragmaStatement &stmt);
14838
+ BoundStatement Bind(ExplainStatement &stmt);
14839
+ BoundStatement Bind(VacuumStatement &stmt);
14840
+ BoundStatement Bind(RelationStatement &stmt);
14841
+ BoundStatement Bind(ShowStatement &stmt);
14842
+ BoundStatement Bind(CallStatement &stmt);
14843
+ BoundStatement Bind(ExportStatement &stmt);
14844
+ BoundStatement Bind(SetStatement &stmt);
14845
+ BoundStatement Bind(LoadStatement &stmt);
14846
+
14847
+ unique_ptr<BoundQueryNode> BindNode(SelectNode &node);
14848
+ unique_ptr<BoundQueryNode> BindNode(SetOperationNode &node);
14849
+ unique_ptr<BoundQueryNode> BindNode(RecursiveCTENode &node);
14850
+ unique_ptr<BoundQueryNode> BindNode(QueryNode &node);
14851
+
14852
+ unique_ptr<LogicalOperator> VisitQueryNode(BoundQueryNode &node, unique_ptr<LogicalOperator> root);
14853
+ unique_ptr<LogicalOperator> CreatePlan(BoundRecursiveCTENode &node);
14854
+ unique_ptr<LogicalOperator> CreatePlan(BoundSelectNode &statement);
14855
+ unique_ptr<LogicalOperator> CreatePlan(BoundSetOperationNode &node);
14856
+ unique_ptr<LogicalOperator> CreatePlan(BoundQueryNode &node);
14857
+
14858
+ unique_ptr<BoundTableRef> Bind(BaseTableRef &ref);
14859
+ unique_ptr<BoundTableRef> Bind(CrossProductRef &ref);
14860
+ unique_ptr<BoundTableRef> Bind(JoinRef &ref);
14861
+ unique_ptr<BoundTableRef> Bind(SubqueryRef &ref, CommonTableExpressionInfo *cte = nullptr);
14862
+ unique_ptr<BoundTableRef> Bind(TableFunctionRef &ref);
14863
+ unique_ptr<BoundTableRef> Bind(EmptyTableRef &ref);
14864
+ unique_ptr<BoundTableRef> Bind(ExpressionListRef &ref);
14865
+
14866
+ bool BindFunctionParameters(vector<unique_ptr<ParsedExpression>> &expressions, vector<LogicalType> &arguments,
14867
+ vector<Value> &parameters, unordered_map<string, Value> &named_parameters,
14868
+ unique_ptr<BoundSubqueryRef> &subquery, string &error);
14869
+
14870
+ unique_ptr<LogicalOperator> CreatePlan(BoundBaseTableRef &ref);
14871
+ unique_ptr<LogicalOperator> CreatePlan(BoundCrossProductRef &ref);
14872
+ unique_ptr<LogicalOperator> CreatePlan(BoundJoinRef &ref);
14873
+ unique_ptr<LogicalOperator> CreatePlan(BoundSubqueryRef &ref);
14874
+ unique_ptr<LogicalOperator> CreatePlan(BoundTableFunction &ref);
14875
+ unique_ptr<LogicalOperator> CreatePlan(BoundEmptyTableRef &ref);
14876
+ unique_ptr<LogicalOperator> CreatePlan(BoundExpressionListRef &ref);
14877
+ unique_ptr<LogicalOperator> CreatePlan(BoundCTERef &ref);
14878
+
14879
+ unique_ptr<LogicalOperator> BindTable(TableCatalogEntry &table, BaseTableRef &ref);
14880
+ unique_ptr<LogicalOperator> BindView(ViewCatalogEntry &view, BaseTableRef &ref);
14881
+ unique_ptr<LogicalOperator> BindTableOrView(BaseTableRef &ref);
14882
+
14883
+ BoundStatement BindCopyTo(CopyStatement &stmt);
14884
+ BoundStatement BindCopyFrom(CopyStatement &stmt);
14885
+
14886
+ void BindModifiers(OrderBinder &order_binder, QueryNode &statement, BoundQueryNode &result);
14887
+ void BindModifierTypes(BoundQueryNode &result, const vector<LogicalType> &sql_types, idx_t projection_index);
14888
+
14889
+ BoundStatement BindSummarize(ShowStatement &stmt);
14890
+ unique_ptr<BoundResultModifier> BindLimit(LimitModifier &limit_mod);
14891
+ unique_ptr<BoundResultModifier> BindLimitPercent(LimitPercentModifier &limit_mod);
14892
+ unique_ptr<Expression> BindOrderExpression(OrderBinder &order_binder, unique_ptr<ParsedExpression> expr);
14893
+
14894
+ unique_ptr<LogicalOperator> PlanFilter(unique_ptr<Expression> condition, unique_ptr<LogicalOperator> root);
14895
+
14896
+ void PlanSubqueries(unique_ptr<Expression> *expr, unique_ptr<LogicalOperator> *root);
14897
+ unique_ptr<Expression> PlanSubquery(BoundSubqueryExpression &expr, unique_ptr<LogicalOperator> &root);
14898
+
14899
+ unique_ptr<LogicalOperator> CastLogicalOperatorToTypes(vector<LogicalType> &source_types,
14900
+ vector<LogicalType> &target_types,
14901
+ unique_ptr<LogicalOperator> op);
14902
+
14903
+ string FindBinding(const string &using_column, const string &join_side);
14904
+ bool TryFindBinding(const string &using_column, const string &join_side, string &result);
14905
+
14906
+ void AddUsingBindingSet(unique_ptr<UsingColumnSet> set);
14907
+ string RetrieveUsingBinding(Binder &current_binder, UsingColumnSet *current_set, const string &column_name,
14908
+ const string &join_side, UsingColumnSet *new_set);
14909
+
14910
+ public:
14911
+ // This should really be a private constructor, but make_shared does not allow it...
14912
+ // If you are thinking about calling this, you should probably call Binder::CreateBinder
14913
+ Binder(bool I_know_what_I_am_doing, ClientContext &context, shared_ptr<Binder> parent, bool inherit_ctes);
14914
+ };
14915
+
14916
+ } // namespace duckdb
14917
+
14918
+ //===----------------------------------------------------------------------===//
14919
+ // DuckDB
14920
+ //
14921
+ // duckdb/planner/bound_query_node.hpp
14922
+ //
14923
+ //
14924
+ //===----------------------------------------------------------------------===//
14925
+
14926
+
14927
+
14928
+
14929
+
14930
+ //===----------------------------------------------------------------------===//
14931
+ // DuckDB
14932
+ //
14933
+ // duckdb/parser/query_node.hpp
14934
+ //
14935
+ //
14936
+ //===----------------------------------------------------------------------===//
14937
+
14938
+
14939
+
14940
+
14941
+
14942
+
14943
+
14944
+ //===----------------------------------------------------------------------===//
14945
+ // DuckDB
14946
+ //
14947
+ // duckdb/parser/common_table_expression_info.hpp
14948
+ //
14949
+ //
14950
+ //===----------------------------------------------------------------------===//
14951
+
14952
+
14953
+
14954
+ //===----------------------------------------------------------------------===//
14955
+ // DuckDB
14956
+ //
14957
+ // duckdb/parser/statement/select_statement.hpp
14958
+ //
14959
+ //
14960
+ //===----------------------------------------------------------------------===//
14961
+
14962
+
14963
+
14964
+
14965
+
14966
+
14967
+
14968
+ //===----------------------------------------------------------------------===//
14969
+ // DuckDB
14970
+ //
14971
+ // duckdb/parser/tableref.hpp
14972
+ //
14973
+ //
14974
+ //===----------------------------------------------------------------------===//
14975
+
14976
+
14977
+
14978
+
14979
+ //===----------------------------------------------------------------------===//
14980
+ // DuckDB
14981
+ //
14982
+ // duckdb/common/enums/tableref_type.hpp
14983
+ //
14984
+ //
14985
+ //===----------------------------------------------------------------------===//
14986
+
14987
+
14988
+
14989
+
14990
+
14991
+ namespace duckdb {
14992
+
14993
+ //===--------------------------------------------------------------------===//
14994
+ // Table Reference Types
14995
+ //===--------------------------------------------------------------------===//
14996
+ enum class TableReferenceType : uint8_t {
14997
+ INVALID = 0, // invalid table reference type
14998
+ BASE_TABLE = 1, // base table reference
14999
+ SUBQUERY = 2, // output of a subquery
15000
+ JOIN = 3, // output of join
15001
+ CROSS_PRODUCT = 4, // out of cartesian product
15002
+ TABLE_FUNCTION = 5, // table producing function
15003
+ EXPRESSION_LIST = 6, // expression list
15004
+ CTE = 7, // Recursive CTE
15005
+ EMPTY = 8 // placeholder for empty FROM
15006
+ };
15007
+
15008
+ } // namespace duckdb
15009
+
15010
+ //===----------------------------------------------------------------------===//
15011
+ // DuckDB
15012
+ //
15013
+ // duckdb/parser/parsed_data/sample_options.hpp
15014
+ //
15015
+ //
15016
+ //===----------------------------------------------------------------------===//
15017
+
15018
+
15019
+
15020
+
15021
+
15022
+
15023
+
15024
+
15025
+ namespace duckdb {
15026
+
15027
+ enum class SampleMethod : uint8_t { SYSTEM_SAMPLE = 0, BERNOULLI_SAMPLE = 1, RESERVOIR_SAMPLE = 2 };
15028
+
15029
+ string SampleMethodToString(SampleMethod method);
15030
+
15031
+ struct SampleOptions {
15032
+ Value sample_size;
15033
+ bool is_percentage;
15034
+ SampleMethod method;
15035
+ int64_t seed = -1;
15036
+
15037
+ unique_ptr<SampleOptions> Copy();
15038
+ void Serialize(Serializer &serializer);
15039
+ static unique_ptr<SampleOptions> Deserialize(Deserializer &source);
15040
+ static bool Equals(SampleOptions *a, SampleOptions *b);
15041
+ };
15042
+
15043
+ } // namespace duckdb
15044
+
15045
+
15046
+ namespace duckdb {
15047
+ class Deserializer;
15048
+ class Serializer;
15049
+
15050
+ //! Represents a generic expression that returns a table.
15051
+ class TableRef {
15052
+ public:
15053
+ explicit TableRef(TableReferenceType type) : type(type) {
15054
+ }
15055
+ virtual ~TableRef() {
15056
+ }
15057
+
15058
+ TableReferenceType type;
15059
+ string alias;
15060
+ //! Sample options (if any)
15061
+ unique_ptr<SampleOptions> sample;
15062
+ //! The location in the query (if any)
15063
+ idx_t query_location = DConstants::INVALID_INDEX;
15064
+
15065
+ public:
15066
+ //! Convert the object to a string
15067
+ virtual string ToString() const;
15068
+ void Print();
15069
+
15070
+ virtual bool Equals(const TableRef *other) const;
15071
+
15072
+ virtual unique_ptr<TableRef> Copy() = 0;
15073
+
15074
+ //! Serializes a TableRef to a stand-alone binary blob
15075
+ virtual void Serialize(Serializer &serializer);
15076
+ //! Deserializes a blob back into a TableRef
15077
+ static unique_ptr<TableRef> Deserialize(Deserializer &source);
15078
+
15079
+ //! Copy the properties of this table ref to the target
15080
+ void CopyProperties(TableRef &target) const;
15081
+ };
15082
+ } // namespace duckdb
15083
+
15084
+
15085
+ namespace duckdb {
15086
+
15087
+ class QueryNode;
15088
+
15089
+ //! SelectStatement is a typical SELECT clause
15090
+ class SelectStatement : public SQLStatement {
15091
+ public:
15092
+ SelectStatement() : SQLStatement(StatementType::SELECT_STATEMENT) {
15093
+ }
15094
+
15095
+ //! The main query node
15096
+ unique_ptr<QueryNode> node;
15097
+
15098
+ public:
15099
+ //! Create a copy of this SelectStatement
15100
+ unique_ptr<SQLStatement> Copy() const override;
15101
+ //! Serializes a SelectStatement to a stand-alone binary blob
15102
+ void Serialize(Serializer &serializer);
15103
+ //! Deserializes a blob back into a SelectStatement, returns nullptr if
15104
+ //! deserialization is not possible
15105
+ static unique_ptr<SelectStatement> Deserialize(Deserializer &source);
15106
+ //! Whether or not the statements are equivalent
15107
+ bool Equals(const SQLStatement *other) const;
15108
+ };
15109
+ } // namespace duckdb
15110
+
15111
+
15112
+ namespace duckdb {
15113
+
15114
+ class SelectStatement;
15115
+
15116
+ struct CommonTableExpressionInfo {
15117
+ vector<string> aliases;
15118
+ unique_ptr<SelectStatement> query;
15119
+ };
15120
+
15121
+ } // namespace duckdb
15122
+
15123
+
15124
+ namespace duckdb {
15125
+
15126
+ enum QueryNodeType : uint8_t {
15127
+ SELECT_NODE = 1,
15128
+ SET_OPERATION_NODE = 2,
15129
+ BOUND_SUBQUERY_NODE = 3,
15130
+ RECURSIVE_CTE_NODE = 4
15131
+ };
15132
+
15133
+ class QueryNode {
15134
+ public:
15135
+ explicit QueryNode(QueryNodeType type) : type(type) {
15136
+ }
15137
+ virtual ~QueryNode() {
15138
+ }
15139
+
15140
+ //! The type of the query node, either SetOperation or Select
15141
+ QueryNodeType type;
15142
+ //! The set of result modifiers associated with this query node
15143
+ vector<unique_ptr<ResultModifier>> modifiers;
15144
+ //! CTEs (used by SelectNode and SetOperationNode)
15145
+ unordered_map<string, unique_ptr<CommonTableExpressionInfo>> cte_map;
15146
+
15147
+ virtual const vector<unique_ptr<ParsedExpression>> &GetSelectList() const = 0;
15148
+
15149
+ public:
15150
+ virtual bool Equals(const QueryNode *other) const;
15151
+
15152
+ //! Create a copy of this QueryNode
15153
+ virtual unique_ptr<QueryNode> Copy() = 0;
15154
+ //! Serializes a QueryNode to a stand-alone binary blob
15155
+ virtual void Serialize(Serializer &serializer);
15156
+ //! Deserializes a blob back into a QueryNode, returns nullptr if
15157
+ //! deserialization is not possible
15158
+ static unique_ptr<QueryNode> Deserialize(Deserializer &source);
15159
+
15160
+ protected:
15161
+ //! Copy base QueryNode properties from another expression to this one,
15162
+ //! used in Copy method
15163
+ void CopyProperties(QueryNode &other) const;
15164
+ };
15165
+
15166
+ } // namespace duckdb
15167
+
15168
+
15169
+ namespace duckdb {
15170
+
15171
+ //! Bound equivalent of QueryNode
15172
+ class BoundQueryNode {
15173
+ public:
15174
+ explicit BoundQueryNode(QueryNodeType type) : type(type) {
15175
+ }
15176
+ virtual ~BoundQueryNode() {
15177
+ }
15178
+
15179
+ //! The type of the query node, either SetOperation or Select
15180
+ QueryNodeType type;
15181
+ //! The result modifiers that should be applied to this query node
15182
+ vector<unique_ptr<BoundResultModifier>> modifiers;
15183
+
15184
+ //! The names returned by this QueryNode.
15185
+ vector<string> names;
15186
+ //! The types returned by this QueryNode.
15187
+ vector<LogicalType> types;
15188
+
15189
+ public:
15190
+ virtual idx_t GetRootIndex() = 0;
15191
+ };
15192
+
15193
+ } // namespace duckdb
15194
+
15195
+
15196
+
15197
+ namespace duckdb {
15198
+
15199
+ class BoundSubqueryExpression : public Expression {
15200
+ public:
15201
+ explicit BoundSubqueryExpression(LogicalType return_type);
15202
+
15203
+ bool IsCorrelated() {
15204
+ return binder->correlated_columns.size() > 0;
15205
+ }
15206
+
15207
+ //! The binder used to bind the subquery node
15208
+ shared_ptr<Binder> binder;
15209
+ //! The bound subquery node
15210
+ unique_ptr<BoundQueryNode> subquery;
15211
+ //! The subquery type
15212
+ SubqueryType subquery_type;
15213
+ //! the child expression to compare with (in case of IN, ANY, ALL operators)
15214
+ unique_ptr<Expression> child;
15215
+ //! The comparison type of the child expression with the subquery (in case of ANY, ALL operators)
15216
+ ExpressionType comparison_type;
15217
+ //! The LogicalType of the subquery result. Only used for ANY expressions.
15218
+ LogicalType child_type;
15219
+ //! The target LogicalType of the subquery result (i.e. to which type it should be casted, if child_type <>
15220
+ //! child_target). Only used for ANY expressions.
15221
+ LogicalType child_target;
15222
+
15223
+ public:
15224
+ bool HasSubquery() const override {
15225
+ return true;
15226
+ }
15227
+ bool IsScalar() const override {
15228
+ return false;
15229
+ }
15230
+ bool IsFoldable() const override {
15231
+ return false;
15232
+ }
15233
+
15234
+ string ToString() const override;
15235
+
15236
+ bool Equals(const BaseExpression *other) const override;
15237
+
15238
+ unique_ptr<Expression> Copy() override;
15239
+ };
15240
+ } // namespace duckdb
15241
+
15242
+ //===----------------------------------------------------------------------===//
15243
+ // DuckDB
15244
+ //
15245
+ // duckdb/planner/expression/bound_unnest_expression.hpp
15246
+ //
15247
+ //
15248
+ //===----------------------------------------------------------------------===//
15249
+
15250
+
15251
+
15252
+
15253
+
15254
+ namespace duckdb {
15255
+
15256
+ //! Represents a function call that has been bound to a base function
15257
+ class BoundUnnestExpression : public Expression {
15258
+ public:
15259
+ explicit BoundUnnestExpression(LogicalType return_type);
15260
+
15261
+ unique_ptr<Expression> child;
15262
+
15263
+ public:
15264
+ bool IsFoldable() const override;
15265
+ string ToString() const override;
15266
+
15267
+ hash_t Hash() const override;
15268
+ bool Equals(const BaseExpression *other) const override;
15269
+
15270
+ unique_ptr<Expression> Copy() override;
15271
+ };
15272
+ } // namespace duckdb
15273
+
15274
+ //===----------------------------------------------------------------------===//
15275
+ // DuckDB
15276
+ //
15277
+ // duckdb/planner/expression/bound_window_expression.hpp
15278
+ //
15279
+ //
15280
+ //===----------------------------------------------------------------------===//
15281
+
15282
+
15283
+
15284
+ //===----------------------------------------------------------------------===//
15285
+ // DuckDB
15286
+ //
15287
+ // duckdb/parser/expression/window_expression.hpp
15288
+ //
15289
+ //
15290
+ //===----------------------------------------------------------------------===//
15291
+
15292
+
15293
+
15294
+
15295
+
15296
+
15297
+ namespace duckdb {
15298
+
15299
+ enum class WindowBoundary : uint8_t {
15300
+ INVALID = 0,
15301
+ UNBOUNDED_PRECEDING = 1,
15302
+ UNBOUNDED_FOLLOWING = 2,
15303
+ CURRENT_ROW_RANGE = 3,
15304
+ CURRENT_ROW_ROWS = 4,
15305
+ EXPR_PRECEDING_ROWS = 5,
15306
+ EXPR_FOLLOWING_ROWS = 6,
15307
+ EXPR_PRECEDING_RANGE = 7,
15308
+ EXPR_FOLLOWING_RANGE = 8
15309
+ };
15310
+
15311
+ //! The WindowExpression represents a window function in the query. They are a special case of aggregates which is why
15312
+ //! they inherit from them.
15313
+ class WindowExpression : public ParsedExpression {
15314
+ public:
15315
+ WindowExpression(ExpressionType type, string schema_name, const string &function_name);
15316
+
15317
+ //! Schema of the aggregate function
15318
+ string schema;
15319
+ //! Name of the aggregate function
15320
+ string function_name;
15321
+ //! The child expression of the main window aggregate
15322
+ vector<unique_ptr<ParsedExpression>> children;
15323
+ //! The set of expressions to partition by
15324
+ vector<unique_ptr<ParsedExpression>> partitions;
15325
+ //! The set of ordering clauses
15326
+ vector<OrderByNode> orders;
15327
+ //! True to ignore NULL values
15328
+ bool ignore_nulls;
15329
+ //! The window boundaries
15330
+ WindowBoundary start = WindowBoundary::INVALID;
15331
+ WindowBoundary end = WindowBoundary::INVALID;
15332
+
15333
+ unique_ptr<ParsedExpression> start_expr;
15334
+ unique_ptr<ParsedExpression> end_expr;
15335
+ //! Offset and default expressions for WINDOW_LEAD and WINDOW_LAG functions
15336
+ unique_ptr<ParsedExpression> offset_expr;
15337
+ unique_ptr<ParsedExpression> default_expr;
15338
+
15339
+ public:
15340
+ bool IsWindow() const override {
15341
+ return true;
15342
+ }
15343
+
15344
+ //! Get the name of the expression
15345
+ string GetName() const override;
15346
+ //! Convert the Expression to a String
15347
+ string ToString() const override;
15348
+
15349
+ static bool Equals(const WindowExpression *a, const WindowExpression *b);
15350
+
15351
+ unique_ptr<ParsedExpression> Copy() const override;
15352
+
15353
+ void Serialize(Serializer &serializer) override;
15354
+ static unique_ptr<ParsedExpression> Deserialize(ExpressionType type, Deserializer &source);
15355
+ };
15356
+ } // namespace duckdb
15357
+
15358
+
15359
+
15360
+
15361
+
15362
+ namespace duckdb {
15363
+ class AggregateFunction;
15364
+
15365
+ class BoundWindowExpression : public Expression {
15366
+ public:
15367
+ BoundWindowExpression(ExpressionType type, LogicalType return_type, unique_ptr<AggregateFunction> aggregate,
15368
+ unique_ptr<FunctionData> bind_info);
15369
+
15370
+ //! The bound aggregate function
15371
+ unique_ptr<AggregateFunction> aggregate;
15372
+ //! The bound function info
15373
+ unique_ptr<FunctionData> bind_info;
15374
+ //! The child expressions of the main window aggregate
15375
+ vector<unique_ptr<Expression>> children;
15376
+ //! The set of expressions to partition by
15377
+ vector<unique_ptr<Expression>> partitions;
15378
+ //! Statistics belonging to the partitions expressions
15379
+ vector<unique_ptr<BaseStatistics>> partitions_stats;
15380
+ //! The set of ordering clauses
15381
+ vector<BoundOrderByNode> orders;
15382
+ //! True to ignore NULL values
15383
+ bool ignore_nulls;
15384
+ //! The window boundaries
15385
+ WindowBoundary start = WindowBoundary::INVALID;
15386
+ WindowBoundary end = WindowBoundary::INVALID;
15387
+
15388
+ unique_ptr<Expression> start_expr;
15389
+ unique_ptr<Expression> end_expr;
15390
+ //! Offset and default expressions for WINDOW_LEAD and WINDOW_LAG functions
15391
+ unique_ptr<Expression> offset_expr;
15392
+ unique_ptr<Expression> default_expr;
15393
+
15394
+ public:
15395
+ bool IsWindow() const override {
15396
+ return true;
15397
+ }
15398
+ bool IsFoldable() const override {
15399
+ return false;
15400
+ }
15401
+
15402
+ string ToString() const override;
15403
+
15404
+ bool KeysAreCompatible(const BoundWindowExpression *other) const;
15405
+ bool Equals(const BaseExpression *other) const override;
15406
+
15407
+ unique_ptr<Expression> Copy() override;
15408
+ };
15409
+ } // namespace duckdb
15410
+
15411
+
15412
+
15413
+ #include <random>
15414
+ namespace duckdb {
15415
+
15416
+ class AdaptiveFilter {
15417
+ public:
15418
+ explicit AdaptiveFilter(const Expression &expr);
15419
+ explicit AdaptiveFilter(TableFilterSet *table_filters);
15420
+ void AdaptRuntimeStatistics(double duration);
15421
+ vector<idx_t> permutation;
15422
+
15423
+ private:
15424
+ //! used for adaptive expression reordering
15425
+ idx_t iteration_count;
15426
+ idx_t swap_idx;
15427
+ idx_t right_random_border;
15428
+ idx_t observe_interval;
15429
+ idx_t execute_interval;
15430
+ double runtime_sum;
15431
+ double prev_mean;
15432
+ bool observe;
15433
+ bool warmup;
15434
+ vector<idx_t> swap_likeliness;
15435
+ std::default_random_engine generator;
15436
+ };
15437
+ } // namespace duckdb
15438
+
15439
+
15440
+ namespace duckdb {
15441
+ class ColumnSegment;
15442
+ class LocalTableStorage;
15443
+ class Index;
15444
+ class RowGroup;
15445
+ class UpdateSegment;
15446
+ class TableScanState;
15447
+ class ColumnSegment;
15448
+ class ValiditySegment;
15449
+ class TableFilterSet;
15450
+
15451
+ struct SegmentScanState {
15452
+ virtual ~SegmentScanState() {
15453
+ }
15454
+ };
15455
+
15456
+ struct IndexScanState {
15457
+ virtual ~IndexScanState() {
15458
+ }
15459
+ };
15460
+
15461
+ typedef unordered_map<block_id_t, unique_ptr<BufferHandle>> buffer_handle_set_t;
15462
+
15463
+ struct ColumnScanState {
15464
+ //! The column segment that is currently being scanned
15465
+ ColumnSegment *current;
15466
+ //! The current row index of the scan
15467
+ idx_t row_index;
15468
+ //! The internal row index (i.e. the position of the SegmentScanState)
15469
+ idx_t internal_index;
15470
+ //! Segment scan state
15471
+ unique_ptr<SegmentScanState> scan_state;
15472
+ //! Child states of the vector
15473
+ vector<ColumnScanState> child_states;
15474
+ //! Whether or not InitializeState has been called for this segment
15475
+ bool initialized = false;
15476
+ //! If this segment has already been checked for skipping purposes
15477
+ bool segment_checked = false;
15478
+
15479
+ public:
15480
+ //! Move the scan state forward by "count" rows (including all child states)
15481
+ void Next(idx_t count);
15482
+ //! Move ONLY this state forward by "count" rows (i.e. not the child states)
15483
+ void NextInternal(idx_t count);
15484
+ //! Move the scan state forward by STANDARD_VECTOR_SIZE rows
15485
+ void NextVector();
15486
+ };
15487
+
15488
+ struct ColumnFetchState {
15489
+ //! The set of pinned block handles for this set of fetches
15490
+ buffer_handle_set_t handles;
15491
+ //! Any child states of the fetch
15492
+ vector<unique_ptr<ColumnFetchState>> child_states;
15493
+ };
15494
+
15495
+ struct LocalScanState {
15496
+ ~LocalScanState();
15497
+
15498
+ void SetStorage(LocalTableStorage *storage);
15499
+ LocalTableStorage *GetStorage() {
15500
+ return storage;
15501
+ }
15502
+
15503
+ idx_t chunk_index;
15504
+ idx_t max_index;
15505
+ idx_t last_chunk_count;
15506
+ TableFilterSet *table_filters;
15507
+
15508
+ private:
15509
+ LocalTableStorage *storage = nullptr;
15510
+ };
15511
+
15512
+ class RowGroupScanState {
15513
+ public:
15514
+ RowGroupScanState(TableScanState &parent_p) : parent(parent_p), vector_index(0), max_row(0) {
15515
+ }
15516
+
15517
+ //! The parent scan state
15518
+ TableScanState &parent;
15519
+ //! The current row_group we are scanning
15520
+ RowGroup *row_group;
15521
+ //! The vector index within the row_group
15522
+ idx_t vector_index;
15523
+ //! The maximum row index of this row_group scan
15524
+ idx_t max_row;
15525
+ //! Child column scans
15526
+ unique_ptr<ColumnScanState[]> column_scans;
15527
+
15528
+ public:
15529
+ //! Move to the next vector, skipping past the current one
15530
+ void NextVector();
15531
+ };
15532
+
15533
+ class TableScanState {
15534
+ public:
15535
+ TableScanState() : row_group_scan_state(*this), max_row(0) {};
15536
+
15537
+ //! The row_group scan state
15538
+ RowGroupScanState row_group_scan_state;
15539
+ //! The total maximum row index
15540
+ idx_t max_row;
15541
+ //! The column identifiers of the scan
15542
+ vector<column_t> column_ids;
15543
+ //! The table filters (if any)
15544
+ TableFilterSet *table_filters = nullptr;
15545
+ //! Adaptive filter info (if any)
15546
+ unique_ptr<AdaptiveFilter> adaptive_filter;
15547
+ //! Transaction-local scan state
15548
+ LocalScanState local_state;
15549
+
15550
+ public:
15551
+ //! Move to the next vector
15552
+ void NextVector();
15553
+ };
15554
+
15555
+ class CreateIndexScanState : public TableScanState {
15556
+ public:
15557
+ vector<unique_ptr<StorageLockKey>> locks;
15558
+ unique_lock<mutex> append_lock;
15559
+ unique_lock<mutex> delete_lock;
15560
+ };
15561
+
15562
+ } // namespace duckdb
15563
+
15564
+
15565
+ namespace duckdb {
15566
+ class DataTable;
15567
+ class WriteAheadLog;
15568
+ struct TableAppendState;
15569
+
15570
+ class LocalTableStorage {
15571
+ public:
15572
+ explicit LocalTableStorage(DataTable &table);
15573
+ ~LocalTableStorage();
15574
+
15575
+ DataTable &table;
15576
+ //! The main chunk collection holding the data
15577
+ ChunkCollection collection;
15578
+ //! The set of unique indexes
15579
+ vector<unique_ptr<Index>> indexes;
15580
+ //! The set of deleted entries
15581
+ unordered_map<idx_t, unique_ptr<bool[]>> deleted_entries;
15582
+ //! The number of deleted rows
15583
+ idx_t deleted_rows;
15584
+ //! The number of active scans
15585
+ atomic<idx_t> active_scans;
15586
+
15587
+ public:
15588
+ void InitializeScan(LocalScanState &state, TableFilterSet *table_filters = nullptr);
15589
+ idx_t EstimatedSize();
15590
+
15591
+ void Clear();
15592
+ };
15593
+
15594
+ //! The LocalStorage class holds appends that have not been committed yet
15595
+ class LocalStorage {
15596
+ public:
15597
+ struct CommitState {
15598
+ unordered_map<DataTable *, unique_ptr<TableAppendState>> append_states;
15599
+ };
15600
+
15601
+ public:
15602
+ explicit LocalStorage(Transaction &transaction) : transaction(transaction) {
15603
+ }
15604
+
15605
+ //! Initialize a scan of the local storage
15606
+ void InitializeScan(DataTable *table, LocalScanState &state, TableFilterSet *table_filters);
15607
+ //! Scan
15608
+ void Scan(LocalScanState &state, const vector<column_t> &column_ids, DataChunk &result);
15609
+
15610
+ //! Append a chunk to the local storage
15611
+ void Append(DataTable *table, DataChunk &chunk);
15612
+ //! Delete a set of rows from the local storage
15613
+ idx_t Delete(DataTable *table, Vector &row_ids, idx_t count);
15614
+ //! Update a set of rows in the local storage
15615
+ void Update(DataTable *table, Vector &row_ids, const vector<column_t> &column_ids, DataChunk &data);
15616
+
15617
+ //! Commits the local storage, writing it to the WAL and completing the commit
15618
+ void Commit(LocalStorage::CommitState &commit_state, Transaction &transaction, WriteAheadLog *log,
15619
+ transaction_t commit_id);
15620
+
15621
+ bool ChangesMade() noexcept {
15622
+ return table_storage.size() > 0;
15623
+ }
15624
+ idx_t EstimatedSize();
15625
+
15626
+ bool Find(DataTable *table) {
15627
+ return table_storage.find(table) != table_storage.end();
15628
+ }
15629
+
15630
+ idx_t AddedRows(DataTable *table) {
15631
+ auto entry = table_storage.find(table);
15632
+ if (entry == table_storage.end()) {
15633
+ return 0;
15634
+ }
15635
+ return entry->second->collection.Count() - entry->second->deleted_rows;
15636
+ }
15637
+
15638
+ void AddColumn(DataTable *old_dt, DataTable *new_dt, ColumnDefinition &new_column, Expression *default_value);
15639
+ void ChangeType(DataTable *old_dt, DataTable *new_dt, idx_t changed_idx, const LogicalType &target_type,
15640
+ const vector<column_t> &bound_columns, Expression &cast_expr);
15641
+
15642
+ private:
15643
+ LocalTableStorage *GetStorage(DataTable *table);
15644
+
15645
+ template <class T>
15646
+ bool ScanTableStorage(DataTable &table, LocalTableStorage &storage, T &&fun);
15647
+
15648
+ private:
15649
+ Transaction &transaction;
15650
+ unordered_map<DataTable *, unique_ptr<LocalTableStorage>> table_storage;
15651
+
15652
+ void Flush(DataTable &table, LocalTableStorage &storage);
15653
+ };
15654
+
15655
+ } // namespace duckdb
15656
+
15657
+
15658
+
15659
+ namespace duckdb {
15660
+ class SequenceCatalogEntry;
15661
+
15662
+ class ColumnData;
15663
+ class ClientContext;
15664
+ class CatalogEntry;
15665
+ class DataTable;
15666
+ class DatabaseInstance;
15667
+ class WriteAheadLog;
15668
+
15669
+ class ChunkVectorInfo;
15670
+
15671
+ struct DeleteInfo;
15672
+ struct UpdateInfo;
15673
+
15674
+ //! The transaction object holds information about a currently running or past
15675
+ //! transaction
15676
+
15677
+ class Transaction {
15678
+ public:
15679
+ Transaction(weak_ptr<ClientContext> context, transaction_t start_time, transaction_t transaction_id,
15680
+ timestamp_t start_timestamp, idx_t catalog_version)
15681
+ : context(move(context)), start_time(start_time), transaction_id(transaction_id), commit_id(0),
15682
+ highest_active_query(0), active_query(MAXIMUM_QUERY_ID), start_timestamp(start_timestamp),
15683
+ catalog_version(catalog_version), storage(*this), is_invalidated(false) {
15684
+ }
15685
+
15686
+ weak_ptr<ClientContext> context;
15687
+ //! The start timestamp of this transaction
15688
+ transaction_t start_time;
15689
+ //! The transaction id of this transaction
15690
+ transaction_t transaction_id;
15691
+ //! The commit id of this transaction, if it has successfully been committed
15692
+ transaction_t commit_id;
15693
+ //! Highest active query when the transaction finished, used for cleaning up
15694
+ transaction_t highest_active_query;
15695
+ //! The current active query for the transaction. Set to MAXIMUM_QUERY_ID if
15696
+ //! no query is active.
15697
+ atomic<transaction_t> active_query;
15698
+ //! The timestamp when the transaction started
15699
+ timestamp_t start_timestamp;
15700
+ //! The catalog version when the transaction was started
15701
+ idx_t catalog_version;
15702
+ //! The set of uncommitted appends for the transaction
15703
+ LocalStorage storage;
15704
+ //! Map of all sequences that were used during the transaction and the value they had in this transaction
15705
+ unordered_map<SequenceCatalogEntry *, SequenceValue> sequence_usage;
15706
+ //! Whether or not the transaction has been invalidated
15707
+ bool is_invalidated;
15708
+
15709
+ public:
15710
+ static Transaction &GetTransaction(ClientContext &context);
15711
+
15712
+ void PushCatalogEntry(CatalogEntry *entry, data_ptr_t extra_data = nullptr, idx_t extra_data_size = 0);
15713
+
15714
+ //! Commit the current transaction with the given commit identifier. Returns an error message if the transaction
15715
+ //! commit failed, or an empty string if the commit was sucessful
15716
+ string Commit(DatabaseInstance &db, transaction_t commit_id, bool checkpoint) noexcept;
15717
+ //! Returns whether or not a commit of this transaction should trigger an automatic checkpoint
15718
+ bool AutomaticCheckpoint(DatabaseInstance &db);
15719
+
15720
+ //! Rollback
15721
+ void Rollback() noexcept {
15722
+ undo_buffer.Rollback();
15723
+ }
15724
+ //! Cleanup the undo buffer
15725
+ void Cleanup() {
15726
+ undo_buffer.Cleanup();
15727
+ }
15728
+
15729
+ void Invalidate() {
15730
+ is_invalidated = true;
15731
+ }
15732
+ bool IsInvalidated() {
15733
+ return is_invalidated;
15734
+ }
15735
+ bool ChangesMade();
15736
+
15737
+ timestamp_t GetCurrentTransactionStartTimestamp() {
15738
+ return start_timestamp;
15739
+ }
15740
+
15741
+ void PushDelete(DataTable *table, ChunkVectorInfo *vinfo, row_t rows[], idx_t count, idx_t base_row);
15742
+ void PushAppend(DataTable *table, idx_t row_start, idx_t row_count);
15743
+ UpdateInfo *CreateUpdateInfo(idx_t type_size, idx_t entries);
15744
+
15745
+ private:
15746
+ //! The undo buffer is used to store old versions of rows that are updated
15747
+ //! or deleted
15748
+ UndoBuffer undo_buffer;
15749
+
15750
+ Transaction(const Transaction &) = delete;
15751
+ };
15752
+
15753
+ } // namespace duckdb
15754
+
15755
+ #include <functional>
15756
+ #include <memory>
15757
+
15758
+ namespace duckdb {
15759
+ struct AlterInfo;
15760
+
15761
+ class ClientContext;
15762
+
15763
+ typedef unordered_map<CatalogSet *, unique_lock<mutex>> set_lock_map_t;
15764
+
15765
+ struct MappingValue {
15766
+ explicit MappingValue(idx_t index_) : index(index_), timestamp(0), deleted(false), parent(nullptr) {
15767
+ }
15768
+
15769
+ idx_t index;
15770
+ transaction_t timestamp;
15771
+ bool deleted;
15772
+ unique_ptr<MappingValue> child;
15773
+ MappingValue *parent;
15774
+ };
15775
+
15776
+ //! The Catalog Set stores (key, value) map of a set of CatalogEntries
15777
+ class CatalogSet {
15778
+ friend class DependencyManager;
15779
+ friend class EntryDropper;
15780
+
15781
+ public:
15782
+ DUCKDB_API explicit CatalogSet(Catalog &catalog, unique_ptr<DefaultGenerator> defaults = nullptr);
15783
+
15784
+ //! Create an entry in the catalog set. Returns whether or not it was
15785
+ //! successful.
15786
+ DUCKDB_API bool CreateEntry(ClientContext &context, const string &name, unique_ptr<CatalogEntry> value,
15787
+ unordered_set<CatalogEntry *> &dependencies);
15788
+
15789
+ DUCKDB_API bool AlterEntry(ClientContext &context, const string &name, AlterInfo *alter_info);
15790
+
15791
+ DUCKDB_API bool DropEntry(ClientContext &context, const string &name, bool cascade);
15792
+
15793
+ bool AlterOwnership(ClientContext &context, ChangeOwnershipInfo *info);
15794
+
15795
+ void CleanupEntry(CatalogEntry *catalog_entry);
15796
+
15797
+ //! Returns the entry with the specified name
15798
+ DUCKDB_API CatalogEntry *GetEntry(ClientContext &context, const string &name);
15799
+
15800
+ //! Gets the entry that is most similar to the given name (i.e. smallest levenshtein distance), or empty string if
15801
+ //! none is found. The returned pair consists of the entry name and the distance (smaller means closer).
15802
+ pair<string, idx_t> SimilarEntry(ClientContext &context, const string &name);
15803
+
15804
+ //! Rollback <entry> to be the currently valid entry for a certain catalog
15805
+ //! entry
15806
+ void Undo(CatalogEntry *entry);
15807
+
15808
+ //! Scan the catalog set, invoking the callback method for every committed entry
15809
+ DUCKDB_API void Scan(const std::function<void(CatalogEntry *)> &callback);
15810
+ //! Scan the catalog set, invoking the callback method for every entry
15811
+ DUCKDB_API void Scan(ClientContext &context, const std::function<void(CatalogEntry *)> &callback);
15812
+
15813
+ template <class T>
15814
+ vector<T *> GetEntries(ClientContext &context) {
15815
+ vector<T *> result;
15816
+ Scan(context, [&](CatalogEntry *entry) { result.push_back((T *)entry); });
15817
+ return result;
15818
+ }
15819
+
15820
+ DUCKDB_API static bool HasConflict(ClientContext &context, transaction_t timestamp);
15821
+ DUCKDB_API static bool UseTimestamp(ClientContext &context, transaction_t timestamp);
15822
+
15823
+ CatalogEntry *GetEntryFromIndex(idx_t index);
15824
+ void UpdateTimestamp(CatalogEntry *entry, transaction_t timestamp);
15825
+
15826
+ private:
15827
+ //! Adjusts table dependencies on the event of an UNDO
15828
+ void AdjustTableDependencies(CatalogEntry *entry);
15829
+ //! Adjust one dependency
15830
+ void AdjustDependency(CatalogEntry *entry, TableCatalogEntry *table, ColumnDefinition &column, bool remove);
15831
+ //! Adjust Enum dependency
15832
+ void AdjustEnumDependency(CatalogEntry *entry, ColumnDefinition &column, bool remove);
15833
+ //! Given a root entry, gets the entry valid for this transaction
15834
+ CatalogEntry *GetEntryForTransaction(ClientContext &context, CatalogEntry *current);
15835
+ CatalogEntry *GetCommittedEntry(CatalogEntry *current);
15836
+ bool GetEntryInternal(ClientContext &context, const string &name, idx_t &entry_index, CatalogEntry *&entry);
15837
+ bool GetEntryInternal(ClientContext &context, idx_t entry_index, CatalogEntry *&entry);
15838
+ //! Drops an entry from the catalog set; must hold the catalog_lock to safely call this
15839
+ void DropEntryInternal(ClientContext &context, idx_t entry_index, CatalogEntry &entry, bool cascade);
15840
+ CatalogEntry *CreateEntryInternal(ClientContext &context, unique_ptr<CatalogEntry> entry);
15841
+ MappingValue *GetMapping(ClientContext &context, const string &name, bool get_latest = false);
15842
+ void PutMapping(ClientContext &context, const string &name, idx_t entry_index);
15843
+ void DeleteMapping(ClientContext &context, const string &name);
15844
+ void DropEntryDependencies(ClientContext &context, idx_t entry_index, CatalogEntry &entry, bool cascade);
15845
+
15846
+ private:
15847
+ Catalog &catalog;
15848
+ //! The catalog lock is used to make changes to the data
15849
+ mutex catalog_lock;
15850
+ //! Mapping of string to catalog entry
15851
+ case_insensitive_map_t<unique_ptr<MappingValue>> mapping;
15852
+ //! The set of catalog entries
15853
+ unordered_map<idx_t, unique_ptr<CatalogEntry>> entries;
15854
+ //! The current catalog entry index
15855
+ idx_t current_entry = 0;
15856
+ //! The generator used to generate default internal entries
15857
+ unique_ptr<DefaultGenerator> defaults;
15858
+ };
15859
+ } // namespace duckdb
15860
+
15861
+
15862
+
15863
+ namespace duckdb {
15864
+ class ClientContext;
15865
+
15866
+ class StandardEntry;
15867
+ class TableCatalogEntry;
15868
+ class TableFunctionCatalogEntry;
15869
+ class SequenceCatalogEntry;
15870
+ class Serializer;
15871
+ class Deserializer;
15872
+
15873
+ enum class OnCreateConflict : uint8_t;
15874
+
15875
+ struct AlterTableInfo;
15876
+ struct CreateIndexInfo;
15877
+ struct CreateFunctionInfo;
15878
+ struct CreateCollationInfo;
15879
+ struct CreateViewInfo;
15880
+ struct BoundCreateTableInfo;
15881
+ struct CreatePragmaFunctionInfo;
15882
+ struct CreateSequenceInfo;
15883
+ struct CreateSchemaInfo;
15884
+ struct CreateTableFunctionInfo;
15885
+ struct CreateCopyFunctionInfo;
15886
+ struct CreateTypeInfo;
15887
+
15888
+ struct DropInfo;
15889
+
15890
+ //! A schema in the catalog
15891
+ class SchemaCatalogEntry : public CatalogEntry {
15892
+ friend class Catalog;
15893
+
15894
+ public:
15895
+ SchemaCatalogEntry(Catalog *catalog, string name, bool is_internal);
15896
+
15897
+ private:
15898
+ //! The catalog set holding the tables
15899
+ CatalogSet tables;
15900
+ //! The catalog set holding the indexes
15901
+ CatalogSet indexes;
15902
+ //! The catalog set holding the table functions
15903
+ CatalogSet table_functions;
15904
+ //! The catalog set holding the copy functions
15905
+ CatalogSet copy_functions;
15906
+ //! The catalog set holding the pragma functions
15907
+ CatalogSet pragma_functions;
15908
+ //! The catalog set holding the scalar and aggregate functions
15909
+ CatalogSet functions;
15910
+ //! The catalog set holding the sequences
15911
+ CatalogSet sequences;
15912
+ //! The catalog set holding the collations
15913
+ CatalogSet collations;
15914
+ //! The catalog set holding the types
15915
+ CatalogSet types;
15916
+
15917
+ public:
15918
+ //! Scan the specified catalog set, invoking the callback method for every entry
15919
+ void Scan(ClientContext &context, CatalogType type, const std::function<void(CatalogEntry *)> &callback);
15920
+ //! Scan the specified catalog set, invoking the callback method for every committed entry
15921
+ void Scan(CatalogType type, const std::function<void(CatalogEntry *)> &callback);
15922
+
15923
+ //! Serialize the meta information of the SchemaCatalogEntry a serializer
15924
+ virtual void Serialize(Serializer &serializer);
15925
+ //! Deserializes to a CreateSchemaInfo
15926
+ static unique_ptr<CreateSchemaInfo> Deserialize(Deserializer &source);
15927
+
15928
+ string ToSQL() override;
15929
+
15930
+ //! Creates an index with the given name in the schema
15931
+ CatalogEntry *CreateIndex(ClientContext &context, CreateIndexInfo *info, TableCatalogEntry *table);
15932
+
15933
+ private:
15934
+ //! Create a scalar or aggregate function within the given schema
15935
+ CatalogEntry *CreateFunction(ClientContext &context, CreateFunctionInfo *info);
15936
+ //! Creates a table with the given name in the schema
15937
+ CatalogEntry *CreateTable(ClientContext &context, BoundCreateTableInfo *info);
15938
+ //! Creates a view with the given name in the schema
15939
+ CatalogEntry *CreateView(ClientContext &context, CreateViewInfo *info);
15940
+ //! Creates a sequence with the given name in the schema
15941
+ CatalogEntry *CreateSequence(ClientContext &context, CreateSequenceInfo *info);
15942
+ //! Create a table function within the given schema
15943
+ CatalogEntry *CreateTableFunction(ClientContext &context, CreateTableFunctionInfo *info);
15944
+ //! Create a copy function within the given schema
15945
+ CatalogEntry *CreateCopyFunction(ClientContext &context, CreateCopyFunctionInfo *info);
15946
+ //! Create a pragma function within the given schema
15947
+ CatalogEntry *CreatePragmaFunction(ClientContext &context, CreatePragmaFunctionInfo *info);
15948
+ //! Create a collation within the given schema
15949
+ CatalogEntry *CreateCollation(ClientContext &context, CreateCollationInfo *info);
15950
+ //! Create a enum within the given schema
15951
+ CatalogEntry *CreateType(ClientContext &context, CreateTypeInfo *info);
15952
+
15953
+ //! Drops an entry from the schema
15954
+ void DropEntry(ClientContext &context, DropInfo *info);
15955
+
15956
+ //! Append a scalar or aggregate function within the given schema
15957
+ CatalogEntry *AddFunction(ClientContext &context, CreateFunctionInfo *info);
15958
+
15959
+ //! Alters a catalog entry
15960
+ void Alter(ClientContext &context, AlterInfo *info);
15961
+
15962
+ //! Add a catalog entry to this schema
15963
+ CatalogEntry *AddEntry(ClientContext &context, unique_ptr<StandardEntry> entry, OnCreateConflict on_conflict);
15964
+ //! Add a catalog entry to this schema
15965
+ CatalogEntry *AddEntry(ClientContext &context, unique_ptr<StandardEntry> entry, OnCreateConflict on_conflict,
15966
+ unordered_set<CatalogEntry *> dependencies);
15967
+
15968
+ //! Get the catalog set for the specified type
15969
+ CatalogSet &GetCatalogSet(CatalogType type);
15970
+ };
15971
+ } // namespace duckdb
15972
+
15973
+
15974
+ //===----------------------------------------------------------------------===//
15975
+ // DuckDB
15976
+ //
15977
+ // duckdb/common/deque.hpp
15978
+ //
15979
+ //
15980
+ //===----------------------------------------------------------------------===//
15981
+
15982
+
15983
+
15984
+ #include <deque>
15985
+
15986
+ namespace duckdb {
15987
+ using std::deque;
15988
+ }
15989
+
15990
+ //===----------------------------------------------------------------------===//
15991
+ // DuckDB
15992
+ //
15993
+ // duckdb/common/progress_bar.hpp
15994
+ //
15995
+ //
15996
+ //===----------------------------------------------------------------------===//
15997
+
15998
+
15999
+
16000
+ #ifndef DUCKDB_NO_THREADS
16001
+ //===----------------------------------------------------------------------===//
16002
+ // DuckDB
16003
+ //
16004
+ // duckdb/common/thread.hpp
16005
+ //
16006
+ //
16007
+ //===----------------------------------------------------------------------===//
16008
+
16009
+
16010
+
16011
+ #include <thread>
16012
+
16013
+ namespace duckdb {
16014
+ using std::thread;
16015
+ }
16016
+
16017
+ #include <future>
16018
+ #endif
16019
+
16020
+
16021
+ //===----------------------------------------------------------------------===//
16022
+ // DuckDB
16023
+ //
16024
+ // duckdb/execution/executor.hpp
16025
+ //
16026
+ //
16027
+ //===----------------------------------------------------------------------===//
16028
+
16029
+
16030
+
16031
+
16032
+
16033
+ //===----------------------------------------------------------------------===//
16034
+ // DuckDB
16035
+ //
16036
+ // duckdb/parallel/pipeline.hpp
16037
+ //
16038
+ //
16039
+ //===----------------------------------------------------------------------===//
16040
+
16041
+
16042
+
16043
+
16044
+ //===----------------------------------------------------------------------===//
16045
+ // DuckDB
16046
+ //
16047
+ // duckdb/execution/physical_operator.hpp
12716
16048
  //
12717
16049
  //
12718
16050
  //===----------------------------------------------------------------------===//
@@ -13042,155 +16374,6 @@ public:
13042
16374
 
13043
16375
  } // namespace duckdb
13044
16376
 
13045
- //===----------------------------------------------------------------------===//
13046
- // DuckDB
13047
- //
13048
- // duckdb/function/table_function.hpp
13049
- //
13050
- //
13051
- //===----------------------------------------------------------------------===//
13052
-
13053
-
13054
-
13055
-
13056
-
13057
-
13058
-
13059
- #include <functional>
13060
-
13061
- namespace duckdb {
13062
- class BaseStatistics;
13063
- class LogicalGet;
13064
- struct ParallelState;
13065
- class TableFilterSet;
13066
-
13067
- struct FunctionOperatorData {
13068
- DUCKDB_API virtual ~FunctionOperatorData();
13069
- };
13070
-
13071
- struct TableFilterCollection {
13072
- DUCKDB_API explicit TableFilterCollection(TableFilterSet *table_filters);
13073
-
13074
- TableFilterSet *table_filters;
13075
- };
13076
-
13077
- typedef unique_ptr<FunctionData> (*table_function_bind_t)(ClientContext &context, vector<Value> &inputs,
13078
- unordered_map<string, Value> &named_parameters,
13079
- vector<LogicalType> &input_table_types,
13080
- vector<string> &input_table_names,
13081
- vector<LogicalType> &return_types, vector<string> &names);
13082
- typedef unique_ptr<FunctionOperatorData> (*table_function_init_t)(ClientContext &context, const FunctionData *bind_data,
13083
- const vector<column_t> &column_ids,
13084
- TableFilterCollection *filters);
13085
- typedef unique_ptr<BaseStatistics> (*table_statistics_t)(ClientContext &context, const FunctionData *bind_data,
13086
- column_t column_index);
13087
- typedef void (*table_function_t)(ClientContext &context, const FunctionData *bind_data,
13088
- FunctionOperatorData *operator_state, DataChunk *input, DataChunk &output);
13089
-
13090
- typedef void (*table_function_parallel_t)(ClientContext &context, const FunctionData *bind_data,
13091
- FunctionOperatorData *operator_state, DataChunk *input, DataChunk &output,
13092
- ParallelState *parallel_state);
13093
-
13094
- typedef void (*table_function_cleanup_t)(ClientContext &context, const FunctionData *bind_data,
13095
- FunctionOperatorData *operator_state);
13096
- typedef idx_t (*table_function_max_threads_t)(ClientContext &context, const FunctionData *bind_data);
13097
- typedef unique_ptr<ParallelState> (*table_function_init_parallel_state_t)(ClientContext &context,
13098
- const FunctionData *bind_data,
13099
- const vector<column_t> &column_ids,
13100
- TableFilterCollection *filters);
13101
- typedef unique_ptr<FunctionOperatorData> (*table_function_init_parallel_t)(ClientContext &context,
13102
- const FunctionData *bind_data,
13103
- ParallelState *state,
13104
- const vector<column_t> &column_ids,
13105
- TableFilterCollection *filters);
13106
- typedef bool (*table_function_parallel_state_next_t)(ClientContext &context, const FunctionData *bind_data,
13107
- FunctionOperatorData *state, ParallelState *parallel_state);
13108
- typedef int (*table_function_progress_t)(ClientContext &context, const FunctionData *bind_data);
13109
- typedef void (*table_function_dependency_t)(unordered_set<CatalogEntry *> &dependencies, const FunctionData *bind_data);
13110
- typedef unique_ptr<NodeStatistics> (*table_function_cardinality_t)(ClientContext &context,
13111
- const FunctionData *bind_data);
13112
- typedef void (*table_function_pushdown_complex_filter_t)(ClientContext &context, LogicalGet &get,
13113
- FunctionData *bind_data,
13114
- vector<unique_ptr<Expression>> &filters);
13115
- typedef string (*table_function_to_string_t)(const FunctionData *bind_data);
13116
-
13117
- class TableFunction : public SimpleNamedParameterFunction {
13118
- public:
13119
- DUCKDB_API
13120
- TableFunction(string name, vector<LogicalType> arguments, table_function_t function,
13121
- table_function_bind_t bind = nullptr, table_function_init_t init = nullptr,
13122
- table_statistics_t statistics = nullptr, table_function_cleanup_t cleanup = nullptr,
13123
- table_function_dependency_t dependency = nullptr, table_function_cardinality_t cardinality = nullptr,
13124
- table_function_pushdown_complex_filter_t pushdown_complex_filter = nullptr,
13125
- table_function_to_string_t to_string = nullptr, table_function_max_threads_t max_threads = nullptr,
13126
- table_function_init_parallel_state_t init_parallel_state = nullptr,
13127
- table_function_parallel_t parallel_function = nullptr,
13128
- table_function_init_parallel_t parallel_init = nullptr,
13129
- table_function_parallel_state_next_t parallel_state_next = nullptr, bool projection_pushdown = false,
13130
- bool filter_pushdown = false, table_function_progress_t query_progress = nullptr);
13131
- DUCKDB_API
13132
- TableFunction(const vector<LogicalType> &arguments, table_function_t function, table_function_bind_t bind = nullptr,
13133
- table_function_init_t init = nullptr, table_statistics_t statistics = nullptr,
13134
- table_function_cleanup_t cleanup = nullptr, table_function_dependency_t dependency = nullptr,
13135
- table_function_cardinality_t cardinality = nullptr,
13136
- table_function_pushdown_complex_filter_t pushdown_complex_filter = nullptr,
13137
- table_function_to_string_t to_string = nullptr, table_function_max_threads_t max_threads = nullptr,
13138
- table_function_init_parallel_state_t init_parallel_state = nullptr,
13139
- table_function_parallel_t parallel_function = nullptr,
13140
- table_function_init_parallel_t parallel_init = nullptr,
13141
- table_function_parallel_state_next_t parallel_state_next = nullptr, bool projection_pushdown = false,
13142
- bool filter_pushdown = false, table_function_progress_t query_progress = nullptr);
13143
- DUCKDB_API TableFunction();
13144
-
13145
- //! Bind function
13146
- //! This function is used for determining the return type of a table producing function and returning bind data
13147
- //! The returned FunctionData object should be constant and should not be changed during execution.
13148
- table_function_bind_t bind;
13149
- //! (Optional) init function
13150
- //! Initialize the operator state of the function. The operator state is used to keep track of the progress in the
13151
- //! table function.
13152
- table_function_init_t init;
13153
- //! The main function
13154
- table_function_t function;
13155
- //! (Optional) statistics function
13156
- //! Returns the statistics of a specified column
13157
- table_statistics_t statistics;
13158
- //! (Optional) cleanup function
13159
- //! The final cleanup function, called after all data is exhausted from the main function
13160
- table_function_cleanup_t cleanup;
13161
- //! (Optional) dependency function
13162
- //! Sets up which catalog entries this table function depend on
13163
- table_function_dependency_t dependency;
13164
- //! (Optional) cardinality function
13165
- //! Returns the expected cardinality of this scan
13166
- table_function_cardinality_t cardinality;
13167
- //! (Optional) pushdown a set of arbitrary filter expressions, rather than only simple comparisons with a constant
13168
- //! Any functions remaining in the expression list will be pushed as a regular filter after the scan
13169
- table_function_pushdown_complex_filter_t pushdown_complex_filter;
13170
- //! (Optional) function for rendering the operator to a string in profiling output
13171
- table_function_to_string_t to_string;
13172
- //! (Optional) function that returns the maximum amount of threads that can work on this task
13173
- table_function_max_threads_t max_threads;
13174
- //! (Optional) initialize the parallel scan state, called once in total.
13175
- table_function_init_parallel_state_t init_parallel_state;
13176
- //! (Optional) Parallel version of the main function
13177
- table_function_parallel_t parallel_function;
13178
- //! (Optional) initialize the parallel scan given the parallel state. Called once per task. Return nullptr if there
13179
- //! is nothing left to scan.
13180
- table_function_init_parallel_t parallel_init;
13181
- //! (Optional) return the next chunk to process in the parallel scan, or return nullptr if there is none
13182
- table_function_parallel_state_next_t parallel_state_next;
13183
- //! (Optional) return how much of the table we have scanned up to this point (% of the data)
13184
- table_function_progress_t table_scan_progress;
13185
- //! Whether or not the table function supports projection pushdown. If not supported a projection will be added
13186
- //! that filters out unused columns.
13187
- bool projection_pushdown;
13188
- //! Whether or not the table function supports filter pushdown. If not supported a filter will be added
13189
- //! that applies the table filter directly.
13190
- bool filter_pushdown;
13191
- };
13192
-
13193
- } // namespace duckdb
13194
16377
 
13195
16378
  //===----------------------------------------------------------------------===//
13196
16379
  // DuckDB
@@ -13911,84 +17094,6 @@ private:
13911
17094
 
13912
17095
 
13913
17096
 
13914
- //===----------------------------------------------------------------------===//
13915
- // DuckDB
13916
- //
13917
- // duckdb/parser/parsed_data/create_info.hpp
13918
- //
13919
- //
13920
- //===----------------------------------------------------------------------===//
13921
-
13922
-
13923
-
13924
- //===----------------------------------------------------------------------===//
13925
- // DuckDB
13926
- //
13927
- // duckdb/parser/parsed_data/parse_info.hpp
13928
- //
13929
- //
13930
- //===----------------------------------------------------------------------===//
13931
-
13932
-
13933
-
13934
-
13935
-
13936
- namespace duckdb {
13937
-
13938
- struct ParseInfo {
13939
- virtual ~ParseInfo() {
13940
- }
13941
- };
13942
-
13943
- } // namespace duckdb
13944
-
13945
-
13946
-
13947
- namespace duckdb {
13948
-
13949
- enum class OnCreateConflict : uint8_t {
13950
- // Standard: throw error
13951
- ERROR_ON_CONFLICT,
13952
- // CREATE IF NOT EXISTS, silently do nothing on conflict
13953
- IGNORE_ON_CONFLICT,
13954
- // CREATE OR REPLACE
13955
- REPLACE_ON_CONFLICT
13956
- };
13957
-
13958
- struct CreateInfo : public ParseInfo {
13959
- explicit CreateInfo(CatalogType type, string schema = DEFAULT_SCHEMA)
13960
- : type(type), schema(schema), on_conflict(OnCreateConflict::ERROR_ON_CONFLICT), temporary(false),
13961
- internal(false) {
13962
- }
13963
- ~CreateInfo() override {
13964
- }
13965
-
13966
- //! The to-be-created catalog type
13967
- CatalogType type;
13968
- //! The schema name of the entry
13969
- string schema;
13970
- //! What to do on create conflict
13971
- OnCreateConflict on_conflict;
13972
- //! Whether or not the entry is temporary
13973
- bool temporary;
13974
- //! Whether or not the entry is an internal entry
13975
- bool internal;
13976
- //! The SQL string of the CREATE statement
13977
- string sql;
13978
-
13979
- public:
13980
- virtual unique_ptr<CreateInfo> Copy() const = 0;
13981
- void CopyProperties(CreateInfo &other) const {
13982
- other.type = type;
13983
- other.schema = schema;
13984
- other.on_conflict = on_conflict;
13985
- other.temporary = temporary;
13986
- other.internal = internal;
13987
- other.sql = sql;
13988
- }
13989
- };
13990
-
13991
- } // namespace duckdb
13992
17097
 
13993
17098
 
13994
17099