| 152 | } |
| 153 | |
| 154 | std::pair<vector_size_t, vector_size_t> WindowPartition::computePeerBuffers( |
| 155 | vector_size_t start, |
| 156 | vector_size_t end, |
| 157 | vector_size_t prevPeerStart, |
| 158 | vector_size_t prevPeerEnd, |
| 159 | vector_size_t* rawPeerStarts, |
| 160 | vector_size_t* rawPeerEnds) const { |
| 161 | auto peerCompare = [&](const char* lhs, const char* rhs) -> bool { |
| 162 | return sortKeyInfo_.size() == 0 ? false : compareRowsWithSortKeys(lhs, rhs); |
| 163 | }; |
| 164 | |
| 165 | BOLT_CHECK_LE(end, numRows()); |
| 166 | |
| 167 | auto lastPartitionRow = numRows() - 1; |
| 168 | auto peerStart = prevPeerStart; |
| 169 | auto peerEnd = prevPeerEnd; |
| 170 | for (auto i = start, j = 0; i < end; i++, j++) { |
| 171 | // When traversing input partition rows, the peers are the rows |
| 172 | // with the same values for the ORDER BY clause. These rows |
| 173 | // are equal in some ways and affect the results of ranking functions. |
| 174 | // This logic exploits the fact that all rows between the peerStart |
| 175 | // and peerEnd have the same values for rawPeerStarts and rawPeerEnds. |
| 176 | // So we can compute them just once and reuse across the rows in that peer |
| 177 | // interval. Note: peerStart and peerEnd can be maintained across |
| 178 | // getOutput calls. Hence, they are returned to the caller. |
| 179 | |
| 180 | if (i == 0 || i >= peerEnd) { |
| 181 | // Compute peerStart and peerEnd rows for the first row of the partition |
| 182 | // or when past the previous peerGroup. |
| 183 | peerStart = i; |
| 184 | peerEnd = i; |
| 185 | while (peerEnd <= lastPartitionRow) { |
| 186 | if (peerCompare( |
| 187 | partition_[peerStart - offsetInPartition()], |
| 188 | partition_[peerEnd - offsetInPartition()])) { |
| 189 | break; |
| 190 | } |
| 191 | peerEnd++; |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | rawPeerStarts[j] = peerStart; |
| 196 | rawPeerEnds[j] = peerEnd - 1; |
| 197 | } |
| 198 | return {peerStart, peerEnd}; |
| 199 | } |
| 200 | |
| 201 | // Searches for start[frameColumn] in orderByColumn. Depending on |
| 202 | // preceding or following, this function traverses from start |
no test coverage detected