| 432 | if (rowBasedSpillSortMerger_ != nullptr) { |
| 433 | BOLT_CHECK(!partitionStartRows_.empty(), "No window partitions available"); |
| 434 | |
| 435 | currentPartition_++; |
| 436 | BOLT_CHECK_LE( |
| 437 | currentPartition_, |
| 438 | partitionStartRows_.size() - 2, |
| 439 | "All window partitions consumed"); |
| 440 | |
| 441 | if (currentPartition_ > 0 && |
| 442 | partitionStartRows_.size() - currentPartition_ <= 3) { |
| 443 | auto numPreviousPartitionRows = partitionStartRows_[currentPartition_]; |
| 444 | |
| 445 | auto lastEraseBuffer = |
| 446 | (lastErasePartition_ == -1) ? 0 : numBuffers_[lastErasePartition_]; |
| 447 | int i = lastEraseBuffer; |
| 448 | |
| 449 | MicrosecondTimer timer(&loadFromSpillTimeUs_); |
| 450 | |
| 451 | for (; i < numBuffers_[currentPartition_ - 1]; i++) { |
| 452 | data_->pool()->free(allocatedStarts_[i], allocatedSizes_[i]); |
| 453 | allocatedSizes_[i] = 0; |
| 454 | } |
| 455 | lastErasePartition_ = currentPartition_ - 1; |
| 456 | |
| 457 | sortRows_.erase( |
| 458 | sortRows_.begin(), sortRows_.begin() + numPreviousPartitionRows); |
| 459 | for (int i = currentPartition_; i < partitionStartRows_.size(); i++) { |
| 460 | partitionStartRows_[i] = |
| 461 | partitionStartRows_[i] - numPreviousPartitionRows; |
| 462 | } |
| 463 | } |
| 464 | |
| 465 | // There is partition data available now. |
| 466 | auto partitionSize = partitionStartRows_[currentPartition_ + 1] - |
| 467 | partitionStartRows_[currentPartition_]; |
| 468 | auto partition = folly::Range( |
| 469 | sortRows_.data() + partitionStartRows_[currentPartition_], |
| 470 | partitionSize); |
| 471 | return std::make_shared<WindowPartitionImpl<RowFormat::kSerializedRows>>( |
| 472 | data_.get(), |
| 473 | partition, |
| 474 | inversedInputChannels_, |
| 475 | sortKeyInfo_, |
| 476 | enableJit_); |
| 477 | } |
| 478 | |
| 479 | BOLT_CHECK(!partitionStartRows_.empty(), "No window partitions available") |
| 480 | |
| 481 | currentPartition_++; |
| 482 | BOLT_CHECK_LE( |
| 483 | currentPartition_, |
| 484 | partitionStartRows_.size() - 2, |
| 485 | "All window partitions consumed"); |
| 486 | |
| 487 | // There is partition data available now. |
| 488 | auto partitionSize = partitionStartRows_[currentPartition_ + 1] - |
| 489 | partitionStartRows_[currentPartition_]; |
| 490 | auto partition = folly::Range( |
| 491 | sortRows_.data() + partitionStartRows_[currentPartition_], partitionSize); |