diff --git a/velox/dwio/dwrf/writer/DictionaryEncodingUtils.h b/velox/dwio/dwrf/writer/DictionaryEncodingUtils.h index 70ecd3a9aa7c..8e348703002d 100644 --- a/velox/dwio/dwrf/writer/DictionaryEncodingUtils.h +++ b/velox/dwio/dwrf/writer/DictionaryEncodingUtils.h @@ -80,6 +80,8 @@ class DictionaryEncodingUtils { uint32_t newIndex = 0; auto dictLengthWriter = createBufferedWriter(pool, 64 * 1024, lengthFn); + auto errorGuard = + folly::makeGuard([&dictLengthWriter]() { dictLengthWriter.abort(); }); for (uint32_t i = 0; i != numKeys; ++i) { auto origIndex = (sort ? sortedIndex[i] : i); if (!dropInfrequentKeys || shouldWriteKey(dictEncoder, origIndex)) { @@ -94,6 +96,7 @@ class DictionaryEncodingUtils { inDict[origIndex] = false; } } + errorGuard.dismiss();: dictLengthWriter.close(); return newIndex; diff --git a/velox/dwio/dwrf/writer/IntegerDictionaryEncoder.h b/velox/dwio/dwrf/writer/IntegerDictionaryEncoder.h index 69c3a18694df..3ce91eb82070 100644 --- a/velox/dwio/dwrf/writer/IntegerDictionaryEncoder.h +++ b/velox/dwio/dwrf/writer/IntegerDictionaryEncoder.h @@ -207,6 +207,7 @@ class IntegerDictionaryEncoder : public AbstractIntegerDictionaryEncoder { uint32_t newIndex = 0; auto dictWriter = createBufferedWriter(writeBuffer, fn); + auto errorGuard = folly::makeGuard([&dictWriter]() { dictWriter.abort(); }); for (uint32_t i = 0; i != numKeys; ++i) { auto origIndex = (sort ? sortedIndex[i] : i); if (!dropInfrequentKeys || shouldWriteKey(dictEncoder, origIndex)) { @@ -218,6 +219,7 @@ class IntegerDictionaryEncoder : public AbstractIntegerDictionaryEncoder { inDict[origIndex] = false; } } + errorGuard.dismiss(); dictWriter.close(); return newIndex; }