258869 {
258870 auto &gvstate = sink.global_state.Cast<WindowValueGlobalState>();
258871 auto &lvstate = sink.local_state.Cast<WindowValueLocalState>();
258872 auto &cursor = *lvstate.cursor;
258873 auto &bounds = lvstate.bounds;
258874 auto &frames = lvstate.frames;
258875 auto &ignore_nulls = *gvstate.ignore_nulls;
258876 auto exclude_mode = gvstate.executor.wexpr.exclude_clause;
258877 WindowAggregator::EvaluateSubFrames(bounds, exclude_mode, count, row_idx, frames, [&](
idx_t i) {
258878 if (gvstate.value_tree) {
258879 idx_t frame_width = 0;
258880 for (const auto &frame : frames) {
258881 frame_width += frame.end - frame.start;
258882 }
258883
258884 if (frame_width) {
258885 auto n = frame_width - 1;
258886 auto last_idx = gvstate.value_tree->SelectNth(frames, n);
258887 if (last_idx.second && last_idx.second <= n) {
258888
258889 n -= last_idx.second;
258890 last_idx = gvstate.value_tree->SelectNth(frames, n);
258891 }
258892 if (last_idx.second || last_idx.first >= cursor.Count()) {
258893
258894 FlatVector::SetNull(result, i, true);
258895 } else {
258896 cursor.CopyCell(0, last_idx.first, result, i);
258897 }
258898 } else {
258899 FlatVector::SetNull(result, i, true);
258900 }
258901 return;
258902 }
258903
258904 for (
idx_t f = frames.size(); f-- > 0;) {
258905 const auto &frame = frames[f];
258906 if (frame.start >= frame.end) {
258907 continue;
258908 }
258909
258911 const auto last_idx = WindowBoundariesState::FindPrevStart(ignore_nulls, frame.start, frame.end, n);
258912 if (!n) {
258913 cursor.CopyCell(0, last_idx, result, i);
258914 return;
258915 }
258916 }
258917
258918
258919 FlatVector::SetNull(result, i, true);
258920 });
258921}
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237