duckdb 0.3.2-dev722.0 → 0.3.2-dev741.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/duckdb.hpp CHANGED
@@ -10,8 +10,9 @@ 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 "f9e6e8675"
14
- #define DUCKDB_VERSION "0.3.2-dev722"
13
+ #define DUCKDB_AMALGAMATION_EXTENDED 1
14
+ #define DUCKDB_SOURCE_ID "3a66c6b20"
15
+ #define DUCKDB_VERSION "0.3.2-dev741"
15
16
  //===----------------------------------------------------------------------===//
16
17
  // DuckDB
17
18
  //
@@ -17586,3 +17587,4548 @@ public:
17586
17587
  };
17587
17588
 
17588
17589
  } // namespace duckdb
17590
+ //===----------------------------------------------------------------------===//
17591
+ // DuckDB
17592
+ //
17593
+ // duckdb/catalog/catalog_entry/scalar_function_catalog_entry.hpp
17594
+ //
17595
+ //
17596
+ //===----------------------------------------------------------------------===//
17597
+
17598
+
17599
+
17600
+
17601
+
17602
+
17603
+ //===----------------------------------------------------------------------===//
17604
+ // DuckDB
17605
+ //
17606
+ // duckdb/parser/parsed_data/create_scalar_function_info.hpp
17607
+ //
17608
+ //
17609
+ //===----------------------------------------------------------------------===//
17610
+
17611
+
17612
+
17613
+
17614
+
17615
+
17616
+
17617
+ namespace duckdb {
17618
+
17619
+ struct CreateScalarFunctionInfo : public CreateFunctionInfo {
17620
+ explicit CreateScalarFunctionInfo(ScalarFunction function)
17621
+ : CreateFunctionInfo(CatalogType::SCALAR_FUNCTION_ENTRY) {
17622
+ this->name = function.name;
17623
+ functions.push_back(function);
17624
+ }
17625
+ explicit CreateScalarFunctionInfo(ScalarFunctionSet set)
17626
+ : CreateFunctionInfo(CatalogType::SCALAR_FUNCTION_ENTRY), functions(move(set.functions)) {
17627
+ this->name = set.name;
17628
+ for (auto &func : functions) {
17629
+ func.name = set.name;
17630
+ }
17631
+ }
17632
+
17633
+ vector<ScalarFunction> functions;
17634
+
17635
+ public:
17636
+ unique_ptr<CreateInfo> Copy() const override {
17637
+ ScalarFunctionSet set(name);
17638
+ set.functions = functions;
17639
+ auto result = make_unique<CreateScalarFunctionInfo>(move(set));
17640
+ CopyProperties(*result);
17641
+ return move(result);
17642
+ }
17643
+ };
17644
+
17645
+ } // namespace duckdb
17646
+
17647
+
17648
+ namespace duckdb {
17649
+
17650
+ //! A table function in the catalog
17651
+ class ScalarFunctionCatalogEntry : public StandardEntry {
17652
+ public:
17653
+ ScalarFunctionCatalogEntry(Catalog *catalog, SchemaCatalogEntry *schema, CreateScalarFunctionInfo *info)
17654
+ : StandardEntry(CatalogType::SCALAR_FUNCTION_ENTRY, schema, catalog, info->name), functions(info->functions) {
17655
+ }
17656
+
17657
+ //! The scalar functions
17658
+ vector<ScalarFunction> functions;
17659
+ };
17660
+ } // namespace duckdb
17661
+ //===----------------------------------------------------------------------===//
17662
+ // DuckDB
17663
+ //
17664
+ // duckdb/parser/parsed_data/create_table_info.hpp
17665
+ //
17666
+ //
17667
+ //===----------------------------------------------------------------------===//
17668
+
17669
+
17670
+
17671
+
17672
+
17673
+
17674
+
17675
+
17676
+
17677
+ namespace duckdb {
17678
+
17679
+ struct CreateTableInfo : public CreateInfo {
17680
+ CreateTableInfo() : CreateInfo(CatalogType::TABLE_ENTRY, INVALID_SCHEMA) {
17681
+ }
17682
+ CreateTableInfo(string schema, string name) : CreateInfo(CatalogType::TABLE_ENTRY, schema), table(name) {
17683
+ }
17684
+
17685
+ //! Table name to insert to
17686
+ string table;
17687
+ //! List of columns of the table
17688
+ vector<ColumnDefinition> columns;
17689
+ //! List of constraints on the table
17690
+ vector<unique_ptr<Constraint>> constraints;
17691
+ //! CREATE TABLE from QUERY
17692
+ unique_ptr<SelectStatement> query;
17693
+
17694
+ public:
17695
+ unique_ptr<CreateInfo> Copy() const override {
17696
+ auto result = make_unique<CreateTableInfo>(schema, table);
17697
+ CopyProperties(*result);
17698
+ for (auto &column : columns) {
17699
+ result->columns.push_back(column.Copy());
17700
+ }
17701
+ for (auto &constraint : constraints) {
17702
+ result->constraints.push_back(constraint->Copy());
17703
+ }
17704
+ if (query) {
17705
+ result->query = unique_ptr_cast<SQLStatement, SelectStatement>(query->Copy());
17706
+ }
17707
+ return move(result);
17708
+ }
17709
+ };
17710
+
17711
+ } // namespace duckdb
17712
+ //===----------------------------------------------------------------------===//
17713
+ // DuckDB
17714
+ //
17715
+ // duckdb/planner/parsed_data/bound_create_table_info.hpp
17716
+ //
17717
+ //
17718
+ //===----------------------------------------------------------------------===//
17719
+
17720
+
17721
+
17722
+
17723
+
17724
+
17725
+
17726
+ //===----------------------------------------------------------------------===//
17727
+ // DuckDB
17728
+ //
17729
+ // duckdb/storage/table/persistent_table_data.hpp
17730
+ //
17731
+ //
17732
+ //===----------------------------------------------------------------------===//
17733
+
17734
+
17735
+
17736
+
17737
+
17738
+ //===----------------------------------------------------------------------===//
17739
+ // DuckDB
17740
+ //
17741
+ // duckdb/storage/table/segment_tree.hpp
17742
+ //
17743
+ //
17744
+ //===----------------------------------------------------------------------===//
17745
+
17746
+
17747
+
17748
+
17749
+
17750
+ //===----------------------------------------------------------------------===//
17751
+ // DuckDB
17752
+ //
17753
+ // duckdb/storage/table/segment_base.hpp
17754
+ //
17755
+ //
17756
+ //===----------------------------------------------------------------------===//
17757
+
17758
+
17759
+
17760
+
17761
+
17762
+
17763
+ namespace duckdb {
17764
+
17765
+ class SegmentBase {
17766
+ public:
17767
+ SegmentBase(idx_t start, idx_t count) : start(start), count(count) {
17768
+ }
17769
+ virtual ~SegmentBase() {
17770
+ // destroy the chain of segments iteratively (rather than recursively)
17771
+ while (next && next->next) {
17772
+ next = move(next->next);
17773
+ }
17774
+ }
17775
+
17776
+ //! The start row id of this chunk
17777
+ const idx_t start;
17778
+ //! The amount of entries in this storage chunk
17779
+ atomic<idx_t> count;
17780
+ //! The next segment after this one
17781
+ unique_ptr<SegmentBase> next;
17782
+ };
17783
+
17784
+ } // namespace duckdb
17785
+
17786
+
17787
+
17788
+
17789
+ namespace duckdb {
17790
+
17791
+ struct SegmentNode {
17792
+ idx_t row_start;
17793
+ SegmentBase *node;
17794
+ };
17795
+
17796
+ //! The SegmentTree maintains a list of all segments of a specific column in a table, and allows searching for a segment
17797
+ //! by row number
17798
+ class SegmentTree {
17799
+ public:
17800
+ //! The initial segment of the tree
17801
+ unique_ptr<SegmentBase> root_node;
17802
+ //! The nodes in the tree, can be binary searched
17803
+ vector<SegmentNode> nodes;
17804
+ //! Lock to access or modify the nodes
17805
+ mutex node_lock;
17806
+
17807
+ public:
17808
+ //! Gets a pointer to the first segment. Useful for scans.
17809
+ SegmentBase *GetRootSegment();
17810
+ //! Gets a pointer to the last segment. Useful for appends.
17811
+ SegmentBase *GetLastSegment();
17812
+ //! Gets a pointer to a specific column segment for the given row
17813
+ SegmentBase *GetSegment(idx_t row_number);
17814
+ //! Append a column segment to the tree
17815
+ void AppendSegment(unique_ptr<SegmentBase> segment);
17816
+
17817
+ //! Replace this tree with another tree, taking over its nodes in-place
17818
+ void Replace(SegmentTree &other);
17819
+
17820
+ //! Get the segment index of the column segment for the given row (does not lock the segment tree!)
17821
+ idx_t GetSegmentIndex(idx_t row_number);
17822
+ };
17823
+
17824
+ } // namespace duckdb
17825
+
17826
+ //===----------------------------------------------------------------------===//
17827
+ // DuckDB
17828
+ //
17829
+ // duckdb/storage/data_pointer.hpp
17830
+ //
17831
+ //
17832
+ //===----------------------------------------------------------------------===//
17833
+
17834
+
17835
+
17836
+
17837
+
17838
+
17839
+ //===----------------------------------------------------------------------===//
17840
+ // DuckDB
17841
+ //
17842
+ // duckdb/storage/block.hpp
17843
+ //
17844
+ //
17845
+ //===----------------------------------------------------------------------===//
17846
+
17847
+
17848
+
17849
+
17850
+
17851
+
17852
+
17853
+ namespace duckdb {
17854
+
17855
+ class Block : public FileBuffer {
17856
+ public:
17857
+ Block(Allocator &allocator, block_id_t id);
17858
+ Block(FileBuffer &source, block_id_t id);
17859
+
17860
+ block_id_t id;
17861
+ };
17862
+
17863
+ struct BlockPointer {
17864
+ block_id_t block_id;
17865
+ uint32_t offset;
17866
+ };
17867
+
17868
+ } // namespace duckdb
17869
+
17870
+ //===----------------------------------------------------------------------===//
17871
+ // DuckDB
17872
+ //
17873
+ // duckdb/storage/table/row_group.hpp
17874
+ //
17875
+ //
17876
+ //===----------------------------------------------------------------------===//
17877
+
17878
+
17879
+
17880
+
17881
+
17882
+ //===----------------------------------------------------------------------===//
17883
+ // DuckDB
17884
+ //
17885
+ // duckdb/storage/table/chunk_info.hpp
17886
+ //
17887
+ //
17888
+ //===----------------------------------------------------------------------===//
17889
+
17890
+
17891
+
17892
+
17893
+
17894
+
17895
+
17896
+ namespace duckdb {
17897
+ class RowGroup;
17898
+ struct SelectionVector;
17899
+ class Transaction;
17900
+
17901
+ enum class ChunkInfoType : uint8_t { CONSTANT_INFO, VECTOR_INFO, EMPTY_INFO };
17902
+
17903
+ class ChunkInfo {
17904
+ public:
17905
+ ChunkInfo(idx_t start, ChunkInfoType type) : start(start), type(type) {
17906
+ }
17907
+ virtual ~ChunkInfo() {
17908
+ }
17909
+
17910
+ //! The row index of the first row
17911
+ idx_t start;
17912
+ //! The ChunkInfo type
17913
+ ChunkInfoType type;
17914
+
17915
+ public:
17916
+ //! Gets up to max_count entries from the chunk info. If the ret is 0>ret>max_count, the selection vector is filled
17917
+ //! with the tuples
17918
+ virtual idx_t GetSelVector(Transaction &transaction, SelectionVector &sel_vector, idx_t max_count) = 0;
17919
+ virtual idx_t GetCommittedSelVector(transaction_t min_start_id, transaction_t min_transaction_id,
17920
+ SelectionVector &sel_vector, idx_t max_count) = 0;
17921
+ //! Returns whether or not a single row in the ChunkInfo should be used or not for the given transaction
17922
+ virtual bool Fetch(Transaction &transaction, row_t row) = 0;
17923
+ virtual void CommitAppend(transaction_t commit_id, idx_t start, idx_t end) = 0;
17924
+
17925
+ virtual void Serialize(Serializer &serialize) = 0;
17926
+ static unique_ptr<ChunkInfo> Deserialize(Deserializer &source);
17927
+ };
17928
+
17929
+ class ChunkConstantInfo : public ChunkInfo {
17930
+ public:
17931
+ ChunkConstantInfo(idx_t start);
17932
+
17933
+ atomic<transaction_t> insert_id;
17934
+ atomic<transaction_t> delete_id;
17935
+
17936
+ public:
17937
+ idx_t GetSelVector(Transaction &transaction, SelectionVector &sel_vector, idx_t max_count) override;
17938
+ idx_t GetCommittedSelVector(transaction_t min_start_id, transaction_t min_transaction_id,
17939
+ SelectionVector &sel_vector, idx_t max_count) override;
17940
+ bool Fetch(Transaction &transaction, row_t row) override;
17941
+ void CommitAppend(transaction_t commit_id, idx_t start, idx_t end) override;
17942
+
17943
+ void Serialize(Serializer &serialize) override;
17944
+ static unique_ptr<ChunkInfo> Deserialize(Deserializer &source);
17945
+
17946
+ private:
17947
+ template <class OP>
17948
+ idx_t TemplatedGetSelVector(transaction_t start_time, transaction_t transaction_id, SelectionVector &sel_vector,
17949
+ idx_t max_count);
17950
+ };
17951
+
17952
+ class ChunkVectorInfo : public ChunkInfo {
17953
+ public:
17954
+ ChunkVectorInfo(idx_t start);
17955
+
17956
+ //! The transaction ids of the transactions that inserted the tuples (if any)
17957
+ atomic<transaction_t> inserted[STANDARD_VECTOR_SIZE];
17958
+ atomic<transaction_t> insert_id;
17959
+ atomic<bool> same_inserted_id;
17960
+
17961
+ //! The transaction ids of the transactions that deleted the tuples (if any)
17962
+ atomic<transaction_t> deleted[STANDARD_VECTOR_SIZE];
17963
+ atomic<bool> any_deleted;
17964
+
17965
+ public:
17966
+ idx_t GetSelVector(transaction_t start_time, transaction_t transaction_id, SelectionVector &sel_vector,
17967
+ idx_t max_count);
17968
+ idx_t GetSelVector(Transaction &transaction, SelectionVector &sel_vector, idx_t max_count) override;
17969
+ idx_t GetCommittedSelVector(transaction_t min_start_id, transaction_t min_transaction_id,
17970
+ SelectionVector &sel_vector, idx_t max_count) override;
17971
+ bool Fetch(Transaction &transaction, row_t row) override;
17972
+ void CommitAppend(transaction_t commit_id, idx_t start, idx_t end) override;
17973
+
17974
+ void Append(idx_t start, idx_t end, transaction_t commit_id);
17975
+ idx_t Delete(Transaction &transaction, row_t rows[], idx_t count);
17976
+ void CommitDelete(transaction_t commit_id, row_t rows[], idx_t count);
17977
+
17978
+ void Serialize(Serializer &serialize) override;
17979
+ static unique_ptr<ChunkInfo> Deserialize(Deserializer &source);
17980
+
17981
+ private:
17982
+ template <class OP>
17983
+ idx_t TemplatedGetSelVector(transaction_t start_time, transaction_t transaction_id, SelectionVector &sel_vector,
17984
+ idx_t max_count);
17985
+ };
17986
+
17987
+ } // namespace duckdb
17988
+
17989
+ //===----------------------------------------------------------------------===//
17990
+ // DuckDB
17991
+ //
17992
+ // duckdb/storage/table/append_state.hpp
17993
+ //
17994
+ //
17995
+ //===----------------------------------------------------------------------===//
17996
+
17997
+
17998
+
17999
+
18000
+
18001
+
18002
+
18003
+
18004
+ namespace duckdb {
18005
+ class ColumnSegment;
18006
+ class DataTable;
18007
+ class RowGroup;
18008
+ class UpdateSegment;
18009
+ class ValiditySegment;
18010
+
18011
+ struct TableAppendState;
18012
+
18013
+ struct ColumnAppendState {
18014
+ //! The current segment of the append
18015
+ ColumnSegment *current;
18016
+ //! Child append states
18017
+ vector<ColumnAppendState> child_appends;
18018
+ //! The write lock that is held by the append
18019
+ unique_ptr<StorageLockKey> lock;
18020
+ };
18021
+
18022
+ struct RowGroupAppendState {
18023
+ RowGroupAppendState(TableAppendState &parent_p) : parent(parent_p) {
18024
+ }
18025
+
18026
+ //! The parent append state
18027
+ TableAppendState &parent;
18028
+ //! The current row_group we are appending to
18029
+ RowGroup *row_group;
18030
+ //! The column append states
18031
+ unique_ptr<ColumnAppendState[]> states;
18032
+ //! Offset within the row_group
18033
+ idx_t offset_in_row_group;
18034
+ };
18035
+
18036
+ struct IndexLock {
18037
+ unique_lock<mutex> index_lock;
18038
+ };
18039
+
18040
+ struct TableAppendState {
18041
+ TableAppendState() : row_group_append_state(*this) {
18042
+ }
18043
+
18044
+ RowGroupAppendState row_group_append_state;
18045
+ unique_lock<mutex> append_lock;
18046
+ row_t row_start;
18047
+ row_t current_row;
18048
+ idx_t remaining_append_count;
18049
+ };
18050
+
18051
+ } // namespace duckdb
18052
+
18053
+
18054
+ //===----------------------------------------------------------------------===//
18055
+ // DuckDB
18056
+ //
18057
+ // duckdb/storage/statistics/segment_statistics.hpp
18058
+ //
18059
+ //
18060
+ //===----------------------------------------------------------------------===//
18061
+
18062
+
18063
+
18064
+
18065
+
18066
+
18067
+
18068
+ namespace duckdb {
18069
+
18070
+ class SegmentStatistics {
18071
+ public:
18072
+ SegmentStatistics(LogicalType type);
18073
+ SegmentStatistics(LogicalType type, unique_ptr<BaseStatistics> statistics);
18074
+
18075
+ LogicalType type;
18076
+
18077
+ //! Type-specific statistics of the segment
18078
+ unique_ptr<BaseStatistics> statistics;
18079
+
18080
+ public:
18081
+ void Reset();
18082
+ };
18083
+
18084
+ } // namespace duckdb
18085
+
18086
+ //===----------------------------------------------------------------------===//
18087
+ // DuckDB
18088
+ //
18089
+ // duckdb/common/enums/scan_options.hpp
18090
+ //
18091
+ //
18092
+ //===----------------------------------------------------------------------===//
18093
+
18094
+
18095
+
18096
+
18097
+
18098
+ namespace duckdb {
18099
+
18100
+ enum class TableScanType : uint8_t {
18101
+ //! Regular table scan: scan all tuples that are relevant for the current transaction
18102
+ TABLE_SCAN_REGULAR = 0,
18103
+ //! Scan all rows, including any deleted rows. Committed updates are merged in.
18104
+ TABLE_SCAN_COMMITTED_ROWS = 1,
18105
+ //! Scan all rows, including any deleted rows. Throws an exception if there are any uncommitted updates.
18106
+ TABLE_SCAN_COMMITTED_ROWS_DISALLOW_UPDATES = 2,
18107
+ //! Scan all rows, excluding any permanently deleted rows.
18108
+ //! Permanently deleted rows are rows which no transaction will ever need again.
18109
+ TABLE_SCAN_COMMITTED_ROWS_OMIT_PERMANENTLY_DELETED = 3
18110
+ };
18111
+
18112
+ } // namespace duckdb
18113
+
18114
+
18115
+
18116
+ namespace duckdb {
18117
+ class ColumnData;
18118
+ class DatabaseInstance;
18119
+ class DataTable;
18120
+ struct DataTableInfo;
18121
+ class ExpressionExecutor;
18122
+ class TableDataWriter;
18123
+ class UpdateSegment;
18124
+ class Vector;
18125
+ struct RowGroupPointer;
18126
+ struct VersionNode;
18127
+
18128
+ class RowGroup : public SegmentBase {
18129
+ public:
18130
+ friend class ColumnData;
18131
+ friend class VersionDeleteState;
18132
+
18133
+ public:
18134
+ static constexpr const idx_t ROW_GROUP_VECTOR_COUNT = 120;
18135
+ static constexpr const idx_t ROW_GROUP_SIZE = STANDARD_VECTOR_SIZE * ROW_GROUP_VECTOR_COUNT;
18136
+
18137
+ public:
18138
+ RowGroup(DatabaseInstance &db, DataTableInfo &table_info, idx_t start, idx_t count);
18139
+ RowGroup(DatabaseInstance &db, DataTableInfo &table_info, const vector<LogicalType> &types,
18140
+ RowGroupPointer &pointer);
18141
+ ~RowGroup();
18142
+
18143
+ private:
18144
+ //! The database instance
18145
+ DatabaseInstance &db;
18146
+ //! The table info of this row_group
18147
+ DataTableInfo &table_info;
18148
+ //! The version info of the row_group (inserted and deleted tuple info)
18149
+ shared_ptr<VersionNode> version_info;
18150
+ //! The column data of the row_group
18151
+ vector<shared_ptr<ColumnData>> columns;
18152
+ //! The segment statistics for each of the columns
18153
+ vector<shared_ptr<SegmentStatistics>> stats;
18154
+
18155
+ public:
18156
+ DatabaseInstance &GetDatabase() {
18157
+ return db;
18158
+ }
18159
+ DataTableInfo &GetTableInfo() {
18160
+ return table_info;
18161
+ }
18162
+ idx_t GetColumnIndex(ColumnData *data) {
18163
+ for (idx_t i = 0; i < columns.size(); i++) {
18164
+ if (columns[i].get() == data) {
18165
+ return i;
18166
+ }
18167
+ }
18168
+ return 0;
18169
+ }
18170
+
18171
+ unique_ptr<RowGroup> AlterType(ClientContext &context, const LogicalType &target_type, idx_t changed_idx,
18172
+ ExpressionExecutor &executor, TableScanState &scan_state, DataChunk &scan_chunk);
18173
+ unique_ptr<RowGroup> AddColumn(ClientContext &context, ColumnDefinition &new_column, ExpressionExecutor &executor,
18174
+ Expression *default_value, Vector &intermediate);
18175
+ unique_ptr<RowGroup> RemoveColumn(idx_t removed_column);
18176
+
18177
+ void CommitDrop();
18178
+ void CommitDropColumn(idx_t index);
18179
+
18180
+ void InitializeEmpty(const vector<LogicalType> &types);
18181
+
18182
+ //! Initialize a scan over this row_group
18183
+ bool InitializeScan(RowGroupScanState &state);
18184
+ bool InitializeScanWithOffset(RowGroupScanState &state, idx_t vector_offset);
18185
+ //! Checks the given set of table filters against the row-group statistics. Returns false if the entire row group
18186
+ //! can be skipped.
18187
+ bool CheckZonemap(TableFilterSet &filters, const vector<column_t> &column_ids);
18188
+ //! Checks the given set of table filters against the per-segment statistics. Returns false if any segments were
18189
+ //! skipped.
18190
+ bool CheckZonemapSegments(RowGroupScanState &state);
18191
+ void Scan(Transaction &transaction, RowGroupScanState &state, DataChunk &result);
18192
+ void ScanCommitted(RowGroupScanState &state, DataChunk &result, TableScanType type);
18193
+
18194
+ idx_t GetSelVector(Transaction &transaction, idx_t vector_idx, SelectionVector &sel_vector, idx_t max_count);
18195
+ idx_t GetCommittedSelVector(transaction_t start_time, transaction_t transaction_id, idx_t vector_idx,
18196
+ SelectionVector &sel_vector, idx_t max_count);
18197
+
18198
+ //! For a specific row, returns true if it should be used for the transaction and false otherwise.
18199
+ bool Fetch(Transaction &transaction, idx_t row);
18200
+ //! Fetch a specific row from the row_group and insert it into the result at the specified index
18201
+ void FetchRow(Transaction &transaction, ColumnFetchState &state, const vector<column_t> &column_ids, row_t row_id,
18202
+ DataChunk &result, idx_t result_idx);
18203
+
18204
+ //! Append count rows to the version info
18205
+ void AppendVersionInfo(Transaction &transaction, idx_t start, idx_t count, transaction_t commit_id);
18206
+ //! Commit a previous append made by RowGroup::AppendVersionInfo
18207
+ void CommitAppend(transaction_t commit_id, idx_t start, idx_t count);
18208
+ //! Revert a previous append made by RowGroup::AppendVersionInfo
18209
+ void RevertAppend(idx_t start);
18210
+
18211
+ //! Delete the given set of rows in the version manager
18212
+ idx_t Delete(Transaction &transaction, DataTable *table, row_t *row_ids, idx_t count);
18213
+
18214
+ RowGroupPointer Checkpoint(TableDataWriter &writer, vector<unique_ptr<BaseStatistics>> &global_stats);
18215
+ static void Serialize(RowGroupPointer &pointer, Serializer &serializer);
18216
+ static RowGroupPointer Deserialize(Deserializer &source, const vector<ColumnDefinition> &columns);
18217
+
18218
+ void InitializeAppend(Transaction &transaction, RowGroupAppendState &append_state, idx_t remaining_append_count);
18219
+ void Append(RowGroupAppendState &append_state, DataChunk &chunk, idx_t append_count);
18220
+
18221
+ void Update(Transaction &transaction, DataChunk &updates, row_t *ids, idx_t offset, idx_t count,
18222
+ const vector<column_t> &column_ids);
18223
+ //! Update a single column; corresponds to DataTable::UpdateColumn
18224
+ //! This method should only be called from the WAL
18225
+ void UpdateColumn(Transaction &transaction, DataChunk &updates, Vector &row_ids,
18226
+ const vector<column_t> &column_path);
18227
+
18228
+ void MergeStatistics(idx_t column_idx, BaseStatistics &other);
18229
+ unique_ptr<BaseStatistics> GetStatistics(idx_t column_idx);
18230
+
18231
+ void GetStorageInfo(idx_t row_group_index, vector<vector<Value>> &result);
18232
+
18233
+ void Verify();
18234
+
18235
+ void NextVector(RowGroupScanState &state);
18236
+
18237
+ private:
18238
+ ChunkInfo *GetChunkInfo(idx_t vector_idx);
18239
+
18240
+ template <TableScanType TYPE>
18241
+ void TemplatedScan(Transaction *transaction, RowGroupScanState &state, DataChunk &result);
18242
+
18243
+ static void CheckpointDeletes(VersionNode *versions, Serializer &serializer);
18244
+ static shared_ptr<VersionNode> DeserializeDeletes(Deserializer &source);
18245
+
18246
+ private:
18247
+ mutex row_group_lock;
18248
+ mutex stats_lock;
18249
+ };
18250
+
18251
+ struct VersionNode {
18252
+ unique_ptr<ChunkInfo> info[RowGroup::ROW_GROUP_VECTOR_COUNT];
18253
+ };
18254
+
18255
+ } // namespace duckdb
18256
+
18257
+
18258
+
18259
+ namespace duckdb {
18260
+
18261
+ struct DataPointer {
18262
+ uint64_t row_start;
18263
+ uint64_t tuple_count;
18264
+ BlockPointer block_pointer;
18265
+ CompressionType compression_type;
18266
+ //! Type-specific statistics of the segment
18267
+ unique_ptr<BaseStatistics> statistics;
18268
+ };
18269
+
18270
+ struct RowGroupPointer {
18271
+ uint64_t row_start;
18272
+ uint64_t tuple_count;
18273
+ //! The data pointers of the column segments stored in the row group
18274
+ vector<BlockPointer> data_pointers;
18275
+ //! The per-column statistics of the row group
18276
+ vector<unique_ptr<BaseStatistics>> statistics;
18277
+ //! The versions information of the row group (if any)
18278
+ shared_ptr<VersionNode> versions;
18279
+ };
18280
+
18281
+ } // namespace duckdb
18282
+
18283
+
18284
+ namespace duckdb {
18285
+ class BaseStatistics;
18286
+
18287
+ class PersistentTableData {
18288
+ public:
18289
+ explicit PersistentTableData(idx_t column_count);
18290
+ ~PersistentTableData();
18291
+
18292
+ vector<RowGroupPointer> row_groups;
18293
+ vector<unique_ptr<BaseStatistics>> column_stats;
18294
+ };
18295
+
18296
+ } // namespace duckdb
18297
+
18298
+
18299
+
18300
+ namespace duckdb {
18301
+ class CatalogEntry;
18302
+
18303
+ struct BoundCreateTableInfo {
18304
+ explicit BoundCreateTableInfo(unique_ptr<CreateInfo> base) : base(move(base)) {
18305
+ }
18306
+
18307
+ //! The schema to create the table in
18308
+ SchemaCatalogEntry *schema;
18309
+ //! The base CreateInfo object
18310
+ unique_ptr<CreateInfo> base;
18311
+ //! The map of column names -> column index, used during binding
18312
+ case_insensitive_map_t<column_t> name_map;
18313
+ //! List of constraints on the table
18314
+ vector<unique_ptr<Constraint>> constraints;
18315
+ //! List of bound constraints on the table
18316
+ vector<unique_ptr<BoundConstraint>> bound_constraints;
18317
+ //! Bound default values
18318
+ vector<unique_ptr<Expression>> bound_defaults;
18319
+ //! Dependents of the table (in e.g. default values)
18320
+ unordered_set<CatalogEntry *> dependencies;
18321
+ //! The existing table data on disk (if any)
18322
+ unique_ptr<PersistentTableData> data;
18323
+ //! CREATE TABLE from QUERY
18324
+ unique_ptr<LogicalOperator> query;
18325
+
18326
+ CreateTableInfo &Base() {
18327
+ return (CreateTableInfo &)*base;
18328
+ }
18329
+ };
18330
+
18331
+ } // namespace duckdb
18332
+ //===----------------------------------------------------------------------===//
18333
+ // DuckDB
18334
+ //
18335
+ // duckdb/parser/constraints/not_null_constraint.hpp
18336
+ //
18337
+ //
18338
+ //===----------------------------------------------------------------------===//
18339
+
18340
+
18341
+
18342
+
18343
+
18344
+ namespace duckdb {
18345
+
18346
+ class NotNullConstraint : public Constraint {
18347
+ public:
18348
+ DUCKDB_API explicit NotNullConstraint(column_t index);
18349
+ DUCKDB_API ~NotNullConstraint() override;
18350
+
18351
+ //! Column index this constraint pertains to
18352
+ column_t index;
18353
+
18354
+ public:
18355
+ DUCKDB_API string ToString() const override;
18356
+
18357
+ DUCKDB_API unique_ptr<Constraint> Copy() override;
18358
+
18359
+ //! Serialize to a stand-alone binary blob
18360
+ DUCKDB_API void Serialize(Serializer &serializer) override;
18361
+ //! Deserializes a NotNullConstraint
18362
+ DUCKDB_API static unique_ptr<Constraint> Deserialize(Deserializer &source);
18363
+ };
18364
+
18365
+ } // namespace duckdb
18366
+ //===----------------------------------------------------------------------===//
18367
+ // DuckDB
18368
+ //
18369
+ // duckdb/storage/data_table.hpp
18370
+ //
18371
+ //
18372
+ //===----------------------------------------------------------------------===//
18373
+
18374
+
18375
+
18376
+ //===----------------------------------------------------------------------===//
18377
+ // DuckDB
18378
+ //
18379
+ // duckdb/common/enums/index_type.hpp
18380
+ //
18381
+ //
18382
+ //===----------------------------------------------------------------------===//
18383
+
18384
+
18385
+
18386
+
18387
+
18388
+ namespace duckdb {
18389
+
18390
+ //===--------------------------------------------------------------------===//
18391
+ // Index Types
18392
+ //===--------------------------------------------------------------------===//
18393
+ enum class IndexType {
18394
+ INVALID = 0, // invalid index type
18395
+ ART = 1 // Adaptive Radix Tree
18396
+ };
18397
+
18398
+ } // namespace duckdb
18399
+
18400
+
18401
+ //===----------------------------------------------------------------------===//
18402
+ // DuckDB
18403
+ //
18404
+ // duckdb/storage/index.hpp
18405
+ //
18406
+ //
18407
+ //===----------------------------------------------------------------------===//
18408
+
18409
+
18410
+
18411
+
18412
+
18413
+
18414
+
18415
+
18416
+
18417
+ //===----------------------------------------------------------------------===//
18418
+ // DuckDB
18419
+ //
18420
+ // duckdb/execution/expression_executor.hpp
18421
+ //
18422
+ //
18423
+ //===----------------------------------------------------------------------===//
18424
+
18425
+
18426
+
18427
+
18428
+
18429
+
18430
+
18431
+
18432
+ namespace duckdb {
18433
+ class ExecutionContext;
18434
+ //! ExpressionExecutor is responsible for executing a set of expressions and storing the result in a data chunk
18435
+ class ExpressionExecutor {
18436
+ public:
18437
+ DUCKDB_API ExpressionExecutor();
18438
+ DUCKDB_API explicit ExpressionExecutor(const Expression *expression);
18439
+ DUCKDB_API explicit ExpressionExecutor(const Expression &expression);
18440
+ DUCKDB_API explicit ExpressionExecutor(const vector<unique_ptr<Expression>> &expressions);
18441
+
18442
+ //! Add an expression to the set of to-be-executed expressions of the executor
18443
+ DUCKDB_API void AddExpression(const Expression &expr);
18444
+
18445
+ //! Execute the set of expressions with the given input chunk and store the result in the output chunk
18446
+ DUCKDB_API void Execute(DataChunk *input, DataChunk &result);
18447
+ inline void Execute(DataChunk &input, DataChunk &result) {
18448
+ Execute(&input, result);
18449
+ }
18450
+ inline void Execute(DataChunk &result) {
18451
+ Execute(nullptr, result);
18452
+ }
18453
+
18454
+ //! Execute the ExpressionExecutor and put the result in the result vector; this should only be used for expression
18455
+ //! executors with a single expression
18456
+ DUCKDB_API void ExecuteExpression(DataChunk &input, Vector &result);
18457
+ //! Execute the ExpressionExecutor and put the result in the result vector; this should only be used for expression
18458
+ //! executors with a single expression
18459
+ DUCKDB_API void ExecuteExpression(Vector &result);
18460
+ //! Execute the ExpressionExecutor and generate a selection vector from all true values in the result; this should
18461
+ //! only be used with a single boolean expression
18462
+ DUCKDB_API idx_t SelectExpression(DataChunk &input, SelectionVector &sel);
18463
+
18464
+ //! Execute the expression with index `expr_idx` and store the result in the result vector
18465
+ DUCKDB_API void ExecuteExpression(idx_t expr_idx, Vector &result);
18466
+ //! Evaluate a scalar expression and fold it into a single value
18467
+ DUCKDB_API static Value EvaluateScalar(const Expression &expr);
18468
+ //! Try to evaluate a scalar expression and fold it into a single value, returns false if an exception is thrown
18469
+ DUCKDB_API static bool TryEvaluateScalar(const Expression &expr, Value &result);
18470
+
18471
+ //! Initialize the state of a given expression
18472
+ static unique_ptr<ExpressionState> InitializeState(const Expression &expr, ExpressionExecutorState &state);
18473
+
18474
+ inline void SetChunk(DataChunk *chunk) {
18475
+ this->chunk = chunk;
18476
+ }
18477
+ inline void SetChunk(DataChunk &chunk) {
18478
+ SetChunk(&chunk);
18479
+ }
18480
+
18481
+ DUCKDB_API vector<unique_ptr<ExpressionExecutorState>> &GetStates();
18482
+
18483
+ //! The expressions of the executor
18484
+ vector<const Expression *> expressions;
18485
+ //! The data chunk of the current physical operator, used to resolve
18486
+ //! column references and determines the output cardinality
18487
+ DataChunk *chunk = nullptr;
18488
+
18489
+ protected:
18490
+ void Initialize(const Expression &expr, ExpressionExecutorState &state);
18491
+
18492
+ static unique_ptr<ExpressionState> InitializeState(const BoundReferenceExpression &expr,
18493
+ ExpressionExecutorState &state);
18494
+ static unique_ptr<ExpressionState> InitializeState(const BoundBetweenExpression &expr,
18495
+ ExpressionExecutorState &state);
18496
+ static unique_ptr<ExpressionState> InitializeState(const BoundCaseExpression &expr, ExpressionExecutorState &state);
18497
+ static unique_ptr<ExpressionState> InitializeState(const BoundCastExpression &expr, ExpressionExecutorState &state);
18498
+ static unique_ptr<ExpressionState> InitializeState(const BoundComparisonExpression &expr,
18499
+ ExpressionExecutorState &state);
18500
+ static unique_ptr<ExpressionState> InitializeState(const BoundConjunctionExpression &expr,
18501
+ ExpressionExecutorState &state);
18502
+ static unique_ptr<ExpressionState> InitializeState(const BoundConstantExpression &expr,
18503
+ ExpressionExecutorState &state);
18504
+ static unique_ptr<ExpressionState> InitializeState(const BoundFunctionExpression &expr,
18505
+ ExpressionExecutorState &state);
18506
+ static unique_ptr<ExpressionState> InitializeState(const BoundOperatorExpression &expr,
18507
+ ExpressionExecutorState &state);
18508
+ static unique_ptr<ExpressionState> InitializeState(const BoundParameterExpression &expr,
18509
+ ExpressionExecutorState &state);
18510
+
18511
+ void Execute(const Expression &expr, ExpressionState *state, const SelectionVector *sel, idx_t count,
18512
+ Vector &result);
18513
+
18514
+ void Execute(const BoundBetweenExpression &expr, ExpressionState *state, const SelectionVector *sel, idx_t count,
18515
+ Vector &result);
18516
+ void Execute(const BoundCaseExpression &expr, ExpressionState *state, const SelectionVector *sel, idx_t count,
18517
+ Vector &result);
18518
+ void Execute(const BoundCastExpression &expr, ExpressionState *state, const SelectionVector *sel, idx_t count,
18519
+ Vector &result);
18520
+
18521
+ void Execute(const BoundComparisonExpression &expr, ExpressionState *state, const SelectionVector *sel, idx_t count,
18522
+ Vector &result);
18523
+ void Execute(const BoundConjunctionExpression &expr, ExpressionState *state, const SelectionVector *sel,
18524
+ idx_t count, Vector &result);
18525
+ void Execute(const BoundConstantExpression &expr, ExpressionState *state, const SelectionVector *sel, idx_t count,
18526
+ Vector &result);
18527
+ void Execute(const BoundFunctionExpression &expr, ExpressionState *state, const SelectionVector *sel, idx_t count,
18528
+ Vector &result);
18529
+ void Execute(const BoundOperatorExpression &expr, ExpressionState *state, const SelectionVector *sel, idx_t count,
18530
+ Vector &result);
18531
+ void Execute(const BoundParameterExpression &expr, ExpressionState *state, const SelectionVector *sel, idx_t count,
18532
+ Vector &result);
18533
+ void Execute(const BoundReferenceExpression &expr, ExpressionState *state, const SelectionVector *sel, idx_t count,
18534
+ Vector &result);
18535
+
18536
+ //! Execute the (boolean-returning) expression and generate a selection vector with all entries that are "true" in
18537
+ //! the result
18538
+ idx_t Select(const Expression &expr, ExpressionState *state, const SelectionVector *sel, idx_t count,
18539
+ SelectionVector *true_sel, SelectionVector *false_sel);
18540
+ idx_t DefaultSelect(const Expression &expr, ExpressionState *state, const SelectionVector *sel, idx_t count,
18541
+ SelectionVector *true_sel, SelectionVector *false_sel);
18542
+
18543
+ idx_t Select(const BoundBetweenExpression &expr, ExpressionState *state, const SelectionVector *sel, idx_t count,
18544
+ SelectionVector *true_sel, SelectionVector *false_sel);
18545
+ idx_t Select(const BoundComparisonExpression &expr, ExpressionState *state, const SelectionVector *sel, idx_t count,
18546
+ SelectionVector *true_sel, SelectionVector *false_sel);
18547
+ idx_t Select(const BoundConjunctionExpression &expr, ExpressionState *state, const SelectionVector *sel,
18548
+ idx_t count, SelectionVector *true_sel, SelectionVector *false_sel);
18549
+
18550
+ //! Verify that the output of a step in the ExpressionExecutor is correct
18551
+ void Verify(const Expression &expr, Vector &result, idx_t count);
18552
+
18553
+ void FillSwitch(Vector &vector, Vector &result, const SelectionVector &sel, sel_t count);
18554
+
18555
+ private:
18556
+ //! The states of the expression executor; this holds any intermediates and temporary states of expressions
18557
+ vector<unique_ptr<ExpressionExecutorState>> states;
18558
+ };
18559
+ } // namespace duckdb
18560
+
18561
+
18562
+ namespace duckdb {
18563
+
18564
+ class ClientContext;
18565
+ class Transaction;
18566
+
18567
+ struct IndexLock;
18568
+
18569
+ //! The index is an abstract base class that serves as the basis for indexes
18570
+ class Index {
18571
+ public:
18572
+ Index(IndexType type, const vector<column_t> &column_ids, const vector<unique_ptr<Expression>> &unbound_expressions,
18573
+ bool is_unique, bool is_primary);
18574
+ virtual ~Index() = default;
18575
+
18576
+ //! The type of the index
18577
+ IndexType type;
18578
+ //! Column identifiers to extract from the base table
18579
+ vector<column_t> column_ids;
18580
+ //! unordered_set of column_ids used by the index
18581
+ unordered_set<column_t> column_id_set;
18582
+ //! Unbound expressions used by the index
18583
+ vector<unique_ptr<Expression>> unbound_expressions;
18584
+ //! The physical types stored in the index
18585
+ vector<PhysicalType> types;
18586
+ //! The logical types of the expressions
18587
+ vector<LogicalType> logical_types;
18588
+ //! Whether or not the index is an index built to enforce a UNIQUE or PRIMARY KEY constraint
18589
+ bool is_unique;
18590
+ //! Whether or not the index is an index built to enforce a PRIMARY KEY constraint
18591
+ bool is_primary;
18592
+
18593
+ public:
18594
+ //! Initialize a scan on the index with the given expression and column ids
18595
+ //! to fetch from the base table when we only have one query predicate
18596
+ virtual unique_ptr<IndexScanState> InitializeScanSinglePredicate(Transaction &transaction, Value value,
18597
+ ExpressionType expressionType) = 0;
18598
+ //! Initialize a scan on the index with the given expression and column ids
18599
+ //! to fetch from the base table for two query predicates
18600
+ virtual unique_ptr<IndexScanState> InitializeScanTwoPredicates(Transaction &transaction, Value low_value,
18601
+ ExpressionType low_expression_type, Value high_value,
18602
+ ExpressionType high_expression_type) = 0;
18603
+ //! Perform a lookup on the index, fetching up to max_count result ids. Returns true if all row ids were fetched,
18604
+ //! and false otherwise.
18605
+ virtual bool Scan(Transaction &transaction, DataTable &table, IndexScanState &state, idx_t max_count,
18606
+ vector<row_t> &result_ids) = 0;
18607
+
18608
+ //! Obtain a lock on the index
18609
+ virtual void InitializeLock(IndexLock &state);
18610
+ //! Called when data is appended to the index. The lock obtained from InitializeAppend must be held
18611
+ virtual bool Append(IndexLock &state, DataChunk &entries, Vector &row_identifiers) = 0;
18612
+ bool Append(DataChunk &entries, Vector &row_identifiers);
18613
+ //! Verify that data can be appended to the index
18614
+ virtual void VerifyAppend(DataChunk &chunk) = 0;
18615
+
18616
+ //! Called when data inside the index is Deleted
18617
+ virtual void Delete(IndexLock &state, DataChunk &entries, Vector &row_identifiers) = 0;
18618
+ void Delete(DataChunk &entries, Vector &row_identifiers);
18619
+
18620
+ //! Insert data into the index. Does not lock the index.
18621
+ virtual bool Insert(IndexLock &lock, DataChunk &input, Vector &row_identifiers) = 0;
18622
+
18623
+ //! Returns true if the index is affected by updates on the specified column ids, and false otherwise
18624
+ bool IndexIsUpdated(const vector<column_t> &column_ids) const;
18625
+
18626
+ protected:
18627
+ void ExecuteExpressions(DataChunk &input, DataChunk &result);
18628
+
18629
+ //! Lock used for updating the index
18630
+ mutex lock;
18631
+
18632
+ private:
18633
+ //! Bound expressions used by the index
18634
+ vector<unique_ptr<Expression>> bound_expressions;
18635
+ //! Expression executor for the index expressions
18636
+ ExpressionExecutor executor;
18637
+
18638
+ unique_ptr<Expression> BindExpression(unique_ptr<Expression> expr);
18639
+ };
18640
+
18641
+ } // namespace duckdb
18642
+
18643
+ //===----------------------------------------------------------------------===//
18644
+ // DuckDB
18645
+ //
18646
+ // duckdb/storage/table_statistics.hpp
18647
+ //
18648
+ //
18649
+ //===----------------------------------------------------------------------===//
18650
+
18651
+
18652
+
18653
+
18654
+
18655
+
18656
+ namespace duckdb {
18657
+
18658
+ struct TableStatistics {
18659
+ idx_t estimated_cardinality;
18660
+ };
18661
+
18662
+ } // namespace duckdb
18663
+
18664
+
18665
+ //===----------------------------------------------------------------------===//
18666
+ // DuckDB
18667
+ //
18668
+ // duckdb/storage/table/column_segment.hpp
18669
+ //
18670
+ //
18671
+ //===----------------------------------------------------------------------===//
18672
+
18673
+
18674
+
18675
+
18676
+
18677
+
18678
+
18679
+ //===----------------------------------------------------------------------===//
18680
+ // DuckDB
18681
+ //
18682
+ // duckdb/storage/buffer_manager.hpp
18683
+ //
18684
+ //
18685
+ //===----------------------------------------------------------------------===//
18686
+
18687
+
18688
+
18689
+
18690
+
18691
+
18692
+
18693
+ //===----------------------------------------------------------------------===//
18694
+ // DuckDB
18695
+ //
18696
+ // duckdb/storage/block_manager.hpp
18697
+ //
18698
+ //
18699
+ //===----------------------------------------------------------------------===//
18700
+
18701
+
18702
+
18703
+
18704
+
18705
+
18706
+
18707
+ namespace duckdb {
18708
+ class ClientContext;
18709
+ class DatabaseInstance;
18710
+
18711
+ //! BlockManager is an abstract representation to manage blocks on DuckDB. When writing or reading blocks, the
18712
+ //! BlockManager creates and accesses blocks. The concrete types implements how blocks are stored.
18713
+ class BlockManager {
18714
+ public:
18715
+ virtual ~BlockManager() = default;
18716
+
18717
+ virtual void StartCheckpoint() = 0;
18718
+ //! Creates a new block inside the block manager
18719
+ virtual unique_ptr<Block> CreateBlock(block_id_t block_id) = 0;
18720
+ //! Return the next free block id
18721
+ virtual block_id_t GetFreeBlockId() = 0;
18722
+ //! Returns whether or not a specified block is the root block
18723
+ virtual bool IsRootBlock(block_id_t root) = 0;
18724
+ //! Mark a block as "modified"; modified blocks are added to the free list after a checkpoint (i.e. their data is
18725
+ //! assumed to be rewritten)
18726
+ virtual void MarkBlockAsModified(block_id_t block_id) = 0;
18727
+ //! Increase the reference count of a block. The block should hold at least one reference before this method is
18728
+ //! called.
18729
+ virtual void IncreaseBlockReferenceCount(block_id_t block_id) = 0;
18730
+ //! Get the first meta block id
18731
+ virtual block_id_t GetMetaBlock() = 0;
18732
+ //! Read the content of the block from disk
18733
+ virtual void Read(Block &block) = 0;
18734
+ //! Writes the block to disk
18735
+ virtual void Write(FileBuffer &block, block_id_t block_id) = 0;
18736
+ //! Writes the block to disk
18737
+ void Write(Block &block) {
18738
+ Write(block, block.id);
18739
+ }
18740
+ //! Write the header; should be the final step of a checkpoint
18741
+ virtual void WriteHeader(DatabaseHeader header) = 0;
18742
+
18743
+ //! Returns the number of total blocks
18744
+ virtual idx_t TotalBlocks() = 0;
18745
+ //! Returns the number of free blocks
18746
+ virtual idx_t FreeBlocks() = 0;
18747
+
18748
+ static BlockManager &GetBlockManager(ClientContext &context);
18749
+ static BlockManager &GetBlockManager(DatabaseInstance &db);
18750
+ };
18751
+ } // namespace duckdb
18752
+
18753
+ //===----------------------------------------------------------------------===//
18754
+ // DuckDB
18755
+ //
18756
+ // duckdb/storage/buffer/block_handle.hpp
18757
+ //
18758
+ //
18759
+ //===----------------------------------------------------------------------===//
18760
+
18761
+
18762
+
18763
+
18764
+
18765
+
18766
+
18767
+
18768
+ namespace duckdb {
18769
+ class BufferHandle;
18770
+ class BufferManager;
18771
+ class DatabaseInstance;
18772
+ class FileBuffer;
18773
+
18774
+ enum class BlockState : uint8_t { BLOCK_UNLOADED = 0, BLOCK_LOADED = 1 };
18775
+
18776
+ class BlockHandle {
18777
+ friend struct BufferEvictionNode;
18778
+ friend class BufferHandle;
18779
+ friend class BufferManager;
18780
+
18781
+ public:
18782
+ BlockHandle(DatabaseInstance &db, block_id_t block_id);
18783
+ BlockHandle(DatabaseInstance &db, block_id_t block_id, unique_ptr<FileBuffer> buffer, bool can_destroy,
18784
+ idx_t block_size);
18785
+ ~BlockHandle();
18786
+
18787
+ DatabaseInstance &db;
18788
+
18789
+ public:
18790
+ block_id_t BlockId() {
18791
+ return block_id;
18792
+ }
18793
+
18794
+ int32_t Readers() const {
18795
+ return readers;
18796
+ }
18797
+
18798
+ private:
18799
+ static unique_ptr<BufferHandle> Load(shared_ptr<BlockHandle> &handle);
18800
+ void Unload();
18801
+ bool CanUnload();
18802
+
18803
+ //! The block-level lock
18804
+ mutex lock;
18805
+ //! Whether or not the block is loaded/unloaded
18806
+ BlockState state;
18807
+ //! Amount of concurrent readers
18808
+ atomic<int32_t> readers;
18809
+ //! The block id of the block
18810
+ const block_id_t block_id;
18811
+ //! Pointer to loaded data (if any)
18812
+ unique_ptr<FileBuffer> buffer;
18813
+ //! Internal eviction timestamp
18814
+ atomic<idx_t> eviction_timestamp;
18815
+ //! Whether or not the buffer can be destroyed (only used for temporary buffers)
18816
+ const bool can_destroy;
18817
+ //! The memory usage of the block
18818
+ idx_t memory_usage;
18819
+ };
18820
+
18821
+ } // namespace duckdb
18822
+
18823
+
18824
+ //===----------------------------------------------------------------------===//
18825
+ // DuckDB
18826
+ //
18827
+ // duckdb/storage/buffer/managed_buffer.hpp
18828
+ //
18829
+ //
18830
+ //===----------------------------------------------------------------------===//
18831
+
18832
+
18833
+
18834
+
18835
+
18836
+
18837
+
18838
+ namespace duckdb {
18839
+ class DatabaseInstance;
18840
+
18841
+ //! Managed buffer is an arbitrarily-sized buffer that is at least of size >= BLOCK_SIZE
18842
+ class ManagedBuffer : public FileBuffer {
18843
+ public:
18844
+ ManagedBuffer(DatabaseInstance &db, idx_t size, bool can_destroy, block_id_t id);
18845
+
18846
+ DatabaseInstance &db;
18847
+ //! Whether or not the managed buffer can be freely destroyed when unpinned.
18848
+ //! - If can_destroy is true, the buffer can be destroyed when unpinned and hence be unrecoverable. After being
18849
+ //! destroyed, Pin() will return false.
18850
+ //! - If can_destroy is false, the buffer will instead be written to a temporary file on disk when unloaded from
18851
+ //! memory, and read back into memory when Pin() is called.
18852
+ bool can_destroy;
18853
+ //! The internal id of the buffer
18854
+ block_id_t id;
18855
+ };
18856
+
18857
+ } // namespace duckdb
18858
+
18859
+
18860
+ namespace duckdb {
18861
+ class DatabaseInstance;
18862
+ class TemporaryDirectoryHandle;
18863
+ struct EvictionQueue;
18864
+
18865
+ //! The buffer manager is in charge of handling memory management for the database. It hands out memory buffers that can
18866
+ //! be used by the database internally.
18867
+ class BufferManager {
18868
+ friend class BufferHandle;
18869
+ friend class BlockHandle;
18870
+
18871
+ public:
18872
+ BufferManager(DatabaseInstance &db, string temp_directory, idx_t maximum_memory);
18873
+ ~BufferManager();
18874
+
18875
+ //! Register a block with the given block id in the base file
18876
+ shared_ptr<BlockHandle> RegisterBlock(block_id_t block_id);
18877
+
18878
+ //! Register an in-memory buffer of arbitrary size, as long as it is >= BLOCK_SIZE. can_destroy signifies whether or
18879
+ //! not the buffer can be destroyed when unpinned, or whether or not it needs to be written to a temporary file so
18880
+ //! it can be reloaded. The resulting buffer will already be allocated, but needs to be pinned in order to be used.
18881
+ shared_ptr<BlockHandle> RegisterMemory(idx_t block_size, bool can_destroy);
18882
+
18883
+ //! Convert an existing in-memory buffer into a persistent disk-backed block
18884
+ shared_ptr<BlockHandle> ConvertToPersistent(BlockManager &block_manager, block_id_t block_id,
18885
+ shared_ptr<BlockHandle> old_block);
18886
+
18887
+ //! Allocate an in-memory buffer with a single pin.
18888
+ //! The allocated memory is released when the buffer handle is destroyed.
18889
+ unique_ptr<BufferHandle> Allocate(idx_t block_size);
18890
+
18891
+ //! Reallocate an in-memory buffer that is pinned.
18892
+ void ReAllocate(shared_ptr<BlockHandle> &handle, idx_t block_size);
18893
+
18894
+ unique_ptr<BufferHandle> Pin(shared_ptr<BlockHandle> &handle);
18895
+ void Unpin(shared_ptr<BlockHandle> &handle);
18896
+
18897
+ void UnregisterBlock(block_id_t block_id, bool can_destroy);
18898
+
18899
+ //! Set a new memory limit to the buffer manager, throws an exception if the new limit is too low and not enough
18900
+ //! blocks can be evicted
18901
+ void SetLimit(idx_t limit = (idx_t)-1);
18902
+
18903
+ static BufferManager &GetBufferManager(ClientContext &context);
18904
+ static BufferManager &GetBufferManager(DatabaseInstance &db);
18905
+
18906
+ idx_t GetUsedMemory() {
18907
+ return current_memory;
18908
+ }
18909
+ idx_t GetMaxMemory() {
18910
+ return maximum_memory;
18911
+ }
18912
+
18913
+ const string &GetTemporaryDirectory() {
18914
+ return temp_directory;
18915
+ }
18916
+
18917
+ void SetTemporaryDirectory(string new_dir);
18918
+
18919
+ private:
18920
+ //! Evict blocks until the currently used memory + extra_memory fit, returns false if this was not possible
18921
+ //! (i.e. not enough blocks could be evicted)
18922
+ bool EvictBlocks(idx_t extra_memory, idx_t memory_limit);
18923
+
18924
+ //! Garbage collect eviction queue
18925
+ void PurgeQueue();
18926
+
18927
+ //! Write a temporary buffer to disk
18928
+ void WriteTemporaryBuffer(ManagedBuffer &buffer);
18929
+ //! Read a temporary buffer from disk
18930
+ unique_ptr<FileBuffer> ReadTemporaryBuffer(block_id_t id);
18931
+ //! Get the path of the temporary buffer
18932
+ string GetTemporaryPath(block_id_t id);
18933
+
18934
+ void DeleteTemporaryFile(block_id_t id);
18935
+
18936
+ void RequireTemporaryDirectory();
18937
+
18938
+ void AddToEvictionQueue(shared_ptr<BlockHandle> &handle);
18939
+
18940
+ string InMemoryWarning();
18941
+
18942
+ private:
18943
+ //! The database instance
18944
+ DatabaseInstance &db;
18945
+ //! The lock for changing the memory limit
18946
+ mutex limit_lock;
18947
+ //! The current amount of memory that is occupied by the buffer manager (in bytes)
18948
+ atomic<idx_t> current_memory;
18949
+ //! The maximum amount of memory that the buffer manager can keep (in bytes)
18950
+ atomic<idx_t> maximum_memory;
18951
+ //! The directory name where temporary files are stored
18952
+ string temp_directory;
18953
+ //! Lock for creating the temp handle
18954
+ mutex temp_handle_lock;
18955
+ //! Handle for the temporary directory
18956
+ unique_ptr<TemporaryDirectoryHandle> temp_directory_handle;
18957
+ //! The lock for the set of blocks
18958
+ mutex blocks_lock;
18959
+ //! A mapping of block id -> BlockHandle
18960
+ unordered_map<block_id_t, weak_ptr<BlockHandle>> blocks;
18961
+ //! Eviction queue
18962
+ unique_ptr<EvictionQueue> queue;
18963
+ //! The temporary id used for managed buffers
18964
+ atomic<block_id_t> temporary_id;
18965
+ };
18966
+ } // namespace duckdb
18967
+
18968
+
18969
+
18970
+
18971
+ //===----------------------------------------------------------------------===//
18972
+ // DuckDB
18973
+ //
18974
+ // duckdb/function/compression_function.hpp
18975
+ //
18976
+ //
18977
+ //===----------------------------------------------------------------------===//
18978
+
18979
+
18980
+
18981
+
18982
+
18983
+
18984
+ //===----------------------------------------------------------------------===//
18985
+ // DuckDB
18986
+ //
18987
+ // duckdb/common/map.hpp
18988
+ //
18989
+ //
18990
+ //===----------------------------------------------------------------------===//
18991
+
18992
+
18993
+
18994
+ #include <map>
18995
+
18996
+ namespace duckdb {
18997
+ using std::map;
18998
+ using std::multimap;
18999
+ } // namespace duckdb
19000
+
19001
+
19002
+
19003
+ namespace duckdb {
19004
+ class DatabaseInstance;
19005
+ class ColumnData;
19006
+ class ColumnDataCheckpointer;
19007
+ class ColumnSegment;
19008
+ class SegmentStatistics;
19009
+
19010
+ struct ColumnFetchState;
19011
+ struct ColumnScanState;
19012
+ struct SegmentScanState;
19013
+
19014
+ struct AnalyzeState {
19015
+ virtual ~AnalyzeState() {
19016
+ }
19017
+ };
19018
+
19019
+ struct CompressionState {
19020
+ virtual ~CompressionState() {
19021
+ }
19022
+ };
19023
+
19024
+ struct CompressedSegmentState {
19025
+ virtual ~CompressedSegmentState() {
19026
+ }
19027
+ };
19028
+
19029
+ //===--------------------------------------------------------------------===//
19030
+ // Analyze
19031
+ //===--------------------------------------------------------------------===//
19032
+ //! The analyze functions are used to determine whether or not to use this compression method
19033
+ //! The system first determines the potential compression methods to use based on the physical type of the column
19034
+ //! After that the following steps are taken:
19035
+ //! 1. The init_analyze is called to initialize the analyze state of every candidate compression method
19036
+ //! 2. The analyze method is called with all of the input data in the order in which it must be stored.
19037
+ //! analyze can return "false". In that case, the compression method is taken out of consideration early.
19038
+ //! 3. The final_analyze method is called, which should return a score for the compression method
19039
+
19040
+ //! The system then decides which compression function to use based on the analyzed score (returned from final_analyze)
19041
+ typedef unique_ptr<AnalyzeState> (*compression_init_analyze_t)(ColumnData &col_data, PhysicalType type);
19042
+ typedef bool (*compression_analyze_t)(AnalyzeState &state, Vector &input, idx_t count);
19043
+ typedef idx_t (*compression_final_analyze_t)(AnalyzeState &state);
19044
+
19045
+ //===--------------------------------------------------------------------===//
19046
+ // Compress
19047
+ //===--------------------------------------------------------------------===//
19048
+ typedef unique_ptr<CompressionState> (*compression_init_compression_t)(ColumnDataCheckpointer &checkpointer,
19049
+ unique_ptr<AnalyzeState> state);
19050
+ typedef void (*compression_compress_data_t)(CompressionState &state, Vector &scan_vector, idx_t count);
19051
+ typedef void (*compression_compress_finalize_t)(CompressionState &state);
19052
+
19053
+ //===--------------------------------------------------------------------===//
19054
+ // Uncompress / Scan
19055
+ //===--------------------------------------------------------------------===//
19056
+ typedef unique_ptr<SegmentScanState> (*compression_init_segment_scan_t)(ColumnSegment &segment);
19057
+ typedef void (*compression_scan_vector_t)(ColumnSegment &segment, ColumnScanState &state, idx_t scan_count,
19058
+ Vector &result);
19059
+ typedef void (*compression_scan_partial_t)(ColumnSegment &segment, ColumnScanState &state, idx_t scan_count,
19060
+ Vector &result, idx_t result_offset);
19061
+ typedef void (*compression_fetch_row_t)(ColumnSegment &segment, ColumnFetchState &state, row_t row_id, Vector &result,
19062
+ idx_t result_idx);
19063
+ typedef void (*compression_skip_t)(ColumnSegment &segment, ColumnScanState &state, idx_t skip_count);
19064
+
19065
+ //===--------------------------------------------------------------------===//
19066
+ // Append (optional)
19067
+ //===--------------------------------------------------------------------===//
19068
+ typedef unique_ptr<CompressedSegmentState> (*compression_init_segment_t)(ColumnSegment &segment, block_id_t block_id);
19069
+ typedef idx_t (*compression_append_t)(ColumnSegment &segment, SegmentStatistics &stats, VectorData &data, idx_t offset,
19070
+ idx_t count);
19071
+ typedef idx_t (*compression_finalize_append_t)(ColumnSegment &segment, SegmentStatistics &stats);
19072
+ typedef void (*compression_revert_append_t)(ColumnSegment &segment, idx_t start_row);
19073
+
19074
+ class CompressionFunction {
19075
+ public:
19076
+ CompressionFunction(CompressionType type, PhysicalType data_type, compression_init_analyze_t init_analyze,
19077
+ compression_analyze_t analyze, compression_final_analyze_t final_analyze,
19078
+ compression_init_compression_t init_compression, compression_compress_data_t compress,
19079
+ compression_compress_finalize_t compress_finalize, compression_init_segment_scan_t init_scan,
19080
+ compression_scan_vector_t scan_vector, compression_scan_partial_t scan_partial,
19081
+ compression_fetch_row_t fetch_row, compression_skip_t skip,
19082
+ compression_init_segment_t init_segment = nullptr, compression_append_t append = nullptr,
19083
+ compression_finalize_append_t finalize_append = nullptr,
19084
+ compression_revert_append_t revert_append = nullptr)
19085
+ : type(type), data_type(data_type), init_analyze(init_analyze), analyze(analyze), final_analyze(final_analyze),
19086
+ init_compression(init_compression), compress(compress), compress_finalize(compress_finalize),
19087
+ init_scan(init_scan), scan_vector(scan_vector), scan_partial(scan_partial), fetch_row(fetch_row), skip(skip),
19088
+ init_segment(init_segment), append(append), finalize_append(finalize_append), revert_append(revert_append) {
19089
+ }
19090
+
19091
+ //! Compression type
19092
+ CompressionType type;
19093
+ //! The data type this function can compress
19094
+ PhysicalType data_type;
19095
+
19096
+ //! Analyze step: determine which compression function is the most effective
19097
+ //! init_analyze is called once to set up the analyze state
19098
+ compression_init_analyze_t init_analyze;
19099
+ //! analyze is called several times (once per vector in the row group)
19100
+ //! analyze should return true, unless compression is no longer possible with this compression method
19101
+ //! in that case false should be returned
19102
+ compression_analyze_t analyze;
19103
+ //! final_analyze should return the score of the compression function
19104
+ //! ideally this is the exact number of bytes required to store the data
19105
+ //! this is not required/enforced: it can be an estimate as well
19106
+ compression_final_analyze_t final_analyze;
19107
+
19108
+ //! Compression step: actually compress the data
19109
+ //! init_compression is called once to set up the comperssion state
19110
+ compression_init_compression_t init_compression;
19111
+ //! compress is called several times (once per vector in the row group)
19112
+ compression_compress_data_t compress;
19113
+ //! compress_finalize is called after
19114
+ compression_compress_finalize_t compress_finalize;
19115
+
19116
+ //! init_scan is called to set up the scan state
19117
+ compression_init_segment_scan_t init_scan;
19118
+ //! scan_vector scans an entire vector using the scan state
19119
+ compression_scan_vector_t scan_vector;
19120
+ //! scan_partial scans a subset of a vector
19121
+ //! this can request > vector_size as well
19122
+ //! this is used if a vector crosses segment boundaries, or for child columns of lists
19123
+ compression_scan_partial_t scan_partial;
19124
+ //! fetch an individual row from the compressed vector
19125
+ //! used for index lookups
19126
+ compression_fetch_row_t fetch_row;
19127
+ //! Skip forward in the compressed segment
19128
+ compression_skip_t skip;
19129
+
19130
+ // Append functions
19131
+ //! This only really needs to be defined for uncompressed segments
19132
+
19133
+ //! Initialize a compressed segment (optional)
19134
+ compression_init_segment_t init_segment;
19135
+ //! Append to the compressed segment (optional)
19136
+ compression_append_t append;
19137
+ //! Finalize an append to the segment
19138
+ compression_finalize_append_t finalize_append;
19139
+ //! Revert append (optional)
19140
+ compression_revert_append_t revert_append;
19141
+ };
19142
+
19143
+ //! The set of compression functions
19144
+ struct CompressionFunctionSet {
19145
+ map<CompressionType, map<PhysicalType, CompressionFunction>> functions;
19146
+ };
19147
+
19148
+ } // namespace duckdb
19149
+
19150
+
19151
+ namespace duckdb {
19152
+ class ColumnSegment;
19153
+ class BlockManager;
19154
+ class ColumnSegment;
19155
+ class ColumnData;
19156
+ class DatabaseInstance;
19157
+ class Transaction;
19158
+ class BaseStatistics;
19159
+ class UpdateSegment;
19160
+ class TableFilter;
19161
+ struct ColumnFetchState;
19162
+ struct ColumnScanState;
19163
+ struct ColumnAppendState;
19164
+
19165
+ enum class ColumnSegmentType : uint8_t { TRANSIENT, PERSISTENT };
19166
+ //! TableFilter represents a filter pushed down into the table scan.
19167
+
19168
+ class ColumnSegment : public SegmentBase {
19169
+ public:
19170
+ ~ColumnSegment() override;
19171
+
19172
+ //! The database instance
19173
+ DatabaseInstance &db;
19174
+ //! The type stored in the column
19175
+ LogicalType type;
19176
+ //! The size of the type
19177
+ idx_t type_size;
19178
+ //! The column segment type (transient or persistent)
19179
+ ColumnSegmentType segment_type;
19180
+ //! The compression function
19181
+ CompressionFunction *function;
19182
+ //! The statistics for the segment
19183
+ SegmentStatistics stats;
19184
+ //! The block that this segment relates to
19185
+ shared_ptr<BlockHandle> block;
19186
+
19187
+ static unique_ptr<ColumnSegment> CreatePersistentSegment(DatabaseInstance &db, block_id_t id, idx_t offset,
19188
+ const LogicalType &type_p, idx_t start, idx_t count,
19189
+ CompressionType compression_type,
19190
+ unique_ptr<BaseStatistics> statistics);
19191
+ static unique_ptr<ColumnSegment> CreateTransientSegment(DatabaseInstance &db, const LogicalType &type, idx_t start);
19192
+
19193
+ public:
19194
+ void InitializeScan(ColumnScanState &state);
19195
+ //! Scan one vector from this segment
19196
+ void Scan(ColumnScanState &state, idx_t scan_count, Vector &result, idx_t result_offset, bool entire_vector);
19197
+ //! Fetch a value of the specific row id and append it to the result
19198
+ void FetchRow(ColumnFetchState &state, row_t row_id, Vector &result, idx_t result_idx);
19199
+
19200
+ static void FilterSelection(SelectionVector &sel, Vector &result, const TableFilter &filter,
19201
+ idx_t &approved_tuple_count, ValidityMask &mask);
19202
+
19203
+ //! Skip a scan forward to the row_index specified in the scan state
19204
+ void Skip(ColumnScanState &state);
19205
+
19206
+ //! Initialize an append of this segment. Appends are only supported on transient segments.
19207
+ void InitializeAppend(ColumnAppendState &state);
19208
+ //! Appends a (part of) vector to the segment, returns the amount of entries successfully appended
19209
+ idx_t Append(ColumnAppendState &state, VectorData &data, idx_t offset, idx_t count);
19210
+ //! Finalize the segment for appending - no more appends can follow on this segment
19211
+ //! The segment should be compacted as much as possible
19212
+ //! Returns the number of bytes occupied within the segment
19213
+ idx_t FinalizeAppend();
19214
+ //! Revert an append made to this segment
19215
+ void RevertAppend(idx_t start_row);
19216
+
19217
+ //! Convert a transient in-memory segment into a persistent segment blocked by an on-disk block.
19218
+ //! Only used during checkpointing.
19219
+ void ConvertToPersistent(block_id_t block_id);
19220
+ //! Convert a transient in-memory segment into a persistent segment blocked by an on-disk block.
19221
+ void ConvertToPersistent(shared_ptr<BlockHandle> block, block_id_t block_id, uint32_t offset_in_block);
19222
+
19223
+ block_id_t GetBlockId() {
19224
+ D_ASSERT(segment_type == ColumnSegmentType::PERSISTENT);
19225
+ return block_id;
19226
+ }
19227
+
19228
+ idx_t GetBlockOffset() {
19229
+ D_ASSERT(segment_type == ColumnSegmentType::PERSISTENT || offset == 0);
19230
+ return offset;
19231
+ }
19232
+
19233
+ idx_t GetRelativeIndex(idx_t row_index) {
19234
+ D_ASSERT(row_index >= this->start);
19235
+ D_ASSERT(row_index <= this->start + this->count);
19236
+ return row_index - this->start;
19237
+ }
19238
+
19239
+ CompressedSegmentState *GetSegmentState() {
19240
+ return segment_state.get();
19241
+ }
19242
+
19243
+ public:
19244
+ ColumnSegment(DatabaseInstance &db, LogicalType type, ColumnSegmentType segment_type, idx_t start, idx_t count,
19245
+ CompressionFunction *function, unique_ptr<BaseStatistics> statistics, block_id_t block_id,
19246
+ idx_t offset);
19247
+
19248
+ private:
19249
+ void Scan(ColumnScanState &state, idx_t scan_count, Vector &result);
19250
+ void ScanPartial(ColumnScanState &state, idx_t scan_count, Vector &result, idx_t result_offset);
19251
+
19252
+ private:
19253
+ //! The block id that this segment relates to (persistent segment only)
19254
+ block_id_t block_id;
19255
+ //! The offset into the block (persistent segment only)
19256
+ idx_t offset;
19257
+ //! Storage associated with the compressed segment
19258
+ unique_ptr<CompressedSegmentState> segment_state;
19259
+ };
19260
+
19261
+ } // namespace duckdb
19262
+
19263
+
19264
+
19265
+
19266
+
19267
+
19268
+
19269
+
19270
+
19271
+ namespace duckdb {
19272
+ class ClientContext;
19273
+ class ColumnDefinition;
19274
+ class DataTable;
19275
+ class RowGroup;
19276
+ class StorageManager;
19277
+ class TableCatalogEntry;
19278
+ class Transaction;
19279
+ class WriteAheadLog;
19280
+ class TableDataWriter;
19281
+
19282
+ class TableIndexList {
19283
+ public:
19284
+ //! Scan the catalog set, invoking the callback method for every entry
19285
+ template <class T>
19286
+ void Scan(T &&callback) {
19287
+ // lock the catalog set
19288
+ lock_guard<mutex> lock(indexes_lock);
19289
+ for (auto &index : indexes) {
19290
+ if (callback(*index)) {
19291
+ break;
19292
+ }
19293
+ }
19294
+ }
19295
+
19296
+ void AddIndex(unique_ptr<Index> index) {
19297
+ D_ASSERT(index);
19298
+ lock_guard<mutex> lock(indexes_lock);
19299
+ indexes.push_back(move(index));
19300
+ }
19301
+
19302
+ void RemoveIndex(Index *index) {
19303
+ D_ASSERT(index);
19304
+ lock_guard<mutex> lock(indexes_lock);
19305
+
19306
+ for (idx_t index_idx = 0; index_idx < indexes.size(); index_idx++) {
19307
+ auto &index_entry = indexes[index_idx];
19308
+ if (index_entry.get() == index) {
19309
+ indexes.erase(indexes.begin() + index_idx);
19310
+ break;
19311
+ }
19312
+ }
19313
+ }
19314
+
19315
+ bool Empty() {
19316
+ lock_guard<mutex> lock(indexes_lock);
19317
+ return indexes.empty();
19318
+ }
19319
+
19320
+ idx_t Count() {
19321
+ lock_guard<mutex> lock(indexes_lock);
19322
+ return indexes.size();
19323
+ }
19324
+
19325
+ private:
19326
+ //! Indexes associated with the current table
19327
+ mutex indexes_lock;
19328
+ vector<unique_ptr<Index>> indexes;
19329
+ };
19330
+
19331
+ struct DataTableInfo {
19332
+ DataTableInfo(DatabaseInstance &db, string schema, string table)
19333
+ : db(db), cardinality(0), schema(move(schema)), table(move(table)) {
19334
+ }
19335
+
19336
+ //! The database instance of the table
19337
+ DatabaseInstance &db;
19338
+ //! The amount of elements in the table. Note that this number signifies the amount of COMMITTED entries in the
19339
+ //! table. It can be inaccurate inside of transactions. More work is needed to properly support that.
19340
+ atomic<idx_t> cardinality;
19341
+ // schema of the table
19342
+ string schema;
19343
+ // name of the table
19344
+ string table;
19345
+
19346
+ TableIndexList indexes;
19347
+
19348
+ bool IsTemporary() {
19349
+ return schema == TEMP_SCHEMA;
19350
+ }
19351
+ };
19352
+
19353
+ struct ParallelTableScanState {
19354
+ RowGroup *current_row_group;
19355
+ idx_t vector_index;
19356
+ idx_t max_row;
19357
+ LocalScanState local_state;
19358
+ bool transaction_local_data;
19359
+ };
19360
+
19361
+ //! DataTable represents a physical table on disk
19362
+ class DataTable {
19363
+ public:
19364
+ //! Constructs a new data table from an (optional) set of persistent segments
19365
+ DataTable(DatabaseInstance &db, const string &schema, const string &table,
19366
+ vector<ColumnDefinition> column_definitions_p, unique_ptr<PersistentTableData> data = nullptr);
19367
+ //! Constructs a DataTable as a delta on an existing data table with a newly added column
19368
+ DataTable(ClientContext &context, DataTable &parent, ColumnDefinition &new_column, Expression *default_value);
19369
+ //! Constructs a DataTable as a delta on an existing data table but with one column removed
19370
+ DataTable(ClientContext &context, DataTable &parent, idx_t removed_column);
19371
+ //! Constructs a DataTable as a delta on an existing data table but with one column changed type
19372
+ DataTable(ClientContext &context, DataTable &parent, idx_t changed_idx, const LogicalType &target_type,
19373
+ vector<column_t> bound_columns, Expression &cast_expr);
19374
+
19375
+ shared_ptr<DataTableInfo> info;
19376
+
19377
+ vector<ColumnDefinition> column_definitions;
19378
+
19379
+ //! A reference to the database instance
19380
+ DatabaseInstance &db;
19381
+
19382
+ public:
19383
+ //! Returns a list of types of the table
19384
+ vector<LogicalType> GetTypes();
19385
+
19386
+ void InitializeScan(TableScanState &state, const vector<column_t> &column_ids,
19387
+ TableFilterSet *table_filter = nullptr);
19388
+ void InitializeScan(Transaction &transaction, TableScanState &state, const vector<column_t> &column_ids,
19389
+ TableFilterSet *table_filters = nullptr);
19390
+
19391
+ //! Returns the maximum amount of threads that should be assigned to scan this data table
19392
+ idx_t MaxThreads(ClientContext &context);
19393
+ void InitializeParallelScan(ClientContext &context, ParallelTableScanState &state);
19394
+ bool NextParallelScan(ClientContext &context, ParallelTableScanState &state, TableScanState &scan_state,
19395
+ const vector<column_t> &column_ids);
19396
+
19397
+ //! Scans up to STANDARD_VECTOR_SIZE elements from the table starting
19398
+ //! from offset and store them in result. Offset is incremented with how many
19399
+ //! elements were returned.
19400
+ //! Returns true if all pushed down filters were executed during data fetching
19401
+ void Scan(Transaction &transaction, DataChunk &result, TableScanState &state, vector<column_t> &column_ids);
19402
+
19403
+ //! Fetch data from the specific row identifiers from the base table
19404
+ void Fetch(Transaction &transaction, DataChunk &result, const vector<column_t> &column_ids, Vector &row_ids,
19405
+ idx_t fetch_count, ColumnFetchState &state);
19406
+
19407
+ //! Append a DataChunk to the table. Throws an exception if the columns don't match the tables' columns.
19408
+ void Append(TableCatalogEntry &table, ClientContext &context, DataChunk &chunk);
19409
+ //! Delete the entries with the specified row identifier from the table
19410
+ idx_t Delete(TableCatalogEntry &table, ClientContext &context, Vector &row_ids, idx_t count);
19411
+ //! Update the entries with the specified row identifier from the table
19412
+ void Update(TableCatalogEntry &table, ClientContext &context, Vector &row_ids, const vector<column_t> &column_ids,
19413
+ DataChunk &data);
19414
+ //! Update a single (sub-)column along a column path
19415
+ //! The column_path vector is a *path* towards a column within the table
19416
+ //! i.e. if we have a table with a single column S STRUCT(A INT, B INT)
19417
+ //! and we update the validity mask of "S.B"
19418
+ //! the column path is:
19419
+ //! 0 (first column of table)
19420
+ //! -> 1 (second subcolumn of struct)
19421
+ //! -> 0 (first subcolumn of INT)
19422
+ //! This method should only be used from the WAL replay. It does not verify update constraints.
19423
+ void UpdateColumn(TableCatalogEntry &table, ClientContext &context, Vector &row_ids,
19424
+ const vector<column_t> &column_path, DataChunk &updates);
19425
+
19426
+ //! Add an index to the DataTable
19427
+ void AddIndex(unique_ptr<Index> index, const vector<unique_ptr<Expression>> &expressions);
19428
+
19429
+ //! Begin appending structs to this table, obtaining necessary locks, etc
19430
+ void InitializeAppend(Transaction &transaction, TableAppendState &state, idx_t append_count);
19431
+ //! Append a chunk to the table using the AppendState obtained from BeginAppend
19432
+ void Append(Transaction &transaction, DataChunk &chunk, TableAppendState &state);
19433
+ //! Commit the append
19434
+ void CommitAppend(transaction_t commit_id, idx_t row_start, idx_t count);
19435
+ //! Write a segment of the table to the WAL
19436
+ void WriteToLog(WriteAheadLog &log, idx_t row_start, idx_t count);
19437
+ //! Revert a set of appends made by the given AppendState, used to revert appends in the event of an error during
19438
+ //! commit (e.g. because of an I/O exception)
19439
+ void RevertAppend(idx_t start_row, idx_t count);
19440
+ void RevertAppendInternal(idx_t start_row, idx_t count);
19441
+
19442
+ void ScanTableSegment(idx_t start_row, idx_t count, const std::function<void(DataChunk &chunk)> &function);
19443
+
19444
+ //! Append a chunk with the row ids [row_start, ..., row_start + chunk.size()] to all indexes of the table, returns
19445
+ //! whether or not the append succeeded
19446
+ bool AppendToIndexes(TableAppendState &state, DataChunk &chunk, row_t row_start);
19447
+ //! Remove a chunk with the row ids [row_start, ..., row_start + chunk.size()] from all indexes of the table
19448
+ void RemoveFromIndexes(TableAppendState &state, DataChunk &chunk, row_t row_start);
19449
+ //! Remove the chunk with the specified set of row identifiers from all indexes of the table
19450
+ void RemoveFromIndexes(TableAppendState &state, DataChunk &chunk, Vector &row_identifiers);
19451
+ //! Remove the row identifiers from all the indexes of the table
19452
+ void RemoveFromIndexes(Vector &row_identifiers, idx_t count);
19453
+
19454
+ void SetAsRoot() {
19455
+ this->is_root = true;
19456
+ }
19457
+
19458
+ unique_ptr<BaseStatistics> GetStatistics(ClientContext &context, column_t column_id);
19459
+
19460
+ //! Checkpoint the table to the specified table data writer
19461
+ BlockPointer Checkpoint(TableDataWriter &writer);
19462
+ void CommitDropTable();
19463
+ void CommitDropColumn(idx_t index);
19464
+
19465
+ idx_t GetTotalRows();
19466
+
19467
+ //! Appends an empty row_group to the table
19468
+ void AppendRowGroup(idx_t start_row);
19469
+
19470
+ vector<vector<Value>> GetStorageInfo();
19471
+
19472
+ private:
19473
+ //! Verify constraints with a chunk from the Append containing all columns of the table
19474
+ void VerifyAppendConstraints(TableCatalogEntry &table, DataChunk &chunk);
19475
+ //! Verify constraints with a chunk from the Update containing only the specified column_ids
19476
+ void VerifyUpdateConstraints(TableCatalogEntry &table, DataChunk &chunk, const vector<column_t> &column_ids);
19477
+
19478
+ void InitializeScanWithOffset(TableScanState &state, const vector<column_t> &column_ids, idx_t start_row,
19479
+ idx_t end_row);
19480
+ bool InitializeScanInRowGroup(TableScanState &state, const vector<column_t> &column_ids,
19481
+ TableFilterSet *table_filters, RowGroup *row_group, idx_t vector_index,
19482
+ idx_t max_row);
19483
+ bool ScanBaseTable(Transaction &transaction, DataChunk &result, TableScanState &state);
19484
+
19485
+ //! The CreateIndexScan is a special scan that is used to create an index on the table, it keeps locks on the table
19486
+ void InitializeCreateIndexScan(CreateIndexScanState &state, const vector<column_t> &column_ids);
19487
+ bool ScanCreateIndex(CreateIndexScanState &state, DataChunk &result, TableScanType type);
19488
+
19489
+ private:
19490
+ //! Lock for appending entries to the table
19491
+ mutex append_lock;
19492
+ //! The number of rows in the table
19493
+ atomic<idx_t> total_rows;
19494
+ //! The segment trees holding the various row_groups of the table
19495
+ shared_ptr<SegmentTree> row_groups;
19496
+ //! Column statistics
19497
+ vector<unique_ptr<BaseStatistics>> column_stats;
19498
+ //! The statistics lock
19499
+ mutex stats_lock;
19500
+ //! Whether or not the data table is the root DataTable for this table; the root DataTable is the newest version
19501
+ //! that can be appended to
19502
+ atomic<bool> is_root;
19503
+ };
19504
+ } // namespace duckdb
19505
+ //===----------------------------------------------------------------------===//
19506
+ // DuckDB
19507
+ //
19508
+ // duckdb/function/pragma_function.hpp
19509
+ //
19510
+ //
19511
+ //===----------------------------------------------------------------------===//
19512
+
19513
+
19514
+
19515
+
19516
+ //===----------------------------------------------------------------------===//
19517
+ // DuckDB
19518
+ //
19519
+ // duckdb/parser/parsed_data/pragma_info.hpp
19520
+ //
19521
+ //
19522
+ //===----------------------------------------------------------------------===//
19523
+
19524
+
19525
+
19526
+
19527
+
19528
+
19529
+
19530
+
19531
+ namespace duckdb {
19532
+
19533
+ enum class PragmaType : uint8_t { PRAGMA_STATEMENT, PRAGMA_CALL };
19534
+
19535
+ struct PragmaInfo : public ParseInfo {
19536
+ //! Name of the PRAGMA statement
19537
+ string name;
19538
+ //! Parameter list (if any)
19539
+ vector<Value> parameters;
19540
+ //! Named parameter list (if any)
19541
+ unordered_map<string, Value> named_parameters;
19542
+
19543
+ public:
19544
+ unique_ptr<PragmaInfo> Copy() const {
19545
+ auto result = make_unique<PragmaInfo>();
19546
+ result->name = name;
19547
+ result->parameters = parameters;
19548
+ result->named_parameters = named_parameters;
19549
+ return result;
19550
+ }
19551
+ };
19552
+
19553
+ } // namespace duckdb
19554
+
19555
+
19556
+
19557
+ namespace duckdb {
19558
+ class ClientContext;
19559
+
19560
+ //! Return a substitute query to execute instead of this pragma statement
19561
+ typedef string (*pragma_query_t)(ClientContext &context, const FunctionParameters &parameters);
19562
+ //! Execute the main pragma function
19563
+ typedef void (*pragma_function_t)(ClientContext &context, const FunctionParameters &parameters);
19564
+
19565
+ //! Pragma functions are invoked by calling PRAGMA x
19566
+ //! Pragma functions come in three types:
19567
+ //! * Call: function call, e.g. PRAGMA table_info('tbl')
19568
+ //! -> call statements can take multiple parameters
19569
+ //! * Statement: statement without parameters, e.g. PRAGMA show_tables
19570
+ //! -> this is similar to a call pragma but without parameters
19571
+ //! Pragma functions can either return a new query to execute (pragma_query_t)
19572
+ //! or they can
19573
+ class PragmaFunction : public SimpleNamedParameterFunction {
19574
+ public:
19575
+ // Call
19576
+ DUCKDB_API static PragmaFunction PragmaCall(const string &name, pragma_query_t query, vector<LogicalType> arguments,
19577
+ LogicalType varargs = LogicalType::INVALID);
19578
+ DUCKDB_API static PragmaFunction PragmaCall(const string &name, pragma_function_t function,
19579
+ vector<LogicalType> arguments,
19580
+ LogicalType varargs = LogicalType::INVALID);
19581
+ // Statement
19582
+ DUCKDB_API static PragmaFunction PragmaStatement(const string &name, pragma_query_t query);
19583
+ DUCKDB_API static PragmaFunction PragmaStatement(const string &name, pragma_function_t function);
19584
+
19585
+ DUCKDB_API string ToString() override;
19586
+
19587
+ public:
19588
+ PragmaType type;
19589
+
19590
+ pragma_query_t query;
19591
+ pragma_function_t function;
19592
+ unordered_map<string, LogicalType> named_parameters;
19593
+
19594
+ private:
19595
+ PragmaFunction(string name, PragmaType pragma_type, pragma_query_t query, pragma_function_t function,
19596
+ vector<LogicalType> arguments, LogicalType varargs);
19597
+ };
19598
+
19599
+ } // namespace duckdb
19600
+ //===----------------------------------------------------------------------===//
19601
+ // DuckDB
19602
+ //
19603
+ // duckdb/parser/parser.hpp
19604
+ //
19605
+ //
19606
+ //===----------------------------------------------------------------------===//
19607
+
19608
+
19609
+
19610
+
19611
+
19612
+
19613
+
19614
+ //===----------------------------------------------------------------------===//
19615
+ // DuckDB
19616
+ //
19617
+ // duckdb/parser/simplified_token.hpp
19618
+ //
19619
+ //
19620
+ //===----------------------------------------------------------------------===//
19621
+
19622
+
19623
+
19624
+
19625
+
19626
+ namespace duckdb {
19627
+
19628
+ //! Simplified tokens are a simplified (dense) representation of the lexer
19629
+ //! Used for simple syntax highlighting in the tests
19630
+ enum class SimplifiedTokenType : uint8_t {
19631
+ SIMPLIFIED_TOKEN_IDENTIFIER,
19632
+ SIMPLIFIED_TOKEN_NUMERIC_CONSTANT,
19633
+ SIMPLIFIED_TOKEN_STRING_CONSTANT,
19634
+ SIMPLIFIED_TOKEN_OPERATOR,
19635
+ SIMPLIFIED_TOKEN_KEYWORD,
19636
+ SIMPLIFIED_TOKEN_COMMENT
19637
+ };
19638
+
19639
+ struct SimplifiedToken {
19640
+ SimplifiedTokenType type;
19641
+ idx_t start;
19642
+ };
19643
+
19644
+ } // namespace duckdb
19645
+
19646
+
19647
+ namespace duckdb_libpgquery {
19648
+ struct PGNode;
19649
+ struct PGList;
19650
+ } // namespace duckdb_libpgquery
19651
+
19652
+ namespace duckdb {
19653
+
19654
+ //! The parser is responsible for parsing the query and converting it into a set
19655
+ //! of parsed statements. The parsed statements can then be converted into a
19656
+ //! plan and executed.
19657
+ class Parser {
19658
+ public:
19659
+ Parser();
19660
+
19661
+ //! Attempts to parse a query into a series of SQL statements. Returns
19662
+ //! whether or not the parsing was successful. If the parsing was
19663
+ //! successful, the parsed statements will be stored in the statements
19664
+ //! variable.
19665
+ void ParseQuery(const string &query);
19666
+
19667
+ //! Tokenize a query, returning the raw tokens together with their locations
19668
+ static vector<SimplifiedToken> Tokenize(const string &query);
19669
+
19670
+ //! Returns true if the given text matches a keyword of the parser
19671
+ static bool IsKeyword(const string &text);
19672
+
19673
+ //! Parses a list of expressions (i.e. the list found in a SELECT clause)
19674
+ static vector<unique_ptr<ParsedExpression>> ParseExpressionList(const string &select_list);
19675
+ //! Parses a list as found in an ORDER BY expression (i.e. including optional ASCENDING/DESCENDING modifiers)
19676
+ static vector<OrderByNode> ParseOrderList(const string &select_list);
19677
+ //! Parses an update list (i.e. the list found in the SET clause of an UPDATE statement)
19678
+ static void ParseUpdateList(const string &update_list, vector<string> &update_columns,
19679
+ vector<unique_ptr<ParsedExpression>> &expressions);
19680
+ //! Parses a VALUES list (i.e. the list of expressions after a VALUES clause)
19681
+ static vector<vector<unique_ptr<ParsedExpression>>> ParseValuesList(const string &value_list);
19682
+ //! Parses a column list (i.e. as found in a CREATE TABLE statement)
19683
+ static vector<ColumnDefinition> ParseColumnList(const string &column_list);
19684
+
19685
+ //! The parsed SQL statements from an invocation to ParseQuery.
19686
+ vector<unique_ptr<SQLStatement>> statements;
19687
+
19688
+ private:
19689
+ //! Transform a Postgres parse tree into a set of SQL Statements
19690
+ bool TransformList(duckdb_libpgquery::PGList *tree);
19691
+ //! Transform a single Postgres parse node into a SQL Statement.
19692
+ unique_ptr<SQLStatement> TransformNode(duckdb_libpgquery::PGNode *stmt);
19693
+ };
19694
+ } // namespace duckdb
19695
+ //===----------------------------------------------------------------------===//
19696
+ // DuckDB
19697
+ //
19698
+ // duckdb/storage/object_cache.hpp
19699
+ //
19700
+ //
19701
+ //===----------------------------------------------------------------------===//
19702
+
19703
+
19704
+
19705
+
19706
+
19707
+
19708
+
19709
+
19710
+
19711
+
19712
+ namespace duckdb {
19713
+ class ClientContext;
19714
+
19715
+ //! ObjectCache is the base class for objects caches in DuckDB
19716
+ class ObjectCacheEntry {
19717
+ public:
19718
+ virtual ~ObjectCacheEntry() {
19719
+ }
19720
+
19721
+ virtual string GetObjectType() = 0;
19722
+ };
19723
+
19724
+ class ObjectCache {
19725
+ public:
19726
+ shared_ptr<ObjectCacheEntry> GetObject(const string &key) {
19727
+ lock_guard<mutex> glock(lock);
19728
+ auto entry = cache.find(key);
19729
+ if (entry == cache.end()) {
19730
+ return nullptr;
19731
+ }
19732
+ return entry->second;
19733
+ }
19734
+
19735
+ template <class T>
19736
+ shared_ptr<T> Get(const string &key) {
19737
+ shared_ptr<ObjectCacheEntry> object = GetObject(key);
19738
+ if (!object || object->GetObjectType() != T::ObjectType()) {
19739
+ return nullptr;
19740
+ }
19741
+ return std::static_pointer_cast<T, ObjectCacheEntry>(object);
19742
+ }
19743
+
19744
+ void Put(string key, shared_ptr<ObjectCacheEntry> value) {
19745
+ lock_guard<mutex> glock(lock);
19746
+ cache[key] = move(value);
19747
+ }
19748
+
19749
+ static ObjectCache &GetObjectCache(ClientContext &context);
19750
+ static bool ObjectCacheEnabled(ClientContext &context);
19751
+
19752
+ private:
19753
+ //! Object Cache
19754
+ unordered_map<string, shared_ptr<ObjectCacheEntry>> cache;
19755
+ mutex lock;
19756
+ };
19757
+
19758
+ } // namespace duckdb
19759
+ //===----------------------------------------------------------------------===//
19760
+ // DuckDB
19761
+ //
19762
+ // duckdb/planner/table_filter.hpp
19763
+ //
19764
+ //
19765
+ //===----------------------------------------------------------------------===//
19766
+
19767
+
19768
+
19769
+
19770
+
19771
+
19772
+ //===----------------------------------------------------------------------===//
19773
+ // DuckDB
19774
+ //
19775
+ // duckdb/common/enums/filter_propagate_result.hpp
19776
+ //
19777
+ //
19778
+ //===----------------------------------------------------------------------===//
19779
+
19780
+
19781
+
19782
+
19783
+
19784
+ namespace duckdb {
19785
+
19786
+ enum class FilterPropagateResult : uint8_t {
19787
+ NO_PRUNING_POSSIBLE = 0,
19788
+ FILTER_ALWAYS_TRUE = 1,
19789
+ FILTER_ALWAYS_FALSE = 2,
19790
+ FILTER_TRUE_OR_NULL = 3,
19791
+ FILTER_FALSE_OR_NULL = 4
19792
+ };
19793
+
19794
+ } // namespace duckdb
19795
+
19796
+
19797
+ namespace duckdb {
19798
+ class BaseStatistics;
19799
+
19800
+ enum class TableFilterType : uint8_t {
19801
+ CONSTANT_COMPARISON = 0, // constant comparison (e.g. =C, >C, >=C, <C, <=C)
19802
+ IS_NULL = 1,
19803
+ IS_NOT_NULL = 2,
19804
+ CONJUNCTION_OR = 3,
19805
+ CONJUNCTION_AND = 4
19806
+ };
19807
+
19808
+ //! TableFilter represents a filter pushed down into the table scan.
19809
+ class TableFilter {
19810
+ public:
19811
+ TableFilter(TableFilterType filter_type_p) : filter_type(filter_type_p) {
19812
+ }
19813
+ virtual ~TableFilter() {
19814
+ }
19815
+
19816
+ TableFilterType filter_type;
19817
+
19818
+ public:
19819
+ //! Returns true if the statistics indicate that the segment can contain values that satisfy that filter
19820
+ virtual FilterPropagateResult CheckStatistics(BaseStatistics &stats) = 0;
19821
+ virtual string ToString(const string &column_name) = 0;
19822
+ virtual bool Equals(const TableFilter &other) const {
19823
+ return filter_type != other.filter_type;
19824
+ }
19825
+ };
19826
+
19827
+ class TableFilterSet {
19828
+ public:
19829
+ unordered_map<idx_t, unique_ptr<TableFilter>> filters;
19830
+
19831
+ public:
19832
+ void PushFilter(idx_t table_index, unique_ptr<TableFilter> filter);
19833
+
19834
+ bool Equals(TableFilterSet &other) {
19835
+ if (filters.size() != other.filters.size()) {
19836
+ return false;
19837
+ }
19838
+ for (auto &entry : filters) {
19839
+ auto other_entry = other.filters.find(entry.first);
19840
+ if (other_entry == other.filters.end()) {
19841
+ return false;
19842
+ }
19843
+ if (!entry.second->Equals(*other_entry->second)) {
19844
+ return false;
19845
+ }
19846
+ }
19847
+ return true;
19848
+ }
19849
+ static bool Equals(TableFilterSet *left, TableFilterSet *right) {
19850
+ if (left == right) {
19851
+ return true;
19852
+ }
19853
+ if (!left || !right) {
19854
+ return false;
19855
+ }
19856
+ return left->Equals(*right);
19857
+ }
19858
+ };
19859
+
19860
+ } // namespace duckdb
19861
+ //===----------------------------------------------------------------------===//
19862
+ // DuckDB
19863
+ //
19864
+ // duckdb/storage/statistics/string_statistics.hpp
19865
+ //
19866
+ //
19867
+ //===----------------------------------------------------------------------===//
19868
+
19869
+
19870
+
19871
+
19872
+
19873
+ //===----------------------------------------------------------------------===//
19874
+ // DuckDB
19875
+ //
19876
+ // duckdb/storage/statistics/validity_statistics.hpp
19877
+ //
19878
+ //
19879
+ //===----------------------------------------------------------------------===//
19880
+
19881
+
19882
+
19883
+
19884
+
19885
+ namespace duckdb {
19886
+ class Serializer;
19887
+ class Deserializer;
19888
+ class Vector;
19889
+
19890
+ class ValidityStatistics : public BaseStatistics {
19891
+ public:
19892
+ ValidityStatistics(bool has_null = false, bool has_no_null = true);
19893
+
19894
+ //! Whether or not the segment can contain NULL values
19895
+ bool has_null;
19896
+ //! Whether or not the segment can contain values that are not null
19897
+ bool has_no_null;
19898
+
19899
+ public:
19900
+ void Merge(const BaseStatistics &other) override;
19901
+
19902
+ bool IsConstant() override;
19903
+
19904
+ unique_ptr<BaseStatistics> Copy() override;
19905
+ void Serialize(Serializer &serializer) override;
19906
+ static unique_ptr<BaseStatistics> Deserialize(Deserializer &source);
19907
+ void Verify(Vector &vector, const SelectionVector &sel, idx_t count) override;
19908
+
19909
+ static unique_ptr<BaseStatistics> Combine(const unique_ptr<BaseStatistics> &lstats,
19910
+ const unique_ptr<BaseStatistics> &rstats);
19911
+
19912
+ string ToString() override;
19913
+ };
19914
+
19915
+ } // namespace duckdb
19916
+
19917
+
19918
+ namespace duckdb {
19919
+
19920
+ class StringStatistics : public BaseStatistics {
19921
+ public:
19922
+ constexpr static uint32_t MAX_STRING_MINMAX_SIZE = 8;
19923
+
19924
+ public:
19925
+ explicit StringStatistics(LogicalType type);
19926
+
19927
+ //! The minimum value of the segment, potentially truncated
19928
+ data_t min[MAX_STRING_MINMAX_SIZE];
19929
+ //! The maximum value of the segment, potentially truncated
19930
+ data_t max[MAX_STRING_MINMAX_SIZE];
19931
+ //! Whether or not the column can contain unicode characters
19932
+ bool has_unicode;
19933
+ //! The maximum string length in bytes
19934
+ uint32_t max_string_length;
19935
+ //! Whether or not the segment contains any big strings in overflow blocks
19936
+ bool has_overflow_strings;
19937
+
19938
+ public:
19939
+ void Update(const string_t &value);
19940
+ void Merge(const BaseStatistics &other) override;
19941
+
19942
+ unique_ptr<BaseStatistics> Copy() override;
19943
+ void Serialize(Serializer &serializer) override;
19944
+ static unique_ptr<BaseStatistics> Deserialize(Deserializer &source, LogicalType type);
19945
+ void Verify(Vector &vector, const SelectionVector &sel, idx_t count) override;
19946
+
19947
+ FilterPropagateResult CheckZonemap(ExpressionType comparison_type, const string &value);
19948
+
19949
+ string ToString() override;
19950
+ };
19951
+
19952
+ } // namespace duckdb
19953
+ //===----------------------------------------------------------------------===//
19954
+ // DuckDB
19955
+ //
19956
+ // duckdb/storage/statistics/numeric_statistics.hpp
19957
+ //
19958
+ //
19959
+ //===----------------------------------------------------------------------===//
19960
+
19961
+
19962
+
19963
+
19964
+
19965
+
19966
+
19967
+
19968
+
19969
+
19970
+
19971
+ //===----------------------------------------------------------------------===//
19972
+ // DuckDB
19973
+ //
19974
+ // duckdb/common/windows_undefs.hpp
19975
+ //
19976
+ //
19977
+ //===----------------------------------------------------------------------===//
19978
+
19979
+
19980
+
19981
+ #ifdef WIN32
19982
+
19983
+ #ifdef min
19984
+ #undef min
19985
+ #endif
19986
+
19987
+ #ifdef max
19988
+ #undef max
19989
+ #endif
19990
+
19991
+ #ifdef ERROR
19992
+ #undef ERROR
19993
+ #endif
19994
+
19995
+ #ifdef small
19996
+ #undef small
19997
+ #endif
19998
+
19999
+ #ifdef CreateDirectory
20000
+ #undef CreateDirectory
20001
+ #endif
20002
+
20003
+ #ifdef MoveFile
20004
+ #undef MoveFile
20005
+ #endif
20006
+
20007
+ #ifdef RemoveDirectory
20008
+ #undef RemoveDirectory
20009
+ #endif
20010
+
20011
+ #endif
20012
+
20013
+
20014
+
20015
+ namespace duckdb {
20016
+
20017
+ class NumericStatistics : public BaseStatistics {
20018
+ public:
20019
+ explicit NumericStatistics(LogicalType type);
20020
+ NumericStatistics(LogicalType type, Value min, Value max);
20021
+
20022
+ //! The minimum value of the segment
20023
+ Value min;
20024
+ //! The maximum value of the segment
20025
+ Value max;
20026
+
20027
+ public:
20028
+ void Merge(const BaseStatistics &other) override;
20029
+
20030
+ bool IsConstant() override;
20031
+
20032
+ FilterPropagateResult CheckZonemap(ExpressionType comparison_type, const Value &constant);
20033
+
20034
+ unique_ptr<BaseStatistics> Copy() override;
20035
+ void Serialize(Serializer &serializer) override;
20036
+ static unique_ptr<BaseStatistics> Deserialize(Deserializer &source, LogicalType type);
20037
+ void Verify(Vector &vector, const SelectionVector &sel, idx_t count) override;
20038
+
20039
+ string ToString() override;
20040
+
20041
+ private:
20042
+ template <class T>
20043
+ void TemplatedVerify(Vector &vector, const SelectionVector &sel, idx_t count);
20044
+
20045
+ public:
20046
+ template <class T>
20047
+ static inline void UpdateValue(T new_value, T &min, T &max) {
20048
+ if (LessThan::Operation(new_value, min)) {
20049
+ min = new_value;
20050
+ }
20051
+ if (GreaterThan::Operation(new_value, max)) {
20052
+ max = new_value;
20053
+ }
20054
+ }
20055
+
20056
+ template <class T>
20057
+ static inline void Update(SegmentStatistics &stats, T new_value);
20058
+ };
20059
+
20060
+ template <>
20061
+ void NumericStatistics::Update<int8_t>(SegmentStatistics &stats, int8_t new_value);
20062
+ template <>
20063
+ void NumericStatistics::Update<int16_t>(SegmentStatistics &stats, int16_t new_value);
20064
+ template <>
20065
+ void NumericStatistics::Update<int32_t>(SegmentStatistics &stats, int32_t new_value);
20066
+ template <>
20067
+ void NumericStatistics::Update<int64_t>(SegmentStatistics &stats, int64_t new_value);
20068
+ template <>
20069
+ void NumericStatistics::Update<uint8_t>(SegmentStatistics &stats, uint8_t new_value);
20070
+ template <>
20071
+ void NumericStatistics::Update<uint16_t>(SegmentStatistics &stats, uint16_t new_value);
20072
+ template <>
20073
+ void NumericStatistics::Update<uint32_t>(SegmentStatistics &stats, uint32_t new_value);
20074
+ template <>
20075
+ void NumericStatistics::Update<uint64_t>(SegmentStatistics &stats, uint64_t new_value);
20076
+ template <>
20077
+ void NumericStatistics::Update<hugeint_t>(SegmentStatistics &stats, hugeint_t new_value);
20078
+ template <>
20079
+ void NumericStatistics::Update<float>(SegmentStatistics &stats, float new_value);
20080
+ template <>
20081
+ void NumericStatistics::Update<double>(SegmentStatistics &stats, double new_value);
20082
+ template <>
20083
+ void NumericStatistics::Update<interval_t>(SegmentStatistics &stats, interval_t new_value);
20084
+ template <>
20085
+ void NumericStatistics::Update<list_entry_t>(SegmentStatistics &stats, list_entry_t new_value);
20086
+
20087
+ } // namespace duckdb
20088
+ //===----------------------------------------------------------------------===//
20089
+ // DuckDB
20090
+ //
20091
+ // duckdb/planner/filter/conjunction_filter.hpp
20092
+ //
20093
+ //
20094
+ //===----------------------------------------------------------------------===//
20095
+
20096
+
20097
+
20098
+
20099
+
20100
+
20101
+ namespace duckdb {
20102
+
20103
+ class ConjunctionOrFilter : public TableFilter {
20104
+ public:
20105
+ ConjunctionOrFilter();
20106
+
20107
+ //! The filters to OR together
20108
+ vector<unique_ptr<TableFilter>> child_filters;
20109
+
20110
+ public:
20111
+ FilterPropagateResult CheckStatistics(BaseStatistics &stats) override;
20112
+ string ToString(const string &column_name) override;
20113
+ bool Equals(const TableFilter &other) const override;
20114
+ };
20115
+
20116
+ class ConjunctionAndFilter : public TableFilter {
20117
+ public:
20118
+ ConjunctionAndFilter();
20119
+
20120
+ //! The filters to OR together
20121
+ vector<unique_ptr<TableFilter>> child_filters;
20122
+
20123
+ public:
20124
+ FilterPropagateResult CheckStatistics(BaseStatistics &stats) override;
20125
+ string ToString(const string &column_name) override;
20126
+ bool Equals(const TableFilter &other) const override;
20127
+ };
20128
+
20129
+ } // namespace duckdb
20130
+ //===----------------------------------------------------------------------===//
20131
+ // DuckDB
20132
+ //
20133
+ // duckdb/planner/filter/constant_filter.hpp
20134
+ //
20135
+ //
20136
+ //===----------------------------------------------------------------------===//
20137
+
20138
+
20139
+
20140
+
20141
+
20142
+
20143
+
20144
+ namespace duckdb {
20145
+
20146
+ class ConstantFilter : public TableFilter {
20147
+ public:
20148
+ ConstantFilter(ExpressionType comparison_type, Value constant);
20149
+
20150
+ //! The comparison type (e.g. COMPARE_EQUAL, COMPARE_GREATERTHAN, COMPARE_LESSTHAN, ...)
20151
+ ExpressionType comparison_type;
20152
+ //! The constant value to filter on
20153
+ Value constant;
20154
+
20155
+ public:
20156
+ FilterPropagateResult CheckStatistics(BaseStatistics &stats) override;
20157
+ string ToString(const string &column_name) override;
20158
+ bool Equals(const TableFilter &other) const override;
20159
+ };
20160
+
20161
+ } // namespace duckdb
20162
+ //===----------------------------------------------------------------------===//
20163
+ // DuckDB
20164
+ //
20165
+ // duckdb/execution/operator/persistent/buffered_csv_reader.hpp
20166
+ //
20167
+ //
20168
+ //===----------------------------------------------------------------------===//
20169
+
20170
+
20171
+
20172
+
20173
+
20174
+ //===----------------------------------------------------------------------===//
20175
+ // DuckDB
20176
+ //
20177
+ // duckdb/function/scalar/strftime.hpp
20178
+ //
20179
+ //
20180
+ //===----------------------------------------------------------------------===//
20181
+
20182
+
20183
+
20184
+
20185
+
20186
+
20187
+ namespace duckdb {
20188
+
20189
+ enum class StrTimeSpecifier : uint8_t {
20190
+ ABBREVIATED_WEEKDAY_NAME = 0, // %a - Abbreviated weekday name. (Sun, Mon, ...)
20191
+ FULL_WEEKDAY_NAME = 1, // %A Full weekday name. (Sunday, Monday, ...)
20192
+ WEEKDAY_DECIMAL = 2, // %w - Weekday as a decimal number. (0, 1, ..., 6)
20193
+ DAY_OF_MONTH_PADDED = 3, // %d - Day of the month as a zero-padded decimal. (01, 02, ..., 31)
20194
+ DAY_OF_MONTH = 4, // %-d - Day of the month as a decimal number. (1, 2, ..., 30)
20195
+ ABBREVIATED_MONTH_NAME = 5, // %b - Abbreviated month name. (Jan, Feb, ..., Dec)
20196
+ FULL_MONTH_NAME = 6, // %B - Full month name. (January, February, ...)
20197
+ MONTH_DECIMAL_PADDED = 7, // %m - Month as a zero-padded decimal number. (01, 02, ..., 12)
20198
+ MONTH_DECIMAL = 8, // %-m - Month as a decimal number. (1, 2, ..., 12)
20199
+ YEAR_WITHOUT_CENTURY_PADDED = 9, // %y - Year without century as a zero-padded decimal number. (00, 01, ..., 99)
20200
+ YEAR_WITHOUT_CENTURY = 10, // %-y - Year without century as a decimal number. (0, 1, ..., 99)
20201
+ YEAR_DECIMAL = 11, // %Y - Year with century as a decimal number. (2013, 2019 etc.)
20202
+ HOUR_24_PADDED = 12, // %H - Hour (24-hour clock) as a zero-padded decimal number. (00, 01, ..., 23)
20203
+ HOUR_24_DECIMAL = 13, // %-H - Hour (24-hour clock) as a decimal number. (0, 1, ..., 23)
20204
+ HOUR_12_PADDED = 14, // %I - Hour (12-hour clock) as a zero-padded decimal number. (01, 02, ..., 12)
20205
+ HOUR_12_DECIMAL = 15, // %-I - Hour (12-hour clock) as a decimal number. (1, 2, ... 12)
20206
+ AM_PM = 16, // %p - Locale’s AM or PM. (AM, PM)
20207
+ MINUTE_PADDED = 17, // %M - Minute as a zero-padded decimal number. (00, 01, ..., 59)
20208
+ MINUTE_DECIMAL = 18, // %-M - Minute as a decimal number. (0, 1, ..., 59)
20209
+ SECOND_PADDED = 19, // %S - Second as a zero-padded decimal number. (00, 01, ..., 59)
20210
+ SECOND_DECIMAL = 20, // %-S - Second as a decimal number. (0, 1, ..., 59)
20211
+ MICROSECOND_PADDED = 21, // %f - Microsecond as a decimal number, zero-padded on the left. (000000 - 999999)
20212
+ MILLISECOND_PADDED = 22, // %g - Millisecond as a decimal number, zero-padded on the left. (000 - 999)
20213
+ UTC_OFFSET = 23, // %z - UTC offset in the form +HHMM or -HHMM. ( )
20214
+ TZ_NAME = 24, // %Z - Time zone name. ( )
20215
+ DAY_OF_YEAR_PADDED = 25, // %j - Day of the year as a zero-padded decimal number. (001, 002, ..., 366)
20216
+ DAY_OF_YEAR_DECIMAL = 26, // %-j - Day of the year as a decimal number. (1, 2, ..., 366)
20217
+ WEEK_NUMBER_PADDED_SUN_FIRST =
20218
+ 27, // %U - Week number of the year (Sunday as the first day of the week). All days in a new year preceding the
20219
+ // first Sunday are considered to be in week 0. (00, 01, ..., 53)
20220
+ WEEK_NUMBER_PADDED_MON_FIRST =
20221
+ 28, // %W - Week number of the year (Monday as the first day of the week). All days in a new year preceding the
20222
+ // first Monday are considered to be in week 0. (00, 01, ..., 53)
20223
+ LOCALE_APPROPRIATE_DATE_AND_TIME =
20224
+ 29, // %c - Locale’s appropriate date and time representation. (Mon Sep 30 07:06:05 2013)
20225
+ LOCALE_APPROPRIATE_DATE = 30, // %x - Locale’s appropriate date representation. (09/30/13)
20226
+ LOCALE_APPROPRIATE_TIME = 31 // %X - Locale’s appropriate time representation. (07:06:05)
20227
+ };
20228
+
20229
+ struct StrTimeFormat {
20230
+ public:
20231
+ virtual ~StrTimeFormat() {
20232
+ }
20233
+
20234
+ static string ParseFormatSpecifier(const string &format_string, StrTimeFormat &format);
20235
+
20236
+ protected:
20237
+ //! The format specifiers
20238
+ vector<StrTimeSpecifier> specifiers;
20239
+ //! The literals that appear in between the format specifiers
20240
+ //! The following must hold: literals.size() = specifiers.size() + 1
20241
+ //! Format is literals[0], specifiers[0], literals[1], ..., specifiers[n - 1], literals[n]
20242
+ vector<string> literals;
20243
+ //! The constant size that appears in the format string
20244
+ idx_t constant_size;
20245
+ //! The max numeric width of the specifier (if it is parsed as a number), or -1 if it is not a number
20246
+ vector<int> numeric_width;
20247
+
20248
+ protected:
20249
+ void AddLiteral(string literal);
20250
+ virtual void AddFormatSpecifier(string preceding_literal, StrTimeSpecifier specifier);
20251
+ };
20252
+
20253
+ struct StrfTimeFormat : public StrTimeFormat {
20254
+ idx_t GetLength(date_t date, dtime_t time);
20255
+
20256
+ void FormatString(date_t date, int32_t data[7], char *target);
20257
+ void FormatString(date_t date, dtime_t time, char *target);
20258
+
20259
+ static string Format(timestamp_t timestamp, const string &format);
20260
+
20261
+ protected:
20262
+ //! The variable-length specifiers. To determine total string size, these need to be checked.
20263
+ vector<StrTimeSpecifier> var_length_specifiers;
20264
+ //! Whether or not the current specifier is a special "date" specifier (i.e. one that requires a date_t object to
20265
+ //! generate)
20266
+ vector<bool> is_date_specifier;
20267
+
20268
+ protected:
20269
+ void AddFormatSpecifier(string preceding_literal, StrTimeSpecifier specifier) override;
20270
+ static idx_t GetSpecifierLength(StrTimeSpecifier specifier, date_t date, dtime_t time);
20271
+ char *WriteString(char *target, const string_t &str);
20272
+ char *Write2(char *target, uint8_t value);
20273
+ char *WritePadded2(char *target, int32_t value);
20274
+ char *WritePadded3(char *target, uint32_t value);
20275
+ char *WritePadded(char *target, int32_t value, int32_t padding);
20276
+ bool IsDateSpecifier(StrTimeSpecifier specifier);
20277
+ char *WriteDateSpecifier(StrTimeSpecifier specifier, date_t date, char *target);
20278
+ char *WriteStandardSpecifier(StrTimeSpecifier specifier, int32_t data[], char *target);
20279
+ };
20280
+
20281
+ struct StrpTimeFormat : public StrTimeFormat {
20282
+ public:
20283
+ //! Type-safe parsing argument
20284
+ struct ParseResult {
20285
+ int32_t data[7];
20286
+ string error_message;
20287
+ idx_t error_position = DConstants::INVALID_INDEX;
20288
+
20289
+ date_t ToDate();
20290
+ timestamp_t ToTimestamp();
20291
+ string FormatError(string_t input, const string &format_specifier);
20292
+ };
20293
+ //! The full format specifier, for error messages
20294
+ string format_specifier;
20295
+
20296
+ bool Parse(string_t str, ParseResult &result);
20297
+
20298
+ bool TryParseDate(string_t str, date_t &result, string &error_message);
20299
+ bool TryParseTimestamp(string_t str, timestamp_t &result, string &error_message);
20300
+
20301
+ date_t ParseDate(string_t str);
20302
+ timestamp_t ParseTimestamp(string_t str);
20303
+
20304
+ protected:
20305
+ static string FormatStrpTimeError(const string &input, idx_t position);
20306
+ void AddFormatSpecifier(string preceding_literal, StrTimeSpecifier specifier) override;
20307
+ int NumericSpecifierWidth(StrTimeSpecifier specifier);
20308
+ int32_t TryParseCollection(const char *data, idx_t &pos, idx_t size, const string_t collection[],
20309
+ idx_t collection_count);
20310
+ };
20311
+
20312
+ } // namespace duckdb
20313
+
20314
+
20315
+
20316
+
20317
+
20318
+ #include <sstream>
20319
+ #include <queue>
20320
+
20321
+ namespace duckdb {
20322
+ struct CopyInfo;
20323
+ struct FileHandle;
20324
+ struct StrpTimeFormat;
20325
+
20326
+ class FileOpener;
20327
+ class FileSystem;
20328
+
20329
+ //! The shifts array allows for linear searching of multi-byte values. For each position, it determines the next
20330
+ //! position given that we encounter a byte with the given value.
20331
+ /*! For example, if we have a string "ABAC", the shifts array will have the following values:
20332
+ * [0] --> ['A'] = 1, all others = 0
20333
+ * [1] --> ['B'] = 2, ['A'] = 1, all others = 0
20334
+ * [2] --> ['A'] = 3, all others = 0
20335
+ * [3] --> ['C'] = 4 (match), 'B' = 2, 'A' = 1, all others = 0
20336
+ * Suppose we then search in the following string "ABABAC", our progression will be as follows:
20337
+ * 'A' -> [1], 'B' -> [2], 'A' -> [3], 'B' -> [2], 'A' -> [3], 'C' -> [4] (match!)
20338
+ */
20339
+ struct TextSearchShiftArray {
20340
+ TextSearchShiftArray();
20341
+ explicit TextSearchShiftArray(string search_term);
20342
+
20343
+ inline bool Match(uint8_t &position, uint8_t byte_value) {
20344
+ if (position >= length) {
20345
+ return false;
20346
+ }
20347
+ position = shifts[position * 255 + byte_value];
20348
+ return position == length;
20349
+ }
20350
+
20351
+ idx_t length;
20352
+ unique_ptr<uint8_t[]> shifts;
20353
+ };
20354
+
20355
+ struct BufferedCSVReaderOptions {
20356
+ //! The file path of the CSV file to read
20357
+ string file_path;
20358
+ //! Whether file is compressed or not, and if so which compression type
20359
+ //! AUTO_DETECT (default; infer from file extension)
20360
+ FileCompressionType compression = FileCompressionType::AUTO_DETECT;
20361
+ //! Whether or not to automatically detect dialect and datatypes
20362
+ bool auto_detect = false;
20363
+ //! Whether or not a delimiter was defined by the user
20364
+ bool has_delimiter = false;
20365
+ //! Delimiter to separate columns within each line
20366
+ string delimiter = ",";
20367
+ //! Whether or not a quote sign was defined by the user
20368
+ bool has_quote = false;
20369
+ //! Quote used for columns that contain reserved characters, e.g., delimiter
20370
+ string quote = "\"";
20371
+ //! Whether or not an escape character was defined by the user
20372
+ bool has_escape = false;
20373
+ //! Escape character to escape quote character
20374
+ string escape;
20375
+ //! Whether or not a header information was given by the user
20376
+ bool has_header = false;
20377
+ //! Whether or not the file has a header line
20378
+ bool header = false;
20379
+ //! Whether or not header names shall be normalized
20380
+ bool normalize_names = false;
20381
+ //! How many leading rows to skip
20382
+ idx_t skip_rows = 0;
20383
+ //! Expected number of columns
20384
+ idx_t num_cols = 0;
20385
+ //! Specifies the string that represents a null value
20386
+ string null_str;
20387
+ //! True, if column with that index must skip null check
20388
+ vector<bool> force_not_null;
20389
+ //! Size of sample chunk used for dialect and type detection
20390
+ idx_t sample_chunk_size = STANDARD_VECTOR_SIZE;
20391
+ //! Number of sample chunks used for type detection
20392
+ idx_t sample_chunks = 10;
20393
+ //! Number of samples to buffer
20394
+ idx_t buffer_size = STANDARD_VECTOR_SIZE * 100;
20395
+ //! Consider all columns to be of type varchar
20396
+ bool all_varchar = false;
20397
+ //! The date format to use (if any is specified)
20398
+ std::map<LogicalTypeId, StrpTimeFormat> date_format = {{LogicalTypeId::DATE, {}}, {LogicalTypeId::TIMESTAMP, {}}};
20399
+ //! Whether or not a type format is specified
20400
+ std::map<LogicalTypeId, bool> has_format = {{LogicalTypeId::DATE, false}, {LogicalTypeId::TIMESTAMP, false}};
20401
+
20402
+ void SetDelimiter(const string &delimiter);
20403
+
20404
+ std::string ToString() const;
20405
+ };
20406
+
20407
+ enum class ParserMode : uint8_t { PARSING = 0, SNIFFING_DIALECT = 1, SNIFFING_DATATYPES = 2, PARSING_HEADER = 3 };
20408
+
20409
+ //! Buffered CSV reader is a class that reads values from a stream and parses them as a CSV file
20410
+ class BufferedCSVReader {
20411
+ //! Initial buffer read size; can be extended for long lines
20412
+ static constexpr idx_t INITIAL_BUFFER_SIZE = 16384;
20413
+ //! Maximum CSV line size: specified because if we reach this amount, we likely have the wrong delimiters
20414
+ static constexpr idx_t MAXIMUM_CSV_LINE_SIZE = 1048576;
20415
+ ParserMode mode;
20416
+
20417
+ public:
20418
+ BufferedCSVReader(ClientContext &context, BufferedCSVReaderOptions options,
20419
+ const vector<LogicalType> &requested_types = vector<LogicalType>());
20420
+
20421
+ BufferedCSVReader(FileSystem &fs, FileOpener *opener, BufferedCSVReaderOptions options,
20422
+ const vector<LogicalType> &requested_types = vector<LogicalType>());
20423
+
20424
+ FileSystem &fs;
20425
+ FileOpener *opener;
20426
+ BufferedCSVReaderOptions options;
20427
+ vector<LogicalType> sql_types;
20428
+ vector<string> col_names;
20429
+ unique_ptr<FileHandle> file_handle;
20430
+ bool plain_file_source = false;
20431
+ idx_t file_size = 0;
20432
+
20433
+ unique_ptr<char[]> buffer;
20434
+ idx_t buffer_size;
20435
+ idx_t position;
20436
+ idx_t start = 0;
20437
+
20438
+ idx_t linenr = 0;
20439
+ bool linenr_estimated = false;
20440
+
20441
+ vector<idx_t> sniffed_column_counts;
20442
+ bool row_empty = false;
20443
+ idx_t sample_chunk_idx = 0;
20444
+ bool jumping_samples = false;
20445
+ bool end_of_file_reached = false;
20446
+ bool bom_checked = false;
20447
+
20448
+ idx_t bytes_in_chunk = 0;
20449
+ double bytes_per_line_avg = 0;
20450
+
20451
+ vector<unique_ptr<char[]>> cached_buffers;
20452
+
20453
+ TextSearchShiftArray delimiter_search, escape_search, quote_search;
20454
+
20455
+ DataChunk parse_chunk;
20456
+
20457
+ std::queue<unique_ptr<DataChunk>> cached_chunks;
20458
+
20459
+ public:
20460
+ //! Extract a single DataChunk from the CSV file and stores it in insert_chunk
20461
+ void ParseCSV(DataChunk &insert_chunk);
20462
+
20463
+ private:
20464
+ //! Initialize Parser
20465
+ void Initialize(const vector<LogicalType> &requested_types);
20466
+ //! Initializes the parse_chunk with varchar columns and aligns info with new number of cols
20467
+ void InitParseChunk(idx_t num_cols);
20468
+ //! Initializes the TextSearchShiftArrays for complex parser
20469
+ void PrepareComplexParser();
20470
+ //! Try to parse a single datachunk from the file. Throws an exception if anything goes wrong.
20471
+ void ParseCSV(ParserMode mode);
20472
+ //! Try to parse a single datachunk from the file. Returns whether or not the parsing is successful
20473
+ bool TryParseCSV(ParserMode mode);
20474
+ //! Extract a single DataChunk from the CSV file and stores it in insert_chunk
20475
+ bool TryParseCSV(ParserMode mode, DataChunk &insert_chunk, string &error_message);
20476
+ //! Sniffs CSV dialect and determines skip rows, header row, column types and column names
20477
+ vector<LogicalType> SniffCSV(const vector<LogicalType> &requested_types);
20478
+ //! Change the date format for the type to the string
20479
+ void SetDateFormat(const string &format_specifier, const LogicalTypeId &sql_type);
20480
+ //! Try to cast a string value to the specified sql type
20481
+ bool TryCastValue(const Value &value, const LogicalType &sql_type);
20482
+ //! Try to cast a vector of values to the specified sql type
20483
+ bool TryCastVector(Vector &parse_chunk_col, idx_t size, const LogicalType &sql_type);
20484
+ //! Skips skip_rows, reads header row from input stream
20485
+ void SkipRowsAndReadHeader(idx_t skip_rows, bool skip_header);
20486
+ //! Jumps back to the beginning of input stream and resets necessary internal states
20487
+ void JumpToBeginning(idx_t skip_rows, bool skip_header);
20488
+ //! Jumps back to the beginning of input stream and resets necessary internal states
20489
+ bool JumpToNextSample();
20490
+ //! Resets the buffer
20491
+ void ResetBuffer();
20492
+ //! Resets the steam
20493
+ void ResetStream();
20494
+
20495
+ //! Parses a CSV file with a one-byte delimiter, escape and quote character
20496
+ bool TryParseSimpleCSV(DataChunk &insert_chunk, string &error_message);
20497
+ //! Parses more complex CSV files with multi-byte delimiters, escapes or quotes
20498
+ bool TryParseComplexCSV(DataChunk &insert_chunk, string &error_message);
20499
+
20500
+ //! Adds a value to the current row
20501
+ void AddValue(char *str_val, idx_t length, idx_t &column, vector<idx_t> &escape_positions);
20502
+ //! Adds a row to the insert_chunk, returns true if the chunk is filled as a result of this row being added
20503
+ bool AddRow(DataChunk &insert_chunk, idx_t &column);
20504
+ //! Finalizes a chunk, parsing all values that have been added so far and adding them to the insert_chunk
20505
+ void Flush(DataChunk &insert_chunk);
20506
+ //! Reads a new buffer from the CSV file if the current one has been exhausted
20507
+ bool ReadBuffer(idx_t &start);
20508
+
20509
+ unique_ptr<FileHandle> OpenCSV(const BufferedCSVReaderOptions &options);
20510
+
20511
+ //! First phase of auto detection: detect CSV dialect (i.e. delimiter, quote rules, etc)
20512
+ void DetectDialect(const vector<LogicalType> &requested_types, BufferedCSVReaderOptions &original_options,
20513
+ vector<BufferedCSVReaderOptions> &info_candidates, idx_t &best_num_cols);
20514
+ //! Second phase of auto detection: detect candidate types for each column
20515
+ void DetectCandidateTypes(const vector<LogicalType> &type_candidates,
20516
+ const map<LogicalTypeId, vector<const char *>> &format_template_candidates,
20517
+ const vector<BufferedCSVReaderOptions> &info_candidates,
20518
+ BufferedCSVReaderOptions &original_options, idx_t best_num_cols,
20519
+ vector<vector<LogicalType>> &best_sql_types_candidates,
20520
+ std::map<LogicalTypeId, vector<string>> &best_format_candidates,
20521
+ DataChunk &best_header_row);
20522
+ //! Third phase of auto detection: detect header of CSV file
20523
+ void DetectHeader(const vector<vector<LogicalType>> &best_sql_types_candidates, const DataChunk &best_header_row);
20524
+ //! Fourth phase of auto detection: refine the types of each column and select which types to use for each column
20525
+ vector<LogicalType> RefineTypeDetection(const vector<LogicalType> &type_candidates,
20526
+ const vector<LogicalType> &requested_types,
20527
+ vector<vector<LogicalType>> &best_sql_types_candidates,
20528
+ map<LogicalTypeId, vector<string>> &best_format_candidates);
20529
+ };
20530
+
20531
+ } // namespace duckdb
20532
+ //===----------------------------------------------------------------------===//
20533
+ // DuckDB
20534
+ //
20535
+ // duckdb/common/types/vector_cache.hpp
20536
+ //
20537
+ //
20538
+ //===----------------------------------------------------------------------===//
20539
+
20540
+
20541
+
20542
+
20543
+
20544
+
20545
+
20546
+ namespace duckdb {
20547
+ class Vector;
20548
+
20549
+ //! The VectorCache holds cached data that allows for re-use of the same memory by vectors
20550
+ class VectorCache {
20551
+ public:
20552
+ //! Instantiate a vector cache with the given type
20553
+ explicit VectorCache(const LogicalType &type);
20554
+
20555
+ buffer_ptr<VectorBuffer> buffer;
20556
+
20557
+ public:
20558
+ void ResetFromCache(Vector &result) const;
20559
+
20560
+ const LogicalType &GetType() const;
20561
+ };
20562
+
20563
+ } // namespace duckdb
20564
+ //===----------------------------------------------------------------------===//
20565
+ // DuckDB
20566
+ //
20567
+ // duckdb/planner/filter/null_filter.hpp
20568
+ //
20569
+ //
20570
+ //===----------------------------------------------------------------------===//
20571
+
20572
+
20573
+
20574
+
20575
+
20576
+ namespace duckdb {
20577
+
20578
+ class IsNullFilter : public TableFilter {
20579
+ public:
20580
+ IsNullFilter();
20581
+
20582
+ public:
20583
+ FilterPropagateResult CheckStatistics(BaseStatistics &stats) override;
20584
+ string ToString(const string &column_name) override;
20585
+ };
20586
+
20587
+ class IsNotNullFilter : public TableFilter {
20588
+ public:
20589
+ IsNotNullFilter();
20590
+
20591
+ public:
20592
+ FilterPropagateResult CheckStatistics(BaseStatistics &stats) override;
20593
+ string ToString(const string &column_name) override;
20594
+ };
20595
+
20596
+ } // namespace duckdb
20597
+ //===----------------------------------------------------------------------===//
20598
+ // DuckDB
20599
+ //
20600
+ // duckdb/common/arrow_wrapper.hpp
20601
+ //
20602
+ //
20603
+ //===----------------------------------------------------------------------===//
20604
+
20605
+
20606
+
20607
+
20608
+
20609
+
20610
+ //! Here we have the internal duckdb classes that interact with Arrow's Internal Header (i.e., duckdb/commons/arrow.hpp)
20611
+ namespace duckdb {
20612
+ class ArrowSchemaWrapper {
20613
+ public:
20614
+ ArrowSchema arrow_schema;
20615
+
20616
+ ArrowSchemaWrapper() {
20617
+ arrow_schema.release = nullptr;
20618
+ }
20619
+
20620
+ ~ArrowSchemaWrapper();
20621
+ };
20622
+ class ArrowArrayWrapper {
20623
+ public:
20624
+ ArrowArray arrow_array;
20625
+ ArrowArrayWrapper() {
20626
+ arrow_array.length = 0;
20627
+ arrow_array.release = nullptr;
20628
+ }
20629
+ ~ArrowArrayWrapper();
20630
+ };
20631
+
20632
+ class ArrowArrayStreamWrapper {
20633
+ public:
20634
+ ArrowArrayStream arrow_array_stream;
20635
+ int64_t number_of_rows;
20636
+ void GetSchema(ArrowSchemaWrapper &schema);
20637
+
20638
+ unique_ptr<ArrowArrayWrapper> GetNextChunk();
20639
+
20640
+ const char *GetError();
20641
+
20642
+ ~ArrowArrayStreamWrapper();
20643
+ ArrowArrayStreamWrapper() {
20644
+ arrow_array_stream.release = nullptr;
20645
+ }
20646
+ };
20647
+
20648
+ class ResultArrowArrayStreamWrapper {
20649
+ public:
20650
+ explicit ResultArrowArrayStreamWrapper(unique_ptr<QueryResult> result, idx_t approx_batch_size);
20651
+ ArrowArrayStream stream;
20652
+ unique_ptr<QueryResult> result;
20653
+ std::string last_error;
20654
+ idx_t vectors_per_chunk;
20655
+
20656
+ private:
20657
+ static int MyStreamGetSchema(struct ArrowArrayStream *stream, struct ArrowSchema *out);
20658
+ static int MyStreamGetNext(struct ArrowArrayStream *stream, struct ArrowArray *out);
20659
+ static void MyStreamRelease(struct ArrowArrayStream *stream);
20660
+ static const char *MyStreamGetLastError(struct ArrowArrayStream *stream);
20661
+ };
20662
+
20663
+ } // namespace duckdb
20664
+ //===----------------------------------------------------------------------===//
20665
+ // DuckDB
20666
+ //
20667
+ // duckdb/common/compressed_file_system.hpp
20668
+ //
20669
+ //
20670
+ //===----------------------------------------------------------------------===//
20671
+
20672
+
20673
+
20674
+
20675
+
20676
+
20677
+ namespace duckdb {
20678
+ class CompressedFile;
20679
+
20680
+ struct StreamData {
20681
+ // various buffers & pointers
20682
+ bool write = false;
20683
+ unique_ptr<data_t[]> in_buff;
20684
+ unique_ptr<data_t[]> out_buff;
20685
+ data_ptr_t out_buff_start = nullptr;
20686
+ data_ptr_t out_buff_end = nullptr;
20687
+ data_ptr_t in_buff_start = nullptr;
20688
+ data_ptr_t in_buff_end = nullptr;
20689
+
20690
+ idx_t in_buf_size = 0;
20691
+ idx_t out_buf_size = 0;
20692
+ };
20693
+
20694
+ struct StreamWrapper {
20695
+ DUCKDB_API virtual ~StreamWrapper();
20696
+
20697
+ DUCKDB_API virtual void Initialize(CompressedFile &file, bool write) = 0;
20698
+ DUCKDB_API virtual bool Read(StreamData &stream_data) = 0;
20699
+ DUCKDB_API virtual void Write(CompressedFile &file, StreamData &stream_data, data_ptr_t buffer,
20700
+ int64_t nr_bytes) = 0;
20701
+ DUCKDB_API virtual void Close() = 0;
20702
+ };
20703
+
20704
+ class CompressedFileSystem : public FileSystem {
20705
+ public:
20706
+ DUCKDB_API int64_t Read(FileHandle &handle, void *buffer, int64_t nr_bytes) override;
20707
+ DUCKDB_API int64_t Write(FileHandle &handle, void *buffer, int64_t nr_bytes) override;
20708
+
20709
+ DUCKDB_API void Reset(FileHandle &handle) override;
20710
+
20711
+ DUCKDB_API int64_t GetFileSize(FileHandle &handle) override;
20712
+
20713
+ DUCKDB_API bool OnDiskFile(FileHandle &handle) override;
20714
+ DUCKDB_API bool CanSeek() override;
20715
+
20716
+ DUCKDB_API virtual unique_ptr<StreamWrapper> CreateStream() = 0;
20717
+ DUCKDB_API virtual idx_t InBufferSize() = 0;
20718
+ DUCKDB_API virtual idx_t OutBufferSize() = 0;
20719
+ };
20720
+
20721
+ class CompressedFile : public FileHandle {
20722
+ public:
20723
+ DUCKDB_API CompressedFile(CompressedFileSystem &fs, unique_ptr<FileHandle> child_handle_p, const string &path);
20724
+ DUCKDB_API virtual ~CompressedFile() override;
20725
+
20726
+ CompressedFileSystem &compressed_fs;
20727
+ unique_ptr<FileHandle> child_handle;
20728
+ //! Whether the file is opened for reading or for writing
20729
+ bool write = false;
20730
+ StreamData stream_data;
20731
+
20732
+ public:
20733
+ DUCKDB_API void Initialize(bool write);
20734
+ DUCKDB_API int64_t ReadData(void *buffer, int64_t nr_bytes);
20735
+ DUCKDB_API int64_t WriteData(data_ptr_t buffer, int64_t nr_bytes);
20736
+ DUCKDB_API void Close() override;
20737
+
20738
+ private:
20739
+ unique_ptr<StreamWrapper> stream_wrapper;
20740
+ };
20741
+
20742
+ } // namespace duckdb
20743
+ //===----------------------------------------------------------------------===//
20744
+ // DuckDB
20745
+ //
20746
+ // duckdb/parser/expression/between_expression.hpp
20747
+ //
20748
+ //
20749
+ //===----------------------------------------------------------------------===//
20750
+
20751
+
20752
+
20753
+
20754
+
20755
+ namespace duckdb {
20756
+
20757
+ class BetweenExpression : public ParsedExpression {
20758
+ public:
20759
+ BetweenExpression(unique_ptr<ParsedExpression> input, unique_ptr<ParsedExpression> lower,
20760
+ unique_ptr<ParsedExpression> upper);
20761
+
20762
+ unique_ptr<ParsedExpression> input;
20763
+ unique_ptr<ParsedExpression> lower;
20764
+ unique_ptr<ParsedExpression> upper;
20765
+
20766
+ public:
20767
+ string ToString() const override;
20768
+
20769
+ static bool Equals(const BetweenExpression *a, const BetweenExpression *b);
20770
+
20771
+ unique_ptr<ParsedExpression> Copy() const override;
20772
+
20773
+ void Serialize(Serializer &serializer) override;
20774
+ static unique_ptr<ParsedExpression> Deserialize(ExpressionType type, Deserializer &source);
20775
+ };
20776
+ } // namespace duckdb
20777
+ //===----------------------------------------------------------------------===//
20778
+ // DuckDB
20779
+ //
20780
+ // duckdb/parser/expression/positional_reference_expression.hpp
20781
+ //
20782
+ //
20783
+ //===----------------------------------------------------------------------===//
20784
+
20785
+
20786
+
20787
+
20788
+
20789
+ namespace duckdb {
20790
+ class PositionalReferenceExpression : public ParsedExpression {
20791
+ public:
20792
+ PositionalReferenceExpression(idx_t index);
20793
+
20794
+ idx_t index;
20795
+
20796
+ public:
20797
+ bool IsScalar() const override {
20798
+ return false;
20799
+ }
20800
+
20801
+ string ToString() const override;
20802
+
20803
+ static bool Equals(const PositionalReferenceExpression *a, const PositionalReferenceExpression *b);
20804
+ unique_ptr<ParsedExpression> Copy() const override;
20805
+ hash_t Hash() const override;
20806
+
20807
+ void Serialize(Serializer &serializer) override;
20808
+ static unique_ptr<ParsedExpression> Deserialize(ExpressionType type, Deserializer &source);
20809
+ };
20810
+ } // namespace duckdb
20811
+ //===----------------------------------------------------------------------===//
20812
+ // DuckDB
20813
+ //
20814
+ // duckdb/parser/expression/subquery_expression.hpp
20815
+ //
20816
+ //
20817
+ //===----------------------------------------------------------------------===//
20818
+
20819
+
20820
+
20821
+
20822
+
20823
+
20824
+
20825
+ namespace duckdb {
20826
+
20827
+ //! Represents a subquery
20828
+ class SubqueryExpression : public ParsedExpression {
20829
+ public:
20830
+ SubqueryExpression();
20831
+
20832
+ //! The actual subquery
20833
+ unique_ptr<SelectStatement> subquery;
20834
+ //! The subquery type
20835
+ SubqueryType subquery_type;
20836
+ //! the child expression to compare with (in case of IN, ANY, ALL operators, empty for EXISTS queries and scalar
20837
+ //! subquery)
20838
+ unique_ptr<ParsedExpression> child;
20839
+ //! The comparison type of the child expression with the subquery (in case of ANY, ALL operators), empty otherwise
20840
+ ExpressionType comparison_type;
20841
+
20842
+ public:
20843
+ bool HasSubquery() const override {
20844
+ return true;
20845
+ }
20846
+ bool IsScalar() const override {
20847
+ return false;
20848
+ }
20849
+
20850
+ string ToString() const override;
20851
+
20852
+ static bool Equals(const SubqueryExpression *a, const SubqueryExpression *b);
20853
+
20854
+ unique_ptr<ParsedExpression> Copy() const override;
20855
+
20856
+ void Serialize(Serializer &serializer) override;
20857
+ static unique_ptr<ParsedExpression> Deserialize(ExpressionType type, Deserializer &source);
20858
+ };
20859
+ } // namespace duckdb
20860
+ //===----------------------------------------------------------------------===//
20861
+ // DuckDB
20862
+ //
20863
+ // duckdb/parser/expression/parameter_expression.hpp
20864
+ //
20865
+ //
20866
+ //===----------------------------------------------------------------------===//
20867
+
20868
+
20869
+
20870
+
20871
+
20872
+ namespace duckdb {
20873
+ class ParameterExpression : public ParsedExpression {
20874
+ public:
20875
+ ParameterExpression();
20876
+
20877
+ idx_t parameter_nr;
20878
+
20879
+ public:
20880
+ bool IsScalar() const override {
20881
+ return true;
20882
+ }
20883
+ bool HasParameter() const override {
20884
+ return true;
20885
+ }
20886
+
20887
+ string ToString() const override;
20888
+
20889
+ unique_ptr<ParsedExpression> Copy() const override;
20890
+ hash_t Hash() const override;
20891
+
20892
+ void Serialize(Serializer &serializer) override;
20893
+ static unique_ptr<ParsedExpression> Deserialize(ExpressionType type, Deserializer &source);
20894
+ };
20895
+ } // namespace duckdb
20896
+ //===----------------------------------------------------------------------===//
20897
+ // DuckDB
20898
+ //
20899
+ // duckdb/parser/expression/constant_expression.hpp
20900
+ //
20901
+ //
20902
+ //===----------------------------------------------------------------------===//
20903
+
20904
+
20905
+
20906
+
20907
+
20908
+
20909
+ namespace duckdb {
20910
+
20911
+ //! ConstantExpression represents a constant value in the query
20912
+ class ConstantExpression : public ParsedExpression {
20913
+ public:
20914
+ explicit ConstantExpression(Value val);
20915
+
20916
+ //! The constant value referenced
20917
+ Value value;
20918
+
20919
+ public:
20920
+ string ToString() const override;
20921
+
20922
+ static bool Equals(const ConstantExpression *a, const ConstantExpression *b);
20923
+ hash_t Hash() const override;
20924
+
20925
+ unique_ptr<ParsedExpression> Copy() const override;
20926
+
20927
+ void Serialize(Serializer &serializer) override;
20928
+ static unique_ptr<ParsedExpression> Deserialize(ExpressionType type, Deserializer &source);
20929
+ };
20930
+
20931
+ } // namespace duckdb
20932
+ //===----------------------------------------------------------------------===//
20933
+ // DuckDB
20934
+ //
20935
+ // duckdb/parser/expression/default_expression.hpp
20936
+ //
20937
+ //
20938
+ //===----------------------------------------------------------------------===//
20939
+
20940
+
20941
+
20942
+
20943
+
20944
+ namespace duckdb {
20945
+ //! Represents the default value of a column
20946
+ class DefaultExpression : public ParsedExpression {
20947
+ public:
20948
+ DefaultExpression();
20949
+
20950
+ public:
20951
+ bool IsScalar() const override {
20952
+ return false;
20953
+ }
20954
+
20955
+ string ToString() const override;
20956
+
20957
+ unique_ptr<ParsedExpression> Copy() const override;
20958
+
20959
+ static unique_ptr<ParsedExpression> Deserialize(ExpressionType type, Deserializer &source);
20960
+ };
20961
+ } // namespace duckdb
20962
+ //===----------------------------------------------------------------------===//
20963
+ // DuckDB
20964
+ //
20965
+ // duckdb/parser/expression/case_expression.hpp
20966
+ //
20967
+ //
20968
+ //===----------------------------------------------------------------------===//
20969
+
20970
+
20971
+
20972
+
20973
+
20974
+
20975
+ namespace duckdb {
20976
+
20977
+ struct CaseCheck {
20978
+ unique_ptr<ParsedExpression> when_expr;
20979
+ unique_ptr<ParsedExpression> then_expr;
20980
+ };
20981
+
20982
+ //! The CaseExpression represents a CASE expression in the query
20983
+ class CaseExpression : public ParsedExpression {
20984
+ public:
20985
+ CaseExpression();
20986
+
20987
+ vector<CaseCheck> case_checks;
20988
+ unique_ptr<ParsedExpression> else_expr;
20989
+
20990
+ public:
20991
+ string ToString() const override;
20992
+
20993
+ static bool Equals(const CaseExpression *a, const CaseExpression *b);
20994
+
20995
+ unique_ptr<ParsedExpression> Copy() const override;
20996
+
20997
+ void Serialize(Serializer &serializer) override;
20998
+ static unique_ptr<ParsedExpression> Deserialize(ExpressionType type, Deserializer &source);
20999
+ };
21000
+ } // namespace duckdb
21001
+ //===----------------------------------------------------------------------===//
21002
+ // DuckDB
21003
+ //
21004
+ // duckdb/parser/expression/function_expression.hpp
21005
+ //
21006
+ //
21007
+ //===----------------------------------------------------------------------===//
21008
+
21009
+
21010
+
21011
+
21012
+
21013
+
21014
+
21015
+ namespace duckdb {
21016
+ //! Represents a function call
21017
+ class FunctionExpression : public ParsedExpression {
21018
+ public:
21019
+ FunctionExpression(string schema_name, const string &function_name, vector<unique_ptr<ParsedExpression>> children,
21020
+ unique_ptr<ParsedExpression> filter = nullptr, unique_ptr<OrderModifier> order_bys = nullptr,
21021
+ bool distinct = false, bool is_operator = false);
21022
+ FunctionExpression(const string &function_name, vector<unique_ptr<ParsedExpression>> children,
21023
+ unique_ptr<ParsedExpression> filter = nullptr, unique_ptr<OrderModifier> order_bys = nullptr,
21024
+ bool distinct = false, bool is_operator = false);
21025
+
21026
+ //! Schema of the function
21027
+ string schema;
21028
+ //! Function name
21029
+ string function_name;
21030
+ //! Whether or not the function is an operator, only used for rendering
21031
+ bool is_operator;
21032
+ //! List of arguments to the function
21033
+ vector<unique_ptr<ParsedExpression>> children;
21034
+ //! Whether or not the aggregate function is distinct, only used for aggregates
21035
+ bool distinct;
21036
+ //! Expression representing a filter, only used for aggregates
21037
+ unique_ptr<ParsedExpression> filter;
21038
+ //! Modifier representing an ORDER BY, only used for aggregates
21039
+ unique_ptr<OrderModifier> order_bys;
21040
+
21041
+ public:
21042
+ string ToString() const override;
21043
+
21044
+ unique_ptr<ParsedExpression> Copy() const override;
21045
+
21046
+ static bool Equals(const FunctionExpression *a, const FunctionExpression *b);
21047
+ hash_t Hash() const override;
21048
+
21049
+ //! Serializes a FunctionExpression to a stand-alone binary blob
21050
+ void Serialize(Serializer &serializer) override;
21051
+ //! Deserializes a blob back into an FunctionExpression
21052
+ static unique_ptr<ParsedExpression> Deserialize(ExpressionType type, Deserializer &source);
21053
+ };
21054
+ } // namespace duckdb
21055
+ //===----------------------------------------------------------------------===//
21056
+ // DuckDB
21057
+ //
21058
+ // duckdb/parser/expression/lambda_expression.hpp
21059
+ //
21060
+ //
21061
+ //===----------------------------------------------------------------------===//
21062
+
21063
+
21064
+
21065
+
21066
+
21067
+
21068
+ namespace duckdb {
21069
+
21070
+ //! LambdaExpression represents a lambda operator that can be used for e.g. mapping an expression to a list
21071
+ //! Lambda expressions are written in the form of "capture -> expr", e.g. "x -> x + 1"
21072
+ class LambdaExpression : public ParsedExpression {
21073
+ public:
21074
+ LambdaExpression(vector<string> parameters, unique_ptr<ParsedExpression> expression);
21075
+
21076
+ vector<string> parameters;
21077
+ unique_ptr<ParsedExpression> expression;
21078
+
21079
+ public:
21080
+ string ToString() const override;
21081
+
21082
+ static bool Equals(const LambdaExpression *a, const LambdaExpression *b);
21083
+ hash_t Hash() const override;
21084
+
21085
+ unique_ptr<ParsedExpression> Copy() const override;
21086
+
21087
+ void Serialize(Serializer &serializer) override;
21088
+ static unique_ptr<ParsedExpression> Deserialize(ExpressionType type, Deserializer &source);
21089
+ };
21090
+
21091
+ } // namespace duckdb
21092
+ //===----------------------------------------------------------------------===//
21093
+ // DuckDB
21094
+ //
21095
+ // duckdb/parser/expression/comparison_expression.hpp
21096
+ //
21097
+ //
21098
+ //===----------------------------------------------------------------------===//
21099
+
21100
+
21101
+
21102
+
21103
+
21104
+ namespace duckdb {
21105
+ //! ComparisonExpression represents a boolean comparison (e.g. =, >=, <>). Always returns a boolean
21106
+ //! and has two children.
21107
+ class ComparisonExpression : public ParsedExpression {
21108
+ public:
21109
+ ComparisonExpression(ExpressionType type, unique_ptr<ParsedExpression> left, unique_ptr<ParsedExpression> right);
21110
+
21111
+ unique_ptr<ParsedExpression> left;
21112
+ unique_ptr<ParsedExpression> right;
21113
+
21114
+ public:
21115
+ string ToString() const override;
21116
+
21117
+ static bool Equals(const ComparisonExpression *a, const ComparisonExpression *b);
21118
+
21119
+ unique_ptr<ParsedExpression> Copy() const override;
21120
+
21121
+ void Serialize(Serializer &serializer) override;
21122
+ static unique_ptr<ParsedExpression> Deserialize(ExpressionType type, Deserializer &source);
21123
+ };
21124
+ } // namespace duckdb
21125
+
21126
+
21127
+
21128
+ //===----------------------------------------------------------------------===//
21129
+ // DuckDB
21130
+ //
21131
+ // duckdb/parser/expression/cast_expression.hpp
21132
+ //
21133
+ //
21134
+ //===----------------------------------------------------------------------===//
21135
+
21136
+
21137
+
21138
+
21139
+
21140
+
21141
+ namespace duckdb {
21142
+
21143
+ //! CastExpression represents a type cast from one SQL type to another SQL type
21144
+ class CastExpression : public ParsedExpression {
21145
+ public:
21146
+ CastExpression(LogicalType target, unique_ptr<ParsedExpression> child, bool try_cast = false);
21147
+
21148
+ //! The child of the cast expression
21149
+ unique_ptr<ParsedExpression> child;
21150
+ //! The type to cast to
21151
+ LogicalType cast_type;
21152
+ //! Whether or not this is a try_cast expression
21153
+ bool try_cast;
21154
+
21155
+ public:
21156
+ string ToString() const override;
21157
+
21158
+ static bool Equals(const CastExpression *a, const CastExpression *b);
21159
+
21160
+ unique_ptr<ParsedExpression> Copy() const override;
21161
+
21162
+ void Serialize(Serializer &serializer) override;
21163
+ static unique_ptr<ParsedExpression> Deserialize(ExpressionType type, Deserializer &source);
21164
+ };
21165
+ } // namespace duckdb
21166
+
21167
+ //===----------------------------------------------------------------------===//
21168
+ // DuckDB
21169
+ //
21170
+ // duckdb/parser/expression/collate_expression.hpp
21171
+ //
21172
+ //
21173
+ //===----------------------------------------------------------------------===//
21174
+
21175
+
21176
+
21177
+
21178
+
21179
+ namespace duckdb {
21180
+
21181
+ //! CollateExpression represents a COLLATE statement
21182
+ class CollateExpression : public ParsedExpression {
21183
+ public:
21184
+ CollateExpression(string collation, unique_ptr<ParsedExpression> child);
21185
+
21186
+ //! The child of the cast expression
21187
+ unique_ptr<ParsedExpression> child;
21188
+ //! The collation clause
21189
+ string collation;
21190
+
21191
+ public:
21192
+ string ToString() const override;
21193
+
21194
+ static bool Equals(const CollateExpression *a, const CollateExpression *b);
21195
+
21196
+ unique_ptr<ParsedExpression> Copy() const override;
21197
+
21198
+ void Serialize(Serializer &serializer) override;
21199
+ static unique_ptr<ParsedExpression> Deserialize(ExpressionType type, Deserializer &source);
21200
+ };
21201
+ } // namespace duckdb
21202
+
21203
+
21204
+
21205
+ //===----------------------------------------------------------------------===//
21206
+ // DuckDB
21207
+ //
21208
+ // duckdb/parser/expression/conjunction_expression.hpp
21209
+ //
21210
+ //
21211
+ //===----------------------------------------------------------------------===//
21212
+
21213
+
21214
+
21215
+
21216
+
21217
+
21218
+ namespace duckdb {
21219
+
21220
+ //! Represents a conjunction (AND/OR)
21221
+ class ConjunctionExpression : public ParsedExpression {
21222
+ public:
21223
+ explicit ConjunctionExpression(ExpressionType type);
21224
+ ConjunctionExpression(ExpressionType type, vector<unique_ptr<ParsedExpression>> children);
21225
+ ConjunctionExpression(ExpressionType type, unique_ptr<ParsedExpression> left, unique_ptr<ParsedExpression> right);
21226
+
21227
+ vector<unique_ptr<ParsedExpression>> children;
21228
+
21229
+ public:
21230
+ void AddExpression(unique_ptr<ParsedExpression> expr);
21231
+
21232
+ string ToString() const override;
21233
+
21234
+ static bool Equals(const ConjunctionExpression *a, const ConjunctionExpression *b);
21235
+
21236
+ unique_ptr<ParsedExpression> Copy() const override;
21237
+
21238
+ void Serialize(Serializer &serializer) override;
21239
+ static unique_ptr<ParsedExpression> Deserialize(ExpressionType type, Deserializer &source);
21240
+ };
21241
+ } // namespace duckdb
21242
+
21243
+
21244
+
21245
+
21246
+
21247
+ //===----------------------------------------------------------------------===//
21248
+ // DuckDB
21249
+ //
21250
+ // duckdb/parser/expression/operator_expression.hpp
21251
+ //
21252
+ //
21253
+ //===----------------------------------------------------------------------===//
21254
+
21255
+
21256
+
21257
+
21258
+
21259
+
21260
+ namespace duckdb {
21261
+ //! Represents a built-in operator expression
21262
+ class OperatorExpression : public ParsedExpression {
21263
+ public:
21264
+ explicit OperatorExpression(ExpressionType type, unique_ptr<ParsedExpression> left = nullptr,
21265
+ unique_ptr<ParsedExpression> right = nullptr);
21266
+ OperatorExpression(ExpressionType type, vector<unique_ptr<ParsedExpression>> children);
21267
+
21268
+ vector<unique_ptr<ParsedExpression>> children;
21269
+
21270
+ public:
21271
+ string ToString() const override;
21272
+
21273
+ static bool Equals(const OperatorExpression *a, const OperatorExpression *b);
21274
+
21275
+ unique_ptr<ParsedExpression> Copy() const override;
21276
+
21277
+ void Serialize(Serializer &serializer) override;
21278
+ static unique_ptr<ParsedExpression> Deserialize(ExpressionType type, Deserializer &source);
21279
+ };
21280
+ } // namespace duckdb
21281
+
21282
+
21283
+
21284
+ //===----------------------------------------------------------------------===//
21285
+ // DuckDB
21286
+ //
21287
+ // duckdb/parser/expression/star_expression.hpp
21288
+ //
21289
+ //
21290
+ //===----------------------------------------------------------------------===//
21291
+
21292
+
21293
+
21294
+
21295
+
21296
+
21297
+ namespace duckdb {
21298
+
21299
+ //! Represents a * expression in the SELECT clause
21300
+ class StarExpression : public ParsedExpression {
21301
+ public:
21302
+ StarExpression(string relation_name = string());
21303
+
21304
+ //! The relation name in case of tbl.*, or empty if this is a normal *
21305
+ string relation_name;
21306
+ //! List of columns to exclude from the STAR expression
21307
+ case_insensitive_set_t exclude_list;
21308
+ //! List of columns to replace with another expression
21309
+ case_insensitive_map_t<unique_ptr<ParsedExpression>> replace_list;
21310
+
21311
+ public:
21312
+ string ToString() const override;
21313
+
21314
+ static bool Equals(const StarExpression *a, const StarExpression *b);
21315
+
21316
+ unique_ptr<ParsedExpression> Copy() const override;
21317
+
21318
+ void Serialize(Serializer &serializer) override;
21319
+ static unique_ptr<ParsedExpression> Deserialize(ExpressionType type, Deserializer &source);
21320
+ };
21321
+ } // namespace duckdb
21322
+
21323
+
21324
+
21325
+ //===----------------------------------------------------------------------===//
21326
+ // DuckDB
21327
+ //
21328
+ // duckdb/parser/parsed_data/create_index_info.hpp
21329
+ //
21330
+ //
21331
+ //===----------------------------------------------------------------------===//
21332
+
21333
+
21334
+
21335
+
21336
+
21337
+
21338
+ //===----------------------------------------------------------------------===//
21339
+ // DuckDB
21340
+ //
21341
+ // duckdb/parser/tableref/basetableref.hpp
21342
+ //
21343
+ //
21344
+ //===----------------------------------------------------------------------===//
21345
+
21346
+
21347
+
21348
+
21349
+
21350
+
21351
+ namespace duckdb {
21352
+ //! Represents a TableReference to a base table in the schema
21353
+ class BaseTableRef : public TableRef {
21354
+ public:
21355
+ BaseTableRef() : TableRef(TableReferenceType::BASE_TABLE), schema_name(INVALID_SCHEMA) {
21356
+ }
21357
+
21358
+ //! Schema name
21359
+ string schema_name;
21360
+ //! Table name
21361
+ string table_name;
21362
+ //! Aliases for the column names
21363
+ vector<string> column_name_alias;
21364
+
21365
+ public:
21366
+ string ToString() const override;
21367
+ bool Equals(const TableRef *other_p) const override;
21368
+
21369
+ unique_ptr<TableRef> Copy() override;
21370
+
21371
+ //! Serializes a blob into a BaseTableRef
21372
+ void Serialize(Serializer &serializer) override;
21373
+ //! Deserializes a blob back into a BaseTableRef
21374
+ static unique_ptr<TableRef> Deserialize(Deserializer &source);
21375
+ };
21376
+ } // namespace duckdb
21377
+
21378
+
21379
+
21380
+ namespace duckdb {
21381
+
21382
+ struct CreateIndexInfo : public CreateInfo {
21383
+ CreateIndexInfo() : CreateInfo(CatalogType::INDEX_ENTRY) {
21384
+ }
21385
+
21386
+ //! Index Type (e.g., B+-tree, Skip-List, ...)
21387
+ IndexType index_type;
21388
+ //! Name of the Index
21389
+ string index_name;
21390
+ //! If it is an unique index
21391
+ bool unique = false;
21392
+ //! The table to create the index on
21393
+ unique_ptr<BaseTableRef> table;
21394
+ //! Set of expressions to index by
21395
+ vector<unique_ptr<ParsedExpression>> expressions;
21396
+
21397
+ public:
21398
+ unique_ptr<CreateInfo> Copy() const override {
21399
+ auto result = make_unique<CreateIndexInfo>();
21400
+ CopyProperties(*result);
21401
+ result->index_type = index_type;
21402
+ result->index_name = index_name;
21403
+ result->unique = unique;
21404
+ result->table = unique_ptr_cast<TableRef, BaseTableRef>(table->Copy());
21405
+ for (auto &expr : expressions) {
21406
+ result->expressions.push_back(expr->Copy());
21407
+ }
21408
+ return move(result);
21409
+ }
21410
+ };
21411
+
21412
+ } // namespace duckdb
21413
+ //===----------------------------------------------------------------------===//
21414
+ // DuckDB
21415
+ //
21416
+ // duckdb/parser/parsed_data/create_view_info.hpp
21417
+ //
21418
+ //
21419
+ //===----------------------------------------------------------------------===//
21420
+
21421
+
21422
+
21423
+
21424
+
21425
+
21426
+ namespace duckdb {
21427
+
21428
+ struct CreateViewInfo : public CreateInfo {
21429
+ CreateViewInfo() : CreateInfo(CatalogType::VIEW_ENTRY, INVALID_SCHEMA) {
21430
+ }
21431
+ CreateViewInfo(string schema, string view_name)
21432
+ : CreateInfo(CatalogType::VIEW_ENTRY, schema), view_name(view_name) {
21433
+ }
21434
+
21435
+ //! Table name to insert to
21436
+ string view_name;
21437
+ //! Aliases of the view
21438
+ vector<string> aliases;
21439
+ //! Return types
21440
+ vector<LogicalType> types;
21441
+ //! The SelectStatement of the view
21442
+ unique_ptr<SelectStatement> query;
21443
+
21444
+ public:
21445
+ unique_ptr<CreateInfo> Copy() const override {
21446
+ auto result = make_unique<CreateViewInfo>(schema, view_name);
21447
+ CopyProperties(*result);
21448
+ result->aliases = aliases;
21449
+ result->types = types;
21450
+ result->query = unique_ptr_cast<SQLStatement, SelectStatement>(query->Copy());
21451
+ return move(result);
21452
+ }
21453
+ };
21454
+
21455
+ } // namespace duckdb
21456
+ //===----------------------------------------------------------------------===//
21457
+ // DuckDB
21458
+ //
21459
+ // duckdb/parser/parsed_data/create_pragma_function_info.hpp
21460
+ //
21461
+ //
21462
+ //===----------------------------------------------------------------------===//
21463
+
21464
+
21465
+
21466
+
21467
+
21468
+
21469
+ namespace duckdb {
21470
+
21471
+ struct CreatePragmaFunctionInfo : public CreateFunctionInfo {
21472
+ explicit CreatePragmaFunctionInfo(PragmaFunction function)
21473
+ : CreateFunctionInfo(CatalogType::PRAGMA_FUNCTION_ENTRY) {
21474
+ functions.push_back(move(function));
21475
+ this->name = function.name;
21476
+ }
21477
+ CreatePragmaFunctionInfo(string name, vector<PragmaFunction> functions_)
21478
+ : CreateFunctionInfo(CatalogType::PRAGMA_FUNCTION_ENTRY), functions(move(functions_)) {
21479
+ this->name = name;
21480
+ for (auto &function : functions) {
21481
+ function.name = name;
21482
+ }
21483
+ }
21484
+
21485
+ vector<PragmaFunction> functions;
21486
+
21487
+ public:
21488
+ unique_ptr<CreateInfo> Copy() const override {
21489
+ auto result = make_unique<CreatePragmaFunctionInfo>(functions[0].name, functions);
21490
+ CopyProperties(*result);
21491
+ return move(result);
21492
+ }
21493
+ };
21494
+
21495
+ } // namespace duckdb
21496
+ //===----------------------------------------------------------------------===//
21497
+ // DuckDB
21498
+ //
21499
+ // duckdb/parser/parsed_data/drop_info.hpp
21500
+ //
21501
+ //
21502
+ //===----------------------------------------------------------------------===//
21503
+
21504
+
21505
+
21506
+
21507
+
21508
+
21509
+ namespace duckdb {
21510
+
21511
+ struct DropInfo : public ParseInfo {
21512
+ DropInfo() : schema(INVALID_SCHEMA), if_exists(false), cascade(false) {
21513
+ }
21514
+
21515
+ //! The catalog type to drop
21516
+ CatalogType type;
21517
+ //! Schema name to drop from, if any
21518
+ string schema;
21519
+ //! Element name to drop
21520
+ string name;
21521
+ //! Ignore if the entry does not exist instead of failing
21522
+ bool if_exists = false;
21523
+ //! Cascade drop (drop all dependents instead of throwing an error if there
21524
+ //! are any)
21525
+ bool cascade = false;
21526
+
21527
+ public:
21528
+ unique_ptr<DropInfo> Copy() const {
21529
+ auto result = make_unique<DropInfo>();
21530
+ result->type = type;
21531
+ result->schema = schema;
21532
+ result->name = name;
21533
+ result->if_exists = if_exists;
21534
+ result->cascade = cascade;
21535
+ return result;
21536
+ }
21537
+ };
21538
+
21539
+ } // namespace duckdb
21540
+ //===----------------------------------------------------------------------===//
21541
+ // DuckDB
21542
+ //
21543
+ // duckdb/parser/parsed_data/transaction_info.hpp
21544
+ //
21545
+ //
21546
+ //===----------------------------------------------------------------------===//
21547
+
21548
+
21549
+
21550
+
21551
+
21552
+ namespace duckdb {
21553
+
21554
+ enum class TransactionType : uint8_t { INVALID, BEGIN_TRANSACTION, COMMIT, ROLLBACK };
21555
+
21556
+ struct TransactionInfo : public ParseInfo {
21557
+ explicit TransactionInfo(TransactionType type) : type(type) {
21558
+ }
21559
+
21560
+ //! The type of transaction statement
21561
+ TransactionType type;
21562
+ };
21563
+
21564
+ } // namespace duckdb
21565
+ //===----------------------------------------------------------------------===//
21566
+ // DuckDB
21567
+ //
21568
+ // duckdb/parser/parsed_data/create_type_info.hpp
21569
+ //
21570
+ //
21571
+ //===----------------------------------------------------------------------===//
21572
+
21573
+
21574
+
21575
+
21576
+
21577
+
21578
+
21579
+
21580
+ namespace duckdb {
21581
+
21582
+ struct CreateTypeInfo : public CreateInfo {
21583
+
21584
+ CreateTypeInfo() : CreateInfo(CatalogType::TYPE_ENTRY) {
21585
+ }
21586
+
21587
+ //! Name of the Type
21588
+ string name;
21589
+ //! Shared Pointer of Logical Type
21590
+ unique_ptr<LogicalType> type;
21591
+
21592
+ public:
21593
+ unique_ptr<CreateInfo> Copy() const override {
21594
+ auto result = make_unique<CreateTypeInfo>();
21595
+ CopyProperties(*result);
21596
+ result->name = name;
21597
+ result->type = make_unique<LogicalType>(*type);
21598
+ return move(result);
21599
+ }
21600
+ };
21601
+
21602
+ } // namespace duckdb
21603
+ //===----------------------------------------------------------------------===//
21604
+ // DuckDB
21605
+ //
21606
+ // duckdb/parser/parsed_data/vacuum_info.hpp
21607
+ //
21608
+ //
21609
+ //===----------------------------------------------------------------------===//
21610
+
21611
+
21612
+
21613
+
21614
+
21615
+ namespace duckdb {
21616
+
21617
+ enum class LoadType { LOAD, INSTALL, FORCE_INSTALL };
21618
+
21619
+ struct LoadInfo : public ParseInfo {
21620
+ std::string filename;
21621
+ LoadType load_type;
21622
+
21623
+ public:
21624
+ unique_ptr<LoadInfo> Copy() const {
21625
+ auto result = make_unique<LoadInfo>();
21626
+ result->filename = filename;
21627
+ result->load_type = load_type;
21628
+ return result;
21629
+ }
21630
+ };
21631
+
21632
+ } // namespace duckdb
21633
+ //===----------------------------------------------------------------------===//
21634
+ // DuckDB
21635
+ //
21636
+ // duckdb/parser/parsed_data/create_collation_info.hpp
21637
+ //
21638
+ //
21639
+ //===----------------------------------------------------------------------===//
21640
+
21641
+
21642
+
21643
+
21644
+
21645
+
21646
+ namespace duckdb {
21647
+
21648
+ struct CreateCollationInfo : public CreateInfo {
21649
+ CreateCollationInfo(string name_p, ScalarFunction function_p, bool combinable_p, bool not_required_for_equality_p)
21650
+ : CreateInfo(CatalogType::COLLATION_ENTRY), function(move(function_p)), combinable(combinable_p),
21651
+ not_required_for_equality(not_required_for_equality_p) {
21652
+ this->name = move(name_p);
21653
+ }
21654
+
21655
+ //! The name of the collation
21656
+ string name;
21657
+ //! The collation function to push in case collation is required
21658
+ ScalarFunction function;
21659
+ //! Whether or not the collation can be combined with other collations.
21660
+ bool combinable;
21661
+ //! Whether or not the collation is required for equality comparisons or not. For many collations a binary
21662
+ //! comparison for equality comparisons is correct, allowing us to skip the collation in these cases which greatly
21663
+ //! speeds up processing.
21664
+ bool not_required_for_equality;
21665
+
21666
+ public:
21667
+ unique_ptr<CreateInfo> Copy() const override {
21668
+ auto result = make_unique<CreateCollationInfo>(name, function, combinable, not_required_for_equality);
21669
+ CopyProperties(*result);
21670
+ return move(result);
21671
+ }
21672
+ };
21673
+
21674
+ } // namespace duckdb
21675
+ //===----------------------------------------------------------------------===//
21676
+ // DuckDB
21677
+ //
21678
+ // duckdb/parser/parsed_data/create_schema_info.hpp
21679
+ //
21680
+ //
21681
+ //===----------------------------------------------------------------------===//
21682
+
21683
+
21684
+
21685
+
21686
+
21687
+ namespace duckdb {
21688
+
21689
+ struct CreateSchemaInfo : public CreateInfo {
21690
+ CreateSchemaInfo() : CreateInfo(CatalogType::SCHEMA_ENTRY) {
21691
+ }
21692
+
21693
+ public:
21694
+ unique_ptr<CreateInfo> Copy() const override {
21695
+ auto result = make_unique<CreateSchemaInfo>();
21696
+ CopyProperties(*result);
21697
+ return move(result);
21698
+ }
21699
+ };
21700
+
21701
+ } // namespace duckdb
21702
+ //===----------------------------------------------------------------------===//
21703
+ // DuckDB
21704
+ //
21705
+ // duckdb/parser/parsed_data/vacuum_info.hpp
21706
+ //
21707
+ //
21708
+ //===----------------------------------------------------------------------===//
21709
+
21710
+
21711
+
21712
+
21713
+
21714
+ namespace duckdb {
21715
+
21716
+ struct VacuumInfo : public ParseInfo {
21717
+ // nothing for now
21718
+ };
21719
+
21720
+ } // namespace duckdb
21721
+ //===----------------------------------------------------------------------===//
21722
+ // DuckDB
21723
+ //
21724
+ // duckdb/parser/parsed_data/create_macro_info.hpp
21725
+ //
21726
+ //
21727
+ //===----------------------------------------------------------------------===//
21728
+
21729
+
21730
+
21731
+
21732
+ //===----------------------------------------------------------------------===//
21733
+ // DuckDB
21734
+ //
21735
+ // duckdb/function/macro_function.hpp
21736
+ //
21737
+ //
21738
+ //===----------------------------------------------------------------------===//
21739
+
21740
+
21741
+
21742
+
21743
+
21744
+
21745
+
21746
+
21747
+ namespace duckdb {
21748
+
21749
+ class MacroCatalogEntry;
21750
+
21751
+ class MacroFunction {
21752
+ public:
21753
+ explicit MacroFunction(unique_ptr<ParsedExpression> expression);
21754
+
21755
+ //! Check whether the supplied arguments are valid
21756
+ static string ValidateArguments(MacroCatalogEntry &macro_func, FunctionExpression &function_expr,
21757
+ vector<unique_ptr<ParsedExpression>> &positionals,
21758
+ unordered_map<string, unique_ptr<ParsedExpression>> &defaults);
21759
+ //! The macro expression
21760
+ unique_ptr<ParsedExpression> expression;
21761
+ //! The positional parameters
21762
+ vector<unique_ptr<ParsedExpression>> parameters;
21763
+ //! The default parameters and their associated values
21764
+ unordered_map<string, unique_ptr<ParsedExpression>> default_parameters;
21765
+
21766
+ public:
21767
+ unique_ptr<MacroFunction> Copy();
21768
+ };
21769
+
21770
+ } // namespace duckdb
21771
+
21772
+
21773
+ namespace duckdb {
21774
+
21775
+ struct CreateMacroInfo : public CreateFunctionInfo {
21776
+ CreateMacroInfo() : CreateFunctionInfo(CatalogType::MACRO_ENTRY, INVALID_SCHEMA) {
21777
+ }
21778
+
21779
+ unique_ptr<MacroFunction> function;
21780
+
21781
+ public:
21782
+ unique_ptr<CreateInfo> Copy() const override {
21783
+ auto result = make_unique<CreateMacroInfo>();
21784
+ result->function = function->Copy();
21785
+ result->name = name;
21786
+ CopyProperties(*result);
21787
+ return move(result);
21788
+ }
21789
+ };
21790
+
21791
+ } // namespace duckdb
21792
+ //===----------------------------------------------------------------------===//
21793
+ // DuckDB
21794
+ //
21795
+ // duckdb/parser/parsed_data/create_aggregate_function_info.hpp
21796
+ //
21797
+ //
21798
+ //===----------------------------------------------------------------------===//
21799
+
21800
+
21801
+
21802
+
21803
+
21804
+
21805
+ namespace duckdb {
21806
+
21807
+ struct CreateAggregateFunctionInfo : public CreateFunctionInfo {
21808
+ explicit CreateAggregateFunctionInfo(AggregateFunction function)
21809
+ : CreateFunctionInfo(CatalogType::AGGREGATE_FUNCTION_ENTRY), functions(function.name) {
21810
+ this->name = function.name;
21811
+ functions.AddFunction(move(function));
21812
+ }
21813
+
21814
+ explicit CreateAggregateFunctionInfo(AggregateFunctionSet set)
21815
+ : CreateFunctionInfo(CatalogType::AGGREGATE_FUNCTION_ENTRY), functions(move(set)) {
21816
+ this->name = functions.name;
21817
+ for (auto &func : functions.functions) {
21818
+ func.name = functions.name;
21819
+ }
21820
+ }
21821
+
21822
+ AggregateFunctionSet functions;
21823
+
21824
+ public:
21825
+ unique_ptr<CreateInfo> Copy() const override {
21826
+ auto result = make_unique<CreateAggregateFunctionInfo>(functions);
21827
+ CopyProperties(*result);
21828
+ return move(result);
21829
+ }
21830
+ };
21831
+
21832
+ } // namespace duckdb
21833
+ //===----------------------------------------------------------------------===//
21834
+ // DuckDB
21835
+ //
21836
+ // duckdb/parser/parsed_data/export_table_data.hpp
21837
+ //
21838
+ //
21839
+ //===----------------------------------------------------------------------===//
21840
+
21841
+
21842
+
21843
+
21844
+
21845
+
21846
+ namespace duckdb {
21847
+
21848
+ struct ExportedTableData {
21849
+ //! Name of the exported table
21850
+ string table_name;
21851
+
21852
+ //! Name of the schema
21853
+ string schema_name;
21854
+
21855
+ //! Path to be exported
21856
+ string file_path;
21857
+ };
21858
+
21859
+ struct BoundExportData : public ParseInfo {
21860
+ unordered_map<TableCatalogEntry *, ExportedTableData> data;
21861
+ };
21862
+
21863
+ } // namespace duckdb
21864
+ //===----------------------------------------------------------------------===//
21865
+ // DuckDB
21866
+ //
21867
+ // duckdb/parser/parsed_data/show_select_info.hpp
21868
+ //
21869
+ //
21870
+ //===----------------------------------------------------------------------===//
21871
+
21872
+
21873
+
21874
+
21875
+
21876
+
21877
+ namespace duckdb {
21878
+
21879
+ struct ShowSelectInfo : public ParseInfo {
21880
+ //! Types of projected columns
21881
+ vector<LogicalType> types;
21882
+ //! The QueryNode of select query
21883
+ unique_ptr<QueryNode> query;
21884
+ //! Aliases of projected columns
21885
+ vector<string> aliases;
21886
+ //! Whether or not we are requesting a summary or a describe
21887
+ bool is_summary;
21888
+
21889
+ unique_ptr<ShowSelectInfo> Copy() {
21890
+ auto result = make_unique<ShowSelectInfo>();
21891
+ result->types = types;
21892
+ result->query = query->Copy();
21893
+ result->aliases = aliases;
21894
+ result->is_summary = is_summary;
21895
+ return result;
21896
+ }
21897
+ };
21898
+
21899
+ } // namespace duckdb
21900
+ //===----------------------------------------------------------------------===//
21901
+ // DuckDB
21902
+ //
21903
+ // duckdb/parser/tableref/subqueryref.hpp
21904
+ //
21905
+ //
21906
+ //===----------------------------------------------------------------------===//
21907
+
21908
+
21909
+
21910
+
21911
+
21912
+
21913
+ namespace duckdb {
21914
+ //! Represents a subquery
21915
+ class SubqueryRef : public TableRef {
21916
+ public:
21917
+ explicit SubqueryRef(unique_ptr<SelectStatement> subquery, string alias = string());
21918
+
21919
+ //! The subquery
21920
+ unique_ptr<SelectStatement> subquery;
21921
+ //! Aliases for the column names
21922
+ vector<string> column_name_alias;
21923
+
21924
+ public:
21925
+ bool Equals(const TableRef *other_p) const override;
21926
+
21927
+ unique_ptr<TableRef> Copy() override;
21928
+
21929
+ //! Serializes a blob into a SubqueryRef
21930
+ void Serialize(Serializer &serializer) override;
21931
+ //! Deserializes a blob back into a SubqueryRef
21932
+ static unique_ptr<TableRef> Deserialize(Deserializer &source);
21933
+ };
21934
+ } // namespace duckdb
21935
+ //===----------------------------------------------------------------------===//
21936
+ // DuckDB
21937
+ //
21938
+ // duckdb/parser/tableref/table_function_ref.hpp
21939
+ //
21940
+ //
21941
+ //===----------------------------------------------------------------------===//
21942
+
21943
+
21944
+
21945
+
21946
+
21947
+
21948
+
21949
+
21950
+ namespace duckdb {
21951
+ //! Represents a Table producing function
21952
+ class TableFunctionRef : public TableRef {
21953
+ public:
21954
+ TableFunctionRef() : TableRef(TableReferenceType::TABLE_FUNCTION) {
21955
+ }
21956
+
21957
+ unique_ptr<ParsedExpression> function;
21958
+ vector<string> column_name_alias;
21959
+
21960
+ // if the function takes a subquery as argument its in here
21961
+ unique_ptr<SelectStatement> subquery;
21962
+
21963
+ public:
21964
+ string ToString() const override;
21965
+
21966
+ bool Equals(const TableRef *other_p) const override;
21967
+
21968
+ unique_ptr<TableRef> Copy() override;
21969
+
21970
+ //! Serializes a blob into a BaseTableRef
21971
+ void Serialize(Serializer &serializer) override;
21972
+ //! Deserializes a blob back into a BaseTableRef
21973
+ static unique_ptr<TableRef> Deserialize(Deserializer &source);
21974
+ };
21975
+ } // namespace duckdb
21976
+ //===----------------------------------------------------------------------===//
21977
+ // DuckDB
21978
+ //
21979
+ // duckdb/parser/tableref/crossproductref.hpp
21980
+ //
21981
+ //
21982
+ //===----------------------------------------------------------------------===//
21983
+
21984
+
21985
+
21986
+
21987
+
21988
+ namespace duckdb {
21989
+ //! Represents a cross product
21990
+ class CrossProductRef : public TableRef {
21991
+ public:
21992
+ CrossProductRef() : TableRef(TableReferenceType::CROSS_PRODUCT) {
21993
+ }
21994
+
21995
+ //! The left hand side of the cross product
21996
+ unique_ptr<TableRef> left;
21997
+ //! The right hand side of the cross product
21998
+ unique_ptr<TableRef> right;
21999
+
22000
+ public:
22001
+ bool Equals(const TableRef *other_p) const override;
22002
+
22003
+ unique_ptr<TableRef> Copy() override;
22004
+
22005
+ //! Serializes a blob into a CrossProductRef
22006
+ void Serialize(Serializer &serializer) override;
22007
+ //! Deserializes a blob back into a CrossProductRef
22008
+ static unique_ptr<TableRef> Deserialize(Deserializer &source);
22009
+ };
22010
+ } // namespace duckdb
22011
+
22012
+
22013
+ //===----------------------------------------------------------------------===//
22014
+ // DuckDB
22015
+ //
22016
+ // duckdb/parser/tableref/emptytableref.hpp
22017
+ //
22018
+ //
22019
+ //===----------------------------------------------------------------------===//
22020
+
22021
+
22022
+
22023
+
22024
+
22025
+ namespace duckdb {
22026
+ //! Represents a cross product
22027
+ class EmptyTableRef : public TableRef {
22028
+ public:
22029
+ EmptyTableRef() : TableRef(TableReferenceType::EMPTY) {
22030
+ }
22031
+
22032
+ public:
22033
+ bool Equals(const TableRef *other_p) const override;
22034
+
22035
+ unique_ptr<TableRef> Copy() override;
22036
+
22037
+ //! Serializes a blob into a DummyTableRef
22038
+ void Serialize(Serializer &serializer) override;
22039
+ //! Deserializes a blob back into a DummyTableRef
22040
+ static unique_ptr<TableRef> Deserialize(Deserializer &source);
22041
+ };
22042
+ } // namespace duckdb
22043
+
22044
+ //===----------------------------------------------------------------------===//
22045
+ // DuckDB
22046
+ //
22047
+ // duckdb/parser/tableref/expressionlistref.hpp
22048
+ //
22049
+ //
22050
+ //===----------------------------------------------------------------------===//
22051
+
22052
+
22053
+
22054
+
22055
+
22056
+
22057
+
22058
+
22059
+ namespace duckdb {
22060
+ //! Represents an expression list as generated by a VALUES statement
22061
+ class ExpressionListRef : public TableRef {
22062
+ public:
22063
+ ExpressionListRef() : TableRef(TableReferenceType::EXPRESSION_LIST) {
22064
+ }
22065
+
22066
+ //! Value list, only used for VALUES statement
22067
+ vector<vector<unique_ptr<ParsedExpression>>> values;
22068
+ //! Expected SQL types
22069
+ vector<LogicalType> expected_types;
22070
+ //! The set of expected names
22071
+ vector<string> expected_names;
22072
+
22073
+ public:
22074
+ bool Equals(const TableRef *other_p) const override;
22075
+
22076
+ unique_ptr<TableRef> Copy() override;
22077
+
22078
+ //! Serializes a blob into a ExpressionListRef
22079
+ void Serialize(Serializer &serializer) override;
22080
+ //! Deserializes a blob back into a ExpressionListRef
22081
+ static unique_ptr<TableRef> Deserialize(Deserializer &source);
22082
+ };
22083
+ } // namespace duckdb
22084
+
22085
+ //===----------------------------------------------------------------------===//
22086
+ // DuckDB
22087
+ //
22088
+ // duckdb/parser/tableref/joinref.hpp
22089
+ //
22090
+ //
22091
+ //===----------------------------------------------------------------------===//
22092
+
22093
+
22094
+
22095
+
22096
+
22097
+
22098
+
22099
+
22100
+
22101
+ namespace duckdb {
22102
+ //! Represents a JOIN between two expressions
22103
+ class JoinRef : public TableRef {
22104
+ public:
22105
+ JoinRef() : TableRef(TableReferenceType::JOIN), is_natural(false) {
22106
+ }
22107
+
22108
+ //! The left hand side of the join
22109
+ unique_ptr<TableRef> left;
22110
+ //! The right hand side of the join
22111
+ unique_ptr<TableRef> right;
22112
+ //! The join condition
22113
+ unique_ptr<ParsedExpression> condition;
22114
+ //! The join type
22115
+ JoinType type;
22116
+ //! Natural join
22117
+ bool is_natural;
22118
+ //! The set of USING columns (if any)
22119
+ vector<string> using_columns;
22120
+
22121
+ public:
22122
+ bool Equals(const TableRef *other_p) const override;
22123
+
22124
+ unique_ptr<TableRef> Copy() override;
22125
+
22126
+ //! Serializes a blob into a JoinRef
22127
+ void Serialize(Serializer &serializer) override;
22128
+ //! Deserializes a blob back into a JoinRef
22129
+ static unique_ptr<TableRef> Deserialize(Deserializer &source);
22130
+ };
22131
+ } // namespace duckdb
22132
+
22133
+
22134
+