| 1 | //===----------------------------------------------------------------------===// |
|---|---|
| 2 | // DuckDB |
| 3 | // |
| 4 | // duckdb/execution/window_segment_tree.hpp |
| 5 | // |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #pragma once |
| 10 | |
| 11 | #include "duckdb/common/types/chunk_collection.hpp" |
| 12 | #include "duckdb/execution/physical_operator.hpp" |
| 13 | #include "duckdb/function/aggregate_function.hpp" |
| 14 | |
| 15 | namespace duckdb { |
| 16 | |
| 17 | class WindowSegmentTree { |
| 18 | public: |
| 19 | WindowSegmentTree(AggregateFunction &aggregate, TypeId result_type, ChunkCollection *input); |
| 20 | Value Compute(idx_t start, idx_t end); |
| 21 | |
| 22 | private: |
| 23 | void ConstructTree(); |
| 24 | void WindowSegmentValue(idx_t l_idx, idx_t begin, idx_t end); |
| 25 | void AggregateInit(); |
| 26 | Value AggegateFinal(); |
| 27 | |
| 28 | AggregateFunction aggregate; |
| 29 | vector<data_t> state; |
| 30 | DataChunk inputs; |
| 31 | StandaloneVector statep; |
| 32 | TypeId result_type; |
| 33 | unique_ptr<data_t[]> levels_flat_native; |
| 34 | vector<idx_t> levels_flat_start; |
| 35 | |
| 36 | ChunkCollection *input_ref; |
| 37 | |
| 38 | // TREE_FANOUT needs to cleanly divide STANDARD_VECTOR_SIZE |
| 39 | #if STANDARD_VECTOR_SIZE < 64 |
| 40 | static constexpr idx_t TREE_FANOUT = STANDARD_VECTOR_SIZE; |
| 41 | #else |
| 42 | static constexpr idx_t TREE_FANOUT = 64; |
| 43 | #endif |
| 44 | }; |
| 45 | |
| 46 | } // namespace duckdb |
| 47 |