Skip to content

Commit

Permalink
Internal duckdb#330: Window Global Init
Browse files Browse the repository at this point in the history
* Define QuantileSortTree for quantile acceleration.
* Add aggregate_wininit_t for constructing global windowing state.
* Update aggregate_window_t to take optional global windowing state.
* Add quantile WindowInit function (not used yet).
  • Loading branch information
Richard Wesley committed Sep 30, 2023
1 parent 2d537bc commit f3daf20
Show file tree
Hide file tree
Showing 9 changed files with 250 additions and 58 deletions.
10 changes: 7 additions & 3 deletions src/core_functions/aggregate/holistic/mode.cpp
Expand Up @@ -41,6 +41,7 @@ struct ModeState {
};
using Counts = unordered_map<KEY_TYPE, ModeAttr>;

FrameBounds prev;
Counts *frequency_map;
KEY_TYPE *mode;
size_t nonzero;
Expand Down Expand Up @@ -209,17 +210,18 @@ struct ModeFunction {

template <class STATE, class INPUT_TYPE, class RESULT_TYPE>
static void Window(const INPUT_TYPE *data, const ValidityMask &fmask, const ValidityMask &dmask,
AggregateInputData &, STATE &state, const FrameBounds &frame, const FrameBounds &prev,
Vector &result, idx_t rid, idx_t bias) {
AggregateInputData &aggr_input_data, STATE &state, const FrameBounds &frame, Vector &result,
idx_t rid, const STATE *gstate) {
auto rdata = FlatVector::GetData<RESULT_TYPE>(result);
auto &rmask = FlatVector::Validity(result);

ModeIncluded included(fmask, dmask, bias);
ModeIncluded included(fmask, dmask, 0);

if (!state.frequency_map) {
state.frequency_map = new typename STATE::Counts;
}
const double tau = .25;
auto &prev = state.prev;
if (state.nonzero <= tau * state.frequency_map->size() || prev.end <= frame.start || frame.end <= prev.start) {
state.Reset();
// for f ∈ F do
Expand Down Expand Up @@ -269,6 +271,8 @@ struct ModeFunction {
} else {
rmask.Set(rid, false);
}

prev = frame;
}

static bool IgnoreNull() {
Expand Down

0 comments on commit f3daf20

Please sign in to comment.