MCPcopy Create free account
hub / github.com/bytedance/bolt / setupSpillData

Method setupSpillData

bolt/exec/tests/AsyncSpillerTest.cpp:302–384  ·  view source on GitHub ↗

'numDuplicates' specifies the number of duplicate rows generated for each distinct sorting key in test.

Source from the content-addressed store, hash-verified

300 // 'numDuplicates' specifies the number of duplicate rows generated for each
301 // distinct sorting key in test.
302 void setupSpillData(
303 RowTypePtr rowType,
304 int32_t numKeys,
305 int32_t numRows,
306 int32_t numDuplicates,
307 std::function<void(RowVectorPtr)> customizeData = {},
308 std::vector<int> numRowsPerPartition = {}) {
309 rowVector_.reset();
310 rowContainer_.reset();
311
312 if (!numRowsPerPartition.empty()) {
313 int32_t totalCount = 0;
314 for (auto count : numRowsPerPartition) {
315 totalCount += count;
316 }
317 BOLT_CHECK_EQ(totalCount, numRows);
318 }
319
320 rowVector_ = BaseVector::create<RowVector>(rowType, numRows, pool_.get());
321 const auto& childTypes = rowType->children();
322 std::vector<TypePtr> keys(childTypes.begin(), childTypes.begin() + numKeys);
323 std::vector<TypePtr> dependents;
324 if (numKeys < childTypes.size()) {
325 dependents.insert(
326 dependents.end(), childTypes.begin() + numKeys, childTypes.end());
327 }
328 // Make non-join build container so that spill runs are sorted. Note
329 // that a distinct or group by hash table can have dependents if
330 // some keys are known to be unique by themselves. Aggregation
331 // spilling will be tested separately.
332 rowContainer_ = makeRowContainer(keys, dependents, false);
333
334 if (numRows == 0 || type_ == Spiller::Type::kHashJoinProbe) {
335 return;
336 }
337 const SelectivityVector allRows(numRows);
338 // Setup temporary row to check spilling partition number.
339 char* testRow = rowContainer_->newRow();
340 std::vector<char*> testRows(1, testRow);
341 const auto testRowSet = folly::Range<char**>(testRows.data(), 1);
342 std::vector<uint64_t> hashes(1);
343
344 int numFilledRows = 0;
345 do {
346 RowVectorPtr batch = makeDataset(rowType, numRows, customizeData);
347 if (!numRowsPerPartition.empty()) {
348 for (int index = 0; index < numRows; ++index) {
349 for (int i = 0; i < keys.size(); ++i) {
350 DecodedVector decodedVector(*batch->childAt(i), allRows);
351 rowContainer_->store(decodedVector, index, testRow, i);
352 // Calculate hashes for this batch of spill candidates.
353 rowContainer_->hash(i, testRowSet, i > 0, hashes.data());
354 }
355 const int partitionNum =
356 hashBits_.partition(hashes[0], numPartitions_);
357 // Copy 'index'th row from 'batch' to 'rowVector_' with
358 // 'numDuplicates' times. 'numDuplicates' is the number of duplicates
359 // per each distinct row key.

Callers

nothing calls this directly

Calls 15

makeRowContainerFunction · 0.85
childAtMethod · 0.80
resetMethod · 0.45
emptyMethod · 0.45
getMethod · 0.45
childrenMethod · 0.45
beginMethod · 0.45
sizeMethod · 0.45
insertMethod · 0.45
endMethod · 0.45
newRowMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected