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

Method setupSpillData

bolt/exec/tests/SpillerTest.cpp:316–398  ·  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

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