| 192 | } |
| 193 | |
| 194 | void testSortedSpill( |
| 195 | int numDuplicates, |
| 196 | int32_t outputBatchSize = 0, |
| 197 | bool ascending = true, |
| 198 | bool makeError = false) { |
| 199 | SCOPED_TRACE(fmt::format( |
| 200 | "spillType: {} numDuplicates: {} outputBatchSize: {} ascending: {} makeError: {}", |
| 201 | Spiller::typeName(type_), |
| 202 | numDuplicates, |
| 203 | outputBatchSize, |
| 204 | ascending, |
| 205 | makeError)); |
| 206 | constexpr int32_t kNumRows = 5'000; |
| 207 | const auto prevGStats = common::globalSpillStats(); |
| 208 | |
| 209 | setupSpillData( |
| 210 | rowType_, numKeys_, kNumRows, numDuplicates, [&](RowVectorPtr rows) { |
| 211 | // Set ordinal so that the sorted order is unambiguous. |
| 212 | setSequentialValue(rows, 5); |
| 213 | }); |
| 214 | sortSpillData(ascending); |
| 215 | |
| 216 | setupSpiller(2'000'000, 0, makeError); |
| 217 | |
| 218 | // We spill spillPct% of the data in 10% increments. |
| 219 | runSpill(makeError); |
| 220 | if (makeError) { |
| 221 | return; |
| 222 | } |
| 223 | // Verify the spilled file exist on file system. |
| 224 | auto stats = spiller_->stats(); |
| 225 | const auto numSpilledFiles = stats.spilledFiles; |
| 226 | if (type_ == Spiller::Type::kAggregateOutput) { |
| 227 | ASSERT_EQ(numSpilledFiles, 1); |
| 228 | } else { |
| 229 | ASSERT_GT(numSpilledFiles, 0); |
| 230 | } |
| 231 | const auto spilledFileSet = spiller_->state().testingSpilledFilePaths(); |
| 232 | ASSERT_EQ(spilledFileSet.size(), numSpilledFiles); |
| 233 | |
| 234 | uint64_t totalSpilledBytes{0}; |
| 235 | for (auto spilledFile : spilledFileSet) { |
| 236 | auto readFile = fs_->openFileForRead(spilledFile); |
| 237 | ASSERT_NE(readFile.get(), nullptr); |
| 238 | totalSpilledBytes += readFile->size(); |
| 239 | } |
| 240 | ASSERT_TRUE(spiller_->isAnySpilled()); |
| 241 | ASSERT_TRUE(spiller_->isAllSpilled()); |
| 242 | ASSERT_FALSE(spiller_->finalized()); |
| 243 | BOLT_ASSERT_THROW(spiller_->spill(0, nullptr), "Unexpected spiller type"); |
| 244 | BOLT_ASSERT_THROW( |
| 245 | spiller_->setPartitionsSpilled({}), "Unexpected spiller type"); |
| 246 | auto spillPartition = spiller_->finishSpill(); |
| 247 | ASSERT_TRUE(spiller_->finalized()); |
| 248 | ASSERT_EQ(rowContainer_->numRows(), 0); |
| 249 | ASSERT_EQ(numPartitions_, spiller_->stats().spilledPartitions); |
| 250 | ASSERT_EQ(numPartitions_, spiller_->state().spilledPartitionSet().size()); |
| 251 | ASSERT_EQ(numSpilledFiles, spiller_->stats().spilledFiles); |
nothing calls this directly
no test coverage detected