File tree Expand file tree Collapse file tree 1 file changed +22
-6
lines changed Expand file tree Collapse file tree 1 file changed +22
-6
lines changed Original file line number Diff line number Diff 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 ;
You can’t perform that action at this time.
0 commit comments