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

Method spill

bolt/exec/SpillableWindowBuild.cpp:100–231  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

98
99template <bool needSort>
100void SpillableWindowBuild<needSort>::spill() {
101 if (inputRows_.size() == 0) {
102 return;
103 }
104 if (spillers_.size() < currentSpilledPartition_ + 1) {
105 setupSpiller();
106 }
107
108 bool keepLastRow =
109 (inputRows_[inputRows_.size() - 1] == previousRow_ && !lastRun_);
110 if (!sortSpiller_) {
111 RowVectorPtr lastRowPtr = nullptr;
112 if (keepLastRow) {
113 if (inputRows_.size() == 1) {
114 return;
115 }
116
117 lastRowPtr = BaseVector::create<RowVector>(
118 inputType_, 1, memory::spillMemoryPool());
119 for (auto i = 0; i < inputType_->size(); ++i) {
120 data_->extractColumn(
121 &previousRow_, 1, data_->columnAt(i), 0, lastRowPtr->childAt(i));
122 }
123
124 // pop_back() here only for aggregate window function
125 // for non-aggregate window function (lag, lead), need to keep the
126 // previousRow in inputRows_ when create partialPartiton
127 // after creating partialPartiton, pop_back() from inputRows_
128 if (isAggWindowFunc()) {
129 inputRows_.pop_back();
130 }
131 }
132
133 // calculate results before spilling
134 auto currentPartition = createPartialPartition();
135 if (keepLastRow && !isAggWindowFunc()) {
136 inputRows_.pop_back();
137 }
138 for (auto i = 0; i < windowFunctions_.size(); ++i) {
139 windowFunctions_[i]->resetPartition(currentPartition.get());
140 windowFunctions_[i]->computeSpillableAggregate(doInitialize_);
141 }
142 doInitialize_ = false;
143
144 spillers_[currentSpilledPartition_]->spill(inputRows_, lastRun_);
145
146 spilledNumRows_ += inputRows_.size();
147
148 if (inputRows_.size() == data_->numRows()) {
149 data_->clear();
150 data_->pool()->release();
151 } else {
152 data_->eraseRows(
153 folly::Range<char**>(inputRows_.data(), inputRows_.size()));
154 }
155 inputRows_.clear();
156
157 if (keepLastRow) {

Callers

nothing calls this directly

Calls 15

spillMemoryPoolFunction · 0.85
copyRowFunction · 0.85
columnAtMethod · 0.80
childAtMethod · 0.80
pop_backMethod · 0.80
eraseRowsMethod · 0.80
backMethod · 0.80
setRowFormatInfoMethod · 0.80
sizeMethod · 0.45
extractColumnMethod · 0.45
resetPartitionMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected