1 | //===----------------------------------------------------------------------===// |
2 | // DuckDB |
3 | // |
4 | // duckdb/common/types/chunk_collection.hpp |
5 | // |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | #pragma once |
10 | |
11 | #include "duckdb/common/enums/order_type.hpp" |
12 | #include "duckdb/common/types/data_chunk.hpp" |
13 | |
14 | namespace duckdb { |
15 | |
16 | //! A ChunkCollection represents a set of DataChunks that all have the same |
17 | //! types |
18 | /*! |
19 | A ChunkCollection represents a set of DataChunks concatenated together in a |
20 | list. Individual values of the collection can be iterated over using the |
21 | iterator. It is also possible to iterate directly over the chunks for more |
22 | direct access. |
23 | */ |
24 | class ChunkCollection { |
25 | public: |
26 | ChunkCollection() : count(0) { |
27 | } |
28 | |
29 | //! The total amount of elements in the collection |
30 | idx_t count; |
31 | //! The set of data chunks in the collection |
32 | vector<unique_ptr<DataChunk>> chunks; |
33 | //! The types of the ChunkCollection |
34 | vector<TypeId> types; |
35 | |
36 | //! The amount of columns in the ChunkCollection |
37 | idx_t column_count() { |
38 | return types.size(); |
39 | } |
40 | |
41 | //! Append a new DataChunk directly to this ChunkCollection |
42 | void Append(DataChunk &new_chunk); |
43 | |
44 | //! Append another ChunkCollection directly to this ChunkCollection |
45 | void Append(ChunkCollection &other); |
46 | |
47 | void Verify(); |
48 | |
49 | //! Gets the value of the column at the specified index |
50 | Value GetValue(idx_t column, idx_t index); |
51 | //! Sets the value of the column at the specified index |
52 | void SetValue(idx_t column, idx_t index, Value value); |
53 | |
54 | vector<Value> GetRow(idx_t index); |
55 | |
56 | string ToString() const { |
57 | return chunks.size() == 0 ? "ChunkCollection [ 0 ]" |
58 | : "ChunkCollection [ " + std::to_string(count) + " ]: \n" + chunks[0]->ToString(); |
59 | } |
60 | void Print(); |
61 | |
62 | //! Gets a reference to the chunk at the given index |
63 | DataChunk &GetChunk(idx_t index) { |
64 | return *chunks[LocateChunk(index)]; |
65 | } |
66 | |
67 | void Sort(vector<OrderType> &desc, idx_t result[]); |
68 | //! Reorders the rows in the collection according to the given indices. NB: order is changed! |
69 | void Reorder(idx_t order[]); |
70 | |
71 | void MaterializeSortedChunk(DataChunk &target, idx_t order[], idx_t start_offset); |
72 | |
73 | //! Returns true if the ChunkCollections are equivalent |
74 | bool Equals(ChunkCollection &other); |
75 | |
76 | //! Locates the chunk that belongs to the specific index |
77 | idx_t LocateChunk(idx_t index) { |
78 | idx_t result = index / STANDARD_VECTOR_SIZE; |
79 | assert(result < chunks.size()); |
80 | return result; |
81 | } |
82 | |
83 | void Heap(vector<OrderType> &desc, idx_t heap[], idx_t heap_size); |
84 | idx_t MaterializeHeapChunk(DataChunk &target, idx_t order[], idx_t start_offset, idx_t heap_size); |
85 | }; |
86 | } // namespace duckdb |
87 | |