Skip to content

Commit f2dbab5

Browse files
committed
initial
1 parent ba52907 commit f2dbab5

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

velox/exec/Spiller.cpp

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -238,12 +238,28 @@ void SpillerBase::ensureSorted(SpillRun& run) {
238238
return container_->compareRows(left, right, compareFlags_) < 0;
239239
});
240240
} else {
241-
PrefixSort::sort(
242-
container_,
243-
compareFlags_,
244-
state_.prefixSortConfig().value(),
245-
memory::spillMemoryPool(),
246-
run.rows);
241+
try {
242+
PrefixSort::sort(
243+
container_,
244+
compareFlags_,
245+
state_.prefixSortConfig().value(),
246+
memory::spillMemoryPool(),
247+
run.rows);
248+
} catch (const VeloxRuntimeError& e) {
249+
// If memory allocation failed, fallback to timsort.
250+
if (e.errorCode() == error_code::kMemAllocError) {
251+
LOG(WARNING) << "PrefixSort failed due to memory allocation error, "
252+
<< "falling back to TimSort";
253+
gfx::timsort(
254+
run.rows.begin(),
255+
run.rows.end(),
256+
[&](const char* left, const char* right) {
257+
return container_->compareRows(left, right, compareFlags_) < 0;
258+
});
259+
} else {
260+
throw;
261+
}
262+
}
247263
}
248264

249265
run.sorted = true;

0 commit comments

Comments
 (0)