256804 {
256805 const auto &aggr = gsink.aggr;
256806 auto &filter_mask = gsink.filter_mask;
256807 const auto types =
cursor->chunk.GetTypes();
256808
256809 auto fdata = FlatVector::GetData<data_ptr_t>(
statef);
256810 auto pdata = FlatVector::GetData<data_ptr_t>(
statep);
256811
256814 RowSet row_set(STANDARD_VECTOR_SIZE, hash_row, equal_row);
256815
256816 WindowAggregator::EvaluateSubFrames(bounds,
aggregator.exclude_mode, count, row_idx,
frames, [&](
idx_t rid) {
256817 auto agg_state = fdata[rid];
256818 aggr.function.GetStateInitCallback()(aggr.function, agg_state);
256819
256820
256821 row_set.clear();
256822
256823
256824 if (arg_orderer) {
256825 auto global_sink = sort->GetGlobalSinkState(context.client);
256826 auto local_sink = sort->GetLocalSinkState(context);
256827 OperatorSinkInput sink {*global_sink, *local_sink, interrupt};
256828
256829 idx_t orderby_count = 0;
256830 auto orderby_row = FlatVector::GetData<idx_t>(orderby_sink.data.back());
256831 for (const auto &frame : frames) {
256832 for (auto f = frame.start; f < frame.end; ++f) {
256833
256834 if (!filter_mask.RowIsValid(f)) {
256835 continue;
256836 }
256837
256838 if (!arg_orderer->RowIsVisible(f) || orderby_count >= STANDARD_VECTOR_SIZE) {
256839 if (orderby_count) {
256840 for (column_t c = 0; c < arg_orderer->chunk.ColumnCount(); ++c) {
256841 orderby_sink.data[c].Reference(arg_orderer->chunk.data[c]);
256842 }
256843 orderby_sink.Slice(orderby_sel, orderby_count);
256844 sort->Sink(context, orderby_sink, sink);
256845 orderby_sink.Reset();
256846 }
256847 orderby_count = 0;
256848 arg_orderer->Seek(f);
256849
256850 for (idx_t i = 0; i < arg_orderer->chunk.size(); ++i) {
256851 orderby_row[i] = arg_orderer->state.current_row_index + i;
256852 }
256853 }
256854 orderby_sel.set_index(orderby_count++, arg_orderer->RowOffset(f));
256855 }
256856 }
256857 if (orderby_count) {
256858 for (column_t c = 0; c < arg_orderer->chunk.ColumnCount(); ++c) {
256859 orderby_sink.data[c].Reference(arg_orderer->chunk.data[c]);
256860 }
256861 orderby_sink.Slice(orderby_sel, orderby_count);
256862 sort->Sink(context, orderby_sink, sink);
256863 orderby_sink.Reset();
256864 }
256865
256866 OperatorSinkCombineInput combine {*global_sink, *local_sink, interrupt};
256867 sort->Combine(context, combine);
256868
256869 OperatorSinkFinalizeInput finalize {*global_sink, interrupt};
256870 sort->Finalize(context.client, finalize);
256871
256872 auto global_source = sort->GetGlobalSourceState(context.client, *global_sink);
256873 auto local_source = sort->GetLocalSourceState(context, *global_source);
256874 OperatorSourceInput source {*global_source, *local_source, interrupt};
256875 orderby_scan.Reset();
256876 for (; SourceResultType::FINISHED != sort->GetData(context, orderby_scan, source); orderby_scan.Reset()) {
256877 orderby_row = FlatVector::GetData<idx_t>(orderby_scan.data[0]);
256878 for (idx_t i = 0; i < orderby_scan.size(); ++i) {
256879 const auto f = orderby_row[i];
256880
256881 if (!cursor->RowIsVisible(f)) {
256882
256883 FlushStates(gsink);
256884 cursor->Seek(f);
256885 }
256886
256887
256888 if (aggr.IsDistinct() && !row_set.insert(f).second) {
256889 continue;
256890 }
256891
256892 pdata[flush_count] = agg_state;
256893 update_sel[flush_count++] = cursor->RowOffset(f);
256894 if (flush_count >= STANDARD_VECTOR_SIZE) {
256895 FlushStates(gsink);
256896 }
256897 }
256898 }
256899 return;
256900 }
256901
256902
256903 for (
const auto &frame :
frames) {
256904 for (auto f = frame.start; f < frame.end; ++f) {
256905 if (!filter_mask.RowIsValid(f)) {
256906 continue;
256907 }
256908
256909
256910 if (!
cursor->RowIsVisible(f)) {
256911
256914 }
256915
256916
256917 if (aggr.IsDistinct() && !row_set.insert(f).second) {
256918 continue;
256919 }
256920
256925 }
256926 }
256927 }
256928 });
256929
256930
256932
256933
256934 AggregateInputData aggr_input_data(aggr.GetFunctionData(),
allocator);
256935 aggr.function.GetStateFinalizeCallback()(
statef, aggr_input_data, result, count, 0);
256936
256937
256938 if (aggr.function.HasStateDestructorCallback()) {
256939 aggr.function.GetStateDestructorCallback()(
statef, aggr_input_data, count);
256940 }
256941}
ArenaAllocator allocator
Global allocator.
Definition duckdb.cpp:164091
void FlushStates(const WindowAggregatorGlobalState &gsink)
Flush the accumulated intermediate states into the result states.
Definition duckdb.cpp:256738
Definition duckdb.cpp:256617
Definition duckdb.cpp:256606