255827 {
255828 using ZippedTuple = WindowDistinctAggregatorGlobalState::ZippedTuple;
255829 auto &collection = *
gdstate.sorted;
255830 auto &prev_idcs =
gdstate.zipped_tree.LowestLevel();
255831 auto &aggregator =
gdstate.aggregator;
255832
255833
255834 const auto block_begin = (
block_idx * collection.ChunkCount()) /
gdstate.total_tasks;
255835 const auto block_end = ((
block_idx + 1) * collection.ChunkCount()) /
gdstate.total_tasks;
255836
255837 const auto &scan_cols =
gdstate.sort_cols;
255838 const auto key_count = aggregator.arg_types.size();
255839
255840
255841 WindowCollectionChunkScanner scanner(collection, scan_cols, block_begin ? block_begin - 1 : 0);
255842 auto &scanned = scanner.chunk;
255843 if (!scanner.Scan()) {
255844 return;
255845 }
255846
255848 if (!block_begin) {
255849
255850 auto input_idx = FlatVector::GetData<idx_t>(scanned.data.back());
255851 prev_i = input_idx[0];
255852 prev_idcs[prev_i] = ZippedTuple(0, prev_i);
255853 } else {
255854
255855
255856 auto input_idx = FlatVector::GetData<idx_t>(scanned.data.back());
255857 auto scan_idx = scanned.size() - 1;
255858 prev_i = input_idx[scan_idx];
255859 }
255860
255861
255862 WindowDeltaScanner(collection, block_begin, block_end, scan_cols, key_count,
255863 [&](
const idx_t row_idx, DataChunk &prev, DataChunk &curr,
const idx_t ndistinct,
255864 SelectionVector &distinct, const SelectionVector &matching) {
255865 const auto count = MinValue<idx_t>(prev.size(), curr.size());
255866
255867
255868 UnifiedVectorFormat input_format;
255869 curr.
data.back().ToUnifiedFormat(count, input_format);
255870 auto input_idx = UnifiedVectorFormat::GetData<idx_t>(input_format);
255871
255872 const auto nmatch = count - ndistinct;
255873
255874
255875 for (
idx_t j = 0; j < nmatch; ++j) {
255876 auto scan_idx = matching.get_index(j);
255877 auto i = input_idx[input_format.sel->get_index(scan_idx)];
255878 auto second = scan_idx ? input_idx[input_format.sel->get_index(scan_idx - 1)] : prev_i;
255879 prev_idcs[i] = ZippedTuple(second + 1, i);
255880 }
255881
255882
255883 for (
idx_t j = 0; j < ndistinct; ++j) {
255884 auto scan_idx = distinct.get_index(j);
255885 auto i = input_idx[input_format.sel->get_index(scan_idx)];
255886 prev_idcs[i] = ZippedTuple(0, i);
255887 }
255888
255889
255890 prev_i = input_idx[input_format.sel->get_index(count - 1)];
255891 });
255892
255893
255894}
idx_t block_idx
Finalize scan block index.
Definition duckdb.cpp:255618
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237